@@ -55,7 +55,6 @@ struct PbrMaterial
5555struct ShadowAtlasInfo
5656{
5757 int4 lightRegions[2];
58- uint2 atlasSize;
5958};
6059
6160struct LightBlock
@@ -170,57 +169,57 @@ float3 calculatePbrLighting(thread const float3& normal, thread const float3& V,
170169static inline __attribute__((always_inline))
171170bool isCoordsInRange(thread const float3& uv)
172171{
173- bool _69 = uv.x >= 0.0;
174- bool _76 ;
175- if (_69 )
172+ bool _72 = uv.x >= 0.0;
173+ bool _79 ;
174+ if (_72 )
176175 {
177- _76 = uv.y >= 0.0;
176+ _79 = uv.y >= 0.0;
178177 }
179178 else
180179 {
181- _76 = _69 ;
180+ _79 = _72 ;
182181 }
183- bool _83 ;
184- if (_76 )
182+ bool _86 ;
183+ if (_79 )
185184 {
186- _83 = uv.x <= 1.0;
185+ _86 = uv.x <= 1.0;
187186 }
188187 else
189188 {
190- _83 = _76 ;
189+ _86 = _79 ;
191190 }
192- bool _89 ;
193- if (_83 )
191+ bool _92 ;
192+ if (_86 )
194193 {
195- _89 = uv.y <= 1.0;
194+ _92 = uv.y <= 1.0;
196195 }
197196 else
198197 {
199- _89 = _83 ;
198+ _92 = _86 ;
200199 }
201- bool _96 ;
202- if (_89 )
200+ bool _99 ;
201+ if (_92 )
203202 {
204- _96 = uv.z >= 0.0;
203+ _99 = uv.z >= 0.0;
205204 }
206205 else
207206 {
208- _96 = _89 ;
207+ _99 = _92 ;
209208 }
210- bool _102 ;
211- if (_96 )
209+ bool _105 ;
210+ if (_99 )
212211 {
213- _102 = uv.z <= 1.0;
212+ _105 = uv.z <= 1.0;
214213 }
215214 else
216215 {
217- _102 = _96 ;
216+ _105 = _99 ;
218217 }
219- return _102 ;
218+ return _105 ;
220219}
221220
222221static inline __attribute__((always_inline))
223- float calcShadowmap(thread const int& lightIndex, thread const float& NdotL, thread spvUnsafeArray<float3, 2>& fragLightPos, constant ShadowAtlasInfo& _420 , depth2d<float> shadowMap, sampler shadowMapSmplr)
222+ float calcShadowmap(thread const int& lightIndex, thread const float& NdotL, thread const int2& atlasSize, thread spvUnsafeArray<float3, 2>& fragLightPos, constant ShadowAtlasInfo& _422 , depth2d<float> shadowMap, sampler shadowMapSmplr)
224223{
225224 float bias0 = 0.004999999888241291046142578125;
226225 float3 lightSpacePos = fragLightPos[lightIndex];
@@ -233,11 +232,24 @@ float calcShadowmap(thread const int& lightIndex, thread const float& NdotL, thr
233232 {
234233 return 1.0;
235234 }
236- int4 region = _420 .lightRegions[lightIndex];
235+ int4 region = _422 .lightRegions[lightIndex];
237236 uv = float2(region.xy) + (uv * float2(region.zw));
238- uv /= float2(_420.atlasSize);
239- float3 texCoords = float3(uv, depthRef);
240- return shadowMap.sample_compare(shadowMapSmplr, texCoords.xy, texCoords.z);
237+ uv /= float2(atlasSize);
238+ float2 regionMin = float2(region.xy) / float2(atlasSize);
239+ float2 regionMax = float2(region.xy + region.zw) / float2(atlasSize);
240+ float value = 0.0;
241+ float2 offsets = float2(1.0) / float2(atlasSize);
242+ for (int i = -1; i <= 1; i++)
243+ {
244+ for (int j = -1; j <= 1; j++)
245+ {
246+ float2 offUV = uv + (float2(float(i), float(j)) * offsets);
247+ offUV = fast::clamp(offUV, regionMin, regionMax);
248+ float3 texCoords = float3(offUV, depthRef);
249+ value += (0.111111111938953399658203125 * shadowMap.sample_compare(shadowMapSmplr, texCoords.xy, texCoords.z));
250+ }
251+ }
252+ return value;
241253}
242254
243255static inline __attribute__((always_inline))
@@ -264,14 +276,15 @@ float3 uncharted2ToneMapping(thread const float3& color)
264276 return curr * white_scale;
265277}
266278
267- fragment main0_out main0(main0_in in [[stage_in]], constant Material& _505 [[buffer(0)]], constant LightBlock& light [[buffer(1)]], constant EffectParams& params [[buffer(2)]], constant ShadowAtlasInfo& _420 [[buffer(3)]], depth2d<float> shadowMap [[texture(0)]], texture2d<float> ssaoTex [[texture(1)]], sampler shadowMapSmplr [[sampler(0)]], sampler ssaoTexSmplr [[sampler(1)]], bool gl_FrontFacing [[front_facing]], float4 gl_FragCoord [[position]])
279+ fragment main0_out main0(main0_in in [[stage_in]], constant Material& _571 [[buffer(0)]], constant LightBlock& light [[buffer(1)]], constant EffectParams& params [[buffer(2)]], constant ShadowAtlasInfo& _422 [[buffer(3)]], depth2d<float> shadowMap [[texture(0)]], texture2d<float> ssaoTex [[texture(1)]], sampler shadowMapSmplr [[sampler(0)]], sampler ssaoTexSmplr [[sampler(1)]], bool gl_FrontFacing [[front_facing]], float4 gl_FragCoord [[position]])
268280{
269281 main0_out out = {};
270282 spvUnsafeArray<float3, 2> fragLightPos = {};
271283 fragLightPos[0] = in.fragLightPos_0;
272284 fragLightPos[1] = in.fragLightPos_1;
273285 float3 normal = fast::normalize(in.fragViewNormal);
274286 float3 V = fast::normalize(-in.fragViewPos);
287+ int2 atlasSize = int2(shadowMap.get_width(), shadowMap.get_height());
275288 if (!gl_FrontFacing)
276289 {
277290 normal = -normal;
@@ -283,34 +296,35 @@ fragment main0_out main0(main0_in in [[stage_in]], constant Material& _505 [[buf
283296 float3 param = normal;
284297 float3 param_1 = V;
285298 float3 param_2 = lightDir;
286- PbrMaterial _518 ;
287- _518 .baseColor = _505 .material.baseColor;
288- _518 .metalness = _505 .material.metalness;
289- _518 .roughness = _505 .material.roughness;
290- _518 .ao = _505 .material.ao;
291- PbrMaterial param_3 = _518 ;
299+ PbrMaterial _584 ;
300+ _584 .baseColor = _571 .material.baseColor;
301+ _584 .metalness = _571 .material.metalness;
302+ _584 .roughness = _571 .material.roughness;
303+ _584 .ao = _571 .material.ao;
304+ PbrMaterial param_3 = _584 ;
292305 float3 param_4 = light.color[i];
293306 float param_5 = light.intensity[i].x;
294307 float3 _lo = calculatePbrLighting(param, param_1, param_2, param_3, param_4, param_5);
295308 float NdotL = fast::max(dot(normal, lightDir), 0.0);
296309 int param_6 = i;
297310 float param_7 = NdotL;
298- float shadowValue = calcShadowmap(param_6, param_7, fragLightPos, _420, shadowMap, shadowMapSmplr);
311+ int2 param_8 = atlasSize;
312+ float shadowValue = calcShadowmap(param_6, param_7, param_8, fragLightPos, _422, shadowMap, shadowMapSmplr);
299313 _lo *= shadowValue;
300314 Lo += _lo;
301315 }
302- float3 ambient = (float3(0.100000001490116119384765625) * _505 .material.baseColor.xyz) * _505 .material.ao;
316+ float3 ambient = (float3(0.100000001490116119384765625) * _571 .material.baseColor.xyz) * _571 .material.ao;
303317 if (params.useSsao == 1u)
304318 {
305319 float2 ssaoTexSize = float2(int2(ssaoTex.get_width(), ssaoTex.get_height()));
306320 float2 ssaoUV = gl_FragCoord.xy / ssaoTexSize;
307321 ambient *= ssaoTex.sample(ssaoTexSmplr, ssaoUV).x;
308322 }
309323 float3 color = ambient + Lo;
310- float3 param_8 = color;
311- color = uncharted2ToneMapping(param_8 );
324+ float3 param_9 = color;
325+ color = uncharted2ToneMapping(param_9 );
312326 color = powr(color, float3(0.4545454680919647216796875));
313- out.fragColor = float4(color, _505 .material.baseColor.w);
327+ out.fragColor = float4(color, _571 .material.baseColor.w);
314328 out.outNormal = in.fragViewNormal.xy;
315329 return out;
316330}
0 commit comments