Implemented visualization of octrees for debugging occlusion culling algorithms.

Corrected project settings to allow objpack to compile again.

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4087
This commit is contained in:
kearwood
2012-09-05 18:14:08 +00:00
parent c74a85d931
commit 527bcb33c3
21 changed files with 264 additions and 45 deletions

View File

@@ -12,7 +12,7 @@
E40BA45415EFF79500D7C3DD /* KRAABB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E40BA45215EFF79500D7C3DD /* KRAABB.cpp */; };
E40BA45515EFF79500D7C3DD /* KRAABB.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E40BA45215EFF79500D7C3DD /* KRAABB.cpp */; };
E40BA45615EFF79500D7C3DD /* KRAABB.h in Headers */ = {isa = PBXBuildFile; fileRef = E40BA45315EFF79500D7C3DD /* KRAABB.h */; };
E40BA45715EFF79500D7C3DD /* KRAABB.h in Headers */ = {isa = PBXBuildFile; fileRef = E40BA45315EFF79500D7C3DD /* KRAABB.h */; };
E40BA45715EFF79500D7C3DD /* KRAABB.h in Headers */ = {isa = PBXBuildFile; fileRef = E40BA45315EFF79500D7C3DD /* KRAABB.h */; settings = {ATTRIBUTES = (Public, ); }; };
E414BAE21435557300A668C4 /* KRInstance.h in Headers */ = {isa = PBXBuildFile; fileRef = E414BAE11435557300A668C4 /* KRInstance.h */; };
E414BAE51435558900A668C4 /* KRInstance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E414BAE41435558800A668C4 /* KRInstance.cpp */; };
E414BAE7143557D200A668C4 /* KRScene.h in Headers */ = {isa = PBXBuildFile; fileRef = E414BAE6143557D200A668C4 /* KRScene.h */; };
@@ -26,11 +26,11 @@
E43B0AC915DDBB8500A5CB9F /* KRNotified.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43B0AC715DDBB8500A5CB9F /* KRNotified.cpp */; };
E43B0ACA15DDBB8500A5CB9F /* KRNotified.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43B0AC715DDBB8500A5CB9F /* KRNotified.cpp */; };
E43B0ACB15DDBB8500A5CB9F /* KRNotified.h in Headers */ = {isa = PBXBuildFile; fileRef = E43B0AC815DDBB8500A5CB9F /* KRNotified.h */; };
E43B0ACC15DDBB8500A5CB9F /* KRNotified.h in Headers */ = {isa = PBXBuildFile; fileRef = E43B0AC815DDBB8500A5CB9F /* KRNotified.h */; };
E43B0ACC15DDBB8500A5CB9F /* KRNotified.h in Headers */ = {isa = PBXBuildFile; fileRef = E43B0AC815DDBB8500A5CB9F /* KRNotified.h */; settings = {ATTRIBUTES = (Public, ); }; };
E43B0AD615DDCA0F00A5CB9F /* KRContextObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43B0AD415DDCA0C00A5CB9F /* KRContextObject.cpp */; };
E43B0AD715DDCA0F00A5CB9F /* KRContextObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43B0AD415DDCA0C00A5CB9F /* KRContextObject.cpp */; };
E43B0AD815DDCA0F00A5CB9F /* KRContextObject.h in Headers */ = {isa = PBXBuildFile; fileRef = E43B0AD515DDCA0D00A5CB9F /* KRContextObject.h */; };
E43B0AD915DDCA0F00A5CB9F /* KRContextObject.h in Headers */ = {isa = PBXBuildFile; fileRef = E43B0AD515DDCA0D00A5CB9F /* KRContextObject.h */; };
E43B0AD915DDCA0F00A5CB9F /* KRContextObject.h in Headers */ = {isa = PBXBuildFile; fileRef = E43B0AD515DDCA0D00A5CB9F /* KRContextObject.h */; settings = {ATTRIBUTES = (Public, ); }; };
E461A152152E54B500F2044A /* KRLight.h in Headers */ = {isa = PBXBuildFile; fileRef = E461A151152E54B500F2044A /* KRLight.h */; };
E461A153152E54B500F2044A /* KRLight.h in Headers */ = {isa = PBXBuildFile; fileRef = E461A151152E54B500F2044A /* KRLight.h */; settings = {ATTRIBUTES = (Public, ); }; };
E461A156152E54F800F2044A /* KRLight.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E461A155152E54F700F2044A /* KRLight.cpp */; };
@@ -53,7 +53,7 @@
E46C214515364BC8009CABF3 /* tinyxml2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46C214215364BC8009CABF3 /* tinyxml2.cpp */; };
E46C214615364BC8009CABF3 /* tinyxml2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46C214215364BC8009CABF3 /* tinyxml2.cpp */; };
E46C214715364BC8009CABF3 /* tinyxml2.h in Headers */ = {isa = PBXBuildFile; fileRef = E46C214315364BC8009CABF3 /* tinyxml2.h */; };
E46C214815364BC8009CABF3 /* tinyxml2.h in Headers */ = {isa = PBXBuildFile; fileRef = E46C214315364BC8009CABF3 /* tinyxml2.h */; };
E46C214815364BC8009CABF3 /* tinyxml2.h in Headers */ = {isa = PBXBuildFile; fileRef = E46C214315364BC8009CABF3 /* tinyxml2.h */; settings = {ATTRIBUTES = (Public, ); }; };
E46C214B15364DEC009CABF3 /* KRSceneManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46C214A15364DEC009CABF3 /* KRSceneManager.cpp */; };
E46C214C15364DEC009CABF3 /* KRSceneManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E46C214A15364DEC009CABF3 /* KRSceneManager.cpp */; };
E46DBE7B1512ACE600D59F86 /* KRMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E49E79FE1512615F009CF99C /* KRMesh.cpp */; };
@@ -75,6 +75,7 @@
E47C25A513F4F66F00FF4370 /* KRShader.h in Headers */ = {isa = PBXBuildFile; fileRef = E47C25A413F4F66F00FF4370 /* KRShader.h */; };
E47C25A713F4F6AB00FF4370 /* KRShaderManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47C25A613F4F6AB00FF4370 /* KRShaderManager.cpp */; };
E47C25A913F4F6DD00FF4370 /* KRShader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47C25A813F4F6DD00FF4370 /* KRShader.cpp */; };
E48278B115F03028001C9431 /* visualize_overlay.fsh in Sources */ = {isa = PBXBuildFile; fileRef = E48278B015F03028001C9431 /* visualize_overlay.fsh */; };
E48B3CBD14393DF5000C50E2 /* KRCamera.h in Headers */ = {isa = PBXBuildFile; fileRef = E48B3CBC14393DF5000C50E2 /* KRCamera.h */; };
E48B3CC014393E30000C50E2 /* KRCamera.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E48B3CBF14393E2F000C50E2 /* KRCamera.cpp */; };
E48C696F15374F5B00232E28 /* KRContext.h in Headers */ = {isa = PBXBuildFile; fileRef = E48C696E15374F5A00232E28 /* KRContext.h */; };
@@ -117,6 +118,13 @@
E497B95D151BF05F00D3DC67 /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E497B95C151BF05F00D3DC67 /* CoreServices.framework */; };
E497B95F151BF09600D3DC67 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E497B95E151BF09600D3DC67 /* SystemConfiguration.framework */; };
E49E79FF1512615F009CF99C /* KRMesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E49E79FE1512615F009CF99C /* KRMesh.cpp */; };
E4AFC6B615F7C46800DDB4C8 /* KRAABB.cpp in Headers */ = {isa = PBXBuildFile; fileRef = E40BA45215EFF79500D7C3DD /* KRAABB.cpp */; settings = {ATTRIBUTES = (Public, ); }; };
E4AFC6B915F7C7B200DDB4C8 /* KROctree.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4924C2415EE95E700B965C6 /* KROctree.cpp */; settings = {ATTRIBUTES = (Public, ); }; };
E4AFC6BA15F7C7C300DDB4C8 /* KRSkyBox.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1000469B15E6EF550053B072 /* KRSkyBox.cpp */; };
E4AFC6BB15F7C7D600DDB4C8 /* KROctreeNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4924C2915EE96AA00B965C6 /* KROctreeNode.cpp */; };
E4AFC6BC15F7C95D00DDB4C8 /* KRSceneManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E46C214915364DDB009CABF3 /* KRSceneManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
E4AFC6BD15F7C9DA00DDB4C8 /* KROctree.h in Headers */ = {isa = PBXBuildFile; fileRef = E4924C2515EE95E800B965C6 /* KROctree.h */; settings = {ATTRIBUTES = (Public, ); }; };
E4AFC6BE15F7C9E600DDB4C8 /* KROctreeNode.h in Headers */ = {isa = PBXBuildFile; fileRef = E4924C2A15EE96AA00B965C6 /* KROctreeNode.h */; settings = {ATTRIBUTES = (Public, ); }; };
E4B2A4391523B027004CB0EC /* KRMaterial.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017D13C99BDC0098455B /* KRMaterial.h */; settings = {ATTRIBUTES = (Public, ); }; };
E4B2A43B1523B02E004CB0EC /* KRMaterial.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017C13C99BDC0098455B /* KRMaterial.cpp */; };
E4BBBB8A1512A40300F43B5B /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = E4BBBB881512A40300F43B5B /* InfoPlist.strings */; };
@@ -218,6 +226,8 @@
E47C25A413F4F66F00FF4370 /* KRShader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRShader.h; path = Classes/KRShader.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
E47C25A613F4F6AB00FF4370 /* KRShaderManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRShaderManager.cpp; path = Classes/KRShaderManager.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
E47C25A813F4F6DD00FF4370 /* KRShader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRShader.cpp; path = Classes/KRShader.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
E48278AE15F03010001C9431 /* visualize_overlay.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = visualize_overlay.vsh; path = Shaders/visualize_overlay.vsh; sourceTree = "<group>"; };
E48278B015F03028001C9431 /* visualize_overlay.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = visualize_overlay.fsh; sourceTree = "<group>"; };
E48B3CBC14393DF5000C50E2 /* KRCamera.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRCamera.h; path = Classes/KRCamera.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
E48B3CBF14393E2F000C50E2 /* KRCamera.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRCamera.cpp; path = Classes/KRCamera.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
E48C696E15374F5A00232E28 /* KRContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRContext.h; path = Classes/KRContext.h; sourceTree = "<group>"; };
@@ -320,6 +330,8 @@
E4A9DEC0154120E8009DF363 /* light_point.vsh */,
E4769DEC158A78B6004B83AC /* flare.fsh */,
E4769DEF158A78C6004B83AC /* flare.vsh */,
E48278AE15F03010001C9431 /* visualize_overlay.vsh */,
E48278B015F03028001C9431 /* visualize_overlay.fsh */,
);
name = Shaders;
sourceTree = "<group>";
@@ -450,13 +462,13 @@
E491016613C99B9E0098455B /* KREngine */ = {
isa = PBXGroup;
children = (
E45772E313C99F160037BEEA /* Shaders */,
E491016E13C99BAE0098455B /* Classes */,
E491016713C99B9E0098455B /* Supporting Files */,
E4924C2415EE95E700B965C6 /* KROctree.cpp */,
E4924C2515EE95E800B965C6 /* KROctree.h */,
E4924C2915EE96AA00B965C6 /* KROctreeNode.cpp */,
E4924C2A15EE96AA00B965C6 /* KROctreeNode.h */,
E45772E313C99F160037BEEA /* Shaders */,
E491016713C99B9E0098455B /* Supporting Files */,
);
path = KREngine;
sourceTree = "<group>";
@@ -605,6 +617,7 @@
E4F9754415362D2900FD60B2 /* KRBoundingVolume.h in Headers */,
E4F975461536327C00FD60B2 /* KRModelManager.h in Headers */,
E497B94B151BCEE900D3DC67 /* KRResource.h in Headers */,
E43B0AD915DDCA0F00A5CB9F /* KRContextObject.h in Headers */,
E4F975331536220900FD60B2 /* KRNode.h in Headers */,
E4B2A4391523B027004CB0EC /* KRMaterial.h in Headers */,
E46DBE811512AFE600D59F86 /* KRMesh.h in Headers */,
@@ -615,6 +628,7 @@
E46DBE851512B9FA00D59F86 /* KREngine-common.h in Headers */,
E4F9754C153632F000FD60B2 /* KRCamera.h in Headers */,
E4F975501536333500FD60B2 /* KRModel.h in Headers */,
E4AFC6BC15F7C95D00DDB4C8 /* KRSceneManager.h in Headers */,
E4D133661537685A0070068C /* KRShader.h in Headers */,
E461A153152E54B500F2044A /* KRLight.h in Headers */,
E4F97552153633EF00FD60B2 /* KRMaterialManager.h in Headers */,
@@ -622,18 +636,20 @@
E46F4A09155DF6E400CCF8B8 /* KRWorld.cpp in Headers */,
E4F975541536340400FD60B2 /* KRTexture.h in Headers */,
E46F4A01155DF46700CCF8B8 /* KRWorld.h in Headers */,
E43B0ACC15DDBB8500A5CB9F /* KRNotified.h in Headers */,
E48C697015374F5B00232E28 /* KRContext.h in Headers */,
E46F4A10155E004100CCF8B8 /* KRDataBlock.cpp in Headers */,
E46C214815364BC8009CABF3 /* tinyxml2.h in Headers */,
E4D13365153767FF0070068C /* KRShaderManager.h in Headers */,
E40BA45715EFF79500D7C3DD /* KRAABB.h in Headers */,
E4AFC6B615F7C46800DDB4C8 /* KRAABB.cpp in Headers */,
E4AFC6BE15F7C9E600DDB4C8 /* KROctreeNode.h in Headers */,
E4AFC6BD15F7C9DA00DDB4C8 /* KROctree.h in Headers */,
E461A15D152E563100F2044A /* KRDirectionalLight.h in Headers */,
E461A169152E570700F2044A /* KRSpotLight.h in Headers */,
E46C214815364BC8009CABF3 /* tinyxml2.h in Headers */,
E46A6B701559EF0A000DBD37 /* KRResource+blend.h in Headers */,
E46F4A0C155E002100CCF8B8 /* KRDataBlock.h in Headers */,
E42CB1ED158446940066E0D8 /* KRQuaternion.h in Headers */,
E43B0ACC15DDBB8500A5CB9F /* KRNotified.h in Headers */,
E43B0AD915DDCA0F00A5CB9F /* KRContextObject.h in Headers */,
E40BA45715EFF79500D7C3DD /* KRAABB.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -755,6 +771,7 @@
E4924C2B15EE96AB00B965C6 /* KROctreeNode.cpp in Sources */,
1000469D15E6EF550053B072 /* KRSkyBox.cpp in Sources */,
E40BA45415EFF79500D7C3DD /* KRAABB.cpp in Sources */,
E48278B115F03028001C9431 /* visualize_overlay.fsh in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -787,12 +804,15 @@
E4D13367153768610070068C /* KRShader.cpp in Sources */,
E46C214615364BC8009CABF3 /* tinyxml2.cpp in Sources */,
E4D13364153767ED0070068C /* KRShaderManager.cpp in Sources */,
E4AFC6B915F7C7B200DDB4C8 /* KROctree.cpp in Sources */,
E46C214C15364DEC009CABF3 /* KRSceneManager.cpp in Sources */,
E48C697315374F7E00232E28 /* KRContext.cpp in Sources */,
E46A6B6D1559E97D000DBD37 /* KRResource+blend.cpp in Sources */,
E46F4A05155DF47C00CCF8B8 /* KRWorld.cpp in Sources */,
E4AFC6BA15F7C7C300DDB4C8 /* KRSkyBox.cpp in Sources */,
E46F4A0F155E003000CCF8B8 /* KRDataBlock.cpp in Sources */,
E42CB1F1158446AB0066E0D8 /* KRQuaternion.cpp in Sources */,
E4AFC6BB15F7C7D600DDB4C8 /* KROctreeNode.cpp in Sources */,
E43B0ACA15DDBB8500A5CB9F /* KRNotified.cpp in Sources */,
E43B0AD715DDCA0F00A5CB9F /* KRContextObject.cpp in Sources */,
E40BA45515EFF79500D7C3DD /* KRAABB.cpp in Sources */,

View File

@@ -36,12 +36,12 @@ bool KRAABB::operator !=(const KRAABB& b) const
return min != b.min || max != b.max;
}
KRVector3 KRAABB::center()
KRVector3 KRAABB::center() const
{
return (min + max) / 2.0f;
}
KRVector3 KRAABB::size()
KRVector3 KRAABB::size() const
{
return max - min;
}
@@ -72,4 +72,10 @@ bool KRAABB::operator <(const KRAABB& b) const
} else {
return false;
}
}
bool KRAABB::intersects(const KRAABB& b) const
{
// Return true if the two volumes intersect
return min.x <= b.max.x && min.y <= b.max.y && min.z <= b.max.z && max.x >= b.min.x && max.y >= b.min.y && max.z >= b.max.z;
}

