Bump mapping

Started by
4 comments, last by mmikkelsen 13 years ago
I was playing around with bump maps today, trying to get a result without the TBN basis, and got the following. The first image is a low res mesh and the second a higher res mesh.

mslxu0.jpg
o71tzl.jpg

The edges are quite prominent though, but I think it would look fine in a scene with dynamic tessellation. Any ideas on how I could smooth out those edges?

float4 PS(VS_OUT pIn) : SV_Target
{
float duv = 1.0f * ( 1.0f / 512.0f );
float f = 0.09f;
float g = 0.05f;
float3 n = pIn.normalW;
float thisbump = gSpecMap.Sample( gTriLinearSam, pIn.texC ).x;
float rightbump = gSpecMap.Sample( gTriLinearSam, pIn.texC + float2( duv, 0 ) ).x;
float upbump = gSpecMap.Sample( gTriLinearSam, pIn.texC + float2( 0, duv ) ).x;

float3 tangent = normalize( ddx( pIn.posW ) );
float3 bitangent = normalize( ddy( pIn.posW ) );

float3 thisPos = pIn.posW + n * thisbump * f;
float3 rightPos = ( pIn.posW + g*tangent ) + ( n * rightbump * f );
float3 upPos = ( pIn.posW + g*bitangent ) + ( n * upbump * f );

float3 pnormal = normalize( cross( rightPos - thisPos, upPos - thisPos ) );

float3 LightDir = normalize( float3( 1, 1, 0 ) );
return dot( LightDir, pnormal );
}
Advertisement
With the edges, you mean those 5 or 6 vertical "lines" over the sphere? My guess is that the normals aren't smoothed.
- Smooth the normals (for each vertex, check which other vertices are on the same location. Then calculate the average normal over them. IF their normals match within a certain degree (use dotProduct to check equality)
- Calculate the tangents / biTangents over the model as you usually do, with the smoothed normals this time.
- Render the object as you are already doing

Cheers,
Rick
Does "without the TBN basis" mean that you are using ddx/y(texCoords) in the pixel shader to get the tangents?
If yes:
From my experience smoothing the normals and building an orthonormal TBN with the smoothed normals will help a bit in this case, but since the triangles ARE flat and the the ddx/ys ARE constant across a triangle some hard transition will remain.
You have to smooth out the tangents to get rid of that and that is probably best done by simply precomputing a tangent frame, like spek suggested.
Sorry i haven't actually read your code, but I thought you might be interested in this other thread on bump-mapping without a TBN:
http://www.gamedev.n...ing-on-the-gpu/

[edit]I guess your hard edges are caused by deriving your tangents from the rate-of-change in the position (which does not curve). You might be able to derive a tangent from the either the rate-of-change in the normal, or using the normal and the rate-of-change in the UVs?
Thats an interesting paper. I wonder why developers havn't taken up to using that approach instead of sticking with the TBN basis and normal maps. I mean it requires a LOT less storage, and seems cheaper for animation too as you have less data to transform.

Thats an interesting paper. I wonder why developers havn't taken up to using that approach instead of sticking with the TBN basis and normal maps. I mean it requires a LOT less storage, and seems cheaper for animation too as you have less data to transform.



It has a lot of strengths and weaknesses to it. I see it as an excellent addition to one's bag of tricks.
Anyway, it is slowly beginning to make it's way into production and is also now implemented in Blender 2.57 which is available for download:

http://www.blender.o...ad/get-blender/

It's used both in the off-line renderer and in the glsl 3D view renderer which means the bump you see in 3D view is the same as what you see in the final renderer (impact wise).
It's also available during texture paint which allows you to paint bump maps straight onto the 3D model (or texture) and then view the lit result in real-time as you paint.

The primary issue with this method is that, for textures, the texture filtering is not great on older cards (and some vendors). And as you take the derivative of the filtered signal
it affects results more then when you sample a texture of precomputed derivatives such as a normal map (essentially).

The other issue is that a normal map has components always in -1;1 range regardless of amplitude. For a bump map it's an issue to get both big low curvature hills and low frequency detail into the same bump map.

That being said you're correct that there are also lots of advantages. No tangent space, works under any kind of deformation and it's an easy drop-in.
It also works well with proceduralism, mirrored textures (without effort). For textures in BC4 you're only using 4 bits per texel and still getting relatively good quality.
It works trivially under adaptive tessellation. It's highly practical and will become more useful as texture filtering gradually gets better.

I even did a version that operates as a post-process (but not for blender). Works very well. During in-process (rasterization) I output the depth, interpolated vertex normal and the height.
In the post-process I compute the derivative of the surface position analytically (exact) since ddx and ddy is not available and since numerical approximation isn't good enough
for the derivative of the surface position. For the height on the other hand it is so I compute the derivative of the height by looking at a 3x3 neighborhood.

I'm using sobel basically but before doing so I bleed/lerp the center height into the neghbor height using the difference of the view-space Z.
The blend value is essentially t = exp(-K * abs(Zdiff)); This bleed is just a temp in the calculations I don't actually modify the height values in the main buffer.
This bleed is to make it fail gracefully when the neighboring pixels aren't connected to the center pixel.
As I was saying I don't use this numerical approximation for the derivative of the surface position because it needs to be more precise. So I compute it the exact way.

It's a little complicated to explain but I hope the overall idea is coming across. Works well anyway.

This topic is closed to new replies.

Advertisement