I FINALLY finished the
shader, which blends three terrain textures (the grass layer uses vertex fur) based on a blend map. Once I use this shader in combination with my cliff terrain system, each height layer should be able to support three different tiles along with blurring.
The Warcraft III-esque cliff-based terrain system will use this shader for each height layer.
Quote: "Disabling the DarkLights stuff did the trick, I have dark shader, but I'm sure I've seen this problem with DarkLights before when trying to lightmap an advanced terrain."
Odd. You shouldn't have to turn off Dark Lights...
Quote: "FPS 470 and when press '3' then fps jump 680 "
Wow.
EDIT: Now I've been working on the shader to combine the cubic lighting (or rather, I'm using a 2d projection shader instead) and the lightmap, in a way casting shadows from the lightmap onto dynamic 3d objects. I've hit a bit of a snag however, as the 2d shadow projection shader by EVOLVED that I edited ends up projecting a spherical image, in that the lightmap I project is fine at the center but the further you get from the center the more distorted the lightmap becomes. Running the spherize filter on it in photoshop is a temporary fix, but considering how the lightmap changes every hour or so, that seems to be an unlikely solution.
//====================================================
// Lightmap Shadow Projection
//====================================================
//--------------
// un-tweaks
//--------------
matrix WorldVP:WorldViewProjection;
matrix World:World;
matrix ViewInv:ViewInverse;
matrix ViewMat={0.5,0,0,0.5,0,-0.5,0,0.5,0,0,0.5,0.5,0,0,0,1};
matrix ProjMatrix;
//--------------
// Tweaks
//--------------
float4 FogColor = {0.375f, 0.5f, 0.75f, 1.0f};
float FogRange = 4096.0f;
//--------------
// Textures
//--------------
texture BaseTX
<
string Name="";
>;
sampler2D Base = sampler_state
{
texture = <BaseTX>;
};
texture ProjetTX
<
string Name="";
>;
sampler2D Projet = sampler_state
{
texture = <ProjetTX>;
ADDRESSU = CLAMP;
ADDRESSV = CLAMP;
ADDRESSW = CLAMP;
MagFilter = Linear;
MinFilter = Point;
MipFilter = None;
};
//--------------
// structs
//--------------
struct Input
{
float4 Pos:POSITION;
float2 UV:TEXCOORD;
};
struct Output
{
float4 OPos:POSITION;
float4 Wpos:TEXCOORD0;
float2 Tex:TEXCOORD1;
float4 Proj:TEXCOORD2;
float Fog:FOG;
};
//--------------
// vertex shaders
//--------------
Output VS(Input IN)
{
Output OUT;
OUT.OPos=mul(IN.Pos,WorldVP);
OUT.Wpos=mul(IN.Pos,World);
OUT.Tex=IN.UV;
float3 WPos=mul(IN.Pos,World);
float3 ViewPos=ViewInv[3].xyz-WPos;
float4 Proj = mul(OUT.Wpos,ProjMatrix);
OUT.Proj = mul(ViewMat,Proj);
OUT.Fog=1-saturate(dot(ViewPos/FogRange,ViewPos/FogRange));
return OUT;
}
//--------------
// pixel shaders
//--------------
float4 PS(Output IN) : COLOR
{
float4 Texture=tex2D(Base,IN.Tex);
float3 Projetlight=tex2Dproj(Projet,IN.Proj);
return float4(Texture*Projetlight,Texture.w);
}
//--------------
// techniques
//--------------
technique ShadowMapping
{
pass p1
{
vertexShader = compile vs_2_0 VS();
pixelShader = compile ps_2_0 PS();
FOGCOLOR=(FogColor);
FOGENABLE=TRUE;
}
}
Any help with this shader would be appreciated so I can finally finish the thread's technique. I believe the problem lies with the Proj matrix multiplication, but any changes I make to it really mess it up. If necessary, I can attach the media and source.
EDIT: Fur Terrain Blend Shader
//--------------------------------
// GRASS TERRAIN SHADER by Aki
//--------------------------------
//--------------------------------
// un-tweaks
//--------------------------------
matrix WorldVP:WorldViewProjection;
matrix World:World;
matrix ViewInv:ViewInverse;
//--------------------------------
// tweaks
//--------------------------------
float4 FogColor = {0.375f, 0.5f, 0.75f, 1.0f};
float FogRange = 4096.0f;
float FurHeight = 0.5;
float Mask = {1.0f};
//--------------------------------
// Textures
//--------------------------------
texture MaskTX
<
string Name="";
>;
sampler2D MaskMap = sampler_state
{
texture = <MaskTX>;
};
texture LightTX
<
string Name="";
>;
sampler2D LightMap = sampler_state
{
texture = <LightTX>;
};
texture GrassTX
<
string Name="";
>;
sampler2D GrassMap = sampler_state
{
texture = <GrassTX>;
};
texture DirtTX
<
string Name="";
>;
sampler2D DirtMap = sampler_state
{
texture = <DirtTX>;
};
texture RockTX
<
string Name="";
>;
sampler2D RockMap = sampler_state
{
texture = <RockTX>;
};
//--------------------------------
// structs
//--------------------------------
struct Input
{
float4 Pos:POSITION;
float2 UV:TEXCOORD0;
float2 UV1:TEXCOORD1;
float3 Normal:NORMAL;
};
struct Output
{
float4 OPos:POSITION;
float2 MaskM:TEXCOORD0;
float2 LightM:TEXCOORD1;
float2 TextureM:TEXCOORD2;
float Fog:FOG;
};
//--------------------------------
// vertex shader
//--------------------------------
Output VS(Input IN,uniform float Dir)
{
Output OUT;
float4 VPos;
VPos.xyz=IN.Pos+(IN.Normal*(Dir*FurHeight));VPos.w=IN.Pos.w;
OUT.OPos=mul(VPos,WorldVP);
OUT.MaskM=IN.UV;
OUT.LightM=IN.UV1;
OUT.TextureM=IN.UV*float2(32.0f,32.0f);
float3 Wnor=mul(IN.Normal,World);Wnor=normalize(Wnor);
float3 WPos=mul(IN.Pos,World);
float3 ViewPos=ViewInv[3].xyz-WPos;
OUT.Fog=1-saturate(dot(ViewPos/FogRange,ViewPos/FogRange));
return OUT;
}
//--------------------------------
// pixel shader
//--------------------------------
float4 PS(Output IN) : COLOR
{
float4 MaskColor=tex2D(MaskMap,IN.MaskM);
float3 LightColor=tex2D(LightMap,IN.LightM);
float3 Texture;
if (MaskColor.x==Mask) {
Texture=tex2D(DirtMap,IN.TextureM);
} else { if (MaskColor.y==Mask) {
Texture=tex2D(GrassMap,IN.TextureM);
} else { if (MaskColor.z==Mask) {
Texture=tex2D(RockMap,IN.TextureM);
} } }
return float4(LightColor*Texture,MaskColor.a*MaskColor.g);
}
float4 PSFirst(Output IN) : COLOR
{
float4 MaskColor=tex2D(MaskMap,IN.MaskM);
float3 LightColor=tex2D(LightMap,IN.LightM);
float3 Texture;
if (MaskColor.r==Mask) {
Texture=tex2D(DirtMap,IN.TextureM);
return float4(LightColor*Texture,MaskColor.a);
} else { if (MaskColor.y==Mask) {
Texture=tex2D(GrassMap,IN.TextureM);
return float4(LightColor*Texture,MaskColor.a);
} else { if (MaskColor.z==Mask) {
Texture=tex2D(RockMap,IN.TextureM);
return float4(LightColor*Texture,MaskColor.a);
} else { if (MaskColor.x==Mask && MaskColor.y==Mask) {
Texture=tex2D(
return float4(LightColor*Texture,MaskColor.a);
}}}}
}
//-----------------
// techniques
//-----------------
technique Grass
{
pass p0
{
vertexShader = compile vs_2_0 VS(0);
Sampler[0] = <GrassMap>;
ColorOp[0] = MODULATE;
ColorArg1[0] = TEXTURE;
SRCBLEND = SRCALPHA;
DESTBLEND = ZERO;
ALPHABLENDENABLE = TRUE;
BLENDOP = ADD;
pixelShader = compile ps_2_0 PSFirst();
FOGCOLOR=(FogColor);
FOGENABLE=TRUE;
}
pass p1
{
vertexShader = compile vs_2_0 VS(1);
Sampler[0] = <GrassMap>;
ColorOp[0] = MODULATE;
ColorArg1[0] = TEXTURE;
SRCBLEND = SRCALPHA;
DESTBLEND = ONE;
ALPHABLENDENABLE = TRUE;
BLENDOP = ADD;
pixelShader = compile ps_2_0 PS();
}
pass p2
{
vertexShader = compile vs_2_0 VS(2);
Sampler[0] = <GrassMap>;
ColorOp[0] = MODULATE;
ColorArg1[0] = TEXTURE;
pixelShader = compile ps_2_0 PS();
}
}