From d2fe964c365095b11c47b8609b5e0d7a8b779543 Mon Sep 17 00:00:00 2001 From: Ruddygreat Date: Mon, 10 Feb 2025 18:30:32 +0000 Subject: [PATCH] shader code cleanup --- .../Shaders/ammonia_gas_shader.swsl | 32 ++++--------------- .../_Impstation/Shaders/basic_gas_shader.swsl | 32 ++++--------------- .../Shaders/frezon_gas_shader.swsl | 32 ++++--------------- .../Shaders/plasma_gas_shader.swsl | 32 ++++--------------- .../Shaders/tritium_gas_shader.swsl | 26 --------------- 5 files changed, 28 insertions(+), 126 deletions(-) diff --git a/Resources/Textures/_Impstation/Shaders/ammonia_gas_shader.swsl b/Resources/Textures/_Impstation/Shaders/ammonia_gas_shader.swsl index f09b4d01a200..4748846fb496 100644 --- a/Resources/Textures/_Impstation/Shaders/ammonia_gas_shader.swsl +++ b/Resources/Textures/_Impstation/Shaders/ammonia_gas_shader.swsl @@ -8,9 +8,7 @@ const highp float tileSize = 32.0; void fragment() { - highp float multiple = (1.0 / tileSize); - highp vec2 rem = vec2(mod(UV.x, multiple), mod(UV.y, multiple)); - highp vec2 rounded = UV - rem; //downsample to a 32 * 32 grid for stylistic consistency + highp vec2 rounded = quantiseVecDown(UV, tileSize); //downsample to a 32 * 32 grid for stylistic consistency COLOR = 0.3 * texture(noise_0, loopVec(rounded + TIME * 0.1)); COLOR += 0.3 * texture(noise_0, loopVec(vec2(rounded.x - TIME * 0.1, rounded.y + 0.2 + TIME * 0.1))); @@ -19,29 +17,13 @@ void fragment() { COLOR *= colour; } +highp vec2 quantiseVecDown(highp vec2 v, highp float divisions) { + highp float multiple = 1.0 / divisions; + highp vec2 rem = mod(v, multiple); + return v - rem; +} + //hate that I have to do this because we can't just highp vec2 loopVec(highp vec2 toLoop) { return abs(mod(toLoop, 1));; } - -//copied out from an error.glsl file so that I can actually edit these -//g because gas :) -highp vec2 gRandom(highp vec2 uv){ - uv = vec2( dot(uv, vec2(127.1,311.7) ), - dot(uv, vec2(269.5,183.3) ) ); - return -1.0 + 2.0 * fract(sin(uv) * 43758.5453123); -} - -highp float gNoise(highp vec2 uv) { - - highp vec2 uv_index = floor(uv); - highp vec2 uv_fract = fract(uv); - - highp vec2 blur = uv_fract * uv_fract * (3.0 - 2.0 * uv_fract); - - return mix( mix( dot( gRandom(uv_index + vec2(0.0,0.0) ), uv_fract - vec2(0.0,0.0) ), - dot( gRandom(uv_index + vec2(1.0,0.0) ), uv_fract - vec2(1.0,0.0) ), blur.x), - mix( dot( gRandom(uv_index + vec2(0.0,1.0) ), uv_fract - vec2(0.0,1.0) ), - dot( gRandom(uv_index + vec2(1.0,1.0) ), uv_fract - vec2(1.0,1.0) ), blur.x), blur.y) * 0.5 + 0.5; -} - diff --git a/Resources/Textures/_Impstation/Shaders/basic_gas_shader.swsl b/Resources/Textures/_Impstation/Shaders/basic_gas_shader.swsl index 1f026681d664..b47a7c3a8931 100644 --- a/Resources/Textures/_Impstation/Shaders/basic_gas_shader.swsl +++ b/Resources/Textures/_Impstation/Shaders/basic_gas_shader.swsl @@ -8,9 +8,7 @@ const highp float tileSize = 32.0; void fragment() { - highp float multiple = (1.0 / tileSize); - highp vec2 rem = vec2(mod(UV.x, multiple), mod(UV.y, multiple)); - highp vec2 rounded = UV - rem; //downsample to a 32 * 32 grid for stylistic consistency + highp vec2 rounded = quantiseVecDown(UV, tileSize); //downsample to a 32 * 32 grid for stylistic consistency COLOR = 0.4 * texture(noise_0, loopVec(rounded + TIME * 0.1)); COLOR += 0.3 * texture(noise_1, loopVec(rounded - TIME * 0.1)); @@ -18,29 +16,13 @@ void fragment() { COLOR *= colour; } +highp vec2 quantiseVecDown(highp vec2 v, highp float divisions) { + highp float multiple = 1.0 / divisions; + highp vec2 rem = mod(v, multiple); + return v - rem; +} + //hate that I have to do this because we can't just highp vec2 loopVec(highp vec2 toLoop) { return abs(mod(toLoop, 1));; } - -//copied out from an error.glsl file so that I can actually edit these -//g because gas :) -highp vec2 gRandom(highp vec2 uv){ - uv = vec2( dot(uv, vec2(127.1,311.7) ), - dot(uv, vec2(269.5,183.3) ) ); - return -1.0 + 2.0 * fract(sin(uv) * 43758.5453123); -} - -highp float gNoise(highp vec2 uv) { - - highp vec2 uv_index = floor(uv); - highp vec2 uv_fract = fract(uv); - - highp vec2 blur = uv_fract * uv_fract * (3.0 - 2.0 * uv_fract); - - return mix( mix( dot( gRandom(uv_index + vec2(0.0,0.0) ), uv_fract - vec2(0.0,0.0) ), - dot( gRandom(uv_index + vec2(1.0,0.0) ), uv_fract - vec2(1.0,0.0) ), blur.x), - mix( dot( gRandom(uv_index + vec2(0.0,1.0) ), uv_fract - vec2(0.0,1.0) ), - dot( gRandom(uv_index + vec2(1.0,1.0) ), uv_fract - vec2(1.0,1.0) ), blur.x), blur.y) * 0.5 + 0.5; -} - diff --git a/Resources/Textures/_Impstation/Shaders/frezon_gas_shader.swsl b/Resources/Textures/_Impstation/Shaders/frezon_gas_shader.swsl index 35d4e4bb5fca..717458b0d3fa 100644 --- a/Resources/Textures/_Impstation/Shaders/frezon_gas_shader.swsl +++ b/Resources/Textures/_Impstation/Shaders/frezon_gas_shader.swsl @@ -8,9 +8,7 @@ const highp float tileSize = 32.0; void fragment() { - highp float multiple = (1.0 / tileSize); - highp vec2 rem = vec2(mod(UV.x, multiple), mod(UV.y, multiple)); - highp vec2 rounded = UV - rem; //downsample to a 32 * 32 grid for stylistic consistency + highp vec2 rounded = quantiseVecDown(UV, tileSize); //downsample to a 32 * 32 grid for stylistic consistency //note to self if I want to change things back - was .4, .2, .2, .2 COLOR = 0.25 * texture(noise_0, loopVec(vec2(rounded.x + sin(rounded.y * 4.0 + TIME * 0.1), rounded.y + sin(rounded.x * 4.0 + TIME * 0.1)))); @@ -22,6 +20,12 @@ void fragment() { COLOR.rgb = hsv2rgb(asHSV + vec3(0.0, 0.0, asHSV.z * asHSV.z)); } +highp vec2 quantiseVecDown(highp vec2 v, highp float divisions) { + highp float multiple = 1.0 / divisions; + highp vec2 rem = mod(v, multiple); + return v - rem; +} + //hate that I have to do this because we can't just set the loop behaviour on the texture highp vec2 loopVec(highp vec2 toLoop) { return abs(mod(toLoop, 1)); @@ -42,25 +46,3 @@ highp vec3 hsv2rgb(highp vec3 c) { highp vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); } - -//copied out from an error.glsl file so that I can actually edit these -//g because gas :) -highp vec2 gRandom(highp vec2 uv){ - uv = vec2( dot(uv, vec2(127.1,311.7) ), - dot(uv, vec2(269.5,183.3) ) ); - return -1.0 + 2.0 * fract(sin(uv) * 43758.5453123); -} - -highp float gNoise(highp vec2 uv) { - - highp vec2 uv_index = floor(uv); - highp vec2 uv_fract = fract(uv); - - highp vec2 blur = uv_fract * uv_fract * (3.0 - 2.0 * uv_fract); - - return mix( mix( dot( gRandom(uv_index + vec2(0.0,0.0) ), uv_fract - vec2(0.0,0.0) ), - dot( gRandom(uv_index + vec2(1.0,0.0) ), uv_fract - vec2(1.0,0.0) ), blur.x), - mix( dot( gRandom(uv_index + vec2(0.0,1.0) ), uv_fract - vec2(0.0,1.0) ), - dot( gRandom(uv_index + vec2(1.0,1.0) ), uv_fract - vec2(1.0,1.0) ), blur.x), blur.y) * 0.5 + 0.5; -} - diff --git a/Resources/Textures/_Impstation/Shaders/plasma_gas_shader.swsl b/Resources/Textures/_Impstation/Shaders/plasma_gas_shader.swsl index 5967e9ca3bfc..1c5cd8b78d4f 100644 --- a/Resources/Textures/_Impstation/Shaders/plasma_gas_shader.swsl +++ b/Resources/Textures/_Impstation/Shaders/plasma_gas_shader.swsl @@ -8,9 +8,7 @@ const highp float tileSize = 32.0; void fragment() { - highp float multiple = (1.0 / tileSize); - highp vec2 rem = vec2(mod(UV.x, multiple), mod(UV.y, multiple)); - highp vec2 rounded = UV - rem; //downsample to a 32 * 32 grid for stylistic consistency + highp vec2 rounded = quantiseVecDown(UV, tileSize); //downsample to a 32 * 32 grid for stylistic consistency COLOR = 0.4 * texture(noise_0, loopVec(vec2(rounded.x + sin(rounded.y * 4.0 + TIME * 0.1), rounded.y))); COLOR += 0.3 * texture(noise_1, loopVec(rounded - TIME * 0.1)); @@ -18,29 +16,13 @@ void fragment() { COLOR *= colour; } +highp vec2 quantiseVecDown(highp vec2 v, highp float divisions) { + highp float multiple = 1.0 / divisions; + highp vec2 rem = mod(v, multiple); + return v - rem; +} + //hate that I have to do this because we can't just set the loop behaviour on the texture highp vec2 loopVec(highp vec2 toLoop) { return abs(mod(toLoop, 1)); } - -//copied out from an error.glsl file so that I can actually edit these -//g because gas :) -highp vec2 gRandom(highp vec2 uv){ - uv = vec2( dot(uv, vec2(127.1,311.7) ), - dot(uv, vec2(269.5,183.3) ) ); - return -1.0 + 2.0 * fract(sin(uv) * 43758.5453123); -} - -highp float gNoise(highp vec2 uv) { - - highp vec2 uv_index = floor(uv); - highp vec2 uv_fract = fract(uv); - - highp vec2 blur = uv_fract * uv_fract * (3.0 - 2.0 * uv_fract); - - return mix( mix( dot( gRandom(uv_index + vec2(0.0,0.0) ), uv_fract - vec2(0.0,0.0) ), - dot( gRandom(uv_index + vec2(1.0,0.0) ), uv_fract - vec2(1.0,0.0) ), blur.x), - mix( dot( gRandom(uv_index + vec2(0.0,1.0) ), uv_fract - vec2(0.0,1.0) ), - dot( gRandom(uv_index + vec2(1.0,1.0) ), uv_fract - vec2(1.0,1.0) ), blur.x), blur.y) * 0.5 + 0.5; -} - diff --git a/Resources/Textures/_Impstation/Shaders/tritium_gas_shader.swsl b/Resources/Textures/_Impstation/Shaders/tritium_gas_shader.swsl index 98e77a1f64eb..f98c7116f778 100644 --- a/Resources/Textures/_Impstation/Shaders/tritium_gas_shader.swsl +++ b/Resources/Textures/_Impstation/Shaders/tritium_gas_shader.swsl @@ -8,10 +8,6 @@ const highp float tileSize = 32.0; void fragment() { - //todo : experiment with alpha quantisation like how I done did it with the uvs? - //todo : get a better colour for water vapour - //todo : figure out how to make the brighter spots significantly brighter while leaving darker spots untouched - highp vec2 rounded = quantiseVecDown(UV, tileSize); //downsample to a 32 * 32 grid for stylistic consistency COLOR = 0.25 * texture(noise_0, loopVec(vec2(rounded.x + 0.2 + TIME * 0.3, rounded.y))); @@ -58,25 +54,3 @@ highp vec3 hsv2rgb(highp vec3 c) { highp vec2 loopVec(highp vec2 toLoop) { return abs(mod(toLoop, 1)); } - -//copied out from an error.glsl file so that I can actually edit these -//g because gas :) -highp vec2 gRandom(highp vec2 uv){ - uv = vec2( dot(uv, vec2(127.1,311.7) ), - dot(uv, vec2(269.5,183.3) ) ); - return -1.0 + 2.0 * fract(sin(uv) * 43758.5453123); -} - -highp float gNoise(highp vec2 uv) { - - highp vec2 uv_index = floor(uv); - highp vec2 uv_fract = fract(uv); - - highp vec2 blur = uv_fract * uv_fract * (3.0 - 2.0 * uv_fract); - - return mix( mix( dot( gRandom(uv_index + vec2(0.0,0.0) ), uv_fract - vec2(0.0,0.0) ), - dot( gRandom(uv_index + vec2(1.0,0.0) ), uv_fract - vec2(1.0,0.0) ), blur.x), - mix( dot( gRandom(uv_index + vec2(0.0,1.0) ), uv_fract - vec2(0.0,1.0) ), - dot( gRandom(uv_index + vec2(1.0,1.0) ), uv_fract - vec2(1.0,1.0) ), blur.x), blur.y) * 0.5 + 0.5; -} -