The light is a point light somewhere above the house.
For some reasons the shadows move with the camera, and are projected wrong.
On the video you can see it (and the shadow map too)
Youtube video: http://www.youtube.com/watch?v=Cr39dVuSgMQ (the codec sux - sorry, but you can see the problem)
base.program
Code: Select all
vertex_program PerPixel_Lim3_Vert cg
{
source normalSpecDiffuse.cg
default_params
{
param_named_auto lightPosition[0] light_position_object_space 0
param_named_auto lightPosition[1] light_position_object_space 1
param_named_auto lightPosition[2] light_position_object_space 2
//param_named_auto lightPosition[3] light_position_object_space 3
//param_named_auto lightPosition[4] light_position_object_space 4
//param_named_auto lightPosition[5] light_position_object_space 5
param_named_auto eyePosition camera_position_object_space
param_named_auto worldviewproj worldviewproj_matrix
param_named_auto lpoz light_position 0
param_named_auto wMat world_matrix
//param_named_auto wvpMat worldviewproj_matrix
param_named_auto tvpMat texture_viewproj_matrix 0
}
entry_point PerPixel_Lim3_Vert
profiles vs_1_1 arbvp1
}
fragment_program PerPixel_Lim3_Frag cg
{
source normalSpecDiffuse.cg
default_params
{
param_named_auto lightDiffuse[0] light_diffuse_colour 0
param_named_auto lightDiffuse[1] light_diffuse_colour 1
param_named_auto lightDiffuse[2] light_diffuse_colour 2
// param_named_auto lightDiffuse[3] light_diffuse_colour 3
// param_named_auto lightDiffuse[4] light_diffuse_colour 4
// param_named_auto lightDiffuse[5] light_diffuse_colour 5
param_named_auto lightSpecular[0] light_specular_colour 0
param_named_auto lightSpecular[1] light_specular_colour 1
param_named_auto lightSpecular[2] light_specular_colour 2
// param_named_auto lightSpecular[3] light_specular_colour 3
// param_named_auto lightSpecular[4] light_specular_colour 4
// param_named_auto lightSpecular[5] light_specular_colour 5
param_named_auto lightAtt[0] light_attenuation 0
param_named_auto lightAtt[1] light_attenuation 1
param_named_auto lightAtt[2] light_attenuation 2
// param_named_auto lightAtt[3] light_attenuation 3
// param_named_auto lightAtt[4] light_attenuation 4
// param_named_auto lightAtt[5] light_attenuation 5
param_named_auto ambient ambient_light_colour
param_named exponent0 float 12
}
entry_point PerPixel_Lim3_Frag
profiles ps_2_x fp30
}
Code: Select all
material DiffuseNormalSpecSSAO
{
technique
{
pass
{
vertex_program_ref PerPixel_Lim3_Vert
{
}
fragment_program_ref PerPixel_Lim3_Frag
{
}
texture_unit diffuse_tex
{
tex_coord_set 0
}
texture_unit normal_tex
{
colour_op replace
tex_coord_set 0
}
texture_unit specular_tex
{
tex_coord_set 0
}
texture_unit shadow_tex
{
content_type shadow
filtering anisotropic
max_anisotropy 16
tex_address_mode border
tex_border_colour 1 1 1
}
}
}
technique geom
{
scheme geom
pass
{
vertex_program_ref geom_vs
{
}
fragment_program_ref geom_ps
{
}
}
}
}
Code: Select all
float3 expand(float3 v)
{
return (v - 0.5) * 2;
}
float4 btex2D(sampler2D map, float2 uv, float radius, float steps)
{
half stepSize = 2.0 * radius / steps;
uv.xy -= radius.xx;
float4 total = float4(0, 0, 0, 0);
for (int x = 0; x < steps; ++x)
for (int y = 0; y < steps; ++y)
total +=
tex2D(map, float2(uv.xy + float2(x * stepSize, y * stepSize)));
return total / (steps * steps);
}
float computeShadow(
sampler2D shadowMap, float4 shadowMapPos, float ourDepth)
{
float2 suv = shadowMapPos.xy / shadowMapPos.w;
float2 moments = btex2D(shadowMap, suv, 0.01, 4).rg;
float litFactor = (ourDepth <= moments.x ? 1 : 0);
// standard variance shadow mapping code
float E_x2 = moments.y;
float Ex_2 = moments.x * moments.x;
float vsmEpsilon = 0.0001;
float variance = min(max(E_x2 - Ex_2, 0.0) + vsmEpsilon, 1.0);
float m_d = moments.x - ourDepth;
float p = variance / (variance + m_d * m_d);
return smoothstep(0.2, 1, max(litFactor, p));
}
struct VOut
{
float4 oPosition : POSITION;
float2 oUv : TEXCOORD0;
float3 oEyeDir : TEXCOORD1;
float4 oLightDir0 : TEXCOORD2;
float4 oLightDir1 : TEXCOORD3;
float4 oLightDir2 : TEXCOORD4;
//float4 oLightDir3 : TEXCOORD5;
//float4 oLightDir4 : TEXCOORD6;
//float4 oLightDir5 : TEXCOORD7;
float4 lpoz : TEXCOORD5;
float4 wp : TEXCOORD6;
float4 lp : TEXCOORD7;
};
VOut PerPixel_Lim3_Vert(
float4 position : POSITION,
float3 normal : NORMAL,
float2 uv : TEXCOORD0,
float3 tangent : TEXCOORD1,
uniform float4 lightPosition[6],
uniform float4 lpoz,
uniform float3 eyePosition,
uniform float4x4 worldviewproj,
uniform float4x4 wMat,
uniform float4x4 tvpMat
)
{
VOut OUT;
OUT.oPosition = mul(worldviewproj , position);
OUT.oUv = uv;
OUT.wp = mul(wMat, position);
OUT.lp = mul(tvpMat, OUT.wp);
OUT.lpoz = lpoz;
float3 eyeDir = eyePosition - position.xyz;
float3 binormal = cross(tangent, normal);
float3x3 rotation = float3x3(tangent, binormal, normal);
eyeDir = normalize(mul(rotation, eyeDir));
OUT.oEyeDir = eyeDir;
float3 temp_lightDir = normalize(lightPosition[0].xyz - (position.xyz * lightPosition[0].w));
OUT.oLightDir0 = float4(normalize(mul(rotation, temp_lightDir)),distance(position.xyz, lightPosition[0].xyz)*lightPosition[0].w);
temp_lightDir = normalize(lightPosition[1].xyz - (position.xyz * lightPosition[1].w));
OUT.oLightDir1 = float4(normalize(mul(rotation, temp_lightDir)),distance(position.xyz, lightPosition[1].xyz)*lightPosition[1].w);
temp_lightDir = normalize(lightPosition[2].xyz - (position.xyz * lightPosition[2].w));
OUT.oLightDir2 = float4(normalize(mul(rotation, temp_lightDir)),distance(position.xyz, lightPosition[2].xyz)*lightPosition[2].w);
//temp_lightDir = normalize(lightPosition[3].xyz - (position.xyz * lightPosition[3].w));
//OUT.oLightDir3 = float4(normalize(mul(rotation, temp_lightDir)),distance(position.xyz, lightPosition[3].xyz)*lightPosition[3].w);
//temp_lightDir = normalize(lightPosition[4].xyz - (position.xyz * lightPosition[4].w));
//OUT.oLightDir4 = float4(normalize(mul(rotation, temp_lightDir)),distance(position.xyz, lightPosition[4].xyz)*lightPosition[4].w);
//temp_lightDir = normalize(lightPosition[5].xyz - (position.xyz * lightPosition[5].w));
//OUT.oLightDir5 = float4(normalize(mul(rotation, temp_lightDir)),distance(position.xyz, lightPosition[5].xyz)*lightPosition[5].w);
return OUT;
}
void PerPixel_Lim3_Frag(
float2 Uv : TEXCOORD0,
float3 eyeDir : TEXCOORD1,
float4 LightDir0 : TEXCOORD2,
float4 LightDir1 : TEXCOORD3,
float4 LightDir2 : TEXCOORD4,
//float4 LightDir3 : TEXCOORD5,
//float4 LightDir4 : TEXCOORD6,
float4 lpoz : TEXCOORD5,
float4 wp : TEXCOORD6,
float4 lp : TEXCOORD7,
uniform float4 lightDiffuse[3],
uniform float4 lightSpecular[3],
uniform float4 lightAtt[3],
uniform float exponent0,
uniform float4 ambient,
out float4 oColor : COLOR,
uniform sampler2D diffuseCol : register(s0),
uniform sampler2D normalMap : register(s1),
uniform sampler2D specularCol : register(s2),
uniform sampler2D ShadowMap : register(s3)
)
{
float4 diffusetex = tex2D(diffuseCol, Uv);
float3 bumpVec = expand(tex2D(normalMap, Uv ).xyz);
float3 specVec = tex2D(specularCol, Uv ).xyz;
float3 N = normalize(bumpVec);
float3 HalfAngle[3];
float NdotL[3];
float NdotH[3];
float4 Lit[3];
float attFactor[3];
float4 ldir[5];
ldir[0] = LightDir0;
ldir[1] = LightDir1;
ldir[2] = LightDir2;
//ldir[3] = LightDir3;
//ldir[4] = LightDir4;
//ldir[5] = LightDir5;
half lightDist = length(lpoz.xyz - wp.xyz) / 100;
float4 diffFact = 0;
float4 specFact = 0;
for(int i=0; i<3; ++i)
{
HalfAngle[i] = normalize(eyeDir + ldir[i].xyz);
NdotL[i] = dot(ldir[i].xyz, N);
NdotH[i] = dot(HalfAngle[i], N);
Lit[i] = lit(NdotL[i],NdotH[i],exponent0);
attFactor[i] = saturate(1 / ldir[i].w / lightAtt[i].z) * saturate(1 / pow(ldir[i].w,2) / lightAtt[i].w);
diffFact += lightDiffuse[i] * Lit[i].y * attFactor[i];
specFact += lightSpecular[i] * Lit[i].z * attFactor[i];
}
float3 shadow = computeShadow(
// pass in the shadow map
ShadowMap,
// the calculated shadow position in the shadow map
lp,
// distance to light, done just as in the caster shader
lightDist).xxx; // 3 components
oColor = (diffusetex * (ambient + diffFact) + specFact) * shadow.x; // I know this produces a very dark shadow - it's just for debugging
}