Skip to content

Commit

Permalink
temp: more shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
akorzunin committed Sep 19, 2024
1 parent 8cc79f2 commit c41f22b
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ mono_crash.*.json
*.import
*.blend*
.ansible_vault_password
addons/discord-rpc-gd/bin/windows/~discord_game_sdk_binding_debug.dll
38 changes: 22 additions & 16 deletions src/models/icosahedron/Icosahedron.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
[gd_scene load_steps=20 format=3 uid="uid://c28nbcejwepp8"]
[gd_scene load_steps=19 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"]
[ext_resource type="Shader" path="res://src/models/icosahedron/shaders/cut_plane_shader.gdshader" id="2_u8yhs"]
[ext_resource type="Shader" path="res://src/models/icosahedron/shaders/cutplane_effect_v4.gdshader" id="2_3wk2e"]
[ext_resource type="Script" path="res://src/models/icosahedron/components/CutPlane.gd" id="2_yg3qy"]
[ext_resource type="Shader" path="res://src/models/icosahedron/shaders/edge_highlight_v1.gdshader" id="5_al5e2"]
[ext_resource type="Shader" path="res://src/models/icosahedron/shaders/cutplane_effect_v2.gdshader" id="5_cipg0"]
[ext_resource type="Script" path="res://src/models/icosahedron/components/MeshIcosahedron.gd" id="5_q8b2e"]
[ext_resource type="Shader" path="res://src/models/icosahedron/shaders/icosahedron_shader_v1.gdshader" id="5_s1usq"]
[ext_resource type="Shader" path="res://src/models/icosahedron/shaders/outline_v1.gdshader" id="5_ucsrc1"]
Expand All @@ -15,7 +14,15 @@

[sub_resource type="ShaderMaterial" id="ShaderMaterial_rdyh1"]
render_priority = 0
shader = ExtResource("2_u8yhs")
shader = ExtResource("2_3wk2e")
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.025
shader_parameter/_center = Vector2(0.5, 0.5)
shader_parameter/_zoom = 1.0
shader_parameter/_repeat = 1.0
shader_parameter/_speed = 1.0

[sub_resource type="PlaneMesh" id="PlaneMesh_8mu0u"]

Expand All @@ -36,25 +43,24 @@ render_priority = 2
next_pass = SubResource("ShaderMaterial_4yeiy")
shader = ExtResource("5_ucsrc1")
shader_parameter/enable = false
shader_parameter/outline_thickness = 0.11
shader_parameter/color = Color(0, 1, 0, 1)
shader_parameter/outline_thickness = 0.05
shader_parameter/color = Color(0.358796, 0.73469, 0.907072, 1)
shader_parameter/pulse_speed = 12.0
shader_parameter/pulse_amplitude = 2.0

[sub_resource type="ShaderMaterial" id="ShaderMaterial_c0lt3"]
render_priority = 1
next_pass = SubResource("ShaderMaterial_i83je")
shader = ExtResource("5_cipg0")
shader = ExtResource("2_3wk2e")
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")
shader_parameter/outline_thickness = 0.04
shader_parameter/_center = Vector2(0.11, 0.39)
shader_parameter/_zoom = 2.85
shader_parameter/_repeat = 6.0
shader_parameter/_speed = 0.35
shader_parameter/TEXTURE = ExtResource("8_h5ail")

[sub_resource type="ShaderMaterial" id="ShaderMaterial_bjqtf"]
render_priority = 0
Expand Down
54 changes: 39 additions & 15 deletions src/models/icosahedron/shaders/cutplane_effect_v2.gdshader
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
shader_type spatial;
render_mode cull_front, depth_test_disabled;
render_mode cull_disabled, depth_test_disabled;

#include "cutplane.gdshaderinc"
#include "res://src/shaders/shader_utils.gdshaderinc"
Expand Down Expand Up @@ -33,7 +33,7 @@ vec2 rotate(vec2 uv, vec2 pivot, float angle) {
// clang-format off
mat2 rotation = mat2(
vec2(sin(angle), -cos(angle)),
vec2(cos(angle), sin(angle)),
vec2(cos(angle), sin(angle))
);
// clang-format on

Expand All @@ -43,6 +43,25 @@ vec2 rotate(vec2 uv, vec2 pivot, float angle) {
return uv;
}

uniform vec2 center;
uniform float strength : hint_range(-10, 10);
uniform float speed : hint_range(-10, 10);

vec2 vortex(vec2 uv, vec2 _center, float _strength, float _speed) {
float t = sin(TIME);
vec2 dir = uv - _center;
float dist = length(dir);
//float angle = atan(dir.y * (1. - abs(sin(TIME))), dir.x * abs(sin(TIME)));
float angle = atan(dir.y, dir.x) * 0.4;
//if (angle)
float radius = dist * _strength;
float new_angle = angle + TIME * _speed;

vec2 new_uv = _center + vec2(cos(new_angle), sin(new_angle)) * radius;

return new_uv;
}

void vertex() {
if (enable) {
// VERTEX += NORMAL * outline_thickness; // apply the outlines thickness
Expand All @@ -52,17 +71,21 @@ 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.);
vec2 new_uv = vortex(uv, center, strength, speed);

vec4 tex = texture(cutlane_tex, new_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 @@ -76,8 +99,9 @@ void fragment() {
// vec3(0.);
// 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.;
ALBEDO = color * (1. - vec3(tex.a));
//ALBEDO = vec3(tex.a);
//ALPHA = a ? 0.7 : 0.;

} else {
ALPHA = .0;
Expand Down
68 changes: 68 additions & 0 deletions src/models/icosahedron/shaders/cutplane_effect_v4.gdshader
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
shader_type spatial;
render_mode cull_front, depth_test_disabled, unshaded;

#include "cutplane.gdshaderinc"
#include "res://src/shaders/shader_utils.gdshaderinc"

// to get vac coord a= sin^2(angle), b = sin(angle)*cos(angle)
uniform vec4 cutplane = vec4(-0.577, -0.577, 0.577, 0.794);
uniform vec3 color : source_color = vec3(0.0, 1., 0.);

uniform bool enable = true;
// outline costumization
uniform float outline_thickness = 0.0; // how thick is the outline?

uniform vec2 _center = vec2(0.5);
uniform float _zoom = 1.;
uniform float _repeat = 1.;
uniform float _speed = 1.;

varying vec3 ver;

uniform sampler2D screen_texture : hint_screen_texture, repeat_disable, filter_nearest;

uniform sampler2D TEXTURE;

vec2 polar_coordinates(vec2 uv, vec2 center, float zoom, float repeat)
{
vec2 dir = uv - center;
float radius = length(dir) * 2.0;
float angle = atan(dir.y, dir.x) * 1.0/(3.1416 * 2.0);
return mod(vec2(radius * zoom, angle * repeat), 1.0);
}

void vertex() {
if (enable) {
//VERTEX += BINORMAL * outline_thickness; // apply the outlines thickness
//VERTEX += TANGENT * outline_thickness; // apply the outlines thickness
ver = VERTEX;
}
}

void fragment() {
vec3 albedo_out;
vec2 uv = UV;
//uv.x += fract(TIME / TAU);
vec2 polar_uv = polar_coordinates(uv, _center, _zoom, _repeat);
polar_uv.x += fract(TIME * _speed);
polar_uv.y += sin(TIME /2.);
vec4 my_tex = texture(TEXTURE, polar_uv);
vec4 currentColor = textureLod(screen_texture, SCREEN_UV, 0.0);
if (enable) {
float dist = cutplane_dist(cutplane, ver);
bool a = dist > 0.;
float c = length(ver);
float b = my_tex.a;
//albedo_out = vec3(b);
//albedo_out = vec3(fract(uv*10.), 0.);
//albedo_out = min(currentColor.rgb + vec3(0, b, 0.));
albedo_out = currentColor.rgb + vec3(b, 0., 0.);
ALBEDO = a ? albedo_out : currentColor.rgb;
ALPHA = currentColor.a;
//ALPHA = a ? 1. : 0.01;

} else {
ALBEDO = currentColor.rgb;
//ALPHA = currentColor.a;
}
}
9 changes: 3 additions & 6 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 cull_front, unshaded;
render_mode unshaded, cull_front;

uniform bool enable = false;

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

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

// 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 c41f22b

Please sign in to comment.