Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 01:28
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (7th_zorro), 793 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 5 1 2 3 4 5
Normalmapping on terrain #122316
04/08/07 14:16
04/08/07 14:16
Joined: Jan 2004
Posts: 2,013
The Netherlands
E
Excessus Offline OP
Expert
Excessus  Offline OP
Expert
E

Joined: Jan 2004
Posts: 2,013
The Netherlands
I'd like to have normalmapping on terrain. Has anyone got experience with this? It seems the tangents are not correct/cannot be used with terrains. The manual says:
Quote:

Tangent
Calculates the u tangents for the 3rd texture coordinate set (TEXCOORD2). This way tangents can be used for model or level geometry shaders. The binormal vector (v tangent) can be calculated by the vertex shader from the cross product of the vertex normal and the u tangent. On animated models the tangents have to be recalculated every frame, affecting the frame rate, so don't use this flag unnecessarily.




Does anyone know if it is possible to use normalmapping for terrains anyway?

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 Offline
Expert
xXxGuitar511  Offline
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?

What do you say?
single choice
Votes accepted starting: 04/08/07 21:48
You must vote before you can view the results of this poll.

xXxGuitar511
- Programmer
Re: Normalmapping on terrain [Re: xXxGuitar511] #122318
04/08/07 23:48
04/08/07 23:48
Joined: Oct 2005
Posts: 4,771
Bay City, MI
lostclimate Offline
Expert
lostclimate  Offline
Expert

Joined: Oct 2005
Posts: 4,771
Bay City, MI
i voted for both because i could see that if you had a medium machine, you wouldnt want to use all 8 textures that'd be required for a tiled version of it, but if you do have the computing power the developer should be able to choose to use it.

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 Offline
Senior Expert
PHeMoX  Offline
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


PHeMoX, Innervision Software (c) 1995-2008

For more info visit: Innervision Software
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 Offline
Expert
xXxGuitar511  Offline
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 Offline
Expert
xXxGuitar511  Offline
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
E
Excessus Offline OP
Expert
Excessus  Offline OP
Expert
E

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 Offline
Expert
xXxGuitar511  Offline
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 Offline
Expert
xXxGuitar511  Offline
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
E
Excessus Offline OP
Expert
Excessus  Offline OP
Expert
E

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.
Page 1 of 5 1 2 3 4 5

Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1