rj-action-library/External/Imposter/materials/normal_baker.gdshader

47 lines
1.2 KiB
Plaintext
Raw Normal View History

2024-12-01 17:07:41 +00:00
shader_type spatial;
render_mode blend_mix,depth_draw_opaque,cull_disabled,diffuse_burley,specular_schlick_ggx;
2025-01-03 12:09:23 +00:00
uniform vec4 albedo_color : source_color;
uniform sampler2D albedo_texture : source_color;
2024-12-01 17:07:41 +00:00
uniform sampler2D normal_texture : source_color;
uniform bool use_normalmap = false;
uniform bool use_alpha_texture = false;
2025-01-03 12:09:23 +00:00
2024-12-01 17:07:41 +00:00
uniform float alpha_scissor_threshold : hint_range(0,1);
uniform float normal_scale : hint_range(-5,5);
uniform vec3 uv1_scale;
uniform vec3 uv1_offset;
2025-01-03 12:09:23 +00:00
void vertex()
{
UV = UV * uv1_scale.xy + uv1_offset.xy;
2024-12-01 17:07:41 +00:00
}
2025-01-03 12:09:23 +00:00
void fragment()
{
2024-12-01 17:07:41 +00:00
vec2 base_uv = UV;
2025-01-03 12:09:23 +00:00
vec4 albedo = texture( albedo_texture, base_uv ) * albedo_color;
vec4 normal_tex = texture( normal_texture, base_uv );
2024-12-01 17:07:41 +00:00
// 0.5 + -1.0 == -1.0 + 0.5
//ALBEDO = vec3(1.0 - NORMAL.y, 1.0 - NORMAL.x, - NORMAL.z)* 0.5;
2025-01-03 12:09:23 +00:00
if ( use_normalmap )
2024-12-01 17:07:41 +00:00
{
vec3 normalmap;
normalmap.xy = normal_tex.xy * 2.0 - 1.0;
normalmap.z = sqrt(max(0.0, 1.0 - dot(normalmap.xy, normalmap.xy)));
NORMAL = normalize(mix(NORMAL, TANGENT * normalmap.x + BINORMAL * normalmap.y + NORMAL * normalmap.z, normal_scale));
}
2025-01-03 12:09:23 +00:00
ALBEDO = vec3( -NORMAL.x, NORMAL.y, -NORMAL.z) * 0.5 + 0.5;
if ( use_alpha_texture )
2024-12-01 17:07:41 +00:00
{
2025-01-03 12:09:23 +00:00
ALPHA = albedo.a;
2024-12-01 17:07:41 +00:00
ALPHA_SCISSOR_THRESHOLD = alpha_scissor_threshold;
}
}