diff options
Diffstat (limited to 'servers/visual/rasterizer_rd/shaders')
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/SCsub | 2 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/scene_high_end.glsl (renamed from servers/visual/rasterizer_rd/shaders/scene_forward.glsl) | 56 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/scene_high_end_inc.glsl (renamed from servers/visual/rasterizer_rd/shaders/scene_forward_inc.glsl) | 17 |
3 files changed, 33 insertions, 42 deletions
diff --git a/servers/visual/rasterizer_rd/shaders/SCsub b/servers/visual/rasterizer_rd/shaders/SCsub index 194d7d6c0e..6151d9bd9f 100644 --- a/servers/visual/rasterizer_rd/shaders/SCsub +++ b/servers/visual/rasterizer_rd/shaders/SCsub @@ -7,7 +7,7 @@ if 'RD_GLSL' in env['BUILDERS']: env.RD_GLSL('canvas_occlusion.glsl'); env.RD_GLSL('blur.glsl'); env.RD_GLSL('cubemap_roughness.glsl'); - env.RD_GLSL('scene_forward.glsl'); + env.RD_GLSL('scene_high_end.glsl'); env.RD_GLSL('sky.glsl'); env.RD_GLSL('tonemap.glsl'); env.RD_GLSL('copy.glsl'); diff --git a/servers/visual/rasterizer_rd/shaders/scene_forward.glsl b/servers/visual/rasterizer_rd/shaders/scene_high_end.glsl index e4addc6fb5..7b36f24010 100644 --- a/servers/visual/rasterizer_rd/shaders/scene_forward.glsl +++ b/servers/visual/rasterizer_rd/shaders/scene_high_end.glsl @@ -5,7 +5,7 @@ VERSION_DEFINES -#include "scene_forward_inc.glsl" +#include "scene_high_end_inc.glsl" /* INPUT ATTRIBS */ @@ -276,7 +276,7 @@ VERTEX_SHADER_CODE VERSION_DEFINES -#include "scene_forward_inc.glsl" +#include "scene_high_end_inc.glsl" /* Varyings */ @@ -1236,9 +1236,7 @@ void main() { float normaldepth = 1.0; -#if defined(SCREEN_UV_USED) vec2 screen_uv = gl_FragCoord.xy * scene_data.screen_pixel_size; -#endif float sss_strength = 0.0; @@ -1394,23 +1392,20 @@ FRAGMENT_SHADER_CODE } } #endif + + uvec4 cluster_cell = texture(usampler3D(cluster_texture, material_samplers[SAMPLER_NEAREST_CLAMP]),vec3(screen_uv,(abs(vertex.z)-scene_data.z_near)/(scene_data.z_far-scene_data.z_near))); + { // process reflections vec4 reflection_accum = vec4(0.0, 0.0, 0.0, 0.0); vec4 ambient_accum = vec4(0.0, 0.0, 0.0, 0.0); - uint reflection_probe_count = instances.data[instance_index].flags & INSTANCE_FLAGS_FORWARD_MASK; + uint reflection_probe_count = cluster_cell.z >> CLUSTER_COUNTER_SHIFT; + uint reflection_probe_pointer = cluster_cell.z & CLUSTER_POINTER_MASK; for (uint i = 0; i < reflection_probe_count; i++) { - uint ref_index = instances.data[instance_index].reflection_probe_indices[i >> 1]; - - if (bool(i & 1)) { - ref_index >>= 16; - } else { - ref_index &= 0xFFFF; - } - + uint ref_index = cluster_data.indices[reflection_probe_pointer + i]; reflection_process(ref_index, vertex, normal, roughness, ambient_light, specular_light, ambient_accum, reflection_accum); } @@ -1527,22 +1522,18 @@ FRAGMENT_SHADER_CODE } { //omni lights - uint omni_light_count = (instances.data[instance_index].flags >> INSTANCE_FLAGS_FORWARD_OMNI_LIGHT_SHIFT) & INSTANCE_FLAGS_FORWARD_MASK; + + uint omni_light_count = cluster_cell.x >> CLUSTER_COUNTER_SHIFT; + uint omni_light_pointer = cluster_cell.x & CLUSTER_POINTER_MASK; + for (uint i = 0; i < omni_light_count; i++) { - uint light_index = instances.data[instance_index].omni_light_indices[i >> 1]; + uint light_index = cluster_data.indices[omni_light_pointer + i]; - if (bool(i & 1)) { - light_index >>= 16; - } else { - light_index &= 0xFFFF; + if (!bool(lights.data[light_index].mask&instances.data[instance_index].layer_mask)) { + continue; //not masked } - //this is done on CPU, so no need to do it here - //if (!bool(lights.data[light_index].mask&instances.data[instance_index].layer_mask)) { - // continue; //not masked - //} - light_process_omni(light_index, vertex, view, normal, albedo, roughness, metallic, specular, specular_blob_intensity, #ifdef LIGHT_TRANSMISSION_USED transmission, @@ -1565,22 +1556,17 @@ FRAGMENT_SHADER_CODE } { //spot lights - uint spot_light_count = (instances.data[instance_index].flags >> INSTANCE_FLAGS_FORWARD_SPOT_LIGHT_SHIFT) & INSTANCE_FLAGS_FORWARD_MASK; + uint spot_light_count = cluster_cell.y >> CLUSTER_COUNTER_SHIFT; + uint spot_light_pointer = cluster_cell.y & CLUSTER_POINTER_MASK; + for (uint i = 0; i < spot_light_count; i++) { - uint light_index = instances.data[instance_index].spot_light_indices[i >> 1]; + uint light_index = cluster_data.indices[spot_light_pointer + i]; - if (bool(i & 1)) { - light_index >>= 16; - } else { - light_index &= 0xFFFF; + if (!bool(lights.data[light_index].mask&instances.data[instance_index].layer_mask)) { + continue; //not masked } - //this is done on CPU, so no need to do it here - //if (!bool(lights.data[light_index].mask&instances.data[instance_index].layer_mask)) { - // continue; //not masked - //} - light_process_spot(light_index, vertex, view, normal, albedo, roughness, metallic, specular, specular_blob_intensity, #ifdef LIGHT_TRANSMISSION_USED transmission, diff --git a/servers/visual/rasterizer_rd/shaders/scene_forward_inc.glsl b/servers/visual/rasterizer_rd/shaders/scene_high_end_inc.glsl index 5701781808..6ad5559b08 100644 --- a/servers/visual/rasterizer_rd/shaders/scene_forward_inc.glsl +++ b/servers/visual/rasterizer_rd/shaders/scene_high_end_inc.glsl @@ -58,7 +58,7 @@ layout(set = 0, binding = 3, std140) uniform SceneData { uint directional_light_count; float dual_paraboloid_side; float z_far; - uint pad0; + float z_near; #if 0 vec4 ambient_light_color; @@ -118,11 +118,6 @@ struct InstanceData { uint instance_ofs; //instance_offset in instancing/skeleton buffer uint gi_offset; //GI information when using lightmapping (VCT or lightmap) uint layer_mask; - - uint reflection_probe_indices[4]; - uint omni_light_indices[4]; - uint spot_light_indices[4]; - uint decal_indices[4]; }; layout(set = 0, binding = 4, std430) buffer Instances { @@ -206,6 +201,16 @@ layout(set = 0, binding = 8, std140) uniform GIProbes { layout(set = 0, binding = 9) uniform texture3D gi_probe_textures[MAX_GI_PROBE_TEXTURES]; +#define CLUSTER_COUNTER_SHIFT 20 +#define CLUSTER_POINTER_MASK ((1 << CLUSTER_COUNTER_SHIFT) - 1) +#define CLUSTER_COUNTER_MASK 0xfff + +layout(set = 0, binding = 10) uniform utexture3D cluster_texture; + +layout(set = 0, binding = 11, std430) buffer ClusterData { + uint indices[]; +} cluster_data; + /* Set 1, Scene data that changes per render pass */ layout(set = 1, binding = 0) uniform texture2D depth_buffer; |