From 84eabb3cf78dfea1e4b5e0d449c02d952c755aa8 Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Mon, 22 Sep 2025 16:15:54 +0200 Subject: [PATCH] Add `.clang-format` and use it to format shader files (#1249) --- .clang-format | 21 ++++++++++ 2d/screen_space_shaders/art/burano.jpg.import | 6 +++ .../art/filmgrain.png.import | 6 +++ 2d/screen_space_shaders/art/forest.jpg.import | 6 +++ .../art/mountains.jpg.import | 6 +++ .../art/platformer.jpg.import | 6 +++ .../art/vignette.png.import | 6 +++ 2d/screen_space_shaders/art/white.png.import | 6 +++ 2d/screen_space_shaders/icon.webp.import | 6 +++ 2d/screen_space_shaders/project.godot | 2 +- 2d/screen_space_shaders/shaders/blur.gdshader | 2 +- .../shaders/old_film.gdshader | 2 +- .../shaders/whirl.gdshader | 2 +- 3d/sprites/shaders/paper_rainbow.gdshader | 3 +- .../gradients/gradient_steps.gdshader | 19 +++------ .../gradients/hues.gdshader | 42 ++++++------------- .../split_screen.gdshader | 12 +++--- .../objects/black_out.gdshader | 2 +- xr/openxr_composition_layers/cursor.gdshader | 2 +- .../objects/black_out.gdshader | 2 +- 20 files changed, 101 insertions(+), 58 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..a5254dfd --- /dev/null +++ b/.clang-format @@ -0,0 +1,21 @@ +BasedOnStyle: LLVM +AlignAfterOpenBracket: DontAlign +AlignOperands: DontAlign +AlignTrailingComments: + Kind: Never + OverEmptyLines: 0 +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortFunctionsOnASingleLine: Inline +BreakConstructorInitializers: AfterColon +ColumnLimit: 0 +ContinuationIndentWidth: 8 +IndentCaseLabels: true +IndentWidth: 4 +InsertBraces: true +KeepEmptyLinesAtTheStartOfBlocks: false +RemoveSemicolon: true +SpacesInLineCommentPrefix: + Minimum: 0 # We want a minimum of 1 for comments, but allow 0 for disabled code. + Maximum: -1 +TabWidth: 4 +UseTab: Always diff --git a/2d/screen_space_shaders/art/burano.jpg.import b/2d/screen_space_shaders/art/burano.jpg.import index 40f52d52..0d215941 100644 --- a/2d/screen_space_shaders/art/burano.jpg.import +++ b/2d/screen_space_shaders/art/burano.jpg.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/burano.jpg-bbae3c5a81f8b6300cd944219dbbbc05.c compress/mode=0 compress/high_quality=false compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 @@ -25,6 +27,10 @@ mipmaps/generate=false mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 process/fix_alpha_border=true process/premult_alpha=false process/normal_map_invert_y=false diff --git a/2d/screen_space_shaders/art/filmgrain.png.import b/2d/screen_space_shaders/art/filmgrain.png.import index 74203246..6cc7a0f9 100644 --- a/2d/screen_space_shaders/art/filmgrain.png.import +++ b/2d/screen_space_shaders/art/filmgrain.png.import @@ -19,6 +19,8 @@ dest_files=["res://.godot/imported/filmgrain.png-8b1c9d8b22a2ffa8f94b1e004d5eddc compress/mode=2 compress/high_quality=false compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 @@ -26,6 +28,10 @@ mipmaps/generate=true mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 process/fix_alpha_border=true process/premult_alpha=false process/normal_map_invert_y=false diff --git a/2d/screen_space_shaders/art/forest.jpg.import b/2d/screen_space_shaders/art/forest.jpg.import index 6036742c..eae79f4a 100644 --- a/2d/screen_space_shaders/art/forest.jpg.import +++ b/2d/screen_space_shaders/art/forest.jpg.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/forest.jpg-f2ce28f12b0871a15d1e9ebfcd24b47f.c compress/mode=0 compress/high_quality=false compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 @@ -25,6 +27,10 @@ mipmaps/generate=false mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 process/fix_alpha_border=true process/premult_alpha=false process/normal_map_invert_y=false diff --git a/2d/screen_space_shaders/art/mountains.jpg.import b/2d/screen_space_shaders/art/mountains.jpg.import index 251c6454..815c00fd 100644 --- a/2d/screen_space_shaders/art/mountains.jpg.import +++ b/2d/screen_space_shaders/art/mountains.jpg.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/mountains.jpg-fd51eb0e2a35878963804e860ef9d18 compress/mode=0 compress/high_quality=false compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 @@ -25,6 +27,10 @@ mipmaps/generate=false mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 process/fix_alpha_border=true process/premult_alpha=false process/normal_map_invert_y=false diff --git a/2d/screen_space_shaders/art/platformer.jpg.import b/2d/screen_space_shaders/art/platformer.jpg.import index bf60714e..11f3f42f 100644 --- a/2d/screen_space_shaders/art/platformer.jpg.import +++ b/2d/screen_space_shaders/art/platformer.jpg.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/platformer.jpg-ce18350247a11c58497c7e0d8e3be2 compress/mode=0 compress/high_quality=false compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 @@ -25,6 +27,10 @@ mipmaps/generate=false mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 process/fix_alpha_border=true process/premult_alpha=false process/normal_map_invert_y=false diff --git a/2d/screen_space_shaders/art/vignette.png.import b/2d/screen_space_shaders/art/vignette.png.import index d4fe926c..81215674 100644 --- a/2d/screen_space_shaders/art/vignette.png.import +++ b/2d/screen_space_shaders/art/vignette.png.import @@ -19,6 +19,8 @@ dest_files=["res://.godot/imported/vignette.png-993dbe0a69e475ef62cba692d80d947d compress/mode=2 compress/high_quality=false compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 @@ -26,6 +28,10 @@ mipmaps/generate=true mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 process/fix_alpha_border=true process/premult_alpha=false process/normal_map_invert_y=false diff --git a/2d/screen_space_shaders/art/white.png.import b/2d/screen_space_shaders/art/white.png.import index fcfd6585..1be41731 100644 --- a/2d/screen_space_shaders/art/white.png.import +++ b/2d/screen_space_shaders/art/white.png.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/white.png-9cdc9524282ba2bce69b45edcd6ac827.ct compress/mode=0 compress/high_quality=false compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 @@ -25,6 +27,10 @@ mipmaps/generate=false mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 process/fix_alpha_border=true process/premult_alpha=false process/normal_map_invert_y=false diff --git a/2d/screen_space_shaders/icon.webp.import b/2d/screen_space_shaders/icon.webp.import index cc29159c..6d517c78 100644 --- a/2d/screen_space_shaders/icon.webp.import +++ b/2d/screen_space_shaders/icon.webp.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/icon.webp-e94f9a68b0f625a567a797079e4d325f.ct compress/mode=0 compress/high_quality=false compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 @@ -25,6 +27,10 @@ mipmaps/generate=false mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 process/fix_alpha_border=true process/premult_alpha=false process/normal_map_invert_y=false diff --git a/2d/screen_space_shaders/project.godot b/2d/screen_space_shaders/project.godot index 66878ca9..fb3082f8 100644 --- a/2d/screen_space_shaders/project.godot +++ b/2d/screen_space_shaders/project.godot @@ -15,7 +15,7 @@ config/description="Several examples of full screen 2D shader processing. Many common full-res effects are implemented here for reference." config/tags=PackedStringArray("2d", "demo", "official", "rendering", "shaders") run/main_scene="res://screen_shaders.tscn" -config/features=PackedStringArray("4.4") +config/features=PackedStringArray("4.5") config/icon="res://icon.webp" [debug] diff --git a/2d/screen_space_shaders/shaders/blur.gdshader b/2d/screen_space_shaders/shaders/blur.gdshader index c3d3c663..70f7988d 100644 --- a/2d/screen_space_shaders/shaders/blur.gdshader +++ b/2d/screen_space_shaders/shaders/blur.gdshader @@ -1,7 +1,7 @@ shader_type canvas_item; uniform sampler2D screen_texture : hint_screen_texture, filter_linear_mipmap; -uniform float amount: hint_range(0.0, 5.0); +uniform float amount : hint_range(0.0, 5.0); void fragment() { COLOR.rgb = textureLod(screen_texture, SCREEN_UV, amount).rgb; diff --git a/2d/screen_space_shaders/shaders/old_film.gdshader b/2d/screen_space_shaders/shaders/old_film.gdshader index e04f1dca..d7c0ae8b 100644 --- a/2d/screen_space_shaders/shaders/old_film.gdshader +++ b/2d/screen_space_shaders/shaders/old_film.gdshader @@ -1,7 +1,7 @@ shader_type canvas_item; uniform sampler2D screen_texture : hint_screen_texture, filter_linear_mipmap; -uniform vec4 base: source_color; +uniform vec4 base : source_color; uniform sampler2D grain; uniform float grain_strength = 0.3; uniform sampler2D vignette; diff --git a/2d/screen_space_shaders/shaders/whirl.gdshader b/2d/screen_space_shaders/shaders/whirl.gdshader index 5d916365..bf42bbd1 100644 --- a/2d/screen_space_shaders/shaders/whirl.gdshader +++ b/2d/screen_space_shaders/shaders/whirl.gdshader @@ -9,6 +9,6 @@ void fragment() { float angle = length(rel) * rotation; mat2 rot = mat2(vec2(cos(angle), -sin(angle)), vec2(sin(angle), cos(angle))); rel = rot * rel; - uv = clamp(rel + vec2(0.5,0.5), vec2(0.0, 0.0), vec2(1.0, 1.0)); + uv = clamp(rel + vec2(0.5, 0.5), vec2(0.0, 0.0), vec2(1.0, 1.0)); COLOR.rgb = textureLod(screen_texture, uv, 0.0).rgb; } diff --git a/3d/sprites/shaders/paper_rainbow.gdshader b/3d/sprites/shaders/paper_rainbow.gdshader index 452ce2ce..7fe9a4da 100644 --- a/3d/sprites/shaders/paper_rainbow.gdshader +++ b/3d/sprites/shaders/paper_rainbow.gdshader @@ -25,8 +25,7 @@ void fragment() { vec3 rainbow = vec3( 0.5 + 0.5 * sin(t), 0.5 + 0.5 * sin(t + 2.0), - 0.5 + 0.5 * sin(t + 4.0) - ); + 0.5 + 0.5 * sin(t + 4.0)); ALBEDO = rainbow; ALPHA = 1.0; } else { diff --git a/3d/tonemap_color_correction/gradients/gradient_steps.gdshader b/3d/tonemap_color_correction/gradients/gradient_steps.gdshader index c1a03533..2429fa02 100644 --- a/3d/tonemap_color_correction/gradients/gradient_steps.gdshader +++ b/3d/tonemap_color_correction/gradients/gradient_steps.gdshader @@ -9,35 +9,28 @@ void fragment() { // Draw base color ALBEDO = my_color; - if (UV.y > 0.25) - { + if (UV.y > 0.25) { // Draw gradient float scale = UV.x * float(steps); - if (exponential_view) - { + if (exponential_view) { scale = (scale * scale) / float(steps); } ALBEDO *= scale; - } - else - { + } else { // Draw step separation bars - for (int i = 1; i < steps; i++) - { + for (int i = 1; i < steps; i++) { float threshold = 0.002; // Bar size float target = float(i); - if (exponential_view) - { + if (exponential_view) { target = sqrt(float(i) * float(steps)); } target = target / float(steps); - if (UV.x < target + threshold && UV.x > target - threshold) - { + if (UV.x < target + threshold && UV.x > target - threshold) { ALBEDO = vec3(0); // Bars are colored black } } diff --git a/3d/tonemap_color_correction/gradients/hues.gdshader b/3d/tonemap_color_correction/gradients/hues.gdshader index 547dd3d9..8aaa6076 100644 --- a/3d/tonemap_color_correction/gradients/hues.gdshader +++ b/3d/tonemap_color_correction/gradients/hues.gdshader @@ -6,45 +6,33 @@ uniform bool exponential_view = true; void fragment() { float top_bar = 0.01; - if (UV.y >= top_bar) - { + if (UV.y >= top_bar) { float padding = 0.002; float y = (UV.y - top_bar - padding) / (1.0 - top_bar - padding * 2.0); y = clamp(y, 0.0, 1.0); float segments = 1.0 / 6.0; vec3 col = vec3(0); - if (y < segments) - { + if (y < segments) { col.r = 1.0; col.g = y / segments; col.b = 0.0; - } - else if (y < segments * 2.0) - { + } else if (y < segments * 2.0) { col.r = (y - segments * 2.0) / -segments; col.g = 1.0; col.b = 0.0; - } - else if (y < segments * 3.0) - { + } else if (y < segments * 3.0) { col.r = 0.0; col.g = 1.0; col.b = (y - segments * 2.0) / segments; - } - else if (y < segments * 4.0) - { + } else if (y < segments * 4.0) { col.r = 0.0; col.g = (y - segments * 4.0) / -segments; col.b = 1.0; - } - else if (y < segments * 5.0) - { + } else if (y < segments * 5.0) { col.r = (y - segments * 4.0) / segments; col.g = 0.0; col.b = 1.0; - } - else - { + } else { col.r = 1.0; col.g = 0.0; col.b = (y - segments * 6.0) / -segments; @@ -52,31 +40,25 @@ void fragment() { float scale = UV.x * float(steps); - if (exponential_view) - { + if (exponential_view) { scale = (scale * scale) / float(steps); } ALBEDO = col * scale; - } - else - { + } else { ALBEDO = vec3(1.0); // Draw step separation bars - for (int i = 1; i < steps; i++) - { + for (int i = 1; i < steps; i++) { float threshold = 0.002; // Bar size float target = float(i); - if (exponential_view) - { + if (exponential_view) { target = sqrt(float(i) * float(steps)); } target = target / float(steps); - if (UV.x < target + threshold && UV.x > target - threshold) - { + if (UV.x < target + threshold && UV.x > target - threshold) { ALBEDO = vec3(0); // Bars are colored black } } diff --git a/viewport/dynamic_split_screen/split_screen.gdshader b/viewport/dynamic_split_screen/split_screen.gdshader index bc3d6ac1..3fd86999 100644 --- a/viewport/dynamic_split_screen/split_screen.gdshader +++ b/viewport/dynamic_split_screen/split_screen.gdshader @@ -1,14 +1,14 @@ shader_type canvas_item; render_mode unshaded; -uniform vec2 viewport_size; // size in pixels of the viewport +uniform vec2 viewport_size; // size in pixels of the viewport uniform sampler2D viewport1 : source_color; uniform sampler2D viewport2 : source_color; -uniform bool split_active; // true: split screen, false: use view1 -uniform vec2 player1_position; // position of player 1 un UV coordinates -uniform vec2 player2_position; // position of player 2 un UV coordinates -uniform float split_line_thickness : hint_range(0, 10, 0.1); // width of the split boder -uniform vec3 split_line_color : source_color; // color of the split border +uniform bool split_active; // true: split screen, false: use view1 +uniform vec2 player1_position; // position of player 1 un UV coordinates +uniform vec2 player2_position; // position of player 2 un UV coordinates +uniform float split_line_thickness : hint_range(0, 10, 0.1); // width of the split boder +uniform vec3 split_line_color : source_color; // color of the split border // from https://stackoverflow.com/questions/15276454/is-it-possible-to-draw-line-thickness-in-a-fragment-shader float distance_to_line(vec2 p1, vec2 p2, vec2 point) { diff --git a/xr/openxr_character_centric_movement/objects/black_out.gdshader b/xr/openxr_character_centric_movement/objects/black_out.gdshader index e021b067..eb3eb56c 100644 --- a/xr/openxr_character_centric_movement/objects/black_out.gdshader +++ b/xr/openxr_character_centric_movement/objects/black_out.gdshader @@ -1,5 +1,5 @@ shader_type spatial; -render_mode blend_mix,depth_draw_opaque,cull_disabled,unshaded,depth_test_disabled; +render_mode blend_mix, depth_draw_opaque, cull_disabled, unshaded, depth_test_disabled; uniform vec4 albedo : source_color; void vertex() { diff --git a/xr/openxr_composition_layers/cursor.gdshader b/xr/openxr_composition_layers/cursor.gdshader index 5fe61287..49348ea8 100644 --- a/xr/openxr_composition_layers/cursor.gdshader +++ b/xr/openxr_composition_layers/cursor.gdshader @@ -5,5 +5,5 @@ uniform vec3 color : source_color = vec3(1.0, 1.0, 1.0); void fragment() { // Called for every pixel the material is visible on. float dist = length(UV - vec2(0.5, 0.5)); - COLOR.a = 1.0 - clamp(abs(0.4 - dist)/0.1, 0.0, 1.0); + COLOR.a = 1.0 - clamp(abs(0.4 - dist) / 0.1, 0.0, 1.0); } diff --git a/xr/openxr_origin_centric_movement/objects/black_out.gdshader b/xr/openxr_origin_centric_movement/objects/black_out.gdshader index e021b067..eb3eb56c 100644 --- a/xr/openxr_origin_centric_movement/objects/black_out.gdshader +++ b/xr/openxr_origin_centric_movement/objects/black_out.gdshader @@ -1,5 +1,5 @@ shader_type spatial; -render_mode blend_mix,depth_draw_opaque,cull_disabled,unshaded,depth_test_disabled; +render_mode blend_mix, depth_draw_opaque, cull_disabled, unshaded, depth_test_disabled; uniform vec4 albedo : source_color; void vertex() {