Implement dynamic shader selection
This commit is contained in:
parent
45c91bce39
commit
d290d00b12
11 changed files with 252 additions and 12 deletions
|
@ -3,9 +3,9 @@ shader_type canvas_item;
|
|||
|
||||
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
|
||||
|
||||
uniform float chaos : hint_range(0., 32.) = 1.;
|
||||
uniform float radius : hint_range(0., 1.) = 0.5;
|
||||
uniform float attenuation : hint_range(1., 5.) = 2.;
|
||||
uniform float chaos : hint_range(0., 32.) = 15.;
|
||||
uniform float radius : hint_range(0., 1.) = 0.8;
|
||||
uniform float attenuation : hint_range(1., 5.) = 4.;
|
||||
|
||||
varying vec2 amount_r;
|
||||
varying vec2 amount_g;
|
||||
|
|
7
assets/shaders/invert.gdshader
Normal file
7
assets/shaders/invert.gdshader
Normal file
|
@ -0,0 +1,7 @@
|
|||
shader_type canvas_item;
|
||||
|
||||
void fragment() {
|
||||
vec3 new_color = texture(TEXTURE, SCREEN_UV, 0.0).rgb;
|
||||
new_color = vec3(1.0) - new_color;
|
||||
COLOR.rgb = new_color;
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
shader_type canvas_item;
|
||||
|
||||
uniform int x_pixel_size : hint_range(1, 100);
|
||||
uniform int y_pixel_size : hint_range(1, 100);
|
||||
uniform int x_pixel_size : hint_range(1, 100) = 3;
|
||||
uniform int y_pixel_size : hint_range(1, 100) = 1;
|
||||
|
||||
void fragment() {
|
||||
vec2 correction = TEXTURE_PIXEL_SIZE * vec2(float(x_pixel_size), float(y_pixel_size)) / vec2(2.0);
|
||||
|
|
28
assets/shaders/pixelsort.gdshader
Normal file
28
assets/shaders/pixelsort.gdshader
Normal file
|
@ -0,0 +1,28 @@
|
|||
//MADE BY : @ahopness
|
||||
//LICENSE : CC0
|
||||
//COMATIBLE WITH : GLES2, GLES3, WEBGL
|
||||
|
||||
shader_type canvas_item;
|
||||
|
||||
|
||||
uniform float sort :hint_range(0.0, 2.6)= .5;
|
||||
|
||||
void fragment(){
|
||||
vec2 uv = FRAGCOORD.xy / (1.0 / SCREEN_PIXEL_SIZE).xy;
|
||||
|
||||
// Pseudo Pixel Sorting
|
||||
float sortThreshold = 1.0 - clamp(sort / 2.6, 0.0, 1.0);
|
||||
vec2 sortUv = vec2(uv.x, sortThreshold);
|
||||
|
||||
// Curved melting transition
|
||||
vec2 transitionUV = uv;
|
||||
transitionUV.y += pow(sort, 2.0 + (sort * 2.0)) * uv.x * fract(sin(dot(vec2(transitionUV.x), vec2(12.9, 78.2)))* 437.5);
|
||||
COLOR = texture(TEXTURE, transitionUV);
|
||||
|
||||
// Draw pixel sorting effect behind the melting transition
|
||||
if(transitionUV.y > 1.){
|
||||
COLOR = texture(TEXTURE, sortUv);
|
||||
}else{
|
||||
COLOR = texture(TEXTURE, uv);
|
||||
}
|
||||
}
|
44
assets/shaders/random-pool/cromatic-abberation.gdshader
Normal file
44
assets/shaders/random-pool/cromatic-abberation.gdshader
Normal file
|
@ -0,0 +1,44 @@
|
|||
//shader by CasualGarageCoder, updated to Godot 4
|
||||
shader_type canvas_item;
|
||||
|
||||
uniform sampler2D SCREEN_TEXTURE : hint_screen_texture, filter_linear_mipmap;
|
||||
|
||||
uniform float chaos : hint_range(0., 32.) = 15.;
|
||||
uniform float radius : hint_range(0., 1.) = 0.8;
|
||||
uniform float attenuation : hint_range(1., 5.) = 4.;
|
||||
|
||||
varying vec2 amount_r;
|
||||
varying vec2 amount_g;
|
||||
varying vec2 amount_b;
|
||||
|
||||
float rand(vec2 co){
|
||||
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453) - .5;
|
||||
}
|
||||
|
||||
void vertex() {
|
||||
vec2 shifted_uv = (UV * 2.) - 1.;
|
||||
amount_r = normalize(
|
||||
vec2(rand(TIME * 1.3 * shifted_uv),
|
||||
rand(TIME * 1.64 * shifted_uv)));
|
||||
amount_g = normalize(
|
||||
vec2(rand(TIME * 1.5 * shifted_uv),
|
||||
rand(TIME * 1.7 * shifted_uv)));
|
||||
amount_b = normalize(
|
||||
vec2(rand(TIME * 1.17 * shifted_uv),
|
||||
rand(TIME * 1.23 * shifted_uv)));
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
vec2 chaos_v = vec2(chaos, -chaos) * SCREEN_PIXEL_SIZE;
|
||||
|
||||
float dist = length((UV - vec2(0.5)) * 2.);
|
||||
float att = clamp(dist / radius, 0., 1.);
|
||||
|
||||
chaos_v *= 1. - pow(att, attenuation);
|
||||
|
||||
COLOR = vec4(
|
||||
texture(TEXTURE, SCREEN_UV + chaos_v * amount_r).r,
|
||||
texture(TEXTURE, SCREEN_UV + chaos_v * amount_g).g,
|
||||
texture(TEXTURE, SCREEN_UV + chaos_v * amount_b).b,
|
||||
1.);
|
||||
}
|
7
assets/shaders/random-pool/invert.gdshader
Normal file
7
assets/shaders/random-pool/invert.gdshader
Normal file
|
@ -0,0 +1,7 @@
|
|||
shader_type canvas_item;
|
||||
|
||||
void fragment() {
|
||||
vec3 new_color = texture(TEXTURE, SCREEN_UV, 0.0).rgb;
|
||||
new_color = vec3(1.0) - new_color;
|
||||
COLOR.rgb = new_color;
|
||||
}
|
57
assets/shaders/random-pool/kaleidoscope.gdshader
Normal file
57
assets/shaders/random-pool/kaleidoscope.gdshader
Normal file
|
@ -0,0 +1,57 @@
|
|||
shader_type canvas_item;
|
||||
|
||||
|
||||
group_uniforms segments;
|
||||
uniform float segments: hint_range(2.0, 48.0, 1.0) = 6.0;
|
||||
uniform bool segmentReflect = true;
|
||||
group_uniforms;
|
||||
group_uniforms polar;
|
||||
uniform vec2 polarOffset = vec2(0.5, 0.5);
|
||||
uniform float polarAngle: hint_range(0.0, 360.0) = 0.0;
|
||||
group_uniforms;
|
||||
group_uniforms source;
|
||||
uniform vec2 sourceOffset = vec2(0.5, 0.5);
|
||||
uniform float sourceScale = 2.0;
|
||||
uniform float sourceAngle: hint_range(0.0, 360.0) = 0.0;
|
||||
group_uniforms;
|
||||
|
||||
|
||||
vec2 simpleRotate(vec2 uv, float rotation) {
|
||||
return vec2(
|
||||
cos(rotation) * uv.x + sin(rotation) * uv.y,
|
||||
cos(rotation) * uv.y - sin(rotation) * uv.x
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
vec2 kaleid(vec2 uv, float addAngle, vec2 origin, float segCount, bool doReflect) {
|
||||
|
||||
uv -= origin;
|
||||
float radius = sqrt(dot(uv, uv));
|
||||
float angle = atan(uv.y, uv.x) + addAngle;
|
||||
|
||||
float segmentAngle = TAU / segCount;
|
||||
angle -= segmentAngle * floor(angle / segmentAngle);
|
||||
|
||||
if (doReflect) {
|
||||
angle = min(angle, segmentAngle - angle);
|
||||
}
|
||||
|
||||
return vec2(cos(angle), sin(angle)) * radius;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void fragment() {
|
||||
|
||||
vec2 newUV = kaleid(UV, radians(polarAngle), polarOffset, segments, segmentReflect);
|
||||
|
||||
newUV = simpleRotate(newUV, radians(sourceAngle));
|
||||
newUV += sourceOffset;
|
||||
newUV *= sourceScale;
|
||||
|
||||
vec4 finalColor = texture(TEXTURE, fract(newUV * sourceScale - sourceOffset));
|
||||
|
||||
COLOR = finalColor;
|
||||
|
||||
}
|
12
assets/shaders/random-pool/pixelate.gdshader
Normal file
12
assets/shaders/random-pool/pixelate.gdshader
Normal file
|
@ -0,0 +1,12 @@
|
|||
shader_type canvas_item;
|
||||
|
||||
uniform int x_pixel_size : hint_range(1, 100) = 3;
|
||||
uniform int y_pixel_size : hint_range(1, 100) = 1;
|
||||
|
||||
void fragment() {
|
||||
vec2 correction = TEXTURE_PIXEL_SIZE * vec2(float(x_pixel_size), float(y_pixel_size)) / vec2(2.0);
|
||||
vec2 texture_uv = floor(UV / TEXTURE_PIXEL_SIZE);
|
||||
vec2 offset = vec2(float(int(texture_uv.x) % x_pixel_size), float(int(texture_uv.y) % y_pixel_size));
|
||||
vec2 target = (texture_uv - offset) * TEXTURE_PIXEL_SIZE;
|
||||
COLOR = texture(TEXTURE, target + correction );
|
||||
}
|
28
assets/shaders/random-pool/pixelsort.gdshader
Normal file
28
assets/shaders/random-pool/pixelsort.gdshader
Normal file
|
@ -0,0 +1,28 @@
|
|||
//MADE BY : @ahopness
|
||||
//LICENSE : CC0
|
||||
//COMATIBLE WITH : GLES2, GLES3, WEBGL
|
||||
|
||||
shader_type canvas_item;
|
||||
|
||||
|
||||
uniform float sort :hint_range(0.0, 2.6)= .5;
|
||||
|
||||
void fragment(){
|
||||
vec2 uv = FRAGCOORD.xy / (1.0 / SCREEN_PIXEL_SIZE).xy;
|
||||
|
||||
// Pseudo Pixel Sorting
|
||||
float sortThreshold = 1.0 - clamp(sort / 2.6, 0.0, 1.0);
|
||||
vec2 sortUv = vec2(uv.x, sortThreshold);
|
||||
|
||||
// Curved melting transition
|
||||
vec2 transitionUV = uv;
|
||||
transitionUV.y += pow(sort, 2.0 + (sort * 2.0)) * uv.x * fract(sin(dot(vec2(transitionUV.x), vec2(12.9, 78.2)))* 437.5);
|
||||
COLOR = texture(TEXTURE, transitionUV);
|
||||
|
||||
// Draw pixel sorting effect behind the melting transition
|
||||
if(transitionUV.y > 1.){
|
||||
COLOR = texture(TEXTURE, sortUv);
|
||||
}else{
|
||||
COLOR = texture(TEXTURE, uv);
|
||||
}
|
||||
}
|
|
@ -1,14 +1,70 @@
|
|||
[gd_scene load_steps=22 format=3 uid="uid://b761uk7sjprrp"]
|
||||
[gd_scene load_steps=23 format=3 uid="uid://b761uk7sjprrp"]
|
||||
|
||||
[ext_resource type="Shader" path="res://assets/shaders/kaleidoscope.gdshader" id="1_nwvg1"]
|
||||
[ext_resource type="PackedScene" uid="uid://qehbjfkqs5pl" path="res://entities/ParticlesCool.tscn" id="1_yc1r8"]
|
||||
[ext_resource type="PackedScene" uid="uid://br7cnj1spc4rk" path="res://assets/auto_scale.tscn" id="2_7v8f2"]
|
||||
[ext_resource type="Shader" path="res://assets/shaders/pixelate.gdshader" id="4_lvys8"]
|
||||
[ext_resource type="Shader" path="res://assets/shaders/pixelsort.gdshader" id="4_v65hu"]
|
||||
[ext_resource type="Shader" path="res://assets/shaders/cromatic-abberation.gdshader" id="5_w16wy"]
|
||||
|
||||
[sub_resource type="GDScript" id="GDScript_mtsk5"]
|
||||
script/source = "extends Control
|
||||
|
||||
@onready var pass3: TextureRect = $RandomPasses/Pass3/TextureRect;
|
||||
@onready var pass2: TextureRect = $RandomPasses/Pass2/TextureRect;
|
||||
@onready var pass1: TextureRect = $RandomPasses/Pass1/TextureRect;
|
||||
|
||||
var materials: Array[ShaderMaterial];
|
||||
|
||||
var shaders: Array[Shader];
|
||||
|
||||
func _ready() -> void:
|
||||
#TODO: FIX RNG SO IT FEELS LESS RANDOM, SO WE DON'T GET THE EXACT SAME SHOW EVERY TIME WE RUN
|
||||
|
||||
var shader_dir: DirAccess = DirAccess.open(\"res://assets/shaders/random-pool\");
|
||||
shader_dir.list_dir_begin()
|
||||
for file: String in shader_dir.get_files():
|
||||
# These should probably be preloaded, but who the fuck cares, the demoparty is in 2 days I don't have time for this
|
||||
var shader: Shader = load(shader_dir.get_current_dir() + \"/\" + file);
|
||||
shader.set_meta(\"shader_name\", file.split(\".gdshader\", false))
|
||||
shaders.push_back(shader);
|
||||
|
||||
for i: int in 3:
|
||||
var material: ShaderMaterial = ShaderMaterial.new();
|
||||
var shader: Shader = shaders.pick_random();
|
||||
material.shader = shader.duplicate();
|
||||
|
||||
var shader_name: String = \"\".join(shader.get_meta(\"shader_name\"));
|
||||
|
||||
print(shader.get_meta(\"shader_name\"))
|
||||
match shader_name:
|
||||
\"pixelate\":
|
||||
print(\"pixelate\")
|
||||
material.set_shader_parameter(\"x_pixel_size\", randi_range(1, 5));
|
||||
material.set_shader_parameter(\"y_pixel_size\", randi_range(1, 5));
|
||||
|
||||
\"cromatic-abberation\":
|
||||
print(\"cromatic-abberation\") #Tiiän et täs on typo FFS, en rupee renamaa tiedostoo
|
||||
material.set_shader_parameter(\"chaos\", randf_range(10.0, 32.0));
|
||||
material.set_shader_parameter(\"radius\", randf_range(0.3, 1.0));
|
||||
material.set_shader_parameter(\"attenuation\", randf_range(2.0, 5.0));
|
||||
|
||||
\"kaleidoscope\":
|
||||
print(\"kaleidoscope\")
|
||||
material.set_shader_parameter(\"segments\", float(randi_range(5.0, 8.0)));
|
||||
|
||||
\"pixelsort\":
|
||||
print(\"pixelsort\")
|
||||
material.set_shader_parameter(\"sort\", randf_range(0.1, 2.6));
|
||||
|
||||
_:
|
||||
print(\"something else\")
|
||||
pass
|
||||
|
||||
materials.push_back(material);
|
||||
|
||||
pass1.material = materials[0];
|
||||
pass2.material = materials[1];
|
||||
pass3.material = materials[2];
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
$AnimationPlayer.play(\"kaleidoskope_1\");
|
||||
|
@ -181,9 +237,8 @@ font_size = 104
|
|||
shadow_size = 0
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_riy6b"]
|
||||
shader = ExtResource("4_lvys8")
|
||||
shader_parameter/x_pixel_size = 1
|
||||
shader_parameter/y_pixel_size = 15
|
||||
shader = ExtResource("4_v65hu")
|
||||
shader_parameter/sort = 1.21
|
||||
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_ff16u"]
|
||||
viewport_path = NodePath("KaleidoViewport")
|
||||
|
@ -197,6 +252,8 @@ shader_parameter/attenuation = 1.5
|
|||
[sub_resource type="ViewportTexture" id="ViewportTexture_3bfaj"]
|
||||
viewport_path = NodePath("RandomPasses/Pass1")
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_j7uru"]
|
||||
|
||||
[sub_resource type="ViewportTexture" id="ViewportTexture_rmol4"]
|
||||
viewport_path = NodePath("RandomPasses/Pass2")
|
||||
|
||||
|
@ -319,7 +376,7 @@ texture = SubResource("ViewportTexture_3bfaj")
|
|||
size = Vector2i(1152, 648)
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="RandomPasses/Pass3"]
|
||||
material = SubResource("ShaderMaterial_wyd4s")
|
||||
material = SubResource("ShaderMaterial_j7uru")
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
texture = SubResource("ViewportTexture_rmol4")
|
||||
|
|
Loading…
Reference in a new issue