|
@@ -47,7 +47,13 @@ layout(push_constant, binding = 0, std430) uniform Params {
|
|
}
|
|
}
|
|
params;
|
|
params;
|
|
|
|
|
|
|
|
+#ifdef MOLTENVK_USED
|
|
|
|
+layout(set = 1, binding = 1) volatile buffer emissive_only_map_buffer {
|
|
|
|
+ uint emissive_only_map[];
|
|
|
|
+};
|
|
|
|
+#else
|
|
layout(r32ui, set = 1, binding = 1) uniform volatile uimage3D emissive_only_map;
|
|
layout(r32ui, set = 1, binding = 1) uniform volatile uimage3D emissive_only_map;
|
|
|
|
+#endif
|
|
|
|
|
|
layout(set = 1, binding = 2, std140) uniform SceneParams {
|
|
layout(set = 1, binding = 2, std140) uniform SceneParams {
|
|
vec2 fog_frustum_size_begin;
|
|
vec2 fog_frustum_size_begin;
|
|
@@ -71,8 +77,17 @@ layout(set = 1, binding = 2, std140) uniform SceneParams {
|
|
}
|
|
}
|
|
scene_params;
|
|
scene_params;
|
|
|
|
|
|
|
|
+#ifdef MOLTENVK_USED
|
|
|
|
+layout(set = 1, binding = 3) volatile buffer density_only_map_buffer {
|
|
|
|
+ uint density_only_map[];
|
|
|
|
+};
|
|
|
|
+layout(set = 1, binding = 4) volatile buffer light_only_map_buffer {
|
|
|
|
+ uint light_only_map[];
|
|
|
|
+};
|
|
|
|
+#else
|
|
layout(r32ui, set = 1, binding = 3) uniform volatile uimage3D density_only_map;
|
|
layout(r32ui, set = 1, binding = 3) uniform volatile uimage3D density_only_map;
|
|
layout(r32ui, set = 1, binding = 4) uniform volatile uimage3D light_only_map;
|
|
layout(r32ui, set = 1, binding = 4) uniform volatile uimage3D light_only_map;
|
|
|
|
+#endif
|
|
|
|
|
|
#ifdef MATERIAL_UNIFORMS_USED
|
|
#ifdef MATERIAL_UNIFORMS_USED
|
|
layout(set = 2, binding = 0, std140) uniform MaterialUniforms{
|
|
layout(set = 2, binding = 0, std140) uniform MaterialUniforms{
|
|
@@ -115,6 +130,9 @@ void main() {
|
|
if (any(greaterThanEqual(pos, scene_params.fog_volume_size))) {
|
|
if (any(greaterThanEqual(pos, scene_params.fog_volume_size))) {
|
|
return; //do not compute
|
|
return; //do not compute
|
|
}
|
|
}
|
|
|
|
+#ifdef MOLTENVK_USED
|
|
|
|
+ uint lpos = pos.z * scene_params.fog_volume_size.x * scene_params.fog_volume_size.y + pos.y * scene_params.fog_volume_size.x + pos.x;
|
|
|
|
+#endif
|
|
|
|
|
|
vec3 posf = vec3(pos);
|
|
vec3 posf = vec3(pos);
|
|
|
|
|
|
@@ -197,7 +215,11 @@ void main() {
|
|
density *= cull_mask;
|
|
density *= cull_mask;
|
|
if (abs(density) > 0.001) {
|
|
if (abs(density) > 0.001) {
|
|
int final_density = int(density * DENSITY_SCALE);
|
|
int final_density = int(density * DENSITY_SCALE);
|
|
|
|
+#ifdef MOLTENVK_USED
|
|
|
|
+ atomicAdd(density_only_map[lpos], uint(final_density));
|
|
|
|
+#else
|
|
imageAtomicAdd(density_only_map, pos, uint(final_density));
|
|
imageAtomicAdd(density_only_map, pos, uint(final_density));
|
|
|
|
+#endif
|
|
|
|
|
|
#ifdef EMISSION_USED
|
|
#ifdef EMISSION_USED
|
|
{
|
|
{
|
|
@@ -207,7 +229,11 @@ void main() {
|
|
uvec3 emission_u = uvec3(emission.r * 511.0, emission.g * 511.0, emission.b * 255.0);
|
|
uvec3 emission_u = uvec3(emission.r * 511.0, emission.g * 511.0, emission.b * 255.0);
|
|
// R and G have 11 bits each and B has 10. Then pack them into a 32 bit uint
|
|
// R and G have 11 bits each and B has 10. Then pack them into a 32 bit uint
|
|
uint final_emission = emission_u.r << 21 | emission_u.g << 10 | emission_u.b;
|
|
uint final_emission = emission_u.r << 21 | emission_u.g << 10 | emission_u.b;
|
|
|
|
+#ifdef MOLTENVK_USED
|
|
|
|
+ uint prev_emission = atomicAdd(emissive_only_map[lpos], final_emission);
|
|
|
|
+#else
|
|
uint prev_emission = imageAtomicAdd(emissive_only_map, pos, final_emission);
|
|
uint prev_emission = imageAtomicAdd(emissive_only_map, pos, final_emission);
|
|
|
|
+#endif
|
|
|
|
|
|
// Adding can lead to colors overflowing, so validate
|
|
// Adding can lead to colors overflowing, so validate
|
|
uvec3 prev_emission_u = uvec3(prev_emission >> 21, (prev_emission << 11) >> 21, prev_emission % 1024);
|
|
uvec3 prev_emission_u = uvec3(prev_emission >> 21, (prev_emission << 11) >> 21, prev_emission % 1024);
|
|
@@ -219,7 +245,11 @@ void main() {
|
|
if (any(overflowing)) {
|
|
if (any(overflowing)) {
|
|
uvec3 overflow_factor = mix(uvec3(0), uvec3(2047 << 21, 2047 << 10, 1023), overflowing);
|
|
uvec3 overflow_factor = mix(uvec3(0), uvec3(2047 << 21, 2047 << 10, 1023), overflowing);
|
|
uint force_max = overflow_factor.r | overflow_factor.g | overflow_factor.b;
|
|
uint force_max = overflow_factor.r | overflow_factor.g | overflow_factor.b;
|
|
|
|
+#ifdef MOLTENVK_USED
|
|
|
|
+ atomicOr(emissive_only_map[lpos], force_max);
|
|
|
|
+#else
|
|
imageAtomicOr(emissive_only_map, pos, force_max);
|
|
imageAtomicOr(emissive_only_map, pos, force_max);
|
|
|
|
+#endif
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
@@ -230,7 +260,11 @@ void main() {
|
|
uvec3 scattering_u = uvec3(scattering.r * 2047.0, scattering.g * 2047.0, scattering.b * 1023.0);
|
|
uvec3 scattering_u = uvec3(scattering.r * 2047.0, scattering.g * 2047.0, scattering.b * 1023.0);
|
|
// R and G have 11 bits each and B has 10. Then pack them into a 32 bit uint
|
|
// R and G have 11 bits each and B has 10. Then pack them into a 32 bit uint
|
|
uint final_scattering = scattering_u.r << 21 | scattering_u.g << 10 | scattering_u.b;
|
|
uint final_scattering = scattering_u.r << 21 | scattering_u.g << 10 | scattering_u.b;
|
|
|
|
+#ifdef MOLTENVK_USED
|
|
|
|
+ uint prev_scattering = atomicAdd(light_only_map[lpos], final_scattering);
|
|
|
|
+#else
|
|
uint prev_scattering = imageAtomicAdd(light_only_map, pos, final_scattering);
|
|
uint prev_scattering = imageAtomicAdd(light_only_map, pos, final_scattering);
|
|
|
|
+#endif
|
|
|
|
|
|
// Adding can lead to colors overflowing, so validate
|
|
// Adding can lead to colors overflowing, so validate
|
|
uvec3 prev_scattering_u = uvec3(prev_scattering >> 21, (prev_scattering << 11) >> 21, prev_scattering % 1024);
|
|
uvec3 prev_scattering_u = uvec3(prev_scattering >> 21, (prev_scattering << 11) >> 21, prev_scattering % 1024);
|
|
@@ -242,7 +276,11 @@ void main() {
|
|
if (any(overflowing)) {
|
|
if (any(overflowing)) {
|
|
uvec3 overflow_factor = mix(uvec3(0), uvec3(2047 << 21, 2047 << 10, 1023), overflowing);
|
|
uvec3 overflow_factor = mix(uvec3(0), uvec3(2047 << 21, 2047 << 10, 1023), overflowing);
|
|
uint force_max = overflow_factor.r | overflow_factor.g | overflow_factor.b;
|
|
uint force_max = overflow_factor.r | overflow_factor.g | overflow_factor.b;
|
|
|
|
+#ifdef MOLTENVK_USED
|
|
|
|
+ atomicOr(light_only_map[lpos], force_max);
|
|
|
|
+#else
|
|
imageAtomicOr(light_only_map, pos, force_max);
|
|
imageAtomicOr(light_only_map, pos, force_max);
|
|
|
|
+#endif
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endif // ALBEDO_USED
|
|
#endif // ALBEDO_USED
|