Debugging cubemap reflections

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40126
This commit is contained in:
kearwood
2012-10-12 00:02:24 +00:00
parent 278c6d5926
commit 40c4f4c897
25 changed files with 290 additions and 153 deletions

View File

@@ -211,11 +211,11 @@
E45772F113C9A13C0037BEEA /* ShadowShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; lineEnding = 0; name = ShadowShader.vsh; path = Shaders/ShadowShader.vsh; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.glsl; }; E45772F113C9A13C0037BEEA /* ShadowShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; lineEnding = 0; name = ShadowShader.vsh; path = Shaders/ShadowShader.vsh; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.glsl; };
E45772F213C9A13C0037BEEA /* ShadowShader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = ShadowShader.fsh; path = Shaders/ShadowShader.fsh; sourceTree = "<group>"; }; E45772F213C9A13C0037BEEA /* ShadowShader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = ShadowShader.fsh; path = Shaders/ShadowShader.fsh; sourceTree = "<group>"; };
E45772F313C9A13C0037BEEA /* PostShader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = PostShader.fsh; path = Shaders/PostShader.fsh; sourceTree = "<group>"; }; E45772F313C9A13C0037BEEA /* PostShader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = PostShader.fsh; path = Shaders/PostShader.fsh; sourceTree = "<group>"; };
E45772F413C9A13C0037BEEA /* ObjectShader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = ObjectShader.fsh; path = Shaders/ObjectShader.fsh; sourceTree = "<group>"; }; E45772F413C9A13C0037BEEA /* ObjectShader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; lineEnding = 0; name = ObjectShader.fsh; path = Shaders/ObjectShader.fsh; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.glsl; };
E45772F513C9A13C0037BEEA /* ObjectShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; lineEnding = 0; name = ObjectShader.vsh; path = Shaders/ObjectShader.vsh; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.glsl; }; E45772F513C9A13C0037BEEA /* ObjectShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; lineEnding = 0; name = ObjectShader.vsh; path = Shaders/ObjectShader.vsh; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.glsl; };
E45772F613C9A13C0037BEEA /* PostShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = PostShader.vsh; path = Shaders/PostShader.vsh; sourceTree = "<group>"; }; E45772F613C9A13C0037BEEA /* PostShader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = PostShader.vsh; path = Shaders/PostShader.vsh; sourceTree = "<group>"; };
E461A151152E54B500F2044A /* KRLight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRLight.h; path = Classes/KRLight.h; sourceTree = "<group>"; }; E461A151152E54B500F2044A /* KRLight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRLight.h; path = Classes/KRLight.h; sourceTree = "<group>"; };
E461A155152E54F700F2044A /* KRLight.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRLight.cpp; path = Classes/KRLight.cpp; sourceTree = "<group>"; }; E461A155152E54F700F2044A /* KRLight.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRLight.cpp; path = Classes/KRLight.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
E461A157152E555400F2044A /* KRPointLight.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRPointLight.h; path = Classes/KRPointLight.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; E461A157152E555400F2044A /* KRPointLight.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRPointLight.h; path = Classes/KRPointLight.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
E461A158152E557E00F2044A /* KRPointLight.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRPointLight.cpp; path = Classes/KRPointLight.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; E461A158152E557E00F2044A /* KRPointLight.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; name = KRPointLight.cpp; path = Classes/KRPointLight.cpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
E461A15B152E563000F2044A /* KRDirectionalLight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRDirectionalLight.h; path = Classes/KRDirectionalLight.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; E461A15B152E563000F2044A /* KRDirectionalLight.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; name = KRDirectionalLight.h; path = Classes/KRDirectionalLight.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
@@ -285,7 +285,7 @@
E497B952151BEDA600D3DC67 /* KRResource+fbx.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "KRResource+fbx.cpp"; path = "Classes/KRResource+fbx.cpp"; sourceTree = "<group>"; }; E497B952151BEDA600D3DC67 /* KRResource+fbx.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "KRResource+fbx.cpp"; path = "Classes/KRResource+fbx.cpp"; sourceTree = "<group>"; };
E497B95C151BF05F00D3DC67 /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = ../../../../MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; }; E497B95C151BF05F00D3DC67 /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = ../../../../MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; };
E497B95E151BF09600D3DC67 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = ../../../../MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; E497B95E151BF09600D3DC67 /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = ../../../../MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
E4A9DEBD154120C4009DF363 /* light_point.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_point.fsh; path = Shaders/light_point.fsh; sourceTree = "<group>"; }; E4A9DEBD154120C4009DF363 /* light_point.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; lineEnding = 0; name = light_point.fsh; path = Shaders/light_point.fsh; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.glsl; };
E4A9DEC0154120E8009DF363 /* light_point.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_point.vsh; path = Shaders/light_point.vsh; sourceTree = "<group>"; }; E4A9DEC0154120E8009DF363 /* light_point.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = light_point.vsh; path = Shaders/light_point.vsh; sourceTree = "<group>"; };
E4B175AA161F5A1000B8FB80 /* KRTexture.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRTexture.cpp; path = Classes/KRTexture.cpp; sourceTree = "<group>"; }; E4B175AA161F5A1000B8FB80 /* KRTexture.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRTexture.cpp; path = Classes/KRTexture.cpp; sourceTree = "<group>"; };
E4B175AB161F5A1000B8FB80 /* KRTexture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRTexture.h; path = Classes/KRTexture.h; sourceTree = "<group>"; }; E4B175AB161F5A1000B8FB80 /* KRTexture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRTexture.h; path = Classes/KRTexture.h; sourceTree = "<group>"; };
@@ -302,7 +302,7 @@
E4BBBB981512A47500F43B5B /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = ../../../../MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; }; E4BBBB981512A47500F43B5B /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = ../../../../MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
E4BBBB9A1512A48200F43B5B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = ../../../../MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; E4BBBB9A1512A48200F43B5B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = ../../../../MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
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>"; }; E4CE184C15FF124600F80870 /* light_point_inside.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; lineEnding = 0; name = light_point_inside.fsh; path = Shaders/light_point_inside.fsh; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.glsl; };
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>"; }; 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>"; };
@@ -345,8 +345,8 @@
E45772F113C9A13C0037BEEA /* ShadowShader.vsh */, E45772F113C9A13C0037BEEA /* ShadowShader.vsh */,
E45772F213C9A13C0037BEEA /* ShadowShader.fsh */, E45772F213C9A13C0037BEEA /* ShadowShader.fsh */,
E45772F513C9A13C0037BEEA /* ObjectShader.vsh */, E45772F513C9A13C0037BEEA /* ObjectShader.vsh */,
E45772F313C9A13C0037BEEA /* PostShader.fsh */,
E45772F413C9A13C0037BEEA /* ObjectShader.fsh */, E45772F413C9A13C0037BEEA /* ObjectShader.fsh */,
E45772F313C9A13C0037BEEA /* PostShader.fsh */,
E45772F613C9A13C0037BEEA /* PostShader.vsh */, E45772F613C9A13C0037BEEA /* PostShader.vsh */,
E4D133B91538F7480070068C /* light_directional.fsh */, E4D133B91538F7480070068C /* light_directional.fsh */,
E4D133BB1538F7560070068C /* light_directional.vsh */, E4D133BB1538F7560070068C /* light_directional.vsh */,

View File

