Help with fragment shaders
in
Programming Questions
•
11 months ago
I'm rather new to shaders and am having some difficulty with the whole thing. I made a basic julia fractal explorer and I got it to work in OpenFrameworks, but it doesn't work in processing (it is giving me the error "Object is not a valid shader"). Any idea why?
Processing code:
- PShader shades;
- void setup(){
- size(640,480,P2D);
- shades=loadShader("shader.glsl");
- }
- void draw(){
- background(255);
- shades.set("iterations",40.0);
- shades.set("c",map(mouseX,0,width,-2,2),map(mouseY,0,width,-2,2));
- shades.set("xRange",-2,2,width);
- shades.set("yRange",-2,2,height);
- filter(shades);
- }
- uniform float iterations;
- uniform vec2 c;
- uniform vec3 xRange,yRange; // form of {x1,x2,width} where the point=map(x-coord,0,width,x1,x2)
- void main() {
- float x=gl_FragCoord.x;
- float y=gl_FragCoord.y;
- x=mix(xRange.x,xRange.y,x/xRange.z);
- y=mix(yRange.x,yRange.y,y/yRange.z);
- float col=0.0,i=0.0;
- float nx=x, x2=x,ny=y;
- gl_FragColor=vec4(0.0,0.0,0.0,1.0);
- for(i=0.0;i<iterations;i++){
- x2=x;
- x=x*x-y*y+c.x;
- y=2.0*x2*y+c.y;
- if(x*x+y*y>4.0){
- col=1.0-i/iterations;
- gl_FragColor=vec4(col,col,col,1.0);
- break;
- }
- }
- }
Thank you!
1