Files
render/toon_fragment.glsl
2025-11-19 20:11:18 +05:00

45 lines
1.2 KiB
GLSL
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#version 330 core
out vec4 FragColor;
in vec3 FragPos;
in vec3 Normal;
uniform vec3 lightPos;
uniform vec3 viewPos;
void main()
{
// Toon shader (мультяшный стиль)
vec3 lightColor = vec3(1.0, 1.0, 1.0);
vec3 objectColor = vec3(0.3, 0.6, 0.9);
// Ambient
float ambientStrength = 0.3;
vec3 ambient = ambientStrength * lightColor;
// Diffuse с дискретными уровнями
vec3 norm = normalize(Normal);
vec3 lightDir = normalize(lightPos - FragPos);
float diff = max(dot(norm, lightDir), 0.0);
// Квантуем освещение на 4 уровня
if (diff > 0.95) diff = 1.0;
else if (diff > 0.5) diff = 0.7;
else if (diff > 0.25) diff = 0.4;
else diff = 0.2;
vec3 diffuse = diff * lightColor;
// Specular с четким бликом
vec3 viewDir = normalize(viewPos - FragPos);
vec3 reflectDir = reflect(-lightDir, norm);
float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32);
vec3 specular = vec3(0.0);
if (spec > 0.5) specular = vec3(1.0); // Четкий блик
vec3 result = (ambient + diffuse + specular * 0.3) * objectColor;
FragColor = vec4(result, 1.0);
}