Implemented multi-pass framework for deferred lighting
--HG-- extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%4044
This commit is contained in:
@@ -23,3 +23,58 @@ KRDirectionalLight::~KRDirectionalLight()
|
|||||||
std::string KRDirectionalLight::getElementName() {
|
std::string KRDirectionalLight::getElementName() {
|
||||||
return "directional_light";
|
return "directional_light";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if TARGET_OS_IPHONE
|
||||||
|
|
||||||
|
void KRDirectionalLight::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, bool bRenderShadowMap, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, int gBufferPass) {
|
||||||
|
|
||||||
|
if(gBufferPass == 2) {
|
||||||
|
// Lights are rendered on the second pass of the deferred renderer
|
||||||
|
/*
|
||||||
|
|
||||||
|
if(m_pModel == NULL) {
|
||||||
|
m_pModel = pContext->getModelManager()->getModel(m_model_name.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(m_pModel != NULL && (getExtents(pContext).test_intersect(frustrumVolume) || bRenderShadowMap)) {
|
||||||
|
|
||||||
|
if(m_pLightMap == NULL && m_lightMap.size()) {
|
||||||
|
m_pLightMap = pContext->getTextureManager()->getTexture(m_lightMap.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cShadowBuffers == 0 && m_pLightMap && pCamera->bEnableLightMap && !bRenderShadowMap) {
|
||||||
|
int iTextureName = m_pLightMap->getName();
|
||||||
|
glActiveTexture(GL_TEXTURE3);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, iTextureName);
|
||||||
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
KRMat4 projectionMatrix;
|
||||||
|
if(!bRenderShadowMap) {
|
||||||
|
projectionMatrix = pCamera->getProjectionMatrix();
|
||||||
|
}
|
||||||
|
KRMat4 mvpmatrix = m_modelMatrix * viewMatrix * projectionMatrix;
|
||||||
|
KRMat4 matModelToView = viewMatrix * m_modelMatrix;
|
||||||
|
matModelToView.transpose();
|
||||||
|
matModelToView.invert();
|
||||||
|
|
||||||
|
// Transform location of camera to object space for calculation of specular halfVec
|
||||||
|
KRMat4 inverseModelMatrix = m_modelMatrix;
|
||||||
|
inverseModelMatrix.invert();
|
||||||
|
KRVector3 cameraPosObject = inverseModelMatrix.dot(cameraPosition);
|
||||||
|
KRVector3 lightDirObject = inverseModelMatrix.dot(lightDirection);
|
||||||
|
|
||||||
|
m_pModel->render(pCamera, pContext, bRenderShadowMap, matModelToView, mvpmatrix, cameraPosObject, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, m_pLightMap, gBufferPass);
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
KRNode::render(pCamera, pContext, frustrumVolume, bRenderShadowMap, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, gBufferPass);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -18,6 +18,11 @@ public:
|
|||||||
virtual ~KRDirectionalLight();
|
virtual ~KRDirectionalLight();
|
||||||
|
|
||||||
virtual std::string getElementName();
|
virtual std::string getElementName();
|
||||||
|
|
||||||
|
#if TARGET_OS_IPHONE
|
||||||
|
|
||||||
|
virtual void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, bool bRenderShadowMap, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, int gBufferPass);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ typedef enum KREngineParameterType {KRENGINE_PARAMETER_INT, KRENGINE_PARAMETER_F
|
|||||||
GLint backingWidth, backingHeight;
|
GLint backingWidth, backingHeight;
|
||||||
|
|
||||||
GLuint compositeFramebuffer, compositeDepthTexture, compositeColorTexture;
|
GLuint compositeFramebuffer, compositeDepthTexture, compositeColorTexture;
|
||||||
|
GLuint lightAccumulationBuffer;
|
||||||
|
|
||||||
int m_cShadowBuffers;
|
int m_cShadowBuffers;
|
||||||
GLuint shadowFramebuffer[KRENGINE_MAX_SHADOW_BUFFERS], shadowDepthTexture[KRENGINE_MAX_SHADOW_BUFFERS];
|
GLuint shadowFramebuffer[KRENGINE_MAX_SHADOW_BUFFERS], shadowDepthTexture[KRENGINE_MAX_SHADOW_BUFFERS];
|
||||||
|
|||||||
@@ -157,6 +157,21 @@ double const PI = 3.141592653589793f;
|
|||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, backingWidth, backingHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, backingWidth, backingHeight, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL);
|
||||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0);
|
||||||
|
|
||||||
|
|
||||||
|
// ===== Create offscreen compositing framebuffer object =====
|
||||||
|
glGenFramebuffers(1, &lightAccumulationBuffer);
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, lightAccumulationBuffer);
|
||||||
|
|
||||||
|
// ----- Create texture color buffer for compositeFramebuffer -----
|
||||||
|
glGenTextures(1, &lightAccumulationBuffer);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, lightAccumulationBuffer);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // This is necessary for non-power-of-two textures
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // This is necessary for non-power-of-two textures
|
||||||
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, backingWidth, backingHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, compositeColorTexture, 0);
|
||||||
|
|
||||||
[self allocateShadowBuffers];
|
[self allocateShadowBuffers];
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@@ -180,6 +195,11 @@ double const PI = 3.141592653589793f;
|
|||||||
glDeleteFramebuffers(1, &compositeFramebuffer);
|
glDeleteFramebuffers(1, &compositeFramebuffer);
|
||||||
compositeFramebuffer = 0;
|
compositeFramebuffer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lightAccumulationBuffer) {
|
||||||
|
glDeleteFramebuffers(1, &lightAccumulationBuffer);
|
||||||
|
lightAccumulationBuffer = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)renderScene: (KRScene *)pScene WithPosition: (KRVector3)position Yaw: (GLfloat)yaw Pitch: (GLfloat)pitch Roll: (GLfloat)roll
|
- (void)renderScene: (KRScene *)pScene WithPosition: (KRVector3)position Yaw: (GLfloat)yaw Pitch: (GLfloat)pitch Roll: (GLfloat)roll
|
||||||
@@ -328,32 +348,119 @@ double const PI = 3.141592653589793f;
|
|||||||
KRVector3 cameraPosition;
|
KRVector3 cameraPosition;
|
||||||
KRVector3 lightDirection;
|
KRVector3 lightDirection;
|
||||||
KRBoundingVolume shadowVolume = KRBoundingVolume(vertices);
|
KRBoundingVolume shadowVolume = KRBoundingVolume(vertices);
|
||||||
pScene->render(&m_camera, m_pContext, shadowVolume, true, shadowmvpmatrix[iShadow], cameraPosition, lightDirection, shadowmvpmatrix, NULL, m_cShadowBuffers);
|
pScene->render(&m_camera, m_pContext, shadowVolume, true, shadowmvpmatrix[iShadow], cameraPosition, lightDirection, shadowmvpmatrix, NULL, m_cShadowBuffers, 0);
|
||||||
glViewport(0, 0, 768, 1024);
|
glViewport(0, 0, 768, 1024);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)renderScene: (KRScene *)pScene WithViewMatrix: (KRMat4)viewMatrix LightDirection: (KRVector3)lightDirection CameraPosition: (KRVector3)cameraPosition
|
- (void)renderScene: (KRScene *)pScene WithViewMatrix: (KRMat4)viewMatrix LightDirection: (KRVector3)lightDirection CameraPosition: (KRVector3)cameraPosition
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
KRBoundingVolume frustrumVolume = KRBoundingVolume(viewMatrix, m_camera.perspective_fov, m_camera.perspective_aspect, m_camera.perspective_nearz, m_camera.perspective_farz);
|
||||||
|
if(m_camera.bEnableDeferredLighting) {
|
||||||
|
// ----====---- Opaque Geometry, Deferred rendering Pass 1 ----====----
|
||||||
|
|
||||||
|
// Set render target
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer);
|
||||||
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
// Enable backface culling
|
||||||
|
glCullFace(GL_BACK);
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
|
// Enable z-buffer test
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glDepthFunc(GL_LEQUAL);
|
||||||
|
glDepthRangef(0.0, 1.0);
|
||||||
|
|
||||||
|
// Disable alpha blending
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
|
// Render the geometry
|
||||||
|
pScene->render(&m_camera, m_pContext, frustrumVolume, false, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, 1);
|
||||||
|
|
||||||
|
// ----====---- Opaque Geometry, Deferred rendering Pass 2 ----====----
|
||||||
|
// Set render target
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, lightAccumulationBuffer);
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0);
|
||||||
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
// Enable additive blending
|
||||||
|
glEnable(GL_BLEND);
|
||||||
|
glBlendFunc(GL_ONE, GL_ONE);
|
||||||
|
|
||||||
|
// Render the geometry
|
||||||
|
pScene->render(&m_camera, m_pContext, frustrumVolume, false, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, 2);
|
||||||
|
|
||||||
|
// ----====---- Opaque Geometry, Deferred rendering Pass 3 ----====----
|
||||||
|
// Set render target
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer);
|
||||||
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0);
|
||||||
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
// Enable backface culling
|
||||||
|
glCullFace(GL_BACK);
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
|
// Enable z-buffer test
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glDepthFunc(GL_LEQUAL);
|
||||||
|
glDepthRangef(0.0, 1.0);
|
||||||
|
|
||||||
|
// Render the geometry
|
||||||
|
pScene->render(&m_camera, m_pContext, frustrumVolume, false, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, 3);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// ----====---- Opaque Geometry, Forward Rendering ----====----
|
||||||
|
|
||||||
|
// Set render target
|
||||||
|
glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer);
|
||||||
|
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
|
||||||
|
// Enable backface culling
|
||||||
|
glCullFace(GL_BACK);
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
|
// Enable z-buffer test
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glDepthFunc(GL_LEQUAL);
|
||||||
|
glDepthRangef(0.0, 1.0);
|
||||||
|
|
||||||
|
// Disable alpha blending
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
|
// Render the geometry
|
||||||
|
pScene->render(&m_camera, m_pContext, frustrumVolume, false, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----====---- Transparent Geometry, Forward Rendering ----====----
|
||||||
|
|
||||||
|
// Set render target
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer);
|
glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer);
|
||||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
||||||
|
|
||||||
// Enable backface culling
|
// Enable backface culling
|
||||||
glCullFace(GL_BACK);
|
glCullFace(GL_BACK);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
|
|
||||||
// Enable z-buffer test
|
// Enable z-buffer test
|
||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
glDepthFunc(GL_LEQUAL);
|
glDepthFunc(GL_LEQUAL);
|
||||||
glDepthRangef(0.0, 1.0);
|
glDepthRangef(0.0, 1.0);
|
||||||
|
|
||||||
// Enable alpha blending
|
// Enable alpha blending
|
||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
KRBoundingVolume frustrumVolume = KRBoundingVolume(viewMatrix, m_camera.perspective_fov, m_camera.perspective_aspect, m_camera.perspective_nearz, m_camera.perspective_farz);
|
// TODO: Need to perform a forward render of all transparent geometry here...
|
||||||
pScene -> render(&m_camera, m_pContext, frustrumVolume, false, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers);
|
//pScene->render(&m_camera, m_pContext, frustrumVolume, false, viewMatrix, cameraPosition, lightDirection, shadowmvpmatrix, shadowDepthTexture, m_cShadowBuffers, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)compileShader:(GLuint *)shader type:(GLenum)type file:(NSString *)file withOptions: (NSString *)options
|
- (BOOL)compileShader:(GLuint *)shader type:(GLenum)type file:(NSString *)file withOptions: (NSString *)options
|
||||||
@@ -594,6 +701,9 @@ double const PI = 3.141592653589793f;
|
|||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 1); // renderFramebuffer
|
glBindFramebuffer(GL_FRAMEBUFFER, 1); // renderFramebuffer
|
||||||
|
|
||||||
|
// Disable alpha blending
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
|
||||||
// Replace the implementation of this method to do your own custom drawing.
|
// Replace the implementation of this method to do your own custom drawing.
|
||||||
static const GLfloat squareVertices[] = {
|
static const GLfloat squareVertices[] = {
|
||||||
-1.0f, -1.0f,
|
-1.0f, -1.0f,
|
||||||
|
|||||||
@@ -65,47 +65,54 @@ KRMat4 &KRInstance::getModelMatrix() {
|
|||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
|
|
||||||
void KRInstance::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, bool bRenderShadowMap, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers) {
|
void KRInstance::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, bool bRenderShadowMap, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, int gBufferPass) {
|
||||||
|
|
||||||
if(m_pModel == NULL) {
|
if(gBufferPass != 2) {
|
||||||
m_pModel = pContext->getModelManager()->getModel(m_model_name.c_str());
|
// Don't render meshes on second pass of the deferred lighting renderer, as only lights will be applied
|
||||||
}
|
|
||||||
|
|
||||||
if(m_pModel != NULL && (getExtents(pContext).test_intersect(frustrumVolume) || bRenderShadowMap)) {
|
|
||||||
|
if(m_pModel == NULL) {
|
||||||
|
m_pModel = pContext->getModelManager()->getModel(m_model_name.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(m_pModel != NULL && (getExtents(pContext).test_intersect(frustrumVolume) || bRenderShadowMap)) {
|
||||||
|
|
||||||
if(m_pLightMap == NULL && m_lightMap.size()) {
|
if(m_pLightMap == NULL && m_lightMap.size()) {
|
||||||
m_pLightMap = pContext->getTextureManager()->getTexture(m_lightMap.c_str());
|
m_pLightMap = pContext->getTextureManager()->getTexture(m_lightMap.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cShadowBuffers == 0 && m_pLightMap && pCamera->bEnableLightMap && !bRenderShadowMap) {
|
|
||||||
int iTextureName = m_pLightMap->getName();
|
|
||||||
glActiveTexture(GL_TEXTURE3);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, iTextureName);
|
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
||||||
}
|
|
||||||
|
|
||||||
KRMat4 projectionMatrix;
|
|
||||||
if(!bRenderShadowMap) {
|
|
||||||
projectionMatrix = pCamera->getProjectionMatrix();
|
|
||||||
}
|
|
||||||
KRMat4 mvpmatrix = m_modelMatrix * viewMatrix * projectionMatrix;
|
|
||||||
KRMat4 matModelToView = viewMatrix * m_modelMatrix;
|
|
||||||
matModelToView.transpose();
|
|
||||||
matModelToView.invert();
|
|
||||||
|
|
||||||
// Transform location of camera to object space for calculation of specular halfVec
|
|
||||||
KRMat4 inverseModelMatrix = m_modelMatrix;
|
|
||||||
inverseModelMatrix.invert();
|
|
||||||
KRVector3 cameraPosObject = inverseModelMatrix.dot(cameraPosition);
|
|
||||||
KRVector3 lightDirObject = inverseModelMatrix.dot(lightDirection);
|
|
||||||
|
|
||||||
m_pModel->render(pCamera, pContext, bRenderShadowMap, matModelToView, mvpmatrix, cameraPosObject, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, m_pLightMap);
|
|
||||||
|
|
||||||
|
if(cShadowBuffers == 0 && m_pLightMap && pCamera->bEnableLightMap && !bRenderShadowMap) {
|
||||||
|
int iTextureName = m_pLightMap->getName();
|
||||||
|
glActiveTexture(GL_TEXTURE3);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, iTextureName);
|
||||||
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 1.0f);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
}
|
||||||
|
|
||||||
|
KRMat4 projectionMatrix;
|
||||||
|
if(!bRenderShadowMap) {
|
||||||
|
projectionMatrix = pCamera->getProjectionMatrix();
|
||||||
|
}
|
||||||
|
KRMat4 mvpmatrix = m_modelMatrix * viewMatrix * projectionMatrix;
|
||||||
|
KRMat4 matModelToView = viewMatrix * m_modelMatrix;
|
||||||
|
matModelToView.transpose();
|
||||||
|
matModelToView.invert();
|
||||||
|
|
||||||
|
// Transform location of camera to object space for calculation of specular halfVec
|
||||||
|
KRMat4 inverseModelMatrix = m_modelMatrix;
|
||||||
|
inverseModelMatrix.invert();
|
||||||
|
KRVector3 cameraPosObject = inverseModelMatrix.dot(cameraPosition);
|
||||||
|
KRVector3 lightDirObject = inverseModelMatrix.dot(lightDirection);
|
||||||
|
|
||||||
|
m_pModel->render(pCamera, pContext, bRenderShadowMap, matModelToView, mvpmatrix, cameraPosObject, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, m_pLightMap, gBufferPass);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KRNode::render(pCamera, pContext, frustrumVolume, bRenderShadowMap, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers);
|
KRNode::render(pCamera, pContext, frustrumVolume, bRenderShadowMap, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, gBufferPass);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public:
|
|||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
|
|
||||||
virtual void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, bool bRenderShadowMap, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers);
|
virtual void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, bool bRenderShadowMap, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, int gBufferPass);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
virtual void calcExtents(KRContext *pContext);
|
virtual void calcExtents(KRContext *pContext);
|
||||||
|
|||||||
@@ -158,7 +158,7 @@ bool KRMaterial::isTransparent() {
|
|||||||
return m_tr != 0.0;
|
return m_tr != 0.0;
|
||||||
}
|
}
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
void KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRContext *pContext, KRTexture *pLightMap) {
|
void KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRContext *pContext, KRTexture *pLightMap, int gBufferPass) {
|
||||||
bool bSameMaterial = *prevBoundMaterial == this;
|
bool bSameMaterial = *prevBoundMaterial == this;
|
||||||
bool bLightMap = pLightMap && pCamera->bEnableLightMap;
|
bool bLightMap = pLightMap && pCamera->bEnableLightMap;
|
||||||
|
|
||||||
@@ -187,11 +187,11 @@ void KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
|
|||||||
bool bNormalMap = m_pNormalMap != NULL && pCamera->bEnableNormalMap;
|
bool bNormalMap = m_pNormalMap != NULL && pCamera->bEnableNormalMap;
|
||||||
bool bSpecMap = m_pSpecularMap != NULL && pCamera->bEnableSpecMap;
|
bool bSpecMap = m_pSpecularMap != NULL && pCamera->bEnableSpecMap;
|
||||||
|
|
||||||
KRShader *pShader = pContext->getShaderManager()->getShader(pCamera, bDiffuseMap, bNormalMap, bSpecMap, cShadowBuffers, bLightMap, m_diffuseMapScale != default_scale && bDiffuseMap, m_specularMapScale != default_scale && bSpecMap, m_normalMapScale != default_scale && bNormalMap, m_diffuseMapOffset != default_offset && bDiffuseMap, m_specularMapOffset != default_offset && bSpecMap, m_normalMapOffset != default_offset && bNormalMap);
|
KRShader *pShader = pContext->getShaderManager()->getShader("ObjectShader", pCamera, bDiffuseMap, bNormalMap, bSpecMap, cShadowBuffers, bLightMap, m_diffuseMapScale != default_scale && bDiffuseMap, m_specularMapScale != default_scale && bSpecMap, m_normalMapScale != default_scale && bNormalMap, m_diffuseMapOffset != default_offset && bDiffuseMap, m_specularMapOffset != default_offset && bSpecMap, m_normalMapOffset != default_offset && bNormalMap, gBufferPass);
|
||||||
|
|
||||||
bool bSameShader = strcmp(pShader->getKey(), szPrevShaderKey) == 0;
|
bool bSameShader = strcmp(pShader->getKey(), szPrevShaderKey) == 0;
|
||||||
if(!bSameShader) {
|
if(!bSameShader) {
|
||||||
pShader->bind(pCamera, matModelToView, mvpMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers);
|
pShader->bind(pCamera, matModelToView, mvpMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, gBufferPass);
|
||||||
glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SHININESS], pCamera->bDebugSuperShiny ? 20.0 : m_ns );
|
glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_SHININESS], pCamera->bDebugSuperShiny ? 20.0 : m_ns );
|
||||||
strcpy(szPrevShaderKey, pShader->getKey());
|
strcpy(szPrevShaderKey, pShader->getKey());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ public:
|
|||||||
char *getName();
|
char *getName();
|
||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
void bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRContext *pContext, KRTexture *pLightMap);
|
void bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRContext *pContext, KRTexture *pLightMap, int gBufferPass);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ KRModel::~KRModel() {
|
|||||||
}
|
}
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
|
|
||||||
void KRModel::render(KRCamera *pCamera, KRContext *pContext, bool bRenderShadowMap, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRTexture *pLightMap) {
|
void KRModel::render(KRCamera *pCamera, KRContext *pContext, bool bRenderShadowMap, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRTexture *pLightMap, int gBufferPass) {
|
||||||
|
|
||||||
if(m_materials.size() == 0) {
|
if(m_materials.size() == 0) {
|
||||||
vector<KRMesh::Submesh *> submeshes = m_pMesh->getSubmeshes();
|
vector<KRMesh::Submesh *> submeshes = m_pMesh->getSubmeshes();
|
||||||
@@ -104,7 +104,7 @@ void KRModel::render(KRCamera *pCamera, KRContext *pContext, bool bRenderShadowM
|
|||||||
KRMaterial *pMaterial = m_materials[iSubmesh];
|
KRMaterial *pMaterial = m_materials[iSubmesh];
|
||||||
|
|
||||||
if(pMaterial != NULL && pMaterial == (*mat_itr)) {
|
if(pMaterial != NULL && pMaterial == (*mat_itr)) {
|
||||||
pMaterial->bind(&pPrevBoundMaterial, szPrevShaderKey, pCamera, matModelToView, mvpMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, pContext, pLightMap);
|
pMaterial->bind(&pPrevBoundMaterial, szPrevShaderKey, pCamera, matModelToView, mvpMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, pContext, pLightMap, gBufferPass);
|
||||||
m_pMesh->renderSubmesh(iSubmesh, &iPrevBuffer);
|
m_pMesh->renderSubmesh(iSubmesh, &iPrevBuffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public:
|
|||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
|
|
||||||
void render(KRCamera *pCamera, KRContext *pContext, bool bRenderShadowMap, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRTexture *pLightMap);
|
void render(KRCamera *pCamera, KRContext *pContext, bool bRenderShadowMap, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRTexture *pLightMap, int gBufferPass);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -142,11 +142,11 @@ KRNode *KRNode::LoadXML(tinyxml2::XMLElement *e) {
|
|||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
|
|
||||||
void KRNode::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, bool bRenderShadowMap, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers) {
|
void KRNode::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, bool bRenderShadowMap, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, int gBufferPass) {
|
||||||
|
|
||||||
for(std::vector<KRNode *>::iterator itr=m_childNodes.begin(); itr < m_childNodes.end(); ++itr) {
|
for(std::vector<KRNode *>::iterator itr=m_childNodes.begin(); itr < m_childNodes.end(); ++itr) {
|
||||||
KRNode *child = (*itr);
|
KRNode *child = (*itr);
|
||||||
child->render(pCamera, pContext, frustrumVolume, bRenderShadowMap, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers);
|
child->render(pCamera, pContext, frustrumVolume, bRenderShadowMap, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, gBufferPass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public:
|
|||||||
KRBoundingVolume getExtents(KRContext *pContext);
|
KRBoundingVolume getExtents(KRContext *pContext);
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
|
|
||||||
virtual void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, bool bRenderShadowMap, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers);
|
virtual void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, bool bRenderShadowMap, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, int gBufferPass);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ KRScene::~KRScene() {
|
|||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
|
|
||||||
void KRScene::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, bool bRenderShadowMap, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers) {
|
void KRScene::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, bool bRenderShadowMap, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, int gBufferPass) {
|
||||||
|
|
||||||
if(cShadowBuffers > 0 && !bRenderShadowMap) {
|
if(cShadowBuffers > 0 && !bRenderShadowMap) {
|
||||||
glActiveTexture(GL_TEXTURE3);
|
glActiveTexture(GL_TEXTURE3);
|
||||||
@@ -77,7 +77,7 @@ void KRScene::render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &f
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pRootNode->render(pCamera, pContext, frustrumVolume, bRenderShadowMap, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers);
|
m_pRootNode->render(pCamera, pContext, frustrumVolume, bRenderShadowMap, viewMatrix, cameraPosition, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, gBufferPass);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public:
|
|||||||
|
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
|
|
||||||
void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, bool bRenderShadowMap, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers);
|
void render(KRCamera *pCamera, KRContext *pContext, KRBoundingVolume &frustrumVolume, bool bRenderShadowMap, KRMat4 &viewMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, int gBufferPass);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ KRShader::~KRShader() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KRShader::bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers) {
|
void KRShader::bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, int gBufferPass) {
|
||||||
glUseProgram(m_iProgram);
|
glUseProgram(m_iProgram);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public:
|
|||||||
GLuint getProgram();
|
GLuint getProgram();
|
||||||
char *getKey();
|
char *getKey();
|
||||||
|
|
||||||
void bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers);
|
void bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &cameraPosition, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, int gBufferPass);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
KRENGINE_ATTRIB_VERTEX,
|
KRENGINE_ATTRIB_VERTEX,
|
||||||
|
|||||||
@@ -47,10 +47,10 @@ KRShaderManager::~KRShaderManager() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
KRShader *KRShaderManager::getShader(KRCamera *pCamera, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, int iShadowQuality, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset) {
|
KRShader *KRShaderManager::getShader(std::string shader_name, KRCamera *pCamera, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, int iShadowQuality, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, int gBufferPass) {
|
||||||
|
|
||||||
char szKey[128];
|
char szKey[128];
|
||||||
sprintf(szKey, "%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d", pCamera->bEnablePerPixel, bDiffuseMap, bNormalMap, bSpecMap, pCamera->bDebugPSSM, iShadowQuality, pCamera->bEnableAmbient, pCamera->bEnableDiffuse, pCamera->bEnableSpecular, bLightMap, bDiffuseMapScale, bSpecMapScale, bNormalMapScale, bDiffuseMapOffset, bSpecMapOffset, bNormalMapOffset);
|
sprintf(szKey, "%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%i_%s", pCamera->bEnablePerPixel, bDiffuseMap, bNormalMap, bSpecMap, pCamera->bDebugPSSM, iShadowQuality, pCamera->bEnableAmbient, pCamera->bEnableDiffuse, pCamera->bEnableSpecular, bLightMap, bDiffuseMapScale, bSpecMapScale, bNormalMapScale, bDiffuseMapOffset, bSpecMapOffset, bNormalMapOffset, gBufferPass, shader_name.c_str());
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -85,6 +85,7 @@ KRShader *KRShaderManager::getShader(KRCamera *pCamera, bool bDiffuseMap, bool b
|
|||||||
stream << "\n#define ENABLE_AMBIENT " << (pCamera->bEnableAmbient ? "1" : "0");
|
stream << "\n#define ENABLE_AMBIENT " << (pCamera->bEnableAmbient ? "1" : "0");
|
||||||
stream << "\n#define ENABLE_DIFFUSE " << (pCamera->bEnableDiffuse ? "1" : "0");
|
stream << "\n#define ENABLE_DIFFUSE " << (pCamera->bEnableDiffuse ? "1" : "0");
|
||||||
stream << "\n#define ENABLE_SPECULAR " << (pCamera->bEnableSpecular ? "1" : "0");
|
stream << "\n#define ENABLE_SPECULAR " << (pCamera->bEnableSpecular ? "1" : "0");
|
||||||
|
stream << "\n#define GBUFFER_PASS " << gBufferPass;
|
||||||
|
|
||||||
stream.setf(ios::fixed,ios::floatfield);
|
stream.setf(ios::fixed,ios::floatfield);
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public:
|
|||||||
KRShaderManager(const GLchar *szVertShaderSource, const GLchar *szFragShaderSource);
|
KRShaderManager(const GLchar *szVertShaderSource, const GLchar *szFragShaderSource);
|
||||||
~KRShaderManager();
|
~KRShaderManager();
|
||||||
|
|
||||||
KRShader *getShader(KRCamera *pCamera, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, int iShadowQuality, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset);
|
KRShader *getShader(std::string shader_name, KRCamera *pCamera, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, int iShadowQuality, bool bLightMap, bool bDiffuseMapScale,bool bSpecMapScale, bool bNormalMapScale, bool bDiffuseMapOffset, bool bSpecMapOffset, bool bNormalMapOffset, int gBufferPass);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, KRShader *> m_shaders;
|
std::map<std::string, KRShader *> m_shaders;
|
||||||
|
|||||||
@@ -25,7 +25,8 @@
|
|||||||
// or implied, of Kearwood Gilbert.
|
// or implied, of Kearwood Gilbert.
|
||||||
//
|
//
|
||||||
|
|
||||||
#define GBUFFER_PASS 0
|
uniform lowp vec3 material_ambient, material_diffuse, material_specular;
|
||||||
|
uniform lowp float material_alpha;
|
||||||
|
|
||||||
#if GBUFFER_PASS == 1
|
#if GBUFFER_PASS == 1
|
||||||
#if HAS_NORMAL_MAP == 1
|
#if HAS_NORMAL_MAP == 1
|
||||||
@@ -35,8 +36,7 @@ uniform highp mat4 model_to_view;
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uniform lowp vec3 material_ambient, material_diffuse, material_specular;
|
|
||||||
uniform lowp float material_alpha;
|
|
||||||
|
|
||||||
#if ENABLE_PER_PIXEL == 1
|
#if ENABLE_PER_PIXEL == 1
|
||||||
uniform mediump float material_shininess;
|
uniform mediump float material_shininess;
|
||||||
@@ -190,7 +190,7 @@ void main()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#if GBUFFER_PASS == 0
|
#if GBUFFER_PASS == 0 || GBUFFER_PASS == 2
|
||||||
|
|
||||||
#if ENABLE_AMBIENT
|
#if ENABLE_AMBIENT
|
||||||
// -------------------- Add ambient light and alpha component --------------------
|
// -------------------- Add ambient light and alpha component --------------------
|
||||||
@@ -225,15 +225,12 @@ void main()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if GBUFFER_PASS == 1
|
#if GBUFFER_PASS == 1
|
||||||
|
#if HAS_NORMAL_MAP == 1
|
||||||
//gl_FragColor = vec4((normal + 1.0) / 2.0, 1.0f);
|
mediump vec3 view_space_normal = tangent_to_view * normal;
|
||||||
|
#else
|
||||||
#if HAS_NORMAL_MAP == 1
|
mediump vec3 view_space_normal = vec3(model_to_view * vec4(normal, 1.0));
|
||||||
mediump vec3 view_space_normal = tangent_to_view * normal;
|
#endif
|
||||||
#else
|
gl_FragColor = vec4(view_space_normal * 0.5 + 0.5, material_shininess / 100.0);
|
||||||
mediump vec3 view_space_normal = vec3(model_to_view * vec4(normal, 1.0));
|
|
||||||
#endif
|
|
||||||
gl_FragColor = vec4(view_space_normal * 0.5 + 0.5, 1.0);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -29,8 +29,6 @@
|
|||||||
// or implied, of Kearwood Gilbert.
|
// or implied, of Kearwood Gilbert.
|
||||||
//
|
//
|
||||||
|
|
||||||
#define GBUFFER_PASS 0
|
|
||||||
|
|
||||||
attribute highp vec3 myVertex, myNormal;
|
attribute highp vec3 myVertex, myNormal;
|
||||||
attribute highp vec3 myTangent;
|
attribute highp vec3 myTangent;
|
||||||
attribute mediump vec2 myUV;
|
attribute mediump vec2 myUV;
|
||||||
|
|||||||
Reference in New Issue
Block a user