[gd_resource type="ShaderMaterial" load_steps=5 format=3 uid="uid://ct7uc5i5yp5qf"]

[ext_resource type="Texture2D" uid="uid://c61ekclk8loxn" path="res://base-environments/youth_room/import/textures/red_plaster_weathered_rough_4k.png" id="1_2nxvx"]
[ext_resource type="Texture2D" uid="uid://kf0vfm4sf0o3" path="res://base-environments/youth_room/import/textures/red_plaster_weathered_nor_gl_4k.png" id="2_80i0p"]
[ext_resource type="Texture2D" uid="uid://5j0s45a8i0t5" path="res://logic-scenes/luna/textures/luna-wing-noise.exr" id="2_ufwkf"]

[sub_resource type="Shader" id="Shader_tevka"]
code = "// NOTE: Shader automatically converted from Godot Engine 4.0.3.stable's StandardMaterial3D.

shader_type spatial;
render_mode blend_mix,depth_draw_opaque,cull_back,diffuse_burley,specular_schlick_ggx;

uniform vec3 alpha_origin;
uniform float alpha_offset;
uniform vec3 emission_color: source_color;
uniform sampler2D texture_albedo : source_color,filter_linear_mipmap,repeat_enable;
uniform vec3 albedo: source_color;
uniform sampler2D texture_noise : source_color,filter_linear_mipmap,repeat_enable;
uniform float alpha_scissor_threshold;
uniform float point_size : hint_range(0,128);
uniform float roughness : hint_range(0,1);
uniform sampler2D texture_metallic : hint_default_white,filter_linear_mipmap,repeat_enable;
uniform sampler2D texture_roughness : hint_roughness_r,filter_linear_mipmap,repeat_enable;
uniform float specular;
uniform sampler2D texture_normal : hint_roughness_normal,filter_linear_mipmap,repeat_enable;
uniform float normal_scale : hint_range(-16,16);
varying vec3 uv1_triplanar_pos;
uniform float uv1_blend_sharpness;
varying vec3 uv1_power_normal;
uniform vec3 uv1_scale;
uniform vec3 uv1_offset;
uniform vec3 uv2_scale;
uniform vec3 uv2_offset;


void vertex() {
	TANGENT = vec3(0.0,0.0,-1.0) * abs(NORMAL.x);
	TANGENT+= vec3(1.0,0.0,0.0) * abs(NORMAL.y);
	TANGENT+= vec3(1.0,0.0,0.0) * abs(NORMAL.z);
	TANGENT = normalize(TANGENT);
	BINORMAL = vec3(0.0,1.0,0.0) * abs(NORMAL.x);
	BINORMAL+= vec3(0.0,0.0,-1.0) * abs(NORMAL.y);
	BINORMAL+= vec3(0.0,1.0,0.0) * abs(NORMAL.z);
	BINORMAL = normalize(BINORMAL);
	uv1_power_normal=pow(abs(NORMAL),vec3(uv1_blend_sharpness));
	uv1_triplanar_pos = VERTEX * uv1_scale + uv1_offset;
	uv1_power_normal/=dot(uv1_power_normal,vec3(1.0));
	uv1_triplanar_pos *= vec3(1.0,-1.0, 1.0);
}




vec4 triplanar_texture(sampler2D p_sampler,vec3 p_weights,vec3 p_triplanar_pos) {
	vec4 samp=vec4(0.0);
	samp+= texture(p_sampler,p_triplanar_pos.xy) * p_weights.z;
	samp+= texture(p_sampler,p_triplanar_pos.xz) * p_weights.y;
	samp+= texture(p_sampler,p_triplanar_pos.zy * vec2(-1.0,1.0)) * p_weights.x;
	return samp;
}


void fragment() {
	ALBEDO = albedo * pow(triplanar_texture(texture_albedo,uv1_power_normal,uv1_triplanar_pos).x, 0.2);
	vec4 roughness_texture_channel = vec4(1.0,0.0,0.0,0.0);
	float roughness_tex = dot(triplanar_texture(texture_roughness,uv1_power_normal,uv1_triplanar_pos),roughness_texture_channel);
	ROUGHNESS = roughness_tex * roughness;
	SPECULAR = specular;
	NORMAL_MAP = triplanar_texture(texture_normal,uv1_power_normal,uv1_triplanar_pos).rgb;
	NORMAL_MAP_DEPTH = normal_scale;
    float alpha_distance = length(alpha_origin - (INV_VIEW_MATRIX * vec4(VERTEX, 1.0)).xyz) - alpha_offset;
    alpha_distance += texture(texture_noise, UV + vec2(TIME * 0.05) + 0.2 * triplanar_texture(texture_noise,uv1_power_normal,uv1_triplanar_pos - vec3(TIME* 0.05)).xy).y * .15;
    EMISSION = pow(max(1.5-alpha_distance, .0), 6.0 + alpha_scissor_threshold * 6.0) * emission_color;
    
	ALPHA = alpha_distance;
	ALPHA_SCISSOR_THRESHOLD = alpha_scissor_threshold;
}
"

[resource]
resource_name = "wall"
render_priority = 0
shader = SubResource("Shader_tevka")
shader_parameter/alpha_origin = Vector3(0.021, 2.336, -0.572)
shader_parameter/alpha_offset = -1.0
shader_parameter/emission_color = Color(0.8, 0.0666667, 0.423529, 1)
shader_parameter/albedo = Color(1.02, 0.99, 0.86, 1)
shader_parameter/alpha_scissor_threshold = -0.3
shader_parameter/point_size = 1.0
shader_parameter/roughness = 1.0
shader_parameter/specular = 0.5
shader_parameter/normal_scale = 1.0
shader_parameter/uv1_blend_sharpness = 1.0
shader_parameter/uv1_scale = Vector3(1, 1, 1)
shader_parameter/uv1_offset = Vector3(0, 0, 0)
shader_parameter/uv2_scale = Vector3(1, 1, 1)
shader_parameter/uv2_offset = Vector3(0, 0, 0)
shader_parameter/texture_albedo = ExtResource("1_2nxvx")
shader_parameter/texture_noise = ExtResource("2_ufwkf")
shader_parameter/texture_roughness = ExtResource("1_2nxvx")
shader_parameter/texture_normal = ExtResource("2_80i0p")
