Terrain Normal Map

Started by
10 comments, last by pbobzebuilder 10 years, 8 months ago

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;
};

Advertisement

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.

@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...

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]

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 smile.png.

@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.

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/

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

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. happy.png

FastCall22: "I want to make the distinction that my laptop is a whore-box that connects to different network"

Blog about... stuff (GDNet, WordPress): www.gamedev.net/blog/1882-the-cuboid-zone/, cuboidzone.wordpress.com/

I would start with something simple, like http://www.dhpoware.com/demos/xnaTerrainNormalMapping.html.

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.

How do I make the Directional Light EVERYWHERE on the terrain? I want the terrain to show light everywhere so the bump map never disappear.

This topic is closed to new replies.

Advertisement