@@ -58,6 +58,7 @@ KRCamera::KRCamera(KRContext &context, GLint width, GLint height) : KRContextObj
bEnableNormalMap = true; bEnableNormalMap = true;
bEnableSpecMap = true; bEnableSpecMap = true;
bEnableReflectionMap = true; bEnableReflectionMap = true;
bEnableReflection = true;
bDebugPSSM = false; bDebugPSSM = false;
bEnableAmbient = true; bEnableAmbient = true;
bEnableDiffuse = true; bEnableDiffuse = true;
@@ -394,8 +395,9 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
if(m_pSkyBoxTexture) { if(m_pSkyBoxTexture) {
KRMat4 mvpMatrix = viewMatrix * getProjectionMatrix(); KRMat4 mvpMatrix = viewMatrix * getProjectionMatrix();
KRShader *pShader = getContext().getShaderManager()->getShader("sky_box", this, false, false, false, 0, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_OPAQUE); KRMat4 matModel;
pShader->bind(this, viewMatrix, mvpMatrix, lightDirection, NULL, NULL, 0, KRNode::RENDER_PASS_FORWARD_OPAQUE); KRShader *pShader = getContext().getShaderManager()->getShader("sky_box", this, false, false, false, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_OPAQUE);
pShader->bind(this, matModel, viewMatrix, mvpMatrix, lightDirection, NULL, NULL, 0, KRNode::RENDER_PASS_FORWARD_OPAQUE);
getContext().getTextureManager()->selectTexture(0, m_pSkyBoxTexture, 2048); getContext().getTextureManager()->selectTexture(0, m_pSkyBoxTexture, 2048);
@@ -468,7 +470,7 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
GLDEBUG(glEnable(GL_CULL_FACE)); GLDEBUG(glEnable(GL_CULL_FACE));
KRShader *pVisShader = m_pContext->getShaderManager()->getShader("visualize_overlay", this, false, false, false, 0, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); KRShader *pVisShader = m_pContext->getShaderManager()->getShader("visualize_overlay", this, false, false, false, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
KRMat4 projectionMatrix = getProjectionMatrix(); KRMat4 projectionMatrix = getProjectionMatrix();
@@ -478,8 +480,7 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, KRVector3 &lightD
matModel.scale((*itr).size() / 2.0f); matModel.scale((*itr).size() / 2.0f);
matModel.translate((*itr).center()); matModel.translate((*itr).center());
KRMat4 mvpmatrix = matModel * viewMatrix * projectionMatrix; KRMat4 mvpmatrix = matModel * viewMatrix * projectionMatrix;
if(pVisShader->bind(this, matModel, viewMatrix, mvpmatrix, lightDirection, shadowmvpmatrix, shadowDepthTexture, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) {
if(pVisShader->bind(this, viewMatrix, mvpmatrix, lightDirection, shadowmvpmatrix, shadowDepthTexture, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) {
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14)); GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14));
} }
} }
@@ -632,10 +633,11 @@ void KRCamera::renderShadowBuffer(KRScene &scene, int iShadow)
GLDEBUG(glDisable(GL_BLEND)); GLDEBUG(glDisable(GL_BLEND));
// Use shader program // Use shader program
KRShader *shadowShader = m_pContext->getShaderManager()->getShader("ShadowShader", this, false, false, false, 0, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); KRShader *shadowShader = m_pContext->getShaderManager()->getShader("ShadowShader", this, false, false, false, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
KRMat4 matIdentity; // Value not used by postshader KRMat4 matIdentity; // Value not used by postshader
KRVector3 vec4Temp; // Value not used by postshader KRVector3 vec4Temp; // Value not used by postshader
shadowShader->bind(this, matIdentity, matIdentity, vec4Temp, NULL, NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); KRMat4 matModel;
shadowShader->bind(this, matModel, matIdentity, matIdentity, vec4Temp, NULL, NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
// Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram // Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram
GLDEBUG(glUniformMatrix4fv(shadowShader->m_uniforms[KRShader::KRENGINE_UNIFORM_SHADOWMVP1], 1, GL_FALSE, shadowmvpmatrix[iShadow].getPointer())); GLDEBUG(glUniformMatrix4fv(shadowShader->m_uniforms[KRShader::KRENGINE_UNIFORM_SHADOWMVP1], 1, GL_FALSE, shadowmvpmatrix[iShadow].getPointer()));
@@ -703,10 +705,11 @@ void KRCamera::renderPost()
GLDEBUG(glDisable(GL_DEPTH_TEST)); GLDEBUG(glDisable(GL_DEPTH_TEST));
KRShader *postShader = m_pContext->getShaderManager()->getShader("PostShader", this, false, false, false, 0, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); KRShader *postShader = m_pContext->getShaderManager()->getShader("PostShader", this, false, false, false, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
KRMat4 matIdentity; // Value not used by postshader KRMat4 matIdentity; // Value not used by postshader
KRVector3 vec4Temp; // Value not used by postshader KRVector3 vec4Temp; // Value not used by postshader
postShader->bind(this, matIdentity, matIdentity, vec4Temp, NULL, NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); KRMat4 matModel;
postShader->bind(this, matModel, matIdentity, matIdentity, vec4Temp, NULL, NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
m_pContext->getTextureManager()->selectTexture(0, NULL, 0); m_pContext->getTextureManager()->selectTexture(0, NULL, 0);
GLDEBUG(glActiveTexture(GL_TEXTURE0)); GLDEBUG(glActiveTexture(GL_TEXTURE0));

View File

@@ -75,6 +75,7 @@ public:
bool bEnableNormalMap; bool bEnableNormalMap;
bool bEnableSpecMap; bool bEnableSpecMap;
bool bEnableReflectionMap; bool bEnableReflectionMap;
bool bEnableReflection;
bool bEnableLightMap; bool bEnableLightMap;
bool bDebugPSSM; bool bDebugPSSM;
bool bDebugSuperShiny; bool bDebugSuperShiny;

View File

@@ -60,16 +60,16 @@ void KRDirectionalLight::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &
KRMat4 projectionMatrix = pCamera->getProjectionMatrix(); KRMat4 projectionMatrix = pCamera->getProjectionMatrix();
KRMat4 mvpmatrix = m_modelMatrix * viewMatrix * projectionMatrix; KRMat4 mvpmatrix = m_modelMatrix * viewMatrix * projectionMatrix;
KRMat4 matModelToView = viewMatrix * m_modelMatrix; KRMat4 matModelViewInverseTranspose = viewMatrix * m_modelMatrix;
matModelToView.transpose(); matModelViewInverseTranspose.transpose();
matModelToView.invert(); matModelViewInverseTranspose.invert();
KRVector3 light_direction_view_space = getWorldLightDirection(); KRVector3 light_direction_view_space = getWorldLightDirection();
light_direction_view_space = KRMat4::Dot(matModelToView, light_direction_view_space); light_direction_view_space = KRMat4::Dot(matModelViewInverseTranspose, light_direction_view_space);
light_direction_view_space.normalize(); light_direction_view_space.normalize();
KRShader *pShader = pContext->getShaderManager()->getShader("light_directional", pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, false, renderPass); KRShader *pShader = pContext->getShaderManager()->getShader("light_directional", pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
if(pShader->bind(pCamera, matModelToView, mvpmatrix, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass)) { if(pShader->bind(pCamera, m_modelMatrix, viewMatrix, mvpmatrix, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass)) {
GLDEBUG(glUniform3f( GLDEBUG(glUniform3f(

View File

@@ -86,10 +86,11 @@ double const PI = 3.141592653589793f;
@"debug_enable_ambient" : @24, @"debug_enable_ambient" : @24,
@"debug_enable_diffuse" : @25, @"debug_enable_diffuse" : @25,
@"debug_enable_specular" : @26, @"debug_enable_specular" : @26,
@"debug_super_shiny" : @27, @"debug_enable_reflection" : @27,
@"debug_octree" : @28, @"debug_super_shiny" : @28,
@"debug_deferred" : @29, @"debug_octree" : @29,
@"enable_deferred_lighting" : @30 @"debug_deferred" : @30,
@"enable_deferred_lighting" : @31
} copy]; } copy];
[self loadShaders]; [self loadShaders];
@@ -159,7 +160,7 @@ double const PI = 3.141592653589793f;
-(NSString *)getParameterLabelWithIndex: (int)i -(NSString *)getParameterLabelWithIndex: (int)i
{ {
NSString *parameter_labels[31] = { NSString *parameter_labels[32] = {
@"Camera FOV", @"Camera FOV",
@"Shadow Quality (0 - 2)", @"Shadow Quality (0 - 2)",
@"Enable per-pixel lighting", @"Enable per-pixel lighting",
@@ -187,6 +188,7 @@ double const PI = 3.141592653589793f;
@"Debug - Enable Ambient", @"Debug - Enable Ambient",
@"Debug - Enable Diffuse", @"Debug - Enable Diffuse",
@"Debug - Enable Specular", @"Debug - Enable Specular",
@"Debug - Enable Reflections",
@"Debug - Super Shiny", @"Debug - Super Shiny",
@"Debug - Octree Visualize", @"Debug - Octree Visualize",
@"Debug - Deferred Lights Visualize", @"Debug - Deferred Lights Visualize",
@@ -196,7 +198,7 @@ double const PI = 3.141592653589793f;
} }
-(KREngineParameterType)getParameterTypeWithIndex: (int)i -(KREngineParameterType)getParameterTypeWithIndex: (int)i
{ {
KREngineParameterType types[31] = { KREngineParameterType types[32] = {
KRENGINE_PARAMETER_FLOAT, KRENGINE_PARAMETER_FLOAT,
KRENGINE_PARAMETER_INT, KRENGINE_PARAMETER_INT,
@@ -228,13 +230,14 @@ double const PI = 3.141592653589793f;
KRENGINE_PARAMETER_BOOL, KRENGINE_PARAMETER_BOOL,
KRENGINE_PARAMETER_BOOL, KRENGINE_PARAMETER_BOOL,
KRENGINE_PARAMETER_BOOL, KRENGINE_PARAMETER_BOOL,
KRENGINE_PARAMETER_BOOL,
KRENGINE_PARAMETER_BOOL KRENGINE_PARAMETER_BOOL
}; };
return types[i]; return types[i];
} }
-(double)getParameterValueWithIndex: (int)i -(double)getParameterValueWithIndex: (int)i
{ {
double values[31] = { double values[32] = {
_camera->perspective_fov, _camera->perspective_fov,
(double)_camera->m_cShadowBuffers, (double)_camera->m_cShadowBuffers,
_camera->bEnablePerPixel ? 1.0f : 0.0f, _camera->bEnablePerPixel ? 1.0f : 0.0f,
@@ -262,6 +265,7 @@ double const PI = 3.141592653589793f;
_camera->bEnableAmbient ? 1.0f : 0.0f, _camera->bEnableAmbient ? 1.0f : 0.0f,
_camera->bEnableDiffuse ? 1.0f : 0.0f, _camera->bEnableDiffuse ? 1.0f : 0.0f,
_camera->bEnableSpecular ? 1.0f : 0.0f, _camera->bEnableSpecular ? 1.0f : 0.0f,
_camera->bEnableReflection ? 1.0f : 0.0f,
_camera->bDebugSuperShiny ? 1.0f : 0.0f, _camera->bDebugSuperShiny ? 1.0f : 0.0f,
_camera->bShowOctree ? 1.0f : 0.0f, _camera->bShowOctree ? 1.0f : 0.0f,
_camera->bShowDeferred ? 1.0f : 0.0f, _camera->bShowDeferred ? 1.0f : 0.0f,
@@ -386,21 +390,26 @@ double const PI = 3.141592653589793f;
} }
break; break;
case 27: case 27:
if(_camera->bEnableReflection != bNewBoolVal) {
_camera->bEnableReflection = bNewBoolVal;
}
break;
case 28:
if(_camera->bDebugSuperShiny != bNewBoolVal) { if(_camera->bDebugSuperShiny != bNewBoolVal) {
_camera->bDebugSuperShiny = bNewBoolVal; _camera->bDebugSuperShiny = bNewBoolVal;
} }
break; break;
case 28: case 29:
if(_camera->bShowOctree != bNewBoolVal) { if(_camera->bShowOctree != bNewBoolVal) {
_camera->bShowOctree = bNewBoolVal; _camera->bShowOctree = bNewBoolVal;
} }
break; break;
case 29: case 30:
if(_camera->bShowDeferred != bNewBoolVal) { if(_camera->bShowDeferred != bNewBoolVal) {
_camera->bShowDeferred = bNewBoolVal; _camera->bShowDeferred = bNewBoolVal;
} }
break; break;
case 30: case 31:
if(_camera->bEnableDeferredLighting != bNewBoolVal) { if(_camera->bEnableDeferredLighting != bNewBoolVal) {
_camera->bEnableDeferredLighting = bNewBoolVal; _camera->bEnableDeferredLighting = bNewBoolVal;
} }
@@ -410,11 +419,11 @@ double const PI = 3.141592653589793f;
-(double)getParameterMinWithIndex: (int)i -(double)getParameterMinWithIndex: (int)i
{ {
double minValues[31] = { double minValues[32] = {
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 0.0f 0.0f, 0.0f, 0.0f, 0.0f
}; };
return minValues[i]; return minValues[i];
@@ -422,11 +431,11 @@ double const PI = 3.141592653589793f;
-(double)getParameterMaxWithIndex: (int)i -(double)getParameterMaxWithIndex: (int)i
{ {
double maxValues[31] = { double maxValues[32] = {
PI, 3.0f, 1.0f, 1.0, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 10.0f, PI, 3.0f, 1.0f, 1.0, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 10.0f,
1.0f, 10.0f, 2.0f, 1.0f, 1.0f, 1.0f, 5.0f, 1.0f, 1.0f, 10.0f, 2.0f, 1.0f, 1.0f, 1.0f, 5.0f, 1.0f,
0.5f, 1.0f, 2.0f, 2.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.5f, 1.0f, 2.0f, 2.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f 1.0f, 1.0f, 1.0f, 1.0f
}; };
return maxValues[i]; return maxValues[i];

View File

@@ -95,8 +95,8 @@ void KRInstance::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatr
if(renderPass != KRNode::RENDER_PASS_SHADOWMAP) { if(renderPass != KRNode::RENDER_PASS_SHADOWMAP) {
projectionMatrix = pCamera->getProjectionMatrix(); projectionMatrix = pCamera->getProjectionMatrix();
} }
KRMat4 matVP = viewMatrix * projectionMatrix; KRMat4 matMVP = m_modelMatrix * viewMatrix * projectionMatrix;
float lod_coverage = getBounds().coverage(matVP, pCamera->getViewportSize()); // This also checks the view frustrum culling float lod_coverage = getBounds().coverage(matMVP, pCamera->getViewportSize()); // This also checks the view frustrum culling
if(lod_coverage > m_min_lod_coverage) { if(lod_coverage > m_min_lod_coverage) {
// ---===--- Select the best LOD model based on screen coverage ---===--- // ---===--- Select the best LOD model based on screen coverage ---===---
@@ -120,10 +120,6 @@ void KRInstance::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatr
m_pContext->getTextureManager()->selectTexture(3, m_pLightMap, 0); m_pContext->getTextureManager()->selectTexture(3, m_pLightMap, 0);
} }
KRMat4 mvpmatrix = m_modelMatrix * viewMatrix * projectionMatrix;
KRMat4 matModelToView = viewMatrix * m_modelMatrix;
matModelToView.transpose();
matModelToView.invert();
KRMat4 inverseViewMatrix = viewMatrix; KRMat4 inverseViewMatrix = viewMatrix;
@@ -136,7 +132,7 @@ void KRInstance::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatr
KRVector3 cameraPosObject = KRMat4::Dot(inverseModelMatrix, cameraPosition); KRVector3 cameraPosObject = KRMat4::Dot(inverseModelMatrix, cameraPosition);
KRVector3 lightDirObject = KRMat4::Dot(inverseModelMatrix, lightDirection); KRVector3 lightDirObject = KRMat4::Dot(inverseModelMatrix, lightDirection);
pModel->render(pCamera, pContext, viewMatrix, matModelToView, mvpmatrix, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, m_pLightMap, renderPass); pModel->render(pCamera, pContext, m_modelMatrix, viewMatrix, matMVP, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, m_pLightMap, renderPass);
} }
} }
} }

View File

@@ -143,8 +143,8 @@ void KRLight::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatrix,
matModelToView.invert(); matModelToView.invert();
// Render light flare on transparency pass // Render light flare on transparency pass
KRShader *pShader = pContext->getShaderManager()->getShader("flare", pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, false, renderPass); KRShader *pShader = pContext->getShaderManager()->getShader("flare", pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
if(pShader->bind(pCamera, matModelToView, mvpmatrix, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass)) { if(pShader->bind(pCamera, m_modelMatrix, matModelToView, mvpmatrix, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass)) {
GLDEBUG(glUniform1f( GLDEBUG(glUniform1f(
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE], pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_FLARE_SIZE],
m_flareSize m_flareSize

View File

@@ -50,7 +50,7 @@ KRMaterial::KRMaterial(KRContext &context, const char *szName) : KRResource(cont
m_ambientColor = KRVector3::Zero(); m_ambientColor = KRVector3::Zero();
m_diffuseColor = KRVector3::One(); m_diffuseColor = KRVector3::One();
m_specularColor = KRVector3::One(); m_specularColor = KRVector3::One();
m_reflectionColor = KRVector3::One(); m_reflectionColor = KRVector3::Zero();
m_tr = (GLfloat)1.0f; m_tr = (GLfloat)1.0f;
m_ns = (GLfloat)0.0f; m_ns = (GLfloat)0.0f;
m_ambientMap = ""; m_ambientMap = "";
@@ -67,8 +67,13 @@ KRMaterial::KRMaterial(KRContext &context, const char *szName) : KRResource(cont
m_diffuseMapScale = KRVector2(1.0f, 1.0f); m_diffuseMapScale = KRVector2(1.0f, 1.0f);
m_reflectionMapOffset = KRVector2(0.0f, 0.0f); m_reflectionMapOffset = KRVector2(0.0f, 0.0f);
m_reflectionMapScale = KRVector2(1.0f, 1.0f); m_reflectionMapScale = KRVector2(1.0f, 1.0f);
m_reflectionFactor = 0.0f;
m_alpha_mode = KRMATERIAL_ALPHA_MODE_OPAQUE; m_alpha_mode = KRMATERIAL_ALPHA_MODE_OPAQUE;
// FINDME - HACK - Test Code:
m_reflectionCube = "skycube";
m_reflectionColor = KRVector3(0.75, 0.75, 0.75);
} }
KRMaterial::~KRMaterial() { KRMaterial::~KRMaterial() {
@@ -91,7 +96,6 @@ bool KRMaterial::save(const std::string& path) {
fprintf(f, "kr %f %f %f\n", m_reflectionColor.x, m_reflectionColor.y, m_reflectionColor.z); fprintf(f, "kr %f %f %f\n", m_reflectionColor.x, m_reflectionColor.y, m_reflectionColor.z);
fprintf(f, "Tr %f\n", m_tr); fprintf(f, "Tr %f\n", m_tr);
fprintf(f, "Ns %f\n", m_ns); fprintf(f, "Ns %f\n", m_ns);
fprintf(f, "reflectionFactor %f\n", m_reflectionFactor);
if(m_ambientMap.size()) { if(m_ambientMap.size()) {
fprintf(f, "map_Ka %s.pvr -s %f %f -o %f %f\n", m_ambientMap.c_str(), m_ambientMapScale.x, m_ambientMapScale.y, m_ambientMapOffset.x, m_ambientMapOffset.y); fprintf(f, "map_Ka %s.pvr -s %f %f -o %f %f\n", m_ambientMap.c_str(), m_ambientMapScale.x, m_ambientMapScale.y, m_ambientMapOffset.x, m_ambientMapOffset.y);
} }
@@ -161,6 +165,9 @@ void KRMaterial::setReflectionMap(std::string texture_name, KRVector2 texture_sc
void KRMaterial::setReflectionCube(std::string texture_name) { void KRMaterial::setReflectionCube(std::string texture_name) {
m_reflectionCube = texture_name; m_reflectionCube = texture_name;
// FINDME - HACK - Test Code:
m_reflectionCube = "skycube";
m_reflectionColor = KRVector3(0.75, 0.75, 0.75);
} }
void KRMaterial::setAlphaMode(KRMaterial::alpha_mode_type alpha_mode) { void KRMaterial::setAlphaMode(KRMaterial::alpha_mode_type alpha_mode) {
@@ -185,6 +192,9 @@ void KRMaterial::setSpecular(const KRVector3 &c) {
void KRMaterial::setReflection(const KRVector3 &c) { void KRMaterial::setReflection(const KRVector3 &c) {
m_reflectionColor = c; m_reflectionColor = c;
// FINDME - HACK - Test Code:
m_reflectionCube = "skycube";
m_reflectionColor = KRVector3(0.75, 0.75, 0.75);
} }
void KRMaterial::setTransparency(GLfloat a) { void KRMaterial::setTransparency(GLfloat a) {
@@ -198,16 +208,12 @@ void KRMaterial::setShininess(GLfloat s) {
m_ns = s; m_ns = s;
} }
void KRMaterial::setReflectionFactor(GLfloat r) {
m_reflectionFactor = r;
}
bool KRMaterial::isTransparent() { bool KRMaterial::isTransparent() {
return m_tr < 1.0 || m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDONESIDE || m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE; return m_tr < 1.0 || m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDONESIDE || m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE;
} }
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
bool KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRContext *pContext, KRTexture *pLightMap, KRNode::RenderPass renderPass) { bool KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRCamera *pCamera, KRMat4 &matModel, KRMat4 &matView, KRMat4 &mvpMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRContext *pContext, KRTexture *pLightMap, KRNode::RenderPass renderPass) {
bool bSameMaterial = *prevBoundMaterial == this; bool bSameMaterial = *prevBoundMaterial == this;
bool bLightMap = pLightMap && pCamera->bEnableLightMap; bool bLightMap = pLightMap && pCamera->bEnableLightMap;
@@ -234,18 +240,21 @@ bool KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
KRVector2 default_scale = KRVector2(1.0f, 1.0f); KRVector2 default_scale = KRVector2(1.0f, 1.0f);
KRVector2 default_offset = KRVector2(0.0f, 0.0f); KRVector2 default_offset = KRVector2(0.0f, 0.0f);
bool bHasReflection = m_reflectionColor != KRVector3(0.0f, 0.0f, 0.0f);
bool bDiffuseMap = m_pDiffuseMap != NULL && pCamera->bEnableDiffuseMap; bool bDiffuseMap = m_pDiffuseMap != NULL && pCamera->bEnableDiffuseMap;
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;
bool bReflectionMap = m_pReflectionMap != NULL && pCamera->bEnableReflectionMap; bool bReflectionMap = m_pReflectionMap != NULL && pCamera->bEnableReflectionMap && pCamera->bEnableReflection && bHasReflection;
bool bReflectionCubeMap = m_pReflectionCube != NULL && pCamera->bEnableReflection && bHasReflection;
bool bAlphaTest = (m_alpha_mode == KRMATERIAL_ALPHA_MODE_TEST) && bDiffuseMap; bool bAlphaTest = (m_alpha_mode == KRMATERIAL_ALPHA_MODE_TEST) && bDiffuseMap;
bool bAlphaBlend = (m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDONESIDE) || (m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE); bool bAlphaBlend = (m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDONESIDE) || (m_alpha_mode == KRMATERIAL_ALPHA_MODE_BLENDTWOSIDE);
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, bAlphaTest, bAlphaBlend, renderPass);
KRShader *pShader = pContext->getShaderManager()->getShader("ObjectShader", pCamera, bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, cShadowBuffers, bLightMap, m_diffuseMapScale != default_scale && bDiffuseMap, m_specularMapScale != default_scale && bSpecMap, m_reflectionMapScale != default_scale && bReflectionMap, m_normalMapScale != default_scale && bNormalMap, m_diffuseMapOffset != default_offset && bDiffuseMap, m_specularMapOffset != default_offset && bSpecMap, m_reflectionMapOffset != default_offset && bReflectionMap, m_normalMapOffset != default_offset && bNormalMap, bAlphaTest, bAlphaBlend, renderPass);
bool bSameShader = strcmp(pShader->getKey(), szPrevShaderKey) == 0; bool bSameShader = strcmp(pShader->getKey(), szPrevShaderKey) == 0;
if(!bSameShader) { if(!bSameShader) {
if(!pShader->bind(pCamera, matModelToView, mvpMatrix, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass)) { if(!pShader->bind(pCamera, matModel, matView, mvpMatrix, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, renderPass)) {
return false; return false;
} }
@@ -406,7 +415,6 @@ bool KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
} }
GLDEBUG(glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA], m_tr)); GLDEBUG(glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_ALPHA], m_tr));
GLDEBUG(glUniform1f(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_MATERIAL_REFLECTIVITY], m_reflectionFactor));
if(bDiffuseMap) { if(bDiffuseMap) {
m_pContext->getTextureManager()->selectTexture(0, m_pDiffuseMap, 2048); m_pContext->getTextureManager()->selectTexture(0, m_pDiffuseMap, 2048);
@@ -420,6 +428,10 @@ bool KRMaterial::bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRC
m_pContext->getTextureManager()->selectTexture(2, m_pNormalMap, 2048); m_pContext->getTextureManager()->selectTexture(2, m_pNormalMap, 2048);
} }
if(bReflectionCubeMap && (renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE || renderPass == KRNode::RENDER_PASS_DEFERRED_OPAQUE)) {
m_pContext->getTextureManager()->selectTexture(4, m_pReflectionCube, 2048);
}
if(bReflectionMap && (renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE || renderPass == KRNode::RENDER_PASS_DEFERRED_OPAQUE)) { if(bReflectionMap && (renderPass == KRNode::RENDER_PASS_FORWARD_OPAQUE || renderPass == KRNode::RENDER_PASS_DEFERRED_OPAQUE)) {
// GL_TEXTURE7 is used for reading the depth buffer in gBuffer pass 2 and re-used for the reflection map in gBuffer Pass 3 and in forward rendering // GL_TEXTURE7 is used for reading the depth buffer in gBuffer pass 2 and re-used for the reflection map in gBuffer Pass 3 and in forward rendering
m_pContext->getTextureManager()->selectTexture(7, m_pReflectionMap, 2048); m_pContext->getTextureManager()->selectTexture(7, m_pReflectionMap, 2048);

View File

@@ -81,7 +81,6 @@ public:
void setReflection(const KRVector3 &c); void setReflection(const KRVector3 &c);
void setTransparency(GLfloat a); void setTransparency(GLfloat a);
void setShininess(GLfloat s); void setShininess(GLfloat s);
void setReflectionFactor(GLfloat r);
void setAlphaMode(alpha_mode_type blend_mode); void setAlphaMode(alpha_mode_type blend_mode);
alpha_mode_type getAlphaMode(); alpha_mode_type getAlphaMode();
@@ -90,7 +89,7 @@ public:
char *getName(); char *getName();
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
bool bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRContext *pContext, KRTexture *pLightMap, KRNode::RenderPass renderPass); bool bind(KRMaterial **prevBoundMaterial, char *szPrevShaderKey, KRCamera *pCamera, KRMat4 &matModel, KRMat4 &matView, KRMat4 &mvpMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRContext *pContext, KRTexture *pLightMap, KRNode::RenderPass renderPass);
#endif #endif
@@ -135,7 +134,6 @@ private:
GLfloat m_tr; // Transparency GLfloat m_tr; // Transparency
GLfloat m_ns; // Shininess GLfloat m_ns; // Shininess
GLfloat m_reflectionFactor; // Level of reflectivity
alpha_mode_type m_alpha_mode; alpha_mode_type m_alpha_mode;
}; };

View File

@@ -105,7 +105,7 @@ void KRModel::loadPack(KRDataBlock *data) {
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
void KRModel::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatrix, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRTexture *pLightMap, KRNode::RenderPass renderPass) { void KRModel::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &matModel, KRMat4 &matView, KRMat4 &matMVP, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRTexture *pLightMap, KRNode::RenderPass renderPass) {
//fprintf(stderr, "Rendering model: %s\n", m_name.c_str()); //fprintf(stderr, "Rendering model: %s\n", m_name.c_str());
if(renderPass != KRNode::RENDER_PASS_FLARES) { if(renderPass != KRNode::RENDER_PASS_FLARES) {
@@ -158,7 +158,8 @@ void KRModel::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatrix,
if(pMaterial != NULL && pMaterial == (*mat_itr)) { if(pMaterial != NULL && pMaterial == (*mat_itr)) {
if((!pMaterial->isTransparent() && renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT) || (pMaterial->isTransparent() && renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) { if((!pMaterial->isTransparent() && renderPass != KRNode::RENDER_PASS_FORWARD_TRANSPARENT) || (pMaterial->isTransparent() && renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) {
if(pMaterial->bind(&pPrevBoundMaterial, szPrevShaderKey, pCamera, matModelToView, mvpMatrix, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, pContext, pLightMap, renderPass)) { KRMat4 matModel; // FINDME - HACK - Model matrices are all currently identity matrices
if(pMaterial->bind(&pPrevBoundMaterial, szPrevShaderKey, pCamera, matModel, matView, matMVP, lightDirection, pShadowMatrices, shadowDepthTextures, cShadowBuffers, pContext, pLightMap, renderPass)) {
switch(pMaterial->getAlphaMode()) { switch(pMaterial->getAlphaMode()) {
case KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE: // Non-transparent materials case KRMaterial::KRMATERIAL_ALPHA_MODE_OPAQUE: // Non-transparent materials

View File

@@ -66,7 +66,7 @@ public:
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
void render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMatrix, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRTexture *pLightMap, KRNode::RenderPass renderPass); void render(KRCamera *pCamera, KRContext *pContext, KRMat4 &matModel, KRMat4 &matView, KRMat4 &matMVP, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRTexture *pLightMap, KRNode::RenderPass renderPass);
#endif #endif

View File

@@ -58,17 +58,6 @@ void KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMa
KRMat4 mvpmatrix = m_modelMatrix * viewMatrix * projectionMatrix; KRMat4 mvpmatrix = m_modelMatrix * viewMatrix * projectionMatrix;
KRMat4 matModelToView = viewMatrix * m_modelMatrix;
matModelToView.transpose();
matModelToView.invert();
KRMat4 matModelToView2 = KRMat4() * m_modelMatrix * viewMatrix;
KRMat4 matViewToModel = m_modelMatrix * viewMatrix;
matViewToModel.invert();
KRVector3 view_space_light_position = KRMat4::Dot(matModelToView2, KRVector3::Zero()); // Origin point of model space is the light source position. No perspective, so no w divide required
KRBoundingVolume influence_extents = KRBoundingVolume(KRVector3(-1.0), KRVector3(1.0), m_modelMatrix); KRBoundingVolume influence_extents = KRBoundingVolume(KRVector3(-1.0), KRVector3(1.0), m_modelMatrix);
@@ -81,8 +70,10 @@ void KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMa
bool bInsideLight = view_light_position.sqrMagnitude() <= (influence_radius + pCamera->perspective_nearz) * (influence_radius + pCamera->perspective_nearz); bool bInsideLight = view_light_position.sqrMagnitude() <= (influence_radius + pCamera->perspective_nearz) * (influence_radius + pCamera->perspective_nearz);
KRShader *pShader = pContext->getShaderManager()->getShader(bVisualize ? "visualize_overlay" : (bInsideLight ? "light_point_inside" : "light_point"), pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, false, renderPass); KRShader *pShader = pContext->getShaderManager()->getShader(bVisualize ? "visualize_overlay" : (bInsideLight ? "light_point_inside" : "light_point"), pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, renderPass);
if(pShader->bind(pCamera, matModelToView, mvpmatrix, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass)) { if(pShader->bind(pCamera, m_modelMatrix, viewMatrix, mvpmatrix, lightDirection, pShadowMatrices, shadowDepthTextures, 0, renderPass)) {
GLDEBUG(glUniform3f( GLDEBUG(glUniform3f(
@@ -115,15 +106,6 @@ void KRPointLight::render(KRCamera *pCamera, KRContext *pContext, KRMat4 &viewMa
light_position.z light_position.z
)); ));
GLDEBUG(glUniform3f(
pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_POSITION_VIEW_SPACE],
view_space_light_position.x,
view_space_light_position.y,
view_space_light_position.z
));
GLDEBUG(glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_V2M], 1, GL_FALSE, matViewToModel.getPointer()));
GLDEBUG(glUniformMatrix4fv(pShader->m_uniforms[KRShader::KRENGINE_UNIFORM_M2V], 1, GL_FALSE, matModelToView2.getPointer()));
if(bVisualize) { if(bVisualize) {

View File

@@ -463,11 +463,15 @@ void LoadMesh(KRNode *parent_node, std::vector<KRResource *> &resources, KFbxGeo
lKFbxDouble1 =((KFbxSurfacePhong *) pMaterial)->SpecularFactor; lKFbxDouble1 =((KFbxSurfacePhong *) pMaterial)->SpecularFactor;
double specular_factor = lKFbxDouble1.Get(); double specular_factor = lKFbxDouble1.Get();
// Reflection factor
lKFbxDouble1 =((KFbxSurfacePhong *) pMaterial)->ReflectionFactor;
// Reflection color // Reflection color
lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Reflection; lKFbxDouble3 =((KFbxSurfacePhong *) pMaterial)->Reflection;
// Reflection factor // We modulate Relection color by reflection factor, as we only have one "reflection color" variable in Kraken
lKFbxDouble1 =((KFbxSurfacePhong *) pMaterial)->ReflectionFactor; new_material->setReflection(KRVector3(lKFbxDouble3.Get()[0] * lKFbxDouble1.Get(), lKFbxDouble3.Get()[1] * lKFbxDouble1.Get(), lKFbxDouble3.Get()[2] * lKFbxDouble1.Get()));
} else if(pMaterial->GetClassId().Is(KFbxSurfaceLambert::ClassId) ) { } else if(pMaterial->GetClassId().Is(KFbxSurfaceLambert::ClassId) ) {
// We found a Lambert material. // We found a Lambert material.

View File

@@ -229,7 +229,7 @@ void KRScene::render(int childOrder[], KROctreeNode *pOctreeNode, std::set<KRAAB
if(bNeedOcclusionTest) { if(bNeedOcclusionTest) {
pOctreeNode->beginOcclusionQuery(); pOctreeNode->beginOcclusionQuery();
KRShader *pVisShader = m_pContext->getShaderManager()->getShader("occlusion_test", pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT); KRShader *pVisShader = m_pContext->getShaderManager()->getShader("occlusion_test", pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
KRMat4 projectionMatrix = pCamera->getProjectionMatrix(); KRMat4 projectionMatrix = pCamera->getProjectionMatrix();
@@ -253,8 +253,7 @@ void KRScene::render(int childOrder[], KROctreeNode *pOctreeNode, std::set<KRAAB
GLDEBUG(glDepthMask(GL_FALSE)); GLDEBUG(glDepthMask(GL_FALSE));
} }
if(pVisShader->bind(pCamera, matModel, viewMatrix, mvpmatrix, lightDirection, pShadowMatrices, shadowDepthTextures, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) {
if(pVisShader->bind(pCamera, viewMatrix, mvpmatrix, lightDirection, pShadowMatrices, shadowDepthTextures, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT)) {
GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14)); GLDEBUG(glDrawArrays(GL_TRIANGLE_STRIP, 0, 14));
} }

View File

@@ -118,9 +118,8 @@ KRShader::KRShader(char *szKey, std::string options, std::string vertShaderSourc
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_DIFFUSE] = glGetUniformLocation(m_iProgram, "material_diffuse")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_DIFFUSE] = glGetUniformLocation(m_iProgram, "material_diffuse"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_SPECULAR] = glGetUniformLocation(m_iProgram, "material_specular")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_SPECULAR] = glGetUniformLocation(m_iProgram, "material_specular"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_REFLECTION] = glGetUniformLocation(m_iProgram, "material_reflection")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_REFLECTION] = glGetUniformLocation(m_iProgram, "material_reflection"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_REFLECTIVITY] = glGetUniformLocation(m_iProgram, "material_reflectivity"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_POSITION] = glGetUniformLocation(m_iProgram, "light_position")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_POSITION] = glGetUniformLocation(m_iProgram, "light_position"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_POSITION_VIEW_SPACE] = glGetUniformLocation(m_iProgram, "view_space_light_position")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_POSITION_VIEW_SPACE] = glGetUniformLocation(m_iProgram, "view_space_model_origin"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_COLOR] = glGetUniformLocation(m_iProgram, "light_color")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_COLOR] = glGetUniformLocation(m_iProgram, "light_color"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_INTENSITY] = glGetUniformLocation(m_iProgram, "light_intensity")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_INTENSITY] = glGetUniformLocation(m_iProgram, "light_intensity"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_DECAY_START] = glGetUniformLocation(m_iProgram, "light_decay_start")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_LIGHT_DECAY_START] = glGetUniformLocation(m_iProgram, "light_decay_start"));
@@ -128,13 +127,17 @@ KRShader::KRShader(char *szKey, std::string options, std::string vertShaderSourc
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_FLARE_SIZE] = glGetUniformLocation(m_iProgram, "flare_size")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_FLARE_SIZE] = glGetUniformLocation(m_iProgram, "flare_size"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_ALPHA] = glGetUniformLocation(m_iProgram, "material_alpha")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_ALPHA] = glGetUniformLocation(m_iProgram, "material_alpha"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_SHININESS] = glGetUniformLocation(m_iProgram, "material_shininess")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MATERIAL_SHININESS] = glGetUniformLocation(m_iProgram, "material_shininess"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MVP] = glGetUniformLocation(m_iProgram, "mvp_matrix")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MVP] = glGetUniformLocation(m_iProgram, "mvp_matrix"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_INVP] = glGetUniformLocation(m_iProgram, "inv_projection_matrix"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_INVMVP] = glGetUniformLocation(m_iProgram, "inv_mvp_matrix")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_INVMVP] = glGetUniformLocation(m_iProgram, "inv_mvp_matrix"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_INVP] = glGetUniformLocation(m_iProgram, "inv_projection_matrix"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_INVMVP_NO_TRANSLATE] = glGetUniformLocation(m_iProgram, "inv_mvp_matrix_no_translate")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_INVMVP_NO_TRANSLATE] = glGetUniformLocation(m_iProgram, "inv_mvp_matrix_no_translate"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MN2V] = glGetUniformLocation(m_iProgram, "model_normal_to_view_matrix")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MODEL_VIEW_INVERSE_TRANSPOSE] = glGetUniformLocation(m_iProgram, "model_view_inverse_transpose_matrix"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_M2V] = glGetUniformLocation(m_iProgram, "model_to_view_matrix")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_M2V] = glGetUniformLocation(m_iProgram, "model_view_matrix"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_V2M] = glGetUniformLocation(m_iProgram, "view_to_model_matrix")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_MODEL_MATRIX] = glGetUniformLocation(m_iProgram, "model_matrix"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_V2M] = glGetUniformLocation(m_iProgram, "inv_model_view_matrix"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWMVP1] = glGetUniformLocation(m_iProgram, "shadow_mvp1")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWMVP1] = glGetUniformLocation(m_iProgram, "shadow_mvp1"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWMVP2] = glGetUniformLocation(m_iProgram, "shadow_mvp2")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWMVP2] = glGetUniformLocation(m_iProgram, "shadow_mvp2"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWMVP3] = glGetUniformLocation(m_iProgram, "shadow_mvp3")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SHADOWMVP3] = glGetUniformLocation(m_iProgram, "shadow_mvp3"));
@@ -145,6 +148,7 @@ KRShader::KRShader(char *szKey, std::string options, std::string vertShaderSourc
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_DIFFUSETEXTURE] = glGetUniformLocation(m_iProgram, "diffuseTexture")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_DIFFUSETEXTURE] = glGetUniformLocation(m_iProgram, "diffuseTexture"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SPECULARTEXTURE] = glGetUniformLocation(m_iProgram, "specularTexture")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SPECULARTEXTURE] = glGetUniformLocation(m_iProgram, "specularTexture"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_REFLECTIONTEXTURE] = glGetUniformLocation(m_iProgram, "reflectionTexture")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_REFLECTIONTEXTURE] = glGetUniformLocation(m_iProgram, "reflectionTexture"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_REFLECTIONCUBETEXTURE] = glGetUniformLocation(m_iProgram, "reflectionCubeTexture"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_NORMALTEXTURE] = glGetUniformLocation(m_iProgram, "normalTexture")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_NORMALTEXTURE] = glGetUniformLocation(m_iProgram, "normalTexture"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_DIFFUSETEXTURE_SCALE] = glGetUniformLocation(m_iProgram, "diffuseTexture_Scale")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_DIFFUSETEXTURE_SCALE] = glGetUniformLocation(m_iProgram, "diffuseTexture_Scale"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SPECULARTEXTURE_SCALE] = glGetUniformLocation(m_iProgram, "specularTexture_Scale")); GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SPECULARTEXTURE_SCALE] = glGetUniformLocation(m_iProgram, "specularTexture_Scale"));
@@ -197,12 +201,12 @@ KRShader::~KRShader() {
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
bool KRShader::bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) { bool KRShader::bind(KRCamera *pCamera, KRMat4 &matModel, KRMat4 &matView, KRMat4 &mvpMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
if(m_iProgram == 0) { if(m_iProgram == 0) {
return false; return false;
} }
KRMat4 inverseViewMatrix = matModelToView; KRMat4 inverseViewMatrix = matView;
inverseViewMatrix.invert(); inverseViewMatrix.invert();
KRVector3 cameraPosition = KRMat4::Dot(inverseViewMatrix, KRVector3::Zero()); KRVector3 cameraPosition = KRMat4::Dot(inverseViewMatrix, KRVector3::Zero());
@@ -211,7 +215,13 @@ bool KRShader::bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix
// Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram // Bind our modelmatrix variable to be a uniform called mvpmatrix in our shaderprogram
GLDEBUG(glUniformMatrix4fv(m_uniforms[KRENGINE_UNIFORM_MVP], 1, GL_FALSE, mvpMatrix.getPointer())); GLDEBUG(glUniformMatrix4fv(m_uniforms[KRENGINE_UNIFORM_MVP], 1, GL_FALSE, mvpMatrix.getPointer()));
GLDEBUG(glUniformMatrix4fv(m_uniforms[KRENGINE_UNIFORM_MN2V], 1, GL_FALSE, matModelToView.getPointer()));
KRMat4 matModelViewInverseTranspose = matView * matModel;
matModelViewInverseTranspose.transpose();
matModelViewInverseTranspose.invert();
GLDEBUG(glUniformMatrix4fv(m_uniforms[KRENGINE_UNIFORM_MODEL_VIEW_INVERSE_TRANSPOSE], 1, GL_FALSE, matModelViewInverseTranspose.getPointer()));
KRMat4 matInvProjection; KRMat4 matInvProjection;
@@ -223,7 +233,7 @@ bool KRShader::bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix
matInvMVP.invert(); matInvMVP.invert();
GLDEBUG(glUniformMatrix4fv(m_uniforms[KRShader::KRENGINE_UNIFORM_INVMVP], 1, GL_FALSE, matInvMVP.getPointer())); GLDEBUG(glUniformMatrix4fv(m_uniforms[KRShader::KRENGINE_UNIFORM_INVMVP], 1, GL_FALSE, matInvMVP.getPointer()));
KRMat4 matInvMVPNoTranslate = matModelToView; KRMat4 matInvMVPNoTranslate = matModel * matView;
// Remove the translation // Remove the translation
matInvMVPNoTranslate.getPointer()[3] = 0; matInvMVPNoTranslate.getPointer()[3] = 0;
matInvMVPNoTranslate.getPointer()[7] = 0; matInvMVPNoTranslate.getPointer()[7] = 0;
@@ -236,6 +246,26 @@ bool KRShader::bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix
matInvMVPNoTranslate.invert(); matInvMVPNoTranslate.invert();
GLDEBUG(glUniformMatrix4fv(m_uniforms[KRShader::KRENGINE_UNIFORM_INVMVP_NO_TRANSLATE], 1, GL_FALSE, matInvMVPNoTranslate.getPointer())); GLDEBUG(glUniformMatrix4fv(m_uniforms[KRShader::KRENGINE_UNIFORM_INVMVP_NO_TRANSLATE], 1, GL_FALSE, matInvMVPNoTranslate.getPointer()));
GLDEBUG(glUniformMatrix4fv(m_uniforms[KRShader::KRENGINE_UNIFORM_MODEL_MATRIX], 1, GL_FALSE, matModel.getPointer()));
{
KRMat4 matModelToView2 = KRMat4() * matModel * matView;
GLDEBUG(glUniformMatrix4fv(m_uniforms[KRShader::KRENGINE_UNIFORM_M2V], 1, GL_FALSE, matModelToView2.getPointer()));
KRVector3 view_space_model_origin = KRMat4::Dot(matModelToView2, KRVector3::Zero()); // Origin point of model space is the light source position. No perspective, so no w divide required
GLDEBUG(glUniform3f(
m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_POSITION_VIEW_SPACE],
view_space_model_origin.x,
view_space_model_origin.y,
view_space_model_origin.z
));
KRMat4 matViewToModel = matModelToView2;
matViewToModel.invert();
GLDEBUG(glUniformMatrix4fv(m_uniforms[KRShader::KRENGINE_UNIFORM_V2M], 1, GL_FALSE, matViewToModel.getPointer()));
}
KRVector3 nLightDir = lightDirection; KRVector3 nLightDir = lightDirection;
@@ -284,6 +314,8 @@ bool KRShader::bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2], 4)); GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE2], 4));
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3], 5)); GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_SHADOWTEXTURE3], 5));
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_REFLECTIONCUBETEXTURE], 4));
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_GBUFFER_FRAME], 6)); GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_GBUFFER_FRAME], 6));
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_GBUFFER_DEPTH], 7)); // Texture unit 7 is used for reading the depth buffer in gBuffer pass #2 and in post-processing pass GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_GBUFFER_DEPTH], 7)); // Texture unit 7 is used for reading the depth buffer in gBuffer pass #2 and in post-processing pass

