couch/shaders/flat.frag

50 lines
981 B
GLSL
Raw Normal View History

2021-01-13 10:42:57 -06:00
#version 330 core
2021-01-19 16:08:37 -06:00
in vec3 UV;
2021-01-21 15:26:39 -06:00
in vec3 NORMAL;
2021-01-13 10:42:57 -06:00
2021-01-20 20:49:12 -06:00
out vec4 FragColor;
struct Material {
vec3 color;
bool usesColor;
sampler2D tex;
bool usesTex;
2021-01-20 20:49:12 -06:00
float alphaScissor;
2021-01-21 15:26:39 -06:00
bool unshaded;
};
struct DirectionalLight {
vec3 direction;
vec3 color;
float ambient;
float diffuse;
float specular;
};
uniform Material material;
2021-01-21 15:26:39 -06:00
uniform DirectionalLight directionalLight;
2021-01-13 10:42:57 -06:00
void main() {
2021-01-20 20:49:12 -06:00
FragColor = vec4(0.0);
if (material.usesColor) {
2021-01-20 20:49:12 -06:00
FragColor += vec4(material.color, 1.0);
}
if (material.usesTex) {
2021-01-20 20:49:12 -06:00
FragColor += texture(material.tex, UV.xy / UV.z);
2021-01-20 12:50:59 -06:00
}
2021-01-20 20:49:12 -06:00
if (FragColor.w < material.alphaScissor) {
2021-01-20 12:50:59 -06:00
discard;
}
2021-01-21 15:26:39 -06:00
if (!material.unshaded) {
vec3 ambient = directionalLight.ambient * directionalLight.color;
2021-01-21 15:35:21 -06:00
ambient = max(ambient, 0.0);
vec3 diffuse = directionalLight.diffuse * dot(directionalLight.direction, NORMAL) * directionalLight.color;
diffuse = max(diffuse, 0.0);
FragColor *= vec4(ambient + diffuse, 1.0);
2021-01-21 15:26:39 -06:00
}
2021-01-13 10:42:57 -06:00
}