[1637] | 1 | //#define SHADOWMAP_SIZE 512.0f // Shadow map size
|
---|
| 2 | //#define HALF_TEXEL 0.5f / (float)SHADOWMAP_SIZE // Size of the half texel
|
---|
| 3 | float SHADOWMAP_SIZE; // Shadow map size
|
---|
| 4 | float HALF_TEXEL; // Size of the half texel
|
---|
| 5 |
|
---|
| 6 | #define PI 3.14159265f // Value of PI
|
---|
| 7 |
|
---|
| 8 | float4x4 TexScaleBias; // Tranformation matrix between light and texture space
|
---|
| 9 | float4x4 WorldLight; // To the light's camera space
|
---|
| 10 | float4x4 WorldViewProj; // To the normalized screen space of the eye camera
|
---|
| 11 | float4x4 WorldLightProj; // To the normalized screen space of the light camera
|
---|
| 12 |
|
---|
| 13 |
|
---|
| 14 | texture g_txDefaultTexture; // Default texture of objects
|
---|
| 15 | texture g_txShadowMapColor; // Shadow map texture
|
---|
| 16 | texture g_txShadowMapZ; // Shadow map texture (Z)
|
---|
| 17 | texture g_txShadowWeight;
|
---|
| 18 |
|
---|
| 19 | float4 g_vMaterial; // Diffuse color
|
---|
| 20 |
|
---|
| 21 | float g_fFov; // FOV of light
|
---|
| 22 | float g_fLightSize; // Size of light source
|
---|
| 23 | float g_fIntensity; // Helper
|
---|
| 24 | float g_fShadowBias; // Shadow map bias
|
---|
| 25 | float g_fBiasSlope;
|
---|
| 26 | float near; // Light source near plane
|
---|
| 27 | float far; // Light source far plane
|
---|
| 28 | float g_fRealSamples;
|
---|
| 29 |
|
---|
| 30 | int g_iKernelSize; // kernel size
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | bool g_bRenderBaseTexture;
|
---|
| 34 |
|
---|
| 35 | struct VS_INPUT {
|
---|
| 36 | float4 Position : POSITION; // input position in modeling space
|
---|
| 37 | float4 Color : COLOR0; // input color to be modulated by shadow
|
---|
| 38 | float2 Tex : TEXCOORD0;
|
---|
| 39 | };
|
---|
| 40 |
|
---|
| 41 | struct VS_OUTPUT {
|
---|
| 42 | float4 hPosition : POSITION; // in normalized device space
|
---|
| 43 | float4 lcPosition : TEXCOORD1; // in light's camera space
|
---|
| 44 | float4 ldPosition : TEXCOORD2; // in light's normalized devide space
|
---|
| 45 | float4 Color : COLOR0; // input color to be modulated by shadow
|
---|
| 46 | float2 Tex : TEXCOORD0;
|
---|
| 47 | };
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | // Texture samplers
|
---|
| 51 | sampler2D g_samScene = sampler_state
|
---|
| 52 | {
|
---|
| 53 | Texture = <g_txDefaultTexture>;
|
---|
| 54 | MinFilter = Point;
|
---|
| 55 | MagFilter = Linear;
|
---|
| 56 | MipFilter = Linear;
|
---|
| 57 | };
|
---|
| 58 |
|
---|
| 59 | sampler2D g_ShadowMapColorSampler = sampler_state
|
---|
| 60 | {
|
---|
| 61 | Texture = <g_txShadowMapColor>;
|
---|
| 62 | MinFilter = Linear;
|
---|
| 63 | MagFilter = Linear;
|
---|
| 64 | MipFilter = Linear;
|
---|
| 65 | AddressU = Clamp;
|
---|
| 66 | AddressV = Clamp;
|
---|
| 67 | };
|
---|
| 68 |
|
---|
| 69 | sampler2D g_ShadowWeightSampler = sampler_state
|
---|
| 70 | {
|
---|
| 71 | Texture = <g_txShadowWeight>;
|
---|
| 72 | MinFilter = Linear;
|
---|
| 73 | MagFilter = Linear;
|
---|
| 74 | MipFilter = Linear;
|
---|
| 75 | AddressU = Clamp;
|
---|
| 76 | AddressV = Clamp;
|
---|
| 77 | };
|
---|
| 78 |
|
---|
| 79 | sampler2D g_ShadowMapZSampler_Point = sampler_state
|
---|
| 80 | {
|
---|
| 81 | Texture = <g_txShadowMapZ>;
|
---|
| 82 | MinFilter = Point;
|
---|
| 83 | MagFilter = Point;
|
---|
| 84 | MipFilter = Point;
|
---|
| 85 | AddressU = Clamp;
|
---|
| 86 | AddressV = Clamp;
|
---|
| 87 | };
|
---|
| 88 |
|
---|
| 89 | sampler2D g_ShadowMapZSampler_Linear = sampler_state
|
---|
| 90 | {
|
---|
| 91 | Texture = <g_txShadowMapZ>;
|
---|
| 92 | MinFilter = Linear;
|
---|
| 93 | MagFilter = Linear;
|
---|
| 94 | MipFilter = Linear;
|
---|
| 95 | AddressU = Clamp;
|
---|
| 96 | AddressV = Clamp;
|
---|
| 97 | }; |
---|