35 eShadowProjectionType projection_type)
38 object_to_world.x.w = 0.0f;
39 object_to_world.y.w = 0.0f;
40 object_to_world.z.w = 0.0f;
42 int clip_index =
tilemaps_buf[tilemap_id].clip_data_index;
47 !transform_equal(object_to_world_history, object_to_world))
63 float half_size = level_size / 2.0f;
64 float tile_size = level_size /
float(SHADOW_TILEMAP_RES);
65 float2 center_offset =
float2(origin_offset) * tile_size;
74 tilemaps_buf[tilemap_id].projection_type = projection_type;
78 -half_size + center_offset.
x,
79 half_size + center_offset.
x,
80 -half_size + center_offset.
y,
81 half_size + center_offset.
y,
89 int level_min =
light.sun.clipmap_lod_min;
90 int level_max =
light.sun.clipmap_lod_max;
91 int level_range = level_max - level_min;
92 int level_len = level_range + 1;
101 float half_size = level_size / 2.0f;
102 float tile_size = level_size /
float(SHADOW_TILEMAP_RES);
105 float3 ws_far_point = ws_camera_position - ws_camera_forward * camera_clip_far;
106 float3 ws_near_point = ws_camera_position - ws_camera_forward * camera_clip_near;
111 float2 local_view_direction =
normalize(ls_far_point.xy - ls_near_point.xy);
112 float2 farthest_tilemap_center = local_view_direction * half_size * level_range;
115 light.object_to_world.x.w = ls_near_point.
x;
116 light.object_to_world.y.w = ls_near_point.
y;
117 light.object_to_world.z.w = ls_near_point.
z;
120 int2 origin_offset =
int2(
round(ls_near_point.xy / tile_size));
122 int2 offset_vector =
int2(
round(farthest_tilemap_center / tile_size));
124 int2 base_offset_pos = (offset_vector * (1 << 16)) /
max(level_range, 1);
127 for (
int i = 0; i < level_len; i++) {
129 int2 level_offset = origin_offset + shadow_cascade_grid_offset(base_offset_pos, i);
132 light.object_to_world,
135 SHADOW_PROJECTION_CASCADE);
138 float2 clipmap_origin =
float2(origin_offset) * tile_size;
140 LightSunData sun_data =
light.sun;
142 sun_data.clipmap_origin = clipmap_origin;
144 sun_data.clipmap_base_offset_pos = base_offset_pos;
145 sun_data.clipmap_base_offset_neg =
int2(0);
147 light.sun = sun_data;
156 int level_min =
light.sun.clipmap_lod_min;
157 int level_max =
light.sun.clipmap_lod_max;
158 int level_len = level_max - level_min + 1;
161 for (
int lod = 0; lod < level_len; lod++) {
162 int level = level_min + lod;
165 float tile_size =
float(1 << level) /
float(SHADOW_TILEMAP_RES);
166 int2 level_offset =
int2(
round(ls_camera_position.xy / tile_size));
169 light.object_to_world,
172 SHADOW_PROJECTION_CLIPMAP);
174 clipmap_origin =
float2(level_offset) * tile_size;
179 for (
int lod = 0; lod < level_len - 1; lod++) {
187 int2 lvl_delta = lvl_offset - (lvl_offset_next * 2);
188 pos_offset |=
max(lvl_delta,
int2(0)) << lod;
189 neg_offset |=
max(-lvl_delta,
int2(0)) << lod;
193 light.object_to_world.x.w = ls_camera_position.
x;
194 light.object_to_world.y.w = ls_camera_position.
y;
195 light.object_to_world.z.w = ls_camera_position.
z;
197 LightSunData sun_data =
light.sun;
199 sun_data.clipmap_origin = clipmap_origin;
201 sun_data.clipmap_base_offset_pos = pos_offset;
202 sun_data.clipmap_base_offset_neg = neg_offset;
204 light.sun = sun_data;
213 object_to_world.x.w = world_jitter_offset.
x;
214 object_to_world.y.w = world_jitter_offset.
y;
215 object_to_world.z.w = world_jitter_offset.
z;
217 int clip_index =
tilemaps_buf[tilemap_id].clip_data_index;
221 !transform_equal(object_to_world_history, object_to_world))
235 viewmat = to_float4x4(
float3x3(+1, +0, +0, +0, +1, +0, +0, +0, +1)) * viewmat;
238 viewmat = to_float4x4(
float3x3(+0, +0, -1, -1, +0, +0, +0, +1, +0)) * viewmat;
241 viewmat = to_float4x4(
float3x3(+0, +0, +1, +1, +0, +0, +0, +1, +0)) * viewmat;
244 viewmat = to_float4x4(
float3x3(+1, +0, +0, +0, +0, -1, +0, +1, +0)) * viewmat;
247 viewmat = to_float4x4(
float3x3(-1, +0, +0, +0, +0, +1, +0, +1, +0)) * viewmat;
250 viewmat = to_float4x4(
float3x3(+1, +0, +0, +0, -1, +0, +0, +0, -1)) * viewmat;
257 tilemaps_buf[tilemap_id].corners[0].xyz += jitter_offset;
258 tilemaps_buf[tilemap_id].corners[1].xyz += jitter_offset;