Exposed volumetric environment effect parameters

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40155
This commit is contained in:
kearwood
2012-11-14 21:46:30 +00:00
parent 1d22aa189d
commit 50fc0a0533
19 changed files with 177 additions and 330 deletions

View File

@@ -36,10 +36,6 @@
E43B0AD715DDCA0F00A5CB9F /* KRContextObject.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E43B0AD415DDCA0C00A5CB9F /* KRContextObject.cpp */; };
E43B0AD815DDCA0F00A5CB9F /* KRContextObject.h in Headers */ = {isa = PBXBuildFile; fileRef = E43B0AD515DDCA0D00A5CB9F /* KRContextObject.h */; };
E43B0AD915DDCA0F00A5CB9F /* KRContextObject.h in Headers */ = {isa = PBXBuildFile; fileRef = E43B0AD515DDCA0D00A5CB9F /* KRContextObject.h */; settings = {ATTRIBUTES = (Public, ); }; };
E443C5FE164B120A00FC4FD8 /* KRVolumetricFog.h in Headers */ = {isa = PBXBuildFile; fileRef = E443C5FD164B120900FC4FD8 /* KRVolumetricFog.h */; };
E443C5FF164B120A00FC4FD8 /* KRVolumetricFog.h in Headers */ = {isa = PBXBuildFile; fileRef = E443C5FD164B120900FC4FD8 /* KRVolumetricFog.h */; };
E443C602164B122C00FC4FD8 /* KRVolumetricFog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E443C601164B122C00FC4FD8 /* KRVolumetricFog.cpp */; };
E443C603164B122C00FC4FD8 /* KRVolumetricFog.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E443C601164B122C00FC4FD8 /* KRVolumetricFog.cpp */; };
E461A152152E54B500F2044A /* KRLight.h in Headers */ = {isa = PBXBuildFile; fileRef = E461A151152E54B500F2044A /* KRLight.h */; };
E461A153152E54B500F2044A /* KRLight.h in Headers */ = {isa = PBXBuildFile; fileRef = E461A151152E54B500F2044A /* KRLight.h */; settings = {ATTRIBUTES = (Public, ); }; };
E461A156152E54F800F2044A /* KRLight.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E461A155152E54F700F2044A /* KRLight.cpp */; };
@@ -234,8 +230,6 @@
E4324BAD16444E120043185B /* KRParticleSystemBrownian.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRParticleSystemBrownian.cpp; path = Classes/KRParticleSystemBrownian.cpp; sourceTree = "<group>"; };
E43B0AD415DDCA0C00A5CB9F /* KRContextObject.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRContextObject.cpp; path = Classes/KRContextObject.cpp; sourceTree = "<group>"; };
E43B0AD515DDCA0D00A5CB9F /* KRContextObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRContextObject.h; path = Classes/KRContextObject.h; sourceTree = "<group>"; };
E443C5FD164B120900FC4FD8 /* KRVolumetricFog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = KRVolumetricFog.h; path = Classes/KRVolumetricFog.h; sourceTree = "<group>"; };
E443C601164B122C00FC4FD8 /* KRVolumetricFog.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = KRVolumetricFog.cpp; path = Classes/KRVolumetricFog.cpp; sourceTree = "<group>"; };
E443C612164B5BE500FC4FD8 /* volumetric_fog.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = volumetric_fog.fsh; path = Shaders/volumetric_fog.fsh; sourceTree = "<group>"; };
E443C615164B5BFB00FC4FD8 /* volumetric_fog.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = volumetric_fog.vsh; path = Shaders/volumetric_fog.vsh; sourceTree = "<group>"; };
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; };
@@ -587,8 +581,6 @@
E461A171152E599E00F2044A /* Lights */,
E4F975311536220900FD60B2 /* KRNode.h */,
E4F975351536221C00FD60B2 /* KRNode.cpp */,
E443C5FD164B120900FC4FD8 /* KRVolumetricFog.h */,
E443C601164B122C00FC4FD8 /* KRVolumetricFog.cpp */,
);
name = "Scene Graph Nodes";
sourceTree = "<group>";
@@ -772,7 +764,6 @@
E4CA11741639CBD6005D9400 /* KRViewport.h in Headers */,
E4324BA416444C0D0043185B /* KRParticleSystem.h in Headers */,
E4324BAB16444DEF0043185B /* KRParticleSystemBrownian.h in Headers */,
E443C5FE164B120A00FC4FD8 /* KRVolumetricFog.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -827,7 +818,6 @@
E461A169152E570700F2044A /* KRSpotLight.h in Headers */,
E4324BA516444C0D0043185B /* KRParticleSystem.h in Headers */,
E4324BAC16444DEF0043185B /* KRParticleSystemBrownian.h in Headers */,
E443C5FF164B120A00FC4FD8 /* KRVolumetricFog.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -955,7 +945,6 @@
E4CA11781639CC90005D9400 /* KRViewport.cpp in Sources */,
E4324BA816444C230043185B /* KRParticleSystem.cpp in Sources */,
E4324BAE16444E120043185B /* KRParticleSystemBrownian.cpp in Sources */,
E443C602164B122C00FC4FD8 /* KRVolumetricFog.cpp in Sources */,
E431C1B8164DB7B200BE1575 /* volumetric_fog_downsampled.fsh in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
@@ -1007,7 +996,6 @@
E4CA11791639CC90005D9400 /* KRViewport.cpp in Sources */,
E4324BAF16444E120043185B /* KRParticleSystemBrownian.cpp in Sources */,
E4324BB0164458930043185B /* KRParticleSystem.cpp in Sources */,
E443C603164B122C00FC4FD8 /* KRVolumetricFog.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@@ -45,7 +45,8 @@ KRCamera::KRCamera(KRContext &context) : KRContextObject(context) {
m_particlesAbsoluteTime = 0.0f;
backingWidth = 0;
backingHeight = 0;
volumetricBufferWidth = 0;
volumetricBufferHeight = 0;
float const PI = 3.141592653589793f;
float const D2R = PI * 2 / 360;
@@ -114,7 +115,13 @@ KRCamera::KRCamera(KRContext &context) : KRContextObject(context) {
m_skyBoxName = "";
m_pSkyBoxTexture = NULL;
volumetric_light_downsample = 8;
volumetric_environment_enable = false;
volumetric_environment_downsample = 2;
volumetric_environment_max_distance = 1000.0f;
volumetric_environment_quality = (50 - 5.0) / 495.0f;
volumetric_environment_intensity = 1.0f;
invalidateShadowBuffers();
}
@@ -442,9 +449,9 @@ void KRCamera::renderFrame(KRScene &scene, KRVector3 &lightDirection, float delt
// ----====---- Volumetric Lighting ----====----
if(m_cShadowBuffers >= 1) {
if(m_cShadowBuffers >= 1 && volumetric_environment_enable) {
if(volumetric_light_downsample != 1) {
if(volumetric_environment_downsample != 0) {
// Set render target
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, volumetricLightAccumulationBuffer));
GLDEBUG(glClearColor(0.0f, 0.0f, 0.0f, 0.0f));
@@ -463,27 +470,30 @@ void KRCamera::renderFrame(KRScene &scene, KRVector3 &lightDirection, float delt
GLDEBUG(glDepthRangef(0.0, 1.0));
}
KRShader *pFogShader = m_pContext->getShaderManager()->getShader(volumetric_light_downsample != 1 ? "volumetric_fog_downsampled" : "volumetric_fog", this, false, false, false, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_ADDITIVE_PARTICLES);
std::string shader_name = volumetric_environment_downsample != 0 ? "volumetric_fog_downsampled" : "volumetric_fog";
KRViewport volumetricLightingViewport = KRViewport(m_viewport.getSize() / volumetric_light_downsample, m_viewport.getViewMatrix(), m_viewport.getProjectionMatrix());
KRShader *pFogShader = m_pContext->getShaderManager()->getShader(shader_name, this, false, false, false, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_ADDITIVE_PARTICLES);
KRViewport volumetricLightingViewport = KRViewport(KRVector2(volumetricBufferWidth, volumetricBufferHeight), m_viewport.getViewMatrix(), m_viewport.getProjectionMatrix());
glViewport(0, 0, volumetricLightingViewport.getSize().x, volumetricLightingViewport.getSize().y);
if(pFogShader->bind(volumetricLightingViewport, m_shadowViewports, KRMat4(), lightDirection, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_ADDITIVE_PARTICLES)) {
int slice_count = 50;
int slice_count = (int)(volumetric_environment_quality * 495.0) + 5;
float slice_near = -100.0;
float slice_far = -1000.0;
float slice_near = -getPerspectiveNearZ();
float slice_far = -volumetric_environment_max_distance;
float slice_spacing = (slice_far - slice_near) / slice_count;
KRVector2(slice_near, slice_spacing).setUniform(pFogShader->m_uniforms[KRShader::KRENGINE_UNIFORM_SLICE_DEPTH_SCALE]);
(KRVector3::One() * volumetric_environment_intensity * -slice_spacing / 1000.0f).setUniform(pFogShader->m_uniforms[KRShader::KRENGINE_UNIFORM_LIGHT_COLOR]);
m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getVolumetricLightingVertexes(), slice_count * 6 * sizeof(KRModelManager::VolumetricLightingVertexData), true, false, false, false, false);
m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getVolumetricLightingVertexes(), KRModelManager::MAX_VOLUMETRIC_PLANES * 6 * sizeof(KRModelManager::VolumetricLightingVertexData), true, false, false, false, false);
GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, slice_count*6));
}
if(volumetric_light_downsample != 1) {
if(volumetric_environment_downsample != 0) {
// Set render target
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer));
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0));
@@ -544,8 +554,32 @@ void KRCamera::createBuffers() {
if(renderBufferWidth != backingWidth || renderBufferHeight != backingHeight) {
backingWidth = renderBufferWidth;
backingHeight = renderBufferHeight;
if (compositeDepthTexture) {
GLDEBUG(glDeleteTextures(1, &compositeDepthTexture));
compositeDepthTexture = 0;
}
if (compositeColorTexture) {
GLDEBUG(glDeleteTextures(1, &compositeColorTexture));
compositeColorTexture = 0;
}
if (lightAccumulationTexture) {
GLDEBUG(glDeleteTextures(1, &lightAccumulationTexture));
lightAccumulationTexture = 0;
}
if (compositeFramebuffer) {
GLDEBUG(glDeleteFramebuffers(1, &compositeFramebuffer));
compositeFramebuffer = 0;
}
if (lightAccumulationBuffer) {
GLDEBUG(glDeleteFramebuffers(1, &lightAccumulationBuffer));
lightAccumulationBuffer = 0;
}
destroyBuffers();
// ===== Create offscreen compositing framebuffer object =====
GLDEBUG(glGenFramebuffers(1, &compositeFramebuffer));
@@ -586,24 +620,47 @@ void KRCamera::createBuffers() {
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); // This is necessary for non-power-of-two textures
GLDEBUG(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, backingWidth, backingHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL));
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, lightAccumulationTexture, 0));
// ===== Create offscreen compositing framebuffer object for volumetric lighting =====
GLDEBUG(glGenFramebuffers(1, &volumetricLightAccumulationBuffer));
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, volumetricLightAccumulationBuffer));
// ----- Create texture color buffer for compositeFramebuffer for volumetric lighting -----
GLDEBUG(glGenTextures(1, &volumetricLightAccumulationTexture));
GLDEBUG(glBindTexture(GL_TEXTURE_2D, volumetricLightAccumulationTexture));
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); // This is necessary for non-power-of-two textures
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); // This is necessary for non-power-of-two textures
GLDEBUG(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, backingWidth / volumetric_light_downsample, backingHeight / volumetric_light_downsample, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL));
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, volumetricLightAccumulationTexture, 0));
allocateShadowBuffers(m_cShadowBuffers);
}
int targetVolumetricBufferWidth = 0;
int targetVolumetricBufferHeight = 0;
if(m_cShadowBuffers >= 1 && volumetric_environment_enable) {
targetVolumetricBufferWidth = renderBufferWidth >> volumetric_environment_downsample;
targetVolumetricBufferHeight = renderBufferHeight >> volumetric_environment_downsample;
}
if(targetVolumetricBufferWidth != volumetricBufferWidth || targetVolumetricBufferHeight != volumetricBufferHeight) {
volumetricBufferWidth = targetVolumetricBufferWidth;
volumetricBufferHeight = targetVolumetricBufferHeight;
if (volumetricLightAccumulationTexture) {
GLDEBUG(glDeleteTextures(1, &volumetricLightAccumulationTexture));
volumetricLightAccumulationTexture = 0;
}
if (volumetricLightAccumulationBuffer) {
GLDEBUG(glDeleteFramebuffers(1, &volumetricLightAccumulationBuffer));
volumetricLightAccumulationBuffer = 0;
}
if(targetVolumetricBufferWidth != 0 && targetVolumetricBufferHeight != 0) {
// ===== Create offscreen compositing framebuffer object for volumetric lighting =====
GLDEBUG(glGenFramebuffers(1, &volumetricLightAccumulationBuffer));
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, volumetricLightAccumulationBuffer));
// ----- Create texture color buffer for compositeFramebuffer for volumetric lighting -----
GLDEBUG(glGenTextures(1, &volumetricLightAccumulationTexture));
GLDEBUG(glBindTexture(GL_TEXTURE_2D, volumetricLightAccumulationTexture));
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); // This is necessary for non-power-of-two textures
GLDEBUG(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); // This is necessary for non-power-of-two textures
GLDEBUG(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, volumetricBufferWidth, volumetricBufferHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL));
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, volumetricLightAccumulationTexture, 0));
}
}
allocateShadowBuffers(m_cShadowBuffers);
}
void KRCamera::allocateShadowBuffers(int cBuffers) {
@@ -780,7 +837,7 @@ void KRCamera::renderPost()
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, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
postShader->bind(m_viewport, m_shadowViewports, KRMat4(), KRVector3(), NULL, 0, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
postShader->bind(m_viewport, m_shadowViewports, KRMat4(), KRVector3(), shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
m_pContext->getTextureManager()->selectTexture(0, NULL, 0);
GLDEBUG(glActiveTexture(GL_TEXTURE0));
@@ -790,9 +847,11 @@ void KRCamera::renderPost()
GLDEBUG(glActiveTexture(GL_TEXTURE1));
GLDEBUG(glBindTexture(GL_TEXTURE_2D, compositeColorTexture));
m_pContext->getTextureManager()->selectTexture(2, NULL, 0);
GLDEBUG(glActiveTexture(GL_TEXTURE2));
GLDEBUG(glBindTexture(GL_TEXTURE_2D, volumetricLightAccumulationTexture));
if(m_cShadowBuffers >= 1 && volumetric_environment_enable) {
m_pContext->getTextureManager()->selectTexture(2, NULL, 0);
GLDEBUG(glActiveTexture(GL_TEXTURE2));
GLDEBUG(glBindTexture(GL_TEXTURE_2D, volumetricLightAccumulationTexture));
}
// Update attribute values.
m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, true, false, false, true, false);

View File

@@ -44,8 +44,8 @@
#import "KRViewport.h"
#define KRENGINE_MAX_SHADOW_BUFFERS 3
#define KRENGINE_SHADOW_MAP_WIDTH 512
#define KRENGINE_SHADOW_MAP_HEIGHT 512
#define KRENGINE_SHADOW_MAP_WIDTH 4096
#define KRENGINE_SHADOW_MAP_HEIGHT 4096
class KRInstance;
class KRScene;
@@ -57,6 +57,7 @@ public:
virtual ~KRCamera();
GLint backingWidth, backingHeight;
GLint volumetricBufferWidth, volumetricBufferHeight;
void renderFrame(KRScene &scene, KRMat4 &viewMatrix, float deltaTime);
@@ -119,7 +120,12 @@ public:
void setPerspectiveNear(float v);
void setPerpsectiveFarZ(float v);
int volumetric_light_downsample;
bool volumetric_environment_enable;
int volumetric_environment_downsample;
float volumetric_environment_max_distance;
float volumetric_environment_quality;
float volumetric_environment_intensity;
private:
KRVector3 m_position;

View File

@@ -130,7 +130,13 @@ float const PI = 3.141592653589793f;
@"debug_deferred" : @30,
@"enable_deferred_lighting" : @31,
@"near_clip" : @32,
@"far_clip" : @33
@"far_clip" : @33,
@"volumetric_environment_enable" : @34,
@"volumetric_environment_downsample" : @35,
@"volumetric_environment_max_distance" : @36,
@"volumetric_environment_slices" : @37,
@"volumetric_environment_intensity" : @38
} copy];
[self loadShaders];
@@ -190,7 +196,7 @@ float const PI = 3.141592653589793f;
-(int)getParameterCount
{
return 34;
return 39;
}
-(NSString *)getParameterNameWithIndex: (int)i
@@ -200,7 +206,7 @@ float const PI = 3.141592653589793f;
-(NSString *)getParameterLabelWithIndex: (int)i
{
NSString *parameter_labels[34] = {
NSString *parameter_labels[39] = {
@"Camera FOV",
@"Shadow Quality (0 - 2)",
@"Enable per-pixel lighting",
@@ -233,14 +239,19 @@ float const PI = 3.141592653589793f;
@"Debug - Octree Visualize",
@"Debug - Deferred Lights Visualize",
@"Enable Deferred Lighting",
@"Near Clip Plane",
@"Far Clip Plane"
@"Clip Plane - Near",
@"Clip Plane - Far",
@"Volumetric Env. - Enabled",
@"Volumetric Env. - Resolution",
@"Volumetric Env. - Maximum Distance",
@"Volumetric Env. - Quality",
@"Volumetric Env. - Intensity"
};
return parameter_labels[i];
}
-(KREngineParameterType)getParameterTypeWithIndex: (int)i
{
KREngineParameterType types[34] = {
KREngineParameterType types[39] = {
KRENGINE_PARAMETER_FLOAT,
KRENGINE_PARAMETER_INT,
@@ -275,13 +286,18 @@ float const PI = 3.141592653589793f;
KRENGINE_PARAMETER_BOOL,
KRENGINE_PARAMETER_BOOL,
KRENGINE_PARAMETER_FLOAT,
KRENGINE_PARAMETER_FLOAT,
KRENGINE_PARAMETER_BOOL,
KRENGINE_PARAMETER_INT,
KRENGINE_PARAMETER_FLOAT,
KRENGINE_PARAMETER_FLOAT,
KRENGINE_PARAMETER_FLOAT
};
return types[i];
}
-(float)getParameterValueWithIndex: (int)i
{
float values[34] = {
float values[39] = {
_camera->perspective_fov,
(float)_camera->m_cShadowBuffers,
_camera->bEnablePerPixel ? 1.0f : 0.0f,
@@ -315,14 +331,19 @@ float const PI = 3.141592653589793f;
_camera->bShowDeferred ? 1.0f : 0.0f,
_camera->bEnableDeferredLighting ? 1.0f : 0.0f,
_camera->getPerspectiveNearZ(),
_camera->getPerspectiveFarZ()
_camera->getPerspectiveFarZ(),
_camera->volumetric_environment_enable,
5 - _camera->volumetric_environment_downsample,
_camera->volumetric_environment_max_distance,
_camera->volumetric_environment_quality,
_camera->volumetric_environment_intensity
};
return values[i];
}
-(void)setParameterValueWithIndex: (int)i Value: (float)v
{
bool bNewBoolVal = v > 0.5;
NSLog(@"Set Parameter: (%s, %f)", [[self getParameterNameWithIndex: i] UTF8String], v);
// NSLog(@"Set Parameter: (%s, %f)", [[self getParameterNameWithIndex: i] UTF8String], v);
switch(i) {
case 0: // FOV
_camera->perspective_fov = v;
@@ -466,16 +487,31 @@ float const PI = 3.141592653589793f;
case 33:
_camera->setPerpsectiveFarZ(v);
break;
case 34:
_camera->volumetric_environment_enable = bNewBoolVal;
break;
case 35:
_camera->volumetric_environment_downsample = 5 - (int)v;
break;
case 36:
_camera->volumetric_environment_max_distance = v;
break;
case 37:
_camera->volumetric_environment_quality = v;
break;
case 38:
_camera->volumetric_environment_intensity = v;
break;
}
}
-(float)getParameterMinWithIndex: (int)i
{
float minValues[34] = {
float minValues[39] = {
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.5f, 50.0f
0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 50.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f
};
return minValues[i];
@@ -483,11 +519,12 @@ float const PI = 3.141592653589793f;
-(float)getParameterMaxWithIndex: (int)i
{
float maxValues[34] = {
float maxValues[39] = {
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,
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, 1000.0f, 50000.0f
1.0f, 1.0f, 1.0f, 1.0f, 1000.0f, 50000.0f,
1.0f, 5.0f, 50000.0f, 1.0f, 10.0f
};
return maxValues[i];

View File

@@ -41,7 +41,6 @@ KRInstance::KRInstance(KRScene &scene, std::string instance_name, std::string mo
m_model_name = model_name;
m_min_lod_coverage = lod_min_coverage;
m_receivesShadow = receives_shadow;
m_receivesShadow = false;
}
KRInstance::~KRInstance() {

View File

@@ -140,7 +140,7 @@ void KRModel::render(KRCamera *pCamera, KRContext *pContext, const KRViewport &v
}
KRMaterial *pPrevBoundMaterial = NULL;
char szPrevShaderKey[128];
char szPrevShaderKey[256];
szPrevShaderKey[0] = '\0';
int cSubmeshes = getSubmeshes().size();
if(renderPass == KRNode::RENDER_PASS_SHADOWMAP) {

View File

@@ -253,11 +253,10 @@ void KRModelManager::rotateBuffers(bool new_frame)
KRModelManager::VolumetricLightingVertexData *KRModelManager::getVolumetricLightingVertexes()
{
const int MAX_PLANES=500;
if(m_volumetricLightingVertexData == NULL) {
m_volumetricLightingVertexData = (VolumetricLightingVertexData *)malloc(sizeof(VolumetricLightingVertexData) * MAX_PLANES * 6);
m_volumetricLightingVertexData = (VolumetricLightingVertexData *)malloc(sizeof(VolumetricLightingVertexData) * MAX_VOLUMETRIC_PLANES * 6);
int iVertex=0;
for(int iPlane=0; iPlane < MAX_PLANES; iPlane++) {
for(int iPlane=0; iPlane < MAX_VOLUMETRIC_PLANES; iPlane++) {
m_volumetricLightingVertexData[iVertex].vertex.x = -1.0f;
m_volumetricLightingVertexData[iVertex].vertex.y = -1.0f;
m_volumetricLightingVertexData[iVertex].vertex.z = iPlane;

View File

@@ -45,6 +45,8 @@ using std::map;
class KRModelManager : public KRContextObject {
public:
static const int MAX_VOLUMETRIC_PLANES=500;
KRModelManager(KRContext &context);
virtual ~KRModelManager();

View File

@@ -17,7 +17,6 @@
#import "KRInstance.h"
#import "KRParticleSystem.h"
#import "KRParticleSystemBrownian.h"
#import "KRVolumetricFog.h"
#import "KRAABB.h"
#import "KRQuaternion.h"
@@ -148,12 +147,6 @@ KRNode *KRNode::LoadXML(KRScene &scene, tinyxml2::XMLElement *e) {
new_node = new KRSpotLight(scene, szName);
} else if(strcmp(szElementName, "brownian_particles") == 0) {
new_node = new KRParticleSystemBrownian(scene, szName);
} else if(strcmp(szElementName, "volumetric_fog") == 0) {
float lod_min_coverage = 0.0f;
if(e->QueryFloatAttribute("lod_min_coverage", &lod_min_coverage) != tinyxml2::XML_SUCCESS) {
lod_min_coverage = 0.0f; //1.0f / 1024.0f / 768.0f; // FINDME - HACK - Need to dynamically select the absolute minimum based on the render buffer size
}
new_node = new KRVolumetricFog(scene, szName, szName, lod_min_coverage);
} else if(strcmp(szElementName, "mesh") == 0) {
float lod_min_coverage = 0.0f;
if(e->QueryFloatAttribute("lod_min_coverage", &lod_min_coverage) != tinyxml2::XML_SUCCESS) {

View File

@@ -33,7 +33,6 @@ void KROctree::add(KRNode *pNode)
m_pRootNode = new KROctreeNode(nodeBounds);
//m_pRootNode = new KROctreeNode(KRAABB(nodeBounds.min - nodeBounds.size() * 0.25f, nodeBounds.max + nodeBounds.size() * 0.25f));
m_pRootNode->add(pNode);
fprintf(stderr, "First Octree Node: %s\n", pNode->getName().c_str());
} else {
// Keep encapsulating the root node until the new root contains the inserted node
bool bInsideRoot = false;

View File

@@ -169,7 +169,7 @@ KRShader::KRShader(char *szKey, std::string options, std::string vertShaderSourc
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_DEPTH_FRAME] = glGetUniformLocation(m_iProgram, "depthFrame"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_RENDER_FRAME] = glGetUniformLocation(m_iProgram, "renderFrame"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_SLICE_DEPTH_SCALE] = glGetUniformLocation(m_iProgram, "slice_depth_scale"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_VOLUMETRIC_LIGHTING_FRAME] = glGetUniformLocation(m_iProgram, "volumetricLightingFrame"));
GLDEBUG(m_uniforms[KRENGINE_UNIFORM_VOLUMETRIC_ENVIRONMENT_FRAME] = glGetUniformLocation(m_iProgram, "volumetricEnvironmentFrame"));
}
@@ -328,7 +328,7 @@ bool KRShader::bind(const KRViewport &viewport, const KRViewport *pShadowViewpor
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_DEPTH_FRAME], 0));
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_RENDER_FRAME], 1));
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_VOLUMETRIC_LIGHTING_FRAME], 2));
GLDEBUG(glUniform1i(m_uniforms[KRENGINE_UNIFORM_VOLUMETRIC_ENVIRONMENT_FRAME], 2));
#if defined(DEBUG)
GLint logLength;

View File

@@ -125,7 +125,7 @@ public:
KRENGINE_UNIFORM_GBUFFER_FRAME,
KRENGINE_UNIFORM_GBUFFER_DEPTH,
KRENGINE_UNIFORM_DEPTH_FRAME,
KRENGINE_UNIFORM_VOLUMETRIC_LIGHTING_FRAME,
KRENGINE_UNIFORM_VOLUMETRIC_ENVIRONMENT_FRAME,
KRENGINE_UNIFORM_RENDER_FRAME,
KRENGINE_UNIFORM_SLICE_DEPTH_SCALE,
@@ -133,7 +133,7 @@ public:
KRENGINE_NUM_UNIFORMS
};
GLint m_uniforms[KRENGINE_NUM_UNIFORMS];
char m_szKey[128];
char m_szKey[256];
private:
GLuint m_iProgram;

View File

@@ -48,7 +48,7 @@ KRShaderManager::~KRShaderManager() {
KRShader *KRShaderManager::getShader(const std::string &shader_name, const 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];
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);
sprintf(szKey, "%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%d_%i_%s_%i_%d_%d_%f_%f_%f_%f_%f_%f_%f", pCamera->bEnablePerPixel, bAlphaTest, bAlphaBlend, bDiffuseMap, bNormalMap, bSpecMap, bReflectionMap, bReflectionCubeMap, pCamera->bDebugPSSM, iShadowQuality, pCamera->bEnableAmbient, pCamera->bEnableDiffuse, pCamera->bEnableSpecular, bLightMap, bDiffuseMapScale, bSpecMapScale, bReflectionMapScale, bNormalMapScale, bDiffuseMapOffset, bSpecMapOffset, bReflectionMapOffset, bNormalMapOffset,pCamera->volumetric_environment_enable, renderPass, shader_name.c_str(),pCamera->dof_quality,pCamera->bEnableFlash,pCamera->bEnableVignette,pCamera->dof_depth,pCamera->dof_falloff,pCamera->flash_depth,pCamera->flash_falloff,pCamera->flash_intensity,pCamera->vignette_radius,pCamera->vignette_falloff);
KRShader *pShader = m_shaders[szKey];
@@ -111,6 +111,7 @@ KRShader *KRShaderManager::getShader(const std::string &shader_name, const KRCam
stream << "\n#define DOF_QUALITY " << pCamera->dof_quality;
stream << "\n#define ENABLE_FLASH " << (pCamera->bEnableFlash ? "1" : "0");
stream << "\n#define ENABLE_VIGNETTE " << (pCamera->bEnableVignette ? "1" : "0");
stream << "\n#define ENABLE_VOLUMETRIC_ENVIRONMENT " << (pCamera->volumetric_environment_enable ? "1" : "0");

View File

@@ -1,154 +0,0 @@
//
// KRVolumetricFog.cpp
// KREngine
//
// Copyright 2012 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
#include <iostream>
#import "KRVolumetricFog.h"
#import "KRContext.h"
#import "KRModel.h"
#import "KRShader.h"
#include <assert.h>
KRVolumetricFog::KRVolumetricFog(KRScene &scene, std::string instance_name, std::string model_name, float lod_min_coverage) : KRNode(scene, instance_name) {
m_model_name = model_name;
m_min_lod_coverage = lod_min_coverage;
}
KRVolumetricFog::~KRVolumetricFog() {
}
std::string KRVolumetricFog::getElementName() {
return "volumetric_fog";
}
tinyxml2::XMLElement *KRVolumetricFog::saveXML( tinyxml2::XMLNode *parent)
{
tinyxml2::XMLElement *e = KRNode::saveXML(parent);
e->SetAttribute("mesh_name", m_model_name.c_str());
e->SetAttribute("lod_min_coverage", m_min_lod_coverage);
return e;
}
void KRVolumetricFog::loadModel() {
if(m_models.size() == 0) {
m_models = m_pContext->getModelManager()->getModel(m_model_name.c_str()); // The model manager returns the LOD levels in sorted order, with the highest detail first
if(m_models.size() > 0) {
getScene().notify_sceneGraphModify(this);
}
// if(m_pModel == NULL) {
// fprintf(stderr, "KREngine - Model not found: %s\n", m_model_name.c_str());
// }
}
}
#if TARGET_OS_IPHONE
void KRVolumetricFog::render(KRCamera *pCamera, KRContext *pContext, const KRViewport &viewport, const KRViewport *pShadowViewports, KRVector3 &lightDirection, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass) {
KRNode::render(pCamera, pContext, viewport, pShadowViewports, lightDirection, shadowDepthTextures, cShadowBuffers, renderPass);
if(renderPass == KRNode::RENDER_PASS_ADDITIVE_PARTICLES) {
// Don't render meshes on second pass of the deferred lighting renderer, as only lights will be applied
loadModel();
KRAABB bounds = getBounds();
if(m_models.size() > 0 && cShadowBuffers > 0) {
float lod_coverage = bounds.coverage(viewport.getViewProjectionMatrix(), viewport.getSize()); // This also checks the view frustrum culling
if(lod_coverage > m_min_lod_coverage) {
// ---===--- Select the best LOD model based on screen coverage ---===---
std::vector<KRModel *>::iterator itr=m_models.begin();
KRModel *pModel = *itr++;
while(itr != m_models.end()) {
KRModel *pLODModel = *itr++;
if((float)pLODModel->getLODCoverage() / 100.0f > lod_coverage && pLODModel->getLODCoverage() < pModel->getLODCoverage()) {
pModel = pLODModel;
} else {
break;
}
}
// KRShader *pFogShader = m_pContext->getShaderManager()->getShader("volumetric_fog_inside", pCamera, false, false, false, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
//
// if(pFogShader->bind(viewport, pShadowViewports, getModelMatrix(), lightDirection, shadowDepthTextures, cShadowBuffers, KRNode::RENDER_PASS_ADDITIVE_PARTICLES)) {
//
// KRAABB viewSpaceBounds = KRAABB(bounds.min, bounds.max, viewport.getViewProjectionMatrix());
//
// // Enable z-buffer test
// GLDEBUG(glEnable(GL_DEPTH_TEST));
// GLDEBUG(glDepthFunc(GL_LEQUAL));
// GLDEBUG(glDepthRangef(0.0, 1.0));
//
// // Enable backface culling
// GLDEBUG(glCullFace(GL_BACK));
// GLDEBUG(glEnable(GL_CULL_FACE));
//
//
// int slice_count = 50;
//
// float slice_near = -100.0;
// float slice_far = -1000.0;
// float slice_spacing = (slice_far - slice_near) / slice_count;
//
// KRVector2(slice_near, slice_spacing).setUniform(pFogShader->m_uniforms[KRShader::KRENGINE_UNIFORM_SLICE_DEPTH_SCALE]);
//
// m_pContext->getModelManager()->bindVBO((void *)m_pContext->getModelManager()->getVolumetricLightingVertexes(), slice_count * 6 * sizeof(KRModelManager::VolumetricLightingVertexData), true, false, false, false, false);
// GLDEBUG(glDrawArrays(GL_TRIANGLES, 0, slice_count*6));
// }
}
}
}
}
#endif
bool KRVolumetricFog::hasTransparency() {
if(m_models.size() > 0) {
return m_models[0]->hasTransparency();
} else {
return false;
}
}
KRAABB KRVolumetricFog::getBounds() {
loadModel();
if(m_models.size() > 0) {
return KRAABB(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix());
} else {
return KRAABB::Infinite();
}
}

View File

@@ -1,79 +0,0 @@
//
// KRVolumetricFog.h
// KREngine
//
// Copyright 2012 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
#import "KREngine-common.h"
#ifndef KRVOLUMETRICFOG_H
#define KRVOLUMETRICFOG_H
#import "KRModel.h"
#import "KRMat4.h"
#import "KRVector3.h"
#import "KRVolumetricFog.h"
#import "KRCamera.h"
#import "KRModelManager.h"
#import "KRNode.h"
#import "KRContext.h"
#import "KRModel.h"
#import "KRTexture.h"
class KRVolumetricFog : public KRNode {
public:
KRVolumetricFog(KRScene &scene, std::string instance_name, std::string model_name, float lod_min_coverage);
virtual ~KRVolumetricFog();
virtual std::string getElementName();
virtual tinyxml2::XMLElement *saveXML( tinyxml2::XMLNode *parent);
#if TARGET_OS_IPHONE
virtual void render(KRCamera *pCamera, KRContext *pContext, const KRViewport &viewport, const KRViewport *pShadowViewports, KRVector3 &lightDirection, GLuint *shadowDepthTextures, int cShadowBuffers, KRNode::RenderPass renderPass);
#endif
bool hasTransparency();
virtual KRAABB getBounds();
private:
std::vector<KRModel *> m_models;
std::string m_model_name;
float m_min_lod_coverage;
void loadModel();
};
#endif

View File

@@ -31,9 +31,6 @@
#define PIXEL_SHIFT_3 0.003
#define PIXEL_SHIFT_4 0.004
#define ENABLE_VOLUMETRIC_LIGHTING 1
varying mediump vec2 textureCoordinate;
precision lowp float;
@@ -44,8 +41,8 @@ uniform lowp sampler2D videoFrame;
uniform lowp sampler2D renderFrame;
uniform lowp sampler2D depthFrame;
#if ENABLE_VOLUMETRIC_LIGHTING
uniform lowp sampler2D volumetricLightingFrame;
#if ENABLE_VOLUMETRIC_ENVIRONMENT == 1
uniform lowp sampler2D volumetricEnvironmentFrame;
#endif
void main()
@@ -165,8 +162,8 @@ void main()
// ---- VIDEO_BG END ----
#if ENABLE_VOLUMETRIC_LIGHTING
pixelColor += texture2D(volumetricLightingFrame, textureCoordinate);
#if ENABLE_VOLUMETRIC_ENVIRONMENT == 1
pixelColor += texture2D(volumetricEnvironmentFrame, textureCoordinate);
#endif

View File

@@ -25,14 +25,13 @@
// or implied, of Kearwood Gilbert.
//
//varying mediump vec2 texCoord;
#extension GL_EXT_shadow_samplers : require
varying mediump vec4 shadowMapCoord1;
uniform sampler2DShadow shadowTexture1;
varying mediump vec4 shadowMapCoord1;
uniform sampler2DShadow shadowTexture1;
uniform mediump vec3 light_color;
void main()
{
gl_FragColor = vec4(shadow2DProjEXT(shadowTexture1, shadowMapCoord1) * 0.02);
gl_FragColor = vec4(light_color, 1.0) * shadow2DProjEXT(shadowTexture1, shadowMapCoord1);
}

View File

@@ -35,6 +35,7 @@ varying mediump vec4 shadowMapCoord1;
uniform highp mat4 projection_matrix;
void main()
{
highp vec4 d = projection_matrix * vec4(0.0, 0.0, slice_depth_scale.x + vertex_position.z * slice_depth_scale.y, 1.0);

View File

@@ -27,15 +27,15 @@
#extension GL_EXT_shadow_samplers : require
varying mediump vec4 shadowMapCoord1;
uniform sampler2DShadow shadowTexture1;
uniform lowp sampler2D depthFrame;
uniform mediump vec4 viewport;
varying mediump vec4 shadowMapCoord1;
uniform sampler2DShadow shadowTexture1;
uniform lowp sampler2D depthFrame;
uniform mediump vec4 viewport;
uniform mediump vec3 light_color;
void main()
{
if(gl_FragCoord.z > texture2D(depthFrame, vec2(gl_FragCoord.xy / viewport.zw)).r) discard;
gl_FragColor = vec4(shadow2DProjEXT(shadowTexture1, shadowMapCoord1) * 0.02);
gl_FragColor = vec4(light_color, 1.0) * shadow2DProjEXT(shadowTexture1, shadowMapCoord1);
}