Modern Apps git
git clone https://git.maproj.org/Modern-Apps.git
dependencies ▾

Modern-Apps.git / library / avatar / src / main / rust / shaders / yuu_avatar.frag

yuu_avatar.frag35 lines · 1.2 KiBRaw
1#version 450
2// Textured Yuu avatar fragment shader: albedo sample, single fixed sun plus a
3// soft fill so faces never go flat black, gentle distance fade into the clear
4// color so the hero reads against any Compose background.
5layout(location = 0) in vec3 vNormal;
6layout(location = 1) in vec2 vUv;
7layout(location = 2) in vec3 vWorld;
8
9layout(location = 0) out vec4 outColor;
10
11layout(set = 0, binding = 0) uniform Ubo {
12 mat4 viewProj;
13 vec3 sunDir;
14 vec3 camPos;
15 mat4 bones[32];
16} ubo;
17
18layout(set = 0, binding = 1) uniform sampler2D albedo;
19
20const vec3 SKY = vec3(0.45, 0.68, 0.94);
21
22void main() {
23 vec3 albedoCol = texture(albedo, vUv).rgb;
24 vec3 n = normalize(vNormal);
25 vec3 sun = normalize(ubo.sunDir);
26 // Front faces get little direct sun (sun points down-back), so carry them
27 // with a strong hemisphere ambient + fill — heroes must read brightly
28 // from the turntable's front view.
29 float ndl = clamp(dot(n, -sun), 0.0, 1.0);
30 float hemi = 0.65 + 0.35 * clamp(n.y * 0.5 + 0.5, 0.0, 1.0);
31 vec3 col = albedoCol * (0.55 + 0.45 * ndl) * hemi + albedoCol * 0.25;
32 float dist = length(vWorld - ubo.camPos);
33 float fog = 1.0 - exp(-dist * 0.02);
34 outColor = vec4(mix(col, SKY, clamp(fog, 0.0, 1.0)), 1.0);
35}