Skip to main content
gamedev.net
🔒 Locked

Normal Map Artifacts

Started by Moet_Man Jun 28, 2010 at 7:58 PM 4 replies 1.5k views
Original Post
Moet_Man
Moet_Man
Hi All,

Would be grateful for some help. I'm getting strange artifacts with my Normals:



The normal map looks fine. I'm assuming it is my Normal Calculations. I'm calculating normals using the normal map so I'm working in Object space not with tangents. It is a simple textured tri. glsl code:

vec4 colour = vec4( texture3D(texture3d, noiseindex).xyz,0.0);
vec4 normal = vec4( texture3D(texture3dNormal, noiseindex).xyz * 2.0 - 1.0,0.0);

vec3 light_pos = normalize(vec3(10.5,0.5,0.5));
//normal = (normal - 0.5) * 2.0;
normal = normalize(normal);
normal.y = -normal.y;

// Calculate the lighting diffuse value
float diffuse = max(0.0,dot(normal,light_pos));

vec4 finalcolor = diffuse * colour;

gl_FragColor = finalcolor;



Has anyone seen this kind of artifact before ?

P.S. Can't find any way to inbed images - running Firefox/SuSe 11.2. Has this been disabled?

Regards

[Edited by - Moet_Man on June 28, 2010 9:43:01 PM]
Hyunkel
Hyunkel
I'm a bit confused by what you're doing, is the mentionned triangle in object/world space? or is it in screen space?
Your normal map is in tangent space, if you do your lighting calculations in world space you need to transform the normals into world space first.
If you're not doing it in world space then disregard this, I may just misunderstand what you're doing.

P.S. you can insert images using html:
<img src="http://mob909.photobucket.com/albums/ac298/Moet_Man/forum_post.png" />
Moet_Man
Moet_Man
I think it depends on how i've generated my Normal map. I've generated it myself by using the surrounding values of my HeightMap. I would suspect this an object space generated Normal map as opposed to Tangent space. Assuming this I would then need to pass the inverse matrix to the frag shader to convert to World space.

Will try implementing.

Thanks
Eternal
Eternal
Quote:
Original post by Moet_Man
vec4 colour = vec4( texture3D(texture3d, noiseindex).xyz,0.0);
vec4 normal = vec4( texture3D(texture3dNormal, noiseindex).xyz * 2.0 - 1.0,0.0);

Are these really 3D/volume textures? If not, replace texture3D with texture2D + 2D texture coordinates. If they are volume textures more info on how they are created might help.
Hyunkel
Hyunkel
If your normal map is in tangent space and you want to get it into world space, you can do so by multiplying the vector by a tbn matrix.

This is hlsl, replace float3 by vec3 etc.
tangentToWorld is a 3x3 matrix.
//In Vertex shadertangentToWorld[0] = normalize(mul(input.Tangent,  (float3x3)World));tangentToWorld[1] = normalize(mul(input.Binormal, (float3x3)World));tangentToWorld[2] = normalize(mul(input.Normal,   (float3x3)World));//In Pixel shaderfloat3 normalFromTex = normalTex.Sample(texSampler, input.texCoord).rgb;//Bring into -1.0 to 1.0 rangenormalFromTex = normalFromTex * 2.0f - 1.0f;//Convert to world spacefloat3 normal = normalize(mul(normalFromTex, input.tangentToWorld));


This requires you to calculate a tangent and binormal (bitangent) vector for every vertex point though, you want to have those values in your vertex buffer.

I also second the 3d texture thing.
If your textures are 2d, use 2d sampling.
n00body
n00body
@Hyunkel:
You forgot to normalize() the tangent normals after unpacking them.

[Hardware:] Falcon Northwest Tiki, Windows 7, Nvidia Geforce GTX 970 [Websites:] Development Blog |

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.