View File

@@ -54,7 +54,7 @@ public:
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
bool bind(KRCamera *pCamera, KRMat4 &matModelToView, KRMat4 &mvpMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass); bool bind(KRCamera *pCamera, KRMat4 &matModel, KRMat4 &matView, KRMat4 &mvpMatrix, KRVector3 &lightDirection, KRMat4 *pShadowMatrices, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass);
#endif #endif
@@ -74,7 +74,6 @@ public:
KRENGINE_UNIFORM_MATERIAL_REFLECTION, KRENGINE_UNIFORM_MATERIAL_REFLECTION,
KRENGINE_UNIFORM_MATERIAL_ALPHA, KRENGINE_UNIFORM_MATERIAL_ALPHA,
KRENGINE_UNIFORM_MATERIAL_SHININESS, KRENGINE_UNIFORM_MATERIAL_SHININESS,
KRENGINE_UNIFORM_MATERIAL_REFLECTIVITY,
KRENGINE_UNIFORM_LIGHT_POSITION, KRENGINE_UNIFORM_LIGHT_POSITION,
KRENGINE_UNIFORM_LIGHT_POSITION_VIEW_SPACE, KRENGINE_UNIFORM_LIGHT_POSITION_VIEW_SPACE,
@@ -91,14 +90,16 @@ public:
KRENGINE_UNIFORM_INVP, KRENGINE_UNIFORM_INVP,
KRENGINE_UNIFORM_INVMVP, KRENGINE_UNIFORM_INVMVP,
KRENGINE_UNIFORM_INVMVP_NO_TRANSLATE, KRENGINE_UNIFORM_INVMVP_NO_TRANSLATE,
KRENGINE_UNIFORM_MN2V, KRENGINE_UNIFORM_MODEL_VIEW_INVERSE_TRANSPOSE,
KRENGINE_UNIFORM_M2V, KRENGINE_UNIFORM_M2V,
KRENGINE_UNIFORM_V2M, KRENGINE_UNIFORM_V2M,
KRENGINE_UNIFORM_MODEL_MATRIX,
KRENGINE_UNIFORM_CAMERAPOS, KRENGINE_UNIFORM_CAMERAPOS,
KRENGINE_UNIFORM_VIEWPORT, KRENGINE_UNIFORM_VIEWPORT,
KRENGINE_UNIFORM_DIFFUSETEXTURE, KRENGINE_UNIFORM_DIFFUSETEXTURE,
KRENGINE_UNIFORM_SPECULARTEXTURE, KRENGINE_UNIFORM_SPECULARTEXTURE,
KRENGINE_UNIFORM_REFLECTIONCUBETEXTURE,
KRENGINE_UNIFORM_REFLECTIONTEXTURE, KRENGINE_UNIFORM_REFLECTIONTEXTURE,
KRENGINE_UNIFORM_NORMALTEXTURE, KRENGINE_UNIFORM_NORMALTEXTURE,
KRENGINE_UNIFORM_DIFFUSETEXTURE_SCALE, KRENGINE_UNIFORM_DIFFUSETEXTURE_SCALE,

View File

@@ -45,15 +45,11 @@ KRShaderManager::~KRShaderManager() {
} }
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, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass) { KRShader *KRShaderManager::getShader(std::string shader_name, KRCamera *pCamera, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, int iShadowQuality, 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) {
char szKey[256]; char szKey[256];
sprintf(szKey, "%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, pCamera->bDebugPSSM, iShadowQuality, pCamera->bEnableAmbient, pCamera->bEnableDiffuse, pCamera->bEnableSpecular, bLightMap, bDiffuseMapScale, bSpecMapScale, bNormalMapScale, bDiffuseMapOffset, bSpecMapOffset, bNormalMapOffset, 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_%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, 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);
/*
const char *options = "#define HAS_DIFFUSE_MAP 1\n#define HAS_NORMAL_MAP 0\n#define HAS_SPEC_MAP 0\n#define ENABLE_PER_PIXEL 0\n#define DEBUG_PSSM 0\n#define SHADOW_QUALITY 0\n#define SUN_INTENSITY 1.5\n#define AMBIENT_INTENSITY_R 0.25\n#define AMBIENT_INTENSITY_G 0.25\n#define AMBIENT_INTENSITY_B 0.25\n";
*/
KRShader *pShader = m_shaders[szKey]; KRShader *pShader = m_shaders[szKey];
if(pShader == NULL) { if(pShader == NULL) {
@@ -69,17 +65,27 @@ KRShader *KRShaderManager::getShader(std::string shader_name, KRCamera *pCamera,
stream.precision(std::numeric_limits<long double>::digits10); stream.precision(std::numeric_limits<long double>::digits10);
stream << "#define HAS_DIFFUSE_MAP " << (bDiffuseMap ? "1" : "0"); stream << "#define HAS_DIFFUSE_MAP " << (bDiffuseMap ? "1" : "0");
stream << "\n#define HAS_DIFFUSE_MAP_SCALE " << (bDiffuseMapScale ? "1" : "0");
stream << "\n#define HAS_DIFFUSE_MAP_OFFSET " << (bDiffuseMapOffset ? "1" : "0");
stream << "\n#define HAS_SPEC_MAP " << (bSpecMap ? "1" : "0");
stream << "\n#define HAS_SPEC_MAP_SCALE " << (bSpecMapScale ? "1" : "0");
stream << "\n#define HAS_SPEC_MAP_OFFSET " << (bSpecMapOffset ? "1" : "0");
stream << "\n#define HAS_NORMAL_MAP " << (bNormalMap ? "1" : "0");
stream << "\n#define HAS_NORMAL_MAP_SCALE " << (bNormalMapScale ? "1" : "0");
stream << "\n#define HAS_NORMAL_MAP_OFFSET " << (bNormalMapOffset ? "1" : "0");
stream << "\n#define HAS_REFLECTION_MAP " << (bReflectionMap ? "1" : "0");
stream << "\n#define HAS_REFLECTION_MAP_SCALE " << (bReflectionMapScale ? "1" : "0");
stream << "\n#define HAS_REFLECTION_MAP_OFFSET " << (bReflectionMapOffset ? "1" : "0");
stream << "\n#define HAS_LIGHT_MAP " << (bLightMap ? "1" : "0");
stream << "\n#define HAS_REFLECTION_CUBE_MAP " << (bReflectionCubeMap ? "1" : "0");
stream << "\n#define ALPHA_TEST " << (bAlphaTest ? "1" : "0"); stream << "\n#define ALPHA_TEST " << (bAlphaTest ? "1" : "0");
stream << "\n#define ALPHA_BLEND " << (bAlphaBlend ? "1" : "0"); stream << "\n#define ALPHA_BLEND " << (bAlphaBlend ? "1" : "0");
stream << "\n#define HAS_NORMAL_MAP " << (bNormalMap ? "1" : "0");
stream << "\n#define HAS_SPEC_MAP " << (bSpecMap ? "1" : "0");
stream << "\n#define HAS_LIGHT_MAP " << (bLightMap ? "1" : "0");
stream << "\n#define HAS_NORMAL_MAP_SCALE " << (bNormalMapScale ? "1" : "0");
stream << "\n#define HAS_SPEC_MAP_SCALE " << (bSpecMapScale ? "1" : "0");
stream << "\n#define HAS_DIFFUSE_MAP_SCALE " << (bDiffuseMapScale ? "1" : "0");
stream << "\n#define HAS_NORMAL_MAP_OFFSET " << (bNormalMapOffset ? "1" : "0");
stream << "\n#define HAS_SPEC_MAP_OFFSET " << (bSpecMapOffset ? "1" : "0");
stream << "\n#define HAS_DIFFUSE_MAP_OFFSET " << (bDiffuseMapOffset ? "1" : "0");
stream << "\n#define ENABLE_PER_PIXEL " << (pCamera->bEnablePerPixel ? "1" : "0"); stream << "\n#define ENABLE_PER_PIXEL " << (pCamera->bEnablePerPixel ? "1" : "0");
stream << "\n#define DEBUG_PSSM " << (pCamera->bDebugPSSM ? "1" : "0"); stream << "\n#define DEBUG_PSSM " << (pCamera->bDebugPSSM ? "1" : "0");
stream << "\n#define SHADOW_QUALITY " << iShadowQuality; stream << "\n#define SHADOW_QUALITY " << iShadowQuality;

View File

@@ -57,7 +57,7 @@ public:
const std::string &getVertShaderSource(const std::string &name); const std::string &getVertShaderSource(const std::string &name);
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, bool bAlphaTest, bool bAlphaBlend, KRNode::RenderPass renderPass); KRShader *getShader(std::string shader_name, KRCamera *pCamera, bool bDiffuseMap, bool bNormalMap, bool bSpecMap, bool bReflectionMap, bool bReflectionCubeMap, int iShadowQuality, 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(); long getShaderHandlesUsed();

View File

@@ -31,8 +31,8 @@
#define KRENGINE_MAX_TEXTURE_UNITS 8 #define KRENGINE_MAX_TEXTURE_UNITS 8
#define KRENGINE_MAX_TEXTURE_HANDLES 10000 #define KRENGINE_MAX_TEXTURE_HANDLES 10000
#define KRENGINE_MAX_TEXTURE_MEM 96000000 #define KRENGINE_MAX_TEXTURE_MEM 64000000
#define KRENGINE_TARGET_TEXTURE_MEM_MAX 64000000 #define KRENGINE_TARGET_TEXTURE_MEM_MAX 48000000
#define KRENGINE_TARGET_TEXTURE_MEM_MIN 32000000 #define KRENGINE_TARGET_TEXTURE_MEM_MIN 32000000
#define KRENGINE_MAX_TEXTURE_DIM 2048 #define KRENGINE_MAX_TEXTURE_DIM 2048
#define KRENGINE_MIN_TEXTURE_DIM 64 #define KRENGINE_MIN_TEXTURE_DIM 64

View File

@@ -290,3 +290,8 @@ bool KRVector3::operator <(const KRVector3& b) const
return false; return false;
} }
} }
void KRVector3::setUniform(GLint location) const
{
GLDEBUG(glUniform3f(location, x, y, z));
}

View File

@@ -91,6 +91,8 @@ public:
static KRVector3 Lerp(const KRVector3 &v1, const KRVector3 &v2, float d); static KRVector3 Lerp(const KRVector3 &v1, const KRVector3 &v2, float d);
static KRVector3 Slerp(const KRVector3 &v1, const KRVector3 &v2, float d); static KRVector3 Slerp(const KRVector3 &v1, const KRVector3 &v2, float d);
static void OrthoNormalize(KRVector3 &normal, KRVector3 &tangent); // Gram-Schmidt Orthonormalization static void OrthoNormalize(KRVector3 &normal, KRVector3 &tangent); // Gram-Schmidt Orthonormalization
void setUniform(GLint location) const;
}; };
#endif #endif

View File

@@ -33,7 +33,7 @@
varying mediump vec3 normal; varying mediump vec3 normal;
#endif #endif
#if HAS_DIFFUSE_MAP == 1 || HAS_NORMAL_MAP == 1 || HAS_SPEC_MAP == 1 #if HAS_DIFFUSE_MAP == 1 || HAS_NORMAL_MAP == 1 || HAS_SPEC_MAP == 1 || HAS_REFLECTION_MAP == 1
varying highp vec2 texCoord; varying highp vec2 texCoord;
#endif #endif
#if HAS_NORMAL_MAP_OFFSET == 1 || HAS_NORMAL_MAP_SCALE == 1 #if HAS_NORMAL_MAP_OFFSET == 1 || HAS_NORMAL_MAP_SCALE == 1
@@ -57,7 +57,7 @@
#if HAS_NORMAL_MAP == 1 #if HAS_NORMAL_MAP == 1
varying highp mat3 tangent_to_view_matrix; varying highp mat3 tangent_to_view_matrix;
#else #else
uniform highp mat4 model_normal_to_view_matrix; uniform highp mat4 model_view_inverse_transpose_matrix;
#endif #endif
#if HAS_DIFFUSE_MAP == 1 && ALPHA_TEST == 1 #if HAS_DIFFUSE_MAP == 1 && ALPHA_TEST == 1
@@ -72,6 +72,7 @@
uniform lowp vec3 material_ambient, material_diffuse, material_specular; uniform lowp vec3 material_ambient, material_diffuse, material_specular;
uniform lowp float material_alpha; uniform lowp float material_alpha;
#if HAS_DIFFUSE_MAP == 1 #if HAS_DIFFUSE_MAP == 1
uniform sampler2D diffuseTexture; uniform sampler2D diffuseTexture;
#endif #endif
@@ -80,6 +81,22 @@
uniform sampler2D specularTexture; uniform sampler2D specularTexture;
#endif #endif
#if HAS_REFLECTION_MAP == 1
uniform sampler2D reflectionTexture;
#endif
#if HAS_REFLECTION_CUBE_MAP == 1
uniform lowp vec3 material_reflection;
uniform samplerCube reflectionCubeTexture;
#if HAS_NORMAL_MAP == 1
varying mediump vec3 eyeVec;
uniform highp mat4 model_matrix;
#else
varying mediump vec3 reflectionVec;
#endif
#endif
#if SHADOW_QUALITY >= 1 #if SHADOW_QUALITY >= 1
uniform sampler2D shadowTexture1; uniform sampler2D shadowTexture1;
varying highp vec4 shadowMapCoord1; varying highp vec4 shadowMapCoord1;
@@ -114,6 +131,12 @@
#define spec_uv texCoord #define spec_uv texCoord
#endif #endif
#if (HAS_REFLECTION_MAP_OFFSET == 1|| HAS_REFLECTION_MAP_SCALE == 1) && ENABLE_PER_PIXEL == 1
varying mediump vec2 reflection_uv;
#else
#define reflection_uv texCoord
#endif
#if HAS_DIFFUSE_MAP_OFFSET == 1 || HAS_DIFFUSE_MAP_SCALE == 1 #if HAS_DIFFUSE_MAP_OFFSET == 1 || HAS_DIFFUSE_MAP_SCALE == 1
varying highp vec2 diffuse_uv; varying highp vec2 diffuse_uv;
#else #else
@@ -123,7 +146,7 @@
#endif #endif
#if GBUFFER_PASS == 1 || GBUFFER_PASS == 3 #if GBUFFER_PASS == 1 || GBUFFER_PASS == 3
uniform mediump vec4 viewport; uniform mediump vec4 viewport;
#endif #endif
void main() void main()
@@ -133,7 +156,7 @@ void main()
if(diffuseMaterial.a < 0.5) discard; if(diffuseMaterial.a < 0.5) discard;
#endif #endif
#if GBUFFER_PASS == 1 && ALPHA_TEST #if GBUFFER_PASS == 1 && ALPHA_TEST == 1
if(texture2D(diffuseTexture, diffuse_uv).a < 0.5) discard; if(texture2D(diffuseTexture, diffuse_uv).a < 0.5) discard;
#endif #endif
@@ -153,12 +176,12 @@ void main()
mediump vec3 normal = normalize(2.0 * texture2D(normalTexture,normal_uv).rgb - 1.0); mediump vec3 normal = normalize(2.0 * texture2D(normalTexture,normal_uv).rgb - 1.0);
mediump vec3 view_space_normal = tangent_to_view_matrix * normal; mediump vec3 view_space_normal = tangent_to_view_matrix * normal;
#else #else
mediump vec3 view_space_normal = vec3(model_normal_to_view_matrix * vec4(normal, 1.0)); mediump vec3 view_space_normal = vec3(model_view_inverse_transpose_matrix * vec4(normal, 1.0));
#endif #endif
gl_FragColor = vec4(view_space_normal * 0.5 + 0.5, material_shininess / 100.0); gl_FragColor = vec4(view_space_normal * 0.5 + 0.5, material_shininess / 100.0);
#else #else
#if HAS_DIFFUSE_MAP == 1 #if HAS_DIFFUSE_MAP == 1
#if ALPHA_TEST #if ALPHA_TEST == 1
diffuseMaterial.a = 1.0; diffuseMaterial.a = 1.0;
#else #else
mediump vec4 diffuseMaterial = texture2D(diffuseTexture, diffuse_uv); mediump vec4 diffuseMaterial = texture2D(diffuseTexture, diffuse_uv);
@@ -247,21 +270,33 @@ void main()
#endif #endif
#endif #endif
#if ENABLE_AMBIENT #if ENABLE_AMBIENT == 1
// -------------------- Add ambient light and alpha component -------------------- // -------------------- Add ambient light and alpha component --------------------
gl_FragColor = vec4(vec3(diffuseMaterial) * material_ambient, 0.0); gl_FragColor = vec4(vec3(diffuseMaterial) * material_ambient, 0.0);
#else #else
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0); gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
#endif #endif
#if ENABLE_DIFFUSE #if ENABLE_DIFFUSE == 1
// -------------------- Add diffuse light -------------------- // -------------------- Add diffuse light --------------------
gl_FragColor += diffuseMaterial * vec4(material_diffuse, 1.0) * vec4(vec3(lamberFactor), 1.0); gl_FragColor += diffuseMaterial * vec4(material_diffuse, 1.0) * vec4(vec3(lamberFactor), 1.0);
//gl_FragColor += vec4(vec3(diffuseMaterial) * material_diffuse * lamberFactor, 0.0);
#endif #endif
#if ENABLE_SPECULAR #if HAS_REFLECTION_CUBE_MAP == 1
// -------------------- Add reflected light --------------------
#if HAS_NORMAL_MAP == 1
// Calculate reflection vector as I - 2.0 * dot(N, I) * N
mediump vec3 normalizedEyeVec = normalize(eyeVec);
mediump vec3 reflectionVec = mat3(model_matrix) * (normalizedEyeVec - 2.0 * dot(normal, normalizedEyeVec) * normal);
#endif
#if HAS_REFLECTION_MAP == 1
gl_FragColor += vec4(material_reflection, 0.0) * texture2D(reflectionTexture, reflection_uv) * textureCube(reflectionCubeTexture, reflectionVec);
#else
gl_FragColor += vec4(material_reflection, 0.0) * textureCube(reflectionCubeTexture, reflectionVec);
#endif
#endif
#if ENABLE_SPECULAR == 1
// -------------------- Add specular light -------------------- // -------------------- Add specular light --------------------
#if HAS_SPEC_MAP == 1 && ENABLE_PER_PIXEL == 1 #if HAS_SPEC_MAP == 1 && ENABLE_PER_PIXEL == 1
@@ -272,13 +307,13 @@ void main()
#endif #endif
#if ALPHA_BLEND #if ALPHA_BLEND == 1
gl_FragColor.a = gl_FragColor.a * material_alpha; gl_FragColor.a = gl_FragColor.a * material_alpha;
#endif #endif
// -------------------- Multiply light map -------------------- // -------------------- Multiply light map --------------------
#if HAS_LIGHT_MAP #if HAS_LIGHT_MAP == 1
mediump vec3 lightMapColor = vec3(texture2D(shadowTexture1, lightmap_uv)); mediump vec3 lightMapColor = vec3(texture2D(shadowTexture1, lightmap_uv));
gl_FragColor = vec4(gl_FragColor.r * lightMapColor.r, gl_FragColor.g * lightMapColor.g, gl_FragColor.b * lightMapColor.b, gl_FragColor.a); gl_FragColor = vec4(gl_FragColor.r * lightMapColor.r, gl_FragColor.g * lightMapColor.g, gl_FragColor.b * lightMapColor.b, gl_FragColor.a);
#endif #endif

View File

@@ -34,7 +34,7 @@ attribute mediump vec2 vertex_uv;
uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying the model, view, and projection matrices uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying the model, view, and projection matrices
#if ENABLE_PER_PIXEL == 1 || GBUFFER_PASS == 1 #if ENABLE_PER_PIXEL == 1 || GBUFFER_PASS == 1
#if HAS_DIFFUSE_MAP == 1 || HAS_NORMAL_MAP == 1 || HAS_SPEC_MAP == 1 #if HAS_DIFFUSE_MAP == 1 || HAS_NORMAL_MAP == 1 || HAS_SPEC_MAP == 1 || HAS_REFLECTION_MAP == 1
varying highp vec2 texCoord; varying highp vec2 texCoord;
#endif #endif
#if HAS_NORMAL_MAP == 1 #if HAS_NORMAL_MAP == 1
@@ -61,7 +61,7 @@ uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying t
#if GBUFFER_PASS == 1 #if GBUFFER_PASS == 1
#if HAS_NORMAL_MAP == 1 #if HAS_NORMAL_MAP == 1
uniform highp mat4 model_normal_to_view_matrix; uniform highp mat4 model_view_inverse_transpose_matrix;
varying highp mat3 tangent_to_view_matrix; varying highp mat3 tangent_to_view_matrix;
#endif #endif
#else #else
@@ -90,6 +90,18 @@ uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying t
uniform highp vec2 specularTexture_Offset; uniform highp vec2 specularTexture_Offset;
#endif #endif
#if HAS_REFLECTION_MAP_OFFSET == 1 || HAS_REFLECTION_MAP_SCALE == 1
varying highp vec2 reflection_uv;
#endif
#if HAS_REFLECTION_MAP_SCALE == 1
uniform highp vec2 reflection_Scale;
#endif
#if HAS_REFLECTION_MAP_OFFSET == 1
uniform highp vec2 reflection_Offset;
#endif
#if SHADOW_QUALITY >= 1 #if SHADOW_QUALITY >= 1
uniform highp mat4 shadow_mvp1; uniform highp mat4 shadow_mvp1;
varying highp vec4 shadowMapCoord1; varying highp vec4 shadowMapCoord1;
@@ -110,6 +122,16 @@ uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying t
varying mediump float specularFactor; varying mediump float specularFactor;
#endif #endif
#if HAS_REFLECTION_CUBE_MAP == 1
#if HAS_NORMAL_MAP == 1
varying mediump vec3 eyeVec;
#else
uniform highp mat4 model_matrix;
varying mediump vec3 reflectionVec;
#endif
#endif
#if HAS_DIFFUSE_MAP_SCALE == 1 #if HAS_DIFFUSE_MAP_SCALE == 1
uniform highp vec2 diffuseTexture_Scale; uniform highp vec2 diffuseTexture_Scale;
#endif #endif
@@ -131,12 +153,14 @@ void main()
// Transform position // Transform position
gl_Position = mvp_matrix * vec4(vertex_position,1.0); gl_Position = mvp_matrix * vec4(vertex_position,1.0);
#if HAS_DIFFUSE_MAP == 1 || (HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1) || (HAS_SPEC_MAP == 1 && ENABLE_PER_PIXEL == 1) #if HAS_DIFFUSE_MAP == 1 || (HAS_NORMAL_MAP == 1 && ENABLE_PER_PIXEL == 1) || (HAS_SPEC_MAP == 1 && ENABLE_PER_PIXEL == 1) || (HAS_REFLECTION_MAP == 1 && ENABLE_PER_PIXEL == 1)
// Pass UV co-ordinates // Pass UV co-ordinates
texCoord = vertex_uv.st; texCoord = vertex_uv.st;
#endif #endif
// Scaled and translated normal map UV's // Scaled and translated normal map UV's
#if (HAS_NORMAL_MAP_OFFSET == 1 || HAS_NORMAL_MAP_SCALE == 1) && ENABLE_PER_PIXEL == 1 #if (HAS_NORMAL_MAP_OFFSET == 1 || HAS_NORMAL_MAP_SCALE == 1) && ENABLE_PER_PIXEL == 1
normal_uv = texCoord; normal_uv = texCoord;
@@ -170,13 +194,25 @@ void main()
#if GBUFFER_PASS == 1 #if GBUFFER_PASS == 1
#if HAS_NORMAL_MAP == 1 #if HAS_NORMAL_MAP == 1
mediump vec3 a_bitangent = cross(vertex_normal, vertex_tangent); mediump vec3 a_bitangent = cross(vertex_normal, vertex_tangent);
tangent_to_view_matrix[0] = vec3(model_normal_to_view_matrix * vec4(vertex_tangent, 1.0)); tangent_to_view_matrix[0] = vec3(model_view_inverse_transpose_matrix * vec4(vertex_tangent, 1.0));
tangent_to_view_matrix[1] = vec3(model_normal_to_view_matrix * vec4(a_bitangent, 1.0)); tangent_to_view_matrix[1] = vec3(model_view_inverse_transpose_matrix * vec4(a_bitangent, 1.0));
tangent_to_view_matrix[2] = vec3(model_normal_to_view_matrix * vec4(vertex_normal, 1.0)); tangent_to_view_matrix[2] = vec3(model_view_inverse_transpose_matrix * vec4(vertex_normal, 1.0));
#else #else
normal = vertex_normal; normal = vertex_normal;
#endif #endif
#else #else
#if HAS_REFLECTION_CUBE_MAP == 1
#if HAS_NORMAL_MAP == 1
eyeVec = normalize(cameraPosition - vertex_position);
#else
// Calculate reflection vector as I - 2.0 * dot(N, I) * N
mediump vec3 eyeVec = normalize(cameraPosition - vertex_position);
reflectionVec = mat3(model_matrix) * (eyeVec - 2.0 * dot(vertex_normal, eyeVec) * vertex_normal);
#endif
#endif
#if HAS_LIGHT_MAP == 1 #if HAS_LIGHT_MAP == 1
// Pass shadow UV co-ordinates // Pass shadow UV co-ordinates
lightmap_uv = vertex_lightmap_uv.st; lightmap_uv = vertex_lightmap_uv.st;
@@ -197,6 +233,18 @@ void main()
#endif #endif
#endif #endif
// Scaled and translated reflection map UV's
#if HAS_REFLECTION_MAP_OFFSET == 1 || HAS_REFLECTION_MAP_SCALE == 1
reflection_uv = texCoord;
#if HAS_REFLECTION_MAP_OFFSET == 1
reflection_uv + reflectionTexture_Offset;
#endif
#if HAS_REFLECTION_MAP_SCALE == 1
reflection_uv *= reflectionTexture_Scale;
#endif
#endif
#if SHADOW_QUALITY >= 1 #if SHADOW_QUALITY >= 1
shadowMapCoord1 = shadow_mvp1 * vec4(vertex_position,1.0); shadowMapCoord1 = shadow_mvp1 * vec4(vertex_position,1.0);
@@ -214,7 +262,10 @@ void main()
#if HAS_NORMAL_MAP == 1 #if HAS_NORMAL_MAP == 1
// ----- Calculate per-pixel lighting in tangent space, for normal mapping ------ // ----- Calculate per-pixel lighting in tangent space, for normal mapping ------
mediump vec3 a_bitangent = cross(vertex_normal, vertex_tangent); mediump vec3 a_bitangent = cross(vertex_normal, vertex_tangent);
mediump vec3 eyeVec = normalize(cameraPosition - vertex_position); #if HAS_REFLECTION_CUBE_MAP == 0
// The cube map reflections also require an eyeVec as a varying attribute when normal mapping, so only re-calculate here when needed
mediump vec3 eyeVec = normalize(cameraPosition - vertex_position);
#endif
lightVec = normalize(vec3(dot(light_direction, vertex_tangent), dot(light_direction, a_bitangent), dot(light_direction, vertex_normal))); lightVec = normalize(vec3(dot(light_direction, vertex_tangent), dot(light_direction, a_bitangent), dot(light_direction, vertex_normal)));
halfVec = normalize(vec3(dot(eyeVec, vertex_tangent), dot(eyeVec, a_bitangent), dot(eyeVec, vertex_normal))); halfVec = normalize(vec3(dot(eyeVec, vertex_tangent), dot(eyeVec, a_bitangent), dot(eyeVec, vertex_normal)));

