Model turns all black in shader

Started by
2 comments, last by EarthBanana 11 years ago

In both Rendermonkey and Shaderdesigner programs used for testing glsl shading, I get a complete black model while I'm trying to learn and test different shaders. Image: http://oi46.tinypic.com/dpg6mu.jpg This image shows the black model in Shaderdesigner, with the following vertex and fragment files:
Vert:


out vec4 color; void main(void)

{

  color = gl_Color;

  vec4 v = vec4(gl_Vertex); 

  v.z = sin(5.0*v.x )*0.25;

 

  gl_Position = gl_ModelViewProjectionMatrix * v;

}

Frag:


in vec4 color;

void main()

{

gl_FragColor = color;

}

What I think is happening, is the shaderdesigner is send the gl_Color from the opengl application to the shader with a black value, and I have no clue how to change that value. I have tried messing around with ALL the menus, options, anything relates to changing color and nothing is working. Why is my model black and how can I fix it?

Advertisement

If its for testing purpose only, why don't you just hard-code the value for gl_Color (or give it some initial value other than 0.0f)? Having one single color supplied to a mesh is not such a huge feature in game developement (as far as I'm concerned) that you do not necessary need to know how to change that. If setting gl_Color in the shader doesn't help, you at least know there is a problem somewhere else.

EDIT: not that there is anything wrong with you wanting to know that, just so you don't have to wait for hours until someone answers but can go on in the meanwhile ^^

Thanks!

Yeah, using a constant color works fine, but I would still like to know how to change gl_Color's default value of black.

I don't know that you can change the default color from black.. maybe using glColor call in your app.. but why not just make a uniform in your fragment shader to set the color how you want.. you can use the format like this in your fragment shader...


uniform vec4 customColor;

and then in your code set the uniform with gl calls...


Vec4Df colorVec = (1.0f,0.0f,0.0f,1.0f); // red
GLuint varIndex = glGetUniformLocation( progID, customColor);  // where progID is the GLuint program ID given to your shader when you compiled it
glUniform4fv(varIndex, 1, colorVec);

This topic is closed to new replies.

Advertisement