Shader shows as white instead of the actual shader (Not applied correctly)

Hello, I programmed a little shader using C++ OpenGL to compile and run it today and I’m doing an numerical art exhibition using mainly processing, I want to use this shader in the show and thus have to make the shader works in processing. I looked at the documention and found the function “shader” which does seems to be what I want, however after I drew a QUAD on the whole screen the shader doesn’t show instead there is 2 case :

  • shader() “kind” parameter set to POINTS or LINES : a white rectangle appears which does indicate the shader is somehow rendered but not properly(again it works fine on my C++ setup)
  • shader() “kind” parameter set to TRIANGLES : a grey screen appear(default processing background), which does indicate the QUAD is not even rendered.

I highly doubt the problem comes from the shader file so don’t waste too much time reading it.

Thanks in advance ! :slight_smile:

Here is my processing code :

PShader fractal;

void setup() {
  size(640, 640, P2D);
  fractal = loadShader("shader.fs", "shader.vs");
  fractal.set("Resolution", float(width), float(height));
}

void draw()
{
    fractal.set("a10", 0);
    fractal.set("a9", 0);
    fractal.set("a8", 0);
    fractal.set("a7", 0);
    fractal.set("a6", 0);
    fractal.set("a5", 0);
    fractal.set("a4", 0);
    fractal.set("a3", 1);
    fractal.set("a2", 0);
    fractal.set("a1", 0);
    fractal.set("a0", -1);
    
    fractal.set("ar", 1);
    fractal.set("ai", 0);
    shader(fractal, POINTS);
    beginShape(QUAD);
    vertex(0,0);
    vertex(0, height);
    vertex(width, height);
    vertex(width, 0);
    endShape();
}

And here is my shader code :

#version 330

out vec4 FragColor;

uniform vec2 Resolution;

uniform float a10;
uniform float a9;
uniform float a8;
uniform float a7;
uniform float a6;
uniform float a5;
uniform float a4;
uniform float a3;
uniform float a2;
uniform float a1;
uniform float a0;

uniform float ar;
uniform float ai;

vec2 cinv(in vec2 z)
{
	return (vec2(z.x, -z.y) / dot(z, z));
}

vec2 cmul(in vec2 z1, in vec2 z2)
{
	return(vec2(z1.x * z2.x - z1.y * z2.y, z1.x * z2.y + z1.y * z2.x));
}

vec2 cdiv(in vec2 z1, in vec2 z2)
{
	return (cmul(z1, cinv(z2)));
}

void main()
{
	vec2 z = (gl_FragCoord.xy / Resolution - 0.5) * 4;
	z.x = abs(z.x);
	z.y = abs(z.y);
	vec2 old_z = z;
	float		i_backup;
	for (int i = 0; i < 16; i++)
	{
		z = z - cmul(vec2(ar, ai), cdiv(	vec2(a0, 0) + cmul(z, vec2(a1, 0) + cmul(z, vec2(a2, 0) + cmul(z, vec2(a3, 0) + cmul(z, vec2(a4, 0) + cmul(z, vec2(a5, 0) + cmul(z, vec2(a6, 0) + cmul(z, vec2(a7, ai) + cmul(z, vec2(a8, 0) + cmul(z, vec2(a9, 0) + cmul(vec2(a10, 0), z)))))))))),
						vec2(a1, 0) + cmul(z, vec2(a2 * 2, 0) + cmul(z, vec2(a3 * 3, 0) + cmul(z, vec2(a4 * 4, 0) + cmul(z, vec2(a5 * 5, 0) + cmul(z, vec2(a6 * 6, 0) + cmul(z, vec2(a7 * 7, 0) + cmul(z, vec2(a8 * 8, 0) + cmul(z, vec2(a9 * 9, 0) + cmul(vec2(a10 * 10, 0), z)))))))))));

		if (old_z.x * old_z.x + old_z.y * old_z.y < z.x * z.x + z.y * z.y + 0.00001
		&&	old_z.x * old_z.x + old_z.y * old_z.y > z.x * z.x + z.y * z.y - 0.00001)
		{
			i_backup = i / 16f;
			break;
		}
		old_z = z;
	}
    FragColor = vec4(z.x, z.y, i_backup, 1.0);
}
#version 330

layout (location = 0) in vec3 Position;

void main()
{
	gl_Position = vec4(Position.x, Position.y, Position.z, 1.0);
}
1 Like