[gd_resource type="ShaderMaterial" load_steps=3 format=2] [ext_resource path="res://decals/scar-texture.png" type="Texture" id=1] [sub_resource type="Shader" id=1] code = "shader_type spatial; render_mode unshaded, depth_draw_never, cull_front, depth_test_disable; uniform sampler2D decal : hint_black; uniform vec2 offset; uniform vec2 scale; uniform bool emulate_lighting; uniform float brightness; varying flat mat4 model_view_matrix; void vertex(){ model_view_matrix = MODELVIEW_MATRIX; } void fragment(){ //float zdepth = textureLod(DEPTH_TEXTURE, SCREEN_UV, 0.0).r * 2.0 - 1.0; vec4 pos = inverse(model_view_matrix) * INV_PROJECTION_MATRIX * vec4(SCREEN_UV * 2.0 - 1.0, textureLod(DEPTH_TEXTURE, SCREEN_UV, 0.0).r * 2.0 - 1.0, 1.0); pos.xyz /= pos.w; bool inside = all(greaterThanEqual(pos.xyz, vec3(-1.0))) && all(lessThanEqual(pos.xyz, vec3(1.0))); if(inside){ vec4 color = texture(decal, (pos.xy * -0.5 - 0.5) * scale + offset); if(emulate_lighting){ float lum = dot(textureLod(SCREEN_TEXTURE, SCREEN_UV, 0).rgb, vec3(0.2125, 0.7154, 0.0721)); lum += brightness; lum = clamp(lum, 0.0, 1.0); ALBEDO = color.rgb * lum; }else{ ALBEDO = color.rgb; } ALPHA = color.a; }else{ discard; } }" [resource] shader = SubResource( 1 ) shader_param/offset = Vector2( 0.5, 0.5 ) shader_param/scale = Vector2( 20, 20 ) shader_param/emulate_lighting = false shader_param/brightness = null shader_param/decal = ExtResource( 1 )