From d46cfd2df67d0d386f306c548dc9878fa972aee2 Mon Sep 17 00:00:00 2001 From: Rob Kelly Date: Sun, 16 Mar 2025 16:59:30 -0600 Subject: [PATCH] Added Ultimate Retro Shader Collection --- addons/ursc/LICENSE.md | 21 + addons/ursc/canvas_item/dithering.gdshader | 30 ++ .../ursc/canvas_item/dithering.gdshader.uid | 1 + addons/ursc/canvas_item/fade.gdshader | 16 + addons/ursc/canvas_item/fade.gdshader.uid | 1 + addons/ursc/setup.gd | 57 +++ addons/ursc/setup.gd.uid | 1 + .../ursc/spatial/basic/basic_opaque.gdshader | 5 + .../spatial/basic/basic_opaque.gdshader.uid | 1 + .../spatial/basic/basic_transparent.gdshader | 6 + .../basic/basic_transparent.gdshader.uid | 1 + addons/ursc/spatial/common.gdshaderinc | 423 ++++++++++++++++++ addons/ursc/spatial/common.gdshaderinc.uid | 1 + addons/ursc/spatial/flat_sky.gdshader | 75 ++++ addons/ursc/spatial/flat_sky.gdshader.uid | 1 + .../spatial/metallic/metallic_opaque.gdshader | 5 + .../metallic/metallic_opaque.gdshader.uid | 1 + .../metallic/metallic_transparent.gdshader | 6 + .../metallic_transparent.gdshader.uid | 1 + .../ursc/spatial/shiny/shiny_opaque.gdshader | 5 + .../spatial/shiny/shiny_opaque.gdshader.uid | 1 + .../spatial/shiny/shiny_transparent.gdshader | 6 + .../shiny/shiny_transparent.gdshader.uid | 1 + .../spatial/sprite/sprite_shaded.gdshader | 6 + .../spatial/sprite/sprite_shaded.gdshader.uid | 1 + .../sprite_shaded_double_sided.gdshader | 7 + .../sprite_shaded_double_sided.gdshader.uid | 1 + .../spatial/sprite/sprite_unshaded.gdshader | 7 + .../sprite/sprite_unshaded.gdshader.uid | 1 + .../sprite_unshaded_double_sided.gdshader | 8 + .../sprite_unshaded_double_sided.gdshader.uid | 1 + .../spatial/standard/standard_opaque.gdshader | 3 + .../standard/standard_opaque.gdshader.uid | 1 + .../standard_opaque_repeating.gdshader | 5 + .../standard_opaque_repeating.gdshader.uid | 1 + .../standard/standard_transparent.gdshader | 5 + .../standard_transparent.gdshader.uid | 1 + .../standard_transparent_repeating.gdshader | 5 + ...tandard_transparent_repeating.gdshader.uid | 1 + 39 files changed, 720 insertions(+) create mode 100644 addons/ursc/LICENSE.md create mode 100644 addons/ursc/canvas_item/dithering.gdshader create mode 100644 addons/ursc/canvas_item/dithering.gdshader.uid create mode 100644 addons/ursc/canvas_item/fade.gdshader create mode 100644 addons/ursc/canvas_item/fade.gdshader.uid create mode 100644 addons/ursc/setup.gd create mode 100644 addons/ursc/setup.gd.uid create mode 100644 addons/ursc/spatial/basic/basic_opaque.gdshader create mode 100644 addons/ursc/spatial/basic/basic_opaque.gdshader.uid create mode 100644 addons/ursc/spatial/basic/basic_transparent.gdshader create mode 100644 addons/ursc/spatial/basic/basic_transparent.gdshader.uid create mode 100644 addons/ursc/spatial/common.gdshaderinc create mode 100644 addons/ursc/spatial/common.gdshaderinc.uid create mode 100644 addons/ursc/spatial/flat_sky.gdshader create mode 100644 addons/ursc/spatial/flat_sky.gdshader.uid create mode 100644 addons/ursc/spatial/metallic/metallic_opaque.gdshader create mode 100644 addons/ursc/spatial/metallic/metallic_opaque.gdshader.uid create mode 100644 addons/ursc/spatial/metallic/metallic_transparent.gdshader create mode 100644 addons/ursc/spatial/metallic/metallic_transparent.gdshader.uid create mode 100644 addons/ursc/spatial/shiny/shiny_opaque.gdshader create mode 100644 addons/ursc/spatial/shiny/shiny_opaque.gdshader.uid create mode 100644 addons/ursc/spatial/shiny/shiny_transparent.gdshader create mode 100644 addons/ursc/spatial/shiny/shiny_transparent.gdshader.uid create mode 100644 addons/ursc/spatial/sprite/sprite_shaded.gdshader create mode 100644 addons/ursc/spatial/sprite/sprite_shaded.gdshader.uid create mode 100644 addons/ursc/spatial/sprite/sprite_shaded_double_sided.gdshader create mode 100644 addons/ursc/spatial/sprite/sprite_shaded_double_sided.gdshader.uid create mode 100644 addons/ursc/spatial/sprite/sprite_unshaded.gdshader create mode 100644 addons/ursc/spatial/sprite/sprite_unshaded.gdshader.uid create mode 100644 addons/ursc/spatial/sprite/sprite_unshaded_double_sided.gdshader create mode 100644 addons/ursc/spatial/sprite/sprite_unshaded_double_sided.gdshader.uid create mode 100644 addons/ursc/spatial/standard/standard_opaque.gdshader create mode 100644 addons/ursc/spatial/standard/standard_opaque.gdshader.uid create mode 100644 addons/ursc/spatial/standard/standard_opaque_repeating.gdshader create mode 100644 addons/ursc/spatial/standard/standard_opaque_repeating.gdshader.uid create mode 100644 addons/ursc/spatial/standard/standard_transparent.gdshader create mode 100644 addons/ursc/spatial/standard/standard_transparent.gdshader.uid create mode 100644 addons/ursc/spatial/standard/standard_transparent_repeating.gdshader create mode 100644 addons/ursc/spatial/standard/standard_transparent_repeating.gdshader.uid diff --git a/addons/ursc/LICENSE.md b/addons/ursc/LICENSE.md new file mode 100644 index 0000000..ff78122 --- /dev/null +++ b/addons/ursc/LICENSE.md @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024-2025 Zorochase + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/addons/ursc/canvas_item/dithering.gdshader b/addons/ursc/canvas_item/dithering.gdshader new file mode 100644 index 0000000..80e41ba --- /dev/null +++ b/addons/ursc/canvas_item/dithering.gdshader @@ -0,0 +1,30 @@ +#pragma disable_preprocessor + +shader_type canvas_item; + +// 0: bypass +uniform float color_depth: hint_range(0, 32, 8) = 24; + +uniform sampler2D dithering_pattern_texture: + hint_default_white, repeat_enable, filter_nearest; + +void fragment() +{ + vec3 base_color = texture(TEXTURE, UV).rgb; + + if (color_depth > 0.0) + { + vec2 dpt_size = vec2(textureSize(dithering_pattern_texture, 0)); + vec2 texture_size = vec2(textureSize(TEXTURE, 0)); + + vec3 dithering = texture( + dithering_pattern_texture, UV * (texture_size / dpt_size)).rgb - 0.5; + + COLOR.rgb = round( + base_color.rgb * color_depth + dithering) / color_depth; + } + else + { + COLOR.rgb = base_color; + } +} diff --git a/addons/ursc/canvas_item/dithering.gdshader.uid b/addons/ursc/canvas_item/dithering.gdshader.uid new file mode 100644 index 0000000..97e730c --- /dev/null +++ b/addons/ursc/canvas_item/dithering.gdshader.uid @@ -0,0 +1 @@ +uid://wxhwpvomk7j8 diff --git a/addons/ursc/canvas_item/fade.gdshader b/addons/ursc/canvas_item/fade.gdshader new file mode 100644 index 0000000..e251005 --- /dev/null +++ b/addons/ursc/canvas_item/fade.gdshader @@ -0,0 +1,16 @@ +#pragma disable_preprocessor + +shader_type canvas_item; + +uniform sampler2D SCREEN_TEXTURE: hint_screen_texture, filter_nearest, repeat_disable; + +// 1: white +// -1: black +uniform int mode: hint_range(-1, 1, 2) = -1; + +void fragment() +{ + vec3 screen_color = texture(SCREEN_TEXTURE, SCREEN_UV).rgb; + COLOR.rgb = screen_color + COLOR.a * float(mode); + COLOR.a = 1.0; +} diff --git a/addons/ursc/canvas_item/fade.gdshader.uid b/addons/ursc/canvas_item/fade.gdshader.uid new file mode 100644 index 0000000..fb6820e --- /dev/null +++ b/addons/ursc/canvas_item/fade.gdshader.uid @@ -0,0 +1 @@ +uid://blpm86lhwl2mx diff --git a/addons/ursc/setup.gd b/addons/ursc/setup.gd new file mode 100644 index 0000000..7429bd3 --- /dev/null +++ b/addons/ursc/setup.gd @@ -0,0 +1,57 @@ +# Ultimate Retro Shader Collection (v1.4.0): Setup Script +# +# This script will add the necessary shader globals for URSC shaders to your project.godot file. +# To run, just click File -> Run. +# In order to fully register the globals, the editor will be restarted upon running. +# +# NOTE: this script CAN'T be used to manage the globals for your game! You'll need to write your +# own code to handle the values of the globals at runtime. +@tool +extends EditorScript + + +var shader_globals := { + "affine_texture_mapping": { + "type": "bool", + "value": true + }, + "fog_color": { + "type": "color", + "value": Color(0, 0, 0, 1) + }, + "fog_start_distance": { + "type": "float", + "value": 0.0 + }, + "fog_end_distance": { + "type": "float", + "value": 0.0 + }, + "cull_distance": { + "type": "float", + "value": 64.0 + }, + "texture_filtering": { + "type": "bool", + "value": false + }, + "texture_lod_halve_distance": { + "type": "float", + "value": 0.0 + }, + "vertex_snap_intensity": { + "type": "int", + "value": 2 + } +} + + +func _run() -> void: + for key: String in shader_globals: + var full_key := "shader_globals/%s" % key + + if not ProjectSettings.has_setting(full_key): + ProjectSettings.set_setting(full_key, shader_globals[key]) + + ProjectSettings.save() + EditorInterface.restart_editor() diff --git a/addons/ursc/setup.gd.uid b/addons/ursc/setup.gd.uid new file mode 100644 index 0000000..d528ce1 --- /dev/null +++ b/addons/ursc/setup.gd.uid @@ -0,0 +1 @@ +uid://bd6jh1ibnerth diff --git a/addons/ursc/spatial/basic/basic_opaque.gdshader b/addons/ursc/spatial/basic/basic_opaque.gdshader new file mode 100644 index 0000000..52f9b93 --- /dev/null +++ b/addons/ursc/spatial/basic/basic_opaque.gdshader @@ -0,0 +1,5 @@ +shader_type spatial; + +#define TEXTURE_DISABLED + +#include "../common.gdshaderinc" diff --git a/addons/ursc/spatial/basic/basic_opaque.gdshader.uid b/addons/ursc/spatial/basic/basic_opaque.gdshader.uid new file mode 100644 index 0000000..a170863 --- /dev/null +++ b/addons/ursc/spatial/basic/basic_opaque.gdshader.uid @@ -0,0 +1 @@ +uid://bj0i6h2fxqytw diff --git a/addons/ursc/spatial/basic/basic_transparent.gdshader b/addons/ursc/spatial/basic/basic_transparent.gdshader new file mode 100644 index 0000000..33b6568 --- /dev/null +++ b/addons/ursc/spatial/basic/basic_transparent.gdshader @@ -0,0 +1,6 @@ +shader_type spatial; + +#define ALPHA_BLEND +#define TEXTURE_DISABLED + +#include "../common.gdshaderinc" diff --git a/addons/ursc/spatial/basic/basic_transparent.gdshader.uid b/addons/ursc/spatial/basic/basic_transparent.gdshader.uid new file mode 100644 index 0000000..58c7b1b --- /dev/null +++ b/addons/ursc/spatial/basic/basic_transparent.gdshader.uid @@ -0,0 +1 @@ +uid://ospxfabwl235 diff --git a/addons/ursc/spatial/common.gdshaderinc b/addons/ursc/spatial/common.gdshaderinc new file mode 100644 index 0000000..a347445 --- /dev/null +++ b/addons/ursc/spatial/common.gdshaderinc @@ -0,0 +1,423 @@ +// If you want to use fog controlled by a Godot Environment resource (pixel-based), +// simply uncomment the following line: +// #define USE_ENVIRONMENT_FOG + +// Render mode +render_mode + +#if defined(BLEND_MODE) + BLEND_MODE, +#endif + +#if defined(CULL_MODE) + CULL_MODE, +#else + cull_back, +#endif + +#if defined(ALPHA_BLEND) + depth_draw_always, +#else + depth_draw_opaque, +#endif + +#if defined(UNSHADED) + unshaded, +#else + diffuse_lambert_wrap, + vertex_lighting, +#endif + +#if defined(AMBIENT_LIGHT_DISABLED) + ambient_light_disabled, +#endif + +#if defined(FOG_DISABLED) + fog_disabled, +#endif + +specular_disabled, +shadows_disabled; + + +// Constants +#if !defined(OVERRIDE_VERTEX_SNAP_RESOLUTION) + const ivec2 VERTEX_SNAP_RESOLUTION = ivec2(320, 240); +#endif + + +// Global uniforms +#if !defined(TEXTURE_DISABLED) && !defined(SHINY) + #if !defined(TEXTURE_METAL) + global uniform bool affine_texture_mapping; + #endif + + global uniform bool texture_filtering; + global uniform float texture_lod_halve_distance; +#endif + +#if defined(OVERRIDE_VERTEX_SNAP_RESOLUTION) + global uniform ivec2 vertex_snap_resolution; +#else + global uniform int vertex_snap_intensity; +#endif + +#if !defined(FOG_DISABLED) && !defined(USE_ENVIRONMENT_FOG) + global uniform vec4 fog_color : source_color; + global uniform float fog_start_distance; + global uniform float fog_end_distance; +#endif + +global uniform float cull_distance; + + +// Uniforms +#if defined(ALPHA_BLEND) || (defined(ALPHA_SCISSOR) && !defined(SHINY) && !defined(TEXTURE_METAL)) + uniform vec4 albedo_color : source_color = vec4(1.0); +#else + uniform vec3 albedo_color : source_color = vec3(1.0); +#endif + +#if defined(SHINY) + uniform float color_depth : hint_range(16, 64, 16) = 16; + uniform float glossiness : hint_range(0, 1, 0.05) = 0.4; + uniform float shadow_intensity : hint_range(0, 1, 0.05) = 0.65; +#elif !defined(TEXTURE_DISABLED) + uniform sampler2D albedo_texture : + source_color, + filter_nearest, + #if defined(TEXTURE_REPEAT) + repeat_enable; + #else + repeat_disable; + #endif + + #if (defined(ALPHA_SCISSOR) && !defined(SHINY) && !defined(TEXTURE_METAL)) + uniform float alpha_scissor : hint_range(0, 1, 0.01) = 0.1; + #else + uniform bool albedo_texture_as_primary_color = true; + uniform float mix_factor: hint_range(0.0, 1.0, 0.01) = 1.0; + #endif + + uniform float texture_lod_halve_distance_override : hint_range(0.0, 32.0, 2.0) = 0; + + #if !defined(TEXTURE_METAL) + uniform vec2 uv_offset = vec2(0.0); + uniform vec2 uv_scale = vec2(1.0); + uniform vec2 uv_scroll_speed = vec2(0.0); + #endif +#endif + +#if defined(BILLBOARD) + uniform int billboard_mode: hint_range(0, 2); + uniform bool use_transform_scale = true; +#endif + +uniform float cull_distance_override: hint_range(0.0, 1024.0, 2.0) = 0; + +uniform bool convert_vertex_colors = false; + + +// Varyings +#if !defined(TEXTURE_DISABLED) && !defined(TEXTURE_METAL) && !defined(SHINY) + varying float position_w; +#endif + +#if !defined(TEXTURE_DISABLED) && !defined(SHINY) + varying flat int should_halve_texture_lod; +#endif + +#if !defined(FOG_DISABLED) && !defined(USE_ENVIRONMENT_FOG) + varying float fog_mix_factor; +#endif + +// Functions +#if defined(SHINY) + vec3 glimmer(vec3 input) + { + float grayscale = max(vec3(input).r, max(vec3(input).g, vec3(input).b)); + float lower = floor(grayscale * color_depth) / color_depth; + float lower_difference = abs(grayscale - lower); + float upper = ceil(grayscale * color_depth) / color_depth; + float upper_difference = abs(upper - grayscale); + float level = lower_difference <= upper_difference ? lower : upper; + float adjustment = level / grayscale; + return vec3(input) * adjustment; + } +#elif !defined(TEXTURE_DISABLED) + vec4 albedoTextureFiltered(vec2 uv) + { + vec2 albedo_texture_size = vec2(textureSize(albedo_texture, 0)); + + vec2 tex_pix_a = vec2(1.0 / albedo_texture_size.x, 0.0); + vec2 tex_pix_b = vec2(0.0, 1.0 / albedo_texture_size.y); + vec2 tex_pix_c = vec2(tex_pix_a.x,tex_pix_b.y); + vec2 half_tex = vec2(tex_pix_a.x * 0.5, tex_pix_b.y * 0.5); + vec2 uv_centered = uv - half_tex; + + vec4 diffuse_color = texture(albedo_texture, uv_centered); + vec4 sample_a = texture(albedo_texture, uv_centered + tex_pix_a); + vec4 sample_b = texture(albedo_texture, uv_centered + tex_pix_b); + vec4 sample_c = texture(albedo_texture, uv_centered + tex_pix_c); + + float interp_x = modf(uv_centered.x * albedo_texture_size.x, albedo_texture_size.x); + float interp_y = modf(uv_centered.y * albedo_texture_size.y, albedo_texture_size.y); + + if (uv_centered.x < 0.0) + { + interp_x = 1.0 - interp_x * -1.0; + } + if (uv_centered.y < 0.0) + { + interp_y = 1.0 - interp_y * -1.0; + } + + diffuse_color = ( + diffuse_color + + interp_x * (sample_a - diffuse_color) + + interp_y * (sample_b - diffuse_color)) * + (1.0 - step(1.0, interp_x + interp_y)); + + diffuse_color += ( + (sample_c + (1.0 - interp_x) * (sample_b - sample_c) + + (1.0 - interp_y) * (sample_a - sample_c)) * + step(1.0, interp_x + interp_y)); + + return diffuse_color; + } +#endif + +// https://gamedev.stackexchange.com/a/194038 +vec3 fromLinear(vec3 linear_color) +{ + bvec3 cutoff = lessThan(linear_color.rgb, vec3(0.0031308)); + vec3 higher = vec3(1.055) * pow(linear_color.rgb, vec3(1.0 / 2.4)) - vec3(0.055); + vec3 lower = linear_color.rgb * vec3(12.92); + + return mix(higher, lower, cutoff); +} + +// https://gamedev.stackexchange.com/a/194038 +vec3 toLinear(vec3 srgb_color) +{ + bvec3 cutoff = lessThan(srgb_color.rgb, vec3(0.04045)); + vec3 higher = pow((srgb_color.rgb + vec3(0.055)) / vec3(1.055), vec3(2.4)); + vec3 lower = srgb_color.rgb / vec3(12.92); + + return mix(higher, lower, cutoff); +} + +void vertex() +{ + if (convert_vertex_colors) + COLOR.rgb = fromLinear(COLOR.rgb); + + #if !defined(TEXTURE_DISABLED) && !defined(TEXTURE_METAL) && !defined(SHINY) + UV = UV * uv_scale + uv_offset + (uv_scroll_speed * TIME); + #endif + + #if defined(BILLBOARD) + if (billboard_mode > 0) + { + if (billboard_mode == 1) + { + MODELVIEW_MATRIX = VIEW_MATRIX * mat4( + INV_VIEW_MATRIX[0], + INV_VIEW_MATRIX[1], + INV_VIEW_MATRIX[2], + MODEL_MATRIX[3]); + } + else + { + MODELVIEW_MATRIX = VIEW_MATRIX * mat4( + vec4(normalize(cross(vec3(0.0, 1.0, 0.0), INV_VIEW_MATRIX[2].xyz)), 0.0), + vec4(0.0, 1.0, 0.0, 0.0), + vec4(normalize(cross(INV_VIEW_MATRIX[0].xyz, vec3(0.0, 1.0, 0.0))), 0.0), + MODEL_MATRIX[3]); + } + + if (use_transform_scale) + { + MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4( + vec4(length(MODEL_MATRIX[0].xyz), 0.0, 0.0, 0.0), + vec4(0.0, length(MODEL_MATRIX[1].xyz), 0.0, 0.0), + vec4(0.0, 0.0, length(MODEL_MATRIX[2].xyz), 0.0), + vec4(0.0, 0.0, 0.0, 1.0)); + } + + MODELVIEW_NORMAL_MATRIX = mat3(MODELVIEW_MATRIX); + } + #endif + + float vertex_distance = length((MODELVIEW_MATRIX * vec4(VERTEX, 1.0))); + + #if !defined(FOG_DISABLED) && !defined(USE_ENVIRONMENT_FOG) + if (fog_start_distance >= 0.0 && fog_start_distance < fog_end_distance) + { + fog_mix_factor = clamp( + (vertex_distance - fog_start_distance) / (fog_end_distance - fog_start_distance), + 0.0, 1.0); + } + else + { + fog_mix_factor = 0.0; + } + #endif + + #if !defined(TEXTURE_DISABLED) && !defined(SHINY) + float actual_texture_lod_halve_distance = + texture_lod_halve_distance_override > 0.0 + ? texture_lod_halve_distance_override + : texture_lod_halve_distance; + + should_halve_texture_lod = ( + !texture_filtering && + actual_texture_lod_halve_distance > 0.0 && + vertex_distance > actual_texture_lod_halve_distance) ? 1 : 0; + #endif + + float actual_cull_distance = + cull_distance_override > 0.0 ? cull_distance_override : cull_distance; + + if (actual_cull_distance > 0.0 && vertex_distance > actual_cull_distance) + { + POSITION = vec4(sqrt(-1)); + } + else + { + POSITION = PROJECTION_MATRIX * MODELVIEW_MATRIX * vec4(VERTEX, 1.0); + + #if defined(OVERRIDE_VERTEX_SNAP_RESOLUTION) + vec4 snapped_position = POSITION; + snapped_position.xyz = POSITION.xyz / POSITION.w; + + vec2 actual_vertex_snap_resolution = vec2(vertex_snap_resolution); + + snapped_position.x = + floor(actual_vertex_snap_resolution.x * snapped_position.x) / + actual_vertex_snap_resolution.x; + + snapped_position.y = + floor(actual_vertex_snap_resolution.y * snapped_position.y) / + actual_vertex_snap_resolution.y; + + snapped_position.xyz *= POSITION.w; + + POSITION.xyz = snapped_position.xyz; + #else + if (vertex_snap_intensity > 0 && vertex_snap_intensity <= 2) + { + vec2 real_vertex_snap_resolution = + vec2(VERTEX_SNAP_RESOLUTION) * (1.0 / float(vertex_snap_intensity)); + + vec4 snapped_position = POSITION; + snapped_position.xyz = POSITION.xyz / POSITION.w; + + snapped_position.x = + floor(real_vertex_snap_resolution.x * snapped_position.x) / + real_vertex_snap_resolution.x; + + snapped_position.y = + floor(real_vertex_snap_resolution.y * snapped_position.y) / + real_vertex_snap_resolution.y; + + snapped_position.xyz *= POSITION.w; + + POSITION.xyz = snapped_position.xyz; + } + #endif + } + + #if !defined(TEXTURE_DISABLED) && !defined(TEXTURE_METAL) && !defined(SHINY) + if (affine_texture_mapping) + { + position_w = POSITION.w; + UV *= abs(POSITION.w); + } + #endif +} + +void fragment() +{ + #if defined(SHINY) + vec3 light_dir = vec3(0.500000, 0.250000, 1.000000); + float light_dot = dot(light_dir, NORMAL); + vec3 brightness = glimmer(vec3(pow(light_dot, 10.0))); + brightness = clamp(brightness * vec3(glossiness), vec3(0.00000), vec3(1.00000)); + vec3 shadow_dir = vec3(-light_dir.x, -light_dir.y, light_dir.z); + float dark_dot = dot(NORMAL, shadow_dir); + vec3 darkness = glimmer(vec3(dark_dot)); + + ALBEDO = + clamp(albedo_color.rgb + + brightness + + darkness * vec3(-shadow_intensity), 0.0, 1.0); + + #if defined(ALPHA_BLEND) + ALPHA = albedo_color.a; + #endif + #else + #if defined(TEXTURE_DISABLED) + ALBEDO = albedo_color.rgb * COLOR.rgb; + + #if defined(ALPHA_BLEND) + ALPHA = albedo_color.a * COLOR.a; + #endif + #else + vec2 uv; + + #if defined(TEXTURE_METAL) + uv = vec2(NORMAL.x / 2.0 + 0.5, (-NORMAL.y) / 2.0 + 0.5); + #else + uv = UV; + + if (affine_texture_mapping) + uv /= abs(position_w); + #endif + + vec4 sampled_color; + + if (should_halve_texture_lod == 1) + { + vec2 half_albedo_texture_size = vec2(textureSize(albedo_texture, 0)) * 0.5; + vec2 new_uv = floor(uv * half_albedo_texture_size) / half_albedo_texture_size; + + sampled_color = texture(albedo_texture, new_uv); + } + else + { + if (texture_filtering) + sampled_color = albedoTextureFiltered(uv); + else + sampled_color = texture(albedo_texture, uv); + } + + #if (defined(ALPHA_SCISSOR) && !defined(SHINY) && !defined(TEXTURE_METAL)) + ALBEDO = albedo_color.rgb * sampled_color.rgb; + ALPHA = albedo_color.a * sampled_color.a; + ALPHA_SCISSOR_THRESHOLD = alpha_scissor; + #else + vec3 primary_color = + albedo_texture_as_primary_color ? sampled_color.rgb : COLOR.rgb; + + vec3 secondary_color = + albedo_texture_as_primary_color ? COLOR.rgb : sampled_color.rgb; + + ALBEDO = + (1.0 - mix_factor) * primary_color + + mix_factor * secondary_color * primary_color; + + ALBEDO *= albedo_color.rgb; + + #if defined(ALPHA_BLEND) + ALPHA = albedo_color.a * sampled_color.a * COLOR.a; + #endif + #endif + #endif + #endif + + #if !defined(FOG_DISABLED) && !defined(USE_ENVIRONMENT_FOG) + FOG.a = fog_mix_factor; + FOG.rgb = toLinear(fog_color.rgb); + #endif +} diff --git a/addons/ursc/spatial/common.gdshaderinc.uid b/addons/ursc/spatial/common.gdshaderinc.uid new file mode 100644 index 0000000..8f9bc30 --- /dev/null +++ b/addons/ursc/spatial/common.gdshaderinc.uid @@ -0,0 +1 @@ +uid://bigsqd73fog6f diff --git a/addons/ursc/spatial/flat_sky.gdshader b/addons/ursc/spatial/flat_sky.gdshader new file mode 100644 index 0000000..f772578 --- /dev/null +++ b/addons/ursc/spatial/flat_sky.gdshader @@ -0,0 +1,75 @@ +shader_type spatial; +render_mode unshaded; + +global uniform bool texture_filtering; + +uniform sampler2D albedo_texture : source_color, filter_nearest, repeat_enable; +uniform vec2 uv_offset = vec2(0.0); +uniform vec2 uv_scale = vec2(1.0); +uniform vec2 uv_scroll_speed = vec2(0.0); + +vec4 albedoTextureFiltered(vec2 uv) +{ + vec2 albedo_texture_size = vec2(textureSize(albedo_texture, 0)); + + vec2 tex_pix_a = vec2(1.0 / albedo_texture_size.x, 0.0); + vec2 tex_pix_b = vec2(0.0, 1.0 / albedo_texture_size.y); + vec2 tex_pix_c = vec2(tex_pix_a.x,tex_pix_b.y); + vec2 half_tex = vec2(tex_pix_a.x * 0.5, tex_pix_b.y * 0.5); + vec2 uv_centered = uv - half_tex; + + vec4 diffuse_color = texture(albedo_texture, uv_centered); + vec4 sample_a = texture(albedo_texture, uv_centered + tex_pix_a); + vec4 sample_b = texture(albedo_texture, uv_centered + tex_pix_b); + vec4 sample_c = texture(albedo_texture, uv_centered + tex_pix_c); + + float interp_x = modf(uv_centered.x * albedo_texture_size.x, albedo_texture_size.x); + float interp_y = modf(uv_centered.y * albedo_texture_size.y, albedo_texture_size.y); + + if (uv_centered.x < 0.0) + { + interp_x = 1.0 - interp_x * -1.0; + } + if (uv_centered.y < 0.0) + { + interp_y = 1.0 - interp_y * -1.0; + } + + diffuse_color = ( + diffuse_color + + interp_x * (sample_a - diffuse_color) + + interp_y * (sample_b - diffuse_color)) * + (1.0 - step(1.0, interp_x + interp_y)); + + diffuse_color += ( + (sample_c + (1.0 - interp_x) * (sample_b - sample_c) + + (1.0 - interp_y) * (sample_a - sample_c)) * + step(1.0, interp_x + interp_y)); + + return diffuse_color; +} + +void fragment() +{ + float y = atan(VIEW_MATRIX[0][2], VIEW_MATRIX[2][2]); + float x = asin(VIEW_MATRIX[1][2]); + + vec2 bg_coordinates = (vec2(y * 0.5, -x) * -(1.0 / PI)) + 0.5; + bg_coordinates.y *= 0.5; + + vec2 bg_scale; + + bg_scale.y = 0.5; + + vec2 albedo_texture_size = vec2(textureSize(albedo_texture, 0)); + float aspect_ratio = albedo_texture_size.x / albedo_texture_size.y; + bg_scale.x = VIEWPORT_SIZE.x / (VIEWPORT_SIZE.y * aspect_ratio) * bg_scale.y; + + vec2 uv = ( + SCREEN_UV * uv_scale + uv_offset + (uv_scroll_speed * TIME)) * bg_scale + bg_coordinates; + + if (texture_filtering) + ALBEDO = albedoTextureFiltered(uv).rgb; + else + ALBEDO = texture(albedo_texture, uv).rgb; +} diff --git a/addons/ursc/spatial/flat_sky.gdshader.uid b/addons/ursc/spatial/flat_sky.gdshader.uid new file mode 100644 index 0000000..2999456 --- /dev/null +++ b/addons/ursc/spatial/flat_sky.gdshader.uid @@ -0,0 +1 @@ +uid://c88sf1hj81kht diff --git a/addons/ursc/spatial/metallic/metallic_opaque.gdshader b/addons/ursc/spatial/metallic/metallic_opaque.gdshader new file mode 100644 index 0000000..091c4ab --- /dev/null +++ b/addons/ursc/spatial/metallic/metallic_opaque.gdshader @@ -0,0 +1,5 @@ +shader_type spatial; + +#define TEXTURE_METAL + +#include "../common.gdshaderinc" diff --git a/addons/ursc/spatial/metallic/metallic_opaque.gdshader.uid b/addons/ursc/spatial/metallic/metallic_opaque.gdshader.uid new file mode 100644 index 0000000..2a99015 --- /dev/null +++ b/addons/ursc/spatial/metallic/metallic_opaque.gdshader.uid @@ -0,0 +1 @@ +uid://b4l886ta0rjdp diff --git a/addons/ursc/spatial/metallic/metallic_transparent.gdshader b/addons/ursc/spatial/metallic/metallic_transparent.gdshader new file mode 100644 index 0000000..296894d --- /dev/null +++ b/addons/ursc/spatial/metallic/metallic_transparent.gdshader @@ -0,0 +1,6 @@ +shader_type spatial; + +#define ALPHA_BLEND +#define TEXTURE_METAL + +#include "../common.gdshaderinc" diff --git a/addons/ursc/spatial/metallic/metallic_transparent.gdshader.uid b/addons/ursc/spatial/metallic/metallic_transparent.gdshader.uid new file mode 100644 index 0000000..51c0c57 --- /dev/null +++ b/addons/ursc/spatial/metallic/metallic_transparent.gdshader.uid @@ -0,0 +1 @@ +uid://c853r62gglbbm diff --git a/addons/ursc/spatial/shiny/shiny_opaque.gdshader b/addons/ursc/spatial/shiny/shiny_opaque.gdshader new file mode 100644 index 0000000..ddf0b9f --- /dev/null +++ b/addons/ursc/spatial/shiny/shiny_opaque.gdshader @@ -0,0 +1,5 @@ +shader_type spatial; + +#define SHINY + +#include "../common.gdshaderinc" diff --git a/addons/ursc/spatial/shiny/shiny_opaque.gdshader.uid b/addons/ursc/spatial/shiny/shiny_opaque.gdshader.uid new file mode 100644 index 0000000..c723b58 --- /dev/null +++ b/addons/ursc/spatial/shiny/shiny_opaque.gdshader.uid @@ -0,0 +1 @@ +uid://dlg654exoipq5 diff --git a/addons/ursc/spatial/shiny/shiny_transparent.gdshader b/addons/ursc/spatial/shiny/shiny_transparent.gdshader new file mode 100644 index 0000000..b3a7b94 --- /dev/null +++ b/addons/ursc/spatial/shiny/shiny_transparent.gdshader @@ -0,0 +1,6 @@ +shader_type spatial; + +#define ALPHA_BLEND +#define SHINY + +#include "../common.gdshaderinc" diff --git a/addons/ursc/spatial/shiny/shiny_transparent.gdshader.uid b/addons/ursc/spatial/shiny/shiny_transparent.gdshader.uid new file mode 100644 index 0000000..b75adc0 --- /dev/null +++ b/addons/ursc/spatial/shiny/shiny_transparent.gdshader.uid @@ -0,0 +1 @@ +uid://ipo25ngjmpic diff --git a/addons/ursc/spatial/sprite/sprite_shaded.gdshader b/addons/ursc/spatial/sprite/sprite_shaded.gdshader new file mode 100644 index 0000000..e58a1e0 --- /dev/null +++ b/addons/ursc/spatial/sprite/sprite_shaded.gdshader @@ -0,0 +1,6 @@ +shader_type spatial; + +#define ALPHA_SCISSOR +#define BILLBOARD + +#include "../common.gdshaderinc" diff --git a/addons/ursc/spatial/sprite/sprite_shaded.gdshader.uid b/addons/ursc/spatial/sprite/sprite_shaded.gdshader.uid new file mode 100644 index 0000000..3c4e36e --- /dev/null +++ b/addons/ursc/spatial/sprite/sprite_shaded.gdshader.uid @@ -0,0 +1 @@ +uid://4be5clun5m8u diff --git a/addons/ursc/spatial/sprite/sprite_shaded_double_sided.gdshader b/addons/ursc/spatial/sprite/sprite_shaded_double_sided.gdshader new file mode 100644 index 0000000..51d833e --- /dev/null +++ b/addons/ursc/spatial/sprite/sprite_shaded_double_sided.gdshader @@ -0,0 +1,7 @@ +shader_type spatial; + +#define CULL_MODE cull_disabled +#define ALPHA_SCISSOR +#define BILLBOARD + +#include "../common.gdshaderinc" diff --git a/addons/ursc/spatial/sprite/sprite_shaded_double_sided.gdshader.uid b/addons/ursc/spatial/sprite/sprite_shaded_double_sided.gdshader.uid new file mode 100644 index 0000000..d59e116 --- /dev/null +++ b/addons/ursc/spatial/sprite/sprite_shaded_double_sided.gdshader.uid @@ -0,0 +1 @@ +uid://dxuve6vg6fc4p diff --git a/addons/ursc/spatial/sprite/sprite_unshaded.gdshader b/addons/ursc/spatial/sprite/sprite_unshaded.gdshader new file mode 100644 index 0000000..40811bd --- /dev/null +++ b/addons/ursc/spatial/sprite/sprite_unshaded.gdshader @@ -0,0 +1,7 @@ +shader_type spatial; + +#define UNSHADED +#define ALPHA_SCISSOR +#define BILLBOARD + +#include "../common.gdshaderinc" diff --git a/addons/ursc/spatial/sprite/sprite_unshaded.gdshader.uid b/addons/ursc/spatial/sprite/sprite_unshaded.gdshader.uid new file mode 100644 index 0000000..7289ee3 --- /dev/null +++ b/addons/ursc/spatial/sprite/sprite_unshaded.gdshader.uid @@ -0,0 +1 @@ +uid://1neaiyfdu7ut diff --git a/addons/ursc/spatial/sprite/sprite_unshaded_double_sided.gdshader b/addons/ursc/spatial/sprite/sprite_unshaded_double_sided.gdshader new file mode 100644 index 0000000..4e05ea8 --- /dev/null +++ b/addons/ursc/spatial/sprite/sprite_unshaded_double_sided.gdshader @@ -0,0 +1,8 @@ +shader_type spatial; + +#define CULL_MODE cull_disabled +#define UNSHADED +#define ALPHA_SCISSOR +#define BILLBOARD + +#include "../common.gdshaderinc" diff --git a/addons/ursc/spatial/sprite/sprite_unshaded_double_sided.gdshader.uid b/addons/ursc/spatial/sprite/sprite_unshaded_double_sided.gdshader.uid new file mode 100644 index 0000000..3b6f7da --- /dev/null +++ b/addons/ursc/spatial/sprite/sprite_unshaded_double_sided.gdshader.uid @@ -0,0 +1 @@ +uid://duicthd3qgb7b diff --git a/addons/ursc/spatial/standard/standard_opaque.gdshader b/addons/ursc/spatial/standard/standard_opaque.gdshader new file mode 100644 index 0000000..46be047 --- /dev/null +++ b/addons/ursc/spatial/standard/standard_opaque.gdshader @@ -0,0 +1,3 @@ +shader_type spatial; + +#include "../common.gdshaderinc" diff --git a/addons/ursc/spatial/standard/standard_opaque.gdshader.uid b/addons/ursc/spatial/standard/standard_opaque.gdshader.uid new file mode 100644 index 0000000..86f25ea --- /dev/null +++ b/addons/ursc/spatial/standard/standard_opaque.gdshader.uid @@ -0,0 +1 @@ +uid://dtuqc6id5o0x5 diff --git a/addons/ursc/spatial/standard/standard_opaque_repeating.gdshader b/addons/ursc/spatial/standard/standard_opaque_repeating.gdshader new file mode 100644 index 0000000..4453d60 --- /dev/null +++ b/addons/ursc/spatial/standard/standard_opaque_repeating.gdshader @@ -0,0 +1,5 @@ +shader_type spatial; + +#define TEXTURE_REPEAT + +#include "../common.gdshaderinc" diff --git a/addons/ursc/spatial/standard/standard_opaque_repeating.gdshader.uid b/addons/ursc/spatial/standard/standard_opaque_repeating.gdshader.uid new file mode 100644 index 0000000..d8ddda1 --- /dev/null +++ b/addons/ursc/spatial/standard/standard_opaque_repeating.gdshader.uid @@ -0,0 +1 @@ +uid://cn7jla5mlv1su diff --git a/addons/ursc/spatial/standard/standard_transparent.gdshader b/addons/ursc/spatial/standard/standard_transparent.gdshader new file mode 100644 index 0000000..ab32d75 --- /dev/null +++ b/addons/ursc/spatial/standard/standard_transparent.gdshader @@ -0,0 +1,5 @@ +shader_type spatial; + +#define ALPHA_BLEND + +#include "../common.gdshaderinc" diff --git a/addons/ursc/spatial/standard/standard_transparent.gdshader.uid b/addons/ursc/spatial/standard/standard_transparent.gdshader.uid new file mode 100644 index 0000000..7480a5e --- /dev/null +++ b/addons/ursc/spatial/standard/standard_transparent.gdshader.uid @@ -0,0 +1 @@ +uid://dvwme6nvxkt0s diff --git a/addons/ursc/spatial/standard/standard_transparent_repeating.gdshader b/addons/ursc/spatial/standard/standard_transparent_repeating.gdshader new file mode 100644 index 0000000..ab32d75 --- /dev/null +++ b/addons/ursc/spatial/standard/standard_transparent_repeating.gdshader @@ -0,0 +1,5 @@ +shader_type spatial; + +#define ALPHA_BLEND + +#include "../common.gdshaderinc" diff --git a/addons/ursc/spatial/standard/standard_transparent_repeating.gdshader.uid b/addons/ursc/spatial/standard/standard_transparent_repeating.gdshader.uid new file mode 100644 index 0000000..d4a0e8f --- /dev/null +++ b/addons/ursc/spatial/standard/standard_transparent_repeating.gdshader.uid @@ -0,0 +1 @@ +uid://cds0mc1ak2cua