couch/shaders/flat.vert

67 lines
1.6 KiB
GLSL
Raw Permalink Normal View History

2021-01-13 10:42:57 -06:00
#version 330 core
layout (location = 0) in vec3 pos;
2021-01-21 15:26:39 -06:00
layout (location = 1) in vec3 normal;
layout (location = 2) in vec2 uv;
2021-01-13 10:42:57 -06:00
2021-01-13 13:17:31 -06:00
uniform mat4 MODEL;
uniform mat4 VIEW;
uniform mat4 PROJECTION;
uniform mat3 NORMAL;
2021-01-13 10:42:57 -06:00
2021-01-22 14:37:32 -06:00
noperspective out vec2 UV; // PSX use affine texture mapping
2021-01-22 18:44:43 -06:00
out vec3 AMBIENT;
out vec3 DIFFUSE;
out vec3 SPECULAR;
2021-01-21 18:03:50 -06:00
struct DirectionalLight {
vec3 direction;
vec3 color;
float ambient;
float diffuse;
float specular;
};
2021-01-22 18:44:43 -06:00
struct Material {
sampler2D tex;
bool usesTex;
vec3 ambient;
vec3 diffuse;
vec3 specular;
int shininess;
float alphaScissor;
bool unshaded;
bool cullBack;
};
2021-01-21 18:03:50 -06:00
uniform DirectionalLight directionalLight;
2021-01-22 18:44:43 -06:00
uniform Material material;
2021-01-13 10:42:57 -06:00
void main() {
2021-01-19 16:08:37 -06:00
vec4 vertex = PROJECTION * VIEW * MODEL * vec4(pos, 1.0);
gl_Position = vertex;
2021-01-22 14:37:32 -06:00
UV = uv;
2021-01-21 18:03:50 -06:00
vec3 my_normal = (VIEW * MODEL * vec4(normal, 0.0)).xyz;
my_normal *= NORMAL;
2021-01-21 18:03:50 -06:00
// Flat shading, we compute light per vertex
2021-01-22 18:44:43 -06:00
AMBIENT = directionalLight.ambient * directionalLight.color * material.ambient;
2021-01-21 18:03:50 -06:00
vec3 direction = -(VIEW * vec4(directionalLight.direction, 0.0)).xyz;
float diff = dot(normalize(direction), normalize(my_normal));
2021-01-21 18:03:50 -06:00
diff = max(diff, 0.0);
2021-01-22 18:44:43 -06:00
DIFFUSE = directionalLight.diffuse * diff * directionalLight.color * material.diffuse;
2021-01-21 18:03:50 -06:00
2021-01-22 18:44:43 -06:00
vec3 viewDir = normalize((VIEW * MODEL * vec4(pos, 1.0)).xyz);
vec3 reflectionDir = reflect(normalize(direction), normalize(my_normal));
2021-01-21 18:03:50 -06:00
float spec = dot(viewDir, reflectionDir);
spec = max(spec, 0.0);
2021-01-22 18:44:43 -06:00
spec = pow(spec, material.shininess);
SPECULAR = directionalLight.color * (spec * material.specular);
2021-01-13 10:42:57 -06:00
}