Light mapping implemented

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4023
This commit is contained in:
kearwood
2012-03-29 19:39:28 +00:00
parent 35d138c31c
commit 5498499b51
23 changed files with 136 additions and 70 deletions

View File

@@ -32,9 +32,11 @@
#include <iostream>
#import "KRInstance.h"
KRInstance::KRInstance(KRModel *pModel, const KRMat4 modelMatrix) {
KRInstance::KRInstance(KRModel *pModel, const KRMat4 modelMatrix, std::string shadow_map) {
m_pModel = pModel;
m_modelMatrix = modelMatrix;
m_shadowMap = shadow_map;
m_pShadowMap = NULL;
}
KRInstance::~KRInstance() {
@@ -50,6 +52,19 @@ KRModel *KRInstance::getModel() {
void KRInstance::render(KRCamera *pCamera, KRMaterialManager *pMaterialManager, bool bRenderShadowMap, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRShaderManager *pShaderManager, KRTextureManager *pTextureManager) {
if(m_pShadowMap == NULL && m_shadowMap.size()) {
m_pShadowMap = pTextureManager->getTexture(m_shadowMap.c_str());
}
if(cShadowBuffers == 0 && m_pShadowMap && pCamera->bEnableShadowMap && !bRenderShadowMap) {
int iTextureName = m_pShadowMap->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();
@@ -62,7 +77,7 @@ void KRInstance::render(KRCamera *pCamera, KRMaterialManager *pMaterialManager,
KRVector3 cameraPosObject = inverseModelMatrix.dot(cameraPosition);
KRVector3 lightDirObject = inverseModelMatrix.dot(lightDirection);
m_pModel->render(pCamera, pMaterialManager, bRenderShadowMap, mvpmatrix, cameraPosObject, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, pShaderManager, pTextureManager);
m_pModel->render(pCamera, pMaterialManager, bRenderShadowMap, mvpmatrix, cameraPosObject, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, pShaderManager, pTextureManager, m_pShadowMap);
}