diff options
author | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2021-11-24 09:14:19 +0200 |
---|---|---|
committer | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2021-11-24 09:16:16 +0200 |
commit | 5e0a034524c25e9b06869e323a8a6313223330b8 (patch) | |
tree | ad9ca6403ab95ffbb5f8b1c76f9dc565a7b0481e /servers/rendering/renderer_rd/shaders/volumetric_fog_process.glsl | |
parent | 5efe80f3085c8c6451363fe4c743bf3d7fc20b6c (diff) |
[macOS / iOS] Use storage buffers instead of unsupported images for the volumetric fog on MoltenVK.
Diffstat (limited to 'servers/rendering/renderer_rd/shaders/volumetric_fog_process.glsl')
-rw-r--r-- | servers/rendering/renderer_rd/shaders/volumetric_fog_process.glsl | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/servers/rendering/renderer_rd/shaders/volumetric_fog_process.glsl b/servers/rendering/renderer_rd/shaders/volumetric_fog_process.glsl index 3d6fbb5653..747f88960c 100644 --- a/servers/rendering/renderer_rd/shaders/volumetric_fog_process.glsl +++ b/servers/rendering/renderer_rd/shaders/volumetric_fog_process.glsl @@ -190,9 +190,22 @@ params; #ifndef MODE_COPY layout(set = 0, binding = 15) uniform texture3D prev_density_texture; +#ifdef MOLTENVK_USED +layout(set = 0, binding = 16) buffer density_only_map_buffer { + uint density_only_map[]; +}; +layout(set = 0, binding = 17) buffer light_only_map_buffer { + uint light_only_map[]; +}; +layout(set = 0, binding = 18) buffer emissive_only_map_buffer { + uint emissive_only_map[]; +}; +#else layout(r32ui, set = 0, binding = 16) uniform uimage3D density_only_map; layout(r32ui, set = 0, binding = 17) uniform uimage3D light_only_map; layout(r32ui, set = 0, binding = 18) uniform uimage3D emissive_only_map; +#endif + #ifdef USE_RADIANCE_CUBEMAP_ARRAY layout(set = 0, binding = 19) uniform textureCubeArray sky_texture; #else @@ -272,6 +285,9 @@ void main() { if (any(greaterThanEqual(pos, params.fog_volume_size))) { return; //do not compute } +#ifdef MOLTENVK_USED + uint lpos = pos.z * params.fog_volume_size.x * params.fog_volume_size.y + pos.y * params.fog_volume_size.x + pos.x; +#endif vec3 posf = vec3(pos); @@ -335,15 +351,28 @@ void main() { vec3 total_light = vec3(0.0); float total_density = params.base_density; +#ifdef MOLTENVK_USED + uint local_density = density_only_map[lpos]; +#else uint local_density = imageLoad(density_only_map, pos).x; +#endif + total_density += float(int(local_density)) / DENSITY_SCALE; total_density = max(0.0, total_density); +#ifdef MOLTENVK_USED + uint scattering_u = light_only_map[lpos]; +#else uint scattering_u = imageLoad(light_only_map, pos).x; +#endif vec3 scattering = vec3(scattering_u >> 21, (scattering_u << 11) >> 21, scattering_u % 1024) / vec3(2047.0, 2047.0, 1023.0); scattering += params.base_scattering * params.base_density; +#ifdef MOLTENVK_USED + uint emission_u = emissive_only_map[lpos]; +#else uint emission_u = imageLoad(emissive_only_map, pos).x; +#endif vec3 emission = vec3(emission_u >> 21, (emission_u << 11) >> 21, emission_u % 1024) / vec3(511.0, 511.0, 255.0); emission += params.base_emission * params.base_density; @@ -673,10 +702,16 @@ void main() { final_density = mix(final_density, reprojected_density, reproject_amount); imageStore(density_map, pos, final_density); +#ifdef MOLTENVK_USED + density_only_map[lpos] = 0; + light_only_map[lpos] = 0; + emissive_only_map[lpos] = 0; +#else imageStore(density_only_map, pos, uvec4(0)); imageStore(light_only_map, pos, uvec4(0)); imageStore(emissive_only_map, pos, uvec4(0)); #endif +#endif #ifdef MODE_FOG |