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