Jump to content
  • Advertisement
Sign in to follow this  

CG texturing problem

This topic is 4784 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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( In.vLightPosition-Out.position.xyz ); 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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!