Skip to content

Instantly share code, notes, and snippets.

@jotson
Created April 15, 2022 15:20
Show Gist options
  • Save jotson/d86543ee2b1b4b615cd8cd53ae6af6fb to your computer and use it in GitHub Desktop.
Save jotson/d86543ee2b1b4b615cd8cd53ae6af6fb to your computer and use it in GitHub Desktop.
Gravity Ace wall texture shader
shader_type canvas_item;
uniform vec2 camera_pos;
uniform vec2 camera_zoom;
uniform vec2 viewport_size;
uniform vec2 viewport_size_override;
uniform sampler2D normal_tex : hint_normal;
uniform sampler2D noise_tex;
uniform bool secret = false;
uniform bool editor = false;
uniform bool reflective = false;
uniform sampler2D reflective_tex;
void fragment() {
vec2 basepx = vec2(1.0/viewport_size.x, 1.0/viewport_size.y); // Fixes texture size at this resolution
vec2 viewport_scale = viewport_size / viewport_size_override;
float aspect = SCREEN_PIXEL_SIZE.y / SCREEN_PIXEL_SIZE.x;
vec2 screenpx = SCREEN_PIXEL_SIZE;
vec2 texpx = TEXTURE_PIXEL_SIZE;
vec2 uv = vec2(0.0);
uv.y = (-FRAGCOORD.y * camera_zoom.y + camera_pos.y * viewport_scale.y) * basepx.y;
uv.x = (FRAGCOORD.x * camera_zoom.x + camera_pos.x * viewport_scale.x) * basepx.x * aspect;
if (secret) {
uv += vec2(0.3, 0.7);
}
float secret_multi = 1.0;
if (editor && secret) {
uv.y += sin(uv.x * 160.0 + TIME * 5.0) * 0.005;
secret_multi = 0.8;
}
vec4 c = texture(TEXTURE, uv);
c *= secret_multi;
if (reflective) {
// Oooh sooooo FANCY!
vec2 reflect_uv = UV * 1.0;
// Based on camera pos
reflect_uv += camera_pos * 0.001;
// Different strata reflect differently
reflect_uv.y += TIME * 0.0 + (c.r + c.g + c.b);
reflect_uv.x += TIME * 0.0 + (c.r + c.g + c.b);
// Add some noise to the UV
vec4 noise_color = textureLod(noise_tex, UV * 3.0, 1.0);
reflect_uv += noise_color.rr * 0.2;
// Get the reflection color
vec4 rt_color = texture(reflective_tex, reflect_uv);
// Multiply it by the wall alpha and make it semi-transparent
c.rgb += rt_color.rgb * c.a * 0.3;
}
COLOR = COLOR * c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment