bumpmapping in fragment shader
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..
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.
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...
Quote:Original post by Dragon_StrikeQuote: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.
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.
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.
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.
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?
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?)
Quote:Original post by jpetrieQuote: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...
Check out Irrlicht's soure code. There is a decent implementation in there and it is easy to read.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement