Add: simple shaders, following Book of Shaders page 6

This commit is contained in:
2025-10-22 10:50:45 -06:00
parent 9d8b5f6831
commit 80c807475d
6 changed files with 125 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
shader_type canvas_item;
#define TWO_PI 6.28318530718
uniform vec2 resolution = vec2(40,40);
uniform vec2 u_resolution;
uniform float u_time;
// Function from Iñigo Quiles
// https://www.shadertoy.com/view/MsS3Wc
vec3 hsb2rgb( in vec3 c ){
vec3 rgb = clamp(abs(mod(c.x*6.0+vec3(0.0,4.0,2.0),
6.0)-3.0)-1.0,
0.0,
1.0 );
rgb = rgb*rgb*(3.0-2.0*rgb);
return c.z * mix( vec3(1.0), rgb, c.y);
}
void fragment() {
// Called for every pixel the material is visible on.
vec2 st = UV/resolution;
vec3 color = vec3(0.0);
vec2 toCenter = vec2(0.5) - UV;
float angle = pow(atan(toCenter.y, toCenter.x), 1.0);
float radius = length(toCenter)*2.0;
float normHue = (angle/TWO_PI)+0.5;
normHue = pow(normHue, 3.0);
color = hsb2rgb(vec3(normHue,radius,1.0));
COLOR = vec4(color, 1.0);
}
//void light() {
// // Called for every pixel for every light affecting the CanvasItem.
// // Uncomment to replace the default light processing function with this one.
//}

View File

@@ -0,0 +1 @@
uid://b1avd7otwdbqx

View File

@@ -0,0 +1,23 @@
[gd_scene load_steps=3 format=3 uid="uid://dk1hun66hk76t"]
[ext_resource type="Shader" uid="uid://b1avd7otwdbqx" path="res://src/simple_hsb_func/HSBField_polar.gdshader" id="1_y6vnc"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_s1hel"]
shader = ExtResource("1_y6vnc")
shader_parameter/resolution = Vector2(40, 40)
shader_parameter/u_resolution = Vector2(0, 0)
shader_parameter/u_time = 0.0
[node name="HsbField" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="ColorRect" type="ColorRect" parent="."]
material = SubResource("ShaderMaterial_s1hel")
layout_mode = 0
offset_right = 40.0
offset_bottom = 40.0

View File

@@ -0,0 +1,37 @@
shader_type canvas_item;
uniform vec2 u_resolution = vec2(40.0,40.0);
uniform float u_time;
vec3 rgb2hsb( in vec3 c ){
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(c.bg, K.wz),
vec4(c.gb, K.xy),
step(c.b, c.g));
vec4 q = mix(vec4(p.xyw, c.r),
vec4(c.r, p.yzx),
step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)),
d / (q.x + e),
q.x);
}
// Function from Iñigo Quiles
// https://www.shadertoy.com/view/MsS3Wc
vec3 hsb2rgb( in vec3 c ){
vec3 rgb = clamp(abs(mod(c.x*6.0+vec3(0.0,4.0,2.0),
6.0)-3.0)-1.0,
0.0,
1.0 );
rgb = rgb*rgb*(3.0-2.0*rgb);
return c.z * mix(vec3(1.0), rgb, c.y);
}
void fragment() {
vec3 color = vec3(0.0);
color = hsb2rgb(vec3(UV.x, 1.0, UV.y));
COLOR = vec4(color, 1.0);
}

View File

@@ -0,0 +1 @@
uid://res5r3cil0uv

View File

@@ -0,0 +1,22 @@
[gd_scene load_steps=3 format=3 uid="uid://8g28bhlvay61"]
[ext_resource type="Shader" uid="uid://res5r3cil0uv" path="res://src/simple_hsb_func/HSB_Field_non_polar.gdshader" id="1_c8wtv"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_e0bhl"]
shader = ExtResource("1_c8wtv")
shader_parameter/u_resolution = Vector2(0, 0)
shader_parameter/u_time = 0.0
[node name="HsbFieldNonPolar" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="ColorRect" type="ColorRect" parent="."]
material = SubResource("ShaderMaterial_e0bhl")
layout_mode = 0
offset_right = 40.0
offset_bottom = 40.0