Sign in to follow this  

bumpmapping in fragment shader

This topic is 4083 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
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
Quote:
Original post by optic2000
Check out Irrlicht's soure code. There is a decent implementation in there and it is easy to read.


id rather not put my time on implementing this... if there is a seperate program that can do it... which i hope there is... dont want to waste time or code space since im getting near my deadline for my project...

Share this post


Link to post
Share on other sites
The "easiest" thing to do is:

1. Download a tool (like ATI's bump map generator) or plugin for a graphics program like photoshop.
http://www.ati.com/developer/sdk/radeonSDK/html/Tools/ToolsPlugIns.html

2. Create and export a normal map for your texture.

3. Load the textures into your OpenGL program.

4. Pass the textures to your fragment shader (where you should have the code to handle this).


Share this post


Link to post
Share on other sites
ok ive replaced the normalmpa calcualtions in my code with the ati bump map generator texture which i load and send to the fragment shader...


uniform sampler2D normals;
uniform float angle;

void main()
{

vec3 Normal = normalize(normalize(texture2D(normals, gl_TexCoord[0].st).rgb)*2.0-1.0);

vec3 LightDir = vec3(-cos(angle*0.01745329), -sin(angle*0.01745329), 0.0);
float brightnes = dot(LightDir, Normal);

gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0)*brightnes ;

}



but it doesnt work as it should for some reason.. no matter what angle i use i always get the same lighting...?

Share this post


Link to post
Share on other sites
Quote:
Original post by adawg1414
Honestly, through all of the stuff I looked through for that stupid tangent space calculation, it turns out that using your surface normal as your tangent works fine.


WHAT? Not possible if you are doing it correct. The tangent is perpendicular to the normal as is the bitangent. But where this happens is what needs to be calculated.

Share this post


Link to post
Share on other sites

This topic is 4083 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this