Point lights no longer disappear when the camera is too close (within their sphere of influence)
--HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4092
This commit is contained in:
@@ -144,6 +144,8 @@
|
|||||||
E4BBBB9E1512A4AE00F43B5B /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4BBBB961512A46700F43B5B /* AppKit.framework */; };
|
E4BBBB9E1512A4AE00F43B5B /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4BBBB961512A46700F43B5B /* AppKit.framework */; };
|
||||||
E4BBBB9F1512A4B100F43B5B /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4BBBB941512A45500F43B5B /* Cocoa.framework */; };
|
E4BBBB9F1512A4B100F43B5B /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E4BBBB941512A45500F43B5B /* Cocoa.framework */; };
|
||||||
E4BBBBA71512A6DC00F43B5B /* KRVector3.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017F13C99BDC0098455B /* KRVector3.cpp */; };
|
E4BBBBA71512A6DC00F43B5B /* KRVector3.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E491017F13C99BDC0098455B /* KRVector3.cpp */; };
|
||||||
|
E4CE184D15FF124600F80870 /* light_point_inside.fsh in Sources */ = {isa = PBXBuildFile; fileRef = E4CE184C15FF124600F80870 /* light_point_inside.fsh */; };
|
||||||
|
E4CE184F15FF125700F80870 /* light_point_inside.vsh in Sources */ = {isa = PBXBuildFile; fileRef = E4CE184E15FF125700F80870 /* light_point_inside.vsh */; };
|
||||||
E4D0683F1512A790005FFBEB /* KRVector3.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017E13C99BDC0098455B /* KRVector3.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
E4D0683F1512A790005FFBEB /* KRVector3.h in Headers */ = {isa = PBXBuildFile; fileRef = E491017E13C99BDC0098455B /* KRVector3.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
E4D13364153767ED0070068C /* KRShaderManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47C25A613F4F6AB00FF4370 /* KRShaderManager.cpp */; settings = {ATTRIBUTES = (Public, ); }; };
|
E4D13364153767ED0070068C /* KRShaderManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E47C25A613F4F6AB00FF4370 /* KRShaderManager.cpp */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
E4D13365153767FF0070068C /* KRShaderManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E47C25A113F4F65A00FF4370 /* KRShaderManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
E4D13365153767FF0070068C /* KRShaderManager.h in Headers */ = {isa = PBXBuildFile; fileRef = E47C25A113F4F65A00FF4370 /* KRShaderManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
@@ -297,6 +299,8 @@
|
|||||||
E4BBBB981512A47500F43B5B /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/CoreData.framework; sourceTree = DEVELOPER_DIR; };
|
E4BBBB981512A47500F43B5B /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/CoreData.framework; sourceTree = DEVELOPER_DIR; };
|
||||||
E4BBBB9A1512A48200F43B5B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; };
|
E4BBBB9A1512A48200F43B5B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; };
|
||||||
E4CE184815FEEDA200F80870 /* font.pvr */ = {isa = PBXFileReference; lastKnownFileType = file; name = font.pvr; path = Shaders/font.pvr; sourceTree = "<group>"; };
|
E4CE184815FEEDA200F80870 /* font.pvr */ = {isa = PBXFileReference; lastKnownFileType = file; name = font.pvr; path = Shaders/font.pvr; sourceTree = "<group>"; };
|
||||||
|
E4CE184C15FF124600F80870 /* light_point_inside.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_point_inside.fsh; path = Shaders/light_point_inside.fsh; sourceTree = "<group>"; };
|
||||||
|
E4CE184E15FF125700F80870 /* light_point_inside.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_point_inside.vsh; path = Shaders/light_point_inside.vsh; sourceTree = "<group>"; };
|
||||||
E4D133B91538F7480070068C /* light_directional.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_directional.fsh; path = Shaders/light_directional.fsh; sourceTree = "<group>"; };
|
E4D133B91538F7480070068C /* light_directional.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_directional.fsh; path = Shaders/light_directional.fsh; sourceTree = "<group>"; };
|
||||||
E4D133BB1538F7560070068C /* light_directional.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_directional.vsh; path = Shaders/light_directional.vsh; sourceTree = "<group>"; };
|
E4D133BB1538F7560070068C /* light_directional.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_directional.vsh; path = Shaders/light_directional.vsh; sourceTree = "<group>"; };
|
||||||
E4F711A41512BB56007EE923 /* libfbxsdk-2012.2-static.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libfbxsdk-2012.2-static.a"; path = "../../../../../../../../Applications/Autodesk/FBXSDK20122/lib/gcc4/ub/libfbxsdk-2012.2-static.a"; sourceTree = "<group>"; };
|
E4F711A41512BB56007EE923 /* libfbxsdk-2012.2-static.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libfbxsdk-2012.2-static.a"; path = "../../../../../../../../Applications/Autodesk/FBXSDK20122/lib/gcc4/ub/libfbxsdk-2012.2-static.a"; sourceTree = "<group>"; };
|
||||||
@@ -351,6 +355,8 @@
|
|||||||
E430D08015F8882F0010558D /* occlusion_test.fsh */,
|
E430D08015F8882F0010558D /* occlusion_test.fsh */,
|
||||||
E430D08815F88AD10010558D /* occlusion_test.vsh */,
|
E430D08815F88AD10010558D /* occlusion_test.vsh */,
|
||||||
E48839A015F92C2800BD66D5 /* visualize_overlay.fsh */,
|
E48839A015F92C2800BD66D5 /* visualize_overlay.fsh */,
|
||||||
|
E4CE184C15FF124600F80870 /* light_point_inside.fsh */,
|
||||||
|
E4CE184E15FF125700F80870 /* light_point_inside.vsh */,
|
||||||
);
|
);
|
||||||
name = Shaders;
|
name = Shaders;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@@ -860,6 +866,8 @@
|
|||||||
E488399415F928CA00BD66D5 /* KRBundle.cpp in Sources */,
|
E488399415F928CA00BD66D5 /* KRBundle.cpp in Sources */,
|
||||||
E488399C15F92BE000BD66D5 /* KRBundleManager.cpp in Sources */,
|
E488399C15F92BE000BD66D5 /* KRBundleManager.cpp in Sources */,
|
||||||
E48839A115F92C2800BD66D5 /* visualize_overlay.fsh in Sources */,
|
E48839A115F92C2800BD66D5 /* visualize_overlay.fsh in Sources */,
|
||||||
|
E4CE184D15FF124600F80870 /* light_point_inside.fsh in Sources */,
|
||||||
|
E4CE184F15FF125700F80870 /* light_point_inside.vsh in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -55,9 +55,7 @@ void KRDataBlock::unload()
|
|||||||
{
|
{
|
||||||
if(m_fdPackFile) {
|
if(m_fdPackFile) {
|
||||||
// Memory mapped file
|
// Memory mapped file
|
||||||
if(m_bMalloced) {
|
munmap(m_data, m_data_size);
|
||||||
munmap(m_data, m_data_size);
|
|
||||||
}
|
|
||||||
close(m_fdPackFile);
|
close(m_fdPackFile);
|
||||||
} else if(m_data != NULL && m_bMalloced) {
|
} else if(m_data != NULL && m_bMalloced) {
|
||||||
// Malloc'ed data
|
// Malloc'ed data
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ vector<KRMesh::Submesh *> KRMesh::getSubmeshes() {
|
|||||||
return m_submeshes;
|
return m_submeshes;
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRMesh::renderSubmesh(int iSubmesh, int *iPrevBuffer) {
|
void KRMesh::renderSubmesh(int iSubmesh, int &iPrevBuffer) {
|
||||||
VertexData *pVertexData = getVertexData();
|
VertexData *pVertexData = getVertexData();
|
||||||
//
|
//
|
||||||
// if(m_cBuffers == 0) {
|
// if(m_cBuffers == 0) {
|
||||||
@@ -130,11 +130,11 @@ void KRMesh::renderSubmesh(int iSubmesh, int *iPrevBuffer) {
|
|||||||
iVertex = iVertex % MAX_VBO_SIZE;
|
iVertex = iVertex % MAX_VBO_SIZE;
|
||||||
int cVertexes = pSubmesh->vertex_count;
|
int cVertexes = pSubmesh->vertex_count;
|
||||||
while(cVertexes > 0) {
|
while(cVertexes > 0) {
|
||||||
//if(*iPrevBuffer != iBuffer) {
|
if(iPrevBuffer != iBuffer) {
|
||||||
GLsizei cBufferVertexes = iBuffer < cBuffers - 1 ? MAX_VBO_SIZE : pHeader->vertex_count % MAX_VBO_SIZE;
|
GLsizei cBufferVertexes = iBuffer < cBuffers - 1 ? MAX_VBO_SIZE : pHeader->vertex_count % MAX_VBO_SIZE;
|
||||||
m_pContext->getModelManager()->bindVBO(pVertexData + iBuffer * MAX_VBO_SIZE, sizeof(VertexData) * cBufferVertexes);
|
m_pContext->getModelManager()->bindVBO(pVertexData + iBuffer * MAX_VBO_SIZE, sizeof(VertexData) * cBufferVertexes);
|
||||||
|
|
||||||
if(*iPrevBuffer == -1) {
|
if(iPrevBuffer == -1) {
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
|
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_NORMAL);
|
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_NORMAL);
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TANGENT);
|
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_TANGENT);
|
||||||
@@ -150,8 +150,8 @@ void KRMesh::renderSubmesh(int iSubmesh, int *iPrevBuffer) {
|
|||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TANGENT, 3, GL_FLOAT, 0, data_size, BUFFER_OFFSET(sizeof(KRVector3D) * 2));
|
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TANGENT, 3, GL_FLOAT, 0, data_size, BUFFER_OFFSET(sizeof(KRVector3D) * 2));
|
||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, 0, data_size, BUFFER_OFFSET(sizeof(KRVector3D) * 3));
|
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVA, 2, GL_FLOAT, 0, data_size, BUFFER_OFFSET(sizeof(KRVector3D) * 3));
|
||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVB, 2, GL_FLOAT, 0, data_size, BUFFER_OFFSET(sizeof(KRVector3D) * 3 + sizeof(TexCoord)));
|
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_TEXUVB, 2, GL_FLOAT, 0, data_size, BUFFER_OFFSET(sizeof(KRVector3D) * 3 + sizeof(TexCoord)));
|
||||||
//}
|
}
|
||||||
*iPrevBuffer = iBuffer;
|
iPrevBuffer = iBuffer;
|
||||||
|
|
||||||
if(iVertex + cVertexes >= MAX_VBO_SIZE) {
|
if(iVertex + cVertexes >= MAX_VBO_SIZE) {
|
||||||
glDrawArrays(GL_TRIANGLES, iVertex, (MAX_VBO_SIZE - iVertex));
|
glDrawArrays(GL_TRIANGLES, iVertex, (MAX_VBO_SIZE - iVertex));
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public:
|
|||||||
void loadPack(KRDataBlock *data);
|
void loadPack(KRDataBlock *data);
|
||||||
|
|
||||||
|
|
||||||
void renderSubmesh(int iSubmesh, int *iPrevBuffer);
|
void renderSubmesh(int iSubmesh, int &iPrevBuffer);
|
||||||
|
|
||||||
GLfloat getMaxDimension();
|
GLfloat getMaxDimension();
|
||||||
|
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ void KRModel::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &matModelToV
|
|||||||
|
|
||||||
if(!pMaterial->isTransparent()) {
|
if(!pMaterial->isTransparent()) {
|
||||||
// Exclude transparent and semi-transparent meshes from shadow maps
|
// Exclude transparent and semi-transparent meshes from shadow maps
|
||||||
m_pMesh->renderSubmesh(iSubmesh, &iPrevBuffer);
|
m_pMesh->renderSubmesh(iSubmesh, iPrevBuffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,19 +121,19 @@ void KRModel::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &matModelToV
|
|||||||
switch(pMaterial->getAlphaMode()) {
|
switch(pMaterial->getAlphaMode()) {
|
||||||
case KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE: // Non-transparent materials
|
case KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE: // Non-transparent materials
|
||||||
case KRMaterial::KRMATERIAL_ALPHA_MODE_TEST: // Alpha in diffuse texture is interpreted as punch-through when < 0.5
|
case KRMaterial::KRMATERIAL_ALPHA_MODE_TEST: // Alpha in diffuse texture is interpreted as punch-through when < 0.5
|
||||||
m_pMesh->renderSubmesh(iSubmesh, &iPrevBuffer);
|
m_pMesh->renderSubmesh(iSubmesh, iPrevBuffer);
|
||||||
break;
|
break;
|
||||||
case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDONESIDE: // Blended alpha with backface culling
|
case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDONESIDE: // Blended alpha with backface culling
|
||||||
m_pMesh->renderSubmesh(iSubmesh, &iPrevBuffer);
|
m_pMesh->renderSubmesh(iSubmesh, iPrevBuffer);
|
||||||
break;
|
break;
|
||||||
case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE: // Blended alpha rendered in two passes. First pass renders backfaces; second pass renders frontfaces.
|
case KRMaterial::KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE: // Blended alpha rendered in two passes. First pass renders backfaces; second pass renders frontfaces.
|
||||||
// Render back faces first
|
// Render back faces first
|
||||||
glCullFace(GL_BACK);
|
glCullFace(GL_BACK);
|
||||||
m_pMesh->renderSubmesh(iSubmesh, &iPrevBuffer);
|
m_pMesh->renderSubmesh(iSubmesh, iPrevBuffer);
|
||||||
|
|
||||||
// Render front faces second
|
// Render front faces second
|
||||||
glCullFace(GL_BACK);
|
glCullFace(GL_BACK);
|
||||||
m_pMesh->renderSubmesh(iSubmesh, &iPrevBuffer);
|
m_pMesh->renderSubmesh(iSubmesh, iPrevBuffer);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,13 +66,11 @@ std::map<std::string, KRModel *> KRModelManager::getModels() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void KRModelManager::bindVBO(const GLvoid *data, GLsizeiptr size) {
|
void KRModelManager::bindVBO(const GLvoid *data, GLsizeiptr size) {
|
||||||
assert(size > 0);
|
|
||||||
|
|
||||||
if(m_currentVBO.data != data || m_currentVBO.size != size) {
|
if(m_currentVBO.data != data || m_currentVBO.size != size) {
|
||||||
|
|
||||||
if(m_vbos.find(data) != m_vbos.end()) {
|
if(m_vbos.find(data) != m_vbos.end()) {
|
||||||
m_currentVBO = m_vbos[data];
|
m_currentVBO = m_vbos[data];
|
||||||
assert(m_currentVBO.size == size);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, m_currentVBO.handle);
|
glBindBuffer(GL_ARRAY_BUFFER, m_currentVBO.handle);
|
||||||
} else {
|
} else {
|
||||||
m_vboMemUsed += size;
|
m_vboMemUsed += size;
|
||||||
|
|||||||
@@ -74,7 +74,11 @@ void KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolu
|
|||||||
if(influence_extents.test_intersect(frustrumVolumeNoNearClip)) {
|
if(influence_extents.test_intersect(frustrumVolumeNoNearClip)) {
|
||||||
// Cull out any lights not within the view frustrum
|
// Cull out any lights not within the view frustrum
|
||||||
|
|
||||||
KRShader *pShader = pContext->getShaderManager()->getShader("light_point", pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, false, renderPass);
|
KRVector3 view_light_position = KRMat4::Dot(viewMatrix, light_position);
|
||||||
|
|
||||||
|
bool bInsideLight = view_light_position.sqrMagnitude() <= (influence_radius + pCamera->perspective_nearz) * (influence_radius + pCamera->perspective_nearz);
|
||||||
|
|
||||||
|
KRShader *pShader = pContext->getShaderManager()->getShader(bInsideLight ? "light_point_inside" : "light_point", pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, false, renderPass);
|
||||||
pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass);
|
pShader->bind(pCamera, matModelToView, mvpmatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass);
|
||||||
glUniform3f(
|
glUniform3f(
|
||||||
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR],
|
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR],
|
||||||
@@ -122,22 +126,40 @@ void KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolu
|
|||||||
matInvProjection.invert();
|
matInvProjection.invert();
|
||||||
glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_INVP], 1, GL_FALSE, matInvProjection.getPointer());
|
glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_INVP], 1, GL_FALSE, matInvProjection.getPointer());
|
||||||
|
|
||||||
|
|
||||||
// Disable z-buffer write
|
// Disable z-buffer write
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
|
|
||||||
// Render sphere of light's influence
|
if(bInsideLight) {
|
||||||
generateMesh();
|
|
||||||
|
// Disable z-buffer test
|
||||||
// Enable z-buffer test
|
glDisable(GL_DEPTH_TEST);
|
||||||
glEnable(GL_DEPTH_TEST);
|
|
||||||
glDepthFunc(GL_LEQUAL);
|
// Render a full screen quad
|
||||||
glDepthRangef(0.0, 1.0);
|
static const GLfloat squareVertices[] = {
|
||||||
|
-1.0f, -1.0f,
|
||||||
|
1.0f, -1.0f,
|
||||||
|
-1.0f, 1.0f,
|
||||||
|
1.0f, 1.0f,
|
||||||
|
};
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices);
|
||||||
|
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
} else {
|
||||||
|
// Render sphere of light's influence
|
||||||
|
generateMesh();
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
// Enable z-buffer test
|
||||||
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, m_sphereVertices);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
|
glDepthFunc(GL_LEQUAL);
|
||||||
glDrawArrays(GL_TRIANGLES, 0, m_cVertices);
|
glDepthRangef(0.0, 1.0);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glVertexAttribPointer(KRShader::KRENGINE_ATTRIB_VERTEX, 3, GL_FLOAT, 0, 0, m_sphereVertices);
|
||||||
|
glEnableVertexAttribArray(KRShader::KRENGINE_ATTRIB_VERTEX);
|
||||||
|
glDrawArrays(GL_TRIANGLES, 0, m_cVertices);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,6 +158,7 @@ void KRScene::render(KROctreeNode *pOctreeNode, std::set<KRAABB> &visibleBounds,
|
|||||||
pOctreeNode->beginOcclusionQuery(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
pOctreeNode->beginOcclusionQuery(renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Occlusion test indicates that this bounding box was visible in the last frame
|
// Occlusion test indicates that this bounding box was visible in the last frame
|
||||||
for(std::set<KRNode *>::iterator itr=pOctreeNode->getSceneNodes().begin(); itr != pOctreeNode->getSceneNodes().end(); itr++) {
|
for(std::set<KRNode *>::iterator itr=pOctreeNode->getSceneNodes().begin(); itr != pOctreeNode->getSceneNodes().end(); itr++) {
|
||||||
//assert(pOctreeNode->getBounds().contains((*itr)->getBounds())); // Sanity check
|
//assert(pOctreeNode->getBounds().contains((*itr)->getBounds())); // Sanity check
|
||||||
|
|||||||
@@ -165,16 +165,16 @@ bool KRTexture::createGLTexture() {
|
|||||||
int width = m_iWidth;
|
int width = m_iWidth;
|
||||||
int height = m_iHeight;
|
int height = m_iHeight;
|
||||||
GLenum err;
|
GLenum err;
|
||||||
|
|
||||||
|
if(m_blocks.size() == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_blocks.size() > 0)
|
glGenTextures(1, &m_iName);
|
||||||
{
|
if(m_iName == 0) {
|
||||||
if (m_iName != 0) {
|
return false;
|
||||||
glDeleteTextures(1, &m_iName);
|
}
|
||||||
}
|
glBindTexture(GL_TEXTURE_2D, m_iName);
|
||||||
|
|
||||||
glGenTextures(1, &m_iName);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, m_iName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_blocks.size() > 1) {
|
if (m_blocks.size() > 1) {
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||||
@@ -188,6 +188,8 @@ bool KRTexture::createGLTexture() {
|
|||||||
|
|
||||||
err = glGetError();
|
err = glGetError();
|
||||||
if (err != GL_NO_ERROR) {
|
if (err != GL_NO_ERROR) {
|
||||||
|
glDeleteTextures(1, &m_iName);
|
||||||
|
m_iName = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,7 +218,7 @@ GLuint KRTexture::getHandle(long &textureMemUsed) {
|
|||||||
textureMemUsed += getMemSize();
|
textureMemUsed += getMemSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
createGLTexture();
|
//createGLTexture();
|
||||||
}
|
}
|
||||||
return m_iName;
|
return m_iName;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include "KRTextureManager.h"
|
#include "KRTextureManager.h"
|
||||||
|
#include "KRContext.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
KRTextureManager::KRTextureManager(KRContext &context) : KRContextObject(context) {
|
KRTextureManager::KRTextureManager(KRContext &context) : KRContextObject(context) {
|
||||||
|
|||||||
73
KREngine/KREngine/Shaders/light_point_inside.fsh
Normal file
73
KREngine/KREngine/Shaders/light_point_inside.fsh
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
// 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.
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
uniform sampler2D gbuffer_frame;
|
||||||
|
uniform sampler2D gbuffer_depth;
|
||||||
|
|
||||||
|
uniform lowp vec3 light_color;
|
||||||
|
uniform highp float light_intensity;
|
||||||
|
uniform highp float light_decay_start;
|
||||||
|
uniform highp float light_cutoff;
|
||||||
|
uniform mediump vec4 viewport;
|
||||||
|
|
||||||
|
uniform highp mat4 inv_projection_matrix;
|
||||||
|
|
||||||
|
uniform highp vec3 view_space_light_position;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
|
||||||
|
lowp vec2 gbuffer_uv = vec2(gl_FragCoord.xy / viewport.zw);
|
||||||
|
lowp vec4 gbuffer_sample = texture2D(gbuffer_frame, gbuffer_uv);
|
||||||
|
|
||||||
|
mediump vec3 gbuffer_normal = normalize(2.0 * gbuffer_sample.rgb - 1.0);
|
||||||
|
mediump float gbuffer_specular_exponent = gbuffer_sample.a * 100.0;
|
||||||
|
|
||||||
|
mediump vec4 clip_space_vertex_position = vec4(
|
||||||
|
gl_FragCoord.xy / viewport.zw * 2.0 - 1.0,
|
||||||
|
texture2D(gbuffer_depth, gbuffer_uv).r * 2.0 - 1.0,
|
||||||
|
1.0
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
mediump vec4 view_space_vertex_position = inv_projection_matrix * clip_space_vertex_position;
|
||||||
|
view_space_vertex_position.xyz /= view_space_vertex_position.w;
|
||||||
|
|
||||||
|
mediump float light_distance = max(0.0, distance(view_space_light_position.xyz, view_space_vertex_position.xyz) - light_decay_start);
|
||||||
|
mediump float light_attenuation = (light_intensity / ((light_distance + 1.0) * (light_distance + 1.0)) - light_cutoff) / (1.0 - light_cutoff);
|
||||||
|
mediump vec3 light_vec = normalize(view_space_light_position.xyz - view_space_vertex_position.xyz);
|
||||||
|
mediump float lamberFactor = dot(light_vec, gbuffer_normal) * 0.2;
|
||||||
|
|
||||||
|
mediump float specularFactor = 0.0;
|
||||||
|
//if(gbuffer_specular_exponent > 0.0) {
|
||||||
|
mediump vec3 halfVec = normalize((normalize(- view_space_vertex_position.xyz) + light_vec));
|
||||||
|
specularFactor = pow(dot(halfVec,gbuffer_normal), gbuffer_specular_exponent);
|
||||||
|
//}
|
||||||
|
|
||||||
|
gl_FragColor = vec4(light_color * lamberFactor, specularFactor) * light_attenuation;
|
||||||
|
}
|
||||||
33
KREngine/KREngine/Shaders/light_point_inside.vsh
Normal file
33
KREngine/KREngine/Shaders/light_point_inside.vsh
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
// Copyright 2012 Kearwood Gilbert. All rights reserved.
|
||||||
|
//
|
||||||
|
// Redistribution and use in source and binary forms, with or without modification, are
|
||||||
|
// permitted provided that the following conditions are met:
|
||||||
|
//
|
||||||
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||||
|
// conditions and the following disclaimer.
|
||||||
|
//
|
||||||
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||||
|
// of conditions and the following disclaimer in the documentation and/or other materials
|
||||||
|
// provided with the distribution.
|
||||||
|
//
|
||||||
|
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
|
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||||
|
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
|
||||||
|
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||||
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||||
|
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||||
|
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
//
|
||||||
|
// The views and conclusions contained in the software and documentation are those of the
|
||||||
|
// authors and should not be interpreted as representing official policies, either expressed
|
||||||
|
// or implied, of Kearwood Gilbert.
|
||||||
|
//
|
||||||
|
|
||||||
|
attribute vec4 vertex_position;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
gl_Position = vertex_position;
|
||||||
|
}
|
||||||
@@ -42,6 +42,10 @@
|
|||||||
E4A9DEC715412923009DF363 /* light_point.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4A9DEC2154128F0009DF363 /* light_point.fsh */; };
|
E4A9DEC715412923009DF363 /* light_point.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4A9DEC2154128F0009DF363 /* light_point.fsh */; };
|
||||||
E4A9DEC815412923009DF363 /* light_point.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4A9DEC515412906009DF363 /* light_point.vsh */; };
|
E4A9DEC815412923009DF363 /* light_point.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4A9DEC515412906009DF363 /* light_point.vsh */; };
|
||||||
E4CE184A15FEEE8500F80870 /* font.pvr in Resources */ = {isa = PBXBuildFile; fileRef = E4CE184915FEEE8500F80870 /* font.pvr */; };
|
E4CE184A15FEEE8500F80870 /* font.pvr in Resources */ = {isa = PBXBuildFile; fileRef = E4CE184915FEEE8500F80870 /* font.pvr */; };
|
||||||
|
E4CE185215FF12A700F80870 /* light_point_inside.fsh in Sources */ = {isa = PBXBuildFile; fileRef = E4CE185015FF12A700F80870 /* light_point_inside.fsh */; };
|
||||||
|
E4CE185315FF12A700F80870 /* light_point_inside.vsh in Sources */ = {isa = PBXBuildFile; fileRef = E4CE185115FF12A700F80870 /* light_point_inside.vsh */; };
|
||||||
|
E4CE185415FF12B700F80870 /* light_point_inside.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4CE185015FF12A700F80870 /* light_point_inside.fsh */; };
|
||||||
|
E4CE185515FF12B700F80870 /* light_point_inside.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4CE185115FF12A700F80870 /* light_point_inside.vsh */; };
|
||||||
E4FF48C51538FBF8002053FC /* light_directional.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4FF48C01538FBF0002053FC /* light_directional.fsh */; };
|
E4FF48C51538FBF8002053FC /* light_directional.fsh in Resources */ = {isa = PBXBuildFile; fileRef = E4FF48C01538FBF0002053FC /* light_directional.fsh */; };
|
||||||
E4FF48C61538FBFC002053FC /* light_directional.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4FF48C11538FBF0002053FC /* light_directional.vsh */; };
|
E4FF48C61538FBFC002053FC /* light_directional.vsh in Resources */ = {isa = PBXBuildFile; fileRef = E4FF48C11538FBF0002053FC /* light_directional.vsh */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
@@ -86,6 +90,8 @@
|
|||||||
E4A9DEC2154128F0009DF363 /* light_point.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_point.fsh; path = ../KREngine/KREngine/Shaders/light_point.fsh; sourceTree = "<group>"; };
|
E4A9DEC2154128F0009DF363 /* light_point.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_point.fsh; path = ../KREngine/KREngine/Shaders/light_point.fsh; sourceTree = "<group>"; };
|
||||||
E4A9DEC515412906009DF363 /* light_point.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_point.vsh; path = ../KREngine/KREngine/Shaders/light_point.vsh; sourceTree = "<group>"; };
|
E4A9DEC515412906009DF363 /* light_point.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_point.vsh; path = ../KREngine/KREngine/Shaders/light_point.vsh; sourceTree = "<group>"; };
|
||||||
E4CE184915FEEE8500F80870 /* font.pvr */ = {isa = PBXFileReference; lastKnownFileType = file; name = font.pvr; path = ../KREngine/KREngine/Shaders/font.pvr; sourceTree = "<group>"; };
|
E4CE184915FEEE8500F80870 /* font.pvr */ = {isa = PBXFileReference; lastKnownFileType = file; name = font.pvr; path = ../KREngine/KREngine/Shaders/font.pvr; sourceTree = "<group>"; };
|
||||||
|
E4CE185015FF12A700F80870 /* light_point_inside.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_point_inside.fsh; path = ../KREngine/KREngine/Shaders/light_point_inside.fsh; sourceTree = "<group>"; };
|
||||||
|
E4CE185115FF12A700F80870 /* light_point_inside.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_point_inside.vsh; path = ../KREngine/KREngine/Shaders/light_point_inside.vsh; sourceTree = "<group>"; };
|
||||||
E4FF48C01538FBF0002053FC /* light_directional.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_directional.fsh; path = ../KREngine/KREngine/Shaders/light_directional.fsh; sourceTree = "<group>"; };
|
E4FF48C01538FBF0002053FC /* light_directional.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_directional.fsh; path = ../KREngine/KREngine/Shaders/light_directional.fsh; sourceTree = "<group>"; };
|
||||||
E4FF48C11538FBF0002053FC /* light_directional.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_directional.vsh; path = ../KREngine/KREngine/Shaders/light_directional.vsh; sourceTree = "<group>"; };
|
E4FF48C11538FBF0002053FC /* light_directional.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_directional.vsh; path = ../KREngine/KREngine/Shaders/light_directional.vsh; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
@@ -202,6 +208,8 @@
|
|||||||
E46FED2013C9A472009F5814 /* Shaders */ = {
|
E46FED2013C9A472009F5814 /* Shaders */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
E4CE185015FF12A700F80870 /* light_point_inside.fsh */,
|
||||||
|
E4CE185115FF12A700F80870 /* light_point_inside.vsh */,
|
||||||
E48839A315F92C6900BD66D5 /* visualize_overlay.fsh */,
|
E48839A315F92C6900BD66D5 /* visualize_overlay.fsh */,
|
||||||
E430D08A15F88B950010558D /* occlusion_test.vsh */,
|
E430D08A15F88B950010558D /* occlusion_test.vsh */,
|
||||||
E430D08515F88A9F0010558D /* occlusion_test.fsh */,
|
E430D08515F88A9F0010558D /* occlusion_test.fsh */,
|
||||||
@@ -291,6 +299,8 @@
|
|||||||
isa = PBXResourcesBuildPhase;
|
isa = PBXResourcesBuildPhase;
|
||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
|
E4CE185415FF12B700F80870 /* light_point_inside.fsh in Resources */,
|
||||||
|
E4CE185515FF12B700F80870 /* light_point_inside.vsh in Resources */,
|
||||||
E48839A515F92C8D00BD66D5 /* visualize_overlay.fsh in Resources */,
|
E48839A515F92C8D00BD66D5 /* visualize_overlay.fsh in Resources */,
|
||||||
E4769DF3158A7915004B83AC /* flare.fsh in Resources */,
|
E4769DF3158A7915004B83AC /* flare.fsh in Resources */,
|
||||||
E4769DF4158A7915004B83AC /* flare.vsh in Resources */,
|
E4769DF4158A7915004B83AC /* flare.vsh in Resources */,
|
||||||
@@ -329,6 +339,8 @@
|
|||||||
E430D08615F88A9F0010558D /* occlusion_test.fsh in Sources */,
|
E430D08615F88A9F0010558D /* occlusion_test.fsh in Sources */,
|
||||||
E430D08B15F88B950010558D /* occlusion_test.vsh in Sources */,
|
E430D08B15F88B950010558D /* occlusion_test.vsh in Sources */,
|
||||||
E48839A415F92C6900BD66D5 /* visualize_overlay.fsh in Sources */,
|
E48839A415F92C6900BD66D5 /* visualize_overlay.fsh in Sources */,
|
||||||
|
E4CE185215FF12A700F80870 /* light_point_inside.fsh in Sources */,
|
||||||
|
E4CE185315FF12A700F80870 /* light_point_inside.vsh in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user