Created
April 29, 2020 19:42
-
-
Save wojtekpil/d4f08c408a3fb2ea209456fee97fbb50 to your computer and use it in GitHub Desktop.
This file contains 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 blend_mix,depth_draw_always, cull_disabled,diffuse_burley,specular_schlick_ggx; | |
uniform vec4 albedo : hint_color; | |
uniform sampler2D texture_albedo : hint_albedo; | |
uniform float specular = 0.5; | |
uniform float metallic = 0; | |
uniform float proximity_fade_distance = 0.85; | |
uniform float roughness : hint_range(0,1) = 1; | |
uniform float alpha_clip : hint_range(0,1) = 0.85; | |
uniform float point_size : hint_range(0,128) = 1; | |
uniform vec4 transmission : hint_color; | |
uniform sampler2D texture_transmission : hint_black; | |
uniform vec3 uv1_scale = vec3(1,1,1); | |
uniform vec3 uv1_offset = vec3(0,0,0); | |
uniform vec3 uv2_scale = vec3(1,1,1); | |
uniform vec3 uv2_offset = vec3(0,0,0); | |
void vertex() { | |
UV=UV*uv1_scale.xy+uv1_offset.xy; | |
} | |
void fragment() { | |
vec2 base_uv = UV; | |
vec4 albedo_tex = texture(texture_albedo,base_uv); | |
float alpha_tex = albedo_tex.a; | |
if(alpha_tex < alpha_clip) | |
alpha_tex = 0f; | |
ALBEDO = albedo.rgb * albedo_tex.rgb; | |
METALLIC = metallic; | |
ROUGHNESS = roughness; | |
SPECULAR = specular; | |
float opacity = albedo.a * alpha_tex; | |
float depth_tex = textureLod(DEPTH_TEXTURE,SCREEN_UV,0.0).r; | |
vec4 world_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV*2.0-1.0,depth_tex*2.0-1.0,1.0); | |
world_pos.xyz/=world_pos.w; | |
opacity*=clamp(1.0-smoothstep(world_pos.z+proximity_fade_distance,world_pos.z,VERTEX.z),0.0,1.0); | |
vec3 transmission_tex = texture(texture_transmission,base_uv).rgb; | |
TRANSMISSION = (transmission.rgb+transmission_tex); | |
ALPHA = opacity; | |
// skip drawing all pixels below this limit | |
if (opacity < 0.001f) | |
discard; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment