There is a different shader, I'm looking at his demo with the terrain, water, reflecting sunlight, trees etc - and there's no reference to terrainvec in the shaders. It appears to take everything it needs from the UV coordinates.
Here is the shader I'm looking at for detail:
//====================================================
// Terrain Detail Map
// By EVOLVED
//====================================================
//--------------
// un-tweaks
//--------------
matrix WorldVP:WorldViewProjection;
matrix World:World;
matrix Worldit:WorldInverseTranspose;
matrix ViewInv:ViewInverse;
matrix ProjMatrix;
float time:Time;
//--------------
// tweaks
//--------------
float LightIntensity;
float4 FogColor;
float FogRange;
float4 WaterFogColor;
float WaterFogRange;
float WaterHeight;
float3 CausticSpeed;
float2 CausticScale;
float3 CausticColor;
//--------------
// Textures
//--------------
texture WorldLightTX <string Name="";>;
sampler WorldLight=sampler_state
{
Texture=<WorldLightTX>;
ADDRESSU = CLAMP;
ADDRESSV = CLAMP;
ADDRESSW = CLAMP;
};
texture CausticMapTX <string Name="";>;
sampler CausticMap = sampler_state
{
texture = <CausticMapTX>;
};
texture BlendTX <string Name="";>;
sampler Blend = sampler_state
{
texture = <BlendTX>;
};
texture Detail1TX <string Name="";>;
sampler Detail1 = sampler_state
{
texture = <Detail1TX>;
};
texture Detail2TX <string Name="";>;
sampler Detail2 = sampler_state
{
texture = <Detail2TX>;
};
texture Detail3TX <string Name="";>;
sampler Detail3 = sampler_state
{
texture = <Detail3TX>;
};
texture Detail4TX <string Name="";>;
sampler Detail4 = sampler_state
{
texture = <Detail4TX>;
};
//--------------
// structs
//--------------
struct In_Diffuse
{
float4 Pos:POSITION;
float2 UV0:TEXCOORD0;
float2 UV1:TEXCOORD1;
};
struct Out_Diffuse
{
float4 OPos:POSITION;
float2 Tex1:TEXCOORD0;
float2 Tex2:TEXCOORD1;
float4 Proj:TEXCOORD2;
float Fog:FOG;
};
struct In_Water
{
float4 Pos:POSITION;
float2 UV0:TEXCOORD0;
float2 UV1:TEXCOORD1;
};
struct Out_Water
{
float4 OPos:POSITION;
float2 Tex1:TEXCOORD0;
float2 Tex2:TEXCOORD1;
float4 Proj:TEXCOORD2;
float3 CausticTex:TEXCOORD3;
float Fog:FOG;
};
//--------------
// vertex shader
//--------------
Out_Diffuse VS_Diffuse(In_Diffuse IN)
{
Out_Diffuse OUT;
OUT.OPos=mul(IN.Pos,WorldVP);
OUT.Tex1=IN.UV0;
OUT.Tex2=IN.UV1;
float4 Proj=mul(IN.Pos,mul(World,ProjMatrix));
OUT.Proj=float4(Proj.x*0.5+0.5*Proj.w,0.5*Proj.w-Proj.y*0.5,Proj.w,Proj.w)+float4(0.01,0.01,0,0);
float3 WPos=mul(IN.Pos,World);
float3 ViewPos=ViewInv[3].xyz-WPos.xyz;
OUT.Fog=1-length(ViewPos/FogRange);
return OUT;
}
Out_Water VS_Water(In_Water IN)
{
Out_Water OUT;
OUT.OPos=mul(IN.Pos,WorldVP);
OUT.Tex1=IN.UV0;
OUT.Tex2=IN.UV1;
float4 Proj=mul(IN.Pos,mul(World,ProjMatrix));
OUT.Proj=float4(Proj.x*0.5+0.5*Proj.w,0.5*Proj.w-Proj.y*0.5,Proj.w,Proj.w)+float4(0.01,0.01,0,0);
float3 WPos=mul(IN.Pos,World);
float3 ViewPos=ViewInv[3].xyz-WPos.xyz;
OUT.CausticTex=float3(float2(WPos.x,WPos.z)*CausticScale+(time*CausticSpeed.xy),time*CausticSpeed.z);
OUT.Fog=(WPos.y/WaterHeight)*(1-length(ViewPos/WaterFogRange));
return OUT;
}
//--------------
// pixel shader
//--------------
float4 PS_Diffuse(Out_Diffuse IN) : COLOR
{
float4 Blend=tex2D(Blend,IN.Tex1);
float3 Detailmap=tex2D(Detail1,IN.Tex2)*Blend.x;
Detailmap=Detailmap+tex2D(Detail2,IN.Tex2)*Blend.y;
Detailmap=Detailmap+tex2D(Detail3,IN.Tex2)*Blend.z;
Detailmap=Detailmap+tex2D(Detail4,IN.Tex2)*Blend.w;
return float4(Detailmap*(tex2Dproj(WorldLight,IN.Proj)*LightIntensity),1);
}
float4 PS_Water(Out_Water IN) : COLOR
{
float4 Blend=tex2D(Blend,IN.Tex1);
float3 Detailmap=tex2D(Detail1,IN.Tex2)*Blend.x;
Detailmap=Detailmap+tex2D(Detail2,IN.Tex2)*Blend.y;
Detailmap=Detailmap+tex2D(Detail3,IN.Tex2)*Blend.z;
Detailmap=Detailmap+tex2D(Detail4,IN.Tex2)*Blend.w;
float3 Caustics=tex3D(CausticMap,IN.CausticTex)*CausticColor;
return float4(((Detailmap+Caustics)*(tex2Dproj(WorldLight,IN.Proj)*LightIntensity)),1);
}
//--------------
// techniques
//--------------
technique Diffuse
{
pass p1
{
vertexShader = compile vs_2_0 VS_Diffuse();
pixelShader = compile ps_2_0 PS_Diffuse();
FOGCOLOR=(FogColor);
FOGENABLE=TRUE;
}
}
technique Water
{
pass p1
{
vertexShader = compile vs_2_0 VS_Water();
pixelShader = compile ps_2_0 PS_Water();
FOGCOLOR=(WaterFogColor);
FOGENABLE=TRUE;
}
}
And normals version:
//====================================================
// Terrain Normals
// By EVOLVED
//====================================================
//--------------
// un-tweaks
//--------------
matrix WorldVP:WorldViewProjection;
matrix World:World;
matrix Worldit:WorldInverseTranspose;
matrix ViewInv:ViewInverse;
//--------------
// tweaks
//--------------
float ShadowBias=0.018f;
float3 LightPosition;
float LightRange;
float3 CamPos1;float Radius1;
float3 CamPos2;float Radius2;
float3 CamPos3;float Radius3;
//--------------
// Textures
//--------------
texture WorldLightTX <string Name="";>;
sampler WorldLight=sampler_state
{
Texture=<WorldLightTX>;
ADDRESSU = CLAMP;
ADDRESSV = CLAMP;
ADDRESSW = CLAMP;
};
texture CausticMapTX <string Name="";>;
sampler CausticMap = sampler_state
{
texture = <CausticMapTX>;
};
texture BlendTX <string Name="";>;
sampler Blend = sampler_state
{
texture = <BlendTX>;
};
texture Normal1TX <string Name="";>;
sampler Normal1 = sampler_state
{
texture = <Normal1TX>;
};
texture Normal2TX <string Name="";>;
sampler Normal2 = sampler_state
{
texture = <Normal2TX>;
};
texture Normal3TX <string Name="";>;
sampler Normal3 = sampler_state
{
texture = <Normal3TX>;
};
texture Normal4TX <string Name="";>;
sampler Normal4 = sampler_state
{
texture = <Normal3TX>;
};
//--------------
// structs
//--------------
struct In_WorldPos
{
float4 Pos:POSITION;
};
struct Out_WorldPos
{
float4 OPos:POSITION;
float3 Wpos:TEXCOORD0;
};
struct In_WorldNormals
{
float4 Pos:POSITION;
float2 UV0:TEXCOORD0;
float2 UV1:TEXCOORD1;
float3 Normal:NORMAL;
float3 Tangent:TANGENT;
float3 Binormal:BINORMAL;
};
struct Out_WorldNormals
{
float4 OPos:POSITION;
float2 Tex1:TEXCOORD0;
float2 Tex2:TEXCOORD1;
float3 tbnRow1:TEXCOORD2;
float3 tbnRow2:TEXCOORD3;
float3 tbnRow3:TEXCOORD4;
};
struct In_PointDepth
{
float4 Pos:POSITION;
};
struct Out_PointDepth
{
float4 OPos:POSITION;
float3 Depth:TEXCOORD0;
};
struct In_SpotDepth
{
float4 Pos:POSITION;
};
struct Out_SpotDepth
{
float4 OPos:POSITION;
float Depth:TEXCOORD0;
};
struct In_DirDepth
{
float4 Pos:POSITION;
};
struct Out_DirDepth
{
float4 OPos:POSITION;
float Depth:TEXCOORD0;
};
//--------------
// vertex shader
//--------------
Out_WorldPos VS_WorldPos(In_WorldPos IN)
{
Out_WorldPos OUT;
OUT.OPos=mul(IN.Pos,WorldVP);
OUT.Wpos=mul(IN.Pos,World)-ViewInv[3].xyz;
return OUT;
}
Out_WorldNormals VS_WorldNormals(In_WorldNormals IN)
{
Out_WorldNormals OUT;
OUT.OPos=mul(IN.Pos,WorldVP);
OUT.Tex1=IN.UV0;
OUT.Tex2=IN.UV1;
float3x3 TBN={IN.Tangent,IN.Binormal,IN.Normal};
TBN=mul(TBN,Worldit);
OUT.tbnRow1=TBN[0];
OUT.tbnRow2=TBN[1];
OUT.tbnRow3=TBN[2];
return OUT;
}
Out_PointDepth VS_PointDepth(In_PointDepth IN)
{
Out_PointDepth OUT;
OUT.OPos = mul(IN.Pos,WorldVP);
float3 WPos=mul(IN.Pos,World);
float3 LightPos=LightPosition-WPos;
OUT.Depth=LightPos/LightRange;
return OUT;
}
Out_SpotDepth VS_SpotDepth(In_SpotDepth IN)
{
Out_SpotDepth OUT;
OUT.OPos=mul(IN.Pos,WorldVP);
OUT.Depth=mul(IN.Pos,WorldVP).z/LightRange;
return OUT;
}
Out_DirDepth VS_DirRDepth(In_DirDepth IN)
{
Out_DirDepth OUT;
OUT.OPos=mul(IN.Pos,WorldVP);
float3 WPos=mul(IN.Pos,World);
OUT.Depth=dot(WPos-CamPos1,LightPosition)/(Radius1*2.5f);
return OUT;
}
Out_DirDepth VS_DirGDepth(In_DirDepth IN)
{
Out_DirDepth OUT;
OUT.OPos=mul(IN.Pos,WorldVP);
float3 WPos=mul(IN.Pos,World);
OUT.Depth=dot(WPos-CamPos2,LightPosition)/(Radius2*2.5f);
return OUT;
}
Out_DirDepth VS_DirBDepth(In_DirDepth IN)
{
Out_DirDepth OUT;
OUT.OPos=mul(IN.Pos,WorldVP);
float3 WPos=mul(IN.Pos,World);
OUT.Depth=dot(WPos-CamPos3,LightPosition)/(Radius3*2.5f);
return OUT;
}
//--------------
// pixel shader
//--------------
float4 PS_WorldPos(Out_WorldPos IN) : COLOR
{
return float4(IN.Wpos,1);
}
float4 PS_WorldNormals(Out_WorldNormals IN) : COLOR
{
float4 Blend=tex2D(Blend,IN.Tex1);
float3 Normalmap=(tex2D(Normal1,IN.Tex2)*Blend.x);
Normalmap=Normalmap+(tex2D(Normal2,IN.Tex2)*Blend.y);
Normalmap=Normalmap+(tex2D(Normal3,IN.Tex2)*Blend.z);
Normalmap=Normalmap+(tex2D(Normal4,IN.Tex2)*Blend.w);
return float4(0.5f+mul(Normalmap*2-1,float3x3(IN.tbnRow1,IN.tbnRow2,IN.tbnRow3))*0.5f,0.5f);
}
float4 PS_PointDepth(Out_PointDepth IN) : COLOR
{
return float4(length(IN.Depth)+ShadowBias,0,0,1);
}
float4 PS_SpotDepth(Out_SpotDepth IN) : COLOR
{
return float4(IN.Depth+ShadowBias,0,0,1);
}
float4 PS_DirRDepth(Out_DirDepth IN) : COLOR
{
return float4(IN.Depth+ShadowBias,0,0,1);
}
float4 PS_DirGDepth(Out_DirDepth IN) : COLOR
{
return float4(0,IN.Depth+(ShadowBias/1.5f),0,1);
}
float4 PS_DirBDepth(Out_DirDepth IN) : COLOR
{
return float4(0,0,IN.Depth+(ShadowBias/2.0f),1);
}
//--------------
// techniques
//--------------
technique WorldPos
{
pass p1
{
vertexShader = compile vs_2_0 VS_WorldPos();
pixelShader = compile ps_2_0 PS_WorldPos();
}
}
technique WorldNormals
{
pass p1
{
vertexShader = compile vs_2_0 VS_WorldNormals();
pixelShader = compile ps_2_0 PS_WorldNormals();
}
}
technique PointDepthMap
{
pass p1
{
VertexShader = compile vs_2_0 VS_PointDepth();
PixelShader = compile ps_2_0 PS_PointDepth();
}
}
technique SpotDepthMap
{
pass p1
{
VertexShader = compile vs_2_0 VS_SpotDepth();
PixelShader = compile ps_2_0 PS_SpotDepth();
}
}
technique DirRDepthMap
{
pass p1
{
VertexShader = compile vs_2_0 VS_DirRDepth();
PixelShader = compile ps_2_0 PS_DirRDepth();
ColorWriteEnable = red;
}
}
technique DirGDepthMap
{
pass p1
{
VertexShader = compile vs_2_0 VS_DirGDepth();
PixelShader = compile ps_2_0 PS_DirGDepth();
ColorWriteEnable = green;
}
}
technique DirBDepthMap
{
pass p1
{
VertexShader = compile vs_2_0 VS_DirBDepth();
PixelShader = compile ps_2_0 PS_DirBDepth();
ColorWriteEnable = Blue;
}
}
The water in the demo I'm looking at looks similar, but with the sun reflecting down, I think it's been improved since then.
Anyhoo, I think that you need to resort to vertex data, to work out the actual size of the terrain and assign UV coords to it yourself. I have code to load a heightmap and make a limbed terrain object from it, works fine with my shader so it should be fine for Evolveds - plus you have to remember that the whole AT terrain gets converted to a mesh, so looses any culling benefit anyway. I'll see if I can take Evolveds shader and apply it to the way I make terrains, it might involve a scaling though as I tend to make my terrain tiles 100x100 units. Anyhoo I'll let you know if I can get it working.