Jump to content
  • Advertisement
Sign in to follow this  
Dragon_Strike

bumpmapping in fragment shader

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

im trying to implement perpixel vumpmapping in my program... my idea is to send a bump heightmap to the shader and then calculate the lighting based on this heightmap... but how would i calculate the normals in the fragmentshader using this method? i need some way to access other values fomr the pixel that is currently being processed..

Share this post


Link to post
Share on other sites
Advertisement
Might I suggest going with Dot3 bumpmapping which uses a normal map instead? It'll make your life easier, as the normals are stored in the texture already.

Share this post


Link to post
Share on other sites
Quote:
Original post by ScottC
Might I suggest going with Dot3 bumpmapping which uses a normal map instead? It'll make your life easier, as the normals are stored in the texture already.


ehm dot3 bump mapping cant calculate the normalmap... i need a way to calculate normals and tangents per pixel since my bumpmap has a higher res than my mesh...

Share this post


Link to post
Share on other sites
Quote:
Original post by Dragon_Strike
Quote:
Original post by ScottC
Might I suggest going with Dot3 bumpmapping which uses a normal map instead? It'll make your life easier, as the normals are stored in the texture already.


ehm dot3 bump mapping cant calculate the normalmap... i need a way to calculate normals and tangents per pixel since my bumpmap has a higher res than my mesh...


You can use normalmapping for bumpmapping for what you need. Use Nvidias Melody tool to take your mesh and create a normalmap from that for use in lower resolution model meshes.

Share this post


Link to post
Share on other sites
You don't want to calculate normals per pixel, you want to calculate them in a pre-processing step (from the heightmap if you wish) and store them in a normal map. Normal maps can have any resolution you want, just like any other texture.

Share this post


Link to post
Share on other sites
A mesh doesn't have a resolution; a texture cannot be "of higher resolution" than a mesh. Obviously the texture is mapped to your mesh, or your couldn't access it. If you turn that height map into a normal map (pretty easy), you can do dot3 normalmapping (which is not supposed to calculate the normal map, it is supposed to use the pre-calculated normal map).

You can't really easily compute per-pixel normals based on a height map in the pixel shader. The trick is turning the height map into a normal map -- something usually done as a preprocessing step by your tools. Generally, to do this, you need to access the pixels around the pixel you are processing, to compute height differences, and thus the implicit slope of the surface. But it will be clumsy and unreliable to try and sample exactly adjacent pixels of the bump map in the pixel shader. I think it is doable, if you pass the pixel dimensions of the texture to the shader and compute tangent space basis vectors based on texture coordinates (so you know which directions to step along the texture space), but it isn't ideal.

Share this post


Link to post
Share on other sites
ok... well using a program to precalculate the values for me wont work since 24bit color isnt precise enough... then iwould have to pre-calcualte the normalmap nad heightmap on the cpu each time i start the program.. which would take far to long time... how can i solve this?

Share this post


Link to post
Share on other sites
Quote:
Original post by Dragon_Strike
ok... well using a program to precalculate the values for me wont work since 24bit color isnt precise enough... then iwould have to pre-calcualte the normalmap nad heightmap on the cpu each time i start the program.. which would take far to long time... how can i solve this?


24 bits per pixel (eight per channel, or vector component) is plenty sufficient. You'll most likely be limited to this on the card anyway. You don't have to compute anything at runtime (you could, but why bother?)

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
Quote:
Original post by Dragon_Strike
ok... well using a program to precalculate the values for me wont work since 24bit color isnt precise enough... then iwould have to pre-calcualte the normalmap nad heightmap on the cpu each time i start the program.. which would take far to long time... how can i solve this?


24 bits per pixel (eight per channel, or vector component) is plenty sufficient. You'll most likely be limited to this on the card anyway. You don't have to compute anything at runtime (you could, but why bother?)


i guess ill have to go with 8 bits per vector then... but anyways do u know of a pgraom that can create a normalmap and tangetmap texture from a hieghtmap.. i looked at nvida melodyu and it only uses models...

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!