Skip to content

Commit

Permalink
temp: shaders ...
Browse files Browse the repository at this point in the history
  • Loading branch information
akorzunin committed Sep 18, 2024
1 parent 9430c2a commit d79f029
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 9 deletions.
Binary file not shown.
28 changes: 28 additions & 0 deletions notes/shaders/base.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Read texture from image

```glsl
uniform sampler2D TEXTURE;
void freagment() {
vec4 my_texture = texture(TEXTURE, UV);
ALBEDO = my_texture.rgb;
}
```

## Retain color in a next pass shader

```glsl
uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest;
void freagment() {
vec4 currentColor = textureLod(screen_texture, SCREEN_UV, 0.0);
ALBEDO = currentColor.rgb;
}
```

## Smoothstep

https://godotshaders.com/snippet/interpolation/
https://thebookofshaders.com/glossary/?search=Smoothstep
2 changes: 1 addition & 1 deletion src/components/controls/MenuControls.gd
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func call_menu_action():
controlledNode,
{
items = LevelPatterns.get_menu_levels(
clampi(G.settings.MAX_LEVEL, 0, LevelPatterns.levels.size - 1)
clampi(G.settings.MAX_LEVEL, 0, LevelPatterns.levels.size() - 1)
)
}
)
Expand Down
17 changes: 13 additions & 4 deletions src/models/icosahedron/Icosahedron.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=19 format=3 uid="uid://c28nbcejwepp8"]
[gd_scene load_steps=20 format=3 uid="uid://c28nbcejwepp8"]

[ext_resource type="ArrayMesh" uid="uid://dh3qpoqqgdct5" path="res://src/models/icosahedron/assets/icosahedron_Solid.res" id="1_kd7xu"]
[ext_resource type="Script" path="res://src/models/icosahedron/components/Icosahedron.gd" id="1_w7qn7"]
Expand All @@ -11,6 +11,7 @@
[ext_resource type="Shader" path="res://src/models/icosahedron/shaders/outline_v1.gdshader" id="5_ucsrc1"]
[ext_resource type="Texture2D" uid="uid://bpr01fnnfusau" path="res://src/models/icosahedron/resources/edge_noise.res" id="6_ai0t7"]
[ext_resource type="Script" path="res://src/models/icosahedron/components/Collider.gd" id="7_6oydw"]
[ext_resource type="Texture2D" uid="uid://cixi1rd0a28e4" path="res://assets/build/textures/texture-test-v1.png" id="8_h5ail"]

[sub_resource type="ShaderMaterial" id="ShaderMaterial_rdyh1"]
render_priority = 0
Expand All @@ -34,9 +35,9 @@ shader_parameter/noise_pattern = ExtResource("6_ai0t7")
render_priority = 2
next_pass = SubResource("ShaderMaterial_4yeiy")
shader = ExtResource("5_ucsrc1")
shader_parameter/enable = true
shader_parameter/outline_thickness = 0.05
shader_parameter/color = Color(0.358796, 0.73469, 0.907072, 1)
shader_parameter/enable = false
shader_parameter/outline_thickness = 0.11
shader_parameter/color = Color(0, 1, 0, 1)

[sub_resource type="ShaderMaterial" id="ShaderMaterial_c0lt3"]
render_priority = 1
Expand All @@ -46,6 +47,14 @@ shader_parameter/cutplane = Vector4(-0.577, -0.577, 0.577, 0.794)
shader_parameter/color = Color(0, 1, 0, 1)
shader_parameter/enable = true
shader_parameter/outline_thickness = 0.0
shader_parameter/uv_offset_x = 0.17
shader_parameter/uv_offset_y = 2.71
shader_parameter/ratio = 0.075
shader_parameter/power = 2.775
shader_parameter/time_speed = 3.61
shader_parameter/max_speed = 90.0
shader_parameter/uv_rot = Vector2(0.11, 0.375)
shader_parameter/cutlane_tex = ExtResource("8_h5ail")

[sub_resource type="ShaderMaterial" id="ShaderMaterial_bjqtf"]
render_priority = 0
Expand Down
45 changes: 44 additions & 1 deletion src/models/icosahedron/shaders/cutplane_effect_v2.gdshader
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,35 @@ uniform float outline_thickness = 0.0; // how thick is the outline?

varying vec3 ver;

uniform sampler2D cutlane_tex;

uniform float uv_offset_x = 0.;
uniform float uv_offset_y = 0.;

uniform float ratio : hint_range(0.0, 1.0) = 0.1;

uniform float power = 3.0;

uniform float time_speed = 10.0;

uniform float max_speed = 90.0;

uniform vec2 uv_rot;

vec2 rotate(vec2 uv, vec2 pivot, float angle) {
// clang-format off
mat2 rotation = mat2(
vec2(sin(angle), -cos(angle)),
vec2(cos(angle), sin(angle)),
);
// clang-format on

uv -= pivot;
uv = uv * rotation;
uv += pivot;
return uv;
}

void vertex() {
if (enable) {
// VERTEX += NORMAL * outline_thickness; // apply the outlines thickness
Expand All @@ -22,6 +51,18 @@ void vertex() {
}

void fragment() {
vec2 uv = UV;

uv *= 2.0;
uv -= vec2(1.0);

float len = length(uv);

vec2 modified_uv = rotate(UV, uv_rot, TIME * time_speed);
float t = sin(TIME);
modified_uv.x += uv_offset_x;
modified_uv.y += uv_offset_y;
vec4 aaa = texture(cutlane_tex, modified_uv * 5.);
if (enable) {
float dist = cutplane_dist(cutplane, ver);
bool a = dist > 0.;
Expand All @@ -33,7 +74,9 @@ void fragment() {
// ALBEDO = a ? mix(vec3(1. - smoothstep(0.51, 0.9, r_sq) * 1.), color,
// 0.01) : vec3(0.); ALBEDO = a ? vec3(smoothstep(0.58, 0.9, r_sq)) :
// vec3(0.);
ALBEDO = color;
// vec2 rotated_uv = rotate(UV, vec2(0.5), TIME);
// ALBEDO = vec3(rotated_uv.g);
ALBEDO = color * (1. - vec3(aaa.a));
ALPHA = a ? 0.7 : 0.;

} else {
Expand Down
9 changes: 6 additions & 3 deletions src/models/icosahedron/shaders/outline_v1.gdshader
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
shader_type spatial;
render_mode unshaded, cull_front;
render_mode cull_front, unshaded;

uniform bool enable = false;

Expand All @@ -8,15 +8,18 @@ uniform sampler2D screen_texture : hint_screen_texture,
filter_nearest;

// outline costumization
uniform float outline_thickness = 0.05;
uniform vec4 color : source_color = vec4(0.0);
uniform float outline_thickness = 0.11;
uniform vec4 color : source_color = vec4(0., 1., 0., 1.);

// pulse customization
uniform float pulse_speed = 12.;
uniform float pulse_amplitude = 2.;

varying vec3 ver;

uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest;
uniform sampler2D outline_tex;

void vertex() {
if (enable) {
float t = sin(TIME * pulse_speed) / pulse_amplitude + 1.;
Expand Down

0 comments on commit d79f029

Please sign in to comment.