diff options
Diffstat (limited to 'servers/visual/rasterizer_rd/shaders')
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/blur.glsl | 63 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/blur_inc.glsl | 19 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/canvas.glsl | 330 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/canvas_occlusion.glsl | 11 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/canvas_uniforms_inc.glsl | 30 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/copy.glsl | 24 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/cubemap_roughness.glsl | 26 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/giprobe.glsl | 414 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/giprobe_debug.glsl | 139 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/giprobe_sdf.glsl | 116 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/giprobe_write.glsl | 155 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/scene_forward.glsl | 423 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/scene_forward_inc.glsl | 60 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/sky.glsl | 26 | ||||
-rw-r--r-- | servers/visual/rasterizer_rd/shaders/tonemap.glsl | 56 |
15 files changed, 826 insertions, 1066 deletions
diff --git a/servers/visual/rasterizer_rd/shaders/blur.glsl b/servers/visual/rasterizer_rd/shaders/blur.glsl index 5907e911a3..3f67638a45 100644 --- a/servers/visual/rasterizer_rd/shaders/blur.glsl +++ b/servers/visual/rasterizer_rd/shaders/blur.glsl @@ -1,68 +1,62 @@ /* clang-format off */ [vertex] -/* clang-format on */ #version 450 -/* clang-format off */ VERSION_DEFINES -/* clang-format on */ #include "blur_inc.glsl" -layout(location =0) out vec2 uv_interp; +layout(location = 0) out vec2 uv_interp; +/* clang-format on */ void main() { - vec2 base_arr[4] = vec2[](vec2(0.0,0.0),vec2(0.0,1.0),vec2(1.0,1.0),vec2(1.0,0.0)); + vec2 base_arr[4] = vec2[](vec2(0.0, 0.0), vec2(0.0, 1.0), vec2(1.0, 1.0), vec2(1.0, 0.0)); uv_interp = base_arr[gl_VertexIndex]; - if (bool(blur.flags&FLAG_USE_BLUR_SECTION)) { + if (bool(blur.flags & FLAG_USE_BLUR_SECTION)) { uv_interp = blur.section.xy + uv_interp * blur.section.zw; } - gl_Position = vec4( uv_interp *2.0 - 1.0, 0.0, 1.0); + gl_Position = vec4(uv_interp * 2.0 - 1.0, 0.0, 1.0); - if (bool(blur.flags&FLAG_FLIP_Y)) { + if (bool(blur.flags & FLAG_FLIP_Y)) { uv_interp.y = 1.0 - uv_interp.y; } - } /* clang-format off */ [fragment] -/* clang-format on */ #version 450 -/* clang-format off */ VERSION_DEFINES -/* clang-format on */ #include "blur_inc.glsl" -layout(location =0) in vec2 uv_interp; +layout(location = 0) in vec2 uv_interp; +/* clang-format on */ -layout( set=0, binding=0 ) uniform sampler2D source_color; +layout(set = 0, binding = 0) uniform sampler2D source_color; #ifdef MODE_SSAO_MERGE -layout( set=1, binding=0 ) uniform sampler2D source_ssao; +layout(set = 1, binding = 0) uniform sampler2D source_ssao; #endif #ifdef GLOW_USE_AUTO_EXPOSURE -layout( set=1, binding=0 ) uniform sampler2D source_auto_exposure; +layout(set = 1, binding = 0) uniform sampler2D source_auto_exposure; #endif - layout(location = 0) out vec4 frag_color; //DOF #if defined(MODE_DOF_FAR_BLUR) || defined(MODE_DOF_NEAR_BLUR) -layout( set=1, binding=0 ) uniform sampler2D dof_source_depth; +layout(set = 1, binding = 0) uniform sampler2D dof_source_depth; #ifdef DOF_NEAR_BLUR_MERGE -layout( set=2, binding=0 ) uniform sampler2D source_dof_original; +layout(set = 2, binding = 0) uniform sampler2D source_dof_original; #endif #ifdef DOF_QUALITY_LOW @@ -86,16 +80,15 @@ const float dof_kernel[21] = float[](0.028174, 0.032676, 0.037311, 0.041944, 0.0 #endif - void main() { #ifdef MODE_MIPMAP vec2 pix_size = blur.pixel_size; - vec4 color = texture(source_color, uv_interp + vec2(-0.5,-0.5) * pix_size); - color += texture(source_color, uv_interp + vec2(0.5,-0.5) * pix_size); - color += texture(source_color, uv_interp + vec2(0.5,0.5) * pix_size); - color += texture(source_color, uv_interp + vec2(-0.5,0.5) * pix_size); + vec4 color = texture(source_color, uv_interp + vec2(-0.5, -0.5) * pix_size); + color += texture(source_color, uv_interp + vec2(0.5, -0.5) * pix_size); + color += texture(source_color, uv_interp + vec2(0.5, 0.5) * pix_size); + color += texture(source_color, uv_interp + vec2(-0.5, 0.5) * pix_size); frag_color = color / 4.0; #endif @@ -104,7 +97,7 @@ void main() { //Simpler blur uses SIGMA2 for the gaussian kernel for a stronger effect - if (bool(blur.flags&FLAG_HORIZONTAL)) { + if (bool(blur.flags & FLAG_HORIZONTAL)) { vec2 pix_size = blur.pixel_size; pix_size *= 0.5; //reading from larger buffer, so use more samples @@ -128,13 +121,11 @@ void main() { } #endif - - #ifdef MODE_GAUSSIAN_GLOW //Glow uses larger sigma 1 for a more rounded blur effect - if (bool(blur.flags&FLAG_HORIZONTAL)) { + if (bool(blur.flags & FLAG_HORIZONTAL)) { vec2 pix_size = blur.pixel_size; pix_size *= 0.5; //reading from larger buffer, so use more samples @@ -159,8 +150,7 @@ void main() { frag_color = color; } - - if (bool(blur.flags&FLAG_GLOW_FIRST_PASS)) { + if (bool(blur.flags & FLAG_GLOW_FIRST_PASS)) { #ifdef GLOW_USE_AUTO_EXPOSURE frag_color /= texelFetch(source_auto_exposure, ivec2(0, 0), 0).r / blur.glow_auto_exposure_grey; @@ -173,7 +163,6 @@ void main() { frag_color = min(frag_color * feedback, vec4(blur.glow_luminance_cap)); } - #endif #ifdef MODE_DOF_FAR_BLUR @@ -183,7 +172,7 @@ void main() { float depth = texture(dof_source_depth, uv_interp, 0.0).r; depth = depth * 2.0 - 1.0; - if (bool(blur.flags&FLAG_USE_ORTHOGONAL_PROJECTION)) { + if (bool(blur.flags & FLAG_USE_ORTHOGONAL_PROJECTION)) { depth = ((depth + (blur.camera_z_far + blur.camera_z_near) / (blur.camera_z_far - blur.camera_z_near)) * (blur.camera_z_far - blur.camera_z_near)) / 2.0; } else { depth = 2.0 * blur.camera_z_near * blur.camera_z_far / (blur.camera_z_far + blur.camera_z_near - depth * (blur.camera_z_far - blur.camera_z_near)); @@ -202,14 +191,14 @@ void main() { float tap_depth = texture(dof_source_depth, tap_uv, 0.0).r; tap_depth = tap_depth * 2.0 - 1.0; - if (bool(blur.flags&FLAG_USE_ORTHOGONAL_PROJECTION)) { + if (bool(blur.flags & FLAG_USE_ORTHOGONAL_PROJECTION)) { tap_depth = ((tap_depth + (blur.camera_z_far + blur.camera_z_near) / (blur.camera_z_far - blur.camera_z_near)) * (blur.camera_z_far - blur.camera_z_near)) / 2.0; } else { tap_depth = 2.0 * blur.camera_z_near * blur.camera_z_far / (blur.camera_z_far + blur.camera_z_near - tap_depth * (blur.camera_z_far - blur.camera_z_near)); } - float tap_amount = mix(smoothstep(blur.dof_begin, blur.dof_end, tap_depth), 1.0, int_ofs == 0); + float tap_amount = mix(smoothstep(blur.dof_begin, blur.dof_end, tap_depth), 1.0, int_ofs == 0); tap_amount *= tap_amount * tap_amount; //prevent undesired glow effect vec4 tap_color = texture(source_color, tap_uv, 0.0) * tap_k; @@ -244,7 +233,7 @@ void main() { float tap_depth = texture(dof_source_depth, tap_uv, 0.0).r; tap_depth = tap_depth * 2.0 - 1.0; - if (bool(blur.flags&FLAG_USE_ORTHOGONAL_PROJECTION)) { + if (bool(blur.flags & FLAG_USE_ORTHOGONAL_PROJECTION)) { tap_depth = ((tap_depth + (blur.camera_z_far + blur.camera_z_near) / (blur.camera_z_far - blur.camera_z_near)) * (blur.camera_z_far - blur.camera_z_near)) / 2.0; } else { @@ -253,7 +242,7 @@ void main() { float tap_amount = 1.0 - smoothstep(blur.dof_end, blur.dof_begin, tap_depth); tap_amount *= tap_amount * tap_amount; //prevent undesired glow effect - if (bool(blur.flags&FLAG_DOF_NEAR_FIRST_TAP)) { + if (bool(blur.flags & FLAG_DOF_NEAR_FIRST_TAP)) { tap_color.a = 1.0 - smoothstep(blur.dof_end, blur.dof_begin, tap_depth); } @@ -271,7 +260,7 @@ void main() { } #endif - if (bool(blur.flags&FLAG_DOF_NEAR_FIRST_TAP)) { + if (bool(blur.flags & FLAG_DOF_NEAR_FIRST_TAP)) { frag_color = color_accum; } #endif diff --git a/servers/visual/rasterizer_rd/shaders/blur_inc.glsl b/servers/visual/rasterizer_rd/shaders/blur_inc.glsl index 275b547fc4..b6bfe13b95 100644 --- a/servers/visual/rasterizer_rd/shaders/blur_inc.glsl +++ b/servers/visual/rasterizer_rd/shaders/blur_inc.glsl @@ -1,16 +1,16 @@ -#define FLAG_HORIZONTAL (1<<0) -#define FLAG_USE_BLUR_SECTION (1<<1) -#define FLAG_USE_ORTHOGONAL_PROJECTION (1<<2) -#define FLAG_DOF_NEAR_FIRST_TAP (1<<3) -#define FLAG_GLOW_FIRST_PASS (1<<4) -#define FLAG_FLIP_Y (1<<5) +#define FLAG_HORIZONTAL (1 << 0) +#define FLAG_USE_BLUR_SECTION (1 << 1) +#define FLAG_USE_ORTHOGONAL_PROJECTION (1 << 2) +#define FLAG_DOF_NEAR_FIRST_TAP (1 << 3) +#define FLAG_GLOW_FIRST_PASS (1 << 4) +#define FLAG_FLIP_Y (1 << 5) layout(push_constant, binding = 1, std430) uniform Blur { vec4 section; vec2 pixel_size; uint flags; uint pad; - //glow + // Glow. float glow_strength; float glow_bloom; float glow_hdr_threshold; @@ -19,7 +19,7 @@ layout(push_constant, binding = 1, std430) uniform Blur { float glow_white; float glow_luminance_cap; float glow_auto_exposure_grey; - //dof + // DOF. float dof_begin; float dof_end; float dof_radius; @@ -30,7 +30,4 @@ layout(push_constant, binding = 1, std430) uniform Blur { float camera_z_near; vec4 ssao_color; - - - } blur; diff --git a/servers/visual/rasterizer_rd/shaders/canvas.glsl b/servers/visual/rasterizer_rd/shaders/canvas.glsl index f6c5251760..7c0b82065a 100644 --- a/servers/visual/rasterizer_rd/shaders/canvas.glsl +++ b/servers/visual/rasterizer_rd/shaders/canvas.glsl @@ -1,15 +1,13 @@ /* clang-format off */ [vertex] -/* clang-format on */ #version 450 -/* clang-format off */ VERSION_DEFINES -/* clang-format on */ #ifdef USE_ATTRIBUTES layout(location = 0) in vec2 vertex_attrib; +/* clang-format on */ layout(location = 3) in vec4 color_attrib; layout(location = 4) in vec2 uv_attrib; @@ -19,22 +17,21 @@ layout(location = 6) in uvec4 bones_attrib; #include "canvas_uniforms_inc.glsl" - -layout(location=0) out vec2 uv_interp; -layout(location=1) out vec4 color_interp; -layout(location=2) out vec2 vertex_interp; +layout(location = 0) out vec2 uv_interp; +layout(location = 1) out vec4 color_interp; +layout(location = 2) out vec2 vertex_interp; #ifdef USE_NINEPATCH -layout(location=3) out vec2 pixel_size_interp; +layout(location = 3) out vec2 pixel_size_interp; #endif #ifdef USE_MATERIAL_UNIFORMS -layout(set = 1, binding = 1, std140) uniform MaterialUniforms { -/* clang-format off */ +layout(set = 1, binding = 1, std140) uniform MaterialUniforms{ + /* clang-format off */ MATERIAL_UNIFORMS -/* clang-format on */ + /* clang-format on */ } material; #endif @@ -42,32 +39,31 @@ MATERIAL_UNIFORMS VERTEX_SHADER_GLOBALS /* clang-format on */ - void main() { vec4 instance_custom = vec4(0.0); #ifdef USE_PRIMITIVE -//weird bug, -//this works + //weird bug, + //this works vec2 vertex; vec2 uv; vec4 color; - if (gl_VertexIndex==0) { + if (gl_VertexIndex == 0) { vertex = draw_data.points[0]; uv = draw_data.uvs[0]; - color = vec4(unpackHalf2x16(draw_data.colors[0]),unpackHalf2x16(draw_data.colors[1])); - } else if (gl_VertexIndex==1) { + color = vec4(unpackHalf2x16(draw_data.colors[0]), unpackHalf2x16(draw_data.colors[1])); + } else if (gl_VertexIndex == 1) { vertex = draw_data.points[1]; uv = draw_data.uvs[1]; - color = vec4(unpackHalf2x16(draw_data.colors[2]),unpackHalf2x16(draw_data.colors[3])); + color = vec4(unpackHalf2x16(draw_data.colors[2]), unpackHalf2x16(draw_data.colors[3])); } else { vertex = draw_data.points[2]; uv = draw_data.uvs[2]; - color = vec4(unpackHalf2x16(draw_data.colors[4]),unpackHalf2x16(draw_data.colors[5])); + color = vec4(unpackHalf2x16(draw_data.colors[4]), unpackHalf2x16(draw_data.colors[5])); } - uvec4 bones = uvec4(0,0,0,0); + uvec4 bones = uvec4(0, 0, 0, 0); #elif defined(USE_ATTRIBUTES) @@ -78,57 +74,56 @@ void main() { uvec4 bones = bones_attrib; #else - vec2 vertex_base_arr[4] = vec2[](vec2(0.0,0.0),vec2(0.0,1.0),vec2(1.0,1.0),vec2(1.0,0.0)); + vec2 vertex_base_arr[4] = vec2[](vec2(0.0, 0.0), vec2(0.0, 1.0), vec2(1.0, 1.0), vec2(1.0, 0.0)); vec2 vertex_base = vertex_base_arr[gl_VertexIndex]; - vec2 uv = draw_data.src_rect.xy + abs(draw_data.src_rect.zw) * ((draw_data.flags&FLAGS_TRANSPOSE_RECT)!=0 ? vertex_base.yx : vertex_base.xy); + vec2 uv = draw_data.src_rect.xy + abs(draw_data.src_rect.zw) * ((draw_data.flags & FLAGS_TRANSPOSE_RECT) != 0 ? vertex_base.yx : vertex_base.xy); vec4 color = draw_data.modulation; vec2 vertex = draw_data.dst_rect.xy + abs(draw_data.dst_rect.zw) * mix(vertex_base, vec2(1.0, 1.0) - vertex_base, lessThan(draw_data.src_rect.zw, vec2(0.0, 0.0))); - uvec4 bones = uvec4(0,0,0,0); + uvec4 bones = uvec4(0, 0, 0, 0); #endif - mat4 world_matrix = mat4(vec4(draw_data.world_x,0.0,0.0),vec4(draw_data.world_y,0.0,0.0),vec4(0.0,0.0,1.0,0.0),vec4(draw_data.world_ofs,0.0,1.0)); -#if 0 + mat4 world_matrix = mat4(vec4(draw_data.world_x, 0.0, 0.0), vec4(draw_data.world_y, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(draw_data.world_ofs, 0.0, 1.0)); - if (draw_data.flags&FLAGS_INSTANCING_ENABLED) { +#if 0 + if (draw_data.flags & FLAGS_INSTANCING_ENABLED) { - uint offset = draw_data.flags&FLAGS_INSTANCING_STRIDE_MASK; + uint offset = draw_data.flags & FLAGS_INSTANCING_STRIDE_MASK; offset *= gl_InstanceIndex; - mat4 instance_xform = mat4( - vec4( texelFetch(instancing_buffer,offset+0),texelFetch(instancing_buffer,offset+1),0.0,texelFetch(instancing_buffer,offset+3) ), - vec4( texelFetch(instancing_buffer,offset+4),texelFetch(instancing_buffer,offset+5),0.0,texelFetch(instancing_buffer,offset+7) ), - vec4( 0.0,0.0,1.0,0.0), - vec4( 0.0,0.0,0.0,1.0 ) ); - offset+=8; - if ( draw_data.flags&FLAGS_INSTANCING_HAS_COLORS ) { + mat4 instance_xform = mat4( + vec4(texelFetch(instancing_buffer, offset + 0), texelFetch(instancing_buffer, offset + 1), 0.0, texelFetch(instancing_buffer, offset + 3)), + vec4(texelFetch(instancing_buffer, offset + 4), texelFetch(instancing_buffer, offset + 5), 0.0, texelFetch(instancing_buffer, offset + 7)), + vec4(0.0, 0.0, 1.0, 0.0), + vec4(0.0, 0.0, 0.0, 1.0)); + offset += 8; + if (draw_data.flags & FLAGS_INSTANCING_HAS_COLORS) { vec4 instance_color; - if (draw_data.flags&FLAGS_INSTANCING_COLOR_8_BIT ) { - uint bits = floatBitsToUint(texelFetch(instancing_buffer,offset)); + if (draw_data.flags & FLAGS_INSTANCING_COLOR_8_BIT) { + uint bits = floatBitsToUint(texelFetch(instancing_buffer, offset)); instance_color = unpackUnorm4x8(bits); - offset+=1; + offset += 1; } else { - instance_color = vec4(texelFetch(instancing_buffer,offset+0),texelFetch(instancing_buffer,offset+1),texelFetch(instancing_buffer,offset+2),texelFetch(instancing_buffer,offset+3)); - offser+=4; + instance_color = vec4(texelFetch(instancing_buffer, offset + 0), texelFetch(instancing_buffer, offset + 1), texelFetch(instancing_buffer, offset + 2), texelFetch(instancing_buffer, offset + 3)); + offser += 4; } - color*=instance_color; + color *= instance_color; } - if ( draw_data.flags&FLAGS_INSTANCING_HAS_CUSTOM_DATA ) { - if (draw_data.flags&FLAGS_INSTANCING_CUSTOM_DATA_8_BIT ) { - uint bits = floatBitsToUint(texelFetch(instancing_buffer,offset)); + if (draw_data.flags & FLAGS_INSTANCING_HAS_CUSTOM_DATA) { + if (draw_data.flags & FLAGS_INSTANCING_CUSTOM_DATA_8_BIT) { + uint bits = floatBitsToUint(texelFetch(instancing_buffer, offset)); instance_custom = unpackUnorm4x8(bits); } else { - instance_custom = vec4(texelFetch(instancing_buffer,offset+0),texelFetch(instancing_buffer,offset+1),texelFetch(instancing_buffer,offset+2),texelFetch(instancing_buffer,offset+3)); + instance_custom = vec4(texelFetch(instancing_buffer, offset + 0), texelFetch(instancing_buffer, offset + 1), texelFetch(instancing_buffer, offset + 2), texelFetch(instancing_buffer, offset + 3)); } } - } #endif #if !defined(USE_ATTRIBUTES) && !defined(USE_PRIMITIVE) - if (bool(draw_data.flags&FLAGS_USING_PARTICLES)) { + if (bool(draw_data.flags & FLAGS_USING_PARTICLES)) { //scale by texture size vertex /= draw_data.color_texture_pixel_size; } @@ -143,19 +138,17 @@ VERTEX_SHADER_CODE /* clang-format on */ } - - #ifdef USE_NINEPATCH pixel_size_interp = abs(draw_data.dst_rect.zw) * vertex_base; #endif #if !defined(SKIP_TRANSFORM_USED) - vertex = (world_matrix * vec4(vertex,0.0,1.0)).xy; + vertex = (world_matrix * vec4(vertex, 0.0, 1.0)).xy; #endif color_interp = color; - if (bool(draw_data.flags&FLAGS_USE_PIXEL_SNAP)) { + if (bool(draw_data.flags & FLAGS_USE_PIXEL_SNAP)) { vertex = floor(vertex + 0.5); // precision issue on some hardware creates artifacts within texture @@ -165,38 +158,38 @@ VERTEX_SHADER_CODE #ifdef USE_ATTRIBUTES #if 0 - if (bool(draw_data.flags&FLAGS_USE_SKELETON) && bone_weights != vec4(0.0)) { //must be a valid bone + if (bool(draw_data.flags & FLAGS_USE_SKELETON) && bone_weights != vec4(0.0)) { //must be a valid bone //skeleton transform ivec4 bone_indicesi = ivec4(bone_indices); - uvec2 tex_ofs = bone_indicesi.x *2; + uvec2 tex_ofs = bone_indicesi.x * 2; mat2x4 m; m = mat2x4( - texelFetch(skeleton_buffer, tex_ofs+0), - texelFetch(skeleton_buffer, tex_ofs+1) ) * + texelFetch(skeleton_buffer, tex_ofs + 0), + texelFetch(skeleton_buffer, tex_ofs + 1)) * bone_weights.x; tex_ofs = bone_indicesi.y * 2; m += mat2x4( - texelFetch(skeleton_buffer, tex_ofs+0), - texelFetch(skeleton_buffer, tex_ofs+1) ) * + texelFetch(skeleton_buffer, tex_ofs + 0), + texelFetch(skeleton_buffer, tex_ofs + 1)) * bone_weights.y; tex_ofs = bone_indicesi.z * 2; m += mat2x4( - texelFetch(skeleton_buffer, tex_ofs+0), - texelFetch(skeleton_buffer, tex_ofs+1) ) * + texelFetch(skeleton_buffer, tex_ofs + 0), + texelFetch(skeleton_buffer, tex_ofs + 1)) * bone_weights.z; tex_ofs = bone_indicesi.w * 2; m += mat2x4( - texelFetch(skeleton_buffer, tex_ofs+0), - texelFetch(skeleton_buffer, tex_ofs+1) ) * + texelFetch(skeleton_buffer, tex_ofs + 0), + texelFetch(skeleton_buffer, tex_ofs + 1)) * bone_weights.w; mat4 bone_matrix = skeleton_data.skeleton_transform * transpose(mat4(m[0], m[1], vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0))) * skeleton_data.skeleton_transform_inverse; @@ -206,18 +199,16 @@ VERTEX_SHADER_CODE #endif #endif - - vertex = (canvas_data.canvas_transform * vec4(vertex,0.0,1.0)).xy; + vertex = (canvas_data.canvas_transform * vec4(vertex, 0.0, 1.0)).xy; vertex_interp = vertex; uv_interp = uv; - gl_Position = canvas_data.screen_transform * vec4(vertex,0.0,1.0); + gl_Position = canvas_data.screen_transform * vec4(vertex, 0.0, 1.0); #ifdef USE_POINT_SIZE - gl_PointSize=point_size; + gl_PointSize = point_size; #endif - } /* clang-format off */ @@ -225,33 +216,31 @@ VERTEX_SHADER_CODE #version 450 -/* clang-format off */ VERSION_DEFINES -/* clang-format on */ #include "canvas_uniforms_inc.glsl" -layout(location=0) in vec2 uv_interp; -layout(location=1) in vec4 color_interp; -layout(location=2) in vec2 vertex_interp; +layout(location = 0) in vec2 uv_interp; +/* clang-format on */ +layout(location = 1) in vec4 color_interp; +layout(location = 2) in vec2 vertex_interp; #ifdef USE_NINEPATCH -layout(location=3) in vec2 pixel_size_interp; +layout(location = 3) in vec2 pixel_size_interp; #endif layout(location = 0) out vec4 frag_color; #ifdef USE_MATERIAL_UNIFORMS -layout(set = 1, binding = 1, std140) uniform MaterialUniforms { -/* clang-format off */ +layout(set = 1, binding = 1, std140) uniform MaterialUniforms{ + /* clang-format off */ MATERIAL_UNIFORMS -/* clang-format on */ + /* clang-format on */ } material; #endif - /* clang-format off */ FRAGMENT_SHADER_GLOBALS /* clang-format on */ @@ -290,7 +279,7 @@ float map_ninepatch_axis(float pixel, float draw_size, float tex_pixel_size, flo } else if (pixel >= draw_size - margin_end) { return (tex_size - (draw_size - pixel)) * tex_pixel_size; } else { - if (!bool(draw_data.flags&FLAGS_NINEPACH_DRAW_CENTER)) { + if (!bool(draw_data.flags & FLAGS_NINEPACH_DRAW_CENTER)) { draw_center--; } @@ -318,7 +307,6 @@ float map_ninepatch_axis(float pixel, float draw_size, float tex_pixel_size, flo } } - #endif void main() { @@ -333,8 +321,8 @@ void main() { int draw_center = 2; uv = vec2( - map_ninepatch_axis(pixel_size_interp.x, abs(draw_data.dst_rect.z), draw_data.color_texture_pixel_size.x, draw_data.ninepatch_margins.x, draw_data.ninepatch_margins.z, int(draw_data.flags>>FLAGS_NINEPATCH_H_MODE_SHIFT)&0x3, draw_center), - map_ninepatch_axis(pixel_size_interp.y, abs(draw_data.dst_rect.w), draw_data.color_texture_pixel_size.y, draw_data.ninepatch_margins.y, draw_data.ninepatch_margins.w, int(draw_data.flags>>FLAGS_NINEPATCH_V_MODE_SHIFT)&0x3, draw_center)); + map_ninepatch_axis(pixel_size_interp.x, abs(draw_data.dst_rect.z), draw_data.color_texture_pixel_size.x, draw_data.ninepatch_margins.x, draw_data.ninepatch_margins.z, int(draw_data.flags >> FLAGS_NINEPATCH_H_MODE_SHIFT) & 0x3, draw_center), + map_ninepatch_axis(pixel_size_interp.y, abs(draw_data.dst_rect.w), draw_data.color_texture_pixel_size.y, draw_data.ninepatch_margins.y, draw_data.ninepatch_margins.w, int(draw_data.flags >> FLAGS_NINEPATCH_V_MODE_SHIFT) & 0x3, draw_center)); if (draw_center == 0) { color.a = 0.0; @@ -342,18 +330,17 @@ void main() { uv = uv * draw_data.src_rect.zw + draw_data.src_rect.xy; //apply region if needed -#endif - if (bool(draw_data.flags&FLAGS_CLIP_RECT_UV)) { +#endif + if (bool(draw_data.flags & FLAGS_CLIP_RECT_UV)) { uv = clamp(uv, draw_data.src_rect.xy, draw_data.src_rect.xy + abs(draw_data.src_rect.zw)); } #endif - color *= texture(sampler2D(color_texture,texture_sampler), uv); - - uint light_count = (draw_data.flags>>FLAGS_LIGHT_COUNT_SHIFT)&0xF; //max 16 lights + color *= texture(sampler2D(color_texture, texture_sampler), uv); + uint light_count = (draw_data.flags >> FLAGS_LIGHT_COUNT_SHIFT) & 0xF; //max 16 lights vec3 normal; @@ -364,9 +351,8 @@ void main() { bool normal_used = false; #endif - - if (normal_used || (light_count > 0 && bool(draw_data.flags&FLAGS_DEFAULT_NORMAL_MAP_USED))) { - normal.xy = texture(sampler2D(normal_texture,texture_sampler), uv).xy * vec2(2.0,-2.0) - vec2(1.0,-1.0); + if (normal_used || (light_count > 0 && bool(draw_data.flags & FLAGS_DEFAULT_NORMAL_MAP_USED))) { + normal.xy = texture(sampler2D(normal_texture, texture_sampler), uv).xy * vec2(2.0, -2.0) - vec2(1.0, -1.0); normal.z = sqrt(1.0 - dot(normal.xy, normal.xy)); normal_used = true; } else { @@ -382,22 +368,21 @@ void main() { bool specular_shininess_used = false; #endif - if (specular_shininess_used || (light_count > 0 && normal_used && bool(draw_data.flags&FLAGS_DEFAULT_SPECULAR_MAP_USED))) { - specular_shininess = texture(sampler2D(specular_texture,texture_sampler ), uv); + if (specular_shininess_used || (light_count > 0 && normal_used && bool(draw_data.flags & FLAGS_DEFAULT_SPECULAR_MAP_USED))) { + specular_shininess = texture(sampler2D(specular_texture, texture_sampler), uv); specular_shininess *= unpackUnorm4x8(draw_data.specular_shininess); - specular_shininess_used=true; + specular_shininess_used = true; } else { specular_shininess = vec4(1.0); } - #if defined(SCREEN_UV_USED) vec2 screen_uv = gl_FragCoord.xy * canvas_data.screen_pixel_size; #else vec2 screen_uv = vec2(0.0); #endif - vec3 light_vertex = vec3(vertex,0.0); + vec3 light_vertex = vec3(vertex, 0.0); vec2 shadow_vertex = vertex; { @@ -423,65 +408,63 @@ FRAGMENT_SHADER_CODE //convert by item transform normal.xy = mat2(normalize(draw_data.world_x), normalize(draw_data.world_y)) * normal.xy; //convert by canvas transform - normal = normalize((canvas_data.canvas_normal_transform * vec4(normal,0.0)).xyz); + normal = normalize((canvas_data.canvas_normal_transform * vec4(normal, 0.0)).xyz); } - - vec4 base_color=color; - if (bool(draw_data.flags&FLAGS_USING_LIGHT_MASK)) { - color=vec4(0.0); //inivisible by default due to using light mask + vec4 base_color = color; + if (bool(draw_data.flags & FLAGS_USING_LIGHT_MASK)) { + color = vec4(0.0); //inivisible by default due to using light mask } - color*=canvas_data.canvas_modulation; + color *= canvas_data.canvas_modulation; #ifdef USE_LIGHTING - for(uint i=0;i<MAX_LIGHT_TEXTURES;i++) { - if (i>=light_count) { + for (uint i = 0; i < MAX_LIGHT_TEXTURES; i++) { + if (i >= light_count) { break; } uint light_base; - if (i<8) { - if (i<4) { - light_base=draw_data.lights[0]; + if (i < 8) { + if (i < 4) { + light_base = draw_data.lights[0]; } else { - light_base=draw_data.lights[1]; + light_base = draw_data.lights[1]; } } else { - if (i<12) { - light_base=draw_data.lights[2]; + if (i < 12) { + light_base = draw_data.lights[2]; } else { - light_base=draw_data.lights[3]; + light_base = draw_data.lights[3]; } } - light_base>>=(i&3)*8; - light_base&=0xFF; + light_base >>= (i & 3) * 8; + light_base &= 0xFF; - vec2 tex_uv = (vec4(vertex,0.0,1.0) * mat4(light_array.data[light_base].matrix[0],light_array.data[light_base].matrix[1],vec4(0.0,0.0,1.0,0.0),vec4(0.0,0.0,0.0,1.0))).xy; //multiply inverse given its transposed. Optimizer removes useless operations. - vec4 light_color = texture(sampler2D(light_textures[i],texture_sampler),tex_uv); + vec2 tex_uv = (vec4(vertex, 0.0, 1.0) * mat4(light_array.data[light_base].matrix[0], light_array.data[light_base].matrix[1], vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0))).xy; //multiply inverse given its transposed. Optimizer removes useless operations. + vec4 light_color = texture(sampler2D(light_textures[i], texture_sampler), tex_uv); vec4 light_base_color = light_array.data[light_base].color; #ifdef LIGHT_SHADER_CODE_USED vec4 shadow_modulate = vec4(1.0); - vec3 light_position = vec3(light_array.data[light_base].position,light_array.data[light_base].height); + vec3 light_position = vec3(light_array.data[light_base].position, light_array.data[light_base].height); - light_color.rgb*=light_base_color.rgb; - light_color = light_compute(light_vertex,light_position,normal,light_color,light_base_color.a,specular_shininess,shadow_modulate,screen_uv,color,uv); + light_color.rgb *= light_base_color.rgb; + light_color = light_compute(light_vertex, light_position, normal, light_color, light_base_color.a, specular_shininess, shadow_modulate, screen_uv, color, uv); #else - - light_color.rgb*=light_base_color.rgb*light_base_color.a; + light_color.rgb *= light_base_color.rgb * light_base_color.a; if (normal_used) { - vec3 light_pos = vec3(light_array.data[light_base].position,light_array.data[light_base].height); + vec3 light_pos = vec3(light_array.data[light_base].position, light_array.data[light_base].height); vec3 pos = light_vertex; - vec3 light_vec = normalize(light_pos-pos); - float cNdotL = max(0.0,dot(normal,light_vec)); + vec3 light_vec = normalize(light_pos - pos); + float cNdotL = max(0.0, dot(normal, light_vec)); if (specular_shininess_used) { //blinn - vec3 view = vec3(0.0,0.0,1.0);// not great but good enough - vec3 half_vec = normalize(view+light_vec); + vec3 view = vec3(0.0, 0.0, 1.0); // not great but good enough + vec3 half_vec = normalize(view + light_vec); float cNdotV = max(dot(normal, view), 0.0); float cNdotH = max(dot(normal, half_vec), 0.0); @@ -496,7 +479,6 @@ FRAGMENT_SHADER_CODE } else { light_color.rgb *= cNdotL; } - } #endif if (any(lessThan(tex_uv, vec2(0.0, 0.0))) || any(greaterThanEqual(tex_uv, vec2(1.0, 1.0)))) { @@ -504,98 +486,96 @@ FRAGMENT_SHADER_CODE light_color.a = 0.0; } - if (bool(light_array.data[light_base].flags&LIGHT_FLAGS_HAS_SHADOW)) { + if (bool(light_array.data[light_base].flags & LIGHT_FLAGS_HAS_SHADOW)) { - vec2 shadow_pos = (vec4(shadow_vertex,0.0,1.0) * mat4(light_array.data[light_base].shadow_matrix[0],light_array.data[light_base].shadow_matrix[1],vec4(0.0,0.0,1.0,0.0),vec4(0.0,0.0,0.0,1.0))).xy; //multiply inverse given its transposed. Optimizer removes useless operations. + vec2 shadow_pos = (vec4(shadow_vertex, 0.0, 1.0) * mat4(light_array.data[light_base].shadow_matrix[0], light_array.data[light_base].shadow_matrix[1], vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0))).xy; //multiply inverse given its transposed. Optimizer removes useless operations. vec2 pos_norm = normalize(shadow_pos); vec2 pos_abs = abs(pos_norm); - vec2 pos_box = pos_norm / max(pos_abs.x,pos_abs.y); - vec2 pos_rot = pos_norm * mat2(vec2(0.7071067811865476,-0.7071067811865476),vec2(0.7071067811865476,0.7071067811865476)); //is there a faster way to 45 degrees rot? + vec2 pos_box = pos_norm / max(pos_abs.x, pos_abs.y); + vec2 pos_rot = pos_norm * mat2(vec2(0.7071067811865476, -0.7071067811865476), vec2(0.7071067811865476, 0.7071067811865476)); //is there a faster way to 45 degrees rot? float tex_ofs; float distance; - if (pos_rot.y>0) { - if (pos_rot.x>0) { - tex_ofs=pos_box.y*0.125+0.125; - distance=shadow_pos.x; + if (pos_rot.y > 0) { + if (pos_rot.x > 0) { + tex_ofs = pos_box.y * 0.125 + 0.125; + distance = shadow_pos.x; } else { - tex_ofs=pos_box.x*-0.125+(0.25+0.125); - distance=shadow_pos.y; + tex_ofs = pos_box.x * -0.125 + (0.25 + 0.125); + distance = shadow_pos.y; } } else { - if (pos_rot.x<0) { - tex_ofs=pos_box.y*-0.125+(0.5+0.125); - distance=-shadow_pos.x; + if (pos_rot.x < 0) { + tex_ofs = pos_box.y * -0.125 + (0.5 + 0.125); + distance = -shadow_pos.x; } else { - tex_ofs=pos_box.x*0.125+(0.75+0.125); - distance=-shadow_pos.y; + tex_ofs = pos_box.x * 0.125 + (0.75 + 0.125); + distance = -shadow_pos.y; } } //float distance = length(shadow_pos); float shadow; - uint shadow_mode = light_array.data[light_base].flags&LIGHT_FLAGS_FILTER_MASK; + uint shadow_mode = light_array.data[light_base].flags & LIGHT_FLAGS_FILTER_MASK; - vec4 shadow_uv = vec4(tex_ofs,0.0,distance,1.0); + vec4 shadow_uv = vec4(tex_ofs, 0.0, distance, 1.0); - if (shadow_mode==LIGHT_FLAGS_SHADOW_NEAREST) { - shadow = textureProj(sampler2DShadow(shadow_textures[i],shadow_sampler),shadow_uv).x; - } else if (shadow_mode==LIGHT_FLAGS_SHADOW_PCF5) { - vec4 shadow_pixel_size = vec4(light_array.data[light_base].shadow_pixel_size,0.0,0.0,0.0); + if (shadow_mode == LIGHT_FLAGS_SHADOW_NEAREST) { + shadow = textureProj(sampler2DShadow(shadow_textures[i], shadow_sampler), shadow_uv).x; + } else if (shadow_mode == LIGHT_FLAGS_SHADOW_PCF5) { + vec4 shadow_pixel_size = vec4(light_array.data[light_base].shadow_pixel_size, 0.0, 0.0, 0.0); shadow = 0.0; - shadow += textureProj(sampler2DShadow(shadow_textures[i],shadow_sampler),shadow_uv-shadow_pixel_size*2.0).x; - shadow += textureProj(sampler2DShadow(shadow_textures[i],shadow_sampler),shadow_uv-shadow_pixel_size).x; - shadow += textureProj(sampler2DShadow(shadow_textures[i],shadow_sampler),shadow_uv).x; - shadow += textureProj(sampler2DShadow(shadow_textures[i],shadow_sampler),shadow_uv+shadow_pixel_size).x; - shadow += textureProj(sampler2DShadow(shadow_textures[i],shadow_sampler),shadow_uv+shadow_pixel_size*2.0).x; - shadow/=5.0; + shadow += textureProj(sampler2DShadow(shadow_textures[i], shadow_sampler), shadow_uv - shadow_pixel_size * 2.0).x; + shadow += textureProj(sampler2DShadow(shadow_textures[i], shadow_sampler), shadow_uv - shadow_pixel_size).x; + shadow += textureProj(sampler2DShadow(shadow_textures[i], shadow_sampler), shadow_uv).x; + shadow += textureProj(sampler2DShadow(shadow_textures[i], shadow_sampler), shadow_uv + shadow_pixel_size).x; + shadow += textureProj(sampler2DShadow(shadow_textures[i], shadow_sampler), shadow_uv + shadow_pixel_size * 2.0).x; + shadow /= 5.0; } else { //PCF13 - vec4 shadow_pixel_size = vec4(light_array.data[light_base].shadow_pixel_size,0.0,0.0,0.0); + vec4 shadow_pixel_size = vec4(light_array.data[light_base].shadow_pixel_size, 0.0, 0.0, 0.0); shadow = 0.0; - shadow += textureProj(sampler2DShadow(shadow_textures[i],shadow_sampler),shadow_uv-shadow_pixel_size*6.0).x; - shadow += textureProj(sampler2DShadow(shadow_textures[i],shadow_sampler),shadow_uv-shadow_pixel_size*5.0).x; - shadow += textureProj(sampler2DShadow(shadow_textures[i],shadow_sampler),shadow_uv-shadow_pixel_size*4.0).x; - shadow += textureProj(sampler2DShadow(shadow_textures[i],shadow_sampler),shadow_uv-shadow_pixel_size*3.0).x; - shadow += textureProj(sampler2DShadow(shadow_textures[i],shadow_sampler),shadow_uv-shadow_pixel_size*2.0).x; - shadow += textureProj(sampler2DShadow(shadow_textures[i],shadow_sampler),shadow_uv-shadow_pixel_size).x; - shadow += textureProj(sampler2DShadow(shadow_textures[i],shadow_sampler),shadow_uv).x; - shadow += textureProj(sampler2DShadow(shadow_textures[i],shadow_sampler),shadow_uv+shadow_pixel_size).x; - shadow += textureProj(sampler2DShadow(shadow_textures[i],shadow_sampler),shadow_uv+shadow_pixel_size*2.0).x; - shadow += textureProj(sampler2DShadow(shadow_textures[i],shadow_sampler),shadow_uv+shadow_pixel_size*3.0).x; - shadow += textureProj(sampler2DShadow(shadow_textures[i],shadow_sampler),shadow_uv+shadow_pixel_size*4.0).x; - shadow += textureProj(sampler2DShadow(shadow_textures[i],shadow_sampler),shadow_uv+shadow_pixel_size*5.0).x; - shadow += textureProj(sampler2DShadow(shadow_textures[i],shadow_sampler),shadow_uv+shadow_pixel_size*6.0).x; - shadow/=13.0; + shadow += textureProj(sampler2DShadow(shadow_textures[i], shadow_sampler), shadow_uv - shadow_pixel_size * 6.0).x; + shadow += textureProj(sampler2DShadow(shadow_textures[i], shadow_sampler), shadow_uv - shadow_pixel_size * 5.0).x; + shadow += textureProj(sampler2DShadow(shadow_textures[i], shadow_sampler), shadow_uv - shadow_pixel_size * 4.0).x; + shadow += textureProj(sampler2DShadow(shadow_textures[i], shadow_sampler), shadow_uv - shadow_pixel_size * 3.0).x; + shadow += textureProj(sampler2DShadow(shadow_textures[i], shadow_sampler), shadow_uv - shadow_pixel_size * 2.0).x; + shadow += textureProj(sampler2DShadow(shadow_textures[i], shadow_sampler), shadow_uv - shadow_pixel_size).x; + shadow += textureProj(sampler2DShadow(shadow_textures[i], shadow_sampler), shadow_uv).x; + shadow += textureProj(sampler2DShadow(shadow_textures[i], shadow_sampler), shadow_uv + shadow_pixel_size).x; + shadow += textureProj(sampler2DShadow(shadow_textures[i], shadow_sampler), shadow_uv + shadow_pixel_size * 2.0).x; + shadow += textureProj(sampler2DShadow(shadow_textures[i], shadow_sampler), shadow_uv + shadow_pixel_size * 3.0).x; + shadow += textureProj(sampler2DShadow(shadow_textures[i], shadow_sampler), shadow_uv + shadow_pixel_size * 4.0).x; + shadow += textureProj(sampler2DShadow(shadow_textures[i], shadow_sampler), shadow_uv + shadow_pixel_size * 5.0).x; + shadow += textureProj(sampler2DShadow(shadow_textures[i], shadow_sampler), shadow_uv + shadow_pixel_size * 6.0).x; + shadow /= 13.0; } vec4 shadow_color = light_array.data[light_base].shadow_color; #ifdef LIGHT_SHADER_CODE_USED - shadow_color*=shadow_modulate; + shadow_color *= shadow_modulate; #endif - light_color = mix(light_color,shadow_color,shadow); - + light_color = mix(light_color, shadow_color, shadow); } - uint blend_mode = light_array.data[light_base].flags&LIGHT_FLAGS_BLEND_MASK; + uint blend_mode = light_array.data[light_base].flags & LIGHT_FLAGS_BLEND_MASK; - switch(blend_mode) { + switch (blend_mode) { case LIGHT_FLAGS_BLEND_MODE_ADD: { - color.rgb+=light_color.rgb*light_color.a; + color.rgb += light_color.rgb * light_color.a; } break; case LIGHT_FLAGS_BLEND_MODE_SUB: { - color.rgb-=light_color.rgb*light_color.a; + color.rgb -= light_color.rgb * light_color.a; } break; case LIGHT_FLAGS_BLEND_MODE_MIX: { - color.rgb=mix(color.rgb,light_color.rgb,light_color.a); + color.rgb = mix(color.rgb, light_color.rgb, light_color.a); } break; case LIGHT_FLAGS_BLEND_MODE_MASK: { - light_color.a*=base_color.a; - color.rgb=mix(color.rgb,light_color.rgb,light_color.a); + light_color.a *= base_color.a; + color.rgb = mix(color.rgb, light_color.rgb, light_color.a); } break; } } #endif frag_color = color; - } diff --git a/servers/visual/rasterizer_rd/shaders/canvas_occlusion.glsl b/servers/visual/rasterizer_rd/shaders/canvas_occlusion.glsl index 01e87411d3..7486fab140 100644 --- a/servers/visual/rasterizer_rd/shaders/canvas_occlusion.glsl +++ b/servers/visual/rasterizer_rd/shaders/canvas_occlusion.glsl @@ -1,10 +1,10 @@ /* clang-format off */ [vertex] -/* clang-format on */ #version 450 layout(location = 0) in highp vec3 vertex; +/* clang-format on */ layout(push_constant, binding = 0, std430) uniform Constants { @@ -18,23 +18,22 @@ layout(location = 0) out highp float depth; void main() { - highp vec4 vtx = vec4(vertex, 1.0) * mat4(constants.modelview[0],constants.modelview[1],vec4(0.0,0.0,1.0,0.0),vec4(0.0,0.0,0.0,1.0)); - depth = dot(constants.direction,vtx.xy); + highp vec4 vtx = vec4(vertex, 1.0) * mat4(constants.modelview[0], constants.modelview[1], vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0)); + depth = dot(constants.direction, vtx.xy); gl_Position = constants.projection * vtx; - } /* clang-format off */ [fragment] -/* clang-format on */ #version 450 layout(location = 0) in highp float depth; +/* clang-format on */ layout(location = 0) out highp float distance_buf; void main() { - distance_buf=depth; + distance_buf = depth; } diff --git a/servers/visual/rasterizer_rd/shaders/canvas_uniforms_inc.glsl b/servers/visual/rasterizer_rd/shaders/canvas_uniforms_inc.glsl index 400c13ba68..bd4dd47eff 100644 --- a/servers/visual/rasterizer_rd/shaders/canvas_uniforms_inc.glsl +++ b/servers/visual/rasterizer_rd/shaders/canvas_uniforms_inc.glsl @@ -1,10 +1,7 @@ - - - #define M_PI 3.14159265359 #define FLAGS_INSTANCING_STRIDE_MASK 0xF -#define FLAGS_INSTANCING_ENABLED (1<<4) +#define FLAGS_INSTANCING_ENABLED (1 << 4) #define FLAGS_INSTANCING_HAS_COLORS (1 << 5) #define FLAGS_INSTANCING_COLOR_8BIT (1 << 6) #define FLAGS_INSTANCING_HAS_CUSTOM_DATA (1 << 7) @@ -53,7 +50,6 @@ layout(push_constant, binding = 0, std430) uniform DrawData { #endif vec2 color_texture_pixel_size; uint lights[4]; - } draw_data; // The values passed per draw primitives are cached within it @@ -67,7 +63,6 @@ layout(set = 0, binding = 5) uniform textureBuffer instancing_buffer; /* SET1: Is reserved for the material */ - #ifdef USE_MATERIAL_SAMPLERS layout(set = 1, binding = 0) uniform sampler material_samplers[12]; @@ -76,7 +71,6 @@ layout(set = 1, binding = 0) uniform sampler material_samplers[12]; /* SET2: Canvas Item State (including lighting) */ - layout(set = 2, binding = 0, std140) uniform CanvasData { mat4 canvas_transform; mat4 screen_transform; @@ -95,21 +89,19 @@ layout(set = 2, binding = 2, std140) uniform SkeletonData { mat4 skeleton_transform_inverse; } skeleton_data; - #ifdef USE_LIGHTING -#define LIGHT_FLAGS_BLEND_MASK (3<<16) -#define LIGHT_FLAGS_BLEND_MODE_ADD (0<<16) -#define LIGHT_FLAGS_BLEND_MODE_SUB (1<<16) -#define LIGHT_FLAGS_BLEND_MODE_MIX (2<<16) -#define LIGHT_FLAGS_BLEND_MODE_MASK (3<<16) -#define LIGHT_FLAGS_HAS_SHADOW (1<<20) +#define LIGHT_FLAGS_BLEND_MASK (3 << 16) +#define LIGHT_FLAGS_BLEND_MODE_ADD (0 << 16) +#define LIGHT_FLAGS_BLEND_MODE_SUB (1 << 16) +#define LIGHT_FLAGS_BLEND_MODE_MIX (2 << 16) +#define LIGHT_FLAGS_BLEND_MODE_MASK (3 << 16) +#define LIGHT_FLAGS_HAS_SHADOW (1 << 20) #define LIGHT_FLAGS_FILTER_SHIFT 22 -#define LIGHT_FLAGS_FILTER_MASK (3<<22) -#define LIGHT_FLAGS_SHADOW_NEAREST (0<<22) -#define LIGHT_FLAGS_SHADOW_PCF5 (1<<22) -#define LIGHT_FLAGS_SHADOW_PCF13 (2<<22) - +#define LIGHT_FLAGS_FILTER_MASK (3 << 22) +#define LIGHT_FLAGS_SHADOW_NEAREST (0 << 22) +#define LIGHT_FLAGS_SHADOW_PCF5 (1 << 22) +#define LIGHT_FLAGS_SHADOW_PCF13 (2 << 22) struct Light { mat2x4 matrix; //light to texture coordinate matrix (transposed) diff --git a/servers/visual/rasterizer_rd/shaders/copy.glsl b/servers/visual/rasterizer_rd/shaders/copy.glsl index e54b3972c0..d180fecd5a 100644 --- a/servers/visual/rasterizer_rd/shaders/copy.glsl +++ b/servers/visual/rasterizer_rd/shaders/copy.glsl @@ -1,53 +1,46 @@ /* clang-format off */ [vertex] -/* clang-format on */ #version 450 -/* clang-format off */ VERSION_DEFINES -/* clang-format on */ -layout(location =0) out vec2 uv_interp; +layout(location = 0) out vec2 uv_interp; +/* clang-format on */ void main() { - vec2 base_arr[4] = vec2[](vec2(0.0,0.0),vec2(0.0,1.0),vec2(1.0,1.0),vec2(1.0,0.0)); + vec2 base_arr[4] = vec2[](vec2(0.0, 0.0), vec2(0.0, 1.0), vec2(1.0, 1.0), vec2(1.0, 0.0)); uv_interp = base_arr[gl_VertexIndex]; - gl_Position = vec4( uv_interp *2.0 - 1.0, 0.0, 1.0); - + gl_Position = vec4(uv_interp * 2.0 - 1.0, 0.0, 1.0); } /* clang-format off */ [fragment] -/* clang-format on */ #version 450 -/* clang-format off */ VERSION_DEFINES -/* clang-format on */ -layout(location =0) in vec2 uv_interp; +layout(location = 0) in vec2 uv_interp; +/* clang-format on */ #ifdef MODE_CUBE_TO_DP -layout( set=0, binding=0 ) uniform samplerCube source_cube; +layout(set = 0, binding = 0) uniform samplerCube source_cube; layout(push_constant, binding = 0, std430) uniform Params { float bias; float z_far; float z_near; bool z_flip; - } params; -layout(location=0) out float depth_buffer; +layout(location = 0) out float depth_buffer; #endif - void main() { #ifdef MODE_CUBE_TO_DP @@ -57,7 +50,6 @@ void main() { normal.z = 0.5 - 0.5 * ((normal.x * normal.x) + (normal.y * normal.y)); normal = normalize(normal); - normal.y = -normal.y; //needs to be flipped to match projection matrix if (!params.z_flip) { normal.z = -normal.z; diff --git a/servers/visual/rasterizer_rd/shaders/cubemap_roughness.glsl b/servers/visual/rasterizer_rd/shaders/cubemap_roughness.glsl index f741fab355..de941c335f 100644 --- a/servers/visual/rasterizer_rd/shaders/cubemap_roughness.glsl +++ b/servers/visual/rasterizer_rd/shaders/cubemap_roughness.glsl @@ -1,41 +1,34 @@ /* clang-format off */ [vertex] -/* clang-format on */ #version 450 -/* clang-format off */ VERSION_DEFINES -/* clang-format on */ - - -layout(location=0) out highp vec2 uv_interp; +layout(location = 0) out highp vec2 uv_interp; +/* clang-format on */ void main() { - vec2 base_arr[4] = vec2[](vec2(0.0,0.0),vec2(0.0,1.0),vec2(1.0,1.0),vec2(1.0,0.0)); + vec2 base_arr[4] = vec2[](vec2(0.0, 0.0), vec2(0.0, 1.0), vec2(1.0, 1.0), vec2(1.0, 0.0)); uv_interp = base_arr[gl_VertexIndex]; - gl_Position = vec4( uv_interp *2.0 - 1.0, 0.0, 1.0); - + gl_Position = vec4(uv_interp * 2.0 - 1.0, 0.0, 1.0); } /* clang-format off */ [fragment] -/* clang-format on */ #version 450 -/* clang-format off */ VERSION_DEFINES -/* clang-format on */ #ifdef MODE_SOURCE_PANORAMA -layout( set=0, binding=0 ) uniform sampler2D source_panorama; +layout(set = 0, binding = 0) uniform sampler2D source_panorama; +/* clang-format on */ #endif #ifdef MODE_SOURCE_CUBEMAP -layout( set=0, binding=0 ) uniform samplerCube source_cube; +layout(set = 0, binding = 0) uniform samplerCube source_cube; #endif layout(push_constant, binding = 1, std430) uniform Params { @@ -45,7 +38,7 @@ layout(push_constant, binding = 1, std430) uniform Params { bool use_direct_write; } params; -layout(location=0) in vec2 uv_interp; +layout(location = 0) in vec2 uv_interp; layout(location = 0) out vec4 frag_color; @@ -184,7 +177,6 @@ vec4 texturePanorama(vec3 normal, sampler2D pano) { #endif - void main() { vec2 uv = (uv_interp * 2.0) - 1.0; @@ -200,7 +192,7 @@ void main() { #endif #ifdef MODE_SOURCE_CUBEMAP - frag_color = vec4(texture(source_cube,N).rgb, 1.0); + frag_color = vec4(texture(source_cube, N).rgb, 1.0); #endif } else { diff --git a/servers/visual/rasterizer_rd/shaders/giprobe.glsl b/servers/visual/rasterizer_rd/shaders/giprobe.glsl index 281156d251..dcbefdb933 100644 --- a/servers/visual/rasterizer_rd/shaders/giprobe.glsl +++ b/servers/visual/rasterizer_rd/shaders/giprobe.glsl @@ -1,3 +1,4 @@ +/* clang-format off */ [compute] #version 450 @@ -5,26 +6,23 @@ VERSION_DEFINES #ifdef MODE_DYNAMIC - layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; - #else - layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in; - #endif +/* clang-format on */ #ifndef MODE_DYNAMIC #define NO_CHILDREN 0xFFFFFFFF -#define GREY_VEC vec3(0.33333,0.33333,0.33333) +#define GREY_VEC vec3(0.33333, 0.33333, 0.33333) struct CellChildren { uint children[8]; }; -layout(set=0,binding=1,std430) buffer CellChildrenBuffer { - CellChildren data[]; +layout(set = 0, binding = 1, std430) buffer CellChildrenBuffer { + CellChildren data[]; } cell_children; struct CellData { @@ -34,11 +32,10 @@ struct CellData { uint normal; //RGB normal encoded }; -layout(set=0,binding=2,std430) buffer CellDataBuffer { - CellData data[]; +layout(set = 0, binding = 2, std430) buffer CellDataBuffer { + CellData data[]; } cell_data; - #endif // MODE DYNAMIC #define LIGHT_TYPE_DIRECTIONAL 0 @@ -64,23 +61,19 @@ struct Light { bool has_shadow; }; - -layout(set=0,binding=3,std140) uniform Lights { - Light data[MAX_LIGHTS]; +layout(set = 0, binding = 3, std140) uniform Lights { + Light data[MAX_LIGHTS]; } lights; - - #endif // MODE COMPUTE LIGHT - #ifdef MODE_SECOND_BOUNCE -layout (set=0,binding=5) uniform texture3D color_texture; +layout(set = 0, binding = 5) uniform texture3D color_texture; #ifdef MODE_ANISOTROPIC -layout (set=0,binding=7) uniform texture3D aniso_pos_texture; -layout (set=0,binding=8) uniform texture3D aniso_neg_texture; +layout(set = 0, binding = 7) uniform texture3D aniso_pos_texture; +layout(set = 0, binding = 8) uniform texture3D aniso_neg_texture; #endif // MODE ANISOTROPIC #endif // MODE_SECOND_BOUNCE @@ -88,7 +81,6 @@ layout (set=0,binding=8) uniform texture3D aniso_neg_texture; #ifndef MODE_DYNAMIC layout(push_constant, binding = 0, std430) uniform Params { - ivec3 limits; uint stack_size; @@ -101,38 +93,33 @@ layout(push_constant, binding = 0, std430) uniform Params { uint cell_count; float aniso_strength; uint pad; - } params; - -layout(set=0,binding=4,std430) buffer Outputs { - vec4 data[]; +layout(set = 0, binding = 4, std430) buffer Outputs { + vec4 data[]; } outputs; #endif // MODE DYNAMIC -layout (set=0,binding=9) uniform texture3D texture_sdf; -layout (set=0,binding=10) uniform sampler texture_sampler; +layout(set = 0, binding = 9) uniform texture3D texture_sdf; +layout(set = 0, binding = 10) uniform sampler texture_sampler; #ifdef MODE_WRITE_TEXTURE -layout (rgba8,set=0,binding=5) uniform restrict writeonly image3D color_tex; +layout(rgba8, set = 0, binding = 5) uniform restrict writeonly image3D color_tex; #ifdef MODE_ANISOTROPIC -layout (r16ui,set=0,binding=6) uniform restrict writeonly uimage3D aniso_pos_tex; -layout (r16ui,set=0,binding=7) uniform restrict writeonly uimage3D aniso_neg_tex; +layout(r16ui, set = 0, binding = 6) uniform restrict writeonly uimage3D aniso_pos_tex; +layout(r16ui, set = 0, binding = 7) uniform restrict writeonly uimage3D aniso_neg_tex; #endif - #endif - #ifdef MODE_DYNAMIC layout(push_constant, binding = 0, std430) uniform Params { - ivec3 limits; uint light_count; //when not lighting ivec3 x_dir; @@ -155,35 +142,35 @@ layout(push_constant, binding = 0, std430) uniform Params { #ifdef MODE_DYNAMIC_LIGHTING -layout (rgba8,set=0,binding=5) uniform restrict readonly image2D source_albedo; -layout (rgba8,set=0,binding=6) uniform restrict readonly image2D source_normal; -layout (rgba8,set=0,binding=7) uniform restrict readonly image2D source_orm; +layout(rgba8, set = 0, binding = 5) uniform restrict readonly image2D source_albedo; +layout(rgba8, set = 0, binding = 6) uniform restrict readonly image2D source_normal; +layout(rgba8, set = 0, binding = 7) uniform restrict readonly image2D source_orm; //layout (set=0,binding=8) uniform texture2D source_depth; -layout (rgba16f,set=0,binding=11) uniform restrict image2D emission; -layout (r32f,set=0,binding=12) uniform restrict image2D depth; +layout(rgba16f, set = 0, binding = 11) uniform restrict image2D emission; +layout(r32f, set = 0, binding = 12) uniform restrict image2D depth; #endif #ifdef MODE_DYNAMIC_SHRINK -layout (rgba16f,set=0,binding=5) uniform restrict readonly image2D source_light; -layout (r32f,set=0,binding=6) uniform restrict readonly image2D source_depth; +layout(rgba16f, set = 0, binding = 5) uniform restrict readonly image2D source_light; +layout(r32f, set = 0, binding = 6) uniform restrict readonly image2D source_depth; #ifdef MODE_DYNAMIC_SHRINK_WRITE -layout (rgba16f,set=0,binding=7) uniform restrict writeonly image2D light; -layout (r32f,set=0,binding=8) uniform restrict writeonly image2D depth; +layout(rgba16f, set = 0, binding = 7) uniform restrict writeonly image2D light; +layout(r32f, set = 0, binding = 8) uniform restrict writeonly image2D depth; #endif // MODE_DYNAMIC_SHRINK_WRITE #ifdef MODE_DYNAMIC_SHRINK_PLOT -layout (rgba8,set=0,binding=11) uniform restrict image3D color_texture; +layout(rgba8, set = 0, binding = 11) uniform restrict image3D color_texture; #ifdef MODE_ANISOTROPIC -layout (r16ui,set=0,binding=12) uniform restrict writeonly uimage3D aniso_pos_texture; -layout (r16ui,set=0,binding=13) uniform restrict writeonly uimage3D aniso_neg_texture; +layout(r16ui, set = 0, binding = 12) uniform restrict writeonly uimage3D aniso_pos_texture; +layout(r16ui, set = 0, binding = 13) uniform restrict writeonly uimage3D aniso_neg_texture; #endif // MODE ANISOTROPIC @@ -193,25 +180,22 @@ layout (r16ui,set=0,binding=13) uniform restrict writeonly uimage3D aniso_neg_te //layout (rgba8,set=0,binding=5) uniform restrict writeonly image3D color_tex; - #endif // MODE DYNAMIC #if defined(MODE_COMPUTE_LIGHT) || defined(MODE_DYNAMIC_LIGHTING) -float raymarch(float distance,float distance_adv,vec3 from,vec3 direction) { - - +float raymarch(float distance, float distance_adv, vec3 from, vec3 direction) { vec3 cell_size = 1.0 / vec3(params.limits); float occlusion = 1.0; while (distance > 0.5) { //use this to avoid precision errors - float advance = texture(sampler3D(texture_sdf,texture_sampler),from * cell_size).r * 255.0 - 1.0; - if (advance<0.0) { + float advance = texture(sampler3D(texture_sdf, texture_sampler), from * cell_size).r * 255.0 - 1.0; + if (advance < 0.0) { occlusion = 0.0; break; } - occlusion=min(advance,occlusion); + occlusion = min(advance, occlusion); advance = max(distance_adv, advance - mod(advance, distance_adv)); //should always advance in multiples of distance_adv @@ -219,14 +203,12 @@ float raymarch(float distance,float distance_adv,vec3 from,vec3 direction) { distance -= advance; } - return occlusion;//max(0.0,distance); - + return occlusion; //max(0.0,distance); } -bool compute_light_vector(uint light, vec3 pos,out float attenuation, out vec3 light_pos) { +bool compute_light_vector(uint light, vec3 pos, out float attenuation, out vec3 light_pos) { - - if (lights.data[light].type==LIGHT_TYPE_DIRECTIONAL) { + if (lights.data[light].type == LIGHT_TYPE_DIRECTIONAL) { light_pos = pos - lights.data[light].direction * length(vec3(params.limits)); attenuation = 1.0; @@ -239,14 +221,12 @@ bool compute_light_vector(uint light, vec3 pos,out float attenuation, out vec3 l return false; } + attenuation = pow(clamp(1.0 - distance / lights.data[light].radius, 0.0001, 1.0), lights.data[light].attenuation); - attenuation = pow( clamp( 1.0 - distance / lights.data[light].radius, 0.0001, 1.0), lights.data[light].attenuation ); - - - if (lights.data[light].type==LIGHT_TYPE_SPOT) { + if (lights.data[light].type == LIGHT_TYPE_SPOT) { vec3 rel = normalize(pos - light_pos); - float angle = acos(dot(rel,lights.data[light].direction)); + float angle = acos(dot(rel, lights.data[light].direction)); if (angle > lights.data[light].spot_angle_radians) { return false; } @@ -279,23 +259,20 @@ float get_normal_advance(vec3 p_normal) { unorm = vec3(1.0, 0.0, 0.0); } - return 1.0 / dot(normal,unorm); + return 1.0 / dot(normal, unorm); } - - - void clip_segment(vec4 plane, vec3 begin, inout vec3 end) { vec3 segment = begin - end; - float den = dot(plane.xyz,segment); + float den = dot(plane.xyz, segment); //printf("den is %i\n",den); if (den < 0.0001) { return; } - float dist = (dot(plane.xyz,begin) - plane.w) / den; + float dist = (dot(plane.xyz, begin) - plane.w) / den; if (dist < 0.0001 || dist > 1.0001) { return; @@ -308,13 +285,13 @@ bool compute_light_at_pos(uint index, vec3 pos, vec3 normal, inout vec3 light, i float attenuation; vec3 light_pos; - if (!compute_light_vector(index,pos,attenuation,light_pos)) { + if (!compute_light_vector(index, pos, attenuation, light_pos)) { return false; } light_dir = normalize(pos - light_pos); - if (attenuation < 0.01 || (length(normal) > 0.2 && dot(normal,light_dir)>=0)) { + if (attenuation < 0.01 || (length(normal) > 0.2 && dot(normal, light_dir) >= 0)) { return false; //not facing the light, or attenuation is near zero } @@ -322,21 +299,19 @@ bool compute_light_at_pos(uint index, vec3 pos, vec3 normal, inout vec3 light, i float distance_adv = get_normal_advance(light_dir); - vec3 to = pos; if (length(normal) > 0.2) { to += normal * distance_adv * 0.51; } else { - to -= sign(light_dir)*0.45; //go near the edge towards the light direction to avoid self occlusion + to -= sign(light_dir) * 0.45; //go near the edge towards the light direction to avoid self occlusion } //clip - clip_segment(mix(vec4(-1.0,0.0,0.0,0.0),vec4(1.0,0.0,0.0,float(params.limits.x-1)),bvec4(light_dir.x < 0.0)),to,light_pos); - clip_segment(mix(vec4(0.0,-1.0,0.0,0.0),vec4(0.0,1.0,0.0,float(params.limits.y-1)),bvec4(light_dir.y < 0.0)),to,light_pos); - clip_segment(mix(vec4(0.0,0.0,-1.0,0.0),vec4(0.0,0.0,1.0,float(params.limits.z-1)),bvec4(light_dir.z < 0.0)),to,light_pos); + clip_segment(mix(vec4(-1.0, 0.0, 0.0, 0.0), vec4(1.0, 0.0, 0.0, float(params.limits.x - 1)), bvec4(light_dir.x < 0.0)), to, light_pos); + clip_segment(mix(vec4(0.0, -1.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, float(params.limits.y - 1)), bvec4(light_dir.y < 0.0)), to, light_pos); + clip_segment(mix(vec4(0.0, 0.0, -1.0, 0.0), vec4(0.0, 0.0, 1.0, float(params.limits.z - 1)), bvec4(light_dir.z < 0.0)), to, light_pos); - - float distance = length(to-light_pos); + float distance = length(to - light_pos); if (distance < 0.1) { return false; // hit } @@ -355,14 +330,13 @@ bool compute_light_at_pos(uint index, vec3 pos, vec3 normal, inout vec3 light, i attenuation *= 1.0 - smoothstep(0.1*distance_adv,distance_adv,dist); */ - float occlusion = raymarch(distance,distance_adv,light_pos,light_dir); + float occlusion = raymarch(distance, distance_adv, light_pos, light_dir); - if (occlusion==0.0) { + if (occlusion == 0.0) { return false; } - attenuation *= occlusion;//1.0 - smoothstep(0.1*distance_adv,distance_adv,dist); - + attenuation *= occlusion; //1.0 - smoothstep(0.1*distance_adv,distance_adv,dist); } light = lights.data[index].color * attenuation * lights.data[index].energy; @@ -375,91 +349,88 @@ void main() { #ifndef MODE_DYNAMIC - uint cell_index = gl_GlobalInvocationID.x;; + uint cell_index = gl_GlobalInvocationID.x; if (cell_index >= params.cell_count) { return; } cell_index += params.cell_offset; - uvec3 posu = uvec3(cell_data.data[cell_index].position&0x7FF,(cell_data.data[cell_index].position>>11)&0x3FF,cell_data.data[cell_index].position>>21); + uvec3 posu = uvec3(cell_data.data[cell_index].position & 0x7FF, (cell_data.data[cell_index].position >> 11) & 0x3FF, cell_data.data[cell_index].position >> 21); vec4 albedo = unpackUnorm4x8(cell_data.data[cell_index].albedo); #endif -/////////////////COMPUTE LIGHT/////////////////////////////// + /////////////////COMPUTE LIGHT/////////////////////////////// #ifdef MODE_COMPUTE_LIGHT vec3 pos = vec3(posu) + vec3(0.5); - vec3 emission = vec3(uvec3(cell_data.data[cell_index].emission & 0x1ff,(cell_data.data[cell_index].emission >> 9) & 0x1ff,(cell_data.data[cell_index].emission >> 18) & 0x1ff)) * pow(2.0, float(cell_data.data[cell_index].emission >> 27) - 15.0 - 9.0); + vec3 emission = vec3(uvec3(cell_data.data[cell_index].emission & 0x1ff, (cell_data.data[cell_index].emission >> 9) & 0x1ff, (cell_data.data[cell_index].emission >> 18) & 0x1ff)) * pow(2.0, float(cell_data.data[cell_index].emission >> 27) - 15.0 - 9.0); vec3 normal = unpackSnorm4x8(cell_data.data[cell_index].normal).xyz; #ifdef MODE_ANISOTROPIC - vec3 accum[6]=vec3[](vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0)); - const vec3 accum_dirs[6]=vec3[](vec3(1.0,0.0,0.0),vec3(-1.0,0.0,0.0),vec3(0.0,1.0,0.0),vec3(0.0,-1.0,0.0),vec3(0.0,0.0,1.0),vec3(0.0,0.0,-1.0)); + vec3 accum[6] = vec3[](vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0)); + const vec3 accum_dirs[6] = vec3[](vec3(1.0, 0.0, 0.0), vec3(-1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(0.0, -1.0, 0.0), vec3(0.0, 0.0, 1.0), vec3(0.0, 0.0, -1.0)); #else vec3 accum = vec3(0.0); #endif - for(uint i=0;i<params.light_count;i++) { + for (uint i = 0; i < params.light_count; i++) { vec3 light; vec3 light_dir; - if (!compute_light_at_pos(i,pos,normal.xyz,light,light_dir)) { + if (!compute_light_at_pos(i, pos, normal.xyz, light, light_dir)) { continue; } - light*= albedo.rgb; + light *= albedo.rgb; #ifdef MODE_ANISOTROPIC - for(uint j=0;j<6;j++) { + for (uint j = 0; j < 6; j++) { - accum[j]+=max(0.0,dot(accum_dirs[j],-light_dir))*light; + accum[j] += max(0.0, dot(accum_dirs[j], -light_dir)) * light; } #else if (length(normal) > 0.2) { - accum+=max(0.0,dot(normal,-light_dir))*light; + accum += max(0.0, dot(normal, -light_dir)) * light; } else { //all directions - accum+=light; + accum += light; } #endif } - #ifdef MODE_ANISOTROPIC - for(uint i=0;i<6;i++) { + for (uint i = 0; i < 6; i++) { vec3 light = accum[i]; if (length(normal) > 0.2) { - light += max(0.0,dot(accum_dirs[i],-normal)) * emission; + light += max(0.0, dot(accum_dirs[i], -normal)) * emission; } else { light += emission; } - outputs.data[cell_index*6+i] = vec4(light,0.0); + outputs.data[cell_index * 6 + i] = vec4(light, 0.0); } #else - outputs.data[cell_index]=vec4(accum + emission,0.0); + outputs.data[cell_index] = vec4(accum + emission, 0.0); #endif - - #endif //MODE_COMPUTE_LIGHT -/////////////////SECOND BOUNCE/////////////////////////////// + /////////////////SECOND BOUNCE/////////////////////////////// + #ifdef MODE_SECOND_BOUNCE vec3 pos = vec3(posu) + vec3(0.5); ivec3 ipos = ivec3(posu); vec4 normal = unpackSnorm4x8(cell_data.data[cell_index].normal); - #ifdef MODE_ANISOTROPIC vec3 accum[6]; - const vec3 accum_dirs[6]=vec3[](vec3(1.0,0.0,0.0),vec3(-1.0,0.0,0.0),vec3(0.0,1.0,0.0),vec3(0.0,-1.0,0.0),vec3(0.0,0.0,1.0),vec3(0.0,0.0,-1.0)); + const vec3 accum_dirs[6] = vec3[](vec3(1.0, 0.0, 0.0), vec3(-1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(0.0, -1.0, 0.0), vec3(0.0, 0.0, 1.0), vec3(0.0, 0.0, -1.0)); /*vec3 src_color = texelFetch(sampler3D(color_texture,texture_sampler),ipos,0).rgb * params.dynamic_range; vec3 src_aniso_pos = texelFetch(sampler3D(aniso_pos_texture,texture_sampler),ipos,0).rgb; @@ -471,12 +442,12 @@ void main() { accum[4]=src_col * src_aniso_pos.z; accum[5]=src_col * src_aniso_neg.z;*/ - accum[0] = outputs.data[cell_index*6+0].rgb; - accum[1] = outputs.data[cell_index*6+1].rgb; - accum[2] = outputs.data[cell_index*6+2].rgb; - accum[3] = outputs.data[cell_index*6+3].rgb; - accum[4] = outputs.data[cell_index*6+4].rgb; - accum[5] = outputs.data[cell_index*6+5].rgb; + accum[0] = outputs.data[cell_index * 6 + 0].rgb; + accum[1] = outputs.data[cell_index * 6 + 1].rgb; + accum[2] = outputs.data[cell_index * 6 + 2].rgb; + accum[3] = outputs.data[cell_index * 6 + 3].rgb; + accum[4] = outputs.data[cell_index * 6 + 4].rgb; + accum[5] = outputs.data[cell_index * 6 + 5].rgb; #else vec3 accum = outputs.data[cell_index].rgb; @@ -493,12 +464,12 @@ void main() { #define MAX_CONE_DIRS 6 vec3 cone_dirs[MAX_CONE_DIRS] = vec3[]( - vec3(0.0, 0.0, 1.0), - vec3(0.866025, 0.0, 0.5), - vec3(0.267617, 0.823639, 0.5), - vec3(-0.700629, 0.509037, 0.5), - vec3(-0.700629, -0.509037, 0.5), - vec3(0.267617, -0.823639, 0.5)); + vec3(0.0, 0.0, 1.0), + vec3(0.866025, 0.0, 0.5), + vec3(0.267617, 0.823639, 0.5), + vec3(-0.700629, 0.509037, 0.5), + vec3(-0.700629, -0.509037, 0.5), + vec3(0.267617, -0.823639, 0.5)); float cone_weights[MAX_CONE_DIRS] = float[](0.25, 0.15, 0.15, 0.15, 0.15, 0.15); float tan_half_angle = 0.577; @@ -514,7 +485,7 @@ void main() { vec3 cell_size = 1.0 / vec3(params.limits); #ifdef MODE_ANISOTROPIC - vec3 aniso_normal = mix(direction,normal.xyz,params.aniso_strength); + vec3 aniso_normal = mix(direction, normal.xyz, params.aniso_strength); #endif while (dist < max_distance && color.a < 0.95) { float diameter = max(1.0, 2.0 * tan_half_angle * dist); @@ -526,148 +497,141 @@ void main() { //} float log2_diameter = log2(diameter); - vec4 scolor = textureLod(sampler3D(color_texture,texture_sampler), uvw_pos, log2_diameter); + vec4 scolor = textureLod(sampler3D(color_texture, texture_sampler), uvw_pos, log2_diameter); #ifdef MODE_ANISOTROPIC - vec3 aniso_neg = textureLod(sampler3D(aniso_neg_texture,texture_sampler), uvw_pos, log2_diameter).rgb; - vec3 aniso_pos = textureLod(sampler3D(aniso_pos_texture,texture_sampler), uvw_pos, log2_diameter).rgb; + vec3 aniso_neg = textureLod(sampler3D(aniso_neg_texture, texture_sampler), uvw_pos, log2_diameter).rgb; + vec3 aniso_pos = textureLod(sampler3D(aniso_pos_texture, texture_sampler), uvw_pos, log2_diameter).rgb; - scolor.rgb*=dot(max(vec3(0.0),(aniso_normal * aniso_pos)),vec3(1.0)) + dot(max(vec3(0.0),(-aniso_normal * aniso_neg)),vec3(1.0)); + scolor.rgb *= dot(max(vec3(0.0), (aniso_normal * aniso_pos)), vec3(1.0)) + dot(max(vec3(0.0), (-aniso_normal * aniso_neg)), vec3(1.0)); #endif float a = (1.0 - color.a); color += a * scolor; dist += half_diameter; - } - } - color *= cone_weights[i] * vec4(albedo.rgb,1.0) * params.dynamic_range; //restore range + color *= cone_weights[i] * vec4(albedo.rgb, 1.0) * params.dynamic_range; //restore range #ifdef MODE_ANISOTROPIC - for(uint j=0;j<6;j++) { + for (uint j = 0; j < 6; j++) { - accum[j]+=max(0.0,dot(accum_dirs[j],direction))*color.rgb; + accum[j] += max(0.0, dot(accum_dirs[j], direction)) * color.rgb; } #else - accum+=color.rgb; + accum += color.rgb; #endif } } #ifdef MODE_ANISOTROPIC - outputs.data[cell_index*6+0]=vec4(accum[0],0.0); - outputs.data[cell_index*6+1]=vec4(accum[1],0.0); - outputs.data[cell_index*6+2]=vec4(accum[2],0.0); - outputs.data[cell_index*6+3]=vec4(accum[3],0.0); - outputs.data[cell_index*6+4]=vec4(accum[4],0.0); - outputs.data[cell_index*6+5]=vec4(accum[5],0.0); + outputs.data[cell_index * 6 + 0] = vec4(accum[0], 0.0); + outputs.data[cell_index * 6 + 1] = vec4(accum[1], 0.0); + outputs.data[cell_index * 6 + 2] = vec4(accum[2], 0.0); + outputs.data[cell_index * 6 + 3] = vec4(accum[3], 0.0); + outputs.data[cell_index * 6 + 4] = vec4(accum[4], 0.0); + outputs.data[cell_index * 6 + 5] = vec4(accum[5], 0.0); #else - outputs.data[cell_index]=vec4(accum,0.0); + outputs.data[cell_index] = vec4(accum, 0.0); #endif #endif // MODE_SECOND_BOUNCE -/////////////////UPDATE MIPMAPS/////////////////////////////// + + /////////////////UPDATE MIPMAPS/////////////////////////////// #ifdef MODE_UPDATE_MIPMAPS { #ifdef MODE_ANISOTROPIC - vec3 light_accum[6] = vec3[](vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0)); + vec3 light_accum[6] = vec3[](vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0)); #else vec3 light_accum = vec3(0.0); #endif float count = 0.0; - for(uint i=0;i<8;i++) { + for (uint i = 0; i < 8; i++) { uint child_index = cell_children.data[cell_index].children[i]; - if (child_index==NO_CHILDREN) { + if (child_index == NO_CHILDREN) { continue; } #ifdef MODE_ANISOTROPIC - light_accum[0] += outputs.data[child_index*6+0].rgb; - light_accum[1] += outputs.data[child_index*6+1].rgb; - light_accum[2] += outputs.data[child_index*6+2].rgb; - light_accum[3] += outputs.data[child_index*6+3].rgb; - light_accum[4] += outputs.data[child_index*6+4].rgb; - light_accum[5] += outputs.data[child_index*6+5].rgb; + light_accum[0] += outputs.data[child_index * 6 + 0].rgb; + light_accum[1] += outputs.data[child_index * 6 + 1].rgb; + light_accum[2] += outputs.data[child_index * 6 + 2].rgb; + light_accum[3] += outputs.data[child_index * 6 + 3].rgb; + light_accum[4] += outputs.data[child_index * 6 + 4].rgb; + light_accum[5] += outputs.data[child_index * 6 + 5].rgb; #else light_accum += outputs.data[child_index].rgb; #endif - count+=1.0; + count += 1.0; } - float divisor = mix(8.0,count,params.propagation); + float divisor = mix(8.0, count, params.propagation); #ifdef MODE_ANISOTROPIC - outputs.data[cell_index*6+0]=vec4(light_accum[0] / divisor,0.0); - outputs.data[cell_index*6+1]=vec4(light_accum[1] / divisor,0.0); - outputs.data[cell_index*6+2]=vec4(light_accum[2] / divisor,0.0); - outputs.data[cell_index*6+3]=vec4(light_accum[3] / divisor,0.0); - outputs.data[cell_index*6+4]=vec4(light_accum[4] / divisor,0.0); - outputs.data[cell_index*6+5]=vec4(light_accum[5] / divisor,0.0); + outputs.data[cell_index * 6 + 0] = vec4(light_accum[0] / divisor, 0.0); + outputs.data[cell_index * 6 + 1] = vec4(light_accum[1] / divisor, 0.0); + outputs.data[cell_index * 6 + 2] = vec4(light_accum[2] / divisor, 0.0); + outputs.data[cell_index * 6 + 3] = vec4(light_accum[3] / divisor, 0.0); + outputs.data[cell_index * 6 + 4] = vec4(light_accum[4] / divisor, 0.0); + outputs.data[cell_index * 6 + 5] = vec4(light_accum[5] / divisor, 0.0); #else - outputs.data[cell_index]=vec4(light_accum / divisor,0.0); + outputs.data[cell_index] = vec4(light_accum / divisor, 0.0); #endif - - - } #endif -///////////////////WRITE TEXTURE///////////////////////////// + ///////////////////WRITE TEXTURE///////////////////////////// #ifdef MODE_WRITE_TEXTURE { #ifdef MODE_ANISOTROPIC vec3 accum_total = vec3(0.0); - accum_total += outputs.data[cell_index*6+0].rgb; - accum_total += outputs.data[cell_index*6+1].rgb; - accum_total += outputs.data[cell_index*6+2].rgb; - accum_total += outputs.data[cell_index*6+3].rgb; - accum_total += outputs.data[cell_index*6+4].rgb; - accum_total += outputs.data[cell_index*6+5].rgb; - - float accum_total_energy = max(dot(accum_total,GREY_VEC),0.00001); - vec3 iso_positive = vec3(dot(outputs.data[cell_index*6+0].rgb,GREY_VEC),dot(outputs.data[cell_index*6+2].rgb,GREY_VEC),dot(outputs.data[cell_index*6+4].rgb,GREY_VEC))/vec3(accum_total_energy); - vec3 iso_negative = vec3(dot(outputs.data[cell_index*6+1].rgb,GREY_VEC),dot(outputs.data[cell_index*6+3].rgb,GREY_VEC),dot(outputs.data[cell_index*6+5].rgb,GREY_VEC))/vec3(accum_total_energy); + accum_total += outputs.data[cell_index * 6 + 0].rgb; + accum_total += outputs.data[cell_index * 6 + 1].rgb; + accum_total += outputs.data[cell_index * 6 + 2].rgb; + accum_total += outputs.data[cell_index * 6 + 3].rgb; + accum_total += outputs.data[cell_index * 6 + 4].rgb; + accum_total += outputs.data[cell_index * 6 + 5].rgb; + float accum_total_energy = max(dot(accum_total, GREY_VEC), 0.00001); + vec3 iso_positive = vec3(dot(outputs.data[cell_index * 6 + 0].rgb, GREY_VEC), dot(outputs.data[cell_index * 6 + 2].rgb, GREY_VEC), dot(outputs.data[cell_index * 6 + 4].rgb, GREY_VEC)) / vec3(accum_total_energy); + vec3 iso_negative = vec3(dot(outputs.data[cell_index * 6 + 1].rgb, GREY_VEC), dot(outputs.data[cell_index * 6 + 3].rgb, GREY_VEC), dot(outputs.data[cell_index * 6 + 5].rgb, GREY_VEC)) / vec3(accum_total_energy); { - uint aniso_pos = uint(clamp(iso_positive.b * 31.0,0.0,31.0)); - aniso_pos |= uint(clamp(iso_positive.g * 63.0,0.0,63.0))<<5; - aniso_pos |= uint(clamp(iso_positive.r * 31.0,0.0,31.0))<<11; - imageStore(aniso_pos_tex,ivec3(posu),uvec4(aniso_pos)); + uint aniso_pos = uint(clamp(iso_positive.b * 31.0, 0.0, 31.0)); + aniso_pos |= uint(clamp(iso_positive.g * 63.0, 0.0, 63.0)) << 5; + aniso_pos |= uint(clamp(iso_positive.r * 31.0, 0.0, 31.0)) << 11; + imageStore(aniso_pos_tex, ivec3(posu), uvec4(aniso_pos)); } { - uint aniso_neg = uint(clamp(iso_negative.b * 31.0,0.0,31.0)); - aniso_neg |= uint(clamp(iso_negative.g * 63.0,0.0,63.0))<<5; - aniso_neg |= uint(clamp(iso_negative.r * 31.0,0.0,31.0))<<11; - imageStore(aniso_neg_tex,ivec3(posu),uvec4(aniso_neg)); + uint aniso_neg = uint(clamp(iso_negative.b * 31.0, 0.0, 31.0)); + aniso_neg |= uint(clamp(iso_negative.g * 63.0, 0.0, 63.0)) << 5; + aniso_neg |= uint(clamp(iso_negative.r * 31.0, 0.0, 31.0)) << 11; + imageStore(aniso_neg_tex, ivec3(posu), uvec4(aniso_neg)); } - imageStore(color_tex,ivec3(posu),vec4(accum_total / params.dynamic_range ,albedo.a)); + imageStore(color_tex, ivec3(posu), vec4(accum_total / params.dynamic_range, albedo.a)); #else - imageStore(color_tex,ivec3(posu),vec4(outputs.data[cell_index].rgb / params.dynamic_range,albedo.a)); + imageStore(color_tex, ivec3(posu), vec4(outputs.data[cell_index].rgb / params.dynamic_range, albedo.a)); #endif - - } #endif -///////////////////DYNAMIC LIGHTING///////////////////////////// + ///////////////////DYNAMIC LIGHTING///////////////////////////// #ifdef MODE_DYNAMIC ivec2 pos_xy = ivec2(gl_GlobalInvocationID.xy); - if (any(greaterThanEqual(pos_xy,params.rect_size))) { + if (any(greaterThanEqual(pos_xy, params.rect_size))) { return; //out of bounds } @@ -679,47 +643,38 @@ void main() { uv_xy.y = params.rect_size.y - pos_xy.y - 1; } - #ifdef MODE_DYNAMIC_LIGHTING - { + float z = params.z_base + imageLoad(depth, uv_xy).x * params.z_sign; + ivec3 pos = params.x_dir * (params.rect_pos.x + pos_xy.x) + params.y_dir * (params.rect_pos.y + pos_xy.y) + abs(params.z_dir) * int(z); - float z = params.z_base + imageLoad(depth,uv_xy).x * params.z_sign; - - ivec3 pos = params.x_dir * (params.rect_pos.x + pos_xy.x) + params.y_dir * (params.rect_pos.y + pos_xy.y) + abs(params.z_dir) * int(z); - - vec3 normal = imageLoad(source_normal,uv_xy).xyz * 2.0 - 1.0; - normal = vec3(params.x_dir) * normal.x * mix(1.0,-1.0,params.flip_x) + vec3(params.y_dir) * normal.y * mix(1.0,-1.0,params.flip_y) - vec3(params.z_dir) * normal.z; - - - + vec3 normal = imageLoad(source_normal, uv_xy).xyz * 2.0 - 1.0; + normal = vec3(params.x_dir) * normal.x * mix(1.0, -1.0, params.flip_x) + vec3(params.y_dir) * normal.y * mix(1.0, -1.0, params.flip_y) - vec3(params.z_dir) * normal.z; - vec4 albedo = imageLoad(source_albedo,uv_xy); + vec4 albedo = imageLoad(source_albedo, uv_xy); //determine the position in space vec3 accum = vec3(0.0); - for(uint i=0;i<params.light_count;i++) { + for (uint i = 0; i < params.light_count; i++) { vec3 light; vec3 light_dir; - if (!compute_light_at_pos(i,vec3(pos) * params.pos_multiplier,normal,light,light_dir)) { + if (!compute_light_at_pos(i, vec3(pos) * params.pos_multiplier, normal, light, light_dir)) { continue; } - light*= albedo.rgb; - - accum+=max(0.0,dot(normal,-light_dir))*light; + light *= albedo.rgb; + accum += max(0.0, dot(normal, -light_dir)) * light; } - accum+=imageLoad(emission,uv_xy).xyz; - - imageStore(emission,uv_xy,vec4(accum,albedo.a)); - imageStore(depth,uv_xy,vec4(z)); + accum += imageLoad(emission, uv_xy).xyz; + imageStore(emission, uv_xy, vec4(accum, albedo.a)); + imageStore(depth, uv_xy, vec4(z)); } #endif // MODE DYNAMIC LIGHTING @@ -731,9 +686,9 @@ void main() { float accum_z = 0.0; float count = 0.0; - for(int i=0;i<4;i++) { - ivec2 ofs = pos_xy*2 + ivec2(i&1,i>>1) - params.prev_rect_ofs; - if (any(lessThan(ofs,ivec2(0))) || any(greaterThanEqual(ofs,params.prev_rect_size))) { + for (int i = 0; i < 4; i++) { + ivec2 ofs = pos_xy * 2 + ivec2(i & 1, i >> 1) - params.prev_rect_ofs; + if (any(lessThan(ofs, ivec2(0))) || any(greaterThanEqual(ofs, params.prev_rect_size))) { continue; } if (params.flip_x) { @@ -743,67 +698,64 @@ void main() { ofs.y = params.prev_rect_size.y - ofs.y - 1; } - vec4 light = imageLoad(source_light,ofs); - if (light.a==0.0) { //ignore empty + vec4 light = imageLoad(source_light, ofs); + if (light.a == 0.0) { //ignore empty continue; } accum += light; - float z = imageLoad(source_depth,ofs).x; - accum_z += z*0.5; //shrink half too - count+=1.0; + float z = imageLoad(source_depth, ofs).x; + accum_z += z * 0.5; //shrink half too + count += 1.0; } - if (params.on_mipmap) { - accum.rgb /= mix(8.0,count,params.propagation); + accum.rgb /= mix(8.0, count, params.propagation); accum.a /= 8.0; } else { - accum/=4.0; + accum /= 4.0; } - if (count==0.0) { - accum_z=0.0; //avoid nan + if (count == 0.0) { + accum_z = 0.0; //avoid nan } else { - accum_z/=count; + accum_z /= count; } #ifdef MODE_DYNAMIC_SHRINK_WRITE - imageStore(light,uv_xy,accum); - imageStore(depth,uv_xy,vec4(accum_z)); + imageStore(light, uv_xy, accum); + imageStore(depth, uv_xy, vec4(accum_z)); #endif #ifdef MODE_DYNAMIC_SHRINK_PLOT - - if (accum.a<0.001) { + if (accum.a < 0.001) { return; //do not blit if alpha is too low } - ivec3 pos = params.x_dir * (params.rect_pos.x + pos_xy.x) + params.y_dir * (params.rect_pos.y + pos_xy.y) + abs(params.z_dir) * int(accum_z); + ivec3 pos = params.x_dir * (params.rect_pos.x + pos_xy.x) + params.y_dir * (params.rect_pos.y + pos_xy.y) + abs(params.z_dir) * int(accum_z); float z_frac = fract(accum_z); - for(int i = 0; i< 2; i++) { + for (int i = 0; i < 2; i++) { ivec3 pos3d = pos + abs(params.z_dir) * i; - if (any(lessThan(pos3d,ivec3(0))) || any(greaterThanEqual(pos3d,params.limits))) { + if (any(lessThan(pos3d, ivec3(0))) || any(greaterThanEqual(pos3d, params.limits))) { //skip if offlimits continue; } - vec4 color_blit = accum * (i==0 ? 1.0 - z_frac : z_frac ); - vec4 color = imageLoad(color_texture,pos3d); - color.rgb *=params.dynamic_range; + vec4 color_blit = accum * (i == 0 ? 1.0 - z_frac : z_frac); + vec4 color = imageLoad(color_texture, pos3d); + color.rgb *= params.dynamic_range; #if 0 color.rgb = mix(color.rgb,color_blit.rgb,color_blit.a); color.a+=color_blit.a; #else - float sa = 1.0 - color_blit.a; vec4 result; result.a = color.a * sa + color_blit.a; - if (result.a==0.0) { + if (result.a == 0.0) { result = vec4(0.0); } else { result.rgb = (color.rgb * color.a * sa + color_blit.rgb * color_blit.a) / result.a; @@ -812,19 +764,17 @@ void main() { #endif color.rgb /= params.dynamic_range; - imageStore(color_texture,pos3d,color); + imageStore(color_texture, pos3d, color); //imageStore(color_texture,pos3d,vec4(1,1,1,1)); #ifdef MODE_ANISOTROPIC //do not care about anisotropy for dynamic objects, just store full lit in all directions - imageStore(aniso_pos_texture,pos3d,uvec4(0xFFFF)); - imageStore(aniso_neg_texture,pos3d,uvec4(0xFFFF)); + imageStore(aniso_pos_texture, pos3d, uvec4(0xFFFF)); + imageStore(aniso_neg_texture, pos3d, uvec4(0xFFFF)); #endif // ANISOTROPIC } #endif // MODE_DYNAMIC_SHRINK_PLOT - - } #endif diff --git a/servers/visual/rasterizer_rd/shaders/giprobe_debug.glsl b/servers/visual/rasterizer_rd/shaders/giprobe_debug.glsl index 7218d2da3a..fa5e07bf3c 100644 --- a/servers/visual/rasterizer_rd/shaders/giprobe_debug.glsl +++ b/servers/visual/rasterizer_rd/shaders/giprobe_debug.glsl @@ -1,3 +1,4 @@ +/* clang-format off */ [vertex] #version 450 @@ -10,21 +11,21 @@ struct CellData { uint emission; //rgb normalized with e as multiplier uint normal; //RGB normal encoded }; +/* clang-format on */ -layout(set=0,binding=1,std140) buffer CellDataBuffer { - CellData data[]; +layout(set = 0, binding = 1, std140) buffer CellDataBuffer { + CellData data[]; } cell_data; -layout (set=0,binding=2) uniform texture3D color_tex; +layout(set = 0, binding = 2) uniform texture3D color_tex; -layout (set=0,binding=3) uniform sampler tex_sampler; +layout(set = 0, binding = 3) uniform sampler tex_sampler; #ifdef USE_ANISOTROPY -layout (set=0,binding=4) uniform texture3D aniso_pos_tex; -layout (set=0,binding=5) uniform texture3D aniso_neg_tex; +layout(set = 0, binding = 4) uniform texture3D aniso_pos_tex; +layout(set = 0, binding = 5) uniform texture3D aniso_neg_tex; #endif - layout(push_constant, binding = 0, std430) uniform Params { mat4 projection; @@ -34,64 +35,61 @@ layout(push_constant, binding = 0, std430) uniform Params { uint level; ivec3 bounds; uint pad; - } params; -layout(location=0) out vec4 color_interp; +layout(location = 0) out vec4 color_interp; void main() { const vec3 cube_triangles[36] = vec3[]( - vec3(-1.0f,-1.0f,-1.0f), - vec3(-1.0f,-1.0f, 1.0f), - vec3(-1.0f, 1.0f, 1.0f), - vec3(1.0f, 1.0f,-1.0f), - vec3(-1.0f,-1.0f,-1.0f), - vec3(-1.0f, 1.0f,-1.0f), - vec3(1.0f,-1.0f, 1.0f), - vec3(-1.0f,-1.0f,-1.0f), - vec3(1.0f,-1.0f,-1.0f), - vec3(1.0f, 1.0f,-1.0f), - vec3(1.0f,-1.0f,-1.0f), - vec3(-1.0f,-1.0f,-1.0f), - vec3(-1.0f,-1.0f,-1.0f), - vec3(-1.0f, 1.0f, 1.0f), - vec3(-1.0f, 1.0f,-1.0f), - vec3(1.0f,-1.0f, 1.0f), - vec3(-1.0f,-1.0f, 1.0f), - vec3(-1.0f,-1.0f,-1.0f), - vec3(-1.0f, 1.0f, 1.0f), - vec3(-1.0f,-1.0f, 1.0f), - vec3(1.0f,-1.0f, 1.0f), - vec3(1.0f, 1.0f, 1.0f), - vec3(1.0f,-1.0f,-1.0f), - vec3(1.0f, 1.0f,-1.0f), - vec3(1.0f,-1.0f,-1.0f), - vec3(1.0f, 1.0f, 1.0f), - vec3(1.0f,-1.0f, 1.0f), - vec3(1.0f, 1.0f, 1.0f), - vec3(1.0f, 1.0f,-1.0f), - vec3(-1.0f, 1.0f,-1.0f), - vec3(1.0f, 1.0f, 1.0f), - vec3(-1.0f, 1.0f,-1.0f), - vec3(-1.0f, 1.0f, 1.0f), - vec3(1.0f, 1.0f, 1.0f), - vec3(-1.0f, 1.0f, 1.0f), - vec3(1.0f,-1.0f, 1.0f) - ); - + vec3(-1.0f, -1.0f, -1.0f), + vec3(-1.0f, -1.0f, 1.0f), + vec3(-1.0f, 1.0f, 1.0f), + vec3(1.0f, 1.0f, -1.0f), + vec3(-1.0f, -1.0f, -1.0f), + vec3(-1.0f, 1.0f, -1.0f), + vec3(1.0f, -1.0f, 1.0f), + vec3(-1.0f, -1.0f, -1.0f), + vec3(1.0f, -1.0f, -1.0f), + vec3(1.0f, 1.0f, -1.0f), + vec3(1.0f, -1.0f, -1.0f), + vec3(-1.0f, -1.0f, -1.0f), + vec3(-1.0f, -1.0f, -1.0f), + vec3(-1.0f, 1.0f, 1.0f), + vec3(-1.0f, 1.0f, -1.0f), + vec3(1.0f, -1.0f, 1.0f), + vec3(-1.0f, -1.0f, 1.0f), + vec3(-1.0f, -1.0f, -1.0f), + vec3(-1.0f, 1.0f, 1.0f), + vec3(-1.0f, -1.0f, 1.0f), + vec3(1.0f, -1.0f, 1.0f), + vec3(1.0f, 1.0f, 1.0f), + vec3(1.0f, -1.0f, -1.0f), + vec3(1.0f, 1.0f, -1.0f), + vec3(1.0f, -1.0f, -1.0f), + vec3(1.0f, 1.0f, 1.0f), + vec3(1.0f, -1.0f, 1.0f), + vec3(1.0f, 1.0f, 1.0f), + vec3(1.0f, 1.0f, -1.0f), + vec3(-1.0f, 1.0f, -1.0f), + vec3(1.0f, 1.0f, 1.0f), + vec3(-1.0f, 1.0f, -1.0f), + vec3(-1.0f, 1.0f, 1.0f), + vec3(1.0f, 1.0f, 1.0f), + vec3(-1.0f, 1.0f, 1.0f), + vec3(1.0f, -1.0f, 1.0f)); vec3 vertex = cube_triangles[gl_VertexIndex] * 0.5 + 0.5; #ifdef MODE_DEBUG_LIGHT_FULL - uvec3 posu = uvec3( gl_InstanceIndex % params.bounds.x, (gl_InstanceIndex / params.bounds.x) % params.bounds.y,gl_InstanceIndex / (params.bounds.y * params.bounds.x) ); + uvec3 posu = uvec3(gl_InstanceIndex % params.bounds.x, (gl_InstanceIndex / params.bounds.x) % params.bounds.y, gl_InstanceIndex / (params.bounds.y * params.bounds.x)); #else uint cell_index = gl_InstanceIndex + params.cell_offset; - uvec3 posu = uvec3(cell_data.data[cell_index].position&0x7FF,(cell_data.data[cell_index].position>>11)&0x3FF,cell_data.data[cell_index].position>>21); + uvec3 posu = uvec3(cell_data.data[cell_index].position & 0x7FF, (cell_data.data[cell_index].position >> 11) & 0x3FF, cell_data.data[cell_index].position >> 21); #endif #ifdef MODE_DEBUG_EMISSION - color_interp.xyz = vec3(uvec3(cell_data.data[cell_index].emission & 0x1ff,(cell_data.data[cell_index].emission >> 9) & 0x1ff,(cell_data.data[cell_index].emission >> 18) & 0x1ff)) * pow(2.0, float(cell_data.data[cell_index].emission >> 27) - 15.0 - 9.0); + color_interp.xyz = vec3(uvec3(cell_data.data[cell_index].emission & 0x1ff, (cell_data.data[cell_index].emission >> 9) & 0x1ff, (cell_data.data[cell_index].emission >> 18) & 0x1ff)) * pow(2.0, float(cell_data.data[cell_index].emission >> 27) - 15.0 - 9.0); #endif #ifdef MODE_DEBUG_COLOR @@ -121,37 +119,35 @@ void main() { POS_X, POS_Y, POS_Y, - POS_Z - ); + POS_Z); - color_interp.xyz = texelFetch(sampler3D(color_tex,tex_sampler),ivec3(posu),int(params.level)).xyz * params.dynamic_range; - vec3 aniso_pos = texelFetch(sampler3D(aniso_pos_tex,tex_sampler),ivec3(posu),int(params.level)).xyz; - vec3 aniso_neg = texelFetch(sampler3D(aniso_neg_tex,tex_sampler),ivec3(posu),int(params.level)).xyz; - uint side = triangle_aniso[gl_VertexIndex/3]; + color_interp.xyz = texelFetch(sampler3D(color_tex, tex_sampler), ivec3(posu), int(params.level)).xyz * params.dynamic_range; + vec3 aniso_pos = texelFetch(sampler3D(aniso_pos_tex, tex_sampler), ivec3(posu), int(params.level)).xyz; + vec3 aniso_neg = texelFetch(sampler3D(aniso_neg_tex, tex_sampler), ivec3(posu), int(params.level)).xyz; + uint side = triangle_aniso[gl_VertexIndex / 3]; float strength = 0.0; - switch(side) { - case POS_X: strength = aniso_pos.x; break; - case POS_Y: strength = aniso_pos.y; break; - case POS_Z: strength = aniso_pos.z; break; - case NEG_X: strength = aniso_neg.x; break; - case NEG_Y: strength = aniso_neg.y; break; - case NEG_Z: strength = aniso_neg.z; break; - + switch (side) { + case POS_X: strength = aniso_pos.x; break; + case POS_Y: strength = aniso_pos.y; break; + case POS_Z: strength = aniso_pos.z; break; + case NEG_X: strength = aniso_neg.x; break; + case NEG_Y: strength = aniso_neg.y; break; + case NEG_Z: strength = aniso_neg.z; break; } color_interp.xyz *= strength; #else - color_interp = texelFetch(sampler3D(color_tex,tex_sampler),ivec3(posu),int(params.level)); - color_interp.xyz * params.dynamic_range; + color_interp = texelFetch(sampler3D(color_tex, tex_sampler), ivec3(posu), int(params.level)); + color_interp.xyz *params.dynamic_range; #endif #endif - float scale = (1<<params.level); + float scale = (1 << params.level); - gl_Position = params.projection * vec4((vec3(posu)+vertex)*scale,1.0); + gl_Position = params.projection * vec4((vec3(posu) + vertex) * scale, 1.0); #ifdef MODE_DEBUG_LIGHT_FULL if (color_interp.a == 0.0) { @@ -160,17 +156,18 @@ void main() { #else color_interp.a = params.alpha; #endif - } +/* clang-format off */ [fragment] #version 450 VERSION_DEFINES -layout(location=0) in vec4 color_interp; -layout(location=0) out vec4 frag_color; +layout(location = 0) in vec4 color_interp; +/* clang-format on */ +layout(location = 0) out vec4 frag_color; void main() { diff --git a/servers/visual/rasterizer_rd/shaders/giprobe_sdf.glsl b/servers/visual/rasterizer_rd/shaders/giprobe_sdf.glsl index 02f0f67a15..dd3910f52e 100644 --- a/servers/visual/rasterizer_rd/shaders/giprobe_sdf.glsl +++ b/servers/visual/rasterizer_rd/shaders/giprobe_sdf.glsl @@ -1,3 +1,4 @@ +/* clang-format off */ [compute] #version 450 @@ -5,21 +6,21 @@ VERSION_DEFINES layout(local_size_x = 4, local_size_y = 4, local_size_z = 4) in; +/* clang-format on */ #define MAX_DISTANCE 100000 #define NO_CHILDREN 0xFFFFFFFF -#define GREY_VEC vec3(0.33333,0.33333,0.33333) +#define GREY_VEC vec3(0.33333, 0.33333, 0.33333) struct CellChildren { uint children[8]; }; -layout(set=0,binding=1,std430) buffer CellChildrenBuffer { - CellChildren data[]; +layout(set = 0, binding = 1, std430) buffer CellChildrenBuffer { + CellChildren data[]; } cell_children; - struct CellData { uint position; // xyz 10 bits uint albedo; //rgb albedo @@ -27,15 +28,13 @@ struct CellData { uint normal; //RGB normal encoded }; -layout(set=0,binding=2,std430) buffer CellDataBuffer { - CellData data[]; +layout(set = 0, binding = 2, std430) buffer CellDataBuffer { + CellData data[]; } cell_data; -layout (r8ui,set=0,binding=3) uniform restrict writeonly uimage3D sdf_tex; - +layout(r8ui, set = 0, binding = 3) uniform restrict writeonly uimage3D sdf_tex; layout(push_constant, binding = 0, std430) uniform Params { - uint offset; uint end; uint pad0; @@ -47,9 +46,9 @@ void main() { vec3 pos = vec3(gl_GlobalInvocationID); float closest_dist = 100000.0; - for(uint i=params.offset;i<params.end;i++) { - vec3 posu = vec3(uvec3(cell_data.data[i].position&0x7FF,(cell_data.data[i].position>>11)&0x3FF,cell_data.data[i].position>>21)); - float dist = length(pos-posu); + for (uint i = params.offset; i < params.end; i++) { + vec3 posu = vec3(uvec3(cell_data.data[i].position & 0x7FF, (cell_data.data[i].position >> 11) & 0x3FF, cell_data.data[i].position >> 21)); + float dist = length(pos - posu); if (dist < closest_dist) { closest_dist = dist; } @@ -57,17 +56,16 @@ void main() { uint dist_8; - if (closest_dist<0.0001) { // same cell - dist_8=0; //equals to -1 + if (closest_dist < 0.0001) { // same cell + dist_8 = 0; //equals to -1 } else { - dist_8 = clamp(uint(closest_dist),0,254) + 1; //conservative, 0 is 1, so <1 is considered solid + dist_8 = clamp(uint(closest_dist), 0, 254) + 1; //conservative, 0 is 1, so <1 is considered solid } - imageStore(sdf_tex,ivec3(gl_GlobalInvocationID),uvec4(dist_8)); + imageStore(sdf_tex, ivec3(gl_GlobalInvocationID), uvec4(dist_8)); //imageStore(sdf_tex,pos,uvec4(pos*2,0)); } - #if 0 layout(push_constant, binding = 0, std430) uniform Params { @@ -75,10 +73,9 @@ layout(push_constant, binding = 0, std430) uniform Params { uint stack_size; } params; - float distance_to_aabb(ivec3 pos, ivec3 aabb_pos, ivec3 aabb_size) { - vec3 delta = vec3(max(ivec3(0),max(aabb_pos - pos, pos - (aabb_pos + aabb_size - ivec3(1))))); + vec3 delta = vec3(max(ivec3(0), max(aabb_pos - pos, pos - (aabb_pos + aabb_size - ivec3(1))))); return length(delta); } @@ -86,20 +83,19 @@ void main() { ivec3 pos = ivec3(gl_GlobalInvocationID); - uint stack[10]=uint[](0,0,0,0,0,0,0,0,0,0); - uint stack_indices[10]=uint[](0,0,0,0,0,0,0,0,0,0); - ivec3 stack_positions[10]=ivec3[](ivec3(0),ivec3(0),ivec3(0),ivec3(0),ivec3(0),ivec3(0),ivec3(0),ivec3(0),ivec3(0),ivec3(0)); - - const uint cell_orders[8]=uint[]( - 0x11f58d1, - 0xe2e70a, - 0xd47463, - 0xbb829c, - 0x8d11f5, - 0x70ae2e, - 0x463d47, - 0x29cbb8 - ); + uint stack[10] = uint[](0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + uint stack_indices[10] = uint[](0, 0, 0, 0, 0, 0, 0, 0, 0, 0); + ivec3 stack_positions[10] = ivec3[](ivec3(0), ivec3(0), ivec3(0), ivec3(0), ivec3(0), ivec3(0), ivec3(0), ivec3(0), ivec3(0), ivec3(0)); + + const uint cell_orders[8] = uint[]( + 0x11f58d1, + 0xe2e70a, + 0xd47463, + 0xbb829c, + 0x8d11f5, + 0x70ae2e, + 0x463d47, + 0x29cbb8); bool cell_found = false; bool cell_found_exact = false; @@ -107,46 +103,45 @@ void main() { float closest_distance = MAX_DISTANCE; int stack_pos = 0; - while(true) { + while (true) { - uint index = stack_indices[stack_pos]>>24; + uint index = stack_indices[stack_pos] >> 24; if (index == 8) { //go up - if (stack_pos==0) { + if (stack_pos == 0) { break; //done going through octree } stack_pos--; continue; } - stack_indices[stack_pos] = (stack_indices[stack_pos]&((1<<24)-1))|((index + 1)<<24); + stack_indices[stack_pos] = (stack_indices[stack_pos] & ((1 << 24) - 1)) | ((index + 1) << 24); - - uint cell_index = (stack_indices[stack_pos]>>(index*3))&0x7; + uint cell_index = (stack_indices[stack_pos] >> (index * 3)) & 0x7; uint child_cell = cell_children.data[stack[stack_pos]].children[cell_index]; if (child_cell == NO_CHILDREN) { continue; } - ivec3 child_cell_size = params.limits >> (stack_pos+1); + ivec3 child_cell_size = params.limits >> (stack_pos + 1); ivec3 child_cell_pos = stack_positions[stack_pos]; - child_cell_pos+=mix(ivec3(0),child_cell_size,bvec3(uvec3(index&1,index&2,index&4)!=uvec3(0))); + child_cell_pos += mix(ivec3(0), child_cell_size, bvec3(uvec3(index & 1, index & 2, index & 4) != uvec3(0))); - bool is_leaf = stack_pos == (params.stack_size-2); + bool is_leaf = stack_pos == (params.stack_size - 2); - if (child_cell_pos==pos && is_leaf) { + if (child_cell_pos == pos && is_leaf) { //we may actually end up in the exact cell. //if this happens, just abort - cell_found_exact=true; + cell_found_exact = true; break; } if (cell_found) { //discard by distance - float distance = distance_to_aabb(pos,child_cell_pos,child_cell_size); + float distance = distance_to_aabb(pos, child_cell_pos, child_cell_size); if (distance >= closest_distance) { continue; //pointless, just test next child } else if (is_leaf) { @@ -157,38 +152,33 @@ void main() { } } else if (is_leaf) { //first solid cell we find, save and continue - closest_distance = distance_to_aabb(pos,child_cell_pos,child_cell_size); + closest_distance = distance_to_aabb(pos, child_cell_pos, child_cell_size); closest_cell_pos = child_cell_pos; - cell_found=true; + cell_found = true; continue; } - - - - bvec3 direction = greaterThan(( pos - ( child_cell_pos + (child_cell_size >>1) ) ) , ivec3(0) ); + bvec3 direction = greaterThan((pos - (child_cell_pos + (child_cell_size >> 1))), ivec3(0)); uint cell_order = 0; - cell_order|=mix(0,1,direction.x); - cell_order|=mix(0,2,direction.y); - cell_order|=mix(0,4,direction.z); + cell_order |= mix(0, 1, direction.x); + cell_order |= mix(0, 2, direction.y); + cell_order |= mix(0, 4, direction.z); - stack[stack_pos+1]=child_cell; - stack_indices[stack_pos+1]=cell_orders[cell_order]; //start counting - stack_positions[stack_pos+1]=child_cell_pos; + stack[stack_pos + 1] = child_cell; + stack_indices[stack_pos + 1] = cell_orders[cell_order]; //start counting + stack_positions[stack_pos + 1] = child_cell_pos; stack_pos++; //go up stack - } uint dist_8; if (cell_found_exact) { - dist_8=0; //equals to -1 + dist_8 = 0; //equals to -1 } else { - float closest_distance = length(vec3(pos-closest_cell_pos)); - dist_8 = clamp(uint(closest_distance),0,254) + 1; //conservative, 0 is 1, so <1 is considered solid + float closest_distance = length(vec3(pos - closest_cell_pos)); + dist_8 = clamp(uint(closest_distance), 0, 254) + 1; //conservative, 0 is 1, so <1 is considered solid } - imageStore(sdf_tex,pos,uvec4(dist_8)); - + imageStore(sdf_tex, pos, uvec4(dist_8)); } #endif diff --git a/servers/visual/rasterizer_rd/shaders/giprobe_write.glsl b/servers/visual/rasterizer_rd/shaders/giprobe_write.glsl index 01d33c28de..50412a3b2f 100644 --- a/servers/visual/rasterizer_rd/shaders/giprobe_write.glsl +++ b/servers/visual/rasterizer_rd/shaders/giprobe_write.glsl @@ -1,3 +1,4 @@ +/* clang-format off */ [compute] #version 450 @@ -5,16 +6,17 @@ VERSION_DEFINES layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in; +/* clang-format on */ #define NO_CHILDREN 0xFFFFFFFF -#define GREY_VEC vec3(0.33333,0.33333,0.33333) +#define GREY_VEC vec3(0.33333, 0.33333, 0.33333) struct CellChildren { uint children[8]; }; -layout(set=0,binding=1,std430) buffer CellChildrenBuffer { - CellChildren data[]; +layout(set = 0, binding = 1, std430) buffer CellChildrenBuffer { + CellChildren data[]; } cell_children; struct CellData { @@ -24,8 +26,8 @@ struct CellData { uint normal; //RGB normal encoded }; -layout(set=0,binding=2,std430) buffer CellDataBuffer { - CellData data[]; +layout(set = 0, binding = 2, std430) buffer CellDataBuffer { + CellData data[]; } cell_data; #define LIGHT_TYPE_DIRECTIONAL 0 @@ -35,7 +37,6 @@ layout(set=0,binding=2,std430) buffer CellDataBuffer { #ifdef MODE_COMPUTE_LIGHT struct Light { - uint type; float energy; float radius; @@ -51,15 +52,13 @@ struct Light { bool has_shadow; }; - -layout(set=0,binding=3,std140) uniform Lights { - Light data[MAX_LIGHTS]; +layout(set = 0, binding = 3, std140) uniform Lights { + Light data[MAX_LIGHTS]; } lights; #endif layout(push_constant, binding = 0, std430) uniform Params { - ivec3 limits; uint stack_size; @@ -71,23 +70,19 @@ layout(push_constant, binding = 0, std430) uniform Params { uint cell_offset; uint cell_count; uint pad[2]; - } params; - -layout(set=0,binding=4,std140) uniform Outputs { - vec4 data[]; +layout(set = 0, binding = 4, std140) uniform Outputs { + vec4 data[]; } output; - - #ifdef MODE_COMPUTE_LIGHT -uint raymarch(float distance,float distance_adv,vec3 from,vec3 direction) { +uint raymarch(float distance, float distance_adv, vec3 from, vec3 direction) { uint result = NO_CHILDREN; - ivec3 size = ivec3(max(max(params.limits.x,params.limits.y),params.limits.z)); + ivec3 size = ivec3(max(max(params.limits.x, params.limits.y), params.limits.z)); while (distance > -distance_adv) { //use this to avoid precision errors @@ -95,26 +90,26 @@ uint raymarch(float distance,float distance_adv,vec3 from,vec3 direction) { ivec3 pos = ivec3(from); - if (all(greaterThanEqual(pos,ivec3(0))) && all(lessThan(pos,size))) { + if (all(greaterThanEqual(pos, ivec3(0))) && all(lessThan(pos, size))) { ivec3 ofs = ivec3(0); ivec3 half_size = size / 2; for (int i = 0; i < params.stack_size - 1; i++) { - bvec3 greater = greaterThanEqual(pos,ofs+half_size); + bvec3 greater = greaterThanEqual(pos, ofs + half_size); - ofs += mix(ivec3(0),half_size,greater); + ofs += mix(ivec3(0), half_size, greater); uint child = 0; //wonder if this can be done faster if (greater.x) { - child|=1; + child |= 1; } if (greater.y) { - child|=2; + child |= 2; } if (greater.z) { - child|=4; + child |= 4; } cell = cell_children.data[cell].children[child]; @@ -124,10 +119,9 @@ uint raymarch(float distance,float distance_adv,vec3 from,vec3 direction) { half_size >>= ivec3(1); } - if ( cell != NO_CHILDREN) { + if (cell != NO_CHILDREN) { return cell; //found cell! } - } from += direction * distance_adv; @@ -137,10 +131,9 @@ uint raymarch(float distance,float distance_adv,vec3 from,vec3 direction) { return NO_CHILDREN; } -bool compute_light_vector(uint light,uint cell, vec3 pos,out float attenuation, out vec3 light_pos) { - +bool compute_light_vector(uint light, uint cell, vec3 pos, out float attenuation, out vec3 light_pos) { - if (lights.data[light].type==LIGHT_TYPE_DIRECTIONAL) { + if (lights.data[light].type == LIGHT_TYPE_DIRECTIONAL) { light_pos = pos - lights.data[light].direction * length(vec3(params.limits)); attenuation = 1.0; @@ -153,14 +146,12 @@ bool compute_light_vector(uint light,uint cell, vec3 pos,out float attenuation, return false; } + attenuation = pow(clamp(1.0 - distance / lights.data[light].radius, 0.0001, 1.0), lights.data[light].attenuation); - attenuation = pow( clamp( 1.0 - distance / lights.data[light].radius, 0.0001, 1.0), lights.data[light].attenuation ); - - - if (lights.data[light].type==LIGHT_TYPE_SPOT) { + if (lights.data[light].type == LIGHT_TYPE_SPOT) { vec3 rel = normalize(pos - light_pos); - float angle = acos(dot(rel,lights.data[light].direction)); + float angle = acos(dot(rel, lights.data[light].direction)); if (angle > lights.data[light].spot_angle_radians) { return false; } @@ -193,53 +184,50 @@ float get_normal_advance(vec3 p_normal) { unorm = vec3(1.0, 0.0, 0.0); } - return 1.0 / dot(normal,unorm); + return 1.0 / dot(normal, unorm); } #endif - - - void main() { - uint cell_index = gl_GlobalInvocationID.x;; + uint cell_index = gl_GlobalInvocationID.x; if (cell_index >= params.cell_count) { return; } cell_index += params.cell_offset; - uvec3 posu = uvec3(cell_data.data[cell_index].position&0x7FF,(cell_data.data[cell_index].position>>11)&0x3FF,cell_data.data[cell_index].position>>21); + uvec3 posu = uvec3(cell_data.data[cell_index].position & 0x7FF, (cell_data.data[cell_index].position >> 11) & 0x3FF, cell_data.data[cell_index].position >> 21); vec4 albedo = unpackUnorm4x8(cell_data.data[cell_index].albedo); #ifdef MODE_COMPUTE_LIGHT vec3 pos = vec3(posu) + vec3(0.5); - vec3 emission = vec3(ivec3(cell_data.data[cell_index].emission&0x3FF,(cell_data.data[cell_index].emission>>10)&0x7FF,cell_data.data[cell_index].emission>>21)) * params.emission_scale; + vec3 emission = vec3(ivec3(cell_data.data[cell_index].emission & 0x3FF, (cell_data.data[cell_index].emission >> 10) & 0x7FF, cell_data.data[cell_index].emission >> 21)) * params.emission_scale; vec4 normal = unpackSnorm4x8(cell_data.data[cell_index].normal); #ifdef MODE_ANISOTROPIC - vec3 accum[6]=vec3[](vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0)); - const vec3 accum_dirs[6]=vec3[](vec3(1.0,0.0,0.0),vec3(-1.0,0.0,0.0),vec3(0.0,1.0,0.0),vec3(0.0,-1.0,0.0),vec3(0.0,0.0,1.0),vec3(0.0,0.0,-1.0)); + vec3 accum[6] = vec3[](vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0)); + const vec3 accum_dirs[6] = vec3[](vec3(1.0, 0.0, 0.0), vec3(-1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(0.0, -1.0, 0.0), vec3(0.0, 0.0, 1.0), vec3(0.0, 0.0, -1.0)); #else vec3 accum = vec3(0.0); #endif - for(uint i=0;i<params.light_count;i++) { + for (uint i = 0; i < params.light_count; i++) { float attenuation; vec3 light_pos; - if (!compute_light_vector(i,cell_index,pos,attenuation,light_pos)) { + if (!compute_light_vector(i, cell_index, pos, attenuation, light_pos)) { continue; } vec3 light_dir = pos - light_pos; float distance = length(light_dir); - light_dir=normalize(light_dir); + light_dir = normalize(light_dir); - if (length(normal.xyz) > 0.2 && dot(normal.xyz,light_dir)>=0) { + if (length(normal.xyz) > 0.2 && dot(normal.xyz, light_dir) >= 0) { continue; //not facing the light } @@ -247,15 +235,12 @@ void main() { float distance_adv = get_normal_advance(light_dir); - distance += distance_adv - mod(distance, distance_adv); //make it reach the center of the box always vec3 from = pos - light_dir * distance; //approximate - from -= sign(light_dir)*0.45; //go near the edge towards the light direction to avoid self occlusion - + from -= sign(light_dir) * 0.45; //go near the edge towards the light direction to avoid self occlusion - - uint result = raymarch(distance,distance_adv,from,light_dir); + uint result = raymarch(distance, distance_adv, from, light_dir); if (result != cell_index) { continue; //was occluded @@ -265,89 +250,81 @@ void main() { vec3 light = lights.data[i].color * albedo.rgb * attenuation * lights.data[i].energy; #ifdef MODE_ANISOTROPIC - for(uint j=0;j<6;j++) { - accum[j]+=max(0.0,dot(accum_dir,-light_dir))*light+emission; + for (uint j = 0; j < 6; j++) { + accum[j] += max(0.0, dot(accum_dir, -light_dir)) * light + emission; } #else if (length(normal.xyz) > 0.2) { - accum+=max(0.0,dot(normal.xyz,-light_dir))*light+emission; + accum += max(0.0, dot(normal.xyz, -light_dir)) * light + emission; } else { //all directions - accum+=light+emission; + accum += light + emission; } #endif - } #ifdef MODE_ANISOTROPIC - output.data[cell_index*6+0]=vec4(accum[0],0.0); - output.data[cell_index*6+1]=vec4(accum[1],0.0); - output.data[cell_index*6+2]=vec4(accum[2],0.0); - output.data[cell_index*6+3]=vec4(accum[3],0.0); - output.data[cell_index*6+4]=vec4(accum[4],0.0); - output.data[cell_index*6+5]=vec4(accum[5],0.0); + output.data[cell_index * 6 + 0] = vec4(accum[0], 0.0); + output.data[cell_index * 6 + 1] = vec4(accum[1], 0.0); + output.data[cell_index * 6 + 2] = vec4(accum[2], 0.0); + output.data[cell_index * 6 + 3] = vec4(accum[3], 0.0); + output.data[cell_index * 6 + 4] = vec4(accum[4], 0.0); + output.data[cell_index * 6 + 5] = vec4(accum[5], 0.0); #else - output.data[cell_index]=vec4(accum,0.0); + output.data[cell_index] = vec4(accum, 0.0); #endif #endif //MODE_COMPUTE_LIGHT - #ifdef MODE_UPDATE_MIPMAPS { #ifdef MODE_ANISOTROPIC - vec3 light_accum[6] = vec3[](vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0)); + vec3 light_accum[6] = vec3[](vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0), vec3(0.0)); #else vec3 light_accum = vec3(0.0); #endif float count = 0.0; - for(uint i=0;i<8;i++) { + for (uint i = 0; i < 8; i++) { uint child_index = cell_children.data[cell_index].children[i]; - if (child_index==NO_CHILDREN) { + if (child_index == NO_CHILDREN) { continue; } #ifdef MODE_ANISOTROPIC - light_accum[1] += output.data[child_index*6+0].rgb; - light_accum[2] += output.data[child_index*6+1].rgb; - light_accum[3] += output.data[child_index*6+2].rgb; - light_accum[4] += output.data[child_index*6+3].rgb; - light_accum[5] += output.data[child_index*6+4].rgb; - light_accum[6] += output.data[child_index*6+5].rgb; + light_accum[1] += output.data[child_index * 6 + 0].rgb; + light_accum[2] += output.data[child_index * 6 + 1].rgb; + light_accum[3] += output.data[child_index * 6 + 2].rgb; + light_accum[4] += output.data[child_index * 6 + 3].rgb; + light_accum[5] += output.data[child_index * 6 + 4].rgb; + light_accum[6] += output.data[child_index * 6 + 5].rgb; #else light_accum += output.data[child_index].rgb; #endif - count+=1.0; + count += 1.0; } - float divisor = mix(8.0,count,params.propagation); + float divisor = mix(8.0, count, params.propagation); #ifdef MODE_ANISOTROPIC - output.data[cell_index*6+0]=vec4(light_accum[0] / divisor,0.0); - output.data[cell_index*6+1]=vec4(light_accum[1] / divisor,0.0); - output.data[cell_index*6+2]=vec4(light_accum[2] / divisor,0.0); - output.data[cell_index*6+3]=vec4(light_accum[3] / divisor,0.0); - output.data[cell_index*6+4]=vec4(light_accum[4] / divisor,0.0); - output.data[cell_index*6+5]=vec4(light_accum[5] / divisor,0.0); + output.data[cell_index * 6 + 0] = vec4(light_accum[0] / divisor, 0.0); + output.data[cell_index * 6 + 1] = vec4(light_accum[1] / divisor, 0.0); + output.data[cell_index * 6 + 2] = vec4(light_accum[2] / divisor, 0.0); + output.data[cell_index * 6 + 3] = vec4(light_accum[3] / divisor, 0.0); + output.data[cell_index * 6 + 4] = vec4(light_accum[4] / divisor, 0.0); + output.data[cell_index * 6 + 5] = vec4(light_accum[5] / divisor, 0.0); #else - output.data[cell_index]=vec4(light_accum / divisor,0.0); + output.data[cell_index] = vec4(light_accum / divisor, 0.0); #endif - - - } #endif #ifdef MODE_WRITE_TEXTURE { - - - } #endif } diff --git a/servers/visual/rasterizer_rd/shaders/scene_forward.glsl b/servers/visual/rasterizer_rd/shaders/scene_forward.glsl index 259904dd60..fe4e8a52a3 100644 --- a/servers/visual/rasterizer_rd/shaders/scene_forward.glsl +++ b/servers/visual/rasterizer_rd/shaders/scene_forward.glsl @@ -1,16 +1,12 @@ /* clang-format off */ [vertex] -/* clang-format on */ #version 450 -/* clang-format off */ VERSION_DEFINES -/* clang-format on */ #include "scene_forward_inc.glsl" - /* INPUT ATTRIBS */ layout(location = 0) in vec3 vertex_attrib; @@ -57,14 +53,13 @@ layout(location = 6) out vec3 binormal_interp; #endif #ifdef USE_MATERIAL_UNIFORMS -layout(set = 3, binding = 0, std140) uniform MaterialUniforms { -/* clang-format off */ +layout(set = 3, binding = 0, std140) uniform MaterialUniforms{ + /* clang-format off */ MATERIAL_UNIFORMS -/* clang-format on */ + /* clang-format on */ } material; #endif - /* clang-format off */ VERTEX_SHADER_GLOBALS @@ -75,11 +70,11 @@ VERTEX_SHADER_GLOBALS // See GH-13450 and https://bugs.freedesktop.org/show_bug.cgi?id=100316 invariant gl_Position; -layout(location =7) flat out uint instance_index; +layout(location = 7) flat out uint instance_index; #ifdef MODE_DUAL_PARABOLOID -layout(location =8) out float dp_clip; +layout(location = 8) out float dp_clip; #endif @@ -92,28 +87,27 @@ void main() { #endif mat4 world_matrix = instances.data[instance_index].transform; - mat3 world_normal_matrix= mat3(instances.data[instance_index].normal_transform); + mat3 world_normal_matrix = mat3(instances.data[instance_index].normal_transform); if (bool(instances.data[instance_index].flags & INSTANCE_FLAGS_MULTIMESH)) { //multimesh, instances are for it - uint offset = (instances.data[instance_index].flags>>INSTANCE_FLAGS_MULTIMESH_STRIDE_SHIFT)&INSTANCE_FLAGS_MULTIMESH_STRIDE_MASK; - offset*=gl_InstanceIndex; - + uint offset = (instances.data[instance_index].flags >> INSTANCE_FLAGS_MULTIMESH_STRIDE_SHIFT) & INSTANCE_FLAGS_MULTIMESH_STRIDE_MASK; + offset *= gl_InstanceIndex; mat4 matrix; if (bool(instances.data[instance_index].flags & INSTANCE_FLAGS_MULTIMESH_FORMAT_2D)) { - matrix = mat4(transforms.data[offset+0],transforms.data[offset+1],vec4(0.0,0.0,1.0,0.0),vec4(0.0,0.0,0.0,1.0)); - offset+=2; + matrix = mat4(transforms.data[offset + 0], transforms.data[offset + 1], vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0)); + offset += 2; } else { - matrix = mat4(transforms.data[offset+0],transforms.data[offset+1],transforms.data[offset+2],vec4(0.0,0.0,0.0,1.0)); - offset+=3; + matrix = mat4(transforms.data[offset + 0], transforms.data[offset + 1], transforms.data[offset + 2], vec4(0.0, 0.0, 0.0, 1.0)); + offset += 3; } if (bool(instances.data[instance_index].flags & INSTANCE_FLAGS_MULTIMESH_HAS_COLOR)) { #ifdef COLOR_USED color_interp *= transforms.data[offset]; #endif - offset+=1; + offset += 1; } if (bool(instances.data[instance_index].flags & INSTANCE_FLAGS_MULTIMESH_HAS_CUSTOM_DATA)) { @@ -139,30 +133,28 @@ void main() { vec3 binormal = normalize(cross(normal, tangent) * binormalf); #endif - if (bool(instances.data[instance_index].flags & INSTANCE_FLAGS_SKELETON)) { //multimesh, instances are for it - uvec2 bones_01 = uvec2(bone_attrib.x&0xFFFF,bone_attrib.x>>16) * 3; - uvec2 bones_23 = uvec2(bone_attrib.y&0xFFFF,bone_attrib.y>>16) * 3; + uvec2 bones_01 = uvec2(bone_attrib.x & 0xFFFF, bone_attrib.x >> 16) * 3; + uvec2 bones_23 = uvec2(bone_attrib.y & 0xFFFF, bone_attrib.y >> 16) * 3; vec2 weights_01 = unpackUnorm2x16(bone_attrib.z); vec2 weights_23 = unpackUnorm2x16(bone_attrib.w); - mat4 m = mat4(transforms.data[bones_01.x],transforms.data[bones_01.x+1],transforms.data[bones_01.x+2],vec4(0.0,0.0,0.0,1.0)) * weights_01.x; - m += mat4(transforms.data[bones_01.y],transforms.data[bones_01.y+1],transforms.data[bones_01.y+2],vec4(0.0,0.0,0.0,1.0)) * weights_01.y; - m += mat4(transforms.data[bones_23.x],transforms.data[bones_23.x+1],transforms.data[bones_23.x+2],vec4(0.0,0.0,0.0,1.0)) * weights_23.x; - m += mat4(transforms.data[bones_23.y],transforms.data[bones_23.y+1],transforms.data[bones_23.y+2],vec4(0.0,0.0,0.0,1.0)) * weights_23.y; + mat4 m = mat4(transforms.data[bones_01.x], transforms.data[bones_01.x + 1], transforms.data[bones_01.x + 2], vec4(0.0, 0.0, 0.0, 1.0)) * weights_01.x; + m += mat4(transforms.data[bones_01.y], transforms.data[bones_01.y + 1], transforms.data[bones_01.y + 2], vec4(0.0, 0.0, 0.0, 1.0)) * weights_01.y; + m += mat4(transforms.data[bones_23.x], transforms.data[bones_23.x + 1], transforms.data[bones_23.x + 2], vec4(0.0, 0.0, 0.0, 1.0)) * weights_23.x; + m += mat4(transforms.data[bones_23.y], transforms.data[bones_23.y + 1], transforms.data[bones_23.y + 2], vec4(0.0, 0.0, 0.0, 1.0)) * weights_23.y; //reverse order because its transposed - vertex = (vec4(vertex,1.0) * m).xyz; - normal = (vec4(normal,0.0) * m).xyz; + vertex = (vec4(vertex, 1.0) * m).xyz; + normal = (vec4(normal, 0.0) * m).xyz; #if defined(TANGENT_USED) || defined(NORMALMAP_USED) || defined(LIGHT_ANISOTROPY_USED) - tangent = (vec4(tangent,0.0) * m).xyz; - binormal = (vec4(binormal,0.0) * m).xyz; + tangent = (vec4(tangent, 0.0) * m).xyz; + binormal = (vec4(binormal, 0.0) * m).xyz; #endif - } #if defined(UV_USED) @@ -177,14 +169,12 @@ void main() { vec4 position; #endif - - mat4 projection_matrix = scene_data.projection_matrix; //using world coordinates #if !defined(SKIP_TRANSFORM_USED) && defined(VERTEX_WORLD_COORDS_USED) - vertex = (world_matrix * vec4(vertex,1.0)).xyz; + vertex = (world_matrix * vec4(vertex, 1.0)).xyz; normal = world_normal_matrix * normal; @@ -212,7 +202,7 @@ VERTEX_SHADER_CODE // using local coordinates (default) #if !defined(SKIP_TRANSFORM_USED) && !defined(VERTEX_WORLD_COORDS_USED) - vertex = (modelview * vec4(vertex,1.0)).xyz; + vertex = (modelview * vec4(vertex, 1.0)).xyz; normal = modelview_normal * normal; #endif @@ -222,11 +212,10 @@ VERTEX_SHADER_CODE tangent = modelview_normal * tangent; #endif - //using world coordinates #if !defined(SKIP_TRANSFORM_USED) && defined(VERTEX_WORLD_COORDS_USED) - vertex = (scene_data.inv_camera_matrix * vec4(vertex,1.0)).xyz; + vertex = (scene_data.inv_camera_matrix * vec4(vertex, 1.0)).xyz; normal = mat3(scene_data.inverse_normal_matrix) * normal; #if defined(TANGENT_USED) || defined(NORMALMAP_USED) || defined(LIGHT_ANISOTROPY_USED) @@ -266,7 +255,7 @@ VERTEX_SHADER_CODE #else float z_ofs = scene_data.z_offset; - z_ofs += max(0.0,1.0 - abs(normalize(normal_interp).z)) * scene_data.z_slope_scale; + z_ofs += max(0.0, 1.0 - abs(normalize(normal_interp).z)) * scene_data.z_slope_scale; vertex_interp.z -= z_ofs; #endif @@ -278,24 +267,21 @@ VERTEX_SHADER_CODE #else gl_Position = projection_matrix * vec4(vertex_interp, 1.0); #endif - } /* clang-format off */ [fragment] -/* clang-format on */ #version 450 -/* clang-format off */ VERSION_DEFINES -/* clang-format on */ #include "scene_forward_inc.glsl" /* Varyings */ layout(location = 0) in vec3 vertex_interp; +/* clang-format on */ layout(location = 1) in vec3 normal_interp; #if defined(COLOR_USED) @@ -315,15 +301,14 @@ layout(location = 5) in vec3 tangent_interp; layout(location = 6) in vec3 binormal_interp; #endif -layout(location =7) flat in uint instance_index; +layout(location = 7) flat in uint instance_index; #ifdef MODE_DUAL_PARABOLOID -layout(location =8) in float dp_clip; +layout(location = 8) in float dp_clip; #endif - //defines to keep compatibility with vertex #define world_matrix instances.data[instance_index].transform @@ -331,10 +316,10 @@ layout(location =8) in float dp_clip; #define projection_matrix scene_data.projection_matrix #ifdef USE_MATERIAL_UNIFORMS -layout(set = 3, binding = 0, std140) uniform MaterialUniforms { -/* clang-format off */ +layout(set = 3, binding = 0, std140) uniform MaterialUniforms{ + /* clang-format off */ MATERIAL_UNIFORMS -/* clang-format on */ + /* clang-format on */ } material; #endif @@ -369,8 +354,6 @@ layout(location = 0) out vec4 frag_color; #endif // RENDER DEPTH - - // This returns the G_GGX function divided by 2 cos_theta_m, where in practice cos_theta_m is either N.L or N.V. // We're dividing this factor off because the overall term we'll end up looks like // (see, for example, the first unnumbered equation in B. Burley, "Physically Based Shading at Disney", SIGGRAPH 2012): @@ -445,7 +428,7 @@ vec3 F0(float metallic, float specular, vec3 albedo) { return mix(vec3(dielectric), albedo, vec3(metallic)); } -void light_compute(vec3 N, vec3 L, vec3 V, vec3 light_color, vec3 attenuation, vec3 diffuse_color,float roughness, float metallic, float specular,float specular_blob_intensity, +void light_compute(vec3 N, vec3 L, vec3 V, vec3 light_color, vec3 attenuation, vec3 diffuse_color, float roughness, float metallic, float specular, float specular_blob_intensity, #ifdef LIGHT_TRANSMISSION_USED vec3 transmission, #endif @@ -456,13 +439,12 @@ void light_compute(vec3 N, vec3 L, vec3 V, vec3 light_color, vec3 attenuation, v float clearcoat, float clearcoat_gloss, #endif #ifdef LIGHT_ANISOTROPY_USED - vec3 B, vec3 T,float anisotropy, + vec3 B, vec3 T, float anisotropy, #endif #ifdef USE_SHADOW_TO_OPACITY inout float alpha, #endif - inout vec3 diffuse_light, inout vec3 specular_light - ) { + inout vec3 diffuse_light, inout vec3 specular_light) { #if defined(USE_LIGHT_SHADER_CODE) // light is written by the light shader @@ -661,59 +643,58 @@ float sample_shadow(texture2D shadow, vec2 shadow_pixel_size, vec4 coord) { #ifdef SHADOW_MODE_PCF_13 float avg = textureProj(shadow, vec4(pos, depth, 1.0)); - avg += textureProj(sampler2DShadow(shadow,shadow_sampler), vec4(pos + vec2(shadow_pixel_size.x, 0.0), depth, 1.0)); - avg += textureProj(sampler2DShadow(shadow,shadow_sampler), vec4(pos + vec2(-shadow_pixel_size.x, 0.0), depth, 1.0)); - avg += textureProj(sampler2DShadow(shadow,shadow_sampler), vec4(pos + vec2(0.0, shadow_pixel_size.y), depth, 1.0)); - avg += textureProj(sampler2DShadow(shadow,shadow_sampler), vec4(pos + vec2(0.0, -shadow_pixel_size.y), depth, 1.0)); - avg += textureProj(sampler2DShadow(shadow,shadow_sampler), vec4(pos + vec2(shadow_pixel_size.x, shadow_pixel_size.y), depth, 1.0)); - avg += textureProj(sampler2DShadow(shadow,shadow_sampler), vec4(pos + vec2(-shadow_pixel_size.x, shadow_pixel_size.y), depth, 1.0)); - avg += textureProj(sampler2DShadow(shadow,shadow_sampler), vec4(pos + vec2(shadow_pixel_size.x, -shadow_pixel_size.y), depth, 1.0)); - avg += textureProj(sampler2DShadow(shadow,shadow_sampler), vec4(pos + vec2(-shadow_pixel_size.x, -shadow_pixel_size.y), depth, 1.0)); - avg += textureProj(sampler2DShadow(shadow,shadow_sampler), vec4(pos + vec2(shadow_pixel_size.x * 2.0, 0.0), depth, 1.0)); - avg += textureProj(sampler2DShadow(shadow,shadow_sampler), vec4(pos + vec2(-shadow_pixel_size.x * 2.0, 0.0), depth, 1.0)); - avg += textureProj(sampler2DShadow(shadow,shadow_sampler), vec4(pos + vec2(0.0, shadow_pixel_size.y * 2.0), depth, 1.0)); - avg += textureProj(sampler2DShadow(shadow,shadow_sampler), vec4(pos + vec2(0.0, -shadow_pixel_size.y * 2.0), depth, 1.0)); + avg += textureProj(sampler2DShadow(shadow, shadow_sampler), vec4(pos + vec2(shadow_pixel_size.x, 0.0), depth, 1.0)); + avg += textureProj(sampler2DShadow(shadow, shadow_sampler), vec4(pos + vec2(-shadow_pixel_size.x, 0.0), depth, 1.0)); + avg += textureProj(sampler2DShadow(shadow, shadow_sampler), vec4(pos + vec2(0.0, shadow_pixel_size.y), depth, 1.0)); + avg += textureProj(sampler2DShadow(shadow, shadow_sampler), vec4(pos + vec2(0.0, -shadow_pixel_size.y), depth, 1.0)); + avg += textureProj(sampler2DShadow(shadow, shadow_sampler), vec4(pos + vec2(shadow_pixel_size.x, shadow_pixel_size.y), depth, 1.0)); + avg += textureProj(sampler2DShadow(shadow, shadow_sampler), vec4(pos + vec2(-shadow_pixel_size.x, shadow_pixel_size.y), depth, 1.0)); + avg += textureProj(sampler2DShadow(shadow, shadow_sampler), vec4(pos + vec2(shadow_pixel_size.x, -shadow_pixel_size.y), depth, 1.0)); + avg += textureProj(sampler2DShadow(shadow, shadow_sampler), vec4(pos + vec2(-shadow_pixel_size.x, -shadow_pixel_size.y), depth, 1.0)); + avg += textureProj(sampler2DShadow(shadow, shadow_sampler), vec4(pos + vec2(shadow_pixel_size.x * 2.0, 0.0), depth, 1.0)); + avg += textureProj(sampler2DShadow(shadow, shadow_sampler), vec4(pos + vec2(-shadow_pixel_size.x * 2.0, 0.0), depth, 1.0)); + avg += textureProj(sampler2DShadow(shadow, shadow_sampler), vec4(pos + vec2(0.0, shadow_pixel_size.y * 2.0), depth, 1.0)); + avg += textureProj(sampler2DShadow(shadow, shadow_sampler), vec4(pos + vec2(0.0, -shadow_pixel_size.y * 2.0), depth, 1.0)); return avg * (1.0 / 13.0); #endif #ifdef SHADOW_MODE_PCF_5 - float avg = textureProj(sampler2DShadow(shadow,shadow_sampler), vec4(pos, depth, 1.0)); - avg += textureProj(sampler2DShadow(shadow,shadow_sampler), vec4(pos + vec2(shadow_pixel_size.x, 0.0), depth, 1.0)); - avg += textureProj(sampler2DShadow(shadow,shadow_sampler), vec4(pos + vec2(-shadow_pixel_size.x, 0.0), depth, 1.0)); - avg += textureProj(sampler2DShadow(shadow,shadow_sampler), vec4(pos + vec2(0.0, shadow_pixel_size.y), depth, 1.0)); - avg += textureProj(sampler2DShadow(shadow,shadow_sampler), vec4(pos + vec2(0.0, -shadow_pixel_size.y), depth, 1.0)); + float avg = textureProj(sampler2DShadow(shadow, shadow_sampler), vec4(pos, depth, 1.0)); + avg += textureProj(sampler2DShadow(shadow, shadow_sampler), vec4(pos + vec2(shadow_pixel_size.x, 0.0), depth, 1.0)); + avg += textureProj(sampler2DShadow(shadow, shadow_sampler), vec4(pos + vec2(-shadow_pixel_size.x, 0.0), depth, 1.0)); + avg += textureProj(sampler2DShadow(shadow, shadow_sampler), vec4(pos + vec2(0.0, shadow_pixel_size.y), depth, 1.0)); + avg += textureProj(sampler2DShadow(shadow, shadow_sampler), vec4(pos + vec2(0.0, -shadow_pixel_size.y), depth, 1.0)); return avg * (1.0 / 5.0); #endif #if !defined(SHADOW_MODE_PCF_5) || !defined(SHADOW_MODE_PCF_13) - return textureProj(sampler2DShadow(shadow,shadow_sampler), vec4(pos, depth, 1.0)); + return textureProj(sampler2DShadow(shadow, shadow_sampler), vec4(pos, depth, 1.0)); #endif } #endif //USE_NO_SHADOWS - -void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 albedo,float roughness, float metallic, float specular,float p_blob_intensity, +void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 albedo, float roughness, float metallic, float specular, float p_blob_intensity, #ifdef LIGHT_TRANSMISSION_USED - vec3 transmission, + vec3 transmission, #endif #ifdef LIGHT_RIM_USED - float rim, float rim_tint, + float rim, float rim_tint, #endif #ifdef LIGHT_CLEARCOAT_USED - float clearcoat, float clearcoat_gloss, + float clearcoat, float clearcoat_gloss, #endif #ifdef LIGHT_ANISOTROPY_USED - vec3 binormal, vec3 tangent, float anisotropy, + vec3 binormal, vec3 tangent, float anisotropy, #endif #ifdef USE_SHADOW_TO_OPACITY - inout float alpha, + inout float alpha, #endif - inout vec3 diffuse_light, inout vec3 specular_light) { + inout vec3 diffuse_light, inout vec3 specular_light) { vec3 light_rel_vec = lights.data[idx].position - vertex; float light_length = length(light_rel_vec); @@ -722,7 +703,7 @@ void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 a float omni_attenuation = pow(max(1.0 - normalized_distance, 0.0), attenuation_energy.x); vec3 light_attenuation = vec3(omni_attenuation); vec4 color_specular = unpackUnorm4x8(lights.data[idx].color_specular); - color_specular.rgb*=attenuation_energy.y; + color_specular.rgb *= attenuation_energy.y; #ifndef USE_NO_SHADOWS vec4 shadow_color_enabled = unpackUnorm4x8(lights.data[idx].shadow_color_enabled); @@ -743,7 +724,6 @@ void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 a } else { splane.z = 1.0 - splane.z; - } splane.xy /= splane.z; @@ -757,45 +737,44 @@ void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 a } #endif //USE_NO_SHADOWS - light_compute(normal, normalize(light_rel_vec), eye_vec, color_specular.rgb, light_attenuation, albedo, roughness, metallic, specular,color_specular.a * p_blob_intensity, + light_compute(normal, normalize(light_rel_vec), eye_vec, color_specular.rgb, light_attenuation, albedo, roughness, metallic, specular, color_specular.a * p_blob_intensity, #ifdef LIGHT_TRANSMISSION_USED - transmission, + transmission, #endif #ifdef LIGHT_RIM_USED - rim * omni_attenuation, rim_tint, + rim * omni_attenuation, rim_tint, #endif #ifdef LIGHT_CLEARCOAT_USED - clearcoat, clearcoat_gloss, + clearcoat, clearcoat_gloss, #endif #ifdef LIGHT_ANISOTROPY_USED - binormal, tangent, anisotropy, + binormal, tangent, anisotropy, #endif #ifdef USE_SHADOW_TO_OPACITY - alpha + alpha, #endif - diffuse_light, specular_light); + diffuse_light, + specular_light); } - - - -void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 albedo,float roughness, float metallic, float specular,float p_blob_intensity, +void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 albedo, float roughness, float metallic, float specular, float p_blob_intensity, #ifdef LIGHT_TRANSMISSION_USED - vec3 transmission, + vec3 transmission, #endif #ifdef LIGHT_RIM_USED - float rim, float rim_tint, + float rim, float rim_tint, #endif #ifdef LIGHT_CLEARCOAT_USED - float clearcoat, float clearcoat_gloss, + float clearcoat, float clearcoat_gloss, #endif #ifdef LIGHT_ANISOTROPY_USED - vec3 binormal, vec3 tangent, float anisotropy, + vec3 binormal, vec3 tangent, float anisotropy, #endif #ifdef USE_SHADOW_TO_OPACITY - inout float alpha + inout float alpha, #endif - inout vec3 diffuse_light, inout vec3 specular_light) { + inout vec3 diffuse_light, + inout vec3 specular_light) { vec3 light_rel_vec = lights.data[idx].position - vertex; float light_length = length(light_rel_vec); @@ -809,9 +788,7 @@ void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 a spot_attenuation *= 1.0 - pow(spot_rim, spot_att_angle.x); vec3 light_attenuation = vec3(spot_attenuation); vec4 color_specular = unpackUnorm4x8(lights.data[idx].color_specular); - color_specular.rgb*=attenuation_energy.y; - - + color_specular.rgb *= attenuation_energy.y; /* if (lights.data[idx].atlas_rect!=vec4(0.0)) { @@ -831,26 +808,26 @@ void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 a #endif //USE_NO_SHADOWS - light_compute(normal, normalize(light_rel_vec), eye_vec, color_specular.rgb, light_attenuation, albedo, roughness, metallic, specular,color_specular.a * p_blob_intensity, + light_compute(normal, normalize(light_rel_vec), eye_vec, color_specular.rgb, light_attenuation, albedo, roughness, metallic, specular, color_specular.a * p_blob_intensity, #ifdef LIGHT_TRANSMISSION_USED - transmission, + transmission, #endif #ifdef LIGHT_RIM_USED - rim * spot_attenuation, rim_tint, + rim * spot_attenuation, rim_tint, #endif #ifdef LIGHT_CLEARCOAT_USED - clearcoat, clearcoat_gloss, + clearcoat, clearcoat_gloss, #endif #ifdef LIGHT_ANISOTROPY_USED - binormal, tangent, anisotropy, + binormal, tangent, anisotropy, #endif #ifdef USE_SHADOW_TO_OPACITY - alpha, + alpha, #endif - diffuse_light, specular_light); + diffuse_light, specular_light); } -void reflection_process(uint ref_index, vec3 vertex, vec3 normal,float roughness,vec3 ambient_light,vec3 specular_light,inout vec4 ambient_accum, inout vec4 reflection_accum) { +void reflection_process(uint ref_index, vec3 vertex, vec3 normal, float roughness, vec3 ambient_light, vec3 specular_light, inout vec4 ambient_accum, inout vec4 reflection_accum) { vec3 box_extents = reflections.data[ref_index].box_extents; vec3 local_pos = (reflections.data[ref_index].local_matrix * vec4(vertex, 1.0)).xyz; @@ -887,7 +864,7 @@ void reflection_process(uint ref_index, vec3 vertex, vec3 normal,float roughness vec4 reflection; - reflection.rgb = textureLod(samplerCubeArray(reflection_atlas,material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), vec4(local_ref_vec,reflections.data[ref_index].index), roughness * MAX_ROUGHNESS_LOD).rgb; + reflection.rgb = textureLod(samplerCubeArray(reflection_atlas, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), vec4(local_ref_vec, reflections.data[ref_index].index), roughness * MAX_ROUGHNESS_LOD).rgb; if (reflections.data[ref_index].params.z < 0.5) { reflection.rgb = mix(specular_light, reflection.rgb, blend); @@ -907,7 +884,7 @@ void reflection_process(uint ref_index, vec3 vertex, vec3 normal,float roughness vec4 ambient_out; - ambient_out.rgb = textureLod(samplerCubeArray(reflection_atlas,material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), vec4(local_amb_vec,reflections.data[ref_index].index), MAX_ROUGHNESS_LOD).rgb; + ambient_out.rgb = textureLod(samplerCubeArray(reflection_atlas, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), vec4(local_amb_vec, reflections.data[ref_index].index), MAX_ROUGHNESS_LOD).rgb; ambient_out.a = blend; ambient_out.rgb = mix(reflections.data[ref_index].ambient.rgb, ambient_out.rgb, reflections.data[ref_index].ambient.a); @@ -944,82 +921,77 @@ vec4 voxel_cone_trace(texture3D probe, vec3 cell_size, vec3 pos, vec3 direction, vec3 uvw_pos = (pos + dist * direction) * cell_size; float half_diameter = diameter * 0.5; //check if outside, then break - if ( any(greaterThan(abs(uvw_pos - 0.5),vec3(0.5f + half_diameter * cell_size)) ) ) { + if (any(greaterThan(abs(uvw_pos - 0.5), vec3(0.5f + half_diameter * cell_size)))) { break; } - vec4 scolor = textureLod(sampler3D(probe,material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, log2(diameter)); + vec4 scolor = textureLod(sampler3D(probe, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, log2(diameter)); float a = (1.0 - color.a); color += a * scolor; dist += half_diameter; - } return color; } - #ifndef GI_PROBE_HIGH_QUALITY //faster version for 45 degrees #ifdef GI_PROBE_USE_ANISOTROPY -vec4 voxel_cone_trace_anisotropic_45_degrees(texture3D probe,texture3D aniso_pos,texture3D aniso_neg,vec3 normal, vec3 cell_size, vec3 pos, vec3 direction, float tan_half_angle, float max_distance, float p_bias) { +vec4 voxel_cone_trace_anisotropic_45_degrees(texture3D probe, texture3D aniso_pos, texture3D aniso_neg, vec3 normal, vec3 cell_size, vec3 pos, vec3 direction, float tan_half_angle, float max_distance, float p_bias) { float dist = p_bias; vec4 color = vec4(0.0); float radius = max(0.5, tan_half_angle * dist); - float lod_level = log2(radius*2.0); + float lod_level = log2(radius * 2.0); while (dist < max_distance && color.a < 0.95) { vec3 uvw_pos = (pos + dist * direction) * cell_size; //check if outside, then break - if ( any(greaterThan(abs(uvw_pos - 0.5),vec3(0.5f + radius * cell_size)) ) ) { + if (any(greaterThan(abs(uvw_pos - 0.5), vec3(0.5f + radius * cell_size)))) { break; } - vec4 scolor = textureLod(sampler3D(probe,material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, lod_level); - vec3 aniso_neg = textureLod(sampler3D(aniso_neg,material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, lod_level).rgb; - vec3 aniso_pos = textureLod(sampler3D(aniso_pos,material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, lod_level).rgb; + vec4 scolor = textureLod(sampler3D(probe, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, lod_level); + vec3 aniso_neg = textureLod(sampler3D(aniso_neg, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, lod_level).rgb; + vec3 aniso_pos = textureLod(sampler3D(aniso_pos, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, lod_level).rgb; - scolor.rgb*=dot(max(vec3(0.0),(normal * aniso_pos)),vec3(1.0)) + dot(max(vec3(0.0),(-normal * aniso_neg)),vec3(1.0)); - lod_level+=1.0; + scolor.rgb *= dot(max(vec3(0.0), (normal * aniso_pos)), vec3(1.0)) + dot(max(vec3(0.0), (-normal * aniso_neg)), vec3(1.0)); + lod_level += 1.0; float a = (1.0 - color.a); scolor *= a; color += scolor; dist += radius; radius = max(0.5, tan_half_angle * dist); - - } return color; } #else -vec4 voxel_cone_trace_45_degrees(texture3D probe, vec3 cell_size, vec3 pos, vec3 direction, float tan_half_angle, float max_distance, float p_bias ) { +vec4 voxel_cone_trace_45_degrees(texture3D probe, vec3 cell_size, vec3 pos, vec3 direction, float tan_half_angle, float max_distance, float p_bias) { float dist = p_bias; vec4 color = vec4(0.0); float radius = max(0.5, tan_half_angle * dist); - float lod_level = log2(radius*2.0); + float lod_level = log2(radius * 2.0); while (dist < max_distance && color.a < 0.95) { vec3 uvw_pos = (pos + dist * direction) * cell_size; //check if outside, then break - if ( any(greaterThan(abs(uvw_pos - 0.5),vec3(0.5f + radius * cell_size)) ) ) { + if (any(greaterThan(abs(uvw_pos - 0.5), vec3(0.5f + radius * cell_size)))) { break; } - vec4 scolor = textureLod(sampler3D(probe,material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, lod_level); - lod_level+=1.0; + vec4 scolor = textureLod(sampler3D(probe, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, lod_level); + lod_level += 1.0; float a = (1.0 - color.a); scolor *= a; color += scolor; dist += radius; radius = max(0.5, tan_half_angle * dist); - } return color; @@ -1027,12 +999,10 @@ vec4 voxel_cone_trace_45_degrees(texture3D probe, vec3 cell_size, vec3 pos, vec3 #endif - #elif defined(GI_PROBE_USE_ANISOTROPY) - //standard voxel cone trace -vec4 voxel_cone_trace_anisotropic(texture3D probe,texture3D aniso_pos,texture3D aniso_neg,vec3 normal, vec3 cell_size, vec3 pos, vec3 direction, float tan_half_angle, float max_distance, float p_bias ) { +vec4 voxel_cone_trace_anisotropic(texture3D probe, texture3D aniso_pos, texture3D aniso_neg, vec3 normal, vec3 cell_size, vec3 pos, vec3 direction, float tan_half_angle, float max_distance, float p_bias) { float dist = p_bias; vec4 color = vec4(0.0); @@ -1042,33 +1012,28 @@ vec4 voxel_cone_trace_anisotropic(texture3D probe,texture3D aniso_pos,texture3D vec3 uvw_pos = (pos + dist * direction) * cell_size; float half_diameter = diameter * 0.5; //check if outside, then break - if ( any(greaterThan(abs(uvw_pos - 0.5),vec3(0.5f + half_diameter * cell_size)) ) ) { + if (any(greaterThan(abs(uvw_pos - 0.5), vec3(0.5f + half_diameter * cell_size)))) { break; } float log2_diameter = log2(diameter); - vec4 scolor = textureLod(sampler3D(probe,material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, log2_diameter); - vec3 aniso_neg = textureLod(sampler3D(aniso_neg,material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, log2_diameter).rgb; - vec3 aniso_pos = textureLod(sampler3D(aniso_pos,material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, log2_diameter).rgb; + vec4 scolor = textureLod(sampler3D(probe, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, log2_diameter); + vec3 aniso_neg = textureLod(sampler3D(aniso_neg, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, log2_diameter).rgb; + vec3 aniso_pos = textureLod(sampler3D(aniso_pos, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), uvw_pos, log2_diameter).rgb; - scolor.rgb*=dot(max(vec3(0.0),(normal * aniso_pos)),vec3(1.0)) + dot(max(vec3(0.0),(-normal * aniso_neg)),vec3(1.0)); + scolor.rgb *= dot(max(vec3(0.0), (normal * aniso_pos)), vec3(1.0)) + dot(max(vec3(0.0), (-normal * aniso_neg)), vec3(1.0)); float a = (1.0 - color.a); scolor *= a; color += scolor; dist += half_diameter; - } return color; } - - #endif -void gi_probe_compute(uint index, vec3 position, vec3 normal,vec3 ref_vec, mat3 normal_xform, float roughness,vec3 ambient, vec3 environment, inout vec4 out_spec, inout vec4 out_diff) { - - +void gi_probe_compute(uint index, vec3 position, vec3 normal, vec3 ref_vec, mat3 normal_xform, float roughness, vec3 ambient, vec3 environment, inout vec4 out_spec, inout vec4 out_diff) { position = (gi_probes.data[index].xform * vec4(position, 1.0)).xyz; ref_vec = normalize((gi_probes.data[index].xform * vec4(ref_vec, 0.0)).xyz); @@ -1136,7 +1101,7 @@ void gi_probe_compute(uint index, vec3 position, vec3 normal,vec3 ref_vec, mat3 #if defined(GI_PROBE_HIGH_QUALITY) || defined(GI_PROBE_LOW_QUALITY) #ifdef GI_PROBE_USE_ANISOTROPY - vec4 cone_light = voxel_cone_trace_anisotropic(gi_probe_textures[gi_probes.data[index].texture_slot],gi_probe_textures[gi_probes.data[index].texture_slot+1],gi_probe_textures[gi_probes.data[index].texture_slot+2],normalize(mix(dir,normal,gi_probes.data[index].anisotropy_strength)),cell_size, position, dir, cone_angle_tan, max_distance, gi_probes.data[index].bias); + vec4 cone_light = voxel_cone_trace_anisotropic(gi_probe_textures[gi_probes.data[index].texture_slot], gi_probe_textures[gi_probes.data[index].texture_slot + 1], gi_probe_textures[gi_probes.data[index].texture_slot + 2], normalize(mix(dir, normal, gi_probes.data[index].anisotropy_strength)), cell_size, position, dir, cone_angle_tan, max_distance, gi_probes.data[index].bias); #else vec4 cone_light = voxel_cone_trace(gi_probe_textures[gi_probes.data[index].texture_slot], cell_size, position, dir, cone_angle_tan, max_distance, gi_probes.data[index].bias); @@ -1145,9 +1110,8 @@ void gi_probe_compute(uint index, vec3 position, vec3 normal,vec3 ref_vec, mat3 #else - #ifdef GI_PROBE_USE_ANISOTROPY - vec4 cone_light = voxel_cone_trace_anisotropic_45_degrees(gi_probe_textures[gi_probes.data[index].texture_slot],gi_probe_textures[gi_probes.data[index].texture_slot+1],gi_probe_textures[gi_probes.data[index].texture_slot+2],normalize(mix(dir,normal,gi_probes.data[index].anisotropy_strength)),cell_size, position, dir, cone_angle_tan, max_distance, gi_probes.data[index].bias); + vec4 cone_light = voxel_cone_trace_anisotropic_45_degrees(gi_probe_textures[gi_probes.data[index].texture_slot], gi_probe_textures[gi_probes.data[index].texture_slot + 1], gi_probe_textures[gi_probes.data[index].texture_slot + 2], normalize(mix(dir, normal, gi_probes.data[index].anisotropy_strength)), cell_size, position, dir, cone_angle_tan, max_distance, gi_probes.data[index].bias); #else vec4 cone_light = voxel_cone_trace_45_degrees(gi_probe_textures[gi_probes.data[index].texture_slot], cell_size, position, dir, cone_angle_tan, max_distance, gi_probes.data[index].bias); #endif // GI_PROBE_USE_ANISOTROPY @@ -1157,33 +1121,31 @@ void gi_probe_compute(uint index, vec3 position, vec3 normal,vec3 ref_vec, mat3 cone_light.rgb = mix(ambient, cone_light.rgb, min(1.0, cone_light.a / 0.95)); } - light+=cone_weights[i] * cone_light.rgb; - - + light += cone_weights[i] * cone_light.rgb; } light *= gi_probes.data[index].dynamic_range; if (gi_probes.data[index].ambient_occlusion > 0.001) { - float size = 1.0+gi_probes.data[index].ambient_occlusion_size*7.0; + float size = 1.0 + gi_probes.data[index].ambient_occlusion_size * 7.0; - float taps,blend; + float taps, blend; blend = modf(size, taps); float ao = 0.0; - for(float i=1.0;i<=taps;i++) { - vec3 ofs = (position + normal * (i*0.5+1.0)) * cell_size; - ao+=textureLod(sampler3D(gi_probe_textures[gi_probes.data[index].texture_slot],material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]),ofs,i-1.0).a*i; + for (float i = 1.0; i <= taps; i++) { + vec3 ofs = (position + normal * (i * 0.5 + 1.0)) * cell_size; + ao += textureLod(sampler3D(gi_probe_textures[gi_probes.data[index].texture_slot], material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), ofs, i - 1.0).a * i; } - if (blend>0.001) { - vec3 ofs = (position + normal * ((taps+1.0)*0.5+1.0)) * cell_size; - ao+=textureLod(sampler3D(gi_probe_textures[gi_probes.data[index].texture_slot],material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]),ofs,taps).a*(taps+1.0)*blend; + if (blend > 0.001) { + vec3 ofs = (position + normal * ((taps + 1.0) * 0.5 + 1.0)) * cell_size; + ao += textureLod(sampler3D(gi_probe_textures[gi_probes.data[index].texture_slot], material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), ofs, taps).a * (taps + 1.0) * blend; } - ao = 1.0 - min(1.0,ao); + ao = 1.0 - min(1.0, ao); - light *= mix(1.0,ao,gi_probes.data[index].ambient_occlusion); + light *= mix(1.0, ao, gi_probes.data[index].ambient_occlusion); } out_diff += vec4(light * blend, blend); @@ -1192,7 +1154,7 @@ void gi_probe_compute(uint index, vec3 position, vec3 normal,vec3 ref_vec, mat3 #ifndef GI_PROBE_LOW_QUALITY vec4 irr_light = voxel_cone_trace(gi_probe_textures[gi_probes.data[index].texture_slot], cell_size, position, ref_vec, tan(roughness * 0.5 * M_PI * 0.99), max_distance, gi_probes.data[index].bias); if (gi_probes.data[index].blend_ambient) { - irr_light.rgb = mix(environment,irr_light.rgb, min(1.0, irr_light.a / 0.95)); + irr_light.rgb = mix(environment, irr_light.rgb, min(1.0, irr_light.a / 0.95)); } irr_light.rgb *= gi_probes.data[index].dynamic_range; //irr_light=vec3(0.0); @@ -1205,7 +1167,6 @@ void gi_probe_compute(uint index, vec3 position, vec3 normal,vec3 ref_vec, mat3 #endif //!defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED) - void main() { #ifdef MODE_DUAL_PARABOLOID @@ -1281,7 +1242,6 @@ void main() { float sss_strength = 0.0; - { /* clang-format off */ @@ -1342,23 +1302,23 @@ FRAGMENT_SHADER_CODE vec3 specular_light = vec3(0.0, 0.0, 0.0); vec3 diffuse_light = vec3(0.0, 0.0, 0.0); - vec3 ambient_light = vec3( 0.0, 0.0, 0.0); + vec3 ambient_light = vec3(0.0, 0.0, 0.0); #if !defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED) - if (scene_data.use_reflection_cubemap){ + if (scene_data.use_reflection_cubemap) { vec3 ref_vec = reflect(-view, normal); ref_vec = scene_data.radiance_inverse_xform * ref_vec; #ifdef USE_RADIANCE_CUBEMAP_ARRAY - float lod,blend; + float lod, blend; blend = modf(roughness * MAX_ROUGHNESS_LOD, lod); - specular_light = texture(samplerCubeArray(radiance_cubemap,material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), vec4(ref_vec, lod)).rgb; - specular_light = mix(specular_light,texture(samplerCubeArray(radiance_cubemap,material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), vec4(ref_vec, lod+1)).rgb,blend); + specular_light = texture(samplerCubeArray(radiance_cubemap, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), vec4(ref_vec, lod)).rgb; + specular_light = mix(specular_light, texture(samplerCubeArray(radiance_cubemap, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), vec4(ref_vec, lod + 1)).rgb, blend); #else - specular_light = textureLod(samplerCube(radiance_cubemap,material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), ref_vec, roughness * MAX_ROUGHNESS_LOD).rgb; + specular_light = textureLod(samplerCube(radiance_cubemap, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), ref_vec, roughness * MAX_ROUGHNESS_LOD).rgb; #endif //USE_RADIANCE_CUBEMAP_ARRAY specular_light *= scene_data.ambient_light_color_energy.a; @@ -1366,28 +1326,25 @@ FRAGMENT_SHADER_CODE #ifndef USE_LIGHTMAP //lightmap overrides everything - if (scene_data.use_ambient_light){ + if (scene_data.use_ambient_light) { ambient_light = scene_data.ambient_light_color_energy.rgb; if (scene_data.use_ambient_cubemap) { vec3 ambient_dir = scene_data.radiance_inverse_xform * normal; #ifdef USE_RADIANCE_CUBEMAP_ARRAY - vec3 cubemap_ambient = texture(samplerCubeArray(radiance_cubemap,material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), vec4(ambient_dir, MAX_ROUGHNESS_LOD)).rgb; + vec3 cubemap_ambient = texture(samplerCubeArray(radiance_cubemap, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), vec4(ambient_dir, MAX_ROUGHNESS_LOD)).rgb; #else - vec3 cubemap_ambient = textureLod(samplerCube(radiance_cubemap,material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), ambient_dir, MAX_ROUGHNESS_LOD).rgb; + vec3 cubemap_ambient = textureLod(samplerCube(radiance_cubemap, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), ambient_dir, MAX_ROUGHNESS_LOD).rgb; #endif //USE_RADIANCE_CUBEMAP_ARRAY - ambient_light = mix( ambient_light, cubemap_ambient * scene_data.ambient_light_color_energy.a, scene_data.ambient_color_sky_mix ); + ambient_light = mix(ambient_light, cubemap_ambient * scene_data.ambient_light_color_energy.a, scene_data.ambient_color_sky_mix); } - - } #endif // USE_LIGHTMAP #endif //!defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED) - //radiance float specular_blob_intensity = 1.0; @@ -1405,8 +1362,8 @@ FRAGMENT_SHADER_CODE #ifdef USE_VOXEL_CONE_TRACING { // process giprobes - uint index1 = instances.data[instance_index].gi_offset&0xFFFF; - if (index1!=0xFFFF) { + uint index1 = instances.data[instance_index].gi_offset & 0xFFFF; + if (index1 != 0xFFFF) { vec3 ref_vec = normalize(reflect(normalize(vertex), normal)); //find arbitrary tangent and bitangent, then build a matrix vec3 v0 = abs(normal.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(0.0, 1.0, 0.0); @@ -1416,12 +1373,12 @@ FRAGMENT_SHADER_CODE vec4 amb_accum = vec4(0.0); vec4 spec_accum = vec4(0.0); - gi_probe_compute(index1, vertex, normal, ref_vec,normal_mat, roughness * roughness, ambient_light, specular_light, spec_accum, amb_accum); + gi_probe_compute(index1, vertex, normal, ref_vec, normal_mat, roughness * roughness, ambient_light, specular_light, spec_accum, amb_accum); - uint index2 = instances.data[instance_index].gi_offset>>16; + uint index2 = instances.data[instance_index].gi_offset >> 16; - if (index2!=0xFFFF) { - gi_probe_compute(index2, vertex, normal, ref_vec,normal_mat, roughness * roughness, ambient_light, specular_light, spec_accum, amb_accum); + if (index2 != 0xFFFF) { + gi_probe_compute(index2, vertex, normal, ref_vec, normal_mat, roughness * roughness, ambient_light, specular_light, spec_accum, amb_accum); } if (amb_accum.a > 0.0) { @@ -1434,13 +1391,11 @@ FRAGMENT_SHADER_CODE specular_light = spec_accum.rgb; ambient_light = amb_accum.rgb; - } } #endif { // 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); @@ -1448,18 +1403,15 @@ FRAGMENT_SHADER_CODE for (uint i = 0; i < reflection_probe_count; i++) { + uint ref_index = instances.data[instance_index].reflection_probe_indices[i >> 1]; - uint ref_index = instances.data[instance_index].reflection_probe_indices[i>>1]; - - if (bool(i&1)) { - ref_index>>=16; + if (bool(i & 1)) { + ref_index >>= 16; } else { - ref_index&=0xFFFF; + ref_index &= 0xFFFF; } - - reflection_process(ref_index,vertex,normal,roughness,ambient_light,specular_light,ambient_accum,reflection_accum); - + reflection_process(ref_index, vertex, normal, roughness, ambient_light, specular_light, ambient_accum, reflection_accum); } if (reflection_accum.a > 0.0) { @@ -1471,8 +1423,6 @@ FRAGMENT_SHADER_CODE ambient_light = ambient_accum.rgb / ambient_accum.a; } #endif - - } { @@ -1502,7 +1452,7 @@ FRAGMENT_SHADER_CODE for (uint i = 0; i < scene_data.directional_light_count; i++) { - if (!bool(directional_lights.data[i].mask&instances.data[instance_index].layer_mask)) { + if (!bool(directional_lights.data[i].mask & instances.data[instance_index].layer_mask)) { continue; //not masked } @@ -1523,7 +1473,7 @@ FRAGMENT_SHADER_CODE pssm_coord = (directional_lights.data[i].shadow_matrix4 * vec4(vertex, 1.0)); } - pssm_coord/=pssm_coord.w; + pssm_coord /= pssm_coord.w; float shadow = sample_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size, pssm_coord); @@ -1544,36 +1494,35 @@ FRAGMENT_SHADER_CODE pssm_blend = 0.0; //if no blend, same coord will be used (divide by z will result in same value, and already cached) } - pssm_coord/=pssm_coord.w; + pssm_coord /= pssm_coord.w; float shadow2 = sample_shadow(directional_shadow_atlas, scene_data.directional_shadow_pixel_size, pssm_coord); - shadow = mix(shadow,shadow2,pssm_blend); - + shadow = mix(shadow, shadow2, pssm_blend); } - shadow = mix(shadow,1.0,smoothstep(directional_lights.data[i].fade_from,directional_lights.data[i].fade_to,vertex.z)); //done with negative values for performance + shadow = mix(shadow, 1.0, smoothstep(directional_lights.data[i].fade_from, directional_lights.data[i].fade_to, vertex.z)); //done with negative values for performance light_attenuation = mix(directional_lights.data[i].shadow_color, vec3(1.0), shadow); } - - light_compute(normal, directional_lights.data[i].direction, normalize(view), directional_lights.data[i].color * directional_lights.data[i].energy, light_attenuation, albedo, roughness, metallic, specular,directional_lights.data[i].specular * specular_blob_intensity, + light_compute(normal, directional_lights.data[i].direction, normalize(view), directional_lights.data[i].color * directional_lights.data[i].energy, light_attenuation, albedo, roughness, metallic, specular, directional_lights.data[i].specular * specular_blob_intensity, #ifdef LIGHT_TRANSMISSION_USED - transmission, + transmission, #endif #ifdef LIGHT_RIM_USED - rim, rim_tint, + rim, rim_tint, #endif #ifdef LIGHT_CLEARCOAT_USED - clearcoat, clearcoat_gloss, + clearcoat, clearcoat_gloss, #endif #ifdef LIGHT_ANISOTROPY_USED - binormal, tangent, anisotropy, + binormal, tangent, anisotropy, #endif #ifdef USE_SHADOW_TO_OPACITY - alpha + alpha, #endif - diffuse_light, specular_light); + diffuse_light, + specular_light); } } @@ -1581,12 +1530,12 @@ FRAGMENT_SHADER_CODE uint omni_light_count = (instances.data[instance_index].flags >> INSTANCE_FLAGS_FORWARD_OMNI_LIGHT_SHIFT) & INSTANCE_FLAGS_FORWARD_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 = instances.data[instance_index].omni_light_indices[i >> 1]; - if (bool(i&1)) { - light_index>>=16; + if (bool(i & 1)) { + light_index >>= 16; } else { - light_index&=0xFFFF; + light_index &= 0xFFFF; } //this is done on CPU, so no need to do it here @@ -1594,38 +1543,37 @@ FRAGMENT_SHADER_CODE // continue; //not masked //} - light_process_omni(light_index, vertex, view, normal, albedo, roughness, metallic, specular,specular_blob_intensity, + light_process_omni(light_index, vertex, view, normal, albedo, roughness, metallic, specular, specular_blob_intensity, #ifdef LIGHT_TRANSMISSION_USED - transmission, + transmission, #endif #ifdef LIGHT_RIM_USED - rim, - rim_tint, + rim, + rim_tint, #endif #ifdef LIGHT_CLEARCOAT_USED - clearcoat, clearcoat_gloss, + clearcoat, clearcoat_gloss, #endif #ifdef LIGHT_ANISOTROPY_USED - tangent, binormal, anisotropy, + tangent, binormal, anisotropy, #endif #ifdef USE_SHADOW_TO_OPACITY - alpha, + alpha, #endif - diffuse_light, specular_light); + diffuse_light, specular_light); } - } { //spot lights uint spot_light_count = (instances.data[instance_index].flags >> INSTANCE_FLAGS_FORWARD_SPOT_LIGHT_SHIFT) & INSTANCE_FLAGS_FORWARD_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 = instances.data[instance_index].spot_light_indices[i >> 1]; - if (bool(i&1)) { - light_index>>=16; + if (bool(i & 1)) { + light_index >>= 16; } else { - light_index&=0xFFFF; + light_index &= 0xFFFF; } //this is done on CPU, so no need to do it here @@ -1633,31 +1581,27 @@ FRAGMENT_SHADER_CODE // continue; //not masked //} - light_process_spot(light_index, vertex, view, normal, albedo, roughness, metallic, specular,specular_blob_intensity, + light_process_spot(light_index, vertex, view, normal, albedo, roughness, metallic, specular, specular_blob_intensity, #ifdef LIGHT_TRANSMISSION_USED - transmission, + transmission, #endif #ifdef LIGHT_RIM_USED - rim, - rim_tint, + rim, + rim_tint, #endif #ifdef LIGHT_CLEARCOAT_USED - clearcoat, clearcoat_gloss, + clearcoat, clearcoat_gloss, #endif #ifdef LIGHT_ANISOTROPY_USED - tangent, binormal, anisotropy, + tangent, binormal, anisotropy, #endif #ifdef USE_SHADOW_TO_OPACITY - alpha, + alpha, #endif - diffuse_light, specular_light); + diffuse_light, specular_light); } - } - - - #ifdef USE_SHADOW_TO_OPACITY alpha = min(alpha, clamp(length(ambient_light), 0.0, 1.0)); @@ -1679,7 +1623,6 @@ FRAGMENT_SHADER_CODE #endif //!defined(MODE_RENDER_DEPTH) && !defined(MODE_UNSHADED) - #ifdef MODE_RENDER_DEPTH #ifdef MODE_RENDER_MATERIAL diff --git a/servers/visual/rasterizer_rd/shaders/scene_forward_inc.glsl b/servers/visual/rasterizer_rd/shaders/scene_forward_inc.glsl index e616d7d0b6..5701781808 100644 --- a/servers/visual/rasterizer_rd/shaders/scene_forward_inc.glsl +++ b/servers/visual/rasterizer_rd/shaders/scene_forward_inc.glsl @@ -1,4 +1,3 @@ - #define M_PI 3.14159265359 #define ROUGHNESS_MAX_LOD 5 @@ -7,11 +6,8 @@ layout(push_constant, binding = 0, std430) uniform DrawCall { uint pad[3]; //16 bits minimum size } draw_call; - - /* Set 0 Scene data that never changes, ever */ - #define SAMPLER_NEAREST_CLAMP 0 #define SAMPLER_LINEAR_CLAMP 1 #define SAMPLER_NEAREST_WITH_MIMPAMPS_CLAMP 2 @@ -29,7 +25,7 @@ layout(set = 0, binding = 1) uniform sampler material_samplers[12]; layout(set = 0, binding = 2) uniform sampler shadow_sampler; -layout(set=0,binding=3,std140) uniform SceneData { +layout(set = 0, binding = 3, std140) uniform SceneData { mat4 projection_matrix; mat4 inv_projection_matrix; @@ -44,7 +40,6 @@ layout(set=0,binding=3,std140) uniform SceneData { float z_offset; float z_slope_scale; - float time; float reflection_multiplier; // one normally, zero when rendering reflections @@ -74,14 +69,12 @@ layout(set=0,binding=3,std140) uniform SceneData { float ambient_energy; float bg_energy; - #endif #if 0 vec2 shadow_atlas_pixel_size; vec2 directional_shadow_pixel_size; - float z_far; float subsurface_scatter_width; @@ -108,17 +101,16 @@ layout(set=0,binding=3,std140) uniform SceneData { #define INSTANCE_FLAGS_FORWARD_SPOT_LIGHT_SHIFT 6 #define INSTANCE_FLAGS_FORWARD_DECAL_SHIFT 9 -#define INSTANCE_FLAGS_MULTIMESH (1 << 12) -#define INSTANCE_FLAGS_MULTIMESH_FORMAT_2D (1 << 13) -#define INSTANCE_FLAGS_MULTIMESH_HAS_COLOR (1 << 14) -#define INSTANCE_FLAGS_MULTIMESH_HAS_CUSTOM_DATA (1 << 15) +#define INSTANCE_FLAGS_MULTIMESH (1 << 12) +#define INSTANCE_FLAGS_MULTIMESH_FORMAT_2D (1 << 13) +#define INSTANCE_FLAGS_MULTIMESH_HAS_COLOR (1 << 14) +#define INSTANCE_FLAGS_MULTIMESH_HAS_CUSTOM_DATA (1 << 15) #define INSTANCE_FLAGS_MULTIMESH_STRIDE_SHIFT 16 //3 bits of stride #define INSTANCE_FLAGS_MULTIMESH_STRIDE_MASK 0x7 #define INSTANCE_FLAGS_SKELETON (1 << 19) - struct InstanceData { mat4 transform; mat4 normal_transform; @@ -133,13 +125,11 @@ struct InstanceData { uint decal_indices[4]; }; - -layout(set=0,binding=4,std430) buffer Instances { - InstanceData data[]; +layout(set = 0, binding = 4, std430) buffer Instances { + InstanceData data[]; } instances; struct LightData { //this structure needs to be 128 bits - vec3 position; float inv_radius; vec3 direction; @@ -152,7 +142,7 @@ struct LightData { //this structure needs to be 128 bits mat4 shadow_matrix; }; -layout(set=0,binding=5,std140) uniform Lights { +layout(set = 0, binding = 5, std140) uniform Lights { LightData data[MAX_LIGHT_DATA_STRUCTS]; } lights; @@ -168,12 +158,11 @@ struct ReflectionData { // notes: for ambientblend, use distance to edge to blend between already existing global environment }; -layout(set=0,binding=6,std140) uniform ReflectionProbeData { +layout(set = 0, binding = 6, std140) uniform ReflectionProbeData { ReflectionData data[MAX_REFLECTION_DATA_STRUCTS]; } reflections; struct DirectionalLightData { - vec3 direction; float energy; vec3 color; @@ -189,10 +178,9 @@ struct DirectionalLightData { mat4 shadow_matrix2; mat4 shadow_matrix3; mat4 shadow_matrix4; - }; -layout(set=0,binding=7,std140) uniform DirectionalLights { +layout(set = 0, binding = 7, std140) uniform DirectionalLights { DirectionalLightData data[MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS]; } directional_lights; @@ -212,20 +200,18 @@ struct GIProbeData { uint pad2; }; -layout(set=0,binding=8,std140) uniform GIProbes { +layout(set = 0, binding = 8, std140) uniform GIProbes { GIProbeData data[MAX_GI_PROBES]; } gi_probes; -layout(set=0,binding=9) uniform texture3D gi_probe_textures[MAX_GI_PROBE_TEXTURES]; - +layout(set = 0, binding = 9) uniform texture3D gi_probe_textures[MAX_GI_PROBE_TEXTURES]; /* Set 1, Scene data that changes per render pass */ - -layout(set=1,binding=0) uniform texture2D depth_buffer; -layout(set=1,binding=1) uniform texture2D color_buffer; -layout(set=1,binding=2) uniform texture2D normal_buffer; -layout(set=1,binding=3) uniform texture2D roughness_limit; +layout(set = 1, binding = 0) uniform texture2D depth_buffer; +layout(set = 1, binding = 1) uniform texture2D color_buffer; +layout(set = 1, binding = 2) uniform texture2D normal_buffer; +layout(set = 1, binding = 3) uniform texture2D roughness_limit; #ifdef USE_RADIANCE_CUBEMAP_ARRAY @@ -237,20 +223,16 @@ layout(set = 1, binding = 4) uniform textureCube radiance_cubemap; #endif +layout(set = 1, binding = 5) uniform textureCubeArray reflection_atlas; -layout(set=1,binding=5) uniform textureCubeArray reflection_atlas; - -layout(set=1,binding=6) uniform texture2D shadow_atlas; - -layout(set=1,binding=7) uniform texture2D directional_shadow_atlas; +layout(set = 1, binding = 6) uniform texture2D shadow_atlas; +layout(set = 1, binding = 7) uniform texture2D directional_shadow_atlas; /* Set 2 Skeleton & Instancing (Multimesh) */ -layout(set=2,binding=0,std430) buffer Transforms { - vec4 data[]; +layout(set = 2, binding = 0, std430) buffer Transforms { + vec4 data[]; } transforms; /* Set 3 User Material */ - - diff --git a/servers/visual/rasterizer_rd/shaders/sky.glsl b/servers/visual/rasterizer_rd/shaders/sky.glsl index a32a1da41c..2de865383a 100644 --- a/servers/visual/rasterizer_rd/shaders/sky.glsl +++ b/servers/visual/rasterizer_rd/shaders/sky.glsl @@ -1,14 +1,12 @@ /* clang-format off */ [vertex] -/* clang-format on */ #version 450 -/* clang-format off */ VERSION_DEFINES -/* clang-format on */ -layout(location =0) out vec2 uv_interp; +layout(location = 0) out vec2 uv_interp; +/* clang-format on */ layout(push_constant, binding = 1, std430) uniform Params { mat3 orientation; @@ -17,33 +15,28 @@ layout(push_constant, binding = 1, std430) uniform Params { float alpha; float depth; float pad; - } params; void main() { - vec2 base_arr[4] = vec2[](vec2(-1.0,-1.0),vec2(-1.0,1.0),vec2(1.0,1.0),vec2(1.0,-1.0)); + vec2 base_arr[4] = vec2[](vec2(-1.0, -1.0), vec2(-1.0, 1.0), vec2(1.0, 1.0), vec2(1.0, -1.0)); uv_interp = base_arr[gl_VertexIndex]; - gl_Position = vec4(uv_interp,params.depth,1.0); - + gl_Position = vec4(uv_interp, params.depth, 1.0); } /* clang-format off */ [fragment] -/* clang-format on */ #version 450 -/* clang-format off */ VERSION_DEFINES -/* clang-format on */ #define M_PI 3.14159265359 -layout(location =0) in vec2 uv_interp; - -layout( set=0, binding=0 ) uniform sampler2D source_panorama; +layout(location = 0) in vec2 uv_interp; +/* clang-format on */ +layout(set = 0, binding = 0) uniform sampler2D source_panorama; layout(push_constant, binding = 1, std430) uniform Params { mat3 orientation; @@ -52,10 +45,8 @@ layout(push_constant, binding = 1, std430) uniform Params { float alpha; float depth; float pad; - } params; - vec4 texturePanorama(sampler2D pano, vec3 normal) { vec2 st = vec2( @@ -70,10 +61,8 @@ vec4 texturePanorama(sampler2D pano, vec3 normal) { return texture(pano, st); } - layout(location = 0) out vec4 frag_color; - void main() { vec3 cube_normal; @@ -85,5 +74,4 @@ void main() { frag_color.rgb = texturePanorama(source_panorama, normalize(cube_normal.xyz)).rgb; frag_color.a = params.alpha; - } diff --git a/servers/visual/rasterizer_rd/shaders/tonemap.glsl b/servers/visual/rasterizer_rd/shaders/tonemap.glsl index f54c938e24..477e0d1055 100644 --- a/servers/visual/rasterizer_rd/shaders/tonemap.glsl +++ b/servers/visual/rasterizer_rd/shaders/tonemap.glsl @@ -1,40 +1,34 @@ /* clang-format off */ [vertex] -/* clang-format on */ #version 450 -/* clang-format off */ VERSION_DEFINES -/* clang-format on */ layout(location = 0) out vec2 uv_interp; +/* clang-format on */ void main() { - vec2 base_arr[4] = vec2[](vec2(0.0,0.0),vec2(0.0,1.0),vec2(1.0,1.0),vec2(1.0,0.0)); + vec2 base_arr[4] = vec2[](vec2(0.0, 0.0), vec2(0.0, 1.0), vec2(1.0, 1.0), vec2(1.0, 0.0)); uv_interp = base_arr[gl_VertexIndex]; - gl_Position = vec4( uv_interp *2.0 - 1.0, 0.0, 1.0); + gl_Position = vec4(uv_interp * 2.0 - 1.0, 0.0, 1.0); } /* clang-format off */ [fragment] -/* clang-format on */ - - #version 450 -/* clang-format off */ VERSION_DEFINES -/* clang-format on */ -layout(location =0) in vec2 uv_interp; +layout(location = 0) in vec2 uv_interp; +/* clang-format on */ -layout( set=0, binding=0 ) uniform sampler2D source_color; -layout( set=1, binding=0 ) uniform sampler2D source_auto_exposure; -layout( set=2, binding=0 ) uniform sampler2D source_glow; -layout( set=3, binding=0 ) uniform sampler3D color_correction; +layout(set = 0, binding = 0) uniform sampler2D source_color; +layout(set = 1, binding = 0) uniform sampler2D source_auto_exposure; +layout(set = 2, binding = 0) uniform sampler2D source_glow; +layout(set = 3, binding = 0) uniform sampler3D color_correction; layout(push_constant, binding = 1, std430) uniform Params { vec3 bcs; @@ -54,7 +48,6 @@ layout(push_constant, binding = 1, std430) uniform Params { float exposure; float white; float auto_exposure_grey; - } params; layout(location = 0) out vec4 frag_color; @@ -95,7 +88,6 @@ float h1(float a) { return 1.0f + w3(a) / (w2(a) + w3(a)); } - vec4 texture2D_bicubic(sampler2D tex, vec2 uv, int p_lod) { float lod = float(p_lod); vec2 tex_size = vec2(params.glow_texture_size >> p_lod); @@ -168,7 +160,7 @@ vec3 tonemap_reinhard(vec3 color, float white) { vec3 linear_to_srgb(vec3 color) { //if going to srgb, clamp from 0 to 1. - color = clamp(color,vec3(0.0),vec3(1.0)); + color = clamp(color, vec3(0.0), vec3(1.0)); const vec3 a = vec3(0.055f); return mix((vec3(1.0f) + a) * pow(color.rgb, vec3(1.0f / 2.4f)) - a, 12.92f * color.rgb, lessThan(color.rgb, vec3(0.0031308f))); } @@ -180,11 +172,11 @@ vec3 linear_to_srgb(vec3 color) { vec3 apply_tonemapping(vec3 color, float white) { // inputs are LINEAR, always outputs clamped [0;1] color - if (params.tonemapper==TONEMAPPER_LINEAR) { + if (params.tonemapper == TONEMAPPER_LINEAR) { return color; - } else if (params.tonemapper==TONEMAPPER_REINHARD) { + } else if (params.tonemapper == TONEMAPPER_REINHARD) { return tonemap_reinhard(color, white); - } else if (params.tonemapper==TONEMAPPER_FILMIC) { + } else if (params.tonemapper == TONEMAPPER_FILMIC) { return tonemap_filmic(color, white); } else { //aces return tonemap_aces(color, white); @@ -194,31 +186,31 @@ vec3 apply_tonemapping(vec3 color, float white) { // inputs are LINEAR, always o vec3 gather_glow(sampler2D tex, vec2 uv) { // sample all selected glow levels vec3 glow = vec3(0.0f); - if (bool(params.glow_level_flags&(1<<0))) { + if (bool(params.glow_level_flags & (1 << 0))) { glow += GLOW_TEXTURE_SAMPLE(tex, uv, 1).rgb; } - if (bool(params.glow_level_flags&(1<<1))) { + if (bool(params.glow_level_flags & (1 << 1))) { glow += GLOW_TEXTURE_SAMPLE(tex, uv, 2).rgb; } - if (bool(params.glow_level_flags&(1<<2))) { + if (bool(params.glow_level_flags & (1 << 2))) { glow += GLOW_TEXTURE_SAMPLE(tex, uv, 3).rgb; } - if (bool(params.glow_level_flags&(1<<3))) { + if (bool(params.glow_level_flags & (1 << 3))) { glow += GLOW_TEXTURE_SAMPLE(tex, uv, 4).rgb; } - if (bool(params.glow_level_flags&(1<<4))) { + if (bool(params.glow_level_flags & (1 << 4))) { glow += GLOW_TEXTURE_SAMPLE(tex, uv, 5).rgb; } - if (bool(params.glow_level_flags&(1<<5))) { + if (bool(params.glow_level_flags & (1 << 5))) { glow += GLOW_TEXTURE_SAMPLE(tex, uv, 6).rgb; } - if (bool(params.glow_level_flags&(1<<6))) { + if (bool(params.glow_level_flags & (1 << 6))) { glow += GLOW_TEXTURE_SAMPLE(tex, uv, 7).rgb; } @@ -231,12 +223,12 @@ vec3 gather_glow(sampler2D tex, vec2 uv) { // sample all selected glow levels #define GLOW_MODE_REPLACE 3 vec3 apply_glow(vec3 color, vec3 glow) { // apply glow using the selected blending mode - if (params.glow_mode==GLOW_MODE_ADD) { + if (params.glow_mode == GLOW_MODE_ADD) { return color + glow; - } else if (params.glow_mode==GLOW_MODE_SCREEN) { + } else if (params.glow_mode == GLOW_MODE_SCREEN) { //need color clamping return max((color + glow) - (color * glow), vec3(0.0)); - } else if ( params.glow_mode==GLOW_MODE_SOFTLIGHT) { + } else if (params.glow_mode == GLOW_MODE_SOFTLIGHT) { //need color clamping glow = glow * vec3(0.5f) + vec3(0.5f); @@ -258,7 +250,7 @@ vec3 apply_bcs(vec3 color, vec3 bcs) { } vec3 apply_color_correction(vec3 color, sampler3D correction_tex) { - return texture(correction_tex,color).rgb; + return texture(correction_tex, color).rgb; } void main() { |