Skip to content

Commit 67f12e6

Browse files
committed
light indirection removals
1 parent 210ea85 commit 67f12e6

12 files changed

Lines changed: 184 additions & 195 deletions

WickedEngine/shaders/ShaderInterop_Renderer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,12 +1252,12 @@ struct alignas(16) FrameCB
12521252
float cloudShadowFarPlaneKm;
12531253
int texture_volumetricclouds_shadow_index;
12541254
uint giboost_packed; // force fp16 load
1255-
uint entity_culling_count;
1256-
12571255
uint capsuleshadow_fade_angle;
1256+
12581257
int indirect_debugbufferindex;
12591258
int padding0;
12601259
int padding1;
1260+
int padding2;
12611261

12621262
float blue_noise_phase;
12631263
int texture_random64x64_index;

WickedEngine/shaders/emittedparticle_simulateCS.hlsl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ void main(uint3 DTid : SV_DispatchThreadID, uint Gid : SV_GroupIndex)
9393
// process forces and colliders:
9494
for (uint i = 0; i < forces().item_count(); ++i)
9595
{
96-
ShaderEntity entity = load_entity(forces().first_item() + i);
96+
const uint entity_index = forces().first_item() + i;
97+
ShaderEntity entity = load_entity(entity_index);
9798

9899
[branch]
99100
if (entity.layerMask & xEmitterLayerMask)
@@ -162,7 +163,7 @@ void main(uint3 DTid : SV_DispatchThreadID, uint Gid : SV_GroupIndex)
162163
dist = dist - particleSize;
163164
if (dist < 0)
164165
{
165-
float4x4 planeProjection = load_entitymatrix(entity.GetMatrixIndex());
166+
float4x4 planeProjection = load_entitymatrix(entity_index);
166167
const float3 clipSpacePos = mul(planeProjection, float4(particle.position, 1)).xyz;
167168
const float3 uvw = clipspace_to_uvw(clipSpacePos.xyz);
168169
[branch]

WickedEngine/shaders/hairparticle_simulateCS.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ void main(uint3 DTid : SV_DispatchThreadID, uint3 Gid : SV_GroupID, uint groupIn
311311
dist = dist - segment_radius;
312312
if (dist < 0)
313313
{
314-
float4x4 planeProjection = load_entitymatrix(entity.GetMatrixIndex());
314+
float4x4 planeProjection = load_entitymatrix(i);
315315
const float3 clipSpacePos = mul(planeProjection, float4(closest_point, 1)).xyz;
316316
const float3 uvw = clipspace_to_uvw(clipSpacePos.xyz);
317317
[branch]

WickedEngine/shaders/lightCullingCS.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ void main(uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid :
250250

251251
// frustum AABB in world space transformed into the space of the probe/decal OBB:
252252
AABB b = GroupAABB_WS;
253-
AABBtransform(b, load_entitymatrix(entity.GetMatrixIndex()));
253+
AABBtransform(b, load_entitymatrix(i));
254254

255255
if (IntersectAABB(a, b))
256256
{
@@ -280,7 +280,7 @@ void main(uint3 Gid : SV_GroupID, uint3 DTid : SV_DispatchThreadID, uint3 GTid :
280280

281281
// frustum AABB in world space transformed into the space of the probe/decal OBB:
282282
AABB b = GroupAABB_WS;
283-
AABBtransform(b, load_entitymatrix(entity.GetMatrixIndex()));
283+
AABBtransform(b, load_entitymatrix(i));
284284

285285
if (IntersectAABB(a, b))
286286
{

WickedEngine/shaders/lightingHF.hlsli

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ inline void ApplyLighting(in Surface surface, in Lighting lighting, inout half4
5555
}
5656

5757
//#define CASCADE_DITHERING
58-
inline void light_directional(in ShaderEntity light, in Surface surface, inout Lighting lighting, in half shadow_mask = 1)
58+
inline void light_directional(in ShaderEntity light, in uint entity_index, in Surface surface, inout Lighting lighting, in half shadow_mask = 1)
5959
{
6060
if (shadow_mask <= 0.001)
6161
return; // shadow mask zero
@@ -186,7 +186,7 @@ inline half attenuation_pointlight(in half dist2, in half range, in half range2)
186186
dist_per_range *= dist_per_range; // pow4
187187
return saturate(1 - dist_per_range) / max(0.0001, dist2);
188188
}
189-
inline void light_point(in ShaderEntity light, in Surface surface, inout Lighting lighting, in half shadow_mask = 1)
189+
inline void light_point(in ShaderEntity light, in uint entity_index, in Surface surface, inout Lighting lighting, in half shadow_mask = 1)
190190
{
191191
if (shadow_mask <= 0.001)
192192
return; // shadow mask zero
@@ -303,7 +303,7 @@ inline half attenuation_spotlight(in half dist2, in half range, in half range2,
303303
attenuation *= angularAttenuation;
304304
return attenuation;
305305
}
306-
inline void light_spot(in ShaderEntity light, in Surface surface, inout Lighting lighting, in half shadow_mask = 1)
306+
inline void light_spot(in ShaderEntity light, in uint entity_index, in Surface surface, inout Lighting lighting, in half shadow_mask = 1)
307307
{
308308
if (shadow_mask <= 0.001)
309309
return; // shadow mask zero
@@ -343,7 +343,7 @@ inline void light_spot(in ShaderEntity light, in Surface surface, inout Lighting
343343
if ((GetFrame().options & OPTION_BIT_RAYTRACED_SHADOWS) == 0 || GetCamera().texture_rtshadow_index < 0 || (GetCamera().options & SHADERCAMERA_OPTION_USE_SHADOW_MASK) == 0)
344344
#endif // SHADOW_MASK_ENABLED
345345
{
346-
float4 shadow_pos = mul(load_entitymatrix(light.GetMatrixIndex() + 0), float4(surface.P, 1));
346+
float4 shadow_pos = mul(load_entitymatrix(entity_index), float4(surface.P, 1));
347347
shadow_pos.xyz /= shadow_pos.w;
348348
float2 shadow_uv = clipspace_to_uv(shadow_pos.xy);
349349
[branch]
@@ -361,7 +361,7 @@ inline void light_spot(in ShaderEntity light, in Surface surface, inout Lighting
361361
[branch]
362362
if (maskTex > 0)
363363
{
364-
float4 shadow_pos = mul(load_entitymatrix(light.GetMatrixIndex() + 0), float4(surface.P, 1));
364+
float4 shadow_pos = mul(load_entitymatrix(entity_index), float4(surface.P, 1));
365365
shadow_pos.xyz /= shadow_pos.w;
366366
float2 shadow_uv = clipspace_to_uv(shadow_pos.xy);
367367
half4 mask = bindless_textures_half4[descriptor_index(maskTex)].SampleLevel(sampler_linear_clamp, shadow_uv, 0);
@@ -394,7 +394,7 @@ inline void light_spot(in ShaderEntity light, in Surface surface, inout Lighting
394394
#endif // LIGHTING_SCATTER
395395
}
396396

397-
inline void light_rect(in ShaderEntity light, in Surface surface, inout Lighting lighting, in half shadow_mask = 1)
397+
inline void light_rect(in ShaderEntity light, in uint entity_index, in Surface surface, inout Lighting lighting, in half shadow_mask = 1)
398398
{
399399
#ifndef DISABLE_AREA_LIGHTS
400400
if (shadow_mask <= 0.001)
@@ -477,7 +477,7 @@ inline void light_rect(in ShaderEntity light, in Surface surface, inout Lighting
477477
if ((GetFrame().options & OPTION_BIT_RAYTRACED_SHADOWS) == 0 || GetCamera().texture_rtshadow_index < 0 || (GetCamera().options & SHADERCAMERA_OPTION_USE_SHADOW_MASK) == 0)
478478
#endif // SHADOW_MASK_ENABLED
479479
{
480-
float4 shadow_pos = mul(load_entitymatrix(light.GetMatrixIndex() + 0), float4(surface.P, 1));
480+
float4 shadow_pos = mul(load_entitymatrix(entity_index), float4(surface.P, 1));
481481
shadow_pos.xyz /= shadow_pos.w;
482482
float2 shadow_uv = clipspace_to_uv(shadow_pos.xy);
483483
[branch]
@@ -513,7 +513,7 @@ inline void light_rect(in ShaderEntity light, in Surface surface, inout Lighting
513513
uint mipcount;
514514
tex.GetDimensions(0, dim.x, dim.y, mipcount);
515515

516-
float4 shadow_pos = mul(load_entitymatrix(light.GetMatrixIndex() + 0), float4(surface.P, 1));
516+
float4 shadow_pos = mul(load_entitymatrix(entity_index), float4(surface.P, 1));
517517
shadow_pos.xyz /= shadow_pos.w;
518518
float2 diffuse_uv = clipspace_to_uv(shadow_pos.xy);
519519
half4 diffuse_mask = tex.SampleLevel(sampler_linear_clamp, diffuse_uv, mipcount - 2);

WickedEngine/shaders/rtdiffuseCS.hlsl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ void main(uint2 DTid : SV_DispatchThreadID)
164164
[loop]
165165
for (uint iterator = 0; iterator < lights().item_count(); iterator++)
166166
{
167-
ShaderEntity light = load_entity(lights().first_item() + iterator);
167+
const uint entity_index = lights().first_item() + iterator;
168+
ShaderEntity light = load_entity(entity_index);
168169
if ((light.layerMask & surface.material.layerMask) == 0)
169170
continue;
170171

@@ -177,22 +178,22 @@ void main(uint2 DTid : SV_DispatchThreadID)
177178
{
178179
case ENTITY_TYPE_DIRECTIONALLIGHT:
179180
{
180-
light_directional(light, surface, lighting);
181+
light_directional(light, entity_index, surface, lighting);
181182
}
182183
break;
183184
case ENTITY_TYPE_POINTLIGHT:
184185
{
185-
light_point(light, surface, lighting);
186+
light_point(light, entity_index, surface, lighting);
186187
}
187188
break;
188189
case ENTITY_TYPE_RECTLIGHT:
189190
{
190-
light_rect(light, surface, lighting);
191+
light_rect(light, entity_index, surface, lighting);
191192
}
192193
break;
193194
case ENTITY_TYPE_SPOTLIGHT:
194195
{
195-
light_spot(light, surface, lighting);
196+
light_spot(light, entity_index, surface, lighting);
196197
}
197198
break;
198199
}

WickedEngine/shaders/rtreflectionCS.hlsl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ void main(uint2 DTid : SV_DispatchThreadID)
170170
[loop]
171171
for (uint iterator = 0; iterator < lights().item_count(); iterator++)
172172
{
173-
ShaderEntity light = load_entity(lights().first_item() + iterator);
173+
const uint entity_index = lights().first_item() + iterator;
174+
ShaderEntity light = load_entity(entity_index);
174175
if ((light.layerMask & surface.material.layerMask) == 0)
175176
continue;
176177

@@ -183,22 +184,22 @@ void main(uint2 DTid : SV_DispatchThreadID)
183184
{
184185
case ENTITY_TYPE_DIRECTIONALLIGHT:
185186
{
186-
light_directional(light, surface, lighting);
187+
light_directional(light, entity_index, surface, lighting);
187188
}
188189
break;
189190
case ENTITY_TYPE_POINTLIGHT:
190191
{
191-
light_point(light, surface, lighting);
192+
light_point(light, entity_index, surface, lighting);
192193
}
193194
break;
194195
case ENTITY_TYPE_RECTLIGHT:
195196
{
196-
light_rect(light, surface, lighting);
197+
light_rect(light, entity_index, surface, lighting);
197198
}
198199
break;
199200
case ENTITY_TYPE_SPOTLIGHT:
200201
{
201-
light_spot(light, surface, lighting);
202+
light_spot(light, entity_index, surface, lighting);
202203
}
203204
break;
204205
}

WickedEngine/shaders/rtreflectionLIB.hlsl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ void RTReflection_ClosestHit(inout RayPayload payload, in BuiltInTriangleInterse
119119
[loop]
120120
for (uint iterator = 0; iterator < lights().item_count(); iterator++)
121121
{
122-
ShaderEntity light = load_entity(lights().first_item() + iterator);
122+
const uint entity_index = lights().first_item() + iterator;
123+
ShaderEntity light = load_entity(entity_index);
123124
if ((light.layerMask & surface.material.layerMask) == 0)
124125
continue;
125126

@@ -132,22 +133,22 @@ void RTReflection_ClosestHit(inout RayPayload payload, in BuiltInTriangleInterse
132133
{
133134
case ENTITY_TYPE_DIRECTIONALLIGHT:
134135
{
135-
light_directional(light, surface, lighting);
136+
light_directional(light, entity_index, surface, lighting);
136137
}
137138
break;
138139
case ENTITY_TYPE_POINTLIGHT:
139140
{
140-
light_point(light, surface, lighting);
141+
light_point(light, entity_index, surface, lighting);
141142
}
142143
break;
143144
case ENTITY_TYPE_RECTLIGHT:
144145
{
145-
light_rect(light, surface, lighting);
146+
light_rect(light, entity_index, surface, lighting);
146147
}
147148
break;
148149
case ENTITY_TYPE_SPOTLIGHT:
149150
{
150-
light_spot(light, surface, lighting);
151+
light_spot(light, entity_index, surface, lighting);
151152
}
152153
break;
153154
}

WickedEngine/shaders/shadingHF.hlsli

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,22 +133,22 @@ inline void ForwardLighting(inout Surface surface, inout Lighting lighting)
133133
{
134134
case ENTITY_TYPE_DIRECTIONALLIGHT:
135135
{
136-
light_directional(light, surface, lighting);
136+
light_directional(light, entity_index, surface, lighting);
137137
}
138138
break;
139139
case ENTITY_TYPE_POINTLIGHT:
140140
{
141-
light_point(light, surface, lighting);
141+
light_point(light, entity_index, surface, lighting);
142142
}
143143
break;
144144
case ENTITY_TYPE_SPOTLIGHT:
145145
{
146-
light_spot(light, surface, lighting);
146+
light_spot(light, entity_index, surface, lighting);
147147
}
148148
break;
149149
case ENTITY_TYPE_RECTLIGHT:
150150
{
151-
light_rect(light, surface, lighting);
151+
light_rect(light, entity_index, surface, lighting);
152152
}
153153
break;
154154
}
@@ -412,7 +412,7 @@ inline void TiledLighting(inout Surface surface, inout Lighting lighting, uint f
412412
}
413413
#endif // SHADOW_MASK_ENABLED && !TRANSPARENT
414414

415-
light_directional(light, surface, lighting, shadow_mask);
415+
light_directional(light, entity_index, surface, lighting, shadow_mask);
416416
}
417417
}
418418

@@ -452,7 +452,7 @@ inline void TiledLighting(inout Surface surface, inout Lighting lighting, uint f
452452
}
453453
#endif // SHADOW_MASK_ENABLED && !TRANSPARENT
454454

455-
light_spot(light, surface, lighting, shadow_mask);
455+
light_spot(light, entity_index, surface, lighting, shadow_mask);
456456

457457
}
458458
}
@@ -494,7 +494,7 @@ inline void TiledLighting(inout Surface surface, inout Lighting lighting, uint f
494494
}
495495
#endif // SHADOW_MASK_ENABLED && !TRANSPARENT
496496

497-
light_point(light, surface, lighting, shadow_mask);
497+
light_point(light, entity_index, surface, lighting, shadow_mask);
498498

499499
}
500500
}
@@ -536,7 +536,7 @@ inline void TiledLighting(inout Surface surface, inout Lighting lighting, uint f
536536
}
537537
#endif // SHADOW_MASK_ENABLED && !TRANSPARENT
538538

539-
light_rect(light, surface, lighting, shadow_mask);
539+
light_rect(light, entity_index, surface, lighting, shadow_mask);
540540

541541
}
542542
}

WickedEngine/shaders/volumetricLight_SpotPS.hlsl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ bool intersectInfiniteCone(float3 p, float3 v, float3 pa, float3 va, float sina2
3939

4040
float4 main(VertexToPixel input) : SV_TARGET
4141
{
42-
ShaderEntity light = load_entity(spotlights().first_item() + (uint)g_xColor.x);
42+
const uint entity_index = spotlights().first_item() + (uint)g_xColor.x;
43+
ShaderEntity light = load_entity(entity_index);
4344

4445
float2 ScreenCoord = input.pos2D.xy / input.pos2D.w * float2(0.5, -0.5) + 0.5;
4546
float4 depths = texture_depth.GatherRed(sampler_point_clamp, ScreenCoord);
@@ -112,7 +113,7 @@ float4 main(VertexToPixel input) : SV_TARGET
112113
[branch]
113114
if (light.IsCastingShadow())
114115
{
115-
float4 shadow_pos = mul(load_entitymatrix(light.GetMatrixIndex() + 0), float4(P, 1));
116+
float4 shadow_pos = mul(load_entitymatrix(entity_index), float4(P, 1));
116117
shadow_pos.xyz /= shadow_pos.w;
117118
float2 shadow_uv = shadow_pos.xy * float2(0.5f, -0.5f) + float2(0.5f, 0.5f);
118119
[branch]
@@ -125,7 +126,7 @@ float4 main(VertexToPixel input) : SV_TARGET
125126
[branch]
126127
if (maskTex > 0)
127128
{
128-
float4 shadow_pos = mul(load_entitymatrix(light.GetMatrixIndex() + 0), float4(P, 1));
129+
float4 shadow_pos = mul(load_entitymatrix(entity_index), float4(P, 1));
129130
shadow_pos.xyz /= shadow_pos.w;
130131
float2 shadow_uv = shadow_pos.xy * float2(0.5f, -0.5f) + float2(0.5f, 0.5f);
131132
half4 mask = bindless_textures_half4[descriptor_index(maskTex)].Sample(sampler_linear_clamp, shadow_uv);

0 commit comments

Comments
 (0)