Jump to content
  • Advertisement
Sign in to follow this  
rekotc

DX11 directional light and dx11 shader

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

I'm trying to understand the basics of directional lighting, i have a very simple demo with a few axes (i mean the weapon), instanced in different positions, some of them rotated, and i'm using the light.ps shader file i found in this tutorial http://www.rastertek.com/dx11tut09.html in order to add a directional light to the scene.

As you can see from the screenshot below, the light always hits the left side of the axes, like if the directional light vector (pointing at (0,0,-1) is being considered relative to the position of every axe, instead of being fixed to the z negative axis of the scene.

 

Could you help me on this one?

 

thanks

 

 

Share this post


Link to post
Share on other sites
Advertisement

All lighting vectors need to be in the space. The shaders linked to seem to pass a lightDirection in world space by simply setting it and passing it to the shaders. The vertex shader in the link transforms the normal to world space by apply a world transform matrix.

output.normal = mul(input.normal, (float3x3)worldMatrix);

If youre only using the pixel shader I would take a look at how your normal is handled in your vertex shader before being passed to the pixel shader. You probably want it in world space to stay consistent, but all vectors in view space would also be an option.

Share this post


Link to post
Share on other sites

mmm, these are the only lines where i touch the normals in the vertex shader:

 

// Calculate the normal vector against the world matrix only.

output.normal = mul(input.normal, (float3x3)worldMatrix);

 

// Normalize the normal vector.

output.normal = normalize(output.normal);

 

Share this post


Link to post
Share on other sites

i attached the vertex shader below, it's based on the tutorial with a few modifications, in particular i had to add some calculations to translate and rotate the instances in the correct position, i don't know if it's the best approach (and it might be the root of my problems..) , i just couldn't find any example for it.

Share this post


Link to post
Share on other sites

thank you!!! that was stupid... you were right, these are the modified lines:

 

output.normal = mul(input.normal,composition);

output.normal = mul(output.normal, (float3x3)worldMatrix);

Share this post


Link to post
Share on other sites

thank you!!! that was stupid... you were right, these are the modified lines:

 

output.normal = mul(input.normal,composition);

output.normal = mul(output.normal, (float3x3)worldMatrix);

Should probably change that to:

output.normal = mul(input.normal,(float3x3)composition);

As you do not want the translation of the instance to affect the normals, just the rotation :)

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!