Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,449 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 4 of 5 1 2 3 4 5
Re: Normalmapping on terrain [Re: PHeMoX] #122346
04/10/07 21:43
04/10/07 21:43
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
Yep, I shouldn't have doubted the manual...

It works. I'll have to update the NM shader I posted, see if it makes any difference...


xXxGuitar511
- Programmer
Re: Normalmapping on terrain [Re: xXxGuitar511] #122347
04/11/07 04:45
04/11/07 04:45
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
Like I said before, I hate just posting alot of code, but here it is...

It's nowhere near finished, but it works...


WDL: MLTITerrain.wdl
Code:

/////////////////////////////////////////
// terrain Multi-Texture shader

string fxMLTITex = "MLTITex.fx";

function mtl_terrainmulti3_event();


MATERIAL mtl_terrainmulti3
{
event = mtl_terrainmulti3_event;
flags = tangent;
effect = fxMLTITex;
}

function mtl_terrainmulti3_event()
{
mtl.skin1 = bmap_for_entity(my, 5);
mtl.skin2 = bmap_for_entity(my, 6);
mtl.skin3 = bmap_for_entity(my, 7);
mtl.skin4 = bmap_for_entity(my, 8);
}


starter FXLoad
{
effect_load(mtl_terrainmulti3, fxMLTITex);
}



FX: MLTITex.fx
Code:

//
float4x4 matWorldViewProj;
float4x4 matWorldInv;
float4x4 matWorld;
float4 vecViewPos;
float4 vecFog;
float3 vecSunDir;
float3 vecSunPos;

Texture entSkin1; // mask texture
Texture entSkin2; // Red texture
Texture entSkin3; // Green texture
Texture entSkin4; // Blue texture
Texture mtlSkin1; // overlay normal
Texture mtlSkin2; // red normal
Texture mtlSkin3; // green noemal
Texture mtlSkin4; // blue normal

float4 vecSunDiffuse = {1.0f, 1.0f, 1.0f, 1.0f};


sampler mapMask = sampler_state
{
Texture = <entSkin1>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Wrap;
Addressv = Wrap;
};

sampler mapNormal = sampler_state
{
Texture = <mtlSkin1>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Wrap;
Addressv = Wrap;
};

sampler mapRC = sampler_state
{
Texture = <entSkin2>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Wrap;
Addressv = Wrap;
};

sampler mapGC = sampler_state
{
Texture = <entSkin3>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Wrap;
Addressv = Wrap;
};

sampler mapBC = sampler_state
{
Texture = <entSkin4>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Wrap;
Addressv = Wrap;
};

sampler mapRN = sampler_state
{
Texture = <mtlSkin2>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Wrap;
Addressv = Wrap;
};

sampler mapGN = sampler_state
{
Texture = <mtlSkin3>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Wrap;
Addressv = Wrap;
};

sampler mapBN = sampler_state
{
Texture = <mtlSkin4>;
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
AddressU = Wrap;
Addressv = Wrap;
};

//////////////////////////////////////////////////////////////////////

float DoFog(float3 WPos)
{
return(1 - (distance(WPos, vecViewPos) - vecFog.x) * (vecFog.z));
}

//////////////////////////////////////////////////////////////////////
struct TMULTI_VS_OUT
{
float4 Pos : POSITION;
float2 tCoord : TEXCOORD0;
float3 Sun : TEXCOORD1;
float3 View : TEXCOORD2;
float Fog : FOG;
};

struct TMULTI_PS_IN
{
float4 Pos : POSITION;
float2 tCoord : TEXCOORD0;
float3 Sun : TEXCOORD1;
float3 View : TEXCOORD2;
};


TMULTI_VS_OUT TMulti_VS(
float4 inPos : POSITION,
float3 inNormal : NORMAL,
float3 inTangent : TEXCOORD2,
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 = tex2D(mapNormal, In.tCoord);
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) - 1;
float4 GNormal = 2 * tex2D(mapGN, In.tCoord * 10) - 1;
float4 BNormal = 2 * tex2D(mapBN, In.tCoord * 10) - 1;

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 = 2*NormalColor.rgb - 1;
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);
float3 sunReflect = normalize(2 * sunDiff * outNormal - sunDir);
float4 sunSpec = pow(saturate(dot(sunReflect, ViewDir)), 15);

float4 sunOut = (sunDiff*outColor + (NormalColor.a)*sunSpec) * sunShadow * vecSunDiffuse;
sunOut.a = 1.0f;

return sunOut;
}


technique tmulti3
{
pass one
{
alphaBlendEnable = true;
VertexShader = compile vs_2_0 TMulti_VS();
PixelShader = compile ps_2_0 TMulti_PS();
}
}




xXxGuitar511
- Programmer
Re: Normalmapping on terrain [Re: xXxGuitar511] #122348
04/12/07 12:28
04/12/07 12:28
Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
Puppeteer Offline
Expert
Puppeteer  Offline
Expert

Joined: Jan 2007
Posts: 2,247
Deutsch Niedersachsen
Why does this xXxGuitar511 guy just has 3 stars?
I think 6 would be better


Formally known as Omega
Avatar randomness by Quadraxas & Blade
http://omegapuppeteer.mybrute.com
Re: Normalmapping on terrain [Re: Puppeteer] #122349
04/12/07 13:03
04/12/07 13:03
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
Quote:

alphaBlendEnable = true;




Why do you set this render state? Probabaly not a good idea here as it will disable correct z sorting.

instead you should set these render states:

alphablendenable = false;
zenable=true;
zwriteenable=true;


Sphere Engine--the premier A6 graphics plugin.
Re: Normalmapping on terrain [Re: Matt_Aufderheide] #122350
04/12/07 15:53
04/12/07 15:53
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
@derOmega: Thankz man

@Matt: Umm.. I didn't know you could do it that way, but now it's too late to edit my post... I was using the terrain with a complex-object-placement script I'm working on, and the ent's fade away as the get to a certain distance, so i thought I needed to enableAlphaBlend.


xXxGuitar511
- Programmer
Re: Normalmapping on terrain [Re: xXxGuitar511] #122351
04/12/07 19:48
04/12/07 19: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
NOTE:

Skin1: Color Mask (RGB)
Skin2: Red Diffuse
Skin3: Green Diffuse
Skin4: Blue Diffuse
Skin5: Overlay Normal
Skin6: Red Normal
Skin7: Green Normal
Skin8: Blue Normal


Alpha channel of normal maps is the specular channel.


xXxGuitar511
- Programmer
Re: Normalmapping on terrain [Re: xXxGuitar511] #122352
05/11/07 21:18
05/11/07 21:18
Joined: Sep 2006
Posts: 36
Ger
F
Fussfoehn Offline
Newbie
Fussfoehn  Offline
Newbie
F

Joined: Sep 2006
Posts: 36
Ger
This shader sounds nice, will there be a demo or could you explain me how these skins should look like and what each of them does? Just imagine how a desert terrain would look like, when every sandwave looks 3d...

Re: Normalmapping on terrain [Re: Fussfoehn] #122353
05/11/07 22:43
05/11/07 22:43
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
Look up normal mapping on wikipedia, or on forums, or anywhere else...


xXxGuitar511
- Programmer
Re: Normalmapping on terrain [Re: xXxGuitar511] #122354
05/12/07 12:08
05/12/07 12:08
Joined: Jul 2005
Posts: 421
Germany
DoC Offline
Senior Member
DoC  Offline
Senior Member

Joined: Jul 2005
Posts: 421
Germany
I had test this shader quite now and Im really happy with it, here a little Pic of my first test. I had play with the numbers of sunReflect,sunSpec and so on to reduce the reflection. Now I think its look more like a terrain and not like plastic ^^, thanks xXxGuitar511 thats realy a good help
a little Test

Re: Normalmapping on terrain [Re: DoC] #122355
05/12/07 12:11
05/12/07 12:11
Joined: Mar 2006
Posts: 2,503
SC, United States
xXxGuitar511 Offline
Expert
xXxGuitar511  Offline
Expert

Joined: Mar 2006
Posts: 2,503
SC, United States
Thats what the alpha-channel of your normal-map is for

- It's called Specular mapping. Everyone says this as well, and I try tellin' them


xXxGuitar511
- Programmer
Page 4 of 5 1 2 3 4 5

Moderated by  Blink, Hummel, Superku 

Gamestudio download | 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