| 1 |
float3 LightDiffuse(float3 vNormal,float3 vLightDir,float3 vLightColor,float3 vDiffuseMaterial) |
| 2 |
{ |
| 3 |
return vDiffuseMaterial * vLightColor * max(dot(vNormal, vLightDir), 0.0f); |
| 4 |
} |
| 5 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 6 |
// Structs |
| 7 |
|
| 8 |
struct PS_INPUT_FLORB |
| 9 |
{ |
| 10 |
float4 vColor : COLOR0; |
| 11 |
float2 Tex0 : TEXCOORD0; |
| 12 |
float4 SunLight : TEXCOORD1; |
| 13 |
float4 ShadowTexCoord : TEXCOORD2; |
| 14 |
float2 TexelPos : TEXCOORD3; |
| 15 |
}; |
| 16 |
struct VS_OUTPUT_FLORB |
| 17 |
{ |
| 18 |
float4 vPosition : POSITION; |
| 19 |
float4 vColor : COLOR; |
| 20 |
float3 vNormal : TEXCOORD4; |
| 21 |
float2 Tex0 : TEXCOORD0; |
| 22 |
float4 SunLight : TEXCOORD1; |
| 23 |
float4 ShadowTexCoord : TEXCOORD2; |
| 24 |
float2 TexelPos : TEXCOORD3; |
| 25 |
float Fog : FOG; |
| 26 |
}; |
| 27 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 28 |
// Vertex Shader, not too much has changed here. |
| 29 |
|
| 30 |
VS_OUTPUT_FLORB vs_florb(uniform const int PcfMode,float4 vPosition : POSITION,float2 tc : TEXCOORD0,float4 vColor : COLOR, float3 vNormal : NORMAL) |
| 31 |
{ |
| 32 |
VS_OUTPUT_FLORB Out = (VS_OUTPUT_FLORB)0; |
| 33 |
Out.vPosition = mul(matWorldViewProj, vPosition); |
| 34 |
float4 vWorldPos = (float4)mul(matWorld,vPosition); |
| 35 |
float3 P = mul(matWorldView,vPosition); |
| 36 |
Out.Tex0 = tc; |
| 37 |
vColor.rgb = LightDiffuse(vNormal.xyz, vSunDir.rgb, vSunColor.rgb, vColor.rgb); // New |
| 38 |
Out.vColor = vColor * (vAmbientColor + vSunColor * 0.06f); |
| 39 |
Out.SunLight = (vSunColor * 0.34f)* vMaterialColor * Out.vColor; |
| 40 |
if (PcfMode != PCF_NONE) |
| 41 |
{ |
| 42 |
float4 ShadowPos = mul(matSunViewProj, vWorldPos); |
| 43 |
Out.ShadowTexCoord = ShadowPos; |
| 44 |
Out.ShadowTexCoord.z /= ShadowPos.w; |
| 45 |
Out.ShadowTexCoord.w = 1.0f; |
| 46 |
Out.TexelPos = Out.ShadowTexCoord * fShadowMapSize; |
| 47 |
} |
| 48 |
float d = length(P); |
| 49 |
Out.Fog = get_fog_amount(d); |
| 50 |
return Out; |
| 51 |
} |
| 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 53 |
// Pixel Shaders |
| 54 |
|
| 55 |
PS_OUTPUT ps_florb(PS_INPUT_FLORB In, uniform const int PcfMode) |
| 56 |
{ |
| 57 |
PS_OUTPUT Output; |
| 58 |
float4 tex_col = tex2D(MeshTextureSampler, In.Tex0); |
| 59 |
clip(tex_col.a - 0.05f); |
| 60 |
tex_col.rgb = pow(tex_col.rgb, input_gamma); |
| 61 |
if (PcfMode != PCF_NONE) |
| 62 |
{ |
| 63 |
float sun_amount = GetSunAmount(PcfMode, In.ShadowTexCoord, In.TexelPos); |
| 64 |
Output.RGBColor = tex_col * ((In.vColor + In.SunLight * sun_amount)); |
| 65 |
} |
| 66 |
else |
| 67 |
{ |
| 68 |
Output.RGBColor = tex_col * ((In.vColor + In.SunLight)); |
| 69 |
} |
| 70 |
Output.RGBColor.rgb = pow(Output.RGBColor.rgb, output_gamma_inv); |
| 71 |
return Output; |
| 72 |
} |