• 12
• 12
• 9
• 10
• 13

# Terrain Normal Map

This topic is 1695 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm trying to apply bump map to my terrain using Pixel Shader.

I found a tutorial, but it's using BiNormal and Tangent, I don't have both in my terrain mesh, I only have Position, TexCoord (UV) and Normal.

http://rastertek.com/tertut15.html

Can someone give me idea on how can I convert the code to use Position, TexCoord and Normal only?

Here is my Vertex Shader "IN" structure:

struct VERTEX_IN
{
float3 Pos : POSITION;
float2 UV : TEXCOORD0;
float3 Normal : NORMAL;
};

##### Share on other sites

You cannot bump objects in a pixel shader without a tangent and bitangent, as they describe the mapping from tangent space to object space so that normal can be brought from tangent space into object/world/view space.

You already have what you need to calculate the tangents and bitangents for your mesh, you just need to do it.

http://www.terathon.com/code/tangent.html

This describes the math behind process. It's heavy on the linear algebra, but provides source as well.

##### Share on other sites

@Burnt_Fyr: I created some lights (such as point light) that use bump mapping with meshes other than the terrain, and it works, I don't use BiNormal or Tangent.

So did you mean I can't create bump mapping on any mesh without Binormal/Tangent calculation? Because I already did.

BTW, I tried the directional light on my terrain, but it doesn't work on the terrain as expected.

So I think probably the terrain bump map should be calculated differently...

Edited by Medo3337

##### Share on other sites

After working for sometime, here is what I got

I'm NOT sure if this is bump map, if it's bump map, how do I improve it to make it more realistic?

[attachment=16999:terrain.png]

##### Share on other sites

Hi!

That does look like a bump mapping effect, only it is kind of weak. It is hard to tell if it is correct without seeing the textures and the bump map. What kind of light are you using? A directional light?

But what I actually wanted to say was that you can compute the the tangents on the CPU like Burnt_Fyr said. I did that for ages. But eventually my terrain got so big and real time terrain editing such a major feature, that doing it on the CPU was a major performance bottleneck. And also RAM use was a major issue.

So now I am approximating them in the vertex shader:

float3 n = normalize(mul(inNormal, world));
float3 c1 = cross(inNormal, float3(0, 0, 1));
float3 c2 = cross(inNormal, float3(0, 1, 0));

// Calculate tangent
float3 t = (distance(c1, 0) > distance(c2, 0)) ? c1 : c2;
float3 b = cross(inNormal, t);

float3x3 tbnMatrix = float3x3(t.x, b.x, n.x,
t.y, b.y, n.y,
t.z, b.z, n.z);


This produces almost identical results with the CPU version and all you need is the terrain normal. It gives the best results for well behaved continuous heightmap. This is also my not too clever way of asking for feedback on this computation .

##### Share on other sites

@DwarvesH: Yes I'm using Directional Light.

Basically, I'm trying to create commercial quality terrain, how do I make the bump map look realistic? I just applied a random bump map to the terrain in the screenshot above.

##### Share on other sites

Well, to make it even more realistic, you could try to implement Parallax Occlusion mapping.

An example of that would be that you have a small area of dirt, and you wanted some wheel tracks, without adding more vertices, indices...

I made a small experiment with it a while ago, you can see it here if you wish: (Just 4 vertices and 6 indices. A plane basically)

http://cuboidzone.wordpress.com/2013/05/10/pom-parallax-occlusion-mapping-cuboid-engine/

##### Share on other sites

And to make it look more realistic, you could generate a bump map for each texture layer.

I know that several bump map generators exist, just don't remember their names.

Too lazy to Google it right now.

##### Share on other sites

After you fully understand that, going from those simple shaders to something really complicated that makes your normals pop will take you quite a while, but it is easier if you start with the basics.

Obtaining something of "commercial quality" will take you months at least, and something like FarCry 3 years. I'm slowly getting there:

So maybe you should look into an existing engine so that you can concentrate on the gameplay. Or maybe you do wish to write an OKish 10-25k lines of code terrain engine.