Premier commit
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
shader_type spatial;
|
||||
render_mode unshaded, depth_draw_never, cull_disabled;
|
||||
|
||||
uniform float width = 15.0;
|
||||
uniform float height = 15.0;
|
||||
uniform float density = 5.0;
|
||||
uniform float line_thickness = 0.1;
|
||||
uniform vec4 line_color : source_color = vec4( 0.2, 1.0, 1.0, 1.0 );
|
||||
|
||||
uniform sampler2D depth_texture : source_color, hint_depth_texture;
|
||||
uniform vec4 color1: source_color = vec4(1,1,1,.1);
|
||||
uniform vec4 color2: source_color = vec4(1,1,1,1);
|
||||
uniform float threshold = .2;
|
||||
uniform float fresnel_sharpness = 1.0;
|
||||
uniform float fresnel_factor = 1.0;
|
||||
|
||||
|
||||
float hex_cells( vec2 uv )
|
||||
{
|
||||
float x = uv.x * width * density;
|
||||
float y = mod( floor(x), 2.0 ) * 0.5 + ( uv.y * height ) * density;
|
||||
|
||||
vec2 base_chip = abs( vec2( 0.5 ) - mod( vec2( x, y ), 1.0 ) );
|
||||
return abs( max( base_chip.x * 1.5 + base_chip.y, base_chip.y * 2.0 ) - 1.0 );
|
||||
}
|
||||
|
||||
void fragment( )
|
||||
{
|
||||
float depth = texture(depth_texture, SCREEN_UV).x;
|
||||
//vec3 ndc = vec3(SCREEN_UV, depth) * 2.0 - 1.0;
|
||||
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;
|
||||
|
||||
float object_depth = FRAGCOORD.z;
|
||||
//vec3 object_ndc = vec3(SCREEN_UV, object_depth) * 2.0 - 1.0;
|
||||
vec3 object_ndc = vec3(SCREEN_UV * 2.0 - 1.0, object_depth);
|
||||
vec4 object_view = INV_PROJECTION_MATRIX * vec4(object_ndc, 1.0);
|
||||
object_view.xyz /= object_view.w;
|
||||
float linear_object_depth = -object_view.z;
|
||||
|
||||
float fresnel = pow(1.0 - dot(VIEW, NORMAL), fresnel_sharpness) * fresnel_factor;
|
||||
|
||||
if (linear_depth - linear_object_depth > threshold) {
|
||||
float hex = hex_cells( UV );
|
||||
|
||||
vec4 final_color = mix(
|
||||
color1,
|
||||
line_color,
|
||||
float( hex < line_thickness )
|
||||
);
|
||||
|
||||
ALBEDO = final_color.rgb;
|
||||
ALPHA = final_color.a+(fresnel);
|
||||
}
|
||||
else {
|
||||
ALBEDO = color2.rgb;
|
||||
ALPHA = color2.a+fresnel;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user