View File

@@ -37,7 +37,7 @@ uniform mediump vec4 viewport;
uniform highp mat4 inv_projection_matrix; uniform highp mat4 inv_projection_matrix;
uniform highp vec3 view_space_light_position; uniform highp vec3 view_space_model_origin; // For point lights, this is the position of the light
void main() void main()
{ {
@@ -58,9 +58,9 @@ void main()
mediump vec4 view_space_vertex_position = inv_projection_matrix * clip_space_vertex_position; mediump vec4 view_space_vertex_position = inv_projection_matrix * clip_space_vertex_position;
view_space_vertex_position.xyz /= view_space_vertex_position.w; 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_distance = max(0.0, distance(view_space_model_origin.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 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 vec3 light_vec = normalize(view_space_model_origin.xyz - view_space_vertex_position.xyz);
mediump float lamberFactor = dot(light_vec, gbuffer_normal) * 0.2; mediump float lamberFactor = dot(light_vec, gbuffer_normal) * 0.2;
mediump float specularFactor = 0.0; mediump float specularFactor = 0.0;

View File

@@ -37,7 +37,7 @@ uniform mediump vec4 viewport;
uniform highp mat4 inv_projection_matrix; uniform highp mat4 inv_projection_matrix;
uniform highp vec3 view_space_light_position; uniform highp vec3 view_space_model_origin;
void main() void main()
{ {
@@ -58,9 +58,9 @@ void main()
mediump vec4 view_space_vertex_position = inv_projection_matrix * clip_space_vertex_position; mediump vec4 view_space_vertex_position = inv_projection_matrix * clip_space_vertex_position;
view_space_vertex_position.xyz /= view_space_vertex_position.w; 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_distance = max(0.0, distance(view_space_model_origin.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 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 vec3 light_vec = normalize(view_space_model_origin.xyz - view_space_vertex_position.xyz);
mediump float lamberFactor = dot(light_vec, gbuffer_normal) * 0.2; mediump float lamberFactor = dot(light_vec, gbuffer_normal) * 0.2;
mediump float specularFactor = 0.0; mediump float specularFactor = 0.0;