Jump to content
  • Advertisement
Sign in to follow this  
CDProp

Normalizing a vector in the vertex shader causing bad interpolations.

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

Sorry about the weird phrasing of my question. I created a vertex shader and a pixel shader. The vertex shader outputs, among other things, a vector that is to represent the CameraPos - VertexPos. The pixel shader then accepts it as input, interpolated of course, and then normalizes it before using it. Now, I originally was normalizing the vector in the vertex shader too. I knew I didn't have to do this, because I was normalizing in the pixel shader, which I knew was necessary, but I didn't think it would hurt anything. I thought that, at worst, it wouldn't run as fast as it otherwise would because I'm doing an extra normalization per vertex. Anyway, my effect was all messed up. Didn't look right at all. I couldn't figure out why. At one point, on a whim, I commented out the normalization of the vector. Viola. It works wonderfully now. And now I'm reading at many places all over the web that normalization in the vertex shader most definitely should not be done. Why not? Why isn't the directionality of the vector retained?

Share this post


Link to post
Share on other sites
Advertisement
Imagine a point, and a surface close to it (draw this on paper with me):


1-------------M-------------2
x



Draw a line from x to 1, call X1, and x to 2, call it X2, you'll notice that halfway across the surface, at M, the interpolated line XM will be correct.


Try normalizing X1, and X2, and see what value you get at M now, its completely off.

Share this post


Link to post
Share on other sites
Oh duh, lol.

I've done similar visualizations but for some reason I never thought to use vectors of different magnitudes.

Thanks!

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!