Volumetric lighting in progress

--HG--
rename : KREngine/KREngine/Shaders/volumetric_fog_inside.fsh => KREngine/KREngine/Shaders/volumetric_fog.fsh
rename : KREngine/KREngine/Shaders/volumetric_fog_inside.vsh => KREngine/KREngine/Shaders/volumetric_fog.vsh
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40153
This commit is contained in:
kearwood
2012-11-09 20:55:23 +00:00
parent 602425dd51
commit 152e0139a6
11 changed files with 150 additions and 178 deletions

View File

@@ -233,10 +233,8 @@
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>"; };
E443C606164B27B400FC4FD8 /* volumetric_fog.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = volumetric_fog.fsh; path = Shaders/volumetric_fog.fsh; sourceTree = "<group>"; };
E443C609164B27C500FC4FD8 /* volumetric_fog.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = volumetric_fog.vsh; path = Shaders/volumetric_fog.vsh; sourceTree = "<group>"; };
E443C612164B5BE500FC4FD8 /* volumetric_fog_inside.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = volumetric_fog_inside.fsh; path = Shaders/volumetric_fog_inside.fsh; sourceTree = "<group>"; };
E443C615164B5BFB00FC4FD8 /* volumetric_fog_inside.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = volumetric_fog_inside.vsh; path = Shaders/volumetric_fog_inside.vsh; 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; };
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>"; };
@@ -424,10 +422,8 @@
E45AC0411641DE6D00DC3C3B /* debug_font.fsh */,
E45AC0461643451200DC3C3B /* particle.fsh */,
E45AC0491643452000DC3C3B /* particle.vsh */,
E443C606164B27B400FC4FD8 /* volumetric_fog.fsh */,
E443C609164B27C500FC4FD8 /* volumetric_fog.vsh */,
E443C612164B5BE500FC4FD8 /* volumetric_fog_inside.fsh */,
E443C615164B5BFB00FC4FD8 /* volumetric_fog_inside.vsh */,
E443C612164B5BE500FC4FD8 /* volumetric_fog.fsh */,
E443C615164B5BFB00FC4FD8 /* volumetric_fog.vsh */,
);
name = Shaders;
sourceTree = "<group>";

View File

@@ -102,6 +102,9 @@ KRCamera::KRCamera(KRContext &context) : KRContextObject(context) {
compositeFramebuffer = 0;
lightAccumulationBuffer = 0;
volumetricLightAccumulationBuffer = 0;
volumetricLightAccumulationTexture = 0;
memset(shadowFramebuffer, sizeof(GLuint) * 3, 0);
memset(shadowDepthTexture, sizeof(GLuint) * 3, 0);
@@ -110,6 +113,8 @@ KRCamera::KRCamera(KRContext &context) : KRContextObject(context) {
m_skyBoxName = "";
m_pSkyBoxTexture = NULL;
volumetric_light_downsample = 4;
}
KRCamera::~KRCamera() {
@@ -221,6 +226,7 @@ void KRCamera::renderFrame(KRScene &scene, KRMat4 &viewMatrix, float deltaTime)
void KRCamera::renderFrame(KRScene &scene, KRVector3 &lightDirection, float deltaTime) {
KRVector3 vecCameraDirection = m_viewport.getCameraDirection();
@@ -433,6 +439,45 @@ void KRCamera::renderFrame(KRScene &scene, KRVector3 &lightDirection, float delt
// Render all flares
scene.render(this, m_viewport.getVisibleBounds(), m_pContext, m_viewport, m_shadowViewports, lightDirection, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_ADDITIVE_PARTICLES, newVisibleBounds);
// ----====---- Volumetric Lighting ----====----
if(m_cShadowBuffers >= 1) {
// Set render target
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, volumetricLightAccumulationBuffer));
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0));
GLDEBUG(glClearColor(0.0f, 0.0f, 0.0f, 0.0f));
GLDEBUG(glClear(GL_COLOR_BUFFER_BIT));
KRShader *pFogShader = m_pContext->getShaderManager()->getShader("volumetric_fog", this, false, false, false, 0, false, false, false, false, false, false, false, false, false, false, false, false, false, KRNode::RENDER_PASS_FORWARD_TRANSPARENT);
KRViewport volumetricLightingViewport = KRViewport(m_viewport.getSize() / volumetric_light_downsample, m_viewport.getViewMatrix(), m_viewport.getProjectionMatrix());
if(pFogShader->bind(volumetricLightingViewport, m_shadowViewports, KRMat4(), lightDirection, shadowDepthTexture, m_cShadowBuffers, KRNode::RENDER_PASS_ADDITIVE_PARTICLES)) {
// Enable z-buffer test
GLDEBUG(glEnable(GL_DEPTH_TEST));
GLDEBUG(glDepthFunc(GL_LEQUAL));
GLDEBUG(glDepthRangef(0.0, 1.0));
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));
}
// Set render target
GLDEBUG(glBindFramebuffer(GL_FRAMEBUFFER, compositeFramebuffer));
GLDEBUG(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, compositeDepthTexture, 0));
}
// ----====---- Debug Overlay ----====----
@@ -527,6 +572,21 @@ void KRCamera::createBuffers() {
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);
}
}
@@ -601,6 +661,18 @@ void KRCamera::destroyBuffers()
GLDEBUG(glDeleteFramebuffers(1, &lightAccumulationBuffer));
lightAccumulationBuffer = 0;
}
if (volumetricLightAccumulationTexture) {
GLDEBUG(glDeleteTextures(1, &volumetricLightAccumulationTexture));
volumetricLightAccumulationTexture = 0;
}
if (volumetricLightAccumulationBuffer) {
GLDEBUG(glDeleteFramebuffers(1, &volumetricLightAccumulationBuffer));
volumetricLightAccumulationBuffer = 0;
}
}
@@ -704,6 +776,10 @@ void KRCamera::renderPost()
m_pContext->getTextureManager()->selectTexture(1, NULL, 0);
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));
// Update attribute values.
m_pContext->getModelManager()->bindVBO((void *)KRENGINE_VBO_2D_SQUARE, KRENGINE_VBO_2D_SQUARE_SIZE, true, false, false, true, false);

