fix: incorrect fragment world normal calculation
This commit is contained in:
parent
ee825527d0
commit
35ffc33ea8
|
@ -9,12 +9,13 @@ uniform vec4 colDiffuse;
|
||||||
out vec4 finalColor;
|
out vec4 finalColor;
|
||||||
|
|
||||||
uniform vec3 lightDirection; // direction of light
|
uniform vec3 lightDirection; // direction of light
|
||||||
uniform vec4 ambient;
|
uniform vec4 ambientLight;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
vec4 texelColor = texture(texture0, fragTexCoord);
|
vec4 texelColor = texture(texture0, fragTexCoord);
|
||||||
vec3 light_dot = vec3(pow(clamp(dot(fragNormal, lightDirection), 0.0, 1.0), 2.0));
|
float light_dot = clamp(dot(normalize(fragNormal), normalize(lightDirection)), 0.0, 1.0);
|
||||||
finalColor = texelColor * colDiffuse * vec4(light_dot, 1.0);
|
vec4 light_col = vec4(vec3(light_dot), 1.0);
|
||||||
finalColor += texelColor * (ambient/10.0) * colDiffuse;
|
finalColor = texelColor * colDiffuse * light_col;
|
||||||
finalColor = pow(finalColor, vec4(vec3(0.6), 1.0));
|
finalColor += texelColor * colDiffuse * ambientLight;
|
||||||
|
finalColor = pow(finalColor, vec4(vec3(0.8), 1.0));
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ void main()
|
||||||
{
|
{
|
||||||
// Send vertex attributes to fragment shader
|
// Send vertex attributes to fragment shader
|
||||||
fragTexCoord = vertexTexCoord;
|
fragTexCoord = vertexTexCoord;
|
||||||
fragNormal = normalize(vec3(matModel * vec4(vertexNormal, 1.0)));
|
fragNormal = -normalize(vec3(matModel * vec4(vertexNormal, 0.0)));
|
||||||
|
|
||||||
// Calculate final vertex position
|
// Calculate final vertex position
|
||||||
gl_Position = mvp*vec4(vertexPosition, 1.0);
|
gl_Position = mvp*vec4(vertexPosition, 1.0);
|
||||||
|
|
Loading…
Reference in a new issue