PDA

View Full Version : problem with shader



ale211734
07-01-2015, 02:57 AM
// vertex shader
bool resultVertex=p.attachVertexShader(GLSL(
layout (location = 0) in vec4 position;
uniform mat4 Modelview;
uniform mat4 Projection;
uniform vec4 colorIn;
out vec4 finalColor;
void main()
{
//ec_pos = (Modelview * position).xyz;
finalColor=colorIn;
gl_Position = Projection * Modelview * position;
}
));

// geometric shader
bool resultGeometric=p.attachGeometryShader(GLSL(
layout(triangles) in;
layout(triangle_strip, max_vertices=3) out;
out vec3 normal;

void main()
{
vec3 v1 = (gl_in[1].gl_Position - gl_in[0].gl_Position).xyz;
vec3 v2 = (gl_in[2].gl_Position - gl_in[0].gl_Position).xyz;
normal = normalize(cross(v1, v2));
for (int i = 0; i < gl_in.length(); i++) {
gl_Position = gl_in[i].gl_Position;
EmitVertex();
}
EndPrimitive();
}
));


// fragment shader
bool resultFragment=p.attachFragmentShader(GLSL(
//fragment shader
//#version 150
in vec4 finalColor;
in vec3 normal;
out vec4 frameBufferColor;
void main() {

vec3 light_dir=vec3(0.0,0.85,0.85);
float d=dot(light_dir,normal);
vec4 color = vec4(d,d,d,0);
frameBufferColor = finalColor*d;
}
));


I have an problem with this shader.
I am trying to pass finalColor variable from vertex shader to fragment shader, but I dont know why can't do it.
My object is rendered with a black color.

GClements
07-01-2015, 04:50 AM
I am trying to pass finalColor variable from vertex shader to fragment shader, but I dont know why can't do it.
Because there's a geometry shader.

The geometry shader needs to have an extra input array and an extra output, and copy the value from the input to the output. E.g.


in vec4 color[];
out vec4 finalColor;
...
for (int i = 0; i < gl_in.length(); i++) {
gl_Position = gl_in[i].gl_Position;
finalColor = color[i];
EmitVertex();
}
...