Specular calculations for deferred lighting in progress
--HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4049
This commit is contained in:
@@ -60,7 +60,6 @@ KRCamera::KRCamera() {
|
|||||||
dSunB = 0.70f;
|
dSunB = 0.70f;
|
||||||
|
|
||||||
perspective_fov = PI / 8.0;
|
perspective_fov = PI / 8.0;
|
||||||
perspective_aspect = 1.3333;
|
|
||||||
perspective_nearz = 0.25f;
|
perspective_nearz = 0.25f;
|
||||||
perspective_farz = 100.0f;
|
perspective_farz = 100.0f;
|
||||||
|
|
||||||
@@ -86,8 +85,7 @@ KRCamera::~KRCamera() {
|
|||||||
|
|
||||||
KRMat4 KRCamera::getProjectionMatrix() {
|
KRMat4 KRCamera::getProjectionMatrix() {
|
||||||
KRMat4 projectionMatrix;
|
KRMat4 projectionMatrix;
|
||||||
projectionMatrix.perspective(perspective_fov, perspective_aspect, perspective_nearz, perspective_farz);
|
projectionMatrix.perspective(perspective_fov, m_viewportSize.x / m_viewportSize.y, perspective_nearz, perspective_farz);
|
||||||
projectionMatrix.rotate(-90 * 0.0174532925199, Z_AXIS);
|
|
||||||
return projectionMatrix;
|
return projectionMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ public:
|
|||||||
double perspective_fov;
|
double perspective_fov;
|
||||||
double perspective_nearz;
|
double perspective_nearz;
|
||||||
double perspective_farz;
|
double perspective_farz;
|
||||||
double perspective_aspect;
|
|
||||||
|
|
||||||
int dof_quality;
|
int dof_quality;
|
||||||
double dof_depth;
|
double dof_depth;
|
||||||
|
|||||||
@@ -121,7 +121,6 @@ typedef enum KREngineParameterType {KRENGINE_PARAMETER_INT, KRENGINE_PARAMETER_F
|
|||||||
- (void)renderScene: (KRScene *)pScene WithPosition: (KRVector3)position Yaw: (GLfloat)yaw Pitch: (GLfloat)pitch Roll: (GLfloat)roll;
|
- (void)renderScene: (KRScene *)pScene WithPosition: (KRVector3)position Yaw: (GLfloat)yaw Pitch: (GLfloat)pitch Roll: (GLfloat)roll;
|
||||||
- (void)setNearZ: (double)dNearZ;
|
- (void)setNearZ: (double)dNearZ;
|
||||||
- (void)setFarZ: (double)dFarZ;
|
- (void)setFarZ: (double)dFarZ;
|
||||||
- (void)setAspect: (double)dAspect;
|
|
||||||
- (void)setDebugText: (NSString *)text;
|
- (void)setDebugText: (NSString *)text;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -210,11 +210,14 @@ double const PI = 3.141592653589793f;
|
|||||||
viewMatrix.rotate(yaw, Y_AXIS);
|
viewMatrix.rotate(yaw, Y_AXIS);
|
||||||
viewMatrix.rotate(pitch, X_AXIS);
|
viewMatrix.rotate(pitch, X_AXIS);
|
||||||
viewMatrix.rotate(roll, Z_AXIS);
|
viewMatrix.rotate(roll, Z_AXIS);
|
||||||
|
|
||||||
[self renderScene: pScene WithViewMatrix: viewMatrix];
|
[self renderScene: pScene WithViewMatrix: viewMatrix];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)renderScene: (KRScene *)pScene WithViewMatrix: (KRMat4)viewMatrix
|
- (void)renderScene: (KRScene *)pScene WithViewMatrix: (KRMat4)viewMatrix
|
||||||
{
|
{
|
||||||
|
viewMatrix.rotate(-90 * 0.0174532925199, Z_AXIS);
|
||||||
|
|
||||||
KRMat4 invViewMatrix = viewMatrix;
|
KRMat4 invViewMatrix = viewMatrix;
|
||||||
invViewMatrix.invert();
|
invViewMatrix.invert();
|
||||||
|
|
||||||
@@ -248,7 +251,7 @@ double const PI = 3.141592653589793f;
|
|||||||
|
|
||||||
newShadowMVP = ext.calcShadowProj(pScene, m_pContext, sun_yaw, sun_pitch);
|
newShadowMVP = ext.calcShadowProj(pScene, m_pContext, sun_yaw, sun_pitch);
|
||||||
} else {
|
} else {
|
||||||
KRBoundingVolume frustrumSliceVolume = KRBoundingVolume(viewMatrix, m_camera.perspective_fov, m_camera.perspective_aspect, m_camera.perspective_nearz + (m_camera.perspective_farz - m_camera.perspective_nearz) * shadowMinDepths[m_cShadowBuffers - 1][iShadow], m_camera.perspective_nearz + (m_camera.perspective_farz - m_camera.perspective_nearz) * shadowMaxDepths[m_cShadowBuffers - 1][iShadow]);
|
KRBoundingVolume frustrumSliceVolume = KRBoundingVolume(viewMatrix, m_camera.perspective_fov, m_camera.getViewportSize().x / m_camera.getViewportSize().y, m_camera.perspective_nearz + (m_camera.perspective_farz - m_camera.perspective_nearz) * shadowMinDepths[m_cShadowBuffers - 1][iShadow], m_camera.perspective_nearz + (m_camera.perspective_farz - m_camera.perspective_nearz) * shadowMaxDepths[m_cShadowBuffers - 1][iShadow]);
|
||||||
newShadowMVP = frustrumSliceVolume.calcShadowProj(pScene, m_pContext, sun_yaw, sun_pitch);
|
newShadowMVP = frustrumSliceVolume.calcShadowProj(pScene, m_pContext, sun_yaw, sun_pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,7 +363,7 @@ double const PI = 3.141592653589793f;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
KRBoundingVolume frustrumVolume = KRBoundingVolume(viewMatrix, m_camera.perspective_fov, m_camera.perspective_aspect, m_camera.perspective_nearz, m_camera.perspective_farz);
|
KRBoundingVolume frustrumVolume = KRBoundingVolume(viewMatrix, m_camera.perspective_fov, m_camera.getViewportSize().x / m_camera.getViewportSize().y, m_camera.perspective_nearz, m_camera.perspective_farz);
|
||||||
if(m_camera.bEnableDeferredLighting) {
|
if(m_camera.bEnableDeferredLighting) {
|
||||||
// ----====---- Opaque Geometry, Deferred rendering Pass 1 ----====----
|
// ----====---- Opaque Geometry, Deferred rendering Pass 1 ----====----
|
||||||
|
|
||||||
@@ -1238,13 +1241,6 @@ double const PI = 3.141592653589793f;
|
|||||||
[self invalidateShadowBuffers];
|
[self invalidateShadowBuffers];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
- (void)setAspect: (double)dAspect
|
|
||||||
{
|
|
||||||
if(m_camera.perspective_aspect != dAspect) {
|
|
||||||
m_camera.perspective_aspect = dAspect;
|
|
||||||
[self invalidateShadowBuffers];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setDebugText: (NSString *)text
|
- (void)setDebugText: (NSString *)text
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,12 +41,7 @@ void main()
|
|||||||
|
|
||||||
mediump vec2 gbuffer_uv = vec2(gl_FragCoord.xy / viewport.zw);
|
mediump vec2 gbuffer_uv = vec2(gl_FragCoord.xy / viewport.zw);
|
||||||
|
|
||||||
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.z = -(2.0 * texture2D(gbuffer_depth, gbuffer_uv).r - gl_DepthRange.near - gl_DepthRange.far) /
|
|
||||||
(gl_DepthRange.far - gl_DepthRange.near) - 1.0;
|
|
||||||
*/
|
|
||||||
view_space_vertex_position.z = -texture2D(gbuffer_depth, gbuffer_uv).r;
|
|
||||||
|
|
||||||
|
|
||||||
lowp vec4 gbuffer_sample = texture2D(gbuffer_frame, gbuffer_uv);
|
lowp vec4 gbuffer_sample = texture2D(gbuffer_frame, gbuffer_uv);
|
||||||
@@ -61,15 +56,12 @@ void main()
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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.z = -texture2D(gbuffer_depth, gbuffer_uv).r;
|
||||||
|
|
||||||
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);
|
||||||
//highp vec3 halfVec = normalize(view_space_light - normalize(view_space_vertex_position));
|
|
||||||
//highp vec3 halfVec = normalize(vec3(0.0, 0.0, -1.0) - normalize(view_space_vertex_position));
|
|
||||||
|
|
||||||
mediump float specularFactor = max(0.0,pow(clamp(dot(halfVec,normalize(gbuffer_normal)), 0.0, 1.0), gbuffer_specular_exponent));
|
|
||||||
//mediump float specularFactor = 0.0;
|
|
||||||
|
|
||||||
//specularFactor = halfVec.z;
|
|
||||||
|
|
||||||
gl_FragColor = vec4(vec3(lamberFactor), specularFactor);
|
gl_FragColor = vec4(vec3(lamberFactor), specularFactor);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user