• Advertisement
Sign in to follow this  

Adding texture to The Cg Tutorial's Per-Vertex Lighting Example

This topic is 4482 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 there, I am trying to add texture to the per-vertex lighting example on chapter 5 of [The Cg Tutorial - The Definitive Guide to Programmable Real-Time Graphics]. I tried adding the color and texture color simply on fragment shader but naturally the result is an object that is shining always even if there is no light. How can I do this? Should I try passing specular and diffuse parts from vertex program to fragment program?

Share this post


Link to post
Share on other sites
Advertisement
ok, bind the texture in the normal way and set up the tex coords, and perform a tex2D() lookup like you would (this should return the colour as a float4), then just mult the computed lighting colour by the colour returned from the texture. If i recall correctly, the Cg Tutorial utilises TEXCOORD0 for its normal when password from the vert shader onto the frag shader, so you'll want to shift that down a slot to TEXCOORD1 and the same goes for whatever its using for TEXCOORD1 (move it to TEXCOORD2).

Hope this helps! :-)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement