axmol/tests/cpp-tests/Source/shaders/toon.frag

32 lines
944 B
GLSL
Raw Normal View History

2023-07-22 23:59:17 +08:00
#version 310 es
precision highp float;
precision highp int;
2023-07-25 19:06:12 +08:00
layout(location = TEXCOORD0) in vec2 v_texCoord;
layout(location = NORMAL) in vec3 v_normal;
2023-07-22 23:59:17 +08:00
layout(binding = 0) uniform sampler2D u_sampler0;
layout(std140, binding = 0) uniform fs_ub {
vec4 u_color;
};
2023-07-25 19:06:12 +08:00
layout(location = SV_Target0) out vec4 FragColor;
2023-07-22 23:59:17 +08:00
void main(void)
{
vec3 light_direction = vec3(1,-1,-1);
light_direction = normalize(light_direction);
vec3 light_color = vec3(1,1,1);
vec3 normal = normalize(v_normal);
float diffuse_factor = dot(normal,-light_direction);
2023-07-25 19:06:12 +08:00
vec4 diffuse_color = texture(u_sampler0,v_texCoord);
2023-07-22 23:59:17 +08:00
if (diffuse_factor > 0.95) diffuse_factor=1.0;
else if (diffuse_factor > 0.75) diffuse_factor = 0.8;
else if (diffuse_factor > 0.50) diffuse_factor = 0.6;
else diffuse_factor = 0.4;
light_color = light_color * diffuse_factor;
FragColor = vec4(light_color,1.0) * diffuse_color * u_color;
}