2 registered members (OptimusPrime, AndrewAMD),
14,580
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Normalmapping on terrain
[Re: Excessus]
#122326
04/09/07 10:59
04/09/07 10:59
|
Joined: Nov 2004
Posts: 7,121 Potsdam, Brandenburg, Germany
Machinery_Frank
Senior Expert
|
Senior Expert
Joined: Nov 2004
Posts: 7,121
Potsdam, Brandenburg, Germany
|
Thank you very much for looking into this. This effort is very appreciated.
If this is really a bug with calculating normals in GS then it would be fantastic if you would create a report to Conitec so that they can change that for A7.
Models, Textures and Games from Dexsoft
|
|
|
Re: Normalmapping on terrain
[Re: Machinery_Frank]
#122327
04/09/07 11:16
04/09/07 11:16
|
Joined: Jan 2004
Posts: 2,013 The Netherlands
Excessus
OP
Expert
|
OP
Expert
Joined: Jan 2004
Posts: 2,013
The Netherlands
|
After some more testing I've found that this is also caused by the differences between 6.31.4 and 6.50: the terrain was saved by the old MED. When resaving it with the 6.50 MED, everything worked fine.. So no bug in 6.50, only one in 6.31 where no tangents are passed to terrains. Oh well, I've found a faster way to calculate the tangent for terrains EDIT: wrongI don't understand then, why your shader is not working xXxGuitar.
Last edited by Excessus; 04/10/07 07:32.
|
|
|
Re: Normalmapping on terrain
[Re: Excessus]
#122328
04/09/07 16:58
04/09/07 16:58
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
I must be doing something wrong, lol. I'm actually using a model for terrain as well.
It calculates lighting for the faces of the terrain just fine, but the bump maps don't. As I [tried] to describe, the "brightness" will adjust depending on the sun's angle, but the bumps always look as if the sun was comming from the same direction...
maybe I sgould try passing the worldToTangent(normal,tangent) to the pixel shader...
xXxGuitar511 - Programmer
|
|
|
Re: Normalmapping on terrain
[Re: xXxGuitar511]
#122329
04/09/07 19:49
04/09/07 19:49
|
Joined: Jan 2004
Posts: 2,013 The Netherlands
Excessus
OP
Expert
|
OP
Expert
Joined: Jan 2004
Posts: 2,013
The Netherlands
|
Quote:
maybe I sgould try passing the worldToTangent(normal,tangent) to the pixel shader...
I wouldn't do that, as it will be very slow. There are many more pixels than vertices, so as a general rule you should keep as much calculations in the vertex shader as possible.
Maybe I or someone else can spot the error if you post your code.
|
|
|
Re: Normalmapping on terrain
[Re: Excessus]
#122330
04/09/07 20:51
04/09/07 20:51
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
Damn, I hate posting shaders on here. It's too messy. Code:
TMULTI_VS_OUT TMulti_VS( float4 inPos : POSITION, float3 inNormal : NORMAL, float3 inTangent : TANGENT, float2 inTCoord : TEXCOORD0) { TMULTI_VS_OUT Out;
float3x3 worldToTangentSpace; worldToTangentSpace[0] = mul(inTangent, matWorld); worldToTangentSpace[1] = mul(cross(inTangent, inNormal), matWorld); worldToTangentSpace[2] = mul(inNormal, matWorld);
Out.Pos = mul(inPos, matWorldViewProj); float3 N = normalize(mul(inNormal, matWorldInv)); float3 P = mul(inPos, matWorld); Out.Sun = mul(worldToTangentSpace, -vecSunDir); float3 Viewer = P - vecViewPos; Out.View = mul(worldToTangentSpace, -Viewer);
Out.Fog = DoFog(P);
Out.tCoord = inTCoord.xy; return Out; }
float4 TMulti_PS(TMULTI_PS_IN In): COLOR { float4 MaskColor = tex2D(mapMask, In.tCoord); float4 NormalColor = 2*(tex2D(mapNormal, In.tCoord)-0.5); float4 RColor = tex2D(mapRC, In.tCoord * 10); float4 GColor = tex2D(mapGC, In.tCoord * 10); float4 BColor = tex2D(mapBC, In.tCoord * 10); float4 RNormal = 2*(tex2D(mapRN, In.tCoord * 10)-0.5); float4 GNormal = 2*(tex2D(mapGN, In.tCoord * 10)-0.5); float4 BNormal = 2*(tex2D(mapBN, In.tCoord * 10)-0.5); float3 ViewDir = normalize(In.View);
float4 outColor = 0.5f; outColor = lerp(outColor, RColor, MaskColor.r); outColor = lerp(outColor, GColor, MaskColor.g); outColor = lerp(outColor, BColor, MaskColor.b); float3 outNormal = NormalColor; outNormal = lerp(outNormal, RNormal, MaskColor.r); outNormal = lerp(outNormal, GNormal, MaskColor.g); outNormal = lerp(outNormal, BNormal, MaskColor.b);
float3 sunDir = In.Sun; float4 sunDiff = saturate(dot(outNormal, sunDir)); float4 sunShadow = saturate(4 * sunDiff);
float4 sunOut = (outColor*sunDiff) * sunShadow * vecSunDiffuse; sunOut.a = 1.0f; return sunOut; }
xXxGuitar511 - Programmer
|
|
|
Re: Normalmapping on terrain
[Re: Excessus]
#122332
04/09/07 21:16
04/09/07 21:16
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
Thats what I've read/heard as well. I'm not sure why this would be, but I'll give it a try. (It worked fine in the other NM shader, I think...)
Also, for calculating the sun. The code I'm basing mine on is matts light. float3 Light1 = P - vecLightPos; Out.Light1 = mul(worldToTangent, -Light1);
I replaced the light with sun, and instead of subtracting the two points, i simply input -vecSunDir (see above)...
xXxGuitar511 - Programmer
|
|
|
Re: Normalmapping on terrain
[Re: xXxGuitar511]
#122333
04/09/07 21:17
04/09/07 21:17
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
I think I should mention the fact that I'm driving blind, lol.
I don't know what the tangent is? Whats a tangent? I know normals, but are they not enough?
xXxGuitar511 - Programmer
|
|
|
Re: Normalmapping on terrain
[Re: xXxGuitar511]
#122334
04/09/07 21:30
04/09/07 21:30
|
Joined: Jan 2004
Posts: 2,013 The Netherlands
Excessus
OP
Expert
|
OP
Expert
Joined: Jan 2004
Posts: 2,013
The Netherlands
|
Quote:
Also, for calculating the sun. The code I'm basing mine on is matts light. float3 Light1 = P - vecLightPos; Out.Light1 = mul(worldToTangent, -Light1);
I replaced the light with sun, and instead of subtracting the two points, i simply input -vecSunDir (see above)...
Yes, P - vecLightPos will calculate a direction vector from the light to the vertex. Since with sunlight, the direction is always the same, you can just use the sun dir.
The tangent is a vector pointing in the u direction of the texture. The binormal is a vector perpendicular to the tangent and normal. Together, these form an axis system called tangent space or texture space. The normals in the normalmap are relative to the texture, so to have meaningfull comparisons we must transform the other vectors (light, view, etc) to tangent space aswell for normalmapping.
I found a good picture showing the tangent, binormal and normal here.
|
|
|
Re: Normalmapping on terrain
[Re: Excessus]
#122335
04/10/07 03:24
04/10/07 03:24
|
Joined: Mar 2006
Posts: 2,503 SC, United States
xXxGuitar511
Expert
|
Expert
Joined: Mar 2006
Posts: 2,503
SC, United States
|
Yeah, I get very different results when using vecSunDir, and vecSunPos
vecSunDir looks smooth, but still, somethings not right.
vecSunPos results in a much brighter result in a much higher contrast due to normalization, and gives bad results.
xXxGuitar511 - Programmer
|
|
|
|