Jump to content
  • Advertisement
Sign in to follow this  
Mr Kickass

Question on shaders/mathmatics

This topic is 4830 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

edit: OK, I am changing my question because this one is causing me grief not curiosity as the last one. I am trying to do normal mapping. I worked it out great in rendermonkey. So I put the shader into my direct 3d test program, and one part of the object stays lit up as it rotates around - as if the light were rotating with it. Basically, the bumpmap "shadows" do not move as the object rotates with a fixed light in the scene. Here is my vertex shader: void vShader(in VS_INPUT IN, out VS_OUTPUT OUT) { OUT.position = mul(IN.position, matWorldViewProj); OUT.texCoord = IN.texCoord; float3 vertexWorldPos = mul(matWorld, IN.position); float3 lightVector = lightPosition - vertexWorldPos; float3 tangent = mul(matView, IN.tangent); float3 binormal = mul(matView, IN.binormal); float3 normal = mul(matView, IN.normal); float3x3 matTBN = float3x3(tangent, binormal, normal); OUT.tanLightVec = mul(matTBN, lightVector); } [Edited by - Mr Kickass on July 31, 2005 1:14:08 AM]

Share this post


Link to post
Share on other sites
Advertisement
You must multiply the vectors in the first parameter and the matrices in the second. I know what the results look like and I can relate to your grief because of render monkey.

void vShader(in VS_INPUT IN, out VS_OUTPUT OUT)
{
OUT.position = mul(IN.position, matWorldViewProj);
OUT.texCoord = IN.texCoord;

float3 vertexWorldPos = mul(IN.position, matWorld);

float3 lightVector = lightPosition - vertexWorldPos;

float3 tangent = mul(IN.tangent, matView);
float3 binormal = mul(IN.binormal, matView);
float3 normal = mul(IN.normal, matView);
float3x3 matTBN = float3x3(tangent, binormal, normal);

OUT.tanLightVec = mul(lightVector, matTBN);
}

=/

Share this post


Link to post
Share on other sites
By the way, why is matView being applied to the incoming tangent, binormal, and normal vectors? It should be going into world space.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!