Eliminated KRBoundingVolume, as it has been completely replaced by KRAABB
Added logic to eliminate redundant shader binding calls. --HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40157
This commit is contained in:
@@ -17,8 +17,6 @@
|
||||
E414BAE51435558900A668C4 /* KRInstance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E414BAE41435558800A668C4 /* KRInstance.cpp */; };
|
||||
E414BAE7143557D200A668C4 /* KRScene.h in Headers */ = {isa = PBXBuildFile; fileRef = E414BAE6143557D200A668C4 /* KRScene.h */; };
|
||||
E414BAE91435585A00A668C4 /* KRScene.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E414BAE81435585A00A668C4 /* KRScene.cpp */; };
|
||||
E414BAEB14355E5500A668C4 /* KRBoundingVolume.h in Headers */ = {isa = PBXBuildFile; fileRef = E414BAEA14355E5500A668C4 /* KRBoundingVolume.h */; };
|
||||
E414BAED14355EFF00A668C4 /* KRBoundingVolume.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E414BAEC14355EFF00A668C4 /* KRBoundingVolume.cpp */; };
|
||||
E42CB1EC158446940066E0D8 /* KRQuaternion.h in Headers */ = {isa = PBXBuildFile; fileRef = E42CB1EB158446940066E0D8 /* KRQuaternion.h */; };
|
||||
E42CB1ED158446940066E0D8 /* KRQuaternion.h in Headers */ = {isa = PBXBuildFile; fileRef = E42CB1EB158446940066E0D8 /* KRQuaternion.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
E42CB1F0158446AB0066E0D8 /* KRQuaternion.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E42CB1EF158446AB0066E0D8 /* KRQuaternion.cpp */; };
|
||||
@@ -178,8 +176,6 @@
|
||||
E4F9754115362CD900FD60B2 /* KRScene.h in Headers */ = {isa = PBXBuildFile; fileRef = E414BAE6143557D200A668C4 /* KRScene.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
E4F9754215362D0D00FD60B2 /* KRInstance.h in Headers */ = {isa = PBXBuildFile; fileRef = E414BAE11435557300A668C4 /* KRInstance.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
E4F9754315362D0F00FD60B2 /* KRInstance.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E414BAE41435558800A668C4 /* KRInstance.cpp */; };
|
||||
E4F9754415362D2900FD60B2 /* KRBoundingVolume.h in Headers */ = {isa = PBXBuildFile; fileRef = E414BAEA14355E5500A668C4 /* KRBoundingVolume.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
E4F9754515362D2C00FD60B2 /* KRBoundingVolume.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E414BAEC14355EFF00A668C4 /* KRBoundingVolume.cpp */; };
|
||||
E4F975461536327C00FD60B2 /* KRModelManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018313C99BDC0098455B /* KRModelManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
E4F975491536329E00FD60B2 /* KRTextureManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E491018513C99BDC0098455B /* KRTextureManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
E4F9754A153632AA00FD60B2 /* KRModelManager.cpp in Headers */ = {isa = PBXBuildFile; fileRef = E491018213C99BDC0098455B /* KRModelManager.cpp */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
@@ -214,8 +210,6 @@
|
||||
E414BAE41435558800A668C4 /* KRInstance.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRInstance.cpp; path = Classes/KRInstance.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
|
||||
E414BAE6143557D200A668C4 /* KRScene.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRScene.h; path = Classes/KRScene.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
|
||||
E414BAE81435585A00A668C4 /* KRScene.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRScene.cpp; path = Classes/KRScene.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
|
||||
E414BAEA14355E5500A668C4 /* KRBoundingVolume.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRBoundingVolume.h; path = Classes/KRBoundingVolume.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
|
||||
E414BAEC14355EFF00A668C4 /* KRBoundingVolume.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRBoundingVolume.cpp; path = Classes/KRBoundingVolume.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
|
||||
E41B841D16260C5600C7A771 /* sky_box.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = sky_box.fsh; path = Shaders/sky_box.fsh; sourceTree = "<group>"; };
|
||||
E41B842016260C6500C7A771 /* sky_box.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = sky_box.vsh; path = Shaders/sky_box.vsh; sourceTree = "<group>"; };
|
||||
E42CB1EB158446940066E0D8 /* KRQuaternion.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRQuaternion.h; path = Classes/KRQuaternion.h; sourceTree = "<group>"; };
|
||||
@@ -458,8 +452,6 @@
|
||||
E461A173152E59DF00F2044A /* Math */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
E414BAEA14355E5500A668C4 /* KRBoundingVolume.h */,
|
||||
E414BAEC14355EFF00A668C4 /* KRBoundingVolume.cpp */,
|
||||
E491017613C99BDC0098455B /* KRMat4.h */,
|
||||
E491017713C99BDC0098455B /* KRMat4.cpp */,
|
||||
E491017E13C99BDC0098455B /* KRVector3.h */,
|
||||
@@ -738,7 +730,6 @@
|
||||
E47C25A513F4F66F00FF4370 /* KRShader.h in Headers */,
|
||||
E414BAE21435557300A668C4 /* KRInstance.h in Headers */,
|
||||
E414BAE7143557D200A668C4 /* KRScene.h in Headers */,
|
||||
E414BAEB14355E5500A668C4 /* KRBoundingVolume.h in Headers */,
|
||||
E48B3CBD14393DF5000C50E2 /* KRCamera.h in Headers */,
|
||||
E497B94A151BCEE900D3DC67 /* KRResource.h in Headers */,
|
||||
E461A152152E54B500F2044A /* KRLight.h in Headers */,
|
||||
@@ -774,7 +765,6 @@
|
||||
E497B948151BB89D00D3DC67 /* KRVector2.h in Headers */,
|
||||
E4D0683F1512A790005FFBEB /* KRVector3.h in Headers */,
|
||||
E461A177152E5C6600F2044A /* KRMat4.h in Headers */,
|
||||
E4F9754415362D2900FD60B2 /* KRBoundingVolume.h in Headers */,
|
||||
E4F975461536327C00FD60B2 /* KRModelManager.h in Headers */,
|
||||
E497B94B151BCEE900D3DC67 /* KRResource.h in Headers */,
|
||||
E43B0AD915DDCA0F00A5CB9F /* KRContextObject.h in Headers */,
|
||||
@@ -916,7 +906,6 @@
|
||||
E47C25A913F4F6DD00FF4370 /* KRShader.cpp in Sources */,
|
||||
E414BAE51435558900A668C4 /* KRInstance.cpp in Sources */,
|
||||
E414BAE91435585A00A668C4 /* KRScene.cpp in Sources */,
|
||||
E414BAED14355EFF00A668C4 /* KRBoundingVolume.cpp in Sources */,
|
||||
E48B3CC014393E30000C50E2 /* KRCamera.cpp in Sources */,
|
||||
E497B946151BA99500D3DC67 /* KRVector2.cpp in Sources */,
|
||||
E497B94D151BCF2500D3DC67 /* KRResource.cpp in Sources */,
|
||||
@@ -967,7 +956,6 @@
|
||||
E4F9754F1536333200FD60B2 /* KRModel.cpp in Sources */,
|
||||
E4F9754B153632D800FD60B2 /* KRModelManager.cpp in Sources */,
|
||||
E461A160152E565700F2044A /* KRDirectionalLight.cpp in Sources */,
|
||||
E4F9754515362D2C00FD60B2 /* KRBoundingVolume.cpp in Sources */,
|
||||
E4F975531536340000FD60B2 /* KRTexture2D.cpp in Sources */,
|
||||
E4F9754015362CD400FD60B2 /* KRScene.cpp in Sources */,
|
||||
E461A166152E56C000F2044A /* KRSpotLight.cpp in Sources */,
|
||||
|
||||
@@ -1,324 +0,0 @@
|
||||
//
|
||||
// KRBoundingVolume.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 <iostream>
|
||||
#include <math.h>
|
||||
|
||||
#import "KRBoundingVolume.h"
|
||||
|
||||
|
||||
KRBoundingVolume::KRBoundingVolume(const KRVector3 *pVertices) {
|
||||
for(int iVertex=0; iVertex < 8; iVertex++) {
|
||||
m_vertices[iVertex] = pVertices[iVertex];
|
||||
}
|
||||
}
|
||||
|
||||
KRBoundingVolume::KRBoundingVolume(const KRVector3 &corner1, const KRVector3 &corner2, const KRMat4 modelMatrix) {
|
||||
m_vertices[0] = KRVector3(corner1.x, corner1.y, corner1.z);
|
||||
m_vertices[1] = KRVector3(corner2.x, corner1.y, corner1.z);
|
||||
m_vertices[2] = KRVector3(corner2.x, corner2.y, corner1.z);
|
||||
m_vertices[3] = KRVector3(corner1.x, corner2.y, corner1.z);
|
||||
m_vertices[4] = KRVector3(corner1.x, corner1.y, corner2.z);
|
||||
m_vertices[5] = KRVector3(corner2.x, corner1.y, corner2.z);
|
||||
m_vertices[6] = KRVector3(corner2.x, corner2.y, corner2.z);
|
||||
m_vertices[7] = KRVector3(corner1.x, corner2.y, corner2.z);
|
||||
|
||||
for(int iVertex=0; iVertex < 8; iVertex++) {
|
||||
m_vertices[iVertex] = KRMat4::Dot(modelMatrix, m_vertices[iVertex]);
|
||||
}
|
||||
}
|
||||
|
||||
KRBoundingVolume::KRBoundingVolume(const KRMat4 &matView, GLfloat fov, GLfloat aspect, GLfloat nearz, GLfloat farz) {
|
||||
// Construct a bounding volume representing the volume of the view frustrum
|
||||
|
||||
KRMat4 invView = matView;
|
||||
invView.invert();
|
||||
|
||||
GLfloat r = tan(fov / 2.0);
|
||||
|
||||
m_vertices[0] = KRVector3(-1.0 * r * nearz * aspect, -1.0 * r * nearz, -nearz);
|
||||
m_vertices[1] = KRVector3(1.0 * r * nearz * aspect, -1.0 * r * nearz, -nearz);
|
||||
m_vertices[2] = KRVector3(1.0 * r * nearz * aspect, 1.0 * r * nearz, -nearz);
|
||||
m_vertices[3] = KRVector3(-1.0 * r * nearz * aspect, 1.0 * r * nearz, -nearz);
|
||||
m_vertices[4] = KRVector3(-1.0 * r * farz * aspect, -1.0 * r * farz, -farz);
|
||||
m_vertices[5] = KRVector3(1.0 * r * farz * aspect, -1.0 * r * farz, -farz);
|
||||
m_vertices[6] = KRVector3(1.0 * r * farz * aspect, 1.0 * r * farz, -farz);
|
||||
m_vertices[7] = KRVector3(-1.0 * r * farz * aspect, 1.0 * r * farz, -farz);
|
||||
|
||||
for(int iVertex=0; iVertex < 8; iVertex++) {
|
||||
m_vertices[iVertex] = KRMat4::Dot(invView, m_vertices[iVertex]);
|
||||
}
|
||||
}
|
||||
|
||||
KRBoundingVolume::~KRBoundingVolume() {
|
||||
|
||||
}
|
||||
|
||||
KRBoundingVolume::KRBoundingVolume(const KRBoundingVolume& p) {
|
||||
for(int iVertex=0; iVertex < 8; iVertex++) {
|
||||
m_vertices[iVertex] = p.m_vertices[iVertex];
|
||||
}
|
||||
}
|
||||
|
||||
KRBoundingVolume& KRBoundingVolume::operator = ( const KRBoundingVolume& p ) {
|
||||
for(int iVertex=0; iVertex < 8; iVertex++) {
|
||||
m_vertices[iVertex] = p.m_vertices[iVertex];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
KRBoundingVolume KRBoundingVolume::get_union(const KRBoundingVolume &p) const {
|
||||
// Simple, non-aligned bounding box calculated that contains both volumes.
|
||||
|
||||
KRVector3 minPoint = m_vertices[0], maxPoint = m_vertices[0];
|
||||
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;
|
||||
}
|
||||
}
|
||||
for(int iVertex=0; iVertex < 8; iVertex++) {
|
||||
if(p.m_vertices[iVertex].x < minPoint.x) {
|
||||
minPoint.x = p.m_vertices[iVertex].x;
|
||||
}
|
||||
if(p.m_vertices[iVertex].y < minPoint.y) {
|
||||
minPoint.y =p.m_vertices[iVertex].y;
|
||||
}
|
||||
if(p.m_vertices[iVertex].z < minPoint.z) {
|
||||
minPoint.z = p.m_vertices[iVertex].z;
|
||||
}
|
||||
if(p.m_vertices[iVertex].x > maxPoint.x) {
|
||||
maxPoint.x = p.m_vertices[iVertex].x;
|
||||
}
|
||||
if(p.m_vertices[iVertex].y > maxPoint.y) {
|
||||
maxPoint.y = p.m_vertices[iVertex].y;
|
||||
}
|
||||
if(p.m_vertices[iVertex].z > maxPoint.z) {
|
||||
maxPoint.z = p.m_vertices[iVertex].z;
|
||||
}
|
||||
}
|
||||
return KRBoundingVolume(minPoint, maxPoint, KRMat4());
|
||||
}
|
||||
|
||||
bool KRBoundingVolume::test_intersect(const KRBoundingVolume &p) const {
|
||||
// Simple, non-aligned bounding box intersection test
|
||||
|
||||
KRVector3 minPoint = m_vertices[0], maxPoint = m_vertices[0], minPoint2 = p.m_vertices[0], maxPoint2 = p.m_vertices[0];
|
||||
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;
|
||||
}
|
||||
}
|
||||
for(int iVertex=1; iVertex < 8; iVertex++) {
|
||||
if(p.m_vertices[iVertex].x < minPoint2.x) {
|
||||
minPoint2.x = p.m_vertices[iVertex].x;
|
||||
}
|
||||
if(p.m_vertices[iVertex].y < minPoint2.y) {
|
||||
minPoint2.y =p.m_vertices[iVertex].y;
|
||||
}
|
||||
if(p.m_vertices[iVertex].z < minPoint2.z) {
|
||||
minPoint2.z = p.m_vertices[iVertex].z;
|
||||
}
|
||||
if(p.m_vertices[iVertex].x > maxPoint2.x) {
|
||||
maxPoint2.x = p.m_vertices[iVertex].x;
|
||||
}
|
||||
if(p.m_vertices[iVertex].y > maxPoint2.y) {
|
||||
maxPoint2.y = p.m_vertices[iVertex].y;
|
||||
}
|
||||
if(p.m_vertices[iVertex].z > maxPoint2.z) {
|
||||
maxPoint2.z = p.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;
|
||||
}
|
||||
|
||||
bool KRBoundingVolume::test_intersect(const KRAABB &p) const {
|
||||
// Axis 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 = 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);
|
||||
shadowvp.rotate(sun_yaw, Y_AXIS);
|
||||
shadowvp.invert();
|
||||
shadowvp.scale(1.0, 1.0, -1.0);
|
||||
|
||||
KRVector3 minPointFrustrum = KRMat4::Dot(shadowvp, m_vertices[0]), maxPointFrustrum = minPointFrustrum;
|
||||
for(int iVertex=1; iVertex < 8; iVertex++) {
|
||||
KRVector3 v = KRMat4::Dot(shadowvp, m_vertices[iVertex]);
|
||||
if(v.x < minPointFrustrum.x) {
|
||||
minPointFrustrum.x = v.x;
|
||||
}
|
||||
if(v.y < minPointFrustrum.y) {
|
||||
minPointFrustrum.y = v.y;
|
||||
}
|
||||
if(v.z < minPointFrustrum.z) {
|
||||
minPointFrustrum.z = v.z;
|
||||
}
|
||||
if(v.x > maxPointFrustrum.x) {
|
||||
maxPointFrustrum.x = v.x;
|
||||
}
|
||||
if(v.y > maxPointFrustrum.y) {
|
||||
maxPointFrustrum.y = v.y;
|
||||
}
|
||||
if(v.z > maxPointFrustrum.z) {
|
||||
maxPointFrustrum.z = v.z;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
KRVector3 minPointScene = KRMat4::Dot(shadowvp, sceneVolume.m_vertices[0]), maxPointScene = minPointScene;
|
||||
for(int iVertex=1; iVertex < 8; iVertex++) {
|
||||
KRVector3 v = KRMat4::Dot(shadowvp, sceneVolume.m_vertices[iVertex]);
|
||||
if(v.x < minPointScene.x) {
|
||||
minPointScene.x = v.x;
|
||||
}
|
||||
if(v.y < minPointScene.y) {
|
||||
minPointScene.y = v.y;
|
||||
}
|
||||
if(v.z < minPointScene.z) {
|
||||
minPointScene.z = v.z;
|
||||
}
|
||||
if(v.x > maxPointScene.x) {
|
||||
maxPointScene.x = v.x;
|
||||
}
|
||||
if(v.y > maxPointScene.y) {
|
||||
maxPointScene.y = v.y;
|
||||
}
|
||||
if(v.z > maxPointScene.z) {
|
||||
maxPointScene.z = v.z;
|
||||
}
|
||||
}
|
||||
|
||||
// Include potential shadow casters outside of view frustrum
|
||||
minPointFrustrum.z = minPointScene.z;
|
||||
|
||||
if(maxPointScene.z < maxPointFrustrum.z) {
|
||||
maxPointFrustrum.z = maxPointScene.z;
|
||||
}
|
||||
|
||||
/*
|
||||
// Include potential shadow casters outside of view frustrum
|
||||
GLfloat maxFrustrumDepth = maxPointFrustrum.z;
|
||||
|
||||
for(int i=0; i<8; i++) {
|
||||
KRVector3 v = shadowvp.dot(sceneVolume.m_vertices[i]);
|
||||
if(i == 0) {
|
||||
minPointFrustrum.z = v.z;
|
||||
maxPointFrustrum.z = v.z;
|
||||
} else {
|
||||
if(v.z < minPointFrustrum.z) {
|
||||
minPointFrustrum.z = v.z;
|
||||
}
|
||||
if(v.z > maxPointFrustrum.z) {
|
||||
maxPointFrustrum.z = v.z;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(maxPointFrustrum.z > maxFrustrumDepth) {
|
||||
maxPointFrustrum.z = maxFrustrumDepth;
|
||||
}
|
||||
*/
|
||||
|
||||
shadowvp.translate(-minPointFrustrum.x, -minPointFrustrum.y, -minPointFrustrum.z);
|
||||
shadowvp.scale(2.0/(maxPointFrustrum.x - minPointFrustrum.x), 2.0/(maxPointFrustrum.y - minPointFrustrum.y), 1.0/(maxPointFrustrum.z - minPointFrustrum.z));
|
||||
shadowvp.translate(-1.0, -1.0, 0.0);
|
||||
return shadowvp;
|
||||
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
//
|
||||
// KRBoundingVolume.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.
|
||||
//
|
||||
|
||||
|
||||
#ifndef KRBOUNDINGVOLUME_H
|
||||
#define KRBOUNDINGVOLUME_H
|
||||
|
||||
#import "KREngine-common.h"
|
||||
|
||||
#import "KRVector3.h"
|
||||
#import "KRMat4.h"
|
||||
#import "KRScene.h"
|
||||
#import "KRModelManager.h"
|
||||
|
||||
class KRScene;
|
||||
class KRContext;
|
||||
|
||||
class KRBoundingVolume {
|
||||
public:
|
||||
KRBoundingVolume(const KRVector3 *pVertices);
|
||||
KRBoundingVolume(const KRVector3 &corner1, const KRVector3 &corner2, const KRMat4 modelMatrix);
|
||||
KRBoundingVolume(const KRMat4 &matView, GLfloat fov, GLfloat aspect, GLfloat nearz, GLfloat farz);
|
||||
~KRBoundingVolume();
|
||||
|
||||
KRBoundingVolume(const KRBoundingVolume& p);
|
||||
KRBoundingVolume& operator = ( const KRBoundingVolume& p );
|
||||
|
||||
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:
|
||||
KRVector3 m_vertices[8];
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -38,7 +38,6 @@
|
||||
|
||||
#import "KRVector2.h"
|
||||
#import "KRCamera.h"
|
||||
#import "KRBoundingVolume.h"
|
||||
#import "KRStockGeometry.h"
|
||||
#import "KRDirectionalLight.h"
|
||||
|
||||
@@ -341,9 +340,8 @@ void KRCamera::renderFrame(KRScene &scene, KRVector3 &lightDirection, float delt
|
||||
}
|
||||
|
||||
if(m_pSkyBoxTexture) {
|
||||
KRShader *pShader = getContext().getShaderManager()->getShader("sky_box", this, std::stack<KRLight *>(), false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_OPAQUE);
|
||||
pShader->bind(m_viewport, KRMat4(), std::stack<KRLight *>(), KRNode::RENDER_PASS_FORWARD_OPAQUE);
|
||||
|
||||
getContext().getShaderManager()->selectShader("sky_box", this, std::stack<KRLight *>(), m_viewport, KRMat4(), false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_OPAQUE);
|
||||
|
||||
getContext().getTextureManager()->selectTexture(0, m_pSkyBoxTexture, 2048);
|
||||
|
||||
// Render a full screen quad
|
||||
@@ -467,7 +465,8 @@ void KRCamera::renderFrame(KRScene &scene, KRVector3 &lightDirection, float delt
|
||||
KRMat4 matModel = KRMat4();
|
||||
matModel.scale((*itr).size() / 2.0f);
|
||||
matModel.translate((*itr).center());
|
||||
if(pVisShader->bind(m_viewport, matModel, std::stack<KRLight *>(), KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) {
|
||||
|
||||
if(getContext().getShaderManager()->selectShader(pVisShader, m_viewport, matModel, std::stack<KRLight *>(), KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) {
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14));
|
||||
}
|
||||
}
|
||||
@@ -560,10 +559,9 @@ void KRCamera::createBuffers() {
|
||||
}
|
||||
int targetVolumetricBufferWidth = 0;
|
||||
int targetVolumetricBufferHeight = 0;
|
||||
if(m_cShadowBuffers >= 1 && volumetric_environment_enable) {
|
||||
if(volumetric_environment_enable && volumetric_environment_downsample != 0) {
|
||||
targetVolumetricBufferWidth = renderBufferWidth >> volumetric_environment_downsample;
|
||||
targetVolumetricBufferHeight = renderBufferHeight >> volumetric_environment_downsample;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -665,7 +663,7 @@ void KRCamera::renderPost()
|
||||
|
||||
GLDEBUG(glDisable(GL_DEPTH_TEST));
|
||||
KRShader *postShader = m_pContext->getShaderManager()->getShader("PostShader", this, std::stack<KRLight *>(), false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
postShader->bind(m_viewport, KRMat4(), std::stack<KRLight *>(), KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
getContext().getShaderManager()->selectShader(postShader, m_viewport, KRMat4(), std::stack<KRLight *>(), KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
|
||||
m_pContext->getTextureManager()->selectTexture(0, NULL, 0);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE0));
|
||||
@@ -675,7 +673,7 @@ void KRCamera::renderPost()
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE1));
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, compositeColorTexture));
|
||||
|
||||
if(m_cShadowBuffers >= 1 && volumetric_environment_enable) {
|
||||
if(volumetric_environment_enable) {
|
||||
m_pContext->getTextureManager()->selectTexture(2, NULL, 0);
|
||||
GLDEBUG(glActiveTexture(GL_TEXTURE2));
|
||||
GLDEBUG(glBindTexture(GL_TEXTURE_2D, volumetricLightAccumulationTexture));
|
||||
@@ -702,7 +700,7 @@ void KRCamera::renderPost()
|
||||
// KRMat4 viewMatrix = KRMat4();
|
||||
// viewMatrix.scale(0.20, 0.20, 0.20);
|
||||
// viewMatrix.translate(-0.70, 0.70 - 0.45 * iShadow, 0.0);
|
||||
// blitShader->bind(KRViewport(getViewportSize(), viewMatrix, KRMat4()), shadowViewports, KRMat4(), KRVector3(), NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
// getContext().getShaderManager()->selectShader(blitShader, KRViewport(getViewportSize(), viewMatrix, KRMat4()), shadowViewports, KRMat4(), KRVector3(), NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
// m_pContext->getTextureManager()->selectTexture(1, NULL, 0);
|
||||
// m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, true, false, false, true, false);
|
||||
// GLDEBUG(glActiveTexture(GL_TEXTURE0));
|
||||
|
||||
@@ -123,7 +123,7 @@ void KRDirectionalLight::render(KRCamera *pCamera, std::stack<KRLight *> &lights
|
||||
light_direction_view_space.normalize();
|
||||
|
||||
KRShader *pShader = getContext().getShaderManager()->getShader("light_directional", pCamera, lights, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
if(pShader->bind(viewport, getModelMatrix(), lights, renderPass)) {
|
||||
if(getContext().getShaderManager()->selectShader(pShader, viewport, getModelMatrix(), lights, renderPass)) {
|
||||
|
||||
light_direction_view_space.setUniform(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_DIRECTION_VIEW_SPACE]);
|
||||
m_color.setUniform(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR]);
|
||||
|
||||
@@ -142,7 +142,7 @@ void KRLight::render(KRCamera *pCamera, std::stack<KRLight *> &lights, const KRV
|
||||
KRShader *pFogShader = m_pContext->getShaderManager()->getShader(shader_name, pCamera, this_light, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_ADDITIVE_PARTICLES);
|
||||
|
||||
|
||||
if(pFogShader->bind(viewport, KRMat4(), std::stack<KRLight *>(), KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE)) {
|
||||
if(getContext().getShaderManager()->selectShader(pFogShader, viewport, KRMat4(), std::stack<KRLight *>(), KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE)) {
|
||||
int slice_count = (int)(pCamera->volumetric_environment_quality * 495.0) + 5;
|
||||
|
||||
float slice_near = -pCamera->getPerspectiveNearZ();
|
||||
@@ -171,7 +171,7 @@ void KRLight::render(KRCamera *pCamera, std::stack<KRLight *> &lights, const KRV
|
||||
|
||||
// Render light flare on transparency pass
|
||||
KRShader *pShader = getContext().getShaderManager()->getShader("flare", pCamera, lights, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
if(pShader->bind(viewport, getModelMatrix(), lights, renderPass)) {
|
||||
if(getContext().getShaderManager()->selectShader(pShader, viewport, getModelMatrix(), lights, renderPass)) {
|
||||
GLDEBUG(glUniform1f(
|
||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE],
|
||||
m_flareSize
|
||||
@@ -277,38 +277,11 @@ void KRLight::renderShadowBuffers(KRCamera *pCamera)
|
||||
// Use shader program
|
||||
KRShader *shadowShader = m_pContext->getShaderManager()->getShader("ShadowShader", pCamera, std::stack<KRLight *>(), false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
|
||||
shadowShader->bind(m_shadowViewports[iShadow], KRMat4(), std::stack<KRLight *>(), KRNode::RENDER_PASS_SHADOWMAP);
|
||||
|
||||
// // Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram
|
||||
// shadowmvpmatrix[iShadow].setUniform(shadowShader->m_uniforms[KRShader::KRENGINE_UNIFORM_SHADOWMVP1]);
|
||||
|
||||
// // Calculate the bounding volume of the light map
|
||||
// KRMat4 matInvShadow = shadowmvpmatrix[iShadow];
|
||||
// matInvShadow.invert();
|
||||
//
|
||||
// KRVector3 vertices[8];
|
||||
// vertices[0] = KRVector3(-1.0, -1.0, 0.0);
|
||||
// vertices[1] = KRVector3(1.0, -1.0, 0.0);
|
||||
// vertices[2] = KRVector3(1.0, 1.0, 0.0);
|
||||
// vertices[3] = KRVector3(-1.0, 1.0, 0.0);
|
||||
// vertices[4] = KRVector3(-1.0, -1.0, 1.0);
|
||||
// vertices[5] = KRVector3(1.0, -1.0, 1.0);
|
||||
// vertices[6] = KRVector3(1.0, 1.0, 1.0);
|
||||
// vertices[7] = KRVector3(-1.0, 1.0, 1.0);
|
||||
//
|
||||
// for(int iVertex=0; iVertex < 8; iVertex++) {
|
||||
// vertices[iVertex] = KRMat4::Dot(matInvShadow, vertices[iVertex]);
|
||||
// }
|
||||
//
|
||||
// KRVector3 cameraPosition;
|
||||
// KRVector3 lightDirection;
|
||||
// KRBoundingVolume shadowVolume = KRBoundingVolume(vertices);
|
||||
getContext().getShaderManager()->selectShader(shadowShader, m_shadowViewports[iShadow], KRMat4(), std::stack<KRLight *>(), KRNode::RENDER_PASS_SHADOWMAP);
|
||||
|
||||
|
||||
std::set<KRAABB> newVisibleBounds;
|
||||
|
||||
getScene().render(pCamera, m_shadowViewports[iShadow].getVisibleBounds(), m_shadowViewports[iShadow], KRNode::RENDER_PASS_SHADOWMAP, newVisibleBounds);
|
||||
|
||||
m_shadowViewports[iShadow].setVisibleBounds(newVisibleBounds);
|
||||
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ bool KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, con
|
||||
|
||||
bool bSameShader = strcmp(pShader->getKey(), szPrevShaderKey) == 0;
|
||||
if(!bSameShader) {
|
||||
if(!pShader->bind(viewport, matModel, lights, renderPass)) {
|
||||
if(!getContext().getShaderManager()->selectShader(pShader, viewport, matModel, lights, renderPass)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,11 +69,11 @@ void KRParticleSystemBrownian::render(KRCamera *pCamera, std::stack<KRLight *> &
|
||||
KRTexture *pParticleTexture = m_pContext->getTextureManager()->getTexture("flare");
|
||||
m_pContext->getTextureManager()->selectTexture(0, pParticleTexture, 2048);
|
||||
|
||||
KRShader *pParticleShader = m_pContext->getShaderManager()->getShader("particle", pCamera, lights, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
|
||||
int particle_count = 10000;
|
||||
|
||||
if(pParticleShader->bind(viewport, getModelMatrix(), lights, renderPass)) {
|
||||
KRShader *pParticleShader = m_pContext->getShaderManager()->getShader("particle", pCamera, lights, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
|
||||
if(getContext().getShaderManager()->selectShader(pParticleShader, viewport, getModelMatrix(), lights, renderPass)) {
|
||||
GLDEBUG(glUniform1f(
|
||||
pParticleShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE],
|
||||
1.0f
|
||||
@@ -103,7 +103,7 @@ void KRParticleSystemBrownian::render(KRCamera *pCamera, std::stack<KRLight *> &
|
||||
//
|
||||
// int particle_count = 10000;
|
||||
//
|
||||
// if(pParticleShader->bind(m_viewport, particleModelMatrix, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_ADDITIVE_PARTICLES)) {
|
||||
// if(getContext().getShaderManager()->selectShader(pParticleShader, m_viewport, particleModelMatrix, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_ADDITIVE_PARTICLES)) {
|
||||
// GLDEBUG(glUniform1f(
|
||||
// pParticleShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE],
|
||||
// 1.0f
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#import "KRVector3.h"
|
||||
#import "KRCamera.h"
|
||||
#import "KRContext.h"
|
||||
#import "KRBoundingVolume.h"
|
||||
#import "KRStockGeometry.h"
|
||||
#import "assert.h"
|
||||
|
||||
@@ -70,7 +69,8 @@ void KRPointLight::render(KRCamera *pCamera, std::stack<KRLight *> &lights, cons
|
||||
bool bInsideLight = view_light_position.sqrMagnitude() <= (influence_radius + pCamera->getPerspectiveNearZ()) * (influence_radius + pCamera->getPerspectiveNearZ());
|
||||
|
||||
KRShader *pShader = getContext().getShaderManager()->getShader(bVisualize ? "visualize_overlay" : (bInsideLight ? "light_point_inside" : "light_point"), pCamera, lights, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
|
||||
if(pShader->bind(viewport, sphereModelMatrix, lights, renderPass)) {
|
||||
|
||||
if(getContext().getShaderManager()->selectShader(pShader, viewport, sphereModelMatrix, lights, renderPass)) {
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -184,14 +184,16 @@ void KRScene::render(KROctreeNode *pOctreeNode, const std::set<KRAABB> &visibleB
|
||||
if(bNeedOcclusionTest) {
|
||||
pOctreeNode->beginOcclusionQuery();
|
||||
|
||||
KRShader *pVisShader = getContext().getShaderManager()->getShader("occlusion_test", pCamera, lights, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||
|
||||
getContext().getModelManager()->bindVBO((void *)KRENGINE_VBO_3D_CUBE, KRENGINE_VBO_3D_CUBE_SIZE, true, false, false, false, false);
|
||||
|
||||
|
||||
KRMat4 matModel = KRMat4();
|
||||
matModel.scale(octreeBounds.size() / 2.0f);
|
||||
matModel.translate(octreeBounds.center());
|
||||
KRMat4 mvpmatrix = matModel * viewport.getViewProjectionMatrix();
|
||||
|
||||
|
||||
getContext().getModelManager()->bindVBO((void *)KRENGINE_VBO_3D_CUBE, KRENGINE_VBO_3D_CUBE_SIZE, true, false, false, false, false);
|
||||
|
||||
// Enable additive blending
|
||||
if(renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT && renderPass != KRNode::RENDER_PASS_ADDITIVE_PARTICLES && renderPass != KRNode::RENDER_PASS_VOLUMETRIC_EFFECTS_ADDITIVE) {
|
||||
GLDEBUG(glEnable(GL_BLEND));
|
||||
@@ -208,7 +210,7 @@ void KRScene::render(KROctreeNode *pOctreeNode, const std::set<KRAABB> &visibleB
|
||||
GLDEBUG(glDepthMask(GL_FALSE));
|
||||
}
|
||||
|
||||
if(pVisShader->bind(viewport, matModel, std::stack<KRLight *>(), KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) {
|
||||
if(getContext().getShaderManager()->selectShader("occlusion_test", pCamera, lights, viewport, matModel, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) {
|
||||
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14));
|
||||
}
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ KRShader::~KRShader() {
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
bool KRShader::bind(const KRViewport &viewport, const KRMat4 &matModel, const std::stack<KRLight *> &lights, const KRNode::RenderPass &renderPass) {
|
||||
bool KRShader::bind(const KRViewport &viewport, const KRMat4 &matModel, const std::stack<KRLight *> &lights, const KRNode::RenderPass &renderPass) const {
|
||||
if(m_iProgram == 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -395,10 +395,10 @@ bool KRShader::bind(const KRViewport &viewport, const KRMat4 &matModel, const st
|
||||
|
||||
#endif
|
||||
|
||||
GLuint KRShader::getProgram() {
|
||||
GLuint KRShader::getProgram() const {
|
||||
return m_iProgram;
|
||||
}
|
||||
|
||||
char *KRShader::getKey() {
|
||||
const char *KRShader::getKey() const {
|
||||
return m_szKey;
|
||||
}
|
||||
|
||||
@@ -52,12 +52,12 @@ class KRShader : public KRContextObject {
|
||||
public:
|
||||
KRShader(KRContext &context, char *szKey, std::string options, std::string vertShaderSource, const std::string fragShaderSource);
|
||||
virtual ~KRShader();
|
||||
GLuint getProgram();
|
||||
char *getKey();
|
||||
GLuint getProgram() const;
|
||||
const char *getKey() const;
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
bool bind(const KRViewport &viewport, const KRMat4 &matModel, const std::stack<KRLight *> &lights, const KRNode::RenderPass &renderPass);
|
||||
bool bind(const KRViewport &viewport, const KRMat4 &matModel, const std::stack<KRLight *> &lights, const KRNode::RenderPass &renderPass) const;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
using namespace std;
|
||||
|
||||
KRShaderManager::KRShaderManager(KRContext &context) : KRContextObject(context) {
|
||||
|
||||
m_szCurrentShaderKey[0] = '\0';
|
||||
}
|
||||
|
||||
KRShaderManager::~KRShaderManager() {
|
||||
@@ -51,7 +51,7 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, const KRCam
|
||||
|
||||
|
||||
char szKey[256];
|
||||
sprintf(szKey, "%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%i_%s_%i_%d_%d_%f_%f_%f_%f_%f_%f_%f", pCamera->bEnablePerPixel, bAlphaTest, bAlphaBlend, bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, pCamera->bDebugPSSM, iShadowQuality, pCamera->bEnableAmbient, pCamera->bEnableDiffuse, pCamera->bEnableSpecular, bLightMap, bDiffuseMapScale, bSpecMapScale, bReflectionMapScale, bNormalMapScale, bDiffuseMapOffset, bSpecMapOffset, bReflectionMapOffset, bNormalMapOffset,pCamera->volumetric_environment_enable, renderPass, shader_name.c_str(),pCamera->dof_quality,pCamera->bEnableFlash,pCamera->bEnableVignette,pCamera->dof_depth,pCamera->dof_falloff,pCamera->flash_depth,pCamera->flash_falloff,pCamera->flash_intensity,pCamera->vignette_radius,pCamera->vignette_falloff);
|
||||
sprintf(szKey, "%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%i_%s_%i_%d_%d_%f_%f_%f_%f_%f_%f_%f", pCamera->bEnablePerPixel, bAlphaTest, bAlphaBlend, bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, pCamera->bDebugPSSM, iShadowQuality, pCamera->bEnableAmbient, pCamera->bEnableDiffuse, pCamera->bEnableSpecular, bLightMap, bDiffuseMapScale, bSpecMapScale, bReflectionMapScale, bNormalMapScale, bDiffuseMapOffset, bSpecMapOffset, bReflectionMapOffset, bNormalMapOffset,pCamera->volumetric_environment_enable && pCamera->volumetric_environment_downsample != 0, renderPass, shader_name.c_str(),pCamera->dof_quality,pCamera->bEnableFlash,pCamera->bEnableVignette,pCamera->dof_depth,pCamera->dof_falloff,pCamera->flash_depth,pCamera->flash_falloff,pCamera->flash_intensity,pCamera->vignette_radius,pCamera->vignette_falloff);
|
||||
|
||||
KRShader *pShader = m_shaders[szKey];
|
||||
|
||||
@@ -114,7 +114,7 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, const KRCam
|
||||
stream << "\n#define DOF_QUALITY " << pCamera->dof_quality;
|
||||
stream << "\n#define ENABLE_FLASH " << (pCamera->bEnableFlash ? "1" : "0");
|
||||
stream << "\n#define ENABLE_VIGNETTE " << (pCamera->bEnableVignette ? "1" : "0");
|
||||
stream << "\n#define ENABLE_VOLUMETRIC_ENVIRONMENT " << (pCamera->volumetric_environment_enable ? "1" : "0");
|
||||
stream << "\n#define VOLUMETRIC_ENVIRONMENT_DOWNSAMPLED " << (pCamera->volumetric_environment_enable && pCamera->volumetric_environment_downsample != 0 ? "1" : "0");
|
||||
|
||||
|
||||
|
||||
@@ -140,6 +140,27 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, const KRCam
|
||||
return pShader;
|
||||
}
|
||||
|
||||
bool KRShaderManager::selectShader(const std::string &shader_name, const KRCamera *pCamera, const std::stack<KRLight *> &lights, const KRViewport &viewport, const KRMat4 &matModel, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass)
|
||||
{
|
||||
KRShader *pShader = getShader(shader_name, pCamera, lights, bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, bLightMap, bDiffuseMapScale, bSpecMapScale, bNormalMapScale, bReflectionMapScale, bDiffuseMapOffset, bSpecMapOffset, bNormalMapOffset, bReflectionMapOffset, bAlphaTest, bAlphaBlend, renderPass);
|
||||
return selectShader(pShader, viewport, matModel, lights, renderPass);
|
||||
}
|
||||
|
||||
bool KRShaderManager::selectShader(const KRShader *pShader, const KRViewport &viewport, const KRMat4 &matModel, const std::stack<KRLight *> &lights, const KRNode::RenderPass &renderPass)
|
||||
{
|
||||
if(pShader) {
|
||||
bool bSameShader = strcmp(pShader->getKey(), m_szCurrentShaderKey) == 0;
|
||||
if(!bSameShader) {
|
||||
strcpy(m_szCurrentShaderKey, pShader->getKey());
|
||||
return pShader->bind(viewport, matModel, lights, renderPass);
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void KRShaderManager::loadFragmentShader(const std::string &name, KRDataBlock *data) {
|
||||
m_fragShaderSource[name] = string((char *)data->getStart(), data->getSize());
|
||||
delete data;
|
||||
|
||||
@@ -61,6 +61,10 @@ public:
|
||||
|
||||
KRShader *getShader(const std::string &shader_name, const KRCamera *pCamera, const std::stack<KRLight *> &lights, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass);
|
||||
|
||||
bool selectShader(const KRShader *pShader, const KRViewport &viewport, const KRMat4 &matModel, const std::stack<KRLight *> &lights, const KRNode::RenderPass &renderPass);
|
||||
|
||||
bool selectShader(const std::string &shader_name, const KRCamera *pCamera, const std::stack<KRLight *> &lights, const KRViewport &viewport, const KRMat4 &matModel, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bReflectionMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, bool bReflectionMapOffset, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass);
|
||||
|
||||
long getShaderHandlesUsed();
|
||||
|
||||
private:
|
||||
@@ -70,6 +74,7 @@ private:
|
||||
std::map<std::string, std::string> m_vertShaderSource;
|
||||
|
||||
KRShader *m_pShader;
|
||||
char m_szCurrentShaderKey[256];
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -168,7 +168,7 @@ void main()
|
||||
#endif
|
||||
|
||||
#if GBUFFER_PASS == 2 || GBUFFER_PASS == 3
|
||||
mediump vec2 gbuffer_uv = vec2(gl_FragCoord.xy / viewport.zw);
|
||||
mediump vec2 gbuffer_uv = vec2(gl_FragCoord.xy / viewport.zw); // FINDME, TODO - Dependent Texture Read adding latency, due to calculation of texture UV within fragment -- move to vertex shader?
|
||||
#endif
|
||||
|
||||
#if GBUFFER_PASS == 3
|
||||
|
||||
@@ -168,7 +168,7 @@ void main()
|
||||
normal_uv = texCoord;
|
||||
|
||||
#if HAS_NORMAL_MAP_OFFSET == 1
|
||||
normal_uv + normalTexture_Offset;
|
||||
normal_uv += normalTexture_Offset;
|
||||
#endif
|
||||
|
||||
#if HAS_NORMAL_MAP_SCALE == 1
|
||||
@@ -183,7 +183,7 @@ void main()
|
||||
diffuse_uv = texCoord;
|
||||
|
||||
#if HAS_DIFFUSE_MAP_OFFSET == 1
|
||||
diffuse_uv + diffuseTexture_Offset;
|
||||
diffuse_uv += diffuseTexture_Offset;
|
||||
#endif
|
||||
|
||||
#if HAS_DIFFUSE_MAP_SCALE == 1
|
||||
@@ -228,7 +228,7 @@ void main()
|
||||
#if HAS_SPEC_MAP_OFFSET == 1 || HAS_SPEC_MAP_SCALE == 1
|
||||
spec_uv = texCoord;
|
||||
#if HAS_SPEC_MAP_OFFSET == 1
|
||||
spec_uv + specularTexture_Offset;
|
||||
spec_uv += specularTexture_Offset;
|
||||
#endif
|
||||
|
||||
#if HAS_SPEC_MAP_SCALE == 1
|
||||
@@ -240,7 +240,7 @@ void main()
|
||||
#if HAS_REFLECTION_MAP_OFFSET == 1 || HAS_REFLECTION_MAP_SCALE == 1
|
||||
reflection_uv = texCoord;
|
||||
#if HAS_REFLECTION_MAP_OFFSET == 1
|
||||
reflection_uv + reflectionTexture_Offset;
|
||||
reflection_uv += reflectionTexture_Offset;
|
||||
#endif
|
||||
|
||||
#if HAS_REFLECTION_MAP_SCALE == 1
|
||||
|
||||
@@ -41,7 +41,7 @@ uniform lowp sampler2D videoFrame;
|
||||
uniform lowp sampler2D renderFrame;
|
||||
uniform lowp sampler2D depthFrame;
|
||||
|
||||
#if ENABLE_VOLUMETRIC_ENVIRONMENT == 1
|
||||
#if VOLUMETRIC_ENVIRONMENT_DOWNSAMPLED == 1
|
||||
uniform lowp sampler2D volumetricEnvironmentFrame;
|
||||
#endif
|
||||
|
||||
@@ -162,7 +162,7 @@ void main()
|
||||
|
||||
// ---- VIDEO_BG END ----
|
||||
|
||||
#if ENABLE_VOLUMETRIC_ENVIRONMENT == 1
|
||||
#if VOLUMETRIC_ENVIRONMENT_DOWNSAMPLED == 1
|
||||
pixelColor += texture2D(volumetricEnvironmentFrame, textureCoordinate);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ uniform mediump vec4 viewport;
|
||||
|
||||
void main()
|
||||
{
|
||||
lowp vec2 gbuffer_uv = vec2(gl_FragCoord.xy / viewport.zw);
|
||||
lowp vec2 gbuffer_uv = vec2(gl_FragCoord.xy / viewport.zw); // FINDME, TODO - Dependent Texture Read adding latency, due to calculation of texture UV within fragment -- move to vertex shader?
|
||||
lowp vec4 gbuffer_sample = texture2D(gbuffer_frame, gbuffer_uv);
|
||||
|
||||
mediump vec3 gbuffer_normal = normalize(2.0 * gbuffer_sample.rgb - 1.0);
|
||||
|
||||
@@ -42,7 +42,7 @@ uniform highp vec3 view_space_model_origin; // For point lights, this is the pos
|
||||
void main()
|
||||
{
|
||||
|
||||
lowp vec2 gbuffer_uv = vec2(gl_FragCoord.xy / viewport.zw);
|
||||
lowp vec2 gbuffer_uv = vec2(gl_FragCoord.xy / viewport.zw); // FINDME, TODO - Dependent Texture Read adding latency, due to calculation of texture UV within fragment -- move to vertex shader?
|
||||
lowp vec4 gbuffer_sample = texture2D(gbuffer_frame, gbuffer_uv);
|
||||
|
||||
mediump vec3 gbuffer_normal = normalize(2.0 * gbuffer_sample.rgb - 1.0);
|
||||
|
||||
@@ -42,7 +42,7 @@ uniform highp vec3 view_space_model_origin;
|
||||
void main()
|
||||
{
|
||||
|
||||
lowp vec2 gbuffer_uv = vec2(gl_FragCoord.xy / viewport.zw);
|
||||
lowp vec2 gbuffer_uv = vec2(gl_FragCoord.xy / viewport.zw); // FINDME, TODO - Dependent Texture Read adding latency, due to calculation of texture UV within fragment -- move to vertex shader?
|
||||
lowp vec4 gbuffer_sample = texture2D(gbuffer_frame, gbuffer_uv);
|
||||
|
||||
mediump vec3 gbuffer_normal = normalize(2.0 * gbuffer_sample.rgb - 1.0);
|
||||
|
||||
Reference in New Issue
Block a user