Implemented small optimization for hardware occlusion culling.

Implemented parameter to allow hardware occlusion culling to be disabled.
This commit is contained in:
2013-04-11 15:28:59 -07:00
parent def0bae4d8
commit 94cf3f7760
4 changed files with 39 additions and 10 deletions

View File

@@ -193,7 +193,8 @@ void kraken::set_parameter(const std::string &parameter_name, float parameter_va
@"dust_enable" : @46, @"dust_enable" : @46,
@"dust_intensity" : @47, @"dust_intensity" : @47,
@"lod_bias" : @48, @"lod_bias" : @48,
@"debug_display" : @49 @"enable_realtime_occlusion" : @49,
@"debug_display" : @50
} copy]; } copy];
[self loadShaders]; [self loadShaders];
@@ -266,7 +267,7 @@ void kraken::set_parameter(const std::string &parameter_name, float parameter_va
-(int)getParameterCount -(int)getParameterCount
{ {
return 50; return 51;
} }
@@ -282,7 +283,7 @@ void kraken::set_parameter(const std::string &parameter_name, float parameter_va
-(NSString *)getParameterLabelWithIndex: (int)i -(NSString *)getParameterLabelWithIndex: (int)i
{ {
NSString *parameter_labels[50] = { NSString *parameter_labels[51] = {
@"Camera FOV", @"Camera FOV",
@"Shadow Quality (0 - 2)", @"Shadow Quality (0 - 2)",
@"Enable per-pixel lighting", @"Enable per-pixel lighting",
@@ -332,13 +333,14 @@ void kraken::set_parameter(const std::string &parameter_name, float parameter_va
@"Dust - Enable", @"Dust - Enable",
@"Dust - Intensity", @"Dust - Intensity",
@"LOD Bias", @"LOD Bias",
@"Realtime Occlusion Tests",
@"Debug - Display" @"Debug - Display"
}; };
return parameter_labels[i]; return parameter_labels[i];
} }
-(KREngineParameterType)getParameterTypeWithIndex: (int)i -(KREngineParameterType)getParameterTypeWithIndex: (int)i
{ {
KREngineParameterType types[50] = { KREngineParameterType types[51] = {
KRENGINE_PARAMETER_FLOAT, KRENGINE_PARAMETER_FLOAT,
KRENGINE_PARAMETER_INT, KRENGINE_PARAMETER_INT,
@@ -389,13 +391,14 @@ void kraken::set_parameter(const std::string &parameter_name, float parameter_va
KRENGINE_PARAMETER_BOOL, KRENGINE_PARAMETER_BOOL,
KRENGINE_PARAMETER_FLOAT, KRENGINE_PARAMETER_FLOAT,
KRENGINE_PARAMETER_FLOAT, KRENGINE_PARAMETER_FLOAT,
KRENGINE_PARAMETER_BOOL,
KRENGINE_PARAMETER_INT KRENGINE_PARAMETER_INT
}; };
return types[i]; return types[i];
} }
-(float)getParameterValueWithIndex: (int)i -(float)getParameterValueWithIndex: (int)i
{ {
float values[50] = { float values[51] = {
_settings.perspective_fov, _settings.perspective_fov,
(float)_settings.m_cShadowBuffers, (float)_settings.m_cShadowBuffers,
_settings.bEnablePerPixel ? 1.0f : 0.0f, _settings.bEnablePerPixel ? 1.0f : 0.0f,
@@ -445,6 +448,7 @@ void kraken::set_parameter(const std::string &parameter_name, float parameter_va
_settings.dust_particle_enable, _settings.dust_particle_enable,
_settings.dust_particle_intensity, _settings.dust_particle_intensity,
_settings.getLODBias(), _settings.getLODBias(),
_settings.getEnableRealtimeOcclusion(),
_settings.debug_display _settings.debug_display
}; };
return values[i]; return values[i];
@@ -642,6 +646,9 @@ void kraken::set_parameter(const std::string &parameter_name, float parameter_va
_settings.setLODBias(v); _settings.setLODBias(v);
break; break;
case 49: case 49:
_settings.setEnableRealtimeOcclusion(bNewBoolVal);
break;
case 50:
_settings.debug_display = (KRRenderSettings::debug_display_type)v; _settings.debug_display = (KRRenderSettings::debug_display_type)v;
break; break;
} }
@@ -649,12 +656,12 @@ void kraken::set_parameter(const std::string &parameter_name, float parameter_va
-(float)getParameterMinWithIndex: (int)i -(float)getParameterMinWithIndex: (int)i
{ {
float minValues[50] = { float minValues[51] = {
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.01f, 50.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.01f, 50.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, -10.0f, 0.0f 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -10.0f, 0.0f, 0.0f
}; };
return minValues[i]; return minValues[i];
@@ -662,12 +669,12 @@ void kraken::set_parameter(const std::string &parameter_name, float parameter_va
-(float)getParameterMaxWithIndex: (int)i -(float)getParameterMaxWithIndex: (int)i
{ {
float maxValues[50] = { float maxValues[51] = {
PI, 3.0f, 1.0f, 1.0, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 10.0f, PI, 3.0f, 1.0f, 1.0, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 10.0f,
1.0f, 10.0f, 2.0f, 1.0f, 1.0f, 1.0f, 5.0f, 1.0f, 0.5f, 1.0f, 1.0f, 10.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, 1.0f, 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, 10.0f, 1000.0f, 1.0f, 5.0f, 1000.0f, 1.0f, 5.0f, 3.0f, 1.0f, 1.0f, 10.0f, 1000.0f, 1.0f, 5.0f, 1000.0f, 1.0f, 5.0f, 3.0f,
1000.0f, 1000.0f, 0.01f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 10.0f, (float)(KRRenderSettings::KRENGINE_DEBUG_DISPLAY_NUMBER - 1) 1000.0f, 1000.0f, 0.01f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 10.0f, 1.0f, (float)(KRRenderSettings::KRENGINE_DEBUG_DISPLAY_NUMBER - 1)
}; };
return maxValues[i]; return maxValues[i];

View File

@@ -11,6 +11,7 @@
KRRenderSettings::KRRenderSettings() KRRenderSettings::KRRenderSettings()
{ {
m_enable_realtime_occlusion = true;
bShowShadowBuffer = false; bShowShadowBuffer = false;
bShowOctree = false; bShowOctree = false;
bShowDeferred = false; bShowDeferred = false;
@@ -192,3 +193,12 @@ void KRRenderSettings::setLODBias(float v)
{ {
m_lodBias = v; m_lodBias = v;
} }
bool KRRenderSettings::getEnableRealtimeOcclusion()
{
return m_enable_realtime_occlusion;
}
void KRRenderSettings::setEnableRealtimeOcclusion(bool enable)
{
m_enable_realtime_occlusion = enable;
}

View File

@@ -97,8 +97,12 @@ public:
KRENGINE_DEBUG_DISPLAY_NUMBER KRENGINE_DEBUG_DISPLAY_NUMBER
} debug_display; } debug_display;
bool getEnableRealtimeOcclusion();
void setEnableRealtimeOcclusion(bool enable);
private: private:
float m_lodBias; float m_lodBias;
bool m_enable_realtime_occlusion;
}; };
#endif #endif

View File

@@ -201,6 +201,11 @@ void KRScene::render(KROctreeNode *pOctreeNode, std::map<KRAABB, int> &visibleBo
bool bVisible = false; bool bVisible = false;
bool bNeedOcclusionTest = true; bool bNeedOcclusionTest = true;
if(!pCamera->settings.getEnableRealtimeOcclusion()) {
bVisible = true;
bNeedOcclusionTest = false;
}
if(!bVisible) { if(!bVisible) {
// Assume bounding boxes are visible without occlusion test queries if the camera is inside the box. // Assume bounding boxes are visible without occlusion test queries if the camera is inside the box.
// The near clipping plane of the camera is taken into consideration by expanding the match area // The near clipping plane of the camera is taken into consideration by expanding the match area
@@ -239,7 +244,10 @@ void KRScene::render(KROctreeNode *pOctreeNode, std::map<KRAABB, int> &visibleBo
for(int i=0; i<8; i++) { for(int i=0; i<8; i++) {
if(pOctreeNode->getChildren()[i] != NULL) child_count++; if(pOctreeNode->getChildren()[i] != NULL) child_count++;
} }
if(child_count == 1) bVisible = true; if(child_count == 1) {
bVisible = true;
bNeedOcclusionTest = false;
}
} }
} }