Quote: "The present shader seems to have lost those. "
Yup, that was it! The shadowmap only affects pixels colored by the projection image; without that image, the shadows are cast repeatedly over the entire clamp. Just needed the push to get the cogs working again. Thanks GG.
So I've gone a little further with this concept but I've run into trouble again and I'm concerned my problem is something I haven't learned about yet - so I don't know what to google.
The attached image shows what I'm trying to achieve. The floor and the teapot use Evolved's original shadowmapping shader, so forget them for now. BUT above the floor is a plane/box using a modified verson of that shader which only displays the "projection" and sends everything else (shadows) to alpha. Thus combined, the teapot casts two shadows and the two projection images multiply together. So far so good...
My problem is the
shadowmap used by the transparent plane appears to delay its image-update when the position of the
projection-camera is moved; as if it takes a few frames before the image updates. Does that make sense? Should I post the whole demo?
The dbpro code layout is almost unchanged from Evolved's original demo except that the transparent plane uses the "set image transparency 2" setting.
And there's an extra camera - but the problem began before I started using 3 cameras, so that's not it. I'm pretty sure the problem is somewhere between the "transparency" setting in dbpro and the updated code in the shader.
Plus, you know, my first true experience with shader-alpha. Here is the modified shader so far:
//======================================================
// Shadow Mapping
//======================================================
// By EVOLVED
// www.evolved-software.com
// transparency by MMM (based on an idea from Graphiboc)
//======================================================
//--------------
// 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};
//--------------
// Tweaks
//--------------
float3 Ambient={0.1f,0.1f, 0.1f};
float4 lightposition={0.0f,150.0f,0.0f,1.0f};
float3 LightColor={1.0f,1.0f,1.0f};
float LightRange=500.0f;
matrix lightprojmatrix;
float SpecularPow=16.0f;
float4 FogColor={250.5f,0.5f,0.5f,1.0f};
float FogRange=500.0f;
float Alpha=1.0f;
//--------------
// Textures
//--------------
texture BaseTX <string Name="";>;
sampler2D Base = sampler_state
{
texture = <BaseTX>;
};
texture NormalTX <string Name="";>;
sampler2D Normal = sampler_state
{
texture = <NormalTX>;
};
texture ProjetTX <string Name="";>;
sampler2D Projet = sampler_state
{
texture = <ProjetTX>;
ADDRESSU = CLAMP;
ADDRESSV = CLAMP;
ADDRESSW = CLAMP;
MagFilter = Linear;
MinFilter = Point;
MipFilter = None;
};
texture DepthMapTX <string Name="";>;
sampler2D DepthMap=sampler_state
{
texture = <DepthMapTX>;
};
//--------------
// structs
//--------------
struct IN_Depth
{
float4 Pos:POSITION;
};
struct OUT_Depth
{
float4 OPos:POSITION;
float Depth:TEXCOORD1;
};
struct IN_NormalMap
{
float4 Pos:POSITION;
float2 UV:TEXCOORD;
float3 Normal:NORMAL;
float3 Tangent:TANGENT;
float3 Binormal:BINORMAL;
};
struct OUT_NormalMap
{
float4 OPos:POSITION;
float2 Tex:TEXCOORD0;
float3 LightVec:TEXCOORD1;
float3 Attenuation:TEXCOORD2;
float3 ViewVec:TEXCOORD3;
float4 Proj:TEXCOORD4;
float Fog:FOG;
};
//--------------
// vertex shaders
//--------------
OUT_Depth VS_Depth(IN_Depth IN)
{
OUT_Depth OUT;
OUT.OPos = mul(IN.Pos,WorldVP);
float4 WPosP = mul(IN.Pos,World);
float4 Proj = mul(WPosP,lightprojmatrix);
OUT.Depth = Proj.z;
return OUT;
}
OUT_NormalMap VS_NormalMap(IN_NormalMap IN)
{
OUT_NormalMap OUT;
OUT.OPos=mul(IN.Pos,WorldVP);
OUT.Tex=IN.UV;
float3x3 TBN={IN.Tangent,IN.Binormal,IN.Normal};
TBN=transpose(mul(TBN,World));
float3 WPos=mul(IN.Pos,World);
float3 LightPos=lightposition-WPos;
float3 ViewPos=ViewInv[3].xyz-WPos;
OUT.LightVec=mul(LightPos,TBN);
OUT.Attenuation=-(LightPos/LightRange);
OUT.ViewVec=mul(ViewPos,TBN);
float4 Wpos = mul(IN.Pos,World);
float4 Proj = mul(Wpos,lightprojmatrix);
OUT.Proj = mul(ViewMat,Proj);
OUT.Fog=1-saturate(dot(ViewPos/FogRange,ViewPos/FogRange));
return OUT;
}
//--------------
// pixel shaders
//--------------
float4 PS_Depth(OUT_Depth IN) : COLOR
{
return (IN.Depth/LightRange)+0.01f;
}
float4 PS_NormalMap(OUT_NormalMap IN) : COLOR
{
float4 Texture=tex2D(Base,IN.Tex);
float3 NormalMap=tex2D(Normal,IN.Tex)*2-1;
float3 LightV=normalize(IN.LightVec);
float3 ViewV=normalize(IN.ViewVec);
NormalMap=normalize(NormalMap);
float Normal=saturate(dot(reflect(-ViewV,NormalMap),LightV));
Normal=pow(Normal,SpecularPow)+saturate(dot(NormalMap,LightV));
float3 Projetlight=tex2Dproj(Projet,IN.Proj)*saturate(IN.Proj.z);
float3 Light=LightColor*(1-saturate(dot(IN.Attenuation,IN.Attenuation)))*Projetlight;
float Depth=(IN.Proj.z/LightRange);
float shadowmap=1-(tex2Dproj(DepthMap,IN.Proj+float4(0,0,0,0)) < Depth ? 1.0:0.0f);
//shadowmap=shadowmap-(tex2Dproj(DepthMap,IN.Proj+float4(0,-0.8,0,0)) < Depth ? 0.111f:0.0f);
//shadowmap=shadowmap-(tex2Dproj(DepthMap,IN.Proj+float4(0.8,-0.8,0,0)) < Depth ? 0.111f:0.0f);
//shadowmap=shadowmap-(tex2Dproj(DepthMap,IN.Proj+float4(-0.8,0,0,0)) < Depth ? 0.111f:0.0f);
//shadowmap=shadowmap-(tex2Dproj(DepthMap,IN.Proj+float4(0,0,0,0)) < Depth ? 0.111f:0.0f);
//shadowmap=shadowmap-(tex2Dproj(DepthMap,IN.Proj+float4(0.8,0,0,0)) < Depth ? 0.111f:0.0f);
//shadowmap=shadowmap-(tex2Dproj(DepthMap,IN.Proj+float4(-0.8,0.8,0,0)) < Depth ? 0.111f:0.0f);
//shadowmap=shadowmap-(tex2Dproj(DepthMap,IN.Proj+float4(0,0.8,0,0)) < Depth ? 0.111f:0.0f);
//shadowmap=shadowmap-(tex2Dproj(DepthMap,IN.Proj+float4(0.8,0.8,0,0)) < Depth ? 0.111f:0.0f);;
// This Part (still a hacky beta) =================================================================
float ShadowAlpha=((Light.x+Light.y+Light.z)*shadowmap)/3;
return float4(Texture*((Normal*Light*shadowmap)),ShadowAlpha);
//==================================================================================================
}
//--------------
// techniques
//--------------
technique depthmap
{
pass p1
{
VertexShader = compile vs_2_0 VS_Depth();
PixelShader = compile ps_2_0 PS_Depth();
}
}
technique GhostMapping
{
pass p1
{
vertexShader = compile vs_2_0 VS_NormalMap();
pixelShader = compile ps_2_0 PS_NormalMap();
// And here ========================================================================================================
alphaBlendEnable = true;
srcBlend = srcAlpha;
destBlend = one;
blendOp = add;
//FOGCOLOR=(FogColor);
//FOGENABLE=TRUE;
//===============================================================================================================
}
}
Cheers.