Sign in to follow this  

CG texturing problem

Recommended Posts

Hi! I wrote vertex and fragment shader to texture a planet in the way that bright side is of another texture than dark one. The light is at the same position all the time. The planet rotates around its axis. Everything is fine except that bright side rotates with the planet!!!! I am not sure where is the problem. Here is a screen shot to illustrate the problem: screen shot The shaders are: // VERTEX SHADER struct VertexIn { float4 position : POSITION; float4 color : COLOR; float3 vNormal : NORMAL; float2 texCoord : TEXCOORD0; const uniform float4x4 modelViewProjMatrix; const uniform float3 vLightPosition; }; struct VertexOut { float4 position : POSITION; float4 color : COLOR; float2 texCoord : TEXCOORD0; float3 vLightVector : TEXCOORD1; float3 vNormalVector : TEXCOORD2; }; VertexOut main(VertexIn In) { VertexOut Out; Out.position = mul( In.modelViewProjMatrix, In.position ); Out.color = In.color; Out.texCoord = In.texCoord; Out.vLightVector = normalize( ); Out.vNormalVector = In.vNormal; return Out; } // PIXEL SHADER struct FragmentIn { float4 color : COLOR; float3 vLightVector : TEXCOORD1; float3 vNormalVector : TEXCOORD2; float2 texCoord : TEXCOORD0; uniform sampler2D textureLight : TEXUNIT0; uniform sampler2D textureDark : TEXUNIT1; }; struct FragmentOut { float4 color : COLOR; }; FragmentOut main(FragmentIn In) { FragmentOut Out; float lightCoeff = dot( In.vNormalVector, In.vLightVector ); float4 brightSample = tex2D( In.textureLight, In.texCoord ); float4 darkSample = tex2D( In.textureDark, In.texCoord ); Out.color = lerp (darkSample, brightSample * max(lightCoeff, 0), lightCoeff * 0.5 + 0.5); return Out; }

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this