View File

@@ -118,6 +118,8 @@ public:
float getPerspectiveFarZ();
void setPerspectiveNear(float v);
void setPerpsectiveFarZ(float v);
int volumetric_light_downsample;
private:
KRVector3 m_position;
@@ -135,6 +137,9 @@ private:
GLuint lightAccumulationBuffer, lightAccumulationTexture;
GLuint volumetricLightAccumulationBuffer, volumetricLightAccumulationTexture;
GLuint shadowFramebuffer[KRENGINE_MAX_SHADOW_BUFFERS], shadowDepthTexture[KRENGINE_MAX_SHADOW_BUFFERS];
bool shadowValid[KRENGINE_MAX_SHADOW_BUFFERS];

View File

@@ -169,6 +169,8 @@ 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"));
}
} catch(...) {
@@ -326,6 +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));
#if defined(DEBUG)
GLint logLength;

View File

@@ -125,6 +125,7 @@ public:
KRENGINE_UNIFORM_GBUFFER_FRAME,
KRENGINE_UNIFORM_GBUFFER_DEPTH,
KRENGINE_UNIFORM_DEPTH_FRAME,
KRENGINE_UNIFORM_VOLUMETRIC_LIGHTING_FRAME,
KRENGINE_UNIFORM_RENDER_FRAME,
KRENGINE_UNIFORM_SLICE_DEPTH_SCALE,

View File

@@ -101,53 +101,33 @@ void KRVolumetricFog::render(KRCamera *pCamera, KRContext *pContext, const KRVie
}
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));
/*
float slice_near = viewSpaceBounds.max.z;
float slice_far = viewSpaceBounds.min.z;
slice_near = -1.0;
slice_far = 1.0;
float slice_spacing = (slice_far - slice_near) / slice_count;
// slice_spacing = 1.0f / slice_count;
// slice_near = 0.0f;
for(int slice=0; slice < slice_count; slice++) {
KRVector2(slice_near + slice * slice_spacing, slice_spacing).setUniform(pFogShader->m_uniforms[KRShader::KRENGINE_UNIFORM_SLICE_DEPTH_SCALE]);
int mesh_count = pModel->getSubmeshes().size();
for(int iMesh=0; iMesh < mesh_count; iMesh++) {
pModel->renderSubmesh(iMesh);
}
}
*/
}
// 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));
// }
}
}
}

View File

@@ -31,6 +31,8 @@
#define PIXEL_SHIFT_3 0.003
#define PIXEL_SHIFT_4 0.004
#define ENABLE_VOLUMETRIC_LIGHTING 1
varying mediump vec2 textureCoordinate;
precision lowp float;
@@ -42,6 +44,10 @@ uniform lowp sampler2D videoFrame;
uniform lowp sampler2D renderFrame;
uniform lowp sampler2D depthFrame;
#if ENABLE_VOLUMETRIC_LIGHTING
uniform lowp sampler2D volumetricLightingFrame;
#endif
void main()
{
@@ -158,6 +164,10 @@ void main()
*/
// ---- VIDEO_BG END ----
#if ENABLE_VOLUMETRIC_LIGHTING
pixelColor += texture2D(volumetricLightingFrame, textureCoordinate);
#endif
// ---- VIGNETTE START ----

View File

@@ -27,7 +27,15 @@
//varying mediump vec2 texCoord;
#extension GL_EXT_shadow_samplers : require
varying highp vec4 shadowMapCoord1;
uniform sampler2DShadow shadowTexture1;
void main()
{
gl_FragColor = vec4(0.0, 0.02, 0.02, 0.02);
gl_FragColor = vec4(0.04, 0.04, 0.04, 0.04);
gl_FragColor *= shadow2DProjEXT(shadowTexture1, shadowMapCoord1);
// gl_FragColor = vec4(shadowMapCoord1.xyz, 1.0);
}

View File

@@ -26,37 +26,25 @@
//
attribute highp vec4 vertex_position;
uniform highp mat4 mvp_matrix; // mvp_matrix is the result of multiplying the model, view, and projection matrices
//uniform highp mat4 model_view_matrix;
//uniform highp mat4 projection_matrix;
//uniform highp mat4 inv_projection_matrix;
uniform highp mat4 inv_mvp_matrix;
uniform highp vec2 slice_depth_scale; // First component is the depth for the nearest plane, in view space. Second component is the distance between planes, in view space
uniform highp mat4 shadow_mvp1;
varying highp vec4 shadowMapCoord1;
uniform highp mat4 projection_matrix;
void main()
{
// Transform position
/*
position = shadow_mvp1 * vec4(vertex_position,1.0);
*/
// gl_Position = mvp_matrix * vertex_position;
/*
// Pass UV co-ordinates
texCoord = vertex_uv.st;
*/
{
highp vec4 d = projection_matrix * vec4(0.0, 0.0, slice_depth_scale.x + vertex_position.z * slice_depth_scale.y, 1.0);
d /= d.w;
gl_Position = vec4(vertex_position.x, vertex_position.y, d.z, 1.0);
shadowMapCoord1 = inv_mvp_matrix * gl_Position;
shadowMapCoord1 /= shadowMapCoord1.w;
shadowMapCoord1.w = 1.0;
shadowMapCoord1 = shadow_mvp1 * shadowMapCoord1;
// highp vec4 p = model_view_matrix * vertex_position;
// p.z = slice_depth_scale.x;
// gl_Position = projection_matrix * p;
// highp vec4 p = mvp_matrix * vertex_position;
// p = inv_projection_matrix * p;
// p = projection_matrix * p;
// gl_Position = p;
highp vec4 p = mvp_matrix * vertex_position;
p.z = slice_depth_scale.x * p.w;
gl_Position = p;
}

View File

@@ -1,41 +0,0 @@
// 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.
//
//varying mediump vec2 texCoord;
#extension GL_EXT_shadow_samplers : require
varying highp vec4 shadowMapCoord1;
uniform sampler2DShadow shadowTexture1;
void main()
{
gl_FragColor = vec4(0.04, 0.04, 0.04, 0.04);
gl_FragColor *= shadow2DProjEXT(shadowTexture1, shadowMapCoord1);
// gl_FragColor = vec4(shadowMapCoord1.xyz, 1.0);
}

View File

@@ -1,54 +0,0 @@
// Copyright 2012 Kearwood Gilbert. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other materials
// provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY KEARWOOD GILBERT ''AS IS'' AND ANY EXPRESS OR IMPLIED
// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KEARWOOD GILBERT OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The views and conclusions contained in the software and documentation are those of the
// authors and should not be interpreted as representing official policies, either expressed
// or implied, of Kearwood Gilbert.
//
attribute highp vec4 vertex_position;
uniform highp mat4 inv_mvp_matrix;
uniform highp vec2 slice_depth_scale; // First component is the depth for the nearest plane, in view space. Second component is the distance between planes, in view space
uniform highp mat4 shadow_mvp1;
varying highp vec4 shadowMapCoord1;
uniform highp mat4 projection_matrix;
void main()
{
// gl_Position = vec4(vertex_position.x, vertex_position.y, slice_depth_scale.x + vertex_position.z * slice_depth_scale.y, 1.0);
highp vec4 d = projection_matrix * vec4(0.0, 0.0, slice_depth_scale.x + vertex_position.z * slice_depth_scale.y, 1.0);
d /= d.w;
gl_Position = vec4(vertex_position.x, vertex_position.y, d.z, 1.0);
shadowMapCoord1 = inv_mvp_matrix * gl_Position;
shadowMapCoord1 /= shadowMapCoord1.w;
shadowMapCoord1.w = 1.0;
shadowMapCoord1 = shadow_mvp1 * shadowMapCoord1;
}