--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%406
This commit is contained in:
@@ -213,22 +213,37 @@ double const PI = 3.141592653589793f;
|
||||
lightDirection.normalize();
|
||||
|
||||
[self allocateShadowBuffers];
|
||||
for(int iShadow=0; iShadow < m_cShadowBuffers; iShadow++) {
|
||||
if(!shadowValid[iShadow] || true) {
|
||||
int iOffset=m_iFrame % m_cShadowBuffers;
|
||||
for(int iShadow2=iOffset; iShadow2 < m_cShadowBuffers + iOffset; iShadow2++) {
|
||||
int iShadow = iShadow2 % m_cShadowBuffers;
|
||||
|
||||
|
||||
GLfloat shadowMinDepths[3][3] = {{0.0, 0.0, 0.0},{0.0, 0.0, 0.0},{0.0, 0.05, 0.3}};
|
||||
GLfloat shadowMaxDepths[3][3] = {{0.0, 0.0, 1.0},{0.1, 0.0, 0.0},{0.1, 0.3, 1.0}};
|
||||
|
||||
|
||||
KRMat4 newShadowMVP;
|
||||
if(shadowMaxDepths[m_cShadowBuffers - 1][iShadow] == 0.0) {
|
||||
KRBoundingVolume ext = KRBoundingVolume(pScene->getExtents());
|
||||
|
||||
newShadowMVP = ext.calcShadowProj(pScene, sun_yaw, sun_pitch);
|
||||
} else {
|
||||
KRBoundingVolume frustrumSliceVolume = KRBoundingVolume(viewMatrix, m_camera.perspective_fov, m_camera.perspective_aspect, m_camera.perspective_nearz + (m_camera.perspective_farz - m_camera.perspective_nearz) * shadowMinDepths[m_cShadowBuffers - 1][iShadow], m_camera.perspective_nearz + (m_camera.perspective_farz - m_camera.perspective_nearz) * shadowMaxDepths[m_cShadowBuffers - 1][iShadow]);
|
||||
newShadowMVP = frustrumSliceVolume.calcShadowProj(pScene, sun_yaw, sun_pitch);
|
||||
}
|
||||
|
||||
if(!(shadowmvpmatrix[iShadow] == newShadowMVP)) {
|
||||
shadowValid[iShadow] = false;
|
||||
}
|
||||
|
||||
if(!shadowValid[iShadow]) {
|
||||
shadowValid[iShadow] = true;
|
||||
|
||||
GLfloat shadowMinDepths[3][3] = {{0.0, 0.0, 0.0},{0.0, 0.0, 0.0},{0.0, 0.05, 0.3}};
|
||||
GLfloat shadowMaxDepths[3][3] = {{0.0, 0.0, 1.0},{0.1, 0.0, 0.0},{0.1, 0.3, 1.0}};
|
||||
|
||||
|
||||
if(shadowMaxDepths[m_cShadowBuffers - 1][iShadow] == 0.0) {
|
||||
shadowmvpmatrix[iShadow] = pScene->getExtents().calcShadowProj(pScene, sun_yaw, sun_pitch);
|
||||
} else {
|
||||
KRBoundingVolume frustrumSliceVolume = KRBoundingVolume(viewMatrix, m_camera.perspective_fov, m_camera.perspective_aspect, m_camera.perspective_nearz + (m_camera.perspective_farz - m_camera.perspective_nearz) * shadowMinDepths[m_cShadowBuffers - 1][iShadow], m_camera.perspective_nearz + (m_camera.perspective_farz - m_camera.perspective_nearz) * shadowMaxDepths[m_cShadowBuffers - 1][iShadow]);
|
||||
shadowmvpmatrix[iShadow] = frustrumSliceVolume.calcShadowProj(pScene, sun_yaw, sun_pitch);
|
||||
}
|
||||
shadowmvpmatrix[iShadow] = newShadowMVP;
|
||||
|
||||
[self renderShadowBufferNumber: iShadow ForScene: pScene];
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,6 @@ GLfloat *KRMat4::getPointer() {
|
||||
|
||||
// Copy constructor
|
||||
KRMat4::KRMat4(const KRMat4 &m) {
|
||||
|
||||
memcpy(m_mat, m.m_mat, sizeof(GLfloat) * 16);
|
||||
}
|
||||
|
||||
@@ -72,6 +71,11 @@ KRMat4& KRMat4::operator=(const KRMat4 &m) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Overload comparison operator
|
||||
bool KRMat4::operator==(const KRMat4 &m) {
|
||||
return memcmp(m_mat, m.m_mat, sizeof(GLfloat) * 16) == 0;
|
||||
}
|
||||
|
||||
// Overload compound multiply operator
|
||||
KRMat4& KRMat4::operator*=(const KRMat4 &m) {
|
||||
GLfloat temp[16];
|
||||
@@ -93,15 +97,7 @@ KRMat4& KRMat4::operator*=(const KRMat4 &m) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
/*
|
||||
// Overload multiply operator
|
||||
KRMat4& KRMat4::operator*(const KRMat4 &m, const KRMat4 &m) {
|
||||
KRMat4 result = *this;
|
||||
result *= m;
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
|
||||
KRMat4 KRMat4::operator*(const KRMat4 &m) {
|
||||
KRMat4 ret = *this;
|
||||
ret *= m;
|
||||
@@ -137,7 +133,6 @@ void KRMat4::translate(GLfloat x, GLfloat y, GLfloat z) {
|
||||
|
||||
/* Rotate a matrix by an angle on a X, Y, or Z axis */
|
||||
void KRMat4::rotate(GLfloat angle, AXIS axis) {
|
||||
// const GLfloat d2r = 0.0174532925199; /* PI / 180 */
|
||||
const int cos1[3] = { 5, 0, 0 };
|
||||
const int cos2[3] = { 10, 10, 5 };
|
||||
const int sin1[3] = { 6, 2, 1 };
|
||||
@@ -153,6 +148,7 @@ void KRMat4::rotate(GLfloat angle, AXIS axis) {
|
||||
*this *= newMatrix;
|
||||
}
|
||||
|
||||
/* Scale matrix by separate x, y, and z amounts */
|
||||
void KRMat4::scale(GLfloat x, GLfloat y, GLfloat z) {
|
||||
KRMat4 newMatrix; // Create new identity matrix
|
||||
|
||||
@@ -163,12 +159,13 @@ void KRMat4::scale(GLfloat x, GLfloat y, GLfloat z) {
|
||||
*this *= newMatrix;
|
||||
}
|
||||
|
||||
/* Scale all dimensions equally */
|
||||
void KRMat4::scale(GLfloat s) {
|
||||
scale(s,s,s);
|
||||
}
|
||||
|
||||
// Initialize with a bias matrix
|
||||
void KRMat4::bias() {
|
||||
// Initialize with a bias matrix
|
||||
static const GLfloat BIAS_MATRIX[] = {
|
||||
0.5, 0.0, 0.0, 0.0,
|
||||
0.0, 0.5, 0.0, 0.0,
|
||||
@@ -182,15 +179,6 @@ void KRMat4::bias() {
|
||||
/* Generate an orthographic view matrix */
|
||||
void KRMat4::ortho(GLfloat left, GLfloat right, GLfloat top, GLfloat bottom, GLfloat nearz, GLfloat farz) {
|
||||
memset(m_mat, 0, sizeof(GLfloat) * 16);
|
||||
/*
|
||||
m_mat[0] = 2.0f / (right - left);
|
||||
m_mat[3] = -(right + left) / (right - left);
|
||||
m_mat[5] = 2.0f / (top - bottom);
|
||||
m_mat[7] = -(top + bottom) / (top - bottom);
|
||||
m_mat[10] = -2.0f / (farz - nearz);
|
||||
m_mat[11] = -(farz + nearz) / (farz - nearz);
|
||||
m_mat[15] = 1.0f;
|
||||
*/
|
||||
m_mat[0] = 2.0f / (right - left);
|
||||
m_mat[5] = 2.0f / (bottom - top);
|
||||
m_mat[10] = -1.0f / (farz - nearz);
|
||||
@@ -198,30 +186,8 @@ void KRMat4::ortho(GLfloat left, GLfloat right, GLfloat top, GLfloat bottom, GLf
|
||||
m_mat[15] = 1.0f;
|
||||
}
|
||||
|
||||
/* Replace matrix with its inverse */
|
||||
bool KRMat4::invert() {
|
||||
/*
|
||||
GLfloat inverseTranslation[16];
|
||||
GLfloat inverseRotation[16];
|
||||
|
||||
|
||||
|
||||
inverseTranslation[0] = 1 ; inverseTranslation[4] = 0 ; inverseTranslation[8] = 0 ; inverseTranslation[12] = -m_mat[12] ;
|
||||
inverseTranslation[1] = 0 ; inverseTranslation[5] = 1 ; inverseTranslation[9] = 0 ; inverseTranslation[13] = -m_mat[13] ;
|
||||
inverseTranslation[2] = 0 ; inverseTranslation[6] = 0 ; inverseTranslation[10] = 1 ; inverseTranslation[14] = -m_mat[14] ;
|
||||
inverseTranslation[3] = 0 ; inverseTranslation[7] = 0 ; inverseTranslation[11] = 0 ; inverseTranslation[15] = 1 ;
|
||||
|
||||
inverseRotation[0] = m_mat[0] ; inverseRotation[4] = m_mat[1] ; inverseRotation[8] = m_mat[2] ; inverseRotation[12] = 0 ;
|
||||
inverseRotation[1] = m_mat[4] ; inverseRotation[5] = m_mat[5] ; inverseRotation[9] = m_mat[6] ; inverseRotation[13] = 0 ;
|
||||
inverseRotation[2] = m_mat[8] ; inverseRotation[6] = m_mat[9] ; inverseRotation[10] = m_mat[10] ; inverseRotation[14] = 0 ;
|
||||
inverseRotation[3] = 0 ; inverseRotation[7] = 0 ; inverseRotation[11] = 0 ; inverseRotation[15] = 1 ;
|
||||
|
||||
KRMat4 inverseRotMat(inverseRotation);
|
||||
KRMat4 inverseTransMat(inverseTranslation);
|
||||
|
||||
KRMat4 m = inverseRotMat * inverseTransMat;
|
||||
memcpy(m_mat, m.m_mat, sizeof(GLfloat) * 16);
|
||||
*/
|
||||
|
||||
// Based on gluInvertMatrix implementation
|
||||
|
||||
double inv[16], det;
|
||||
@@ -272,12 +238,10 @@ bool KRMat4::invert() {
|
||||
m_mat[i] = inv[i] * det;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* Dot Product */
|
||||
Vector3 KRMat4::dot(const Vector3 &v) const {
|
||||
return Vector3(
|
||||
v.x * (float)m_mat[0*4 + 0] + v.y * (float)m_mat[1*4 + 0] + v.z * (float)m_mat[2*4 + 0] + (float)m_mat[3*4 + 0],
|
||||
|
||||
@@ -75,6 +75,9 @@ public:
|
||||
// Overload assignment operator
|
||||
KRMat4& operator=(const KRMat4 &m);
|
||||
|
||||
// Overload comparison operator
|
||||
bool operator==(const KRMat4 &m);
|
||||
|
||||
// Overload compound multiply operator
|
||||
KRMat4& operator*=(const KRMat4 &m);
|
||||
|
||||
|
||||
@@ -99,12 +99,10 @@ void KRModel::loadPack(std::string path, KRMaterialManager *pMaterialManager) {
|
||||
m_pBuffers = new GLuint[m_cBuffers];
|
||||
glGenBuffers(m_cBuffers, m_pBuffers);
|
||||
for(GLsizei iBuffer=0; iBuffer < m_cBuffers; iBuffer++) {
|
||||
// if(iBuffer < 30) {
|
||||
GLsizei cVertexes = iBuffer < m_cBuffers - 1 ? MAX_VBO_SIZE : pHeader->vertex_count % MAX_VBO_SIZE;
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_pBuffers[iBuffer]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(VertexData) * cVertexes, m_pVertexData + iBuffer * MAX_VBO_SIZE, GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
// }
|
||||
GLsizei cVertexes = iBuffer < m_cBuffers - 1 ? MAX_VBO_SIZE : pHeader->vertex_count % MAX_VBO_SIZE;
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_pBuffers[iBuffer]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(VertexData) * cVertexes, m_pVertexData + iBuffer * MAX_VBO_SIZE, GL_STATIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -438,8 +436,6 @@ void KRModel::loadWavefront(std::string path, KRMaterialManager *pMaterialManage
|
||||
|
||||
|
||||
// Calculate surface normals and tangents
|
||||
// http://www.terathon.com/code/tangent.html
|
||||
// http://www.fabiensanglard.net/bumpMapping/index.php
|
||||
|
||||
for(std::vector<Material *>::iterator itr = m_materials.begin(); itr != m_materials.end(); itr++) {
|
||||
VertexData *pStart = m_pVertexData + (*itr)->start_vertex;
|
||||
|
||||
@@ -166,17 +166,7 @@ void KRShader::bind(KRCamera *pCamera, KRMat4 &mvpMatrix, Vector3 &cameraPositio
|
||||
glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2], 4);
|
||||
glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3], 5);
|
||||
|
||||
/*
|
||||
#if defined(DEBUG)
|
||||
if (![self validateProgram:m_iProgram])
|
||||
{
|
||||
NSLog(@"Failed to validate program: %d", m_shadowShaderProgram);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
|
||||
GLint logLength, status;
|
||||
|
||||
glValidateProgram(m_iProgram);
|
||||
@@ -188,15 +178,8 @@ void KRShader::bind(KRCamera *pCamera, KRMat4 &mvpMatrix, Vector3 &cameraPositio
|
||||
fprintf(stderr, "Program validate log:\n%s", log);
|
||||
free(log);
|
||||
}
|
||||
|
||||
/*
|
||||
glGetProgramiv(m_iProgram, GL_VALIDATE_STATUS, &status);
|
||||
if (status == 0) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
GLuint KRShader::getProgram() {
|
||||
|
||||
Reference in New Issue
Block a user