Specular calculations for deferred lighting in progress

Have integrated the position of the directional light in the scene graph (imported from fbx) with the forward renderer and deferred lighting renderer's directional light angle

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4048
This commit is contained in:
kearwood
2012-04-19 23:39:32 +00:00
parent 2ead2995d5
commit 21762174bf
14 changed files with 148 additions and 17 deletions

View File

@@ -11,6 +11,7 @@
#import "KRDirectionalLight.h"
#import "KRShader.h"
#import "KRContext.h"
#import "KRMat4.h"
KRDirectionalLight::KRDirectionalLight(std::string name) : KRLight(name)
{
@@ -26,6 +27,17 @@ std::string KRDirectionalLight::getElementName() {
return "directional_light";
}
KRVector3 KRDirectionalLight::getLightDirection() {
KRVector3 world_rotation = getWorldRotation();
KRVector3 light_rotation = KRVector3(0.0, -1.0, 0.0);
KRMat4 m;
m.rotate(world_rotation.x, X_AXIS);
m.rotate(world_rotation.y, Y_AXIS);
m.rotate(world_rotation.z, Z_AXIS);
KRVector3 light_direction = m.dot(light_rotation);
return light_direction;
}
#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) {
@@ -40,9 +52,12 @@ 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();
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);
pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, light_direction, pShadowMatrices, shadowDepthTextures, 0, gBufferPass);
// Render a full screen quad