Quote: "I've not attached any media, but I'm hoping people will be able to figure out what I mean"
You could try this:
` Green Gandalf's Terrain Texture Blender v2.1
` Created 12 October 2006, modified 26 October 2010.
` Edited to work with Advanced Terrain objects.
sync on: sync rate 60: sync
global cx#
global cy#
autocam off
position camera 0,100,0
point camera 140, 0, 140
cx# = camera angle x()
cy# = camera angle y()
load image "Media/grass.png", 1
load image "Media/gravel.png", 2
load image "Media/rock.png", 3
load image "Media/rgb.png", 4
`load image "Media/rgbBlurred.png", 4
xscale#=1 : yscale#=0.2 : zscale#=1
make object terrain 1 ` create the terrain object
set terrain heightmap 1, "Media/hMap.png" ` set the heightmap
set terrain scale 1, xscale#, yscale#, zscale# ` set the scale
set terrain split 1, 16 ` split value by 16 * 16
set terrain tiling 1, 4 ` detail map tiling
build terrain 1 ` finally build the terrain
` fiddle with the terrain's format - remove the diffuse colour - this causes problems with shaders
convert object fvf 1, 0x002 + 0x100 ` i.e. XYZ data + 1 UV stage
` the following should work as well if you need normals or more UV data
` but you will need to calculate the extra UV data or normals in your code (if you use them)
`convert object fvf 1, 0x002 + 0x010 + 0x200 ` i.e. XYZ data + NORMAL + 2 UV stages
`convert object fvf 1, 0x002 + 0x010 + 0x100 ` i.e. XYZ data + 1 UV stage
`convert object fvf 1, 0x002 + 0x010 + 0x200 ` i.e. XYZ data + NORMAL + 2 UV stage
CreateUVData(1)
texture object 1, 0, 1
texture object 1, 1, 2
texture object 1, 2, 3
texture object 1, 3, 4
texture object 1, 4, 5
load effect "Media/terrainFXv2.fx",1,0
set object effect 1,1
repeat
text 20, 20, str$(screen fps())
if inkey$() = "w"
set object wireframe 1, 1
else
set object wireframe 1, 0
endif
positionCamera()
sync
until spacekey()
end
function positionCamera()
control camera using arrowkeys 0,1,0
cx#=cx#+mousemovey():cy#=cy#+mousemovex()
rotate camera cx#,cy#,0
endfunction
Function CreateUVData(obj)
perform checklist for object limbs obj
nLimbs = checklist quantity() - 1
for L = 0 to nLimbs
lock vertexdata for limb obj,L
vmax=get vertexdata vertex count() - 1
for v=0 to vmax
x#=get vertexdata position x(v)
z#=get vertexdata position z(v)
u#=x#/object size x(obj, 1)
v#=1.0 - z#/object size z(obj, 1) ` N.B.
Set Vertexdata UV v,0,u#,v#
next v
unlock vertexdata
next L
endfunction
with this:
// Green Gandalf's Terrain Shader v2.0
// blends three images together using a fourth texture
// to give a detailed terrain
// Created 12 October 2006, modified 18 January 2007.
float4x4 wvp : WorldViewProjection;
float2 repeatScale = {4.0, 4.0};
texture detailMap1 <string ResourceName = "";>;
sampler2D detailSample1 = sampler_state
{texture = (detailMap1);
minfilter = linear;
magfilter = linear;
mipfilter = linear;
addressU = wrap;
addressV = wrap;
};
texture detailMap2 <string ResourceName = "";>;
sampler2D detailSample2 = sampler_state
{texture = (detailMap2);
minfilter = linear;
magfilter = linear;
mipfilter = linear;
addressU = wrap;
addressV = wrap;
};
texture detailMap3 <string ResourceName = "";>;
sampler2D detailSample3 = sampler_state
{texture = (detailMap3);
minfilter = linear;
magfilter = linear;
mipfilter = linear;
addressU = wrap;
addressV = wrap;
};
texture rgbMap <string ResourceName = "";>;
sampler2D rgbSample = sampler_state
{texture = (rgbMap);
minfilter = linear;
magfilter = linear;
mipfilter = linear;
addressU = wrap;
addressV = wrap;
};
struct VS_Input
{ float4 pos : position;
float4 UV : texcoord0;
};
struct VS_Output
{ float4 pos : position;
float4 UV : texcoord0;
};
struct PS_Input
{ float4 UV : texcoord0;
};
struct PS_Output { float4 colour : color; };
VS_Output V_Shader(VS_Input In, VS_Output Out)
{ Out.pos = mul(In.pos,wvp);
Out.UV = In.UV;
return Out;
};
PS_Output P_Shader(PS_Input In, PS_Output Out)
{ float4 rgbColours = tex2D(rgbSample, In.UV);
float4 baseColour = tex2D(detailSample1, repeatScale * In.UV) * rgbColours.r;
baseColour += tex2D(detailSample2, repeatScale * In.UV) *rgbColours.g;
baseColour += tex2D(detailSample3, repeatScale * In.UV) * rgbColours.b;
Out.colour = baseColour;
return Out;
};
technique terrainBlendv2
{
pass p0
{ VertexShader = compile vs_1_1 V_Shader();
PixelShader = compile ps_2_0 P_Shader();
}
}
Sample screenshot: