Merge remote-tracking branch 'origin/esm'

This commit is contained in:
Vincent Lejeune 2014-11-03 01:02:27 +01:00
commit 17aafae42c
15 changed files with 88 additions and 28 deletions

View File

@ -20,7 +20,7 @@ void main()
vec4 sum = texture(tex, vec2(X, Y)) * g0;
g0 *= g1;
g1 *= g2;
for (int i = 1; i < 3; i++) {
for (int i = 1; i < 6; i++) {
sum += texture(tex, vec2(X - i * pixel.x, Y)) * g0;
sum += texture(tex, vec2(X + i * pixel.x, Y)) * g0;
g0 *= g1;

View File

@ -20,7 +20,7 @@ void main()
vec4 sum = texture(tex, vec2(X, Y)) * g0;
g0 *= g1;
g1 *= g2;
for (int i = 1; i < 3; i++) {
for (int i = 1; i < 6; i++) {
sum += texture(tex, vec2(X, Y - i * pixel.y)) * g0;
sum += texture(tex, vec2(X, Y + i * pixel.y)) * g0;
g0 *= g1;

View File

@ -17,5 +17,5 @@ void main(void)
vec4 col = texture(tex, uv);
#endif
if (col.a < 0.5) discard;
FragColor = vec4(gl_FragCoord.z);
FragColor = vec4(exp(8. * (2. * gl_FragCoord.z - 1.) / gl_FragCoord.w));
}

View File

@ -2,5 +2,5 @@ out vec4 FragColor;
void main()
{
FragColor = vec4(gl_FragCoord.z);
FragColor = vec4(exp(8. * (2. * gl_FragCoord.z - 1.) / gl_FragCoord.w));
}

View File

@ -12,5 +12,5 @@ void main(void)
{
vec4 col = texture(tex, uv);
if (col.a < 0.5) discard;
FragColor = vec4(gl_FragCoord.z);
FragColor = vec4(exp(8. * (2. * gl_FragCoord.z - 1.) / gl_FragCoord.w));
}

View File

@ -30,7 +30,7 @@ float getShadowFactor(vec3 pos, float bias, int index)
);
vec4 shadowcoord = (ShadowViewProjMatrixes[index] * InverseViewMatrix * vec4(pos, 1.0));
shadowcoord /= shadowcoord.w;
shadowcoord.xy /= shadowcoord.w;
vec2 shadowtexcoord = shadowcoord.xy * 0.5 + 0.5;
// shadowcoord = (shadowcoord * 0.5) + vec3(0.5);
@ -42,16 +42,21 @@ float getShadowFactor(vec3 pos, float bias, int index)
//float shadowmapz = 2. * texture(shadowtex, vec3(shadowtexcoord, shadowcoord.z).x - 1.;
// bias += smoothstep(0.001, 0.1, moved) * 0.014; // According to the warping
float sum = 0.;
for (float i = -1.5; i <= 1.5; i+= 1.)
{
for (float j = -1.5; j <= 1.5; j+= 1.)
{
float z = texture(shadowtex, vec3(shadowtexcoord +vec2(i, j) / 1024., float(index))).x;
sum += (z > 0.5 * shadowcoord.z + 0.5) ? 1. : 0.;
}
}
return sum / 16.;
// float sum = 0.;
// for (float i = -1.5; i <= 1.5; i+= 1.)
// {
// for (float j = -1.5; j <= 1.5; j+= 1.)
// {
// float z = texture(shadowtex, vec3(shadowtexcoord +vec2(i, j) / 1024., float(index))).x;
// sum += (z > 0.5 * shadowcoord.z + 0.5) ? 1. : 0.;
// }
// }
// return sum / 16.;
float z = texture(shadowtex, vec3(shadowtexcoord, float(index))).x;
float d = shadowcoord.z;
return min(pow(exp(-8. * d) * z, 256.), 1.);
}
void main() {

View File

@ -165,7 +165,7 @@ unsigned GPUTimer::elapsedTimeus()
FrameBuffer::FrameBuffer() {}
FrameBuffer::FrameBuffer(const std::vector<GLuint> &RTTs, size_t w, size_t h, bool layered) :
RenderTargets(RTTs), DepthTexture(0), width(w), height(h)
RenderTargets(RTTs), DepthTexture(0), width(w), height(h), fbolayer(0)
{
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
@ -184,7 +184,7 @@ FrameBuffer::FrameBuffer(const std::vector<GLuint> &RTTs, size_t w, size_t h, bo
}
FrameBuffer::FrameBuffer(const std::vector<GLuint> &RTTs, GLuint DS, size_t w, size_t h, bool layered) :
RenderTargets(RTTs), DepthTexture(DS), width(w), height(h)
RenderTargets(RTTs), DepthTexture(DS), width(w), height(h), fbolayer(0)
{
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
@ -202,11 +202,15 @@ FrameBuffer::FrameBuffer(const std::vector<GLuint> &RTTs, GLuint DS, size_t w, s
}
GLenum result = glCheckFramebufferStatus(GL_FRAMEBUFFER);
assert(result == GL_FRAMEBUFFER_COMPLETE_EXT);
if (layered)
glGenFramebuffers(1, &fbolayer);
}
FrameBuffer::~FrameBuffer()
{
glDeleteFramebuffers(1, &fbo);
if (fbolayer)
glDeleteFramebuffers(1, &fbolayer);
}
void FrameBuffer::Bind()
@ -217,6 +221,16 @@ void FrameBuffer::Bind()
glDrawBuffers((int)RenderTargets.size(), bufs);
}
void FrameBuffer::BindLayer(unsigned i)
{
glBindFramebuffer(GL_FRAMEBUFFER, fbolayer);
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, RenderTargets[0], 0, i);
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, DepthTexture, 0, i);
glViewport(0, 0, (int)width, (int)height);
GLenum bufs[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 };
glDrawBuffers((int)RenderTargets.size(), bufs);
}
void FrameBuffer::Blit(const FrameBuffer &Src, FrameBuffer &Dst, GLbitfield mask, GLenum filter)
{
glBindFramebuffer(GL_READ_FRAMEBUFFER, Src.fbo);

View File

@ -43,7 +43,7 @@ public:
class FrameBuffer
{
private:
GLuint fbo;
GLuint fbo, fbolayer;
std::vector<GLuint> RenderTargets;
GLuint DepthTexture;
size_t width, height;
@ -53,6 +53,7 @@ public:
FrameBuffer(const std::vector <GLuint> &RTTs, GLuint DS, size_t w, size_t h, bool layered = false);
~FrameBuffer();
void Bind();
void BindLayer(unsigned);
const std::vector<GLuint> &getRTT() const { return RenderTargets; }
GLuint &getDepthTexture() { assert(DepthTexture); return DepthTexture; }
size_t getWidth() const { return width; }

View File

@ -513,6 +513,7 @@ void IrrDriver::initDevice()
hasDrawIndirect = false;
hasComputeShaders = false;
hasTextureStorage = false;
hasTextureView = false;
// Default false value for hasVSLayer if --no-graphics argument is used
#if !defined(__APPLE__)
if (!ProfileWorld::isNoGraphics())
@ -541,6 +542,10 @@ void IrrDriver::initDevice()
hasTextureStorage = true;
Log::info("GLDriver", "ARB Texture Storage enabled");
}
if (hasGLExtension("GL_ARB_texture_view")) {
hasTextureView = true;
Log::info("GLDriver", "ARB Texture View enabled");
}
}
#endif

View File

@ -180,6 +180,7 @@ private:
bool hasBuffserStorage;
bool hasComputeShaders;
bool hasTextureStorage;
bool hasTextureView;
bool m_need_ubo_workaround;
bool m_need_rh_workaround;
bool m_need_srgb_workaround;
@ -311,6 +312,11 @@ public:
return hasTextureStorage;
}
bool hasARBTextureView() const
{
return hasTextureView;
}
video::SColorf getAmbientLight() const;
struct GlowData {

View File

@ -314,6 +314,25 @@ void PostProcessing::renderGaussian3Blur(FrameBuffer &in_fbo, FrameBuffer &auxil
}
}
void PostProcessing::renderGaussian6BlurLayer(FrameBuffer &in_fbo)
{
for (unsigned i = 0; i < 4; i++)
{
// Used as temp
irr_driver->getFBO(FBO_BLOOM_1024).Bind();
GLuint LayerTex;
glGenTextures(1, &LayerTex);
glTextureView(LayerTex, GL_TEXTURE_2D, in_fbo.getRTT()[0], GL_R32F, 0, 1, i, 1);
FullScreenShader::Gaussian6VBlurShader::getInstance()->SetTextureUnits(LayerTex);
DrawFullScreenEffect<FullScreenShader::Gaussian6VBlurShader>(core::vector2df(1. / 1024., 1. / 1024.));
in_fbo.BindLayer(i);
FullScreenShader::Gaussian6HBlurShader::getInstance()->SetTextureUnits(irr_driver->getFBO(FBO_BLOOM_1024).getRTT()[0]);
DrawFullScreenEffect<FullScreenShader::Gaussian6HBlurShader>(core::vector2df(1. / 1024., 1. / 1024.));
glDeleteTextures(1, &LayerTex);
}
}
void PostProcessing::renderGaussian6Blur(FrameBuffer &in_fbo, FrameBuffer &auxiliary)
{
assert(in_fbo.getWidth() == auxiliary.getWidth() && in_fbo.getHeight() == auxiliary.getHeight());

View File

@ -88,6 +88,7 @@ public:
/** Blur the in texture */
void renderGaussian3Blur(FrameBuffer &in_fbo, FrameBuffer &auxiliary);
void renderGaussian6Blur(FrameBuffer &in_fbo, FrameBuffer &auxiliary);
void renderGaussian6BlurLayer(FrameBuffer &in_fbo);
void renderGaussian17TapBlur(FrameBuffer &in_fbo, FrameBuffer &auxiliary);
/** Render tex. Used for blit/texture resize */

View File

@ -978,11 +978,12 @@ void IrrDriver::renderShadows()
glDepthMask(GL_TRUE);
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
m_rtts->getShadowFBO().Bind();
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.5, 0.);
m_rtts->getShadowFBO().Bind();
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
glClearColor(1., 1., 1., 1.);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glClearColor(0., 0., 0., 0.);
@ -1024,7 +1025,11 @@ void IrrDriver::renderShadows()
}
glDisable(GL_POLYGON_OFFSET_FILL);
glCullFace(GL_BACK);
if (irr_driver->hasARBTextureView())
m_post_processing->renderGaussian6BlurLayer(m_rtts->getShadowFBO());
glBindTexture(GL_TEXTURE_2D_ARRAY, m_rtts->getShadowFBO().getRTT()[0]);
glGenerateMipmap(GL_TEXTURE_2D_ARRAY);
}

