1 registered members (7th_zorro),
793
guests, and 1
spider. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Normalmapping on terrain
[Re: Excessus]
#122317
04/08/07 21:48
04/08/07 21:48
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
terrains are passed to shaders just as models are...
We were talking about this in that other thread, but I guess it's moved here now, which is a better place for it anyways.
I might work on such a shader. My one question was, should there be one normal map for the whole terrain, normal maps for each texture, or both?
xXxGuitar511 - Programmer
|
|
|
Re: Normalmapping on terrain
[Re: Excessus]
#122319
04/09/07 00:55
04/09/07 00:55
|
Joined: Sep 2002
Posts: 8,177 Netherlands
PHeMoX
Senior Expert
|
Senior Expert
Joined: Sep 2002
Posts: 8,177
Netherlands
|
Quote:
Does anyone know if it is possible to use normalmapping for terrains anyway?
Yes, but unless you've got a really highly detailed normal map with only small details, it will look quite horrible. If a normal mapping shader get's tiled, the last thing you would want is one big normal map in my humble opinion.
Isn't it possible to tile a colormap and use a bigger normal map when using external textures and make sure tiling get's done in the shaders itself?? Just a thought,
Cheers
|
|
|
Re: Normalmapping on terrain
[Re: PHeMoX]
#122320
04/09/07 01:01
04/09/07 01:01
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
I've got the shader done, but I need some textures to test it with. If you can send any of these it would be helpful...
1) grass diffuse, normal 2) dirt diffuse, normal 3) rock diffuse, normal 4) sand diffuse, normal 5) heightmap, [some kind of] normal mpa that fits it...
xXxGuitar511 - Programmer
|
|
|
Re: Normalmapping on terrain
[Re: xXxGuitar511]
#122321
04/09/07 03:51
04/09/07 03:51
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
Eh, I'm not getting such good results.
I got the muulti-texture, and importing all the textures to the shader, that was the easy part.
I'm having trouble getting the normals to react to light correctly. The dot product of the normals gives me results, but when moving the sun, it's as if the sun never moved. they stay the same, but the lighting of the face adjusts.
Not sure why this is, I'm gonna go do more testing...
xXxGuitar511 - Programmer
|
|
|
Re: Normalmapping on terrain
[Re: xXxGuitar511]
#122322
04/09/07 07:38
04/09/07 07:38
|
Joined: Jan 2004
Posts: 2,013 The Netherlands
Excessus
OP
Expert
|
OP
Expert
Joined: Jan 2004
Posts: 2,013
The Netherlands
|
Quote:
I'm having trouble getting the normals to react to light correctly. The dot product of the normals gives me results, but when moving the sun, it's as if the sun never moved. they stay the same, but the lighting of the face adjusts.
Not sure why this is, I'm gonna go do more testing...
It's the tangents
|
|
|
Re: Normalmapping on terrain
[Re: Excessus]
#122323
04/09/07 08:30
04/09/07 08:30
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
I'm using the "tangent, binormal, normal" system that I've sen many times before. And it's the same system I used in the "Best VSPS shader"...
Any ideas?
I'll send you the code I've done tomorrow... (Which is actually later today, lol)...
xXxGuitar511 - Programmer
|
|
|
Re: Normalmapping on terrain
[Re: xXxGuitar511]
#122324
04/09/07 08:44
04/09/07 08:44
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
yeah, I'm out for tonight. but I'm still not sure why the shader isn't working. It is a strange result, and hard to explain without showing. it worked in the normal mapping shader I posted, but not in this one. With a model terrain too! why? Code:
{ Vertex Shader: float3x3 worldToTangentSpace; worldToTangentSpace[0] = mul(inTangent, matWorld); worldToTangentSpace[1] = mul(cross(inTangent, inNormal), matWorld); worldToTangentSpace[2] = mul(inNormal, matWorld);
Out.Sun = mul(worldToTangentSpace, -vecSunDir);
Pixel Shader: float4 output = saturate(dot(bumpNormal, In.Sun))l return output; }
I'm out for the night. Sorry. Too much "Russian mineral water"...
xXxGuitar511 - Programmer
|
|
|
Re: Normalmapping on terrain
[Re: xXxGuitar511]
#122325
04/09/07 09:18
04/09/07 09:18
|
Joined: Jan 2004
Posts: 2,013 The Netherlands
Excessus
OP
Expert
|
OP
Expert
Joined: Jan 2004
Posts: 2,013
The Netherlands
|
I've just verified it again: the tangent passed to a terrain entity is always 0,0,0. Try outputting it as a color in the pixel shader..
I think you can calculate the tangent and binormal from only the normal because you know that it's a regular grid (u and v always pointing in xz direction).
So you'd take the cross of the normal and a (unit?) vector pointing in x (or z?) direction to get the tangent and then cross that with the normal to get the binormal or something..
PS. I'm talking about the directX coordinate system here, so z = y.
EDIT: I was creating this shader for a client who is using 6.31.4. I just tried it in 6.50, and it does give some kind of a tangent there, but I'm getting the impression it's still not quite right..
EDIT2: Yes I'm now convinced that in 6.50, the tangents are wrong. Try outputting the tangent as a color on a terrain and then convert that terrain to a mdl and do it again. The tangents look somewhat like they should be, but there are some strange things.. I guess it's a bug, or we're not supposed to use them with terrains (and have to calculate them from the normal).
EDIT3: Ok, I can calculate the tangent and binormal from the normal on a terrain. This works on a model terrain, but when I use it on a terrain, I get the SAME tangents as when I use the tangent flag.. Seems like the problem is related to the normals then.. worldToTangentSpace[0] = cross(InNorm, float3(0.0f, 0.0f, 1.0f)); worldToTangentSpace[1] = cross(worldToTangentSpace[0], InNorm); worldToTangentSpace[2] = InNorm;
EDIT4: Ok, after calling ent_fixnormals everything works fine.. Strange! I would advise you to use the above way of calculating the tangent and not use the tangent flag, because it is faster on the GPU. Ofcourse it only works for terrains. EDIT: it's not faster
Last edited by Excessus; 04/10/07 07:33.
|
|
|
|