2024-08-12 21:40:37 -04:00
|
|
|
#version 430
|
2024-08-14 16:40:51 -04:00
|
|
|
precision highp float;
|
|
|
|
|
2024-08-12 21:40:37 -04:00
|
|
|
layout(binding = 0) uniform sampler2D diffuse_tex;
|
|
|
|
layout(location = 1) uniform float time;
|
|
|
|
|
|
|
|
layout(std140, binding = 0) uniform SceneUniforms
|
|
|
|
{
|
2024-08-13 18:09:49 -04:00
|
|
|
mat4 PV; //camera projection * view matrix
|
|
|
|
vec4 eye_w; //world-space eye position
|
2024-08-12 21:40:37 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
layout(std140, binding = 1) uniform LightUniforms
|
|
|
|
{
|
2024-08-13 18:09:49 -04:00
|
|
|
vec4 La; //ambient light color
|
|
|
|
vec4 Ld; //diffuse light color
|
|
|
|
vec4 Ls; //specular light color
|
|
|
|
vec4 light_w; //world-space light position
|
2024-08-12 21:40:37 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
layout(std140, binding = 2) uniform MaterialUniforms
|
|
|
|
{
|
2024-08-13 18:09:49 -04:00
|
|
|
vec4 ka; //ambient material color
|
|
|
|
vec4 kd; //diffuse material color
|
|
|
|
vec4 ks; //specular material color
|
|
|
|
float shininess; //specular exponent
|
2024-08-12 21:40:37 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
in VertexData
|
|
|
|
{
|
2024-08-13 18:09:49 -04:00
|
|
|
vec2 tex_coord;
|
|
|
|
vec3 pw; //world-space vertex position
|
|
|
|
vec3 nw; //world-space normal vector
|
2024-08-12 21:40:37 -04:00
|
|
|
} inData; //block is named 'inData'
|
|
|
|
|
2024-08-14 18:04:06 -04:00
|
|
|
in vec3 frag_position;
|
|
|
|
|
2024-08-14 16:40:51 -04:00
|
|
|
out vec4 frag_color; //the output color for this fragment
|
2024-08-12 21:40:37 -04:00
|
|
|
|
|
|
|
void main(void)
|
|
|
|
{
|
2024-08-13 18:09:49 -04:00
|
|
|
//Compute per-fragment Phong lighting
|
|
|
|
// vec4 ktex = texture(diffuse_tex, inData.tex_coord);
|
|
|
|
|
|
|
|
// vec4 ambient_term = ka*ktex*La;
|
2024-08-12 21:40:37 -04:00
|
|
|
|
2024-08-13 18:09:49 -04:00
|
|
|
// const float eps = 1e-8; //small value to avoid division by 0
|
|
|
|
// float d = distance(light_w.xyz, inData.pw.xyz);
|
|
|
|
// float atten = 1.0/(d*d+eps); //d-squared attenuation
|
2024-08-12 21:40:37 -04:00
|
|
|
|
2024-08-13 18:09:49 -04:00
|
|
|
// vec3 nw = normalize(inData.nw); //world-space unit normal vector
|
|
|
|
// vec3 lw = normalize(light_w.xyz - inData.pw.xyz); //world-space unit light vector
|
|
|
|
// vec4 diffuse_term = atten*kd*ktex*Ld*max(0.0, dot(nw, lw));
|
2024-08-12 21:40:37 -04:00
|
|
|
|
2024-08-13 18:09:49 -04:00
|
|
|
// vec3 vw = normalize(eye_w.xyz - inData.pw.xyz); //world-space unit view vector
|
|
|
|
// vec3 rw = reflect(-lw, nw); //world-space unit reflection vector
|
2024-08-12 21:40:37 -04:00
|
|
|
|
2024-08-13 18:09:49 -04:00
|
|
|
// vec4 specular_term = atten*ks*Ls*pow(max(0.0, dot(rw, vw)), shininess);
|
2024-08-12 21:40:37 -04:00
|
|
|
|
2024-08-13 18:09:49 -04:00
|
|
|
// fragcolor = ambient_term + diffuse_term + specular_term;
|
2024-08-14 18:04:06 -04:00
|
|
|
frag_color = vec4(frag_position, 1.0f);
|
2024-08-12 21:40:37 -04:00
|
|
|
}
|
|
|
|
|