View File

@ -24,13 +24,13 @@
#include "utils/log.hpp"
#include <ISceneManager.h>
static GLuint generateRTT3D(GLenum target, size_t w, size_t h, size_t d, GLint internalFormat, GLint format, GLint type)
static GLuint generateRTT3D(GLenum target, size_t w, size_t h, size_t d, GLint internalFormat, GLint format, GLint type, unsigned mipmaplevel = 1)
{
GLuint result;
glGenTextures(1, &result);
glBindTexture(target, result);
if (irr_driver->hasARBTextureStorage())
glTexStorage3D(target, 1, internalFormat, w, h, d);
glTexStorage3D(target, mipmaplevel, internalFormat, w, h, d);
else
glTexImage3D(target, 0, internalFormat, w, h, d, 0, format, type, 0);
return result;
@ -223,8 +223,8 @@ RTT::RTT(size_t width, size_t height)
if (UserConfigParams::m_shadows && !irr_driver->needUBOWorkaround())
{
shadowColorTex = generateRTT3D(GL_TEXTURE_2D_ARRAY, 1024, 1024, 4, GL_R32F, GL_RED, GL_FLOAT);
shadowDepthTex = generateRTT3D(GL_TEXTURE_2D_ARRAY, 1024, 1024, 4, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8);
shadowColorTex = generateRTT3D(GL_TEXTURE_2D_ARRAY, 1024, 1024, 4, GL_R32F, GL_RED, GL_FLOAT, 1);
shadowDepthTex = generateRTT3D(GL_TEXTURE_2D_ARRAY, 1024, 1024, 4, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, 1);
somevector.clear();
somevector.push_back(shadowColorTex);

View File

@ -859,9 +859,13 @@ GLuint createShadowSampler()
unsigned id;
glGenSamplers(1, &id);
glSamplerParameteri(id, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glSamplerParameteri(id, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glSamplerParameteri(id, GL_TEXTURE_WRAP_S, GL_REPEAT);
glSamplerParameteri(id, GL_TEXTURE_WRAP_T, GL_REPEAT);
int aniso = UserConfigParams::m_anisotropic;
if (aniso == 0) aniso = 1;
glSamplerParameterf(id, GL_TEXTURE_MAX_ANISOTROPY_EXT, (float)aniso);
return id;
#endif
}