Implemented Deferred Point light visualization
--HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4093
This commit is contained in:
@@ -48,6 +48,7 @@ KRCamera::KRCamera(KRContext &context, GLint width, GLint height) : KRNotified(c
|
|||||||
|
|
||||||
bShowShadowBuffer = false;
|
bShowShadowBuffer = false;
|
||||||
bShowOctree = false;
|
bShowOctree = false;
|
||||||
|
bShowDeferred = false;
|
||||||
bEnablePerPixel = true;
|
bEnablePerPixel = true;
|
||||||
bEnableDiffuseMap = true;
|
bEnableDiffuseMap = true;
|
||||||
bEnableNormalMap = true;
|
bEnableNormalMap = true;
|
||||||
@@ -416,7 +417,7 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
|
|||||||
glDepthMask(GL_TRUE);
|
glDepthMask(GL_TRUE);
|
||||||
|
|
||||||
|
|
||||||
fprintf(stderr, "VBO Mem: %i Kbyte Texture Mem: %i Kbyte\n", (int)m_pContext->getModelManager()->getMemUsed() / 1024, (int)m_pContext->getTextureManager()->getMemUsed() / 1024);
|
//fprintf(stderr, "VBO Mem: %i Kbyte Texture Mem: %i Kbyte\n", (int)m_pContext->getModelManager()->getMemUsed() / 1024, (int)m_pContext->getTextureManager()->getMemUsed() / 1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ public:
|
|||||||
bool bDebugSuperShiny;
|
bool bDebugSuperShiny;
|
||||||
bool bShowShadowBuffer;
|
bool bShowShadowBuffer;
|
||||||
bool bShowOctree;
|
bool bShowOctree;
|
||||||
|
bool bShowDeferred;
|
||||||
bool bEnableAmbient;
|
bool bEnableAmbient;
|
||||||
bool bEnableDiffuse;
|
bool bEnableDiffuse;
|
||||||
bool bEnableSpecular;
|
bool bEnableSpecular;
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ void KRDirectionalLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundi
|
|||||||
|
|
||||||
KRLight::render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
KRLight::render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
||||||
|
|
||||||
|
|
||||||
if(renderPass == KRNode::RENDER_PASS_DEFERRED_LIGHTS) {
|
if(renderPass == KRNode::RENDER_PASS_DEFERRED_LIGHTS) {
|
||||||
// Lights are rendered on the second pass of the deferred renderer
|
// Lights are rendered on the second pass of the deferred renderer
|
||||||
|
|
||||||
|
|||||||
@@ -90,7 +90,8 @@ double const PI = 3.141592653589793f;
|
|||||||
@"debug_enable_specular" : @28,
|
@"debug_enable_specular" : @28,
|
||||||
@"debug_super_shiny" : @29,
|
@"debug_super_shiny" : @29,
|
||||||
@"debug_octree" : @30,
|
@"debug_octree" : @30,
|
||||||
@"enable_deferred_lighting" : @31
|
@"debug_deferred" : @31,
|
||||||
|
@"enable_deferred_lighting" : @32
|
||||||
} copy];
|
} copy];
|
||||||
[self loadShaders];
|
[self loadShaders];
|
||||||
|
|
||||||
@@ -152,7 +153,7 @@ double const PI = 3.141592653589793f;
|
|||||||
|
|
||||||
-(int)getParameterCount
|
-(int)getParameterCount
|
||||||
{
|
{
|
||||||
return 32;
|
return 33;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(NSString *)getParameterNameWithIndex: (int)i
|
-(NSString *)getParameterNameWithIndex: (int)i
|
||||||
@@ -162,7 +163,7 @@ double const PI = 3.141592653589793f;
|
|||||||
|
|
||||||
-(NSString *)getParameterLabelWithIndex: (int)i
|
-(NSString *)getParameterLabelWithIndex: (int)i
|
||||||
{
|
{
|
||||||
NSString *parameter_labels[32] = {
|
NSString *parameter_labels[33] = {
|
||||||
@"Camera FOV",
|
@"Camera FOV",
|
||||||
@"Shadow Quality (0 - 2)",
|
@"Shadow Quality (0 - 2)",
|
||||||
@"Enable per-pixel lighting",
|
@"Enable per-pixel lighting",
|
||||||
@@ -194,13 +195,14 @@ double const PI = 3.141592653589793f;
|
|||||||
@"Debug - Enable Specular",
|
@"Debug - Enable Specular",
|
||||||
@"Debug - Super Shiny",
|
@"Debug - Super Shiny",
|
||||||
@"Debug - Octree Visualize",
|
@"Debug - Octree Visualize",
|
||||||
|
@"Debug - Deferred Lights Visualize",
|
||||||
@"Enable Deferred Lighting"
|
@"Enable Deferred Lighting"
|
||||||
};
|
};
|
||||||
return parameter_labels[i];
|
return parameter_labels[i];
|
||||||
}
|
}
|
||||||
-(KREngineParameterType)getParameterTypeWithIndex: (int)i
|
-(KREngineParameterType)getParameterTypeWithIndex: (int)i
|
||||||
{
|
{
|
||||||
KREngineParameterType types[32] = {
|
KREngineParameterType types[33] = {
|
||||||
|
|
||||||
KRENGINE_PARAMETER_FLOAT,
|
KRENGINE_PARAMETER_FLOAT,
|
||||||
KRENGINE_PARAMETER_INT,
|
KRENGINE_PARAMETER_INT,
|
||||||
@@ -233,13 +235,14 @@ double const PI = 3.141592653589793f;
|
|||||||
KRENGINE_PARAMETER_BOOL,
|
KRENGINE_PARAMETER_BOOL,
|
||||||
KRENGINE_PARAMETER_BOOL,
|
KRENGINE_PARAMETER_BOOL,
|
||||||
KRENGINE_PARAMETER_BOOL,
|
KRENGINE_PARAMETER_BOOL,
|
||||||
|
KRENGINE_PARAMETER_BOOL,
|
||||||
KRENGINE_PARAMETER_BOOL
|
KRENGINE_PARAMETER_BOOL
|
||||||
};
|
};
|
||||||
return types[i];
|
return types[i];
|
||||||
}
|
}
|
||||||
-(double)getParameterValueWithIndex: (int)i
|
-(double)getParameterValueWithIndex: (int)i
|
||||||
{
|
{
|
||||||
double values[32] = {
|
double values[33] = {
|
||||||
_camera->perspective_fov,
|
_camera->perspective_fov,
|
||||||
(double)_camera->m_cShadowBuffers,
|
(double)_camera->m_cShadowBuffers,
|
||||||
_camera->bEnablePerPixel ? 1.0f : 0.0f,
|
_camera->bEnablePerPixel ? 1.0f : 0.0f,
|
||||||
@@ -271,6 +274,7 @@ double const PI = 3.141592653589793f;
|
|||||||
_camera->bEnableSpecular ? 1.0f : 0.0f,
|
_camera->bEnableSpecular ? 1.0f : 0.0f,
|
||||||
_camera->bDebugSuperShiny ? 1.0f : 0.0f,
|
_camera->bDebugSuperShiny ? 1.0f : 0.0f,
|
||||||
_camera->bShowOctree ? 1.0f : 0.0f,
|
_camera->bShowOctree ? 1.0f : 0.0f,
|
||||||
|
_camera->bShowDeferred ? 1.0f : 0.0f,
|
||||||
_camera->bEnableDeferredLighting ? 1.0f : 0.0f
|
_camera->bEnableDeferredLighting ? 1.0f : 0.0f
|
||||||
};
|
};
|
||||||
return values[i];
|
return values[i];
|
||||||
@@ -418,6 +422,11 @@ double const PI = 3.141592653589793f;
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 31:
|
case 31:
|
||||||
|
if(_camera->bShowDeferred != bNewBoolVal) {
|
||||||
|
_camera->bShowDeferred = bNewBoolVal;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 32:
|
||||||
if(_camera->bEnableDeferredLighting != bNewBoolVal) {
|
if(_camera->bEnableDeferredLighting != bNewBoolVal) {
|
||||||
_camera->bEnableDeferredLighting = bNewBoolVal;
|
_camera->bEnableDeferredLighting = bNewBoolVal;
|
||||||
}
|
}
|
||||||
@@ -427,22 +436,22 @@ double const PI = 3.141592653589793f;
|
|||||||
|
|
||||||
-(double)getParameterMinWithIndex: (int)i
|
-(double)getParameterMinWithIndex: (int)i
|
||||||
{
|
{
|
||||||
double minValues[32] = {
|
double minValues[33] = {
|
||||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
|
||||||
0.0f, 0.0f
|
0.0f, 0.0f, 0.0f
|
||||||
};
|
};
|
||||||
return minValues[i];
|
return minValues[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(double)getParameterMaxWithIndex: (int)i
|
-(double)getParameterMaxWithIndex: (int)i
|
||||||
{
|
{
|
||||||
double maxValues[32] = {
|
double maxValues[33] = {
|
||||||
PI, 3.0f, 1.0f, 1.0, 1.0f, 1.0f, 1.0f, 1.0f, 3.0f, 3.0f,
|
PI, 3.0f, 1.0f, 1.0, 1.0f, 1.0f, 1.0f, 1.0f, 3.0f, 3.0f,
|
||||||
3.0f, 3.0f, 3.0f, 3.0f, 2.0f, 1.0f, 1.0f, 1.0f, 5.0f, 1.0f,
|
3.0f, 3.0f, 3.0f, 3.0f, 2.0f, 1.0f, 1.0f, 1.0f, 5.0f, 1.0f,
|
||||||
0.5f, 1.0f, 2.0f, 2.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
|
0.5f, 1.0f, 2.0f, 2.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
|
||||||
1.0f, 1.0f
|
1.0f, 1.0f, 1.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
return maxValues[i];
|
return maxValues[i];
|
||||||
|
|||||||
@@ -41,7 +41,9 @@ void KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolu
|
|||||||
KRLight::render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
KRLight::render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
||||||
|
|
||||||
|
|
||||||
if(renderPass == KRNode::RENDER_PASS_DEFERRED_LIGHTS) {
|
bool bVisualize = renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && pCamera->bShowDeferred;
|
||||||
|
|
||||||
|
if(renderPass == KRNode::RENDER_PASS_DEFERRED_LIGHTS || bVisualize) {
|
||||||
// Lights are rendered on the second pass of the deferred renderer
|
// Lights are rendered on the second pass of the deferred renderer
|
||||||
|
|
||||||
KRMat4 projectionMatrix = pCamera->getProjectionMatrix();
|
KRMat4 projectionMatrix = pCamera->getProjectionMatrix();
|
||||||
@@ -78,8 +80,10 @@ void KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolu
|
|||||||
|
|
||||||
bool bInsideLight = view_light_position.sqrMagnitude() <= (influence_radius + pCamera->perspective_nearz) * (influence_radius + pCamera->perspective_nearz);
|
bool bInsideLight = view_light_position.sqrMagnitude() <= (influence_radius + pCamera->perspective_nearz) * (influence_radius + pCamera->perspective_nearz);
|
||||||
|
|
||||||
KRShader *pShader = pContext->getShaderManager()->getShader(bInsideLight ? "light_point_inside" : "light_point", pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, false, renderPass);
|
KRShader *pShader = pContext->getShaderManager()->getShader(bVisualize ? "visualize_overlay" : (bInsideLight ? "light_point_inside" : "light_point"), pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, false, renderPass);
|
||||||
pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass);
|
pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass);
|
||||||
|
|
||||||
|
|
||||||
glUniform3f(
|
glUniform3f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR],
|
||||||
m_color.x,
|
m_color.x,
|
||||||
@@ -126,6 +130,13 @@ void KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolu
|
|||||||
matInvProjection.invert();
|
matInvProjection.invert();
|
||||||
glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_INVP], 1, GL_FALSE, matInvProjection.getPointer());
|
glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_INVP], 1, GL_FALSE, matInvProjection.getPointer());
|
||||||
|
|
||||||
|
|
||||||
|
if(bVisualize) {
|
||||||
|
// Enable additive blending
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_ONE, GL_ONE);
|
||||||
|
}
|
||||||
|
|
||||||
// Disable z-buffer write
|
// Disable z-buffer write
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
|
|
||||||
@@ -160,6 +171,12 @@ void KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolu
|
|||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
|
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, m_cVertices);
|
glDrawArrays(GL_TRIANGLES, 0, m_cVertices);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(bVisualize) {
|
||||||
|
// Enable alpha blending
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user