Specular lighting now working correctly with the deferred lighting
--HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4051
This commit is contained in:
@@ -29,7 +29,7 @@ std::string KRDirectionalLight::getElementName() {
|
|||||||
|
|
||||||
KRVector3 KRDirectionalLight::getLightDirection() {
|
KRVector3 KRDirectionalLight::getLightDirection() {
|
||||||
KRVector3 world_rotation = getWorldRotation();
|
KRVector3 world_rotation = getWorldRotation();
|
||||||
KRVector3 light_rotation = KRVector3(0.0, -1.0, 0.0);
|
KRVector3 light_rotation = KRVector3(0.0, 0.0, 1.0);
|
||||||
KRMat4 m;
|
KRMat4 m;
|
||||||
m.rotate(world_rotation.x, X_AXIS);
|
m.rotate(world_rotation.x, X_AXIS);
|
||||||
m.rotate(world_rotation.y, Y_AXIS);
|
m.rotate(world_rotation.y, Y_AXIS);
|
||||||
|
|||||||
@@ -258,7 +258,7 @@ void main()
|
|||||||
gl_FragColor = vec4(gl_FragColor.r * lightMapColor.r, gl_FragColor.g * lightMapColor.g, gl_FragColor.b * lightMapColor.b, 1.0);
|
gl_FragColor = vec4(gl_FragColor.r * lightMapColor.r, gl_FragColor.g * lightMapColor.g, gl_FragColor.b * lightMapColor.b, 1.0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// gl_FragColor = vec4(vec3(specularFactor), 1.0);
|
//gl_FragColor = vec4(vec3(specularFactor), 1.0);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,10 +58,16 @@ void main()
|
|||||||
|
|
||||||
highp vec3 view_space_vertex_position;
|
highp vec3 view_space_vertex_position;
|
||||||
view_space_vertex_position.xy = ((2.0 * gl_FragCoord.xy) - (2.0 * viewport.xy)) / (viewport.zw) - 1.0;
|
view_space_vertex_position.xy = ((2.0 * gl_FragCoord.xy) - (2.0 * viewport.xy)) / (viewport.zw) - 1.0;
|
||||||
view_space_vertex_position.z = -texture2D(gbuffer_depth, gbuffer_uv).r;
|
//view_space_vertex_position.z = -texture2D(gbuffer_depth, gbuffer_uv).r * 2.0;
|
||||||
|
view_space_vertex_position.z = (2.0 * -texture2D(gbuffer_depth, gbuffer_uv).r - gl_DepthRange.near - gl_DepthRange.far) /
|
||||||
|
(gl_DepthRange.far - gl_DepthRange.near);
|
||||||
|
|
||||||
|
|
||||||
highp vec3 halfVec = normalize((normalize(vec3(0.0, 0.0, 0.0) - view_space_vertex_position) + view_space_light)); // Normalizing anyways, no need to divide by 2
|
highp vec3 halfVec = normalize((normalize(vec3(0.0, 0.0, 0.0) - view_space_vertex_position) + view_space_light)); // Normalizing anyways, no need to divide by 2
|
||||||
mediump float specularFactor = clamp(pow(dot(halfVec,normalize(gbuffer_normal)), gbuffer_specular_exponent), 0.0, 1.0);
|
mediump float specularFactor = 0.0;
|
||||||
|
if(gbuffer_specular_exponent > 0.0) {
|
||||||
|
specularFactor = clamp(pow(dot(halfVec,normalize(gbuffer_normal)), gbuffer_specular_exponent), 0.0, 1.0);
|
||||||
|
}
|
||||||
|
|
||||||
gl_FragColor = vec4(vec3(lamberFactor), specularFactor);
|
gl_FragColor = vec4(vec3(lamberFactor), specularFactor);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user