I got the normal mapping working. I wonder how to use a normal map. Not in code but in words. I guess you read the values from the texture like when are doing normal mapping. When you got the rgb value what do you do then? I guess you normalize it like the normal?
When you got you vector what do you do then. I guess you move the vertex position but in what direction? Just the direction of the vector, or do any other calculations have to be done?
Normal mapping has nothing in common with vertex movements. You have probably misused the term. A normal map enables more detailed appearance of the low detailed models by using normals from the high detailed one.
So, how to use your normal map? In the fragment shader, instead of reading interpolated value of the normal passed from the vertex shader, or calculate it by some means, you should read the value from the texture that represents normals. Very simple, very fast, but also very effective trick to display your models as very high detailed ones.
Thanks. but I think I got the normal mapping working.
I have a height map texture that I am currently not using. I wont to use that for bumb mapping but don’t know how to do it.
Thank you all!
You map the rgb values to perturbations in the normal from the geometry normal.
Red = perturbation in tangent direction
Green = perturbation in bitangent direction
Blue = regular geometry normal direction
So, for instance, forgetting tangent, bitangent, if the rgb value is all blue you get back your regular geometry normal.
So what are the tangent and bitangent? Two vectors that span the tangent plane to your model at the point you are shading (hence orthogonal to the normal).
You choose these two vectors so that tangent = direction in x,y,z that a change in u texture spaces gives, bitangent same, but for v. The formulas are out there…
in the end:
newNormal = rtangent + gbitangent + b*geomNormal.
newNormal.normalize(); // interpolation can mess this up
Hehehe, I don’t know if you understand what I wont do do? Let us forget about normal mapping(I guess normal mapping and bump mapping can be combined in the same shader)?
I tried this code but nothing happens except for the normalmapping
Typically you would apply the displacment of the height map in the vertex shader. That way when the triangles are rasterized you would see the effect.
But a high res displacement texture won’t do much for you with a low res mesh.
I think what you might be after is parallax mapping, which produces height effects at the fragment level: Parallax mapping
Haven’t implemented it myself, but it seems like an ultra cool effect!