Skip to content

Commit

Permalink
shader code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruddygreat committed Feb 10, 2025
1 parent bbacc83 commit d2fe964
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 126 deletions.
32 changes: 7 additions & 25 deletions Resources/Textures/_Impstation/Shaders/ammonia_gas_shader.swsl
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand All @@ -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;
}

32 changes: 7 additions & 25 deletions Resources/Textures/_Impstation/Shaders/basic_gas_shader.swsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,21 @@ 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));
COLOR += 0.3 * texture(noise_2, loopVec(rounded));
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;
}

32 changes: 7 additions & 25 deletions Resources/Textures/_Impstation/Shaders/frezon_gas_shader.swsl
Original file line number Diff line number Diff line change
Expand Up @@ -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))));
Expand All @@ -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));
Expand All @@ -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;
}

32 changes: 7 additions & 25 deletions Resources/Textures/_Impstation/Shaders/plasma_gas_shader.swsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,21 @@ 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));
COLOR += 0.3 * texture(noise_2, loopVec(rounded + 0.3)); //tiny offset so it's not identical to other gases
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;
}

26 changes: 0 additions & 26 deletions Resources/Textures/_Impstation/Shaders/tritium_gas_shader.swsl
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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;
}

0 comments on commit d2fe964

Please sign in to comment.