[2024] | 1 | struct LightVPos_OUT
|
---|
| 2 | {
|
---|
| 3 | float4 VPos : POSITION;
|
---|
| 4 | float4 LightVPos : TEXCOORD0;
|
---|
| 5 | };
|
---|
| 6 |
|
---|
| 7 | struct LightCPos_OUT
|
---|
| 8 | {
|
---|
| 9 | float4 VPos : POSITION;
|
---|
| 10 | float4 LightVPos : TEXCOORD0;
|
---|
| 11 | float4 LightCPos : TEXCOORD1;
|
---|
| 12 | };
|
---|
| 13 |
|
---|
| 14 | #define DEPTH_BIAS 0.001
|
---|
| 15 | #define DEPTH_BIAS_VSM 0.001
|
---|
[2294] | 16 | #define DEPTH_EPSILON 0.05
|
---|
[2404] | 17 | #define DIST_BIAS 0.005
|
---|
[2311] | 18 | #define DIST_BIAS_VSM 0.0005
|
---|
| 19 | #define DIST_EPSILON 0.001
|
---|
[2024] | 20 |
|
---|
[2438] | 21 | //#define shadowColor float4(0.95,0.95,0.95,1)
|
---|
[2442] | 22 | #define shadowColor float4(0.8,0.8,0.8,1)
|
---|
| 23 | //#define shadowColor float4(0.2,0.2,0.2,1)
|
---|
| 24 | //#define shadowColor float4(0.0,0.0,0.0,1)
|
---|
[2024] | 25 |
|
---|
| 26 | float4 shadowMapDepth(LightVPos_OUT IN,
|
---|
| 27 | uniform sampler2D shadowMap) : COLOR
|
---|
| 28 | {
|
---|
[2181] | 29 | float4 light = shadowColor;
|
---|
| 30 |
|
---|
[2294] | 31 | // if(IN.LightVPos.z > 0.0)
|
---|
[2024] | 32 | {
|
---|
[2181] | 33 | float4 pos = (IN.LightVPos / IN.LightVPos.w);
|
---|
| 34 |
|
---|
| 35 | pos.xy = (pos.xy + 1.0) / 2.0;
|
---|
| 36 | pos.y = 1.0 - pos.y;
|
---|
[2294] | 37 | float storedDepth = abs(tex2D(shadowMap, pos.xy).r);
|
---|
| 38 | //light = (pos.z - storedDepth.r)*100.0;
|
---|
| 39 | light = max(storedDepth + DEPTH_BIAS > pos.z, shadowColor);
|
---|
[2181] | 40 | }
|
---|
[2024] | 41 | return light;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | float4 shadowMapDepth_Variance(LightVPos_OUT IN,
|
---|
| 45 | uniform sampler2D shadowMap) : COLOR
|
---|
| 46 | {
|
---|
| 47 | float4 light = float4(1,1,1,1);
|
---|
| 48 |
|
---|
| 49 | float4 pos = (IN.LightVPos / IN.LightVPos.w);
|
---|
| 50 |
|
---|
| 51 | if( pos.z > 0.0)
|
---|
[2181] | 52 | {
|
---|
[2024] | 53 | float depth = pos.z;
|
---|
| 54 | pos.xy = (pos.xy + 1.0) / 2.0;
|
---|
| 55 | pos.y = 1.0 - pos.y;
|
---|
| 56 | float4 storedDepth = tex2D(shadowMap, pos.xy);
|
---|
| 57 | depth -= DEPTH_BIAS_VSM;
|
---|
| 58 | float lit_factor = light * (depth <= storedDepth.r);
|
---|
| 59 |
|
---|
| 60 | float M1 = storedDepth.r;
|
---|
| 61 | float M2 = storedDepth.g;
|
---|
| 62 | float v2 = min(max(M2 - M1 * M1, 0.0) + DEPTH_EPSILON, 1.0);
|
---|
| 63 | float m_d = M1 - depth;
|
---|
[2181] | 64 | float pmax = v2 / (v2 + m_d * m_d);
|
---|
[2024] | 65 |
|
---|
[2181] | 66 | // Adjust the light color based on the shadow attenuation
|
---|
| 67 | light = max(lit_factor, pmax);
|
---|
[2024] | 68 | }
|
---|
| 69 | else
|
---|
| 70 | light = 0;
|
---|
| 71 |
|
---|
| 72 | return shadowColor + (1 - shadowColor) * light;
|
---|
| 73 |
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[2179] | 76 | float4 shadowMapDist(LightCPos_OUT IN,
|
---|
[2181] | 77 | uniform float lightFarPlane,
|
---|
[2179] | 78 | uniform sampler2D shadowMap) : COLOR
|
---|
[2024] | 79 | {
|
---|
[2404] | 80 | float4 light = 0;//shadowColor;
|
---|
[2179] | 81 | if( IN.LightVPos.z > 0.0)
|
---|
[2024] | 82 | {
|
---|
[2179] | 83 | float4 pos = (IN.LightVPos / IN.LightVPos.w);
|
---|
[2217] | 84 | float d = length(pos.xy);
|
---|
[2404] | 85 | //light = saturate((1.0 - d)/0.05);
|
---|
[2217] | 86 | if(d <= 1.0)
|
---|
| 87 | {
|
---|
[2181] | 88 | float dist = length(IN.LightCPos.xyz) / lightFarPlane;
|
---|
[2179] | 89 | pos.xy = (pos.xy + 1.0) / 2.0;
|
---|
| 90 | pos.y = 1.0 - pos.y;
|
---|
[2311] | 91 | float storedDist = tex2D(shadowMap, pos.xy).r;
|
---|
| 92 | light = dist < storedDist + DIST_BIAS;
|
---|
[2404] | 93 | //if(dist < storedDist + DIST_BIAS)
|
---|
[2422] | 94 | // light = 1;
|
---|
[2217] | 95 | }
|
---|
[2179] | 96 | }
|
---|
[2422] | 97 | light = max(light, shadowColor);
|
---|
| 98 |
|
---|
[2024] | 99 | return light;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | float4 shadowMapDist_Variance(LightCPos_OUT IN,
|
---|
| 103 | uniform float lightFarPlane,
|
---|
| 104 | uniform sampler2D shadowMap) : COLOR
|
---|
| 105 | {
|
---|
[2442] | 106 | float4 light = 0;//loat4(1,1,1,1);
|
---|
[2024] | 107 |
|
---|
[2179] | 108 | if( IN.LightVPos.z > 0.0)
|
---|
[2024] | 109 | {
|
---|
[2179] | 110 | float4 pos = (IN.LightVPos / IN.LightVPos.w);
|
---|
| 111 | float d = length(pos.xy);
|
---|
| 112 | if(d <= 1.0)
|
---|
[2024] | 113 | {
|
---|
[2179] | 114 | float dist = length(IN.LightCPos.xyz) / lightFarPlane;
|
---|
| 115 | pos.xy = (pos.xy + 1.0) / 2.0;
|
---|
| 116 | pos.y = 1.0 - pos.y;
|
---|
| 117 | float4 storedDist = tex2D(shadowMap, pos.xy);
|
---|
| 118 | dist -= DIST_BIAS_VSM;
|
---|
| 119 | float lit_factor = light * (dist <= storedDist.r);
|
---|
[2024] | 120 |
|
---|
[2179] | 121 | float M1 = storedDist.r;
|
---|
| 122 | float M2 = storedDist.g;
|
---|
| 123 | float v2 = min(max(M2 - M1 * M1, 0.0) + DIST_EPSILON, 1.0);
|
---|
| 124 | float m_d = M1 - dist;
|
---|
[2024] | 125 | float pmax = v2 / (v2 + m_d * m_d);
|
---|
| 126 |
|
---|
| 127 | // Adjust the light color based on the shadow attenuation
|
---|
[2179] | 128 | light = max(lit_factor, pmax);
|
---|
| 129 | }
|
---|
[2024] | 130 | }
|
---|
| 131 |
|
---|
| 132 | return shadowColor + (1 - shadowColor) * light;
|
---|
[2337] | 133 | }
|
---|
| 134 |
|
---|
| 135 |
|
---|
| 136 | float4 shadowMapDist_POINT_Variance(LightCPos_OUT IN,
|
---|
| 137 | uniform float lightFarPlane,
|
---|
| 138 | uniform samplerCUBE shadowMap) : COLOR
|
---|
| 139 | {
|
---|
| 140 | float4 light = float4(1,1,1,1);
|
---|
| 141 |
|
---|
| 142 | float dist = length(IN.LightCPos.xyz) / lightFarPlane;
|
---|
| 143 | float4 storedDist = texCUBE(shadowMap, float3(IN.LightCPos.xy, -IN.LightCPos.z));
|
---|
| 144 | dist -= DIST_BIAS_VSM;
|
---|
| 145 | float lit_factor = light * (dist <= storedDist.r);
|
---|
| 146 |
|
---|
| 147 | float M1 = storedDist.r;
|
---|
| 148 | float M2 = storedDist.g;
|
---|
| 149 | float v2 = min(max(M2 - M1 * M1, 0.0) + DIST_EPSILON, 1.0);
|
---|
| 150 | float m_d = M1 - dist;
|
---|
| 151 | float pmax = v2 / (v2 + m_d * m_d);
|
---|
| 152 |
|
---|
| 153 | // Adjust the light color based on the shadow attenuation
|
---|
| 154 | light = max(lit_factor, pmax);
|
---|
| 155 |
|
---|
| 156 |
|
---|
| 157 | return (shadowColor + (1 - shadowColor) * light);
|
---|
[2024] | 158 | } |
---|