Last active
October 9, 2024 18:09
-
-
Save partybusiness/2fc76d1d1522e7af425288bed85ec36b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shader_type spatial; | |
render_mode unshaded, blend_mul, depth_draw_never, depth_test_disabled; | |
// creates a silhouette that appears when the mesh is behind something else | |
// you can combine this with another material by assigning this as the Next Pass material | |
// this might need adjustment to work with 4.3 and later, because of the reversed depth | |
uniform vec3 shadow_colour:source_color = vec3(0.7,0.7,0.9); | |
uniform sampler2D depth_texture:hint_depth_texture; | |
/** | |
* Minimum distance between wall and character before silhouette starts to appear | |
*/ | |
uniform float min_threshold = 0.07; | |
/** | |
* Distance between wall and character where silhouette reaches full opacity | |
*/ | |
uniform float max_threshold = 0.08; | |
// because there wasn't an easy way to just flip the depth testing, I used a depth comparison based on this: | |
// https://github.com/danilw/godot-utils-and-other/blob/03bbe5112377040506d4498a1c5cc91bdda5f5cf/graphic_demo_3d/game/models/objects/spheres/shield.shader#L48 | |
float linearize(float zdepth) { | |
return 1.0 / zdepth; | |
} | |
void fragment() { | |
float zdepth = linearize(texture(depth_texture, SCREEN_UV).x); | |
float zpos = linearize(FRAGCOORD.z); | |
float diff = zpos - zdepth; //difference between two depths | |
float mix_val = smoothstep(min_threshold, max_threshold, diff); | |
ALBEDO.rgb = mix(vec3(1.0), shadow_colour, mix_val); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment