Model turns all black in shader

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?

I think you will have to change the type of your attribute from out to varying that is change this in both vs and fs



out vec4 color; 

to this


varying vec4 color;

or simply if you want, you can remove your output varying altogether by using the gl_FrontColor varying in the vertex shader and gl_Color in the fragment shader like this


//vertex shader
void main(void)  {  
  gl_FrontColor = gl_Color;   
vec4 v = vec4(gl_Vertex);    
 v.z = sin(5.0*v.x )*0.25;    
gl_Position = gl_ModelViewProjectionMatrix * v;  }

//fragment shader
void main() {  
gl_FragColor =  gl_Color; 
}

I havent tested this code but as far as I can see this should do it.

[QUOTE=mobeen;1249668]I think you will have to change the type of your attribute from out to varying that is change this in both vs and fs



out vec4 color; 

to this


varying vec4 color;

or simply if you want, you can remove your output varying altogether by using the gl_FrontColor varying in the vertex shader and gl_Color in the fragment shader like this


//vertex shader
void main(void)  {  
  gl_FrontColor = gl_Color;   
vec4 v = vec4(gl_Vertex);    
 v.z = sin(5.0*v.x )*0.25;    
gl_Position = gl_ModelViewProjectionMatrix * v;  }

//fragment shader
void main() {  
gl_FragColor =  gl_Color; 
}

I havent tested this code but as far as I can see this should do it.[/QUOTE] Unfortunately, both of those ideas resulted in the same black screen.

if possible can u share your shader designer/rm prject. And what happens if you directly output a constant color from the fragment shader or store positions as color and output in fragment shader?

Yeah, using a constant color works fine, but I would still like to know how to change gl_Color’s default value of black that is sent to the shader. http://rapidshare.com/files/280276482/practice.rar

I cant download the file it says ERROR: Download permission denied by uploader. (0b67c2f5)

Sorry about that. http://my.rapidshare.com/shawn619/12387 Right click the file -> Download

OK it does not work for me as well. You shader is correect I have checked it in RenderMonkey which is much more stable. Seems to me that there are some problems with the ShaderDesigner. For me, I even cant see the contents of the vertex/fragment shaders (editor area is all white).

O ok. Since you said it appears to work in RenderMonkey, may I ask what color is sent through gl_Color as default to the shader? And how do you change the value of gl_Color passed to the shader in RenderMonkey?

By default it passes in white color in gl_Color attribute. As far as I know, you can’t change this. You can however change the binding sematics of you per-vertex attributes through Stream Mapping.

O ok, is got white as a color too in RenderMonkey. How can I make lights(ie: light[0]) in RenderMonkey?

In the old GLSL shaders (pre OpenGL 3.0), you can access the fixed function light position using gl_LightSource[0].position
BUT I dont think RenderMonkey passes any GL lights nor does it exposes these to your workspace.

Either way, I think you can just create your own uniform vec3 variable to store the light position/s.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.