View File

@@ -18,8 +18,9 @@ public:
KRAABB(const KRVector3 &minPoint, const KRVector3 &maxPoint);
~KRAABB();
KRVector3 center();
KRVector3 size();
KRVector3 center() const;
KRVector3 size() const;
bool intersects(const KRAABB& b) const;
KRAABB& operator =(const KRAABB& b);
bool operator ==(const KRAABB& b) const;

View File

@@ -193,6 +193,42 @@ bool KRBoundingVolume::test_intersect(const KRBoundingVolume &p) const {
return bIntersect;
}
bool KRBoundingVolume::test_intersect(const KRAABB &p) const {
// Simple, non-aligned bounding box intersection test
KRVector3 minPoint = m_vertices[0], maxPoint = m_vertices[0], minPoint2 = p.min, maxPoint2 = p.max;
for(int iVertex=1; iVertex < 8; iVertex++) {
if(m_vertices[iVertex].x < minPoint.x) {
minPoint.x = m_vertices[iVertex].x;
}
if(m_vertices[iVertex].y < minPoint.y) {
minPoint.y = m_vertices[iVertex].y;
}
if(m_vertices[iVertex].z < minPoint.z) {
minPoint.z = m_vertices[iVertex].z;
}
if(m_vertices[iVertex].x > maxPoint.x) {
maxPoint.x = m_vertices[iVertex].x;
}
if(m_vertices[iVertex].y > maxPoint.y) {
maxPoint.y = m_vertices[iVertex].y;
}
if(m_vertices[iVertex].z > maxPoint.z) {
maxPoint.z = m_vertices[iVertex].z;
}
}
bool bIntersect =
maxPoint.x >= minPoint2.x
&& maxPoint.y >= minPoint2.y
&& maxPoint.z >= minPoint2.z
&& minPoint.x <= maxPoint2.x
&& minPoint.y <= maxPoint2.y
&& minPoint.z <= maxPoint2.z;
return bIntersect;
}
KRMat4 KRBoundingVolume::calcShadowProj(KRScene *pScene, KRContext *pContext, GLfloat sun_yaw, GLfloat sun_pitch) const {
KRBoundingVolume sceneVolume = pScene->getExtents(pContext);

View File

@@ -55,6 +55,7 @@ public:
KRBoundingVolume get_union(const KRBoundingVolume &p) const;
bool test_intersect(const KRBoundingVolume &p) const;
bool test_intersect(const KRAABB &p) const;
KRMat4 calcShadowProj(KRScene *pScene, KRContext *pContext, GLfloat sun_yaw, GLfloat sun_pitch) const;
private:

View File

@@ -329,6 +329,7 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
// Render all transparent geometry
scene.render(this, m_visibleBounds, m_pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
// ----====---- Flares ----====----
// Set render target
@@ -352,12 +353,63 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
// Render all flares
scene.render(this, m_visibleBounds, m_pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_FLARES);
// Re-enable z-buffer write
glDepthMask(GL_TRUE);
// ----====---- Debug Overlay ----====----
bool bVisualize = true;
if(bVisualize) {
// Enable z-buffer test
glEnable(GL_DEPTH_TEST);
glDepthRangef(0.0, 1.0);
// Enable backface culling
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
KRShader *pVisShader = m_pContext->getShaderManager()->getShader("visualize_overlay", this, false, false, false, 0, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
KRMat4 projectionMatrix = getProjectionMatrix();
static const GLfloat cubeVertices[] = {
-1.0, 1.0, 1.0,
1.0, 1.0, 1.0,
-1.0, -1.0, 1.0,
1.0, -1.0, 1.0,
-1.0, -1.0, -1.0,
1.0, -1.0, -1.0,
-1.0, 1.0, -1.0,
1.0, 1.0, -1.0,
-1.0, 1.0, 1.0,
1.0, 1.0, 1.0,
1.0, -1.0, 1.0,
1.0, 1.0, -1.0,
1.0, -1.0, -1.0,
-1.0, -1.0, -1.0,
-1.0, 1.0, -1.0,
-1.0, -1.0, 1.0,
-1.0, 1.0, 1.0
};
glBindBuffer(GL_ARRAY_BUFFER, 0);
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, cubeVertices);
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
for(std::set<KRAABB>::iterator itr=m_visibleBounds.begin(); itr != m_visibleBounds.end(); itr++) {
KRMat4 matModel = KRMat4();
matModel.scale((*itr).size() / 2.0f);
matModel.translate((*itr).center());
KRMat4 mvpmatrix = matModel * viewMatrix * projectionMatrix;
pVisShader->bind(this, viewMatrix, mvpmatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 17);
}
}
scene.getOcclusionQueryResults(m_visibleBounds);
fprintf(stderr, "visible bounds: %i\n", (int)m_visibleBounds.size());
// Re-enable z-buffer write
glDepthMask(GL_TRUE);
}

View File

@@ -64,7 +64,7 @@ KRMat4 &KRInstance::getModelMatrix() {
return m_modelMatrix;
}
#if TARGET_OS_IPHONE
void KRInstance::loadModel() {
if(m_pModel == NULL) {
@@ -72,6 +72,8 @@ void KRInstance::loadModel() {
}
}
#if TARGET_OS_IPHONE
bool KRInstance::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
bool bRendered = KRNode::render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);

View File

@@ -149,6 +149,11 @@ void KRMat4::translate(GLfloat x, GLfloat y, GLfloat z) {
*this *= newMatrix;
}
void KRMat4::translate(const KRVector3 &v)
{
translate(v.x, v.y, v.z);
}
/* Rotate a matrix by an angle on a X, Y, or Z axis */
void KRMat4::rotate(GLfloat angle, AXIS axis) {
const int cos1[3] = { 5, 0, 0 };
@@ -177,6 +182,10 @@ void KRMat4::scale(GLfloat x, GLfloat y, GLfloat z) {
*this *= newMatrix;
}
void KRMat4::scale(const KRVector3 &v) {
scale(v.x, v.y, v.z);
}
/* Scale all dimensions equally */
void KRMat4::scale(GLfloat s) {
scale(s,s,s);

View File

@@ -93,7 +93,9 @@ public:
void perspective(GLfloat fov, GLfloat aspect, GLfloat nearz, GLfloat farz);
void ortho(GLfloat left, GLfloat right, GLfloat top, GLfloat bottom, GLfloat nearz, GLfloat farz);
void translate(GLfloat x, GLfloat y, GLfloat z);
void translate(const KRVector3 &v);
void scale(GLfloat x, GLfloat y, GLfloat z);
void scale(const KRVector3 &v);
void scale(GLfloat s);
void rotate(GLfloat angle, AXIS axis);
void bias();

View File

@@ -91,7 +91,7 @@ std::set<KRNode *> &KROctree::getOuterSceneNodes()
{
return m_outerSceneNodes;
}
#if TARGET_OS_IPHONE
void KROctree::getOcclusionQueryResults(std::set<KRAABB> &renderedBounds)
{
renderedBounds.clear();
@@ -99,4 +99,4 @@ void KROctree::getOcclusionQueryResults(std::set<KRAABB> &renderedBounds)
m_pRootNode->getOcclusionQueryResults(renderedBounds);
}
}
#endif

View File

@@ -26,9 +26,9 @@ public:
KROctreeNode *getRootNode();
std::set<KRNode *> &getOuterSceneNodes();
#if TARGET_OS_IPHONE
void getOcclusionQueryResults(std::set<KRAABB> &renderedBounds);
#endif
private:
KROctreeNode *m_pRootNode;
std::set<KRNode *>m_outerSceneNodes;

View File

@@ -40,16 +40,17 @@ KROctreeNode::~KROctreeNode()
delete m_children[i];
}
}
#if TARGET_OS_IPHONE
if(m_occlusionTested) {
glDeleteQueriesEXT(1, &m_occlusionQuery);
}
if(m_occlusionTestedTransparent) {
glDeleteQueriesEXT(1, &m_occlusionQueryTransparent);
}
#endif
}
#if TARGET_OS_IPHONE
void KROctreeNode::beginOcclusionQuery(bool bTransparentPass)
{
if(bTransparentPass && !m_occlusionTestedTransparent) {
@@ -98,6 +99,10 @@ bool KROctreeNode::getOcclusionQueryResults(std::set<KRAABB> &renderedBounds)
bGoDeeper = true;
}
// FINDME - Test Code:
bGoDeeper = true;
bRendered = true;
if(bGoDeeper) { // Only recurse deeper if we reached this level in the previous pass
for(int i=0; i<8; i++) {
if(m_children[i]) {
@@ -115,6 +120,8 @@ bool KROctreeNode::getOcclusionQueryResults(std::set<KRAABB> &renderedBounds)
return bRendered;
}
#endif
KRAABB KROctreeNode::getBounds()
{
return m_bounds;

View File

@@ -22,9 +22,9 @@
#include "KRResource+blend.h"
std::vector<KRResource *> KRResource::LoadBlenderScene(const std::string& path) {
std::vector<KRResource *> KRResource::LoadBlenderScene(KRContext &context, const std::string& path) {
std::vector<KRResource *> resources;
KRScene *pScene = new KRScene(KRResource::GetFileBase(path));
KRScene *pScene = new KRScene(context, KRResource::GetFileBase(path));
resources.push_back(pScene);
int fdFile = 0;

View File

@@ -44,10 +44,10 @@ void LoadMesh(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxGeo
void LoadLight(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxNode* pNode);
std::vector<KRResource *> KRResource::LoadFbx(const std::string& path)
std::vector<KRResource *> KRResource::LoadFbx(KRContext &context, const std::string& path)
{
std::vector<KRResource *> resources;
KRScene *pScene = new KRScene(KRResource::GetFileBase(path));
KRScene *pScene = new KRScene(context, KRResource::GetFileBase(path));
resources.push_back(pScene);
@@ -271,7 +271,7 @@ void LoadMesh(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxGeo
std::string light_map = pNode->GetName();
light_map.append("_lightmap");
KRInstance *new_instance = new KRInstance(pNode->GetName(), pNode->GetName(), KRMat4(), light_map);
KRInstance *new_instance = new KRInstance(parent_node->getScene(), pNode->GetName(), pNode->GetName(), KRMat4(), light_map);
fbxDouble3 local_rotation = pNode->GetGeometricRotation(KFbxNode::eSOURCE_SET);
fbxDouble3 local_translation = pNode->GetGeometricTranslation(KFbxNode::eSOURCE_SET);
fbxDouble3 local_scale = pNode->GetGeometricScaling(KFbxNode::eSOURCE_SET);
@@ -423,7 +423,7 @@ void LoadMesh(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxGeo
printf(" %s: %i - %i\n", pMaterial->GetName(), mat_vertex_start, mat_vertex_count + mat_vertex_start - 1);
// ----====---- Output Material File ----====----
KRMaterial *new_material = new KRMaterial(pMaterial->GetName());
KRMaterial *new_material = new KRMaterial(parent_node->getContext(), pMaterial->GetName());
KFbxPropertyDouble3 lKFbxDouble3;
KFbxPropertyDouble1 lKFbxDouble1;
@@ -509,8 +509,6 @@ void LoadMesh(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxGeo
assert(pTexture->GetRotationU() == 0.0f);
assert(pTexture->GetRotationV() == 0.0f);
assert(pTexture->GetRotationW() == 0.0f);
assert(pTexture->GetScaleU() == 1.0f);
assert(pTexture->GetScaleV() == 1.0f);
KFbxFileTexture *pFileTexture = KFbxCast<KFbxFileTexture>(pTexture);
if(pFileTexture) {
@@ -573,7 +571,7 @@ void LoadMesh(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxGeo
// ----====---- Generate Output Mesh Object ----====----
KRMesh *new_mesh = new KRMesh(pNode->GetName());
KRMesh *new_mesh = new KRMesh(parent_node->getContext(), pNode->GetName());
new_mesh->LoadData(vertices, uva, uvb, normals, tangents, submesh_starts, submesh_lengths, material_names);
resources.push_back(new_mesh);
@@ -614,20 +612,20 @@ void LoadLight(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxNo
switch(pLight->LightType.Get()) {
case KFbxLight::ePOINT:
{
KRPointLight *l = new KRPointLight(szName);
KRPointLight *l = new KRPointLight(parent_node->getScene(), szName);
new_light = l;
}
break;
case KFbxLight::eDIRECTIONAL:
{
KRDirectionalLight *l = new KRDirectionalLight(szName);
KRDirectionalLight *l = new KRDirectionalLight(parent_node->getScene(), szName);
new_light = l;
}
break;
case KFbxLight::eSPOT:
{
KRSpotLight *l = new KRSpotLight(szName);
KRSpotLight *l = new KRSpotLight(parent_node->getScene(), szName);
l->setInnerAngle(light_hotspot * d2r);
l->setOuterAngle(light_coneangle * d2r);
new_light = l;

View File

@@ -135,13 +135,17 @@ void KRScene::render(KRCamera *pCamera, std::set<KRAABB> &visibleBounds, KRConte
void KRScene::render(KROctreeNode *pOctreeNode, std::set<KRAABB> &visibleBounds, KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass)
{
if(pOctreeNode) {
pOctreeNode->beginOcclusionQuery(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
for(std::set<KRNode *>::iterator itr=pOctreeNode->getSceneNodes().begin(); itr != pOctreeNode->getSceneNodes().end(); itr++) {
(*itr)->render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
}
pOctreeNode->endOcclusionQuery();
for(int i=0; i<8; i++) {
render(pOctreeNode->getChildren()[i], visibleBounds, pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
if(frustrumVolume.test_intersect(pOctreeNode->getBounds())) { // Only recurse deeper if within the view frustrum
pOctreeNode->beginOcclusionQuery(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
for(std::set<KRNode *>::iterator itr=pOctreeNode->getSceneNodes().begin(); itr != pOctreeNode->getSceneNodes().end(); itr++) {
(*itr)->render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
}
pOctreeNode->endOcclusionQuery();
for(int i=0; i<8; i++) {
render(pOctreeNode->getChildren()[i], visibleBounds, pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
}
} else {
fprintf(stderr, "Octree culled: (%f, %f, %f) - (%f, %f, %f)\n", pOctreeNode->getBounds().min.x, pOctreeNode->getBounds().min.y, pOctreeNode->getBounds().min.z, pOctreeNode->getBounds().max.x, pOctreeNode->getBounds().max.y, pOctreeNode->getBounds().max.z);
}
}
}
@@ -260,8 +264,11 @@ void KRScene::updateOctree()
m_newNodes.clear();
m_modifiedNodes.clear();
}
#if TARGET_OS_IPHONE
void KRScene::getOcclusionQueryResults(std::set<KRAABB> &renderedBounds)
{
m_nodeTree.getOcclusionQueryResults(renderedBounds);
}
#endif

View File

@@ -0,0 +1,34 @@
// Copyright 2012 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
attribute vec4 vertex_position;
uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying the model, view, and projection matrices
void main()
{
gl_Position = mvp_matrix * vertex_position;
}

View File

@@ -0,0 +1,34 @@
//
// flare.fsh
// KREngine
//
// Copyright 2012 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
void main() {
gl_FragColor = vec4(0.0, 0.05, 0.05, 0.0);
}

View File

@@ -47,7 +47,6 @@
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
enableOpenGLFrameCaptureMode = "0"
allowLocationSimulation = "YES">
<BuildableProductRunnable>
<BuildableReference

View File

@@ -107,7 +107,7 @@
E404C88F136B8E2F00B6C99B /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0430;
LastUpgradeCheck = 0440;
ORGANIZATIONNAME = "Kearwood Software";
};
buildConfigurationList = E404C892136B8E2F00B6C99B /* Build configuration list for PBXProject "objpack" */;

View File

@@ -43,6 +43,7 @@
#import <KREngine_osx/KRVector2.h>
#import <KREngine_osx/KRVector3.h>
#import <KREngine_osx/KRMesh.h>
#import <KREngine_osx/KRContext.h>
KROBJPacker::KROBJPacker() {
@@ -56,7 +57,9 @@ void KROBJPacker::pack(const char *szPath) {
std::cout << "Reading " << szPath << " ...\n";
std::string base_path = KRResource::GetFilePath(szPath);
vector<KRResource *> resources = KRResource::Load(szPath);
KRContext context = KRContext();
vector<KRResource *> resources = KRResource::Load(context, szPath);
try {
vector<KRResource *>::iterator resource_itr = resources.begin();

View File

@@ -31,6 +31,8 @@
E46FED3213C9A49F009F5814 /* PostShader.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E46FED2613C9A488009F5814 /* PostShader.vsh */; };
E4769DF3158A7915004B83AC /* flare.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4769DF1158A7915004B83AC /* flare.fsh */; };
E4769DF4158A7915004B83AC /* flare.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4769DF2158A7915004B83AC /* flare.vsh */; };
E48278B415F037B9001C9431 /* visualize_overlay.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E48278B215F037B9001C9431 /* visualize_overlay.vsh */; };
E48278B515F037B9001C9431 /* visualize_overlay.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E48278B315F037B9001C9431 /* visualize_overlay.fsh */; };
E49EB29C13806C5D00A4E727 /* MainWindow-iPad.xib in Resources */ = {isa = PBXBuildFile; fileRef = E49EB29B13806C5D00A4E727 /* MainWindow-iPad.xib */; };
E4A9DEC715412923009DF363 /* light_point.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4A9DEC2154128F0009DF363 /* light_point.fsh */; };
E4A9DEC815412923009DF363 /* light_point.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4A9DEC515412906009DF363 /* light_point.vsh */; };
@@ -70,6 +72,8 @@
E46FED2613C9A488009F5814 /* PostShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = PostShader.vsh; path = ../KREngine/KREngine/Shaders/PostShader.vsh; sourceTree = "<group>"; };
E4769DF1158A7915004B83AC /* flare.fsh */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.glsl; name = flare.fsh; path = ../KREngine/KREngine/Shaders/flare.fsh; sourceTree = "<group>"; };
E4769DF2158A7915004B83AC /* flare.vsh */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.glsl; name = flare.vsh; path = ../KREngine/KREngine/Shaders/flare.vsh; sourceTree = "<group>"; };
E48278B215F037B9001C9431 /* visualize_overlay.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file; name = visualize_overlay.vsh; path = ../KREngine/KREngine/Shaders/visualize_overlay.vsh; sourceTree = "<group>"; };
E48278B315F037B9001C9431 /* visualize_overlay.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file; name = visualize_overlay.fsh; path = ../KREngine/KREngine/visualize_overlay.fsh; sourceTree = "<group>"; };
E49EB29B13806C5D00A4E727 /* MainWindow-iPad.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "MainWindow-iPad.xib"; path = "iPad/MainWindow-iPad.xib"; sourceTree = "<group>"; };
E4A9DEC2154128F0009DF363 /* light_point.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_point.fsh; path = ../KREngine/KREngine/Shaders/light_point.fsh; sourceTree = "<group>"; };
E4A9DEC515412906009DF363 /* light_point.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_point.vsh; path = ../KREngine/KREngine/Shaders/light_point.vsh; sourceTree = "<group>"; };
@@ -188,6 +192,8 @@
E46FED2013C9A472009F5814 /* Shaders */ = {
isa = PBXGroup;
children = (
E48278B215F037B9001C9431 /* visualize_overlay.vsh */,
E48278B315F037B9001C9431 /* visualize_overlay.fsh */,
E4769DF1158A7915004B83AC /* flare.fsh */,
E4769DF2158A7915004B83AC /* flare.vsh */,
E4A9DEC2154128F0009DF363 /* light_point.fsh */,
@@ -285,6 +291,8 @@
E4FF48C61538FBFC002053FC /* light_directional.vsh in Resources */,
E46FED3113C9A49F009F5814 /* ObjectShader.vsh in Resources */,
E46FED3213C9A49F009F5814 /* PostShader.vsh in Resources */,
E48278B415F037B9001C9431 /* visualize_overlay.vsh in Resources */,
E48278B515F037B9001C9431 /* visualize_overlay.fsh in Resources */,
28AD733F0D9D9553002E5188 /* MainWindow.xib in Resources */,
E49EB29C13806C5D00A4E727 /* MainWindow-iPad.xib in Resources */,
E40611D714E4E98B0065996A /* README.txt in Resources */,