Fixed colour temperature and intensity engine parameters, which were not calculating r,g,b correctly
Refactoring in preparation for LOD and geometric reflections --HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40116
This commit is contained in:
@@ -27,10 +27,6 @@
|
||||
E42CB1F1158446AB0066E0D8 /* KRQuaternion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E42CB1EF158446AB0066E0D8 /* KRQuaternion.cpp */; };
|
||||
E430D08115F8882F0010558D /* occlusion_test.fsh in Sources */ = {isa = PBXBuildFile; fileRef = E430D08015F8882F0010558D /* occlusion_test.fsh */; };
|
||||
E430D08915F88AD10010558D /* occlusion_test.vsh in Sources */ = {isa = PBXBuildFile; fileRef = E430D08815F88AD10010558D /* occlusion_test.vsh */; };
|
||||
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 */; 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 */; };
|
||||
@@ -203,8 +199,6 @@
|
||||
E42CB1EF158446AB0066E0D8 /* KRQuaternion.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRQuaternion.cpp; path = Classes/KRQuaternion.cpp; sourceTree = "<group>"; };
|
||||
E430D08015F8882F0010558D /* occlusion_test.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = occlusion_test.fsh; path = Shaders/occlusion_test.fsh; sourceTree = "<group>"; };
|
||||
E430D08815F88AD10010558D /* occlusion_test.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = occlusion_test.vsh; path = Shaders/occlusion_test.vsh; sourceTree = "<group>"; };
|
||||
E43B0AC715DDBB8500A5CB9F /* KRNotified.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRNotified.cpp; path = Classes/KRNotified.cpp; sourceTree = "<group>"; };
|
||||
E43B0AC815DDBB8500A5CB9F /* KRNotified.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRNotified.h; path = Classes/KRNotified.h; sourceTree = "<group>"; };
|
||||
E43B0AD415DDCA0C00A5CB9F /* KRContextObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRContextObject.cpp; path = Classes/KRContextObject.cpp; sourceTree = "<group>"; };
|
||||
E43B0AD515DDCA0D00A5CB9F /* KRContextObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRContextObject.h; path = Classes/KRContextObject.h; sourceTree = "<group>"; };
|
||||
E45772F113C9A13C0037BEEA /* ShadowShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; lineEnding = 0; name = ShadowShader.vsh; path = Shaders/ShadowShader.vsh; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.glsl; };
|
||||
@@ -576,8 +570,6 @@
|
||||
E46DBE841512B9E200D59F86 /* KREngine-common.h */,
|
||||
E491017213C99BDC0098455B /* KREngine.h */,
|
||||
E491016F13C99BDC0098455B /* KREngine.mm */,
|
||||
E43B0AC715DDBB8500A5CB9F /* KRNotified.cpp */,
|
||||
E43B0AC815DDBB8500A5CB9F /* KRNotified.h */,
|
||||
E46F4A03155DF47C00CCF8B8 /* KRWorld.cpp */,
|
||||
E46F49FF155DF46700CCF8B8 /* KRWorld.h */,
|
||||
E488399915F92BA300BD66D5 /* Managers */,
|
||||
@@ -673,7 +665,6 @@
|
||||
E46F4A00155DF46700CCF8B8 /* KRWorld.h in Headers */,
|
||||
E46F4A0B155E002100CCF8B8 /* KRDataBlock.h in Headers */,
|
||||
E42CB1EC158446940066E0D8 /* KRQuaternion.h in Headers */,
|
||||
E43B0ACB15DDBB8500A5CB9F /* KRNotified.h in Headers */,
|
||||
E43B0AD815DDCA0F00A5CB9F /* KRContextObject.h in Headers */,
|
||||
E4924C2715EE95E800B965C6 /* KROctree.h in Headers */,
|
||||
E4924C2C15EE96AB00B965C6 /* KROctreeNode.h in Headers */,
|
||||
@@ -716,7 +707,6 @@
|
||||
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 */,
|
||||
@@ -844,7 +834,6 @@
|
||||
E46F4A04155DF47C00CCF8B8 /* KRWorld.cpp in Sources */,
|
||||
E46F4A0E155E003000CCF8B8 /* KRDataBlock.cpp in Sources */,
|
||||
E42CB1F0158446AB0066E0D8 /* KRQuaternion.cpp in Sources */,
|
||||
E43B0AC915DDBB8500A5CB9F /* KRNotified.cpp in Sources */,
|
||||
E43B0AD615DDCA0F00A5CB9F /* KRContextObject.cpp in Sources */,
|
||||
E4924C2615EE95E800B965C6 /* KROctree.cpp in Sources */,
|
||||
E4924C2B15EE96AB00B965C6 /* KROctreeNode.cpp in Sources */,
|
||||
@@ -897,7 +886,6 @@
|
||||
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 */,
|
||||
E488399515F928CA00BD66D5 /* KRBundle.cpp in Sources */,
|
||||
|
||||
@@ -231,7 +231,7 @@ bool KRBoundingVolume::test_intersect(const KRAABB &p) const {
|
||||
|
||||
|
||||
KRMat4 KRBoundingVolume::calcShadowProj(KRScene *pScene, KRContext *pContext, GLfloat sun_yaw, GLfloat sun_pitch) const {
|
||||
KRBoundingVolume sceneVolume = pScene->getExtents(pContext);
|
||||
KRBoundingVolume sceneVolume = KRBoundingVolume(-KRVector3::One(), KRVector3::One(), KRMat4()); // HACK - Temporary workaround to compile until this logic is updated to use information from the Octree
|
||||
|
||||
KRMat4 shadowvp;
|
||||
shadowvp.rotate(sun_pitch, X_AXIS);
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
#import "KRBoundingVolume.h"
|
||||
#import "KRStockGeometry.h"
|
||||
|
||||
KRCamera::KRCamera(KRContext &context, GLint width, GLint height) : KRNotified(context) {
|
||||
KRCamera::KRCamera(KRContext &context, GLint width, GLint height) : KRContextObject(context) {
|
||||
backingWidth = width;
|
||||
backingHeight = height;
|
||||
|
||||
@@ -165,7 +165,7 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix)
|
||||
|
||||
KRMat4 newShadowMVP;
|
||||
if(shadowMaxDepths[m_cShadowBuffers - 1][iShadow] == 0.0) {
|
||||
KRBoundingVolume ext = KRBoundingVolume(scene.getExtents(m_pContext));
|
||||
KRBoundingVolume ext = KRBoundingVolume(-KRVector3::One(), KRVector3::One(), KRMat4()); // HACK - Temporary workaround to compile until this logic is updated to use information from the Octree
|
||||
|
||||
newShadowMVP = ext.calcShadowProj(&scene, m_pContext, scene.sun_yaw, scene.sun_pitch);
|
||||
} else {
|
||||
@@ -269,7 +269,7 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
|
||||
GLDEBUG(glDisable(GL_BLEND));
|
||||
|
||||
// Render the geometry
|
||||
scene.render(this, frontToBackOrder, m_visibleBounds, m_pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_DEFERRED_GBUFFER, newVisibleBounds);
|
||||
scene.render(this, frontToBackOrder, m_visibleBounds, m_pContext, viewMatrix, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_DEFERRED_GBUFFER, newVisibleBounds);
|
||||
|
||||
// ----====---- Opaque Geometry, Deferred rendering Pass 2 ----====----
|
||||
// Set render target
|
||||
@@ -295,7 +295,7 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
|
||||
|
||||
|
||||
// Render the geometry
|
||||
scene.render(this, frontToBackOrder, m_visibleBounds, m_pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, 0, KRNode::RENDER_PASS_DEFERRED_LIGHTS, newVisibleBounds);
|
||||
scene.render(this, frontToBackOrder, m_visibleBounds, m_pContext, viewMatrix, lightDirection, shadowmvpmatrix, shadowDepthTexture, 0, KRNode::RENDER_PASS_DEFERRED_LIGHTS, newVisibleBounds);
|
||||
|
||||
// ----====---- Opaque Geometry, Deferred rendering Pass 3 ----====----
|
||||
// Set render target
|
||||
@@ -327,7 +327,7 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
|
||||
|
||||
// Render the geometry
|
||||
std::set<KRAABB> emptyBoundsSet; // At this point, we only render octree nodes that produced fragments during the 1st pass into the GBuffer
|
||||
scene.render(this, frontToBackOrder, emptyBoundsSet, m_pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_DEFERRED_OPAQUE, newVisibleBounds);
|
||||
scene.render(this, frontToBackOrder, emptyBoundsSet, m_pContext, viewMatrix, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_DEFERRED_OPAQUE, newVisibleBounds);
|
||||
|
||||
// Deactivate source buffer texture units
|
||||
m_pContext->getTextureManager()->selectTexture(6, NULL, 0);
|
||||
@@ -365,7 +365,7 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
|
||||
|
||||
|
||||
// Render the geometry
|
||||
scene.render(this, frontToBackOrder, m_visibleBounds, m_pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_FORWARD_OPAQUE, newVisibleBounds);
|
||||
scene.render(this, frontToBackOrder, m_visibleBounds, m_pContext, viewMatrix, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_FORWARD_OPAQUE, newVisibleBounds);
|
||||
}
|
||||
|
||||
// ----====---- Transparent Geometry, Forward Rendering ----====----
|
||||
@@ -390,7 +390,7 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
|
||||
GLDEBUG(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
|
||||
|
||||
// Render all transparent geometry
|
||||
scene.render(this, backToFrontOrder, m_visibleBounds, m_pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, newVisibleBounds);
|
||||
scene.render(this, backToFrontOrder, m_visibleBounds, m_pContext, viewMatrix, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_FORWARD_TRANSPARENT, newVisibleBounds);
|
||||
|
||||
|
||||
// ----====---- Flares ----====----
|
||||
@@ -414,7 +414,7 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
|
||||
GLDEBUG(glBlendFunc(GL_ONE, GL_ONE));
|
||||
|
||||
// Render all flares
|
||||
scene.render(this, backToFrontOrder, m_visibleBounds, m_pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_FLARES, newVisibleBounds);
|
||||
scene.render(this, backToFrontOrder, m_visibleBounds, m_pContext, viewMatrix, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_FLARES, newVisibleBounds);
|
||||
|
||||
// ----====---- Debug Overlay ----====----
|
||||
|
||||
@@ -440,7 +440,7 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
|
||||
matModel.translate((*itr).center());
|
||||
KRMat4 mvpmatrix = matModel * viewMatrix * projectionMatrix;
|
||||
|
||||
if(pVisShader->bind(this, viewMatrix, mvpmatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) {
|
||||
if(pVisShader->bind(this, viewMatrix, mvpmatrix, lightDirection, shadowmvpmatrix, shadowDepthTexture, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) {
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14));
|
||||
}
|
||||
}
|
||||
@@ -596,7 +596,7 @@ void KRCamera::renderShadowBuffer(KRScene &scene, int iShadow)
|
||||
KRShader *shadowShader = m_pContext->getShaderManager()->getShader("ShadowShader", this, false, false, false, 0, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
KRMat4 matIdentity; // Value not used by postshader
|
||||
KRVector3 vec4Temp; // Value not used by postshader
|
||||
shadowShader->bind(this, matIdentity, matIdentity, m_position, vec4Temp, NULL, NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
shadowShader->bind(this, matIdentity, matIdentity, vec4Temp, NULL, NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
|
||||
// Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram
|
||||
GLDEBUG(glUniformMatrix4fv(shadowShader->m_uniforms[KRShader::KRENGINE_UNIFORM_SHADOWMVP1], 1, GL_FALSE, shadowmvpmatrix[iShadow].getPointer()));
|
||||
@@ -632,7 +632,7 @@ void KRCamera::renderShadowBuffer(KRScene &scene, int iShadow)
|
||||
|
||||
|
||||
std::set<KRAABB> newVisibleBounds;
|
||||
scene.render(this, frontToBackOrder, m_shadowVisibleBounds[iShadow], m_pContext, shadowVolume, shadowmvpmatrix[iShadow], cameraPosition, lightDirection, shadowmvpmatrix, NULL, m_cShadowBuffers, KRNode::RENDER_PASS_SHADOWMAP, newVisibleBounds);
|
||||
scene.render(this, frontToBackOrder, m_shadowVisibleBounds[iShadow], m_pContext, shadowmvpmatrix[iShadow], lightDirection, shadowmvpmatrix, NULL, m_cShadowBuffers, KRNode::RENDER_PASS_SHADOWMAP, newVisibleBounds);
|
||||
m_shadowVisibleBounds[iShadow] = newVisibleBounds;
|
||||
GLDEBUG(glViewport(0, 0, backingWidth, backingHeight));
|
||||
}
|
||||
@@ -667,7 +667,7 @@ void KRCamera::renderPost()
|
||||
KRShader *postShader = m_pContext->getShaderManager()->getShader("PostShader", this, false, false, false, 0, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
KRMat4 matIdentity; // Value not used by postshader
|
||||
KRVector3 vec4Temp; // Value not used by postshader
|
||||
postShader->bind(this, matIdentity, matIdentity, m_position, vec4Temp, NULL, NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
postShader->bind(this, matIdentity, matIdentity, vec4Temp, NULL, NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
|
||||
m_pContext->getTextureManager()->selectTexture(0, NULL, 0);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE0));
|
||||
@@ -779,40 +779,3 @@ void KRCamera::invalidateShadowBuffers() {
|
||||
shadowValid[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
void KRCamera::notify_sceneGraphCreate(KRNode *pNode)
|
||||
{
|
||||
fprintf(stderr, "KRCamera - notify_sceneGraphCreate");
|
||||
|
||||
KRInstance *pInstance = dynamic_cast<KRInstance *>(pNode);
|
||||
if(pInstance) {
|
||||
if(pInstance->hasTransparency()) {
|
||||
KRInstanceDistance transparentInstanceDistance = KRInstanceDistance(pInstance, 0.0f);
|
||||
m_transparentInstances.push_back(transparentInstanceDistance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KRCamera::notify_sceneGraphDelete(KRNode *pNode)
|
||||
{
|
||||
fprintf(stderr, "KRCamera - notify_sceneGraphDelete");
|
||||
|
||||
KRInstance *pInstance = dynamic_cast<KRInstance *>(pNode);
|
||||
if(pInstance) {
|
||||
m_transparentInstances.remove_if(KRInstanceDistance::InstanceEqualsPredicate(pInstance));
|
||||
}
|
||||
}
|
||||
|
||||
void KRCamera::notify_sceneGraphModify(KRNode *pNode)
|
||||
{
|
||||
fprintf(stderr, "KRCamera - notify_sceneGraphModify");
|
||||
|
||||
KRInstance *pInstance = dynamic_cast<KRInstance *>(pNode);
|
||||
if(pInstance) {
|
||||
m_transparentInstances.remove_if(KRInstanceDistance::InstanceEqualsPredicate(pInstance));
|
||||
if(pInstance->hasTransparency()) {
|
||||
KRInstanceDistance transparentInstanceDistance = KRInstanceDistance(pInstance, 0.0f);
|
||||
m_transparentInstances.push_back(transparentInstanceDistance);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,9 +36,9 @@
|
||||
|
||||
#import "KRMat4.h"
|
||||
#import "KRVector2.h"
|
||||
#import "KRNotified.h"
|
||||
#import "KRAABB.h"
|
||||
#import "KRShader.h"
|
||||
#import "KRContextObject.h"
|
||||
|
||||
|
||||
#define KRENGINE_MAX_SHADOW_BUFFERS 3
|
||||
@@ -49,7 +49,7 @@ class KRInstance;
|
||||
class KRScene;
|
||||
class KRContext;
|
||||
|
||||
class KRCamera : public KRNotified {
|
||||
class KRCamera : public KRContextObject {
|
||||
public:
|
||||
KRCamera(KRContext &context, GLint width, GLint height);
|
||||
virtual ~KRCamera();
|
||||
@@ -112,10 +112,6 @@ public:
|
||||
|
||||
std::string m_debug_text;
|
||||
|
||||
virtual void notify_sceneGraphCreate(KRNode *pNode);
|
||||
virtual void notify_sceneGraphDelete(KRNode *pNode);
|
||||
virtual void notify_sceneGraphModify(KRNode *pNode);
|
||||
|
||||
private:
|
||||
KRVector3 m_position;
|
||||
|
||||
@@ -159,8 +155,6 @@ private:
|
||||
float m_distance;
|
||||
};
|
||||
|
||||
std::list<KRInstanceDistance> m_transparentInstances;
|
||||
|
||||
std::set<KRAABB> m_visibleBounds; // AABB's that output fragments in the last frame
|
||||
std::set<KRAABB> m_shadowVisibleBounds[KRENGINE_MAX_SHADOW_BUFFERS]; // AABB's that output fragments in the last frame for each shadow map
|
||||
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
#import "KRMaterialManager.h"
|
||||
#import "KRShaderManager.h"
|
||||
#import "KRModelManager.h"
|
||||
#import "KRNotified.h"
|
||||
|
||||
class KRContext {
|
||||
public:
|
||||
KRContext();
|
||||
|
||||
@@ -50,9 +50,9 @@ KRVector3 KRDirectionalLight::getLocalLightDirection() {
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
void KRDirectionalLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
|
||||
void KRDirectionalLight::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
|
||||
|
||||
KRLight::render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
||||
KRLight::render(pCamera, pContext, viewMatrix, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_DEFERRED_LIGHTS) {
|
||||
// Lights are rendered on the second pass of the deferred renderer
|
||||
@@ -69,7 +69,7 @@ void KRDirectionalLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundi
|
||||
light_direction_view_space.normalize();
|
||||
|
||||
KRShader *pShader = pContext->getShaderManager()->getShader("light_directional", pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
if(pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass)) {
|
||||
if(pShader->bind(pCamera, matModelToView, mvpmatrix, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass)) {
|
||||
|
||||
|
||||
GLDEBUG(glUniform3f(
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
virtual void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass);
|
||||
virtual void render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass);
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
@@ -478,99 +478,86 @@ double const PI = 3.141592653589793f;
|
||||
_camera->m_debug_text = value.UTF8String;
|
||||
}
|
||||
|
||||
// MIKE: adding getters and setters for sun_temperature, sun_intensity, ambient temperature, ambient intensity
|
||||
|
||||
-(double) getSunTemperature
|
||||
{
|
||||
if ( (_camera->dSunR == 0.0f ) || (_camera->dSunB == 0.0f)) {
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
if (_camera->dSunR > _camera->dSunB) {
|
||||
return ((1.0f - (_camera->dSunB/_camera->dSunR))/2.0f + 0.5f);
|
||||
}
|
||||
|
||||
if (_camera->dSunB > _camera->dSunR) {
|
||||
return ((_camera->dSunR/_camera->dSunB) * 0.5f);
|
||||
}
|
||||
|
||||
return 0.5f;
|
||||
}
|
||||
// ---===--- Sun Temperature and intensity ---===---
|
||||
|
||||
-(void) setSunTemperature:(double)t
|
||||
{
|
||||
_camera->dSunR = ((t < 0.5f) ? (t*2.0f) : 1.0f);
|
||||
_camera->dSunB = ((t < 0.5f) ? (t*2.0f) : (1.0f - ((t*2.0f) - 1.0f)));
|
||||
// _camera->dSunG = ((t < 0.5f) ? 1.0f : ((t*2.0f) - 1.0f));
|
||||
_camera->dSunG = 1.0f;
|
||||
double i = [self getSunIntensity];
|
||||
|
||||
}
|
||||
|
||||
-(double) getSunIntensity
|
||||
{
|
||||
if (_camera->dSunR > _camera->dSunB) {
|
||||
return _camera->dSunB;
|
||||
}
|
||||
|
||||
if (_camera->dSunB > _camera->dSunR) {
|
||||
return _camera->dSunR;
|
||||
}
|
||||
|
||||
return 1.0f;
|
||||
_camera->dSunR = (t < 0.5f ? t * 2.0f : 1.0f) * i;
|
||||
_camera->dSunG = (t < 0.5f ? t * 2.0f : (1.0f - t) * 2.0f) * i;
|
||||
_camera->dSunB = (t < 0.5f ? 1.0f : (1.0f - t) * 2.0f) * i;
|
||||
}
|
||||
|
||||
-(void) setSunIntensity:(double)i
|
||||
{
|
||||
_camera->dSunR *= i;
|
||||
_camera->dSunB *= i;
|
||||
_camera->dSunG *= i;
|
||||
double t = [self getSunTemperature];
|
||||
|
||||
_camera->dSunR = (t < 0.5f ? t * 2.0f : 1.0f) * i;
|
||||
_camera->dSunG = (t < 0.5f ? t * 2.0f : (1.0f - t) * 2.0f) * i;
|
||||
_camera->dSunB = (t < 0.5f ? 1.0f : (1.0f - t) * 2.0f) * i;
|
||||
}
|
||||
|
||||
-(double) getAmbientTemperature
|
||||
-(double) getSunIntensity
|
||||
{
|
||||
if ( (_camera->dAmbientR == 0.0f ) || (_camera->dAmbientB == 0.0f)) {
|
||||
return 0.5f;
|
||||
double i = _camera->dSunR;
|
||||
if(_camera->dSunG > i) i = _camera->dSunG;
|
||||
if(_camera->dSunB > i) i = _camera->dSunB;
|
||||
return i;
|
||||
}
|
||||
|
||||
if (_camera->dAmbientR > _camera->dAmbientB) {
|
||||
return ((1.0f - (_camera->dAmbientB/_camera->dAmbientR))/2.0f + 0.5f);
|
||||
-(double) getSunTemperature
|
||||
{
|
||||
double i = [self getSunIntensity];
|
||||
if(i == 0.0f) return 0.5f; // Avoid division by zero; assume black has a colour temperature of 0.5
|
||||
if(_camera->dSunB == i) {
|
||||
// Cold side, t < 0.5
|
||||
return _camera->dSunR / i * 0.5f;
|
||||
} else {
|
||||
// Warm side, t > 0.5
|
||||
return 1.0f - (_camera->dSunB / i) * 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
if (_camera->dAmbientB > _camera->dAmbientR) {
|
||||
return ((_camera->dAmbientR/_camera->dAmbientB) * 0.5f);
|
||||
}
|
||||
|
||||
return 0.5f;
|
||||
}
|
||||
// ---===--- Ambient Temperature and intensity ---===---
|
||||
|
||||
-(void) setAmbientTemperature:(double)t
|
||||
{
|
||||
_camera->dAmbientR = ((t < 0.5f) ? (t*2.0f) : 1.0f);
|
||||
_camera->dAmbientB = ((t < 0.5f) ? (t*2.0f) : (1.0f - ((t*2.0f) - 1.0f)));
|
||||
// _camera->dAmbientG = ((t < 0.5f) ? 1.0f : ((t*2.0f) - 1.0f));
|
||||
_camera->dAmbientG = 1.0f;
|
||||
double i = [self getAmbientIntensity];
|
||||
|
||||
}
|
||||
|
||||
-(double) getAmbientIntensity
|
||||
{
|
||||
if (_camera->dAmbientR > _camera->dAmbientB) {
|
||||
return _camera->dAmbientB;
|
||||
}
|
||||
|
||||
if (_camera->dAmbientB > _camera->dAmbientR) {
|
||||
return _camera->dAmbientR;
|
||||
}
|
||||
|
||||
return 1.0f;
|
||||
_camera->dAmbientR = (t < 0.5f ? t * 2.0f : 1.0f) * i;
|
||||
_camera->dAmbientG = (t < 0.5f ? t * 2.0f : (1.0f - t) * 2.0f) * i;
|
||||
_camera->dAmbientB = (t < 0.5f ? 1.0f : (1.0f - t) * 2.0f) * i;
|
||||
}
|
||||
|
||||
-(void) setAmbientIntensity:(double)i
|
||||
{
|
||||
_camera->dAmbientR *= i;
|
||||
_camera->dAmbientB *= i;
|
||||
_camera->dAmbientG *= i;
|
||||
double t = [self getAmbientTemperature];
|
||||
|
||||
_camera->dAmbientR = (t < 0.5f ? t * 2.0f : 1.0f) * i;
|
||||
_camera->dAmbientG = (t < 0.5f ? t * 2.0f : (1.0f - t) * 2.0f) * i;
|
||||
_camera->dAmbientB = (t < 0.5f ? 1.0f : (1.0f - t) * 2.0f) * i;
|
||||
}
|
||||
|
||||
-(double) getAmbientIntensity
|
||||
{
|
||||
double i = _camera->dAmbientR;
|
||||
if(_camera->dAmbientG > i) i = _camera->dAmbientG;
|
||||
if(_camera->dAmbientB > i) i = _camera->dAmbientB;
|
||||
return i;
|
||||
}
|
||||
|
||||
-(double) getAmbientTemperature
|
||||
{
|
||||
double i = [self getAmbientIntensity];
|
||||
if(i == 0.0f) return 0.5f; // Avoid division by zero; assume black has a colour temperature of 0.5
|
||||
if(_camera->dAmbientB == i) {
|
||||
// Cold side, t < 0.5
|
||||
return _camera->dAmbientR / i * 0.5f;
|
||||
} else {
|
||||
// Warm side, t > 0.5
|
||||
return 1.0f - (_camera->dAmbientB / i) * 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -64,24 +64,25 @@ KRMat4 &KRInstance::getModelMatrix() {
|
||||
return m_modelMatrix;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void KRInstance::loadModel() {
|
||||
if(m_pModel == NULL) {
|
||||
m_pModel = m_pContext->getModelManager()->getModel(m_model_name.c_str());
|
||||
if(m_pModel == NULL) {
|
||||
fprintf(stderr, "KREngine - Model not found: %s\n", m_model_name.c_str());
|
||||
if(m_pModel != NULL) {
|
||||
getScene().notify_sceneGraphModify(this);
|
||||
}
|
||||
// if(m_pModel == NULL) {
|
||||
// fprintf(stderr, "KREngine - Model not found: %s\n", m_model_name.c_str());
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
void KRInstance::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
|
||||
void KRInstance::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
|
||||
|
||||
calcModelMatrix();
|
||||
|
||||
KRNode::render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
||||
KRNode::render(pCamera, pContext, viewMatrix, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
||||
|
||||
if(renderPass != KRNode::RENDER_PASS_DEFERRED_LIGHTS && (renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT || this->hasTransparency()) && renderPass != KRNode::RENDER_PASS_FLARES) {
|
||||
// Don't render meshes on second pass of the deferred lighting renderer, as only lights will be applied
|
||||
@@ -94,7 +95,6 @@ void KRInstance::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume
|
||||
}
|
||||
|
||||
if(m_pModel != NULL) {
|
||||
//if(getExtents(pContext).test_intersect(frustrumVolume) || renderPass == RENDER_PASS_SHADOWMAP) {
|
||||
if(getBounds().visible(viewMatrix * projectionMatrix)) {
|
||||
|
||||
if(m_pLightMap == NULL && m_lightMap.size()) {
|
||||
@@ -110,13 +110,18 @@ void KRInstance::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume
|
||||
matModelToView.transpose();
|
||||
matModelToView.invert();
|
||||
|
||||
|
||||
KRMat4 inverseViewMatrix = viewMatrix;
|
||||
inverseViewMatrix.invert();
|
||||
KRVector3 cameraPosition = KRMat4::Dot(inverseViewMatrix, KRVector3::Zero());
|
||||
|
||||
// Transform location of camera to object space for calculation of specular halfVec
|
||||
KRMat4 inverseModelMatrix = m_modelMatrix;
|
||||
inverseModelMatrix.invert();
|
||||
KRVector3 cameraPosObject = KRMat4::Dot(inverseModelMatrix, cameraPosition);
|
||||
KRVector3 lightDirObject = KRMat4::Dot(inverseModelMatrix, lightDirection);
|
||||
|
||||
m_pModel->render(pCamera, pContext, matModelToView, mvpmatrix, cameraPosObject, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, m_pLightMap, renderPass);
|
||||
m_pModel->render(pCamera, pContext, viewMatrix, matModelToView, mvpmatrix, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, m_pLightMap, renderPass);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -124,22 +129,6 @@ void KRInstance::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume
|
||||
|
||||
#endif
|
||||
|
||||
void KRInstance::calcExtents(KRContext *pContext)
|
||||
{
|
||||
calcModelMatrix();
|
||||
|
||||
KRNode::calcExtents(pContext);
|
||||
loadModel();
|
||||
if(m_pModel != NULL) {
|
||||
KRBoundingVolume mesh_bounds = KRBoundingVolume(m_pModel->getMinPoint(), m_pModel->getMaxPoint(), m_modelMatrix);
|
||||
if(m_pExtents) {
|
||||
*m_pExtents = m_pExtents->get_union(mesh_bounds);
|
||||
} else {
|
||||
m_pExtents = new KRBoundingVolume(mesh_bounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool KRInstance::hasTransparency() {
|
||||
if(m_pModel) {
|
||||
return m_pModel->hasTransparency();
|
||||
@@ -151,10 +140,15 @@ bool KRInstance::hasTransparency() {
|
||||
KRAABB KRInstance::getBounds() {
|
||||
calcModelMatrix();
|
||||
loadModel();
|
||||
assert(m_pModel != NULL);
|
||||
|
||||
KRVector3 meshMin = m_pModel->getMinPoint();
|
||||
KRVector3 meshMax = m_pModel->getMaxPoint();
|
||||
KRVector3 meshMin, meshMax;
|
||||
if(m_pModel) {
|
||||
meshMin = m_pModel->getMinPoint();
|
||||
meshMax = m_pModel->getMaxPoint();
|
||||
} else {
|
||||
meshMin = -KRVector3::Max();
|
||||
meshMax = KRVector3::Max();
|
||||
}
|
||||
|
||||
KRVector3 min, max;
|
||||
for(int iCorner=0; iCorner < 8; iCorner++) {
|
||||
|
||||
@@ -39,7 +39,6 @@
|
||||
#import "KRModel.h"
|
||||
#import "KRMat4.h"
|
||||
#import "KRVector3.h"
|
||||
#import "KRBoundingVolume.h"
|
||||
#import "KRInstance.h"
|
||||
#import "KRCamera.h"
|
||||
#import "KRModelManager.h"
|
||||
@@ -48,8 +47,6 @@
|
||||
#import "KRModel.h"
|
||||
#import "KRTexture.h"
|
||||
|
||||
class KRBoundingVolume;
|
||||
|
||||
class KRInstance : public KRNode {
|
||||
|
||||
public:
|
||||
@@ -61,11 +58,9 @@ public:
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
virtual void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, RenderPass renderPass);
|
||||
virtual void render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, RenderPass renderPass);
|
||||
#endif
|
||||
|
||||
virtual void calcExtents(KRContext *pContext);
|
||||
|
||||
KRMat4 &getModelMatrix();
|
||||
|
||||
bool hasTransparency();
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
#import "KRCamera.h"
|
||||
#import "KRContext.h"
|
||||
|
||||
#import "KRBoundingVolume.h"
|
||||
#import "KRShaderManager.h"
|
||||
#import "KRShader.h"
|
||||
#import "KRStockGeometry.h"
|
||||
@@ -119,9 +118,9 @@ float KRLight::getDecayStart() {
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
void KRLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
|
||||
void KRLight::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
|
||||
|
||||
KRNode::render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
||||
KRNode::render(pCamera, pContext, viewMatrix, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_FLARES) {
|
||||
if(m_flareTexture.size() && m_flareSize > 0.0f) {
|
||||
@@ -143,10 +142,9 @@ void KRLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &f
|
||||
matModelToView.transpose();
|
||||
matModelToView.invert();
|
||||
|
||||
|
||||
// Render light flare on transparency pass
|
||||
KRShader *pShader = pContext->getShaderManager()->getShader("flare", pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
if(pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass)) {
|
||||
if(pShader->bind(pCamera, matModelToView, mvpmatrix, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass)) {
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE],
|
||||
m_flareSize
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
virtual void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass);
|
||||
virtual void render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -198,7 +198,7 @@ bool KRMaterial::isTransparent() {
|
||||
}
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
bool KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRContext *pContext, KRTexture *pLightMap, KRNode::RenderPass renderPass) {
|
||||
bool KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRContext *pContext, KRTexture *pLightMap, KRNode::RenderPass renderPass) {
|
||||
bool bSameMaterial = *prevBoundMaterial == this;
|
||||
bool bLightMap = pLightMap && pCamera->bEnableLightMap;
|
||||
|
||||
@@ -233,7 +233,7 @@ bool KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
|
||||
|
||||
bool bSameShader = strcmp(pShader->getKey(), szPrevShaderKey) == 0;
|
||||
if(!bSameShader) {
|
||||
if(!pShader->bind(pCamera, matModelToView, mvpMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass)) {
|
||||
if(!pShader->bind(pCamera, matModelToView, mvpMatrix, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
char *getName();
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
bool bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRContext *pContext, KRTexture *pLightMap, KRNode::RenderPass renderPass);
|
||||
bool bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRContext *pContext, KRTexture *pLightMap, KRNode::RenderPass renderPass);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ void KRModel::loadPack(KRDataBlock *data) {
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
void KRModel::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRTexture *pLightMap, KRNode::RenderPass renderPass) {
|
||||
void KRModel::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatrix, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRTexture *pLightMap, KRNode::RenderPass renderPass) {
|
||||
|
||||
//fprintf(stderr, "Rendering model: %s\n", m_name.c_str());
|
||||
if(renderPass != KRNode::RENDER_PASS_FLARES) {
|
||||
@@ -140,7 +140,7 @@ void KRModel::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &matModelToV
|
||||
|
||||
if(pMaterial != NULL && pMaterial == (*mat_itr)) {
|
||||
if((!pMaterial->isTransparent() && renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT) || (pMaterial->isTransparent() && renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) {
|
||||
if(pMaterial->bind(&pPrevBoundMaterial, szPrevShaderKey, pCamera, matModelToView, mvpMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, pContext, pLightMap, renderPass)) {
|
||||
if(pMaterial->bind(&pPrevBoundMaterial, szPrevShaderKey, pCamera, matModelToView, mvpMatrix, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, pContext, pLightMap, renderPass)) {
|
||||
|
||||
switch(pMaterial->getAlphaMode()) {
|
||||
case KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE: // Non-transparent materials
|
||||
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
void render(KRCamera *pCamera, KRContext *pContext, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRTexture *pLightMap, KRNode::RenderPass renderPass);
|
||||
void render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatrix, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRTexture *pLightMap, KRNode::RenderPass renderPass);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -21,13 +21,13 @@
|
||||
|
||||
KRNode::KRNode(KRScene &scene, std::string name) : KRContextObject(scene.getContext())
|
||||
{
|
||||
m_pExtents = NULL;
|
||||
m_name = name;
|
||||
m_localScale = KRVector3::One();
|
||||
m_localRotation = KRVector3::Zero();
|
||||
m_localTranslation = KRVector3::Zero();
|
||||
m_parentNode = NULL;
|
||||
m_pScene = &scene;
|
||||
getScene().notify_sceneGraphCreate(this);
|
||||
}
|
||||
|
||||
KRNode::~KRNode() {
|
||||
@@ -36,15 +36,12 @@ KRNode::~KRNode() {
|
||||
delete *itr;
|
||||
}
|
||||
m_childNodes.clear();
|
||||
clearExtents();
|
||||
}
|
||||
|
||||
void KRNode::addChild(KRNode *child) {
|
||||
assert(child->m_parentNode == NULL);
|
||||
child->m_parentNode = this;
|
||||
m_childNodes.push_back(child);
|
||||
clearExtents();
|
||||
getScene().notify_sceneGraphCreate(child);
|
||||
}
|
||||
|
||||
tinyxml2::XMLElement *KRNode::saveXML(tinyxml2::XMLNode *parent) {
|
||||
@@ -92,20 +89,16 @@ void KRNode::loadXML(tinyxml2::XMLElement *e) {
|
||||
addChild(child_node);
|
||||
}
|
||||
}
|
||||
clearExtents();
|
||||
}
|
||||
|
||||
void KRNode::setLocalTranslation(const KRVector3 &v) {
|
||||
m_localTranslation = v;
|
||||
clearExtents();
|
||||
}
|
||||
void KRNode::setLocalScale(const KRVector3 &v) {
|
||||
m_localScale = v;
|
||||
clearExtents();
|
||||
}
|
||||
void KRNode::setLocalRotation(const KRVector3 &v) {
|
||||
m_localRotation = v;
|
||||
clearExtents();
|
||||
}
|
||||
|
||||
const KRVector3 &KRNode::getLocalTranslation() {
|
||||
@@ -159,42 +152,11 @@ KRNode *KRNode::LoadXML(KRScene &scene, tinyxml2::XMLElement *e) {
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
void KRNode::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
|
||||
void KRNode::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void KRNode::clearExtents() {
|
||||
if(m_pExtents) {
|
||||
delete m_pExtents;
|
||||
m_pExtents = NULL;
|
||||
}
|
||||
if(m_parentNode) {
|
||||
m_parentNode->clearExtents();
|
||||
}
|
||||
}
|
||||
|
||||
KRBoundingVolume KRNode::getExtents(KRContext *pContext) {
|
||||
if(!m_pExtents) {
|
||||
calcExtents(pContext);
|
||||
}
|
||||
return *m_pExtents;
|
||||
}
|
||||
|
||||
void KRNode::calcExtents(KRContext *pContext) {
|
||||
clearExtents();
|
||||
/*
|
||||
for(std::vector<KRNode *>::iterator itr=m_childNodes.begin(); itr < m_childNodes.end(); ++itr) {
|
||||
KRNode *child = (*itr);
|
||||
if(m_pExtents) {
|
||||
*m_pExtents = m_pExtents->get_union(child->getExtents(pContext));
|
||||
} else {
|
||||
m_pExtents = new KRBoundingVolume(child->getExtents(pContext));
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
const std::vector<KRNode *> &KRNode::getChildren() {
|
||||
return m_childNodes;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#import "KRVector3.h"
|
||||
#import "tinyxml2.h"
|
||||
|
||||
class KRBoundingVolume;
|
||||
class KRCamera;
|
||||
class KRShaderManager;
|
||||
class KRModelManager;
|
||||
@@ -63,22 +62,16 @@ public:
|
||||
const KRVector3 &getWorldScale();
|
||||
const KRVector3 &getWorldRotation();
|
||||
|
||||
void clearExtents();
|
||||
virtual void calcExtents(KRContext *Context);
|
||||
KRBoundingVolume getExtents(KRContext *pContext);
|
||||
|
||||
virtual KRAABB getBounds();
|
||||
|
||||
KRScene &getScene();
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
virtual void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, RenderPass renderPass);
|
||||
virtual void render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, RenderPass renderPass);
|
||||
|
||||
#endif
|
||||
|
||||
protected:
|
||||
KRBoundingVolume *m_pExtents;
|
||||
|
||||
KRVector3 m_localTranslation;
|
||||
KRVector3 m_localScale;
|
||||
KRVector3 m_localRotation;
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
//
|
||||
// KRNotified.cpp
|
||||
// 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.
|
||||
//
|
||||
|
||||
#include "KRNotified.h"
|
||||
#include "KRContext.h"
|
||||
|
||||
KRNotified::KRNotified(KRContext &context) : KRContextObject(context)
|
||||
{
|
||||
m_pSubscribedScene = NULL;
|
||||
}
|
||||
|
||||
KRNotified::~KRNotified()
|
||||
{
|
||||
if(m_pSubscribedScene) {
|
||||
m_pSubscribedScene->unregisterNotified(this);
|
||||
m_pSubscribedScene = NULL;
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
//
|
||||
// KRNotified.h
|
||||
// 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.
|
||||
//
|
||||
|
||||
#import "KRContextObject.h"
|
||||
|
||||
#ifndef KRNOTIFIED_H
|
||||
#define KRNOTIFIED_H
|
||||
|
||||
class KRContext;
|
||||
class KRNode;
|
||||
class KRScene;
|
||||
|
||||
class KRNotified : public KRContextObject {
|
||||
|
||||
public:
|
||||
KRNotified(KRContext &context);
|
||||
virtual ~KRNotified();
|
||||
|
||||
virtual void notify_sceneGraphCreate(KRNode *pNode) = 0;
|
||||
virtual void notify_sceneGraphDelete(KRNode *pNode) = 0;
|
||||
virtual void notify_sceneGraphModify(KRNode *pNode) = 0;
|
||||
private:
|
||||
KRScene *m_pSubscribedScene;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -33,6 +33,7 @@ void KROctree::add(KRNode *pNode)
|
||||
m_pRootNode = new KROctreeNode(nodeBounds);
|
||||
//m_pRootNode = new KROctreeNode(KRAABB(nodeBounds.min - nodeBounds.size() * 0.25f, nodeBounds.max + nodeBounds.size() * 0.25f));
|
||||
m_pRootNode->add(pNode);
|
||||
fprintf(stderr, "First Octree Node: %s\n", pNode->getName().c_str());
|
||||
} else {
|
||||
// Keep encapsulating the root node until the new root contains the inserted node
|
||||
bool bInsideRoot = false;
|
||||
|
||||
@@ -38,10 +38,9 @@ std::string KRPointLight::getElementName() {
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
void KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
|
||||
|
||||
KRLight::render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
||||
void KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
|
||||
|
||||
KRLight::render(pCamera, pContext, viewMatrix, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
||||
|
||||
bool bVisualize = renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && pCamera->bShowDeferred;
|
||||
|
||||
@@ -83,7 +82,7 @@ void KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolu
|
||||
bool bInsideLight = view_light_position.sqrMagnitude() <= (influence_radius + pCamera->perspective_nearz) * (influence_radius + pCamera->perspective_nearz);
|
||||
|
||||
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);
|
||||
if(pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass)) {
|
||||
if(pShader->bind(pCamera, matModelToView, mvpmatrix, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass)) {
|
||||
|
||||
|
||||
GLDEBUG(glUniform3f(
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
virtual void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass);
|
||||
virtual void render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass);
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
@@ -56,7 +56,7 @@ KRScene::~KRScene() {
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
void KRScene::render(KRCamera *pCamera, int childOrder[], std::set<KRAABB> &visibleBounds, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass, std::set<KRAABB> &newVisibleBounds) {
|
||||
void KRScene::render(KRCamera *pCamera, int childOrder[], std::set<KRAABB> &visibleBounds, KRContext *pContext, KRMat4 &viewMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass, std::set<KRAABB> &newVisibleBounds) {
|
||||
|
||||
updateOctree();
|
||||
|
||||
@@ -116,10 +116,10 @@ void KRScene::render(KRCamera *pCamera, int childOrder[], std::set<KRAABB> &visi
|
||||
newRemainingOctrees.clear();
|
||||
newRemainingOctreesTestResults.clear();
|
||||
for(std::vector<KROctreeNode *>::iterator octree_itr = remainingOctrees.begin(); octree_itr != remainingOctrees.end(); octree_itr++) {
|
||||
render(childOrder, *octree_itr, visibleBounds, pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, forward_render_light_direction, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass, newRemainingOctrees, newRemainingOctreesTestResults, remainingOctreesTestResultsOnly, newVisibleBounds, false, false);
|
||||
render(childOrder, *octree_itr, visibleBounds, pCamera, pContext, viewMatrix, forward_render_light_direction, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass, newRemainingOctrees, newRemainingOctreesTestResults, remainingOctreesTestResultsOnly, newVisibleBounds, false, false);
|
||||
}
|
||||
for(std::vector<KROctreeNode *>::iterator octree_itr = remainingOctreesTestResults.begin(); octree_itr != remainingOctreesTestResults.end(); octree_itr++) {
|
||||
render(childOrder, *octree_itr, visibleBounds, pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, forward_render_light_direction, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass, newRemainingOctrees, newRemainingOctreesTestResults, remainingOctreesTestResultsOnly, newVisibleBounds, true, false);
|
||||
render(childOrder, *octree_itr, visibleBounds, pCamera, pContext, viewMatrix, forward_render_light_direction, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass, newRemainingOctrees, newRemainingOctreesTestResults, remainingOctreesTestResultsOnly, newVisibleBounds, true, false);
|
||||
}
|
||||
remainingOctrees = newRemainingOctrees;
|
||||
remainingOctreesTestResults = newRemainingOctreesTestResults;
|
||||
@@ -128,16 +128,16 @@ void KRScene::render(KRCamera *pCamera, int childOrder[], std::set<KRAABB> &visi
|
||||
newRemainingOctrees.clear();
|
||||
newRemainingOctreesTestResults.clear();
|
||||
for(std::vector<KROctreeNode *>::iterator octree_itr = remainingOctreesTestResultsOnly.begin(); octree_itr != remainingOctreesTestResultsOnly.end(); octree_itr++) {
|
||||
render(childOrder, *octree_itr, visibleBounds, pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, forward_render_light_direction, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass, newRemainingOctrees, newRemainingOctreesTestResults, remainingOctreesTestResultsOnly, newVisibleBounds, true, true);
|
||||
render(childOrder, *octree_itr, visibleBounds, pCamera, pContext, viewMatrix, forward_render_light_direction, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass, newRemainingOctrees, newRemainingOctreesTestResults, remainingOctreesTestResultsOnly, newVisibleBounds, true, true);
|
||||
}
|
||||
|
||||
|
||||
for(std::set<KRNode *>::iterator itr=m_nodeTree.getOuterSceneNodes().begin(); itr != m_nodeTree.getOuterSceneNodes().end(); itr++) {
|
||||
(*itr)->render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
||||
std::set<KRNode *> outerNodes = std::set<KRNode *>(m_nodeTree.getOuterSceneNodes()); // HACK - Copying the std::set as it is potentially modified as KRNode's update their bounds during the iteration. This is very expensive and will be eliminated in the future.
|
||||
for(std::set<KRNode *>::iterator itr=outerNodes.begin(); itr != outerNodes.end(); itr++) {
|
||||
(*itr)->render(pCamera, pContext, viewMatrix, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
||||
}
|
||||
}
|
||||
|
||||
void KRScene::render(int childOrder[], 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, std::vector<KROctreeNode *> &remainingOctrees, std::vector<KROctreeNode *> &remainingOctreesTestResults, std::vector<KROctreeNode *> &remainingOctreesTestResultsOnly, std::set<KRAABB> &newVisibleBounds, bool bOcclusionResultsPass, bool bOcclusionTestResultsOnly)
|
||||
void KRScene::render(int childOrder[], KROctreeNode *pOctreeNode, std::set<KRAABB> &visibleBounds, KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass, std::vector<KROctreeNode *> &remainingOctrees, std::vector<KROctreeNode *> &remainingOctreesTestResults, std::vector<KROctreeNode *> &remainingOctreesTestResultsOnly, std::set<KRAABB> &newVisibleBounds, bool bOcclusionResultsPass, bool bOcclusionTestResultsOnly)
|
||||
{
|
||||
if(pOctreeNode) {
|
||||
|
||||
@@ -164,12 +164,6 @@ void KRScene::render(int childOrder[], KROctreeNode *pOctreeNode, std::set<KRAAB
|
||||
} else {
|
||||
|
||||
|
||||
// KRBoundingVolume frustrumVolumeNoNearClip = KRBoundingVolume(viewMatrix, pCamera->perspective_fov, pCamera->m_viewportSize.x / pCamera->m_viewportSize.y, 0.0, pCamera->perspective_farz);
|
||||
// if(frustrumVolumeNoNearClip.test_intersect(pOctreeNode->getBounds())) { // Only recurse deeper if within the view frustrum
|
||||
//
|
||||
|
||||
|
||||
|
||||
KRMat4 projectionMatrix;
|
||||
if(renderPass != KRNode::RENDER_PASS_SHADOWMAP) {
|
||||
projectionMatrix = pCamera->getProjectionMatrix();
|
||||
@@ -250,7 +244,8 @@ void KRScene::render(int childOrder[], KROctreeNode *pOctreeNode, std::set<KRAAB
|
||||
GLDEBUG(glDepthMask(GL_FALSE));
|
||||
}
|
||||
|
||||
if(pVisShader->bind(pCamera, viewMatrix, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) {
|
||||
|
||||
if(pVisShader->bind(pCamera, viewMatrix, mvpmatrix, lightDirection, pShadowMatrices, shadowDepthTextures, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) {
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14));
|
||||
}
|
||||
|
||||
@@ -281,11 +276,11 @@ void KRScene::render(int childOrder[], KROctreeNode *pOctreeNode, std::set<KRAAB
|
||||
|
||||
for(std::set<KRNode *>::iterator itr=pOctreeNode->getSceneNodes().begin(); itr != pOctreeNode->getSceneNodes().end(); itr++) {
|
||||
//assert(pOctreeNode->getBounds().contains((*itr)->getBounds())); // Sanity check
|
||||
(*itr)->render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
||||
(*itr)->render(pCamera, pContext, viewMatrix, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
||||
}
|
||||
|
||||
for(int i=0; i<8; i++) {
|
||||
render(childOrder, pOctreeNode->getChildren()[childOrder[i]], visibleBounds, pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass, remainingOctrees, remainingOctreesTestResults, remainingOctreesTestResultsOnly, newVisibleBounds, false, false);
|
||||
render(childOrder, pOctreeNode->getChildren()[childOrder[i]], visibleBounds, pCamera, pContext, viewMatrix, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass, remainingOctrees, remainingOctreesTestResults, remainingOctreesTestResultsOnly, newVisibleBounds, false, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -297,11 +292,6 @@ void KRScene::render(int childOrder[], KROctreeNode *pOctreeNode, std::set<KRAAB
|
||||
|
||||
#endif
|
||||
|
||||
KRBoundingVolume KRScene::getExtents(KRContext *pContext) {
|
||||
return m_pRootNode->getExtents(pContext);
|
||||
}
|
||||
|
||||
|
||||
std::string KRScene::getExtension() {
|
||||
return "krscene";
|
||||
}
|
||||
@@ -359,58 +349,38 @@ KRDirectionalLight *KRScene::getFirstDirectionalLight()
|
||||
return m_pFirstDirectionalLight;
|
||||
}
|
||||
|
||||
void KRScene::registerNotified(KRNotified *pNotified)
|
||||
{
|
||||
m_notifiedObjects.insert(pNotified);
|
||||
for(std::set<KRNode *>::iterator itr=m_allNodes.begin(); itr != m_allNodes.end(); itr++) {
|
||||
pNotified->notify_sceneGraphCreate(*itr);
|
||||
}
|
||||
}
|
||||
|
||||
void KRScene::unregisterNotified(KRNotified *pNotified)
|
||||
{
|
||||
m_notifiedObjects.erase(pNotified);
|
||||
}
|
||||
|
||||
void KRScene::notify_sceneGraphCreate(KRNode *pNode)
|
||||
{
|
||||
m_allNodes.insert(pNode);
|
||||
m_newNodes.insert(pNode);
|
||||
for(std::set<KRNotified *>::iterator itr = m_notifiedObjects.begin(); itr != m_notifiedObjects.end(); itr++) {
|
||||
(*itr)->notify_sceneGraphCreate(pNode);
|
||||
}
|
||||
m_nodeTree.add(pNode);
|
||||
// m_newNodes.insert(pNode);
|
||||
}
|
||||
|
||||
void KRScene::notify_sceneGraphDelete(KRNode *pNode)
|
||||
{
|
||||
for(std::set<KRNotified *>::iterator itr = m_notifiedObjects.begin(); itr != m_notifiedObjects.end(); itr++) {
|
||||
(*itr)->notify_sceneGraphDelete(pNode);
|
||||
}
|
||||
m_allNodes.erase(pNode);
|
||||
m_modifiedNodes.erase(pNode);
|
||||
if(!m_newNodes.erase(pNode)) {
|
||||
m_nodeTree.remove(pNode);
|
||||
}
|
||||
//
|
||||
// m_modifiedNodes.erase(pNode);
|
||||
// if(!m_newNodes.erase(pNode)) {
|
||||
// m_nodeTree.remove(pNode);
|
||||
// }
|
||||
}
|
||||
|
||||
void KRScene::notify_sceneGraphModify(KRNode *pNode)
|
||||
{
|
||||
m_modifiedNodes.insert(pNode);
|
||||
for(std::set<KRNotified *>::iterator itr = m_notifiedObjects.begin(); itr != m_notifiedObjects.end(); itr++) {
|
||||
(*itr)->notify_sceneGraphModify(pNode);
|
||||
}
|
||||
m_nodeTree.update(pNode);
|
||||
// m_modifiedNodes.insert(pNode);
|
||||
}
|
||||
|
||||
void KRScene::updateOctree()
|
||||
{
|
||||
for(std::set<KRNode *>::iterator itr=m_newNodes.begin(); itr != m_newNodes.end(); itr++) {
|
||||
m_nodeTree.add(*itr);
|
||||
}
|
||||
for(std::set<KRNode *>::iterator itr=m_modifiedNodes.begin(); itr != m_modifiedNodes.end(); itr++) {
|
||||
m_nodeTree.update(*itr);
|
||||
}
|
||||
m_newNodes.clear();
|
||||
m_modifiedNodes.clear();
|
||||
// for(std::set<KRNode *>::iterator itr=m_newNodes.begin(); itr != m_newNodes.end(); itr++) {
|
||||
// m_nodeTree.add(*itr);
|
||||
// }
|
||||
// for(std::set<KRNode *>::iterator itr=m_modifiedNodes.begin(); itr != m_modifiedNodes.end(); itr++) {
|
||||
// m_nodeTree.update(*itr);
|
||||
// }
|
||||
// m_newNodes.clear();
|
||||
// m_modifiedNodes.clear();
|
||||
}
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
|
||||
@@ -36,14 +36,12 @@
|
||||
|
||||
#import <vector>
|
||||
#import "KRInstance.h"
|
||||
#import "KRBoundingVolume.h"
|
||||
#import "KRMat4.h"
|
||||
#import "KRModel.h"
|
||||
#import "KRCamera.h"
|
||||
#import "KRModelManager.h"
|
||||
#import "KRNode.h"
|
||||
#import "KROctree.h"
|
||||
class KRBoundingVolume;
|
||||
class KRInstance;
|
||||
class KRDirectionalLight;
|
||||
|
||||
@@ -64,17 +62,14 @@ public:
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
void render(KRCamera *pCamera, int childOrder[], std::set<KRAABB> &visibleBounds, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass, std::set<KRAABB> &newVisibleBounds);
|
||||
void render(KRCamera *pCamera, int childOrder[], std::set<KRAABB> &visibleBounds, KRContext *pContext, KRMat4 &viewMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass, std::set<KRAABB> &newVisibleBounds);
|
||||
|
||||
void render(int childOrder[], 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, std::vector<KROctreeNode *> &remainingOctrees, std::vector<KROctreeNode *> &remainingOctreesTestResults, std::vector<KROctreeNode *> &remainingOctreesTestResultsOnly, std::set<KRAABB> &newVisibleBounds, bool bOcclusionResultsPass, bool bOcclusionTestResultsOnly);
|
||||
void render(int childOrder[], KROctreeNode *pOctreeNode, std::set<KRAABB> &visibleBounds, KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass, std::vector<KROctreeNode *> &remainingOctrees, std::vector<KROctreeNode *> &remainingOctreesTestResults, std::vector<KROctreeNode *> &remainingOctreesTestResultsOnly, std::set<KRAABB> &newVisibleBounds, bool bOcclusionResultsPass, bool bOcclusionTestResultsOnly);
|
||||
|
||||
#endif
|
||||
|
||||
KRBoundingVolume getExtents(KRContext *pContext);
|
||||
double sun_pitch, sun_yaw;
|
||||
|
||||
void registerNotified(KRNotified *pNotified);
|
||||
void unregisterNotified(KRNotified *pNotified);
|
||||
|
||||
void notify_sceneGraphCreate(KRNode *pNode);
|
||||
void notify_sceneGraphDelete(KRNode *pNode);
|
||||
@@ -85,11 +80,8 @@ private:
|
||||
KRDirectionalLight *findFirstDirectionalLight(KRNode &node);
|
||||
|
||||
KRNode *m_pRootNode;
|
||||
KRBoundingVolume *m_pExtents;
|
||||
KRDirectionalLight *m_pFirstDirectionalLight;
|
||||
|
||||
std::set<KRNotified *> m_notifiedObjects;
|
||||
std::set<KRNode *> m_allNodes;
|
||||
std::set<KRNode *> m_newNodes;
|
||||
std::set<KRNode *> m_modifiedNodes;
|
||||
|
||||
|
||||
@@ -195,11 +195,15 @@ KRShader::~KRShader() {
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
bool KRShader::bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
|
||||
bool KRShader::bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
|
||||
if(m_iProgram == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
KRMat4 inverseViewMatrix = matModelToView;
|
||||
inverseViewMatrix.invert();
|
||||
KRVector3 cameraPosition = KRMat4::Dot(inverseViewMatrix, KRVector3::Zero());
|
||||
|
||||
|
||||
GLDEBUG(glUseProgram(m_iProgram));
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
bool bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass);
|
||||
bool bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -99,9 +99,9 @@ void KRSkyBox::loadXML(tinyxml2::XMLElement *e) {
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
void KRSkyBox::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRNode::RenderPass renderPass) {
|
||||
void KRSkyBox::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatrix, KRNode::RenderPass renderPass) {
|
||||
|
||||
// KRNode::render(pCamera, pContext, frustrumVolume, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
||||
// KRNode::render(pCamera, pContext, frustrumVolume, viewMatrix, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass);
|
||||
|
||||
if(renderPass == KRNode::RENDER_PASS_SKYBOX) {
|
||||
// Skybox is rendered on the final pass of the deferred renderer
|
||||
@@ -138,7 +138,7 @@ void KRSkyBox::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &
|
||||
matModelToView.invert();
|
||||
|
||||
// KRShader *pShader = pContext->getShaderManager()->getShader("sky_box", pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, renderPass);
|
||||
// pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, NULL, NULL, NULL, 0, renderPass);
|
||||
// pShader->bind(pCamera, matModelToView, mvpmatrix, NULL, NULL, NULL, 0, renderPass);
|
||||
|
||||
m_pContext->getTextureManager()->selectTexture(0, m_pFrontTexture, 2048);
|
||||
m_pContext->getTextureManager()->selectTexture(1, m_pBackTexture, 2048);
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
virtual void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRNode::RenderPass renderPass);
|
||||
virtual void render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatrix, KRNode::RenderPass renderPass);
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user