Point lights now fully functional with deferred lighting
--HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4054
This commit is contained in:
@@ -27,8 +27,8 @@ std::string KRDirectionalLight::getElementName() {
|
||||
return "directional_light";
|
||||
}
|
||||
|
||||
KRVector3 KRDirectionalLight::getLightDirection() {
|
||||
KRVector3 world_rotation = getWorldRotation();
|
||||
KRVector3 KRDirectionalLight::getWorldLightDirection() {
|
||||
KRVector3 world_rotation = getLocalRotation();
|
||||
KRVector3 light_rotation = KRVector3(0.0, 0.0, 1.0);
|
||||
KRMat4 m;
|
||||
m.rotate(world_rotation.x, X_AXIS);
|
||||
@@ -38,6 +38,10 @@ KRVector3 KRDirectionalLight::getLightDirection() {
|
||||
return light_direction;
|
||||
}
|
||||
|
||||
KRVector3 KRDirectionalLight::getLocalLightDirection() {
|
||||
return KRVector3(0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
void KRDirectionalLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, bool bRenderShadowMap, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, int gBufferPass) {
|
||||
@@ -52,19 +56,39 @@ void KRDirectionalLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundi
|
||||
matModelToView.transpose();
|
||||
matModelToView.invert();
|
||||
|
||||
KRVector3 light_direction = getLightDirection();
|
||||
light_direction = matModelToView.dot(light_direction);
|
||||
light_direction.normalize();
|
||||
KRVector3 light_direction_view_space = getWorldLightDirection();
|
||||
light_direction_view_space = matModelToView.dot(light_direction_view_space);
|
||||
light_direction_view_space.normalize();
|
||||
|
||||
KRShader *pShader = pContext->getShaderManager()->getShader("light_directional", pCamera, false, false, false, 0, false, false, false, false, false, false, false, gBufferPass);
|
||||
pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, light_direction, pShadowMatrices, shadowDepthTextures, 0, gBufferPass);
|
||||
pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, gBufferPass);
|
||||
|
||||
|
||||
glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR],
|
||||
m_color.x * m_intensity / 100.0f,
|
||||
m_color.y * m_intensity / 100.0f,
|
||||
m_color.z * m_intensity / 100.0f
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_DIRECTION_VIEW_SPACE],
|
||||
light_direction_view_space.x,
|
||||
light_direction_view_space.y,
|
||||
light_direction_view_space.z
|
||||
);
|
||||
|
||||
glUniform3f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR],
|
||||
m_color.x,
|
||||
m_color.y,
|
||||
m_color.z
|
||||
);
|
||||
|
||||
glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_INTENSITY],
|
||||
m_intensity / 100.0f
|
||||
);
|
||||
|
||||
// Disable z-buffer write
|
||||
glDepthMask(GL_FALSE);
|
||||
|
||||
// Disable z-buffer test
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
// Render a full screen quad
|
||||
static const GLfloat squareVertices[] = {
|
||||
-1.0f, -1.0f,
|
||||
@@ -73,9 +97,6 @@ void KRDirectionalLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundi
|
||||
1.0f, 1.0f,
|
||||
};
|
||||
|
||||
// Disable z-buffer test
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices);
|
||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
|
||||
|
||||
Reference in New Issue
Block a user