feat: diffuse lighting — normals passed to fragment shader
- Vertex shader: pass normal through mat3(model) to fragment - Fragment shader: directional light (0.5, 0.8, 0.3) with 0.25 ambient + 0.75 diffuse = faces now have depth and 3D form - Torus knot has smooth normals (vn in OBJ), cubes have face normals - 0 validation errors, ~2300 FPS
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) in vec3 fragColor;
|
||||
layout(location = 1) in vec3 fragNormal;
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
void main() {
|
||||
outColor = vec4(fragColor, 1.0);
|
||||
vec3 N = normalize(fragNormal);
|
||||
vec3 L = normalize(vec3(0.5, 0.8, 0.3));
|
||||
float diff = max(dot(N, L), 0.0);
|
||||
float ambient = 0.25;
|
||||
vec3 color = fragColor * (ambient + diff * 0.75);
|
||||
outColor = vec4(color, 1.0);
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -5,6 +5,7 @@ layout(location = 1) in vec3 inColor;
|
||||
layout(location = 2) in vec3 inNormal;
|
||||
|
||||
layout(location = 0) out vec3 fragColor;
|
||||
layout(location = 1) out vec3 fragNormal;
|
||||
|
||||
layout(set = 0, binding = 0) uniform CameraUBO {
|
||||
mat4 vp;
|
||||
@@ -17,4 +18,5 @@ layout(push_constant) uniform PC {
|
||||
void main() {
|
||||
gl_Position = vp * pc.model * vec4(inPosition, 1.0);
|
||||
fragColor = inColor;
|
||||
fragNormal = mat3(pc.model) * inNormal;
|
||||
}
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user