PDA

View Full Version : Shaders and non-shader lighting



Waves
11-29-2010, 01:42 PM
Hi all,

I've set up a vertex shader to perform deformations of a model stored in a vertex buffer object. I am currently lighting the model using the tradtional OpenGL approach (glEnable(GL_LIGHTING) etc...).

When the shader (I'm using CG btw) is enabled all of my lighting seemed to be ignored in exchange for cyan colour. What I'd really like to to have a shader that takes the colour values calcualted from the OpenGL lights and then passes it on un-touched.

Here is my shader, that doesn't work:



struct appdata
{
float4 position : POSITION;
float4 color : COLOR0;
};

struct vfconn
{
float4 HPos : POSITION;
float4 Col0 : COLOR0;
};

vfconn main(appdata IN, uniform float4x4 modelViewProj)
{
vfconn OUT;

OUT.HPos = mul(modelViewProj, IN.position);
OUT.Col0.xyz = IN.color.xyz;

return OUT;
}


My question is therefore, is it possible to get this functionality, or if I go down the shader route will I have to write my lighting using shaders. If it is possible however, what am I doing wrong.

Thanks for all your help in advance,

Jon

dukey
11-29-2010, 02:02 PM
yes you need to write your own lighting code, or recycle someone elses