From 265df4b79702fa655aac4abc28578f98d30fcdc3 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sat, 3 Jun 2017 21:19:34 +0200 Subject: [PATCH] - Change shadowmap resolution from 1024 to 128 --- src/gl/dynlights/gl_shadowmap.cpp | 2 +- src/gl/dynlights/gl_shadowmap.h | 4 ++++ src/gl/renderer/gl_renderbuffers.cpp | 2 +- wadsrc/static/shaders/glsl/shadowmap.fp | 14 +++++++++----- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/gl/dynlights/gl_shadowmap.cpp b/src/gl/dynlights/gl_shadowmap.cpp index 81ed1af737..1585aec82b 100644 --- a/src/gl/dynlights/gl_shadowmap.cpp +++ b/src/gl/dynlights/gl_shadowmap.cpp @@ -106,7 +106,7 @@ void FShadowMap::Update() glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, mNodesBuffer); glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, mLinesBuffer); - glViewport(0, 0, 1024, 1024); + glViewport(0, 0, SHADOWMAP_QUALITY, 1024); GLRenderer->RenderScreenQuad(); const auto &viewport = GLRenderer->mScreenViewport; diff --git a/src/gl/dynlights/gl_shadowmap.h b/src/gl/dynlights/gl_shadowmap.h index 281936f80e..d6a68198cb 100644 --- a/src/gl/dynlights/gl_shadowmap.h +++ b/src/gl/dynlights/gl_shadowmap.h @@ -8,6 +8,10 @@ class ADynamicLight; struct level_info_t; +// This constant must match the same constant in shadowmap.fp +//#define SHADOWMAP_QUALITY 1024 +#define SHADOWMAP_QUALITY 128 + class FShadowMap { public: diff --git a/src/gl/renderer/gl_renderbuffers.cpp b/src/gl/renderer/gl_renderbuffers.cpp index 74dc36e729..fbc8294b13 100644 --- a/src/gl/renderer/gl_renderbuffers.cpp +++ b/src/gl/renderer/gl_renderbuffers.cpp @@ -770,7 +770,7 @@ void FGLRenderBuffers::CreateShadowMap() glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding); glGetIntegerv(GL_FRAMEBUFFER_BINDING, &frameBufferBinding); - mShadowMapTexture = Create2DTexture("ShadowMap", GL_R32F, 1024, 1024); + mShadowMapTexture = Create2DTexture("ShadowMap", GL_R32F, SHADOWMAP_QUALITY, 1024); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); diff --git a/wadsrc/static/shaders/glsl/shadowmap.fp b/wadsrc/static/shaders/glsl/shadowmap.fp index 194da954ef..9e4efdd4e5 100644 --- a/wadsrc/static/shaders/glsl/shadowmap.fp +++ b/wadsrc/static/shaders/glsl/shadowmap.fp @@ -2,6 +2,10 @@ in vec2 TexCoord; out vec4 FragColor; +// This constant must match the same constant in gl_shadowmap.h +// #define SHADOWMAP_QUALITY 1024 +#define SHADOWMAP_QUALITY 128 + struct GPUNode { vec2 aabb_min; @@ -140,12 +144,12 @@ void main() if (radius > 0.0) { vec2 pixelpos; - switch (int(gl_FragCoord.x) / 256) + switch (int(gl_FragCoord.x) / int(SHADOWMAP_QUALITY/4)) { - case 0: pixelpos = vec2((gl_FragCoord.x - 128.0) / 128.0, 1.0); break; - case 1: pixelpos = vec2(1.0, (gl_FragCoord.x - 384.0) / 128.0); break; - case 2: pixelpos = vec2(-(gl_FragCoord.x - 640.0) / 128.0, -1.0); break; - case 3: pixelpos = vec2(-1.0, -(gl_FragCoord.x - 896.0) / 128.0); break; + case 0: pixelpos = vec2((gl_FragCoord.x - float(SHADOWMAP_QUALITY/8)) / float(SHADOWMAP_QUALITY/8), 1.0); break; + case 1: pixelpos = vec2(1.0, (gl_FragCoord.x - float(SHADOWMAP_QUALITY/4 + SHADOWMAP_QUALITY/8)) / float(SHADOWMAP_QUALITY/8)); break; + case 2: pixelpos = vec2(-(gl_FragCoord.x - float(SHADOWMAP_QUALITY/2 + SHADOWMAP_QUALITY/8)) / float(SHADOWMAP_QUALITY/8), -1.0); break; + case 3: pixelpos = vec2(-1.0, -(gl_FragCoord.x - float(SHADOWMAP_QUALITY*3/4 + SHADOWMAP_QUALITY/8)) / float(SHADOWMAP_QUALITY/8)); break; } pixelpos = lightpos + pixelpos * radius;