new shaders
This commit is contained in:
parent
c4115b3569
commit
7ada6a0f2c
24 changed files with 567 additions and 124 deletions
51
shaders/010_edge_detection/edge_detection.gdshader
Normal file
51
shaders/010_edge_detection/edge_detection.gdshader
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
shader_type spatial;
|
||||
render_mode unshaded;
|
||||
|
||||
uniform sampler2D SCREEN_TEXTURE: hint_screen_texture, repeat_disable, filter_nearest;
|
||||
|
||||
vec3 convolution(sampler2D tex, vec2 uv, vec2 pixel_size) {
|
||||
vec3 conv = vec3(0.0, 0.0, 0.0);
|
||||
|
||||
for (int row = 0; row < 3; row++) {
|
||||
for (int col = 0; col < 3; col++) {
|
||||
conv += texture(tex, uv + vec2(float(col - 1), float(row - 1)) * pixel_size).rgb;
|
||||
}
|
||||
}
|
||||
|
||||
return conv;
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
// All surrounding pixels
|
||||
vec3 pixels[9];
|
||||
// [0, 1, 2]
|
||||
// [3, 4, 5]
|
||||
// [6, 7, 8]
|
||||
for (int row = 0; row < 3; row++) {
|
||||
for (int col = 0; col < 3; col++) {
|
||||
vec2 uv = SCREEN_UV + vec2(float(col - 1), float(row - 1)) * 1.0 / VIEWPORT_SIZE;// SCREEN_PIXEL_SIZE;
|
||||
pixels[row * 3 + col] = convolution(SCREEN_TEXTURE, uv, 1.0 / VIEWPORT_SIZE); //SCREEN_PIXEL_SIZE);
|
||||
}
|
||||
}
|
||||
|
||||
// Apply Sobel Operator
|
||||
// Sobel Edge Horizontal
|
||||
vec3 gx = (
|
||||
pixels[0] * -1.0 + pixels[3] * -2.0 + pixels[6] * -1.0 +
|
||||
pixels[2] * 1.0 + pixels[5] * 2.0 + pixels[8] * 1.0
|
||||
);
|
||||
|
||||
// Sobel Edge Vertical
|
||||
vec3 gy = (
|
||||
pixels[0] * -1.0 + pixels[1] * -2.0 + pixels[2] * -1.0 +
|
||||
pixels[6] * 1.0 + pixels[7] * 2.0 + pixels[8] * 1.0
|
||||
);
|
||||
|
||||
vec3 sobel = sqrt(gx * gx + gy * gy);
|
||||
|
||||
float alpha = sobel.r + sobel.g + sobel.b;
|
||||
alpha /= 3.0;
|
||||
|
||||
ALPHA = alpha;
|
||||
ALBEDO = sobel;
|
||||
}
|
||||
25
shaders/010_edge_detection/edge_detection.tscn
Normal file
25
shaders/010_edge_detection/edge_detection.tscn
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
[gd_scene load_steps=6 format=3 uid="uid://drgqrnj1otb25"]
|
||||
|
||||
[ext_resource type="Shader" path="res://shaders/010_edge_detection/edge_detection.gdshader" id="1_34hnr"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_vbj21"]
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_wnbfj"]
|
||||
material = SubResource("ShaderMaterial_vbj21")
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_855vq"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("1_34hnr")
|
||||
|
||||
[sub_resource type="QuadMesh" id="QuadMesh_sbqxy"]
|
||||
size = Vector2(1.6, 2)
|
||||
|
||||
[node name="EdgeDetection" type="Node3D"]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("SphereMesh_wnbfj")
|
||||
|
||||
[node name="MeshInstance3D2" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.965926, -0.258819, 0, 0.258819, 0.965926, 0, 0.322139, 0.653597)
|
||||
material_override = SubResource("ShaderMaterial_855vq")
|
||||
mesh = SubResource("QuadMesh_sbqxy")
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
shader_type spatial;
|
||||
|
||||
void vertex() {
|
||||
// Called for every vertex the material is visible on.
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
// Called for every pixel the material is visible on.
|
||||
}
|
||||
|
||||
//void light() {
|
||||
// Called for every pixel for every light affecting the material.
|
||||
// Uncomment to replace the default light processing function with this one.
|
||||
//}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://drgqrnj1otb25"]
|
||||
|
||||
[ext_resource type="Shader" path="res://shaders/010_outline/outline.gdshader" id="1_34hnr"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_vbj21"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("1_34hnr")
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_wnbfj"]
|
||||
material = SubResource("ShaderMaterial_vbj21")
|
||||
|
||||
[node name="Outline" type="Node3D"]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("SphereMesh_wnbfj")
|
||||
32
shaders/014_depth/depth.gdshader
Normal file
32
shaders/014_depth/depth.gdshader
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
shader_type spatial;
|
||||
render_mode unshaded, depth_draw_never, cull_disabled;
|
||||
|
||||
uniform float depth_factor: hint_range(0.0, 256.0, 0.1) = 80.0;
|
||||
uniform float pow_factor: hint_range(0.0, 10.0, 0.1) = 1.0;
|
||||
uniform sampler2D depth_texture : hint_depth_texture;
|
||||
|
||||
void fragment() {
|
||||
// Read the depth from the SCREEN_UV
|
||||
float depth = texture(depth_texture, SCREEN_UV).x;
|
||||
|
||||
// Normalize the device coordiantes
|
||||
// See (https://docs.godotengine.org/en/latest/tutorials/shaders/advanced_postprocessing.html)
|
||||
// for details on Vulkan vs. OpenGL coordinates
|
||||
|
||||
// Puts the normalized device coordinates into X and Y and the depth coordinates into Z
|
||||
vec3 ndc = vec3(SCREEN_UV * 2.0 - 1.0, depth);
|
||||
|
||||
// Convert NDC to view space (also known as camera space or eye space)
|
||||
// View Space gives positions relative to the camera, so Z will give the
|
||||
// distance from the camera to the point
|
||||
vec4 view = INV_PROJECTION_MATRIX * vec4(ndc, 1.0);
|
||||
|
||||
// Transforms the homogeneous coordinates into 3D space
|
||||
// this is a common line in 3D graphics
|
||||
view.xyz /= view.w;
|
||||
|
||||
// negate the z value due to vulkans coordinate system
|
||||
float linear_depth = -view.z;
|
||||
|
||||
ALBEDO = vec3(linear_depth / depth_factor);
|
||||
}
|
||||
25
shaders/014_depth/depth.tscn
Normal file
25
shaders/014_depth/depth.tscn
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://eh06d5qto3hu"]
|
||||
|
||||
[ext_resource type="Shader" path="res://shaders/014_depth/depth.gdshader" id="1_bci2g"]
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_46g6r"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_to4o0"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("1_bci2g")
|
||||
shader_parameter/depth_factor = 80.0
|
||||
shader_parameter/pow_factor = 1.0
|
||||
|
||||
[sub_resource type="QuadMesh" id="QuadMesh_xgf2h"]
|
||||
material = SubResource("ShaderMaterial_to4o0")
|
||||
size = Vector2(1.6, 2)
|
||||
|
||||
[node name="Depth" type="Node3D"]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("SphereMesh_46g6r")
|
||||
|
||||
[node name="MeshInstance3D2" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.965926, -0.258819, 0, 0.258819, 0.965926, 0, 0.322139, 0.653597)
|
||||
mesh = SubResource("QuadMesh_xgf2h")
|
||||
metadata/_edit_lock_ = true
|
||||
32
shaders/016_line/line.gdshader
Normal file
32
shaders/016_line/line.gdshader
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
shader_type spatial;
|
||||
|
||||
uniform vec2 resolution = vec2(600.0, 400.0);
|
||||
uniform vec3 line_color: source_color = vec3(0.2, 0.6, 0.2);
|
||||
uniform float line_thickness: hint_range(0.01, 1.0, 0.01) = 0.05;
|
||||
uniform float speed = 0.5;
|
||||
uniform float amp_coef = 0.1;
|
||||
uniform float freq_coef = 0.5;
|
||||
uniform float iterations: hint_range(1.0, 20.0, 1.0) = 5.0;
|
||||
uniform float brightness: hint_range(0.1, 20.0, 0.1) = 0.5;
|
||||
|
||||
vec3 draw_line(vec2 uv, vec3 color, float shift, float freq) {
|
||||
uv.y += (1.0 - smoothstep(0.0, 1.0, abs(uv.x))) * sin(uv.x + shift * freq) * amp_coef * sin(uv.x + shift);
|
||||
return (1.0 - smoothstep(0.0, line_thickness * (smoothstep(-0.2, 0.9, abs(uv.x))), abs(uv.y))) * color;
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
// Move the center of the uv to the center of the Mesh
|
||||
vec2 uv = UV - 0.5;
|
||||
|
||||
// Apply the aspect ratio
|
||||
uv.x *= resolution.x / resolution.y;
|
||||
|
||||
float shift = TIME * speed;
|
||||
|
||||
vec3 color = vec3(0.0);
|
||||
for (float i = 0.0; i < iterations; i += 1.0) {
|
||||
color += draw_line(uv, line_color, shift + i * 0.4, 1.0 + freq_coef);
|
||||
}
|
||||
|
||||
ALBEDO = color * brightness;
|
||||
}
|
||||
23
shaders/016_line/line.tscn
Normal file
23
shaders/016_line/line.tscn
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://omdbnbi707f8"]
|
||||
|
||||
[ext_resource type="Shader" path="res://shaders/016_line/line.gdshader" id="1_wsdq7"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_jjsaw"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("1_wsdq7")
|
||||
shader_parameter/resolution = Vector2(600, 400)
|
||||
shader_parameter/line_color = Color(0.860779, 0.546136, 0.207257, 1)
|
||||
shader_parameter/line_thickness = 0.02
|
||||
shader_parameter/speed = 0.065
|
||||
shader_parameter/amp_coef = 0.26
|
||||
shader_parameter/freq_coef = 4.175
|
||||
shader_parameter/iterations = 20.0
|
||||
shader_parameter/brightness = 1.0
|
||||
|
||||
[sub_resource type="QuadMesh" id="QuadMesh_ldsi7"]
|
||||
material = SubResource("ShaderMaterial_jjsaw")
|
||||
|
||||
[node name="Line" type="Node3D"]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("QuadMesh_ldsi7")
|
||||
15
shaders/017_blur/blur.gdshader
Normal file
15
shaders/017_blur/blur.gdshader
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
shader_type spatial;
|
||||
render_mode unshaded;
|
||||
|
||||
uniform sampler2D SCREEN_TEXTURE: hint_screen_texture, repeat_disable, filter_nearest;
|
||||
uniform float blur_power: hint_range(0.0, 0.2, 0.001) = 0.05;
|
||||
uniform sampler2D noise_texture;
|
||||
|
||||
vec2 noise(vec2 uv) {
|
||||
return texture(noise_texture, uv).xy - 0.5;
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
vec2 uv = SCREEN_UV;
|
||||
ALBEDO.rgb = texture(SCREEN_TEXTURE, uv + noise(uv)).rgb * blur_power;
|
||||
}
|
||||
34
shaders/017_blur/blur.tscn
Normal file
34
shaders/017_blur/blur.tscn
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
[gd_scene load_steps=7 format=3 uid="uid://dbevfrw75c0lf"]
|
||||
|
||||
[ext_resource type="Shader" path="res://shaders/017_blur/blur.gdshader" id="1_5bxw6"]
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_i42j4"]
|
||||
|
||||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_vfc3l"]
|
||||
noise_type = 0
|
||||
frequency = 0.0132
|
||||
fractal_octaves = 3
|
||||
|
||||
[sub_resource type="NoiseTexture2D" id="NoiseTexture2D_08gkt"]
|
||||
as_normal_map = true
|
||||
bump_strength = 0.4
|
||||
noise = SubResource("FastNoiseLite_vfc3l")
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_rdcxf"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("1_5bxw6")
|
||||
shader_parameter/blur_power = 0.2
|
||||
shader_parameter/noise_texture = SubResource("NoiseTexture2D_08gkt")
|
||||
|
||||
[sub_resource type="QuadMesh" id="QuadMesh_prlu3"]
|
||||
material = SubResource("ShaderMaterial_rdcxf")
|
||||
size = Vector2(1.6, 2)
|
||||
|
||||
[node name="Blur" type="Node3D"]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("SphereMesh_i42j4")
|
||||
|
||||
[node name="MeshInstance3D2" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.965926, -0.258819, 0, 0.258819, 0.965926, 0, 0.322139, 0.653597)
|
||||
mesh = SubResource("QuadMesh_prlu3")
|
||||
63
shaders/018_black_hole/BlackHole.gdshader
Normal file
63
shaders/018_black_hole/BlackHole.gdshader
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
shader_type spatial;
|
||||
render_mode unshaded;
|
||||
|
||||
uniform sampler2D screen_tex : hint_screen_texture;
|
||||
uniform sampler2D depth_tex : hint_depth_texture;
|
||||
uniform float scale;
|
||||
|
||||
bool hit_sphere(vec3 ray_origin, vec3 ray_dir, vec3 sphere_origin, float radius) {
|
||||
vec3 oc = ray_origin - sphere_origin;
|
||||
float a = dot(ray_dir, ray_dir);
|
||||
float b = 2.0 * dot(ray_dir, oc);
|
||||
float c = dot(oc, oc) - (radius * radius);
|
||||
float disc = (b * b) - 4.0 * a * c;
|
||||
return disc > 0.0;
|
||||
}
|
||||
|
||||
vec3 get_world_position_from_uv(vec2 uv, float depth, mat4 inv_proj_m, mat4 inv_view_m) {
|
||||
vec4 ndc = vec4((uv * 2.0) - 1.0, depth, 1.0);
|
||||
vec4 view_p = inv_proj_m * ndc;
|
||||
view_p.xyz /= view_p.w;
|
||||
view_p = (inv_view_m * vec4(view_p.xyz, 1.0));
|
||||
return view_p.xyz;
|
||||
}
|
||||
|
||||
vec2 get_uv_from_world_position(vec3 position_w, mat4 proj_m, mat4 view_m) {
|
||||
vec3 position_v = (view_m * vec4(position_w, 1.0)).xyz;
|
||||
vec4 position_cs = proj_m * vec4(position_v.xyz, 1.0);
|
||||
vec2 ndc = position_cs.xy / position_cs.w;
|
||||
return ndc.xy * 0.5 + 0.5;
|
||||
}
|
||||
|
||||
float fresnel(float amount, vec3 normal, vec3 view) {
|
||||
return pow((1.0 - clamp(dot(normalize(normal), normalize(view)), 0.0, 1.0 )), amount);
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
float depth = texture(depth_tex, SCREEN_UV).x;
|
||||
vec3 frag_p = get_world_position_from_uv(SCREEN_UV, depth, INV_PROJECTION_MATRIX, INV_VIEW_MATRIX);
|
||||
vec3 ray_dir = normalize(frag_p - CAMERA_POSITION_WORLD);
|
||||
|
||||
bool hit = hit_sphere(CAMERA_POSITION_WORLD, ray_dir, NODE_POSITION_WORLD, scale * .3);
|
||||
|
||||
vec4 screen_color = texture(screen_tex, SCREEN_UV);
|
||||
vec3 color;
|
||||
if (hit) {
|
||||
color = vec3(0.0);
|
||||
}
|
||||
else {
|
||||
vec2 bh_p = get_uv_from_world_position(NODE_POSITION_WORLD, PROJECTION_MATRIX, VIEW_MATRIX);
|
||||
vec2 dis_dir = normalize(bh_p - SCREEN_UV) * 0.5;
|
||||
float f = 1.0 - fresnel(0.5, NORMAL, VIEW);
|
||||
|
||||
float fov = atan(-1.0 / PROJECTION_MATRIX[1][1] * 2.0);
|
||||
float dist = distance(CAMERA_POSITION_WORLD, NODE_POSITION_WORLD);
|
||||
float s = (2.0 * dist * tan(fov * 0.5)) / scale;
|
||||
|
||||
vec2 uv = SCREEN_UV + (dis_dir * (f / s));
|
||||
screen_color = texture(screen_tex, uv);
|
||||
color = vec3(screen_color.r, screen_color.g, screen_color.b);
|
||||
|
||||
}
|
||||
ALBEDO = color;
|
||||
}
|
||||
19
shaders/018_black_hole/BlackHole.tscn
Normal file
19
shaders/018_black_hole/BlackHole.tscn
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://dpt0jm6fe6iy"]
|
||||
|
||||
[ext_resource type="Shader" path="res://shaders/018_black_hole/BlackHole.gdshader" id="1_qhb28"]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_101ce"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("1_qhb28")
|
||||
shader_parameter/scale = 1.0
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_yxjof"]
|
||||
material = SubResource("ShaderMaterial_101ce")
|
||||
flip_faces = true
|
||||
radius = 2.5
|
||||
height = 5.0
|
||||
|
||||
[node name="BlackHole" type="Node3D"]
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
mesh = SubResource("SphereMesh_yxjof")
|
||||
Loading…
Add table
Add a link
Reference in a new issue