@luffy8naruto wrote:
Hi, I am trying to implement a worley noise using ofshader. My ofDraw() code looks like this:
ofSetBackgroundColor(0, 0, 0); z += 1; if (z > 400) z = 0; shader.begin(); shader.setUniform1f("u_z", z); shader.setUniform2f("u_resolution", ofGetWidth(), ofGetHeight()); shader.setUniform3fv("u_p", (float*)&a[0].x, nmax); ofRect(0, 0, ofGetWidth(), ofGetHeight()); shader.end();
This is my shader.frag code:
#ifdef GL_ES precision mediump float; #endif #define nmax 1000 uniform vec2 u_resolution; uniform float u_z; uniform vec3 u_p[nmax]; void main() { vec2 xy = gl_FragCoord.xy; float cmin=u_resolution.x*u_resolution.x; float c=0; vec3 dp; for(int i=0;i<nmax; i++) { dp=u_p[i] - vec3(xy,u_z); c=dot(dp,dp); if(c<cmin) cmin=c; } cmin = 1.5*sqrt(cmin)/255.0; gl_FragColor = vec4(cmin,cmin,cmin,1.0); }
In the code, the nmax=1000 and the contents of the array a(in the shader.setUniform3fv) does not change. Is there a way to set it to the shader once rather than setting it each frame?
Posts: 1
Participants: 1