Jump to content
  • Advertisement
Sign in to follow this  
Haroogan

Landscape lighting with Normal map

This topic is 2599 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

Each texel of Normal Map corresponds to each texel of Height Map, i. e. vertex : normal = 1 : 1 ratio. FS:


uniform sampler2D normalSampler2D;

uniform vec3 lightDirection;

varying vec2 fetcher;

void main()
{
vec3 normal = texture2D(normalSampler2D,fetcher).rbg;

normal = normalize(normal * 2.0 - 1.0);

vec3 lightDir = normalize(lightDirection);

float NdotL = max(dot(normal,-lightDir), 0.0);
vec4 diffuse = vec4(1.0,1.0,1.0,1.0);

gl_FragColor = NdotL * diffuse;
}


Why does it look like a quaddy pattern?

18675200103051703800.png

Bilinear filtering is on for sure.

Share this post


Link to post
Share on other sites
Advertisement
That star pattern looks like... bilinear filtering.

What do your normals look like when you visualise them with:void main()
{
vec3 normal = texture2D(normalSampler2D,fetcher).rbg;
normal = normalize(normal * 2.0 - 1.0);
gl_FragColor = normal*0.5+0.5;
}

Off-topic, but this is a strange approach to terrain shading -- if the normals are supplied per vertex, then they should be output by the vertex shader and interpolated via a 'varying' param (fetching them per-fragment is a lot of extra work comparatively).

Share this post


Link to post
Share on other sites

That star pattern looks like... bilinear filtering.

What do your normals look like when you visualise them with:void main()
{
vec3 normal = texture2D(normalSampler2D,fetcher).rbg;
normal = normalize(normal * 2.0 - 1.0);
gl_FragColor = normal*0.5+0.5;
}



Here you go:
75934346163122532675.png


Off-topic, but this is a strange approach to terrain shading -- if the normals are supplied per vertex, then they should be output by the vertex shader and interpolated via a 'varying' param (fetching them per-fragment is a lot of extra work comparatively).
[/quote]

Wrong it is crap approach for several reasons:
1. This will not be per-pixel lighting, and since I'm using triangles it will interpolate between 3 normals of each triangle - and that will produce diamond pattern artifact, you have probably seen it somewhere (if not I can show you, if you ask) - this artifact is much more noticeable than this quaddy pattern artifact and looks ugly.

2. This is LOD-based terrain, therefore if you don't use per-pixel lighting you will see LOD switching, which looks extremely ugly and crappy. You may ask why - this happens because, when you switch LOD's - quantity of normals per block increases by 4 times (according to geo mipmapping) - because you are using discrete normals per vertex. But when I use per-pixel lighting - lighting stays consistent and constant across the whole terrain regardless my position in the world (i. e. the current LOD configuration) - you don't see this switching of lighting quality because you always use the same number of normals - i. e. all pixels of normal map.

Share this post


Link to post
Share on other sites

But what's stopping you from using a higher-res normal map? and btw did you rotate the normals using TBN matrix?


TBN matrix is not the case right now. And I know that it should work ok with 1 : 1 ratio, higher res NM will eat 4x more memory, why would I do that if it should work now with 1 : 1 ratio? I just don't get why this quaddy pattern appears...

Share this post


Link to post
Share on other sites
Look carefully these quaddy artifact appears on the normal map itself already:

45390883985532600895.png

Who's failure is this? Is that due to bi-linear interpolation or because of 8-bits per component (i. e. HDR texture is needed)? I can't believe nobody has faced this problem before.

Share this post


Link to post
Share on other sites
you need more vertices, thats what gouraud interpolation looks like, it sucks yeh, the way you fix it is to move to more polys.
or a higher res normal map.
just sticking a single texel every metre across is going to look shit yes, remember interpolation in linear its not some advanced quadradic thing,
linear interpolation is for crossing small boundaries not large ones like your trying to do.

Bigger normal map, you need to use more memory, theres no other way around it. Maybe try streaming if you cant fit in ram all at once.
And make sure its nicely compressed on disk, if you do that.

You dont just need twice the size either, maybe 16 times the size is what you need. :)

Share this post


Link to post
Share on other sites
Since these quaddy things appear right across the edges of dual triangles (which form a diamond or quad - consider the screenshot) - I believe that it is not about bi-linear interpolation - I just can't believe it!

03084041237035579854.png

21716376574339626808.png

These are screenshots of the same area. As you can see those quaddy artifact appear right across the 4 edges of dual triangles - there must a reason why that happens.

Share this post


Link to post
Share on other sites
That's just the nature of bilinear filtering. If you want to improve it you'll need to try a higher order filtering method like Bicubic. Check out this chapter from GPU Gems 2: http://http.develope..._chapter20.html. Or you can fake it pretty well using smoothstep() in the shader: http://www.iquilezle...ure/texture.htm.


I can't believe nobody has faced this problem before.


Everybody suffers from this issue, but it's essentially unnoticeable once you get some colour and detail normal maps on there. Unless you plan on showing an untextured terrain, I wouldn't worry about it. :)

T

Share this post


Link to post
Share on other sites

That's just the nature of bilinear filtering. If you want to improve it you'll need to try a higher order filtering method like Bicubic. Check out this chapter from GPU Gems 2: http://http.develope..._chapter20.html. Or you can fake it pretty well using smoothstep() in the shader: http://www.iquilezle...ure/texture.htm.

[quote name='Haroogan' timestamp='1302450389' post='4796711']
I can't believe nobody has faced this problem before.


Everybody suffers from this issue, but it's essentially unnoticeable once you get some colour and detail normal maps on there. Unless you plan on showing an untextured terrain, I wouldn't worry about it. :)

T
[/quote]

Yep, I've also thought that when texturing will be applied this artifact will become unnoticeable. However, LOD-based terrain is my bachelor project and the time is running out and I still haven't written a word of documentation (which you know is quite important part of any degree work...), therefore I don't have time to integrate desired texturing into current landscape engine, that's sad but the time is really coming to an end. So all I want now is to make it look smooth without any texturing :)

Thanks for those links, I will try it right now and post some results xD

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!