diff --git a/data/shaders/mesh/mesh.frag b/data/shaders/mesh/mesh.frag index 1d019706..4351151f 100644 --- a/data/shaders/mesh/mesh.frag +++ b/data/shaders/mesh/mesh.frag @@ -8,26 +8,20 @@ layout (binding = 1) uniform sampler2D samplerColorMap; layout (location = 0) in vec3 inNormal; layout (location = 1) in vec3 inColor; layout (location = 2) in vec2 inUV; -layout (location = 3) in vec3 inEyePos; +layout (location = 3) in vec3 inViewVec; layout (location = 4) in vec3 inLightVec; layout (location = 0) out vec4 outFragColor; void main() { - vec3 N = normalize(inNormal); - vec3 L = normalize(vec3(1.0)); - - vec3 Eye = normalize(-inEyePos); - vec3 Reflected = normalize(reflect(-inLightVec, inNormal)); - - vec4 IAmbient = vec4(vec3(0.25), 1.0); - vec4 IDiffuse = vec4(1.0) * max(dot(inNormal, inLightVec), 0.0); - - float specular = 0.75; - vec4 ISpecular = vec4(0.5, 0.5, 0.5, 1.0) * pow(max(dot(Reflected, Eye), 0.0), 4.0) * specular; - vec4 color = texture(samplerColorMap, inUV) * vec4(inColor, 1.0); - - outFragColor = vec4((IAmbient + IDiffuse) * color + (ISpecular * IDiffuse)); + + vec3 N = normalize(inNormal); + vec3 L = normalize(inLightVec); + vec3 V = normalize(inViewVec); + vec3 R = reflect(-L, N); + vec3 diffuse = max(dot(N, L), 0.0) * inColor; + vec3 specular = pow(max(dot(R, V), 0.0), 16.0) * vec3(0.75); + outFragColor = vec4(diffuse * color.rgb + specular, 1.0); } \ No newline at end of file diff --git a/data/shaders/mesh/mesh.frag.spv b/data/shaders/mesh/mesh.frag.spv index e044f482..65425149 100644 Binary files a/data/shaders/mesh/mesh.frag.spv and b/data/shaders/mesh/mesh.frag.spv differ diff --git a/data/shaders/mesh/mesh.vert b/data/shaders/mesh/mesh.vert index f9e6bd19..a055f9d8 100644 --- a/data/shaders/mesh/mesh.vert +++ b/data/shaders/mesh/mesh.vert @@ -18,7 +18,7 @@ layout (binding = 0) uniform UBO layout (location = 0) out vec3 outNormal; layout (location = 1) out vec3 outColor; layout (location = 2) out vec2 outUV; -layout (location = 3) out vec3 outEyePos; +layout (location = 3) out vec3 outViewVec; layout (location = 4) out vec3 outLightVec; void main() @@ -27,6 +27,10 @@ void main() outColor = inColor; outUV = inUV; gl_Position = ubo.projection * ubo.model * vec4(inPos.xyz, 1.0); - outEyePos = (gl_Position).xyz; - outLightVec = normalize(ubo.lightPos.xyz - outEyePos); + + vec4 pos = ubo.model * vec4(inPos, 1.0); + outNormal = mat3(ubo.model) * inNormal; + vec3 lPos = mat3(ubo.model) * ubo.lightPos.xyz; + outLightVec = lPos - pos.xyz; + outViewVec = -pos.xyz; } \ No newline at end of file diff --git a/data/shaders/mesh/mesh.vert.spv b/data/shaders/mesh/mesh.vert.spv index 61916703..0bca5ba8 100644 Binary files a/data/shaders/mesh/mesh.vert.spv and b/data/shaders/mesh/mesh.vert.spv differ diff --git a/mesh/mesh.cpp b/mesh/mesh.cpp index 4f8c2a30..9ecfb34a 100644 --- a/mesh/mesh.cpp +++ b/mesh/mesh.cpp @@ -67,7 +67,7 @@ public: struct { glm::mat4 projection; glm::mat4 model; - glm::vec4 lightPos = glm::vec4(2.0f, 2.0f, -2.0f, 1.0f); + glm::vec4 lightPos = glm::vec4(5.0f, 5.0f, 5.0f, 1.0f); } uboVS; struct { diff --git a/screenshots/basic_mesh.png b/screenshots/basic_mesh.png index b0a2dc9b..f13147a2 100644 Binary files a/screenshots/basic_mesh.png and b/screenshots/basic_mesh.png differ