Deferred lighting now working with directional lights
--HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4047
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
#include <iostream>
|
||||
|
||||
#import "KRDirectionalLight.h"
|
||||
#import "KRShader.h"
|
||||
#import "KRContext.h"
|
||||
|
||||
KRDirectionalLight::KRDirectionalLight(std::string name) : KRLight(name)
|
||||
{
|
||||
@@ -30,48 +32,34 @@ void KRDirectionalLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundi
|
||||
|
||||
if(gBufferPass == 2) {
|
||||
// Lights are rendered on the second pass of the deferred renderer
|
||||
/*
|
||||
|
||||
if(m_pModel == NULL) {
|
||||
m_pModel = pContext->getModelManager()->getModel(m_model_name.c_str());
|
||||
}
|
||||
|
||||
if(m_pModel != NULL && (getExtents(pContext).test_intersect(frustrumVolume) || bRenderShadowMap)) {
|
||||
|
||||
if(m_pLightMap == NULL && m_lightMap.size()) {
|
||||
m_pLightMap = pContext->getTextureManager()->getTexture(m_lightMap.c_str());
|
||||
}
|
||||
|
||||
if(cShadowBuffers == 0 && m_pLightMap && pCamera->bEnableLightMap && !bRenderShadowMap) {
|
||||
int iTextureName = m_pLightMap->getName();
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
glBindTexture(GL_TEXTURE_2D, iTextureName);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
}
|
||||
|
||||
KRMat4 projectionMatrix;
|
||||
if(!bRenderShadowMap) {
|
||||
projectionMatrix = pCamera->getProjectionMatrix();
|
||||
}
|
||||
KRMat4 mvpmatrix = m_modelMatrix * viewMatrix * projectionMatrix;
|
||||
KRMat4 matModelToView = viewMatrix * m_modelMatrix;
|
||||
matModelToView.transpose();
|
||||
matModelToView.invert();
|
||||
|
||||
// Transform location of camera to object space for calculation of specular halfVec
|
||||
KRMat4 inverseModelMatrix = m_modelMatrix;
|
||||
inverseModelMatrix.invert();
|
||||
KRVector3 cameraPosObject = inverseModelMatrix.dot(cameraPosition);
|
||||
KRVector3 lightDirObject = inverseModelMatrix.dot(lightDirection);
|
||||
|
||||
m_pModel->render(pCamera, pContext, bRenderShadowMap, matModelToView, mvpmatrix, cameraPosObject, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, m_pLightMap, gBufferPass);
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
KRMat4 projectionMatrix = pCamera->getProjectionMatrix();
|
||||
|
||||
KRMat4 mvpmatrix = m_modelMatrix * viewMatrix * projectionMatrix;
|
||||
KRMat4 matModelToView = viewMatrix * m_modelMatrix;
|
||||
matModelToView.transpose();
|
||||
matModelToView.invert();
|
||||
|
||||
|
||||
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, lightDirection, pShadowMatrices, shadowDepthTextures, 0, gBufferPass);
|
||||
|
||||
|
||||
// Render a full screen quad
|
||||
static const GLfloat squareVertices[] = {
|
||||
-1.0f, -1.0f,
|
||||
1.0f, -1.0f,
|
||||
-1.0f, 1.0f,
|
||||
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);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
|
||||
KRNode::render(pCamera, pContext, frustrumVolume, bRenderShadowMap, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, gBufferPass);
|
||||
|
||||
Reference in New Issue
Block a user