0 registered members (),
1,397
guests, and 7
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Searching HLSL Terrain Multitexturing...
[Re: Espér]
#322916
05/10/10 14:33
05/10/10 14:33
|
Joined: Apr 2010
Posts: 172
wdlmaster
Member
|
Member
Joined: Apr 2010
Posts: 172
|
Try this one:
float4x4 matWorld;
float4x4 matWorldViewProj;
float4 vecSunDir;
float4 vecAmbient;
float4 vecSunColor;
float2 tiles = {50,50};
texture entSkin1;
texture dmap1_bmap;
texture dmap2_bmap;
texture dmap3_bmap;
texture dmap4_bmap;
texture dmap5_bmap;
sampler2D blend = sampler_state { Texture = <entSkin1>;mipfilter=2;minfilter=2;magfilter=2;};
sampler2D skin1 = sampler_state { Texture = <dmap1_bmap>;mipfilter=2;minfilter=2;magfilter=2;};
sampler2D skin2 = sampler_state { Texture = <dmap2_bmap>;mipfilter=2;minfilter=2;magfilter=2;};
sampler2D skin3 = sampler_state { Texture = <dmap3_bmap>;mipfilter=2;minfilter=2;magfilter=2;};
sampler2D skin4 = sampler_state { Texture = <dmap4_bmap>;mipfilter=2;minfilter=2;magfilter=2;};
sampler2D skin5 = sampler_state { Texture = <dmap5_bmap>;mipfilter=2;minfilter=2;magfilter=2;};
void VS ( in float4 iPos : POSITION,
in float3 iNorm : NORMAL,
in float4 iTex : TEXCOORD0,
out float4 oPos : POSITION,
out float3 oNorm : TEXCOORD1,
out float4 oTex : TEXCOORD0)
{
oPos = mul (iPos,matWorldViewProj);
oNorm = mul(iNorm,matWorld);
oTex = iTex;
}
float4 PS( in float2 tex : TEXCOORD0,
in float3 iNorm : TEXCOORD1) : COLOR {
float4 map = tex2D(blend,tex);
float4 color = tex2D(skin1,tiles * tex);
color = lerp(color,tex2D(skin2,tiles * tex),map.r);
color = lerp(color,tex2D(skin3,tiles * tex),map.g);
color = lerp(color,tex2D(skin4,tiles * tex),map.b);
color = lerp(color,tex2D(skin5,tiles * tex),map.a);
color *= vecSunColor * saturate(dot(-vecSunDir, normalize(iNorm))) + vecAmbient;
return color;}
technique t{ pass p{ AlphaBlendEnable = 0;
zWriteEnable = 1;
VertexShader = compile vs_2_0 VS();
PixelShader = compile ps_2_0 PS();
}}
You have to define 5 BMAPs named dmap1...dmap5. The first skin of the terrain / model ist the blendmap. dmap1 is the basecolor, dmap2,3,4 are RGB and dmap5 is Alpha. This shader only supports the sun. But adding more lights is no problem (if you need them). You can add as many textures as the shader model supports (in a single pass). This is done by "splitting" the RGBA channels. You can use for example 4 textures per channel (would be 17 textures in one pass!) But there are restrictions (of course). You can't blend straight between all textures! If you use such a 17-texture-shader, i recommend to use the 4 textures per channel only as texture variations and not as completely different textures. I hope you understand what i mean... The same can be done by using more blendmaps.
|
|
|
Re: Searching HLSL Terrain Multitexturing...
[Re: Espér]
#322927
05/10/10 15:49
05/10/10 15:49
|
Joined: Apr 2010
Posts: 172
wdlmaster
Member
|
Member
Joined: Apr 2010
Posts: 172
|
yes, but the blendmap method is waaaayyyy more flexible.
float4x4 matWorld;
float4x4 matWorldViewProj;
float4 vecSunDir;
float4 vecAmbient;
float4 vecSunColor;
float2 tiles = {50,50};
texture dmap1_bmap;
texture dmap2_bmap;
texture dmap3_bmap;
texture dmap4_bmap;
texture dmap5_bmap;
sampler2D skin1 = sampler_state { Texture = <dmap1_bmap>;mipfilter=2;minfilter=2;magfilter=2;};
sampler2D skin2 = sampler_state { Texture = <dmap2_bmap>;mipfilter=2;minfilter=2;magfilter=2;};
sampler2D skin3 = sampler_state { Texture = <dmap3_bmap>;mipfilter=2;minfilter=2;magfilter=2;};
sampler2D skin4 = sampler_state { Texture = <dmap4_bmap>;mipfilter=2;minfilter=2;magfilter=2;};
sampler2D skin5 = sampler_state { Texture = <dmap5_bmap>;mipfilter=2;minfilter=2;magfilter=2;};
void VS ( in float4 iPos : POSITION,
in float3 iNorm : NORMAL,
in float4 iTex : TEXCOORD0,
out float4 oPos : POSITION,
out float3 oNorm : TEXCOORD1,
out float4 oTex : TEXCOORD0,
out float y : TEXCOORD2)
{
oPos = mul (iPos,matWorldViewProj);
oNorm = mul(iNorm,matWorld);
oTex = iTex;
y = mul(iPos,matWorld).y;
}
float4 PS( in float2 tex : TEXCOORD0,
in float3 normal : TEXCOORD1,
in float y : TEXCOORD2) : COLOR {
float4 color = tex2D(skin1,tiles * tex);
color = lerp(color,tex2D(skin2,tiles * tex),saturate((1500-y) / 100));
color = lerp(color,tex2D(skin3,tiles * tex),saturate((1000-y) / 100));
color = lerp(color,tex2D(skin4,tiles * tex),saturate((500-y) / 100));
color = lerp(color,tex2D(skin5,tiles * tex),saturate(1-pow(normal.y,1)));
color *= vecSunColor * saturate(dot(-vecSunDir, normalize(normal))) + vecAmbient;
return color;}
technique t{ pass p{ AlphaBlendEnable = 0;
zWriteEnable = 1;
VertexShader = compile vs_2_0 VS();
PixelShader = compile ps_2_0 PS();
}}
you can (must) play around with the values in the pixelshader to fit your needs (example): color = lerp(color,tex2D(skin2,tiles * tex),saturate((1500-y) / 100)); the 1500 is the height in quants and the 100 is the smoothness. The last texture is blended according to the surface normal. I'm not sure if this is what you looking for, but it's worth a try. You could also combine both techniques. (blendmap + height-dependend)
|
|
|
Re: Searching HLSL Terrain Multitexturing...
[Re: wdlmaster]
#322928
05/10/10 16:04
05/10/10 16:04
|
Joined: Mar 2008
Posts: 2,247 Baden Württemberg, Germany
Espér
OP
Expert
|
OP
Expert
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
|
ok.. du you have an example for the blendmap (or an example model with the skins)? ( have no idea what such a thing should look like...)
Last edited by Espér; 05/10/10 16:11.
|
|
|
Re: Searching HLSL Terrain Multitexturing...
[Re: Espér]
#322932
05/10/10 16:20
05/10/10 16:20
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
Thats an easy one. Imagine a plateau with a mountain in the center of it. Leave the blendmap black except for the center area, there you paint it red. Now define the base texture as a grass area and set the first map to a rocky one. The center area now gets the rock texture, the surrounding gets the grass texture.
Always learn from history, to be sure you make the same mistakes again...
|
|
|
|