Extensive work on virtually all of the visuals and the net code
This commit is contained in:
40
visuals/shaders/intersection.gdshader
Normal file
40
visuals/shaders/intersection.gdshader
Normal file
@@ -0,0 +1,40 @@
|
||||
shader_type spatial;
|
||||
render_mode blend_add, cull_disabled;
|
||||
|
||||
uniform vec4 intersection_color : source_color = vec4(1.0, 0.5, 0.0, 1.0);
|
||||
uniform float intersection_thickness = 0.5;
|
||||
uniform float intensity = 1.0f;
|
||||
uniform sampler2D DEPTH_TEXTURE : hint_depth_texture, filter_linear_mipmap;
|
||||
|
||||
void fragment() {
|
||||
// 1. Get linear depth of the scene (opaque objects)
|
||||
float depth = texture(DEPTH_TEXTURE, SCREEN_UV).x;
|
||||
vec3 ndc = vec3(SCREEN_UV * 2.0 - 1.0, depth);
|
||||
vec4 view = INV_PROJECTION_MATRIX * vec4(ndc, 1.0);
|
||||
view.xyz /= view.w;
|
||||
float linear_depth = -view.z;
|
||||
|
||||
// 2. Get linear depth of the current object
|
||||
float linear_frag_coord = -VERTEX.z;
|
||||
|
||||
// 3. Calculate difference
|
||||
float diff = linear_depth - linear_frag_coord;
|
||||
|
||||
// 4. Create intersection mask
|
||||
float intersect = clamp(diff / intersection_thickness, 0.0, 1.0);
|
||||
|
||||
// Invert so the intersection is 1.0
|
||||
intersect = 1.0 - intersect;
|
||||
|
||||
// Output color
|
||||
float strength = .25 + .75 * (1.0 + sin(TIME*3.0))/2.0;
|
||||
|
||||
ALPHA = max(.05, intersect * intersection_color.a * strength);
|
||||
if(ALPHA == .05){
|
||||
ALBEDO = intersection_color.rgb;
|
||||
}else{
|
||||
ALBEDO = intersection_color.rgb * strength;
|
||||
EMISSION = intersection_color.rgb * intensity * strength; // Glow effect
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user