40 lines
1.7 KiB
Text
40 lines
1.7 KiB
Text
shader_type spatial;
|
|
|
|
// Every surface of a card: its face, its back and its edge. CardFaces makes one material per card
|
|
// face and shares one back and one edge material between all cards. What changes per card on the
|
|
// table (highlight, dimming) is an instance uniform, so it never needs a material of its own.
|
|
|
|
uniform sampler2D albedo_texture : source_color, hint_default_white, filter_linear_mipmap_anisotropic, repeat_disable;
|
|
uniform vec4 albedo_color : source_color = vec4(1.0);
|
|
uniform float roughness : hint_range(0.0, 1.0) = 0.55;
|
|
// card.glb's UVs run along the card's length instead of its width: Blender turns the image a
|
|
// quarter turn in its material, and Godot drops that on import. swap_uv turns them back, and
|
|
// mirror_u flips the back, which is seen from the other side. See CardFaces.FIX_GLB_UVS.
|
|
uniform bool swap_uv = false;
|
|
uniform bool mirror_u = false;
|
|
// Faces and backs glow mostly at their border; the edge glows all over.
|
|
uniform bool rim_glow = true;
|
|
|
|
// rgb is the color, a the strength.
|
|
instance uniform vec4 highlight : source_color = vec4(0.0);
|
|
// 0 is normal, 1 dark gray: disabled Hardware and Programs.
|
|
instance uniform float dim = 0.0;
|
|
|
|
void fragment() {
|
|
vec2 uv = swap_uv ? vec2(UV.y, 1.0 - UV.x) : UV;
|
|
if (mirror_u) {
|
|
uv.x = 1.0 - uv.x;
|
|
}
|
|
vec3 color = texture(albedo_texture, uv).rgb * albedo_color.rgb;
|
|
vec3 gray = vec3(dot(color, vec3(0.299, 0.587, 0.114)));
|
|
ALBEDO = mix(color, gray * 0.45, dim);
|
|
ROUGHNESS = roughness;
|
|
SPECULAR = 0.35;
|
|
|
|
float glow = 1.0;
|
|
if (rim_glow) {
|
|
float border = min(min(uv.x, 1.0 - uv.x), min(uv.y, 1.0 - uv.y));
|
|
glow = mix(0.12, 1.6, 1.0 - smoothstep(0.0, 0.07, border));
|
|
}
|
|
EMISSION = highlight.rgb * highlight.a * glow;
|
|
}
|