Posted By: Loopix
Terrainmaking - 11/08/06 22:22
Hello
Nagashi pointed to a nice little terrain tool in the "Tools" forum called Earthsculptor. This tool creates highmaps, shadowmaps and rgb-blendmaps. It's quite easy to port the terrains to 3dgs and get them working with a multi-texture-terain shader. I 've tweaked one of my old and wanted to share it
in Earthsculptor
in 3dgs
the shader:
Code:
Nagashi pointed to a nice little terrain tool in the "Tools" forum called Earthsculptor. This tool creates highmaps, shadowmaps and rgb-blendmaps. It's quite easy to port the terrains to 3dgs and get them working with a multi-texture-terain shader. I 've tweaked one of my old and wanted to share it
in Earthsculptor
in 3dgs
the shader:
Code:
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//This is a multitexture-terrainshader that makes it easy to implement terrains made
//with "EarthSculptor, http://www.earthsculptor.com/" into 3dgs. It's able to blend 4 textures and
//on top of that a shadowmap.
//
//When painting with textures in "earthscuptor" the rgb-blendmap is created as follows:
//(from left to right) texture in slot1 creates red in the rgb-blendmap, slot2 = green, slot3 = blue, slot4 = black.
//After you saved your terrain, you will find the highmap, the blendmap and the shadowmap in the "Maps" folder in the directory where "earthsculptor" is installed.
//
//After converting all needed maps and texture files into a MED compatible format (bmp,pcx,tga), import the highmap into MED
//(File/Import/Import Terrain from Pic)and create a highmap with size according to your needs (I usualy make it around 100x100 vertices),
//then you will have to rescale the terrain in height to fit it as close as possible to the original in "earthsculptor".
//Then assign the rgb-blendmap as first and the shadowmap as second skin to your terrain (Edit/Manage Skins).
//
//Add the terrain to your level (Objec/Add Terrain)
//Include the shader.wdl into your main wdl script and assign the action "multi_rgb" to your terrain. You
//might want to adjust the tiling size of the textures by changing the values in the shader...see:
//"Out.Tex3 = inTexCoord0.xy*30; // tiling texture red...".
//
//
//This terrainshader is a reworked version of Thorsten Kunze 's terrainshader.
//2006 By www.loopix-project.com
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
// entSkin1 rgb-blendmap
// entSkin2 shadowmap
bmap tex3 = <rocks.bmp>; // Texture Layer Red
bmap tex4 = <grass.bmp>; // Texture Layer Green
bmap tex5 = <bark.bmp>; // Texture Layer Blue
bmap tex6 = <cliff.bmp>; // Texture Layer Black
function multirgb_roughness() {
bmap_to_mipmap(mtl.Skin1);
bmap_to_mipmap(mtl.Skin2);
bmap_to_mipmap(mtl.Skin3);
bmap_to_mipmap(mtl.Skin4);
}
material multirgb {
flags = tangent;
skin1 = tex3;
skin2 = tex4;
skin3 = tex5;
skin4 = tex6;
event=multirgb_roughness;
effect
"
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Define your needed values
float4x4 matWorldViewProj;
float4x4 matWorld;
float4x4 matWorldInv;
float4x4 matWorldView;
float4 vecFog;
// Define your textures
texture mtlSkin1;
texture mtlSkin2;
texture mtlSkin3;
texture mtlSkin4;
texture entSkin1;
texture entSkin2;
//////////////////////////////////////////////////////////////////////////////////////////////////////
// Texture settings
sampler sTex1 = sampler_state
{
Texture = <entSkin1>; // rgb-blendmap
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
sampler sTex2 = sampler_state
{
Texture = <entSkin2>; // shadowmap
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
sampler sTex3 = sampler_state
{
Texture = <mtlSkin1>; // red
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
sampler sTex4 = sampler_state
{
Texture = <mtlSkin2>; // green
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
sampler sTex5 = sampler_state
{
Texture = <mtlSkin3>; // blue
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
sampler sTex6 = sampler_state
{
Texture = <mtlSkin4>; // black
MipFilter = Linear;
MinFilter = Linear;
MagFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};
struct TMULTI_VS_OUT // Output to the pixelshader fragment
{
float4 Pos : POSITION;
float Fog : FOG;
float2 Tex1 : TEXCOORD0;
float2 Tex2 : TEXCOORD1;
float2 Tex3 : TEXCOORD2;
float2 Tex4 : TEXCOORD3;
float2 Tex5 : TEXCOORD4;
float2 Tex6 : TEXCOORD5;
};
float DoFog(float4 Pos) {
float3 P = mul(Pos,matWorldView);// apply the linear fog formula
return saturate((vecFog.y-P.z) * vecFog.z);
}
TMULTI_VS_OUT TMulti_VS(
float4 inPos : POSITION,
float3 inNormal : NORMAL,
float2 inTexCoord0 : TEXCOORD0)
{
TMULTI_VS_OUT Out;
// transform the vector position to screen coordinates
Out.Pos = mul(inPos,matWorldViewProj);
// rotate and normalize the normal
float3 N = normalize(mul(inNormal,matWorldInv));
Out.Fog = DoFog(inPos);
// scale the texture coordinates for the masked textures
Out.Tex1 = inTexCoord0.xy; // rgb-blendmap (not tiled)
Out.Tex2 = inTexCoord0.xy; // shadowmap (not tiled)
Out.Tex3 = inTexCoord0.xy*30; // tiling texture red
Out.Tex4 = inTexCoord0.xy*10; // tiling texture green
Out.Tex5 = inTexCoord0.xy*10; // tiling texture blue
Out.Tex6 = inTexCoord0.xy*30; // tiling texture black
return Out;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
// pixelshader
float4 ps( TMULTI_VS_OUT In ) : COLOR
{
float4 BlendColor = tex2D(sTex1,In.Tex1);
float4 ShadowMap = tex2D(sTex2,In.Tex2);
float4 RedColor = tex2D(sTex3,In.Tex3);
float4 GreenColor = tex2D(sTex4,In.Tex4);
float4 BlueColor = tex2D(sTex5,In.Tex5);
float4 BlackColor = tex2D(sTex6,In.Tex6);
float4 BaseRed = lerp(BlackColor,RedColor,BlendColor.r);
float4 BaseGreen = lerp(BaseRed,GreenColor,BlendColor.g);
float4 FinalColor = lerp(BaseGreen,BlueColor,BlendColor.b);
FinalColor = FinalColor*ShadowMap; // maybe you will want to have it brighter ...*(ShadowMap+0.2)
FinalColor.a = 1.0f; // prevent transparency
return FinalColor;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
//
technique mytechnique
{
// Define your passes
pass p0
{
VertexShader = compile vs_2_0 TMulti_VS();
PixelShader = compile ps_2_0 ps();
}
}
";
}
ACTION multi_rgb {
my.material=multirgb;
}