From 3c1868f7e6bfff93def8884f611d58c796273b6a Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 16 Sep 2016 02:53:19 +0200 Subject: [PATCH 1/7] Fix wrong flash rectangle size after window resize --- src/gl/data/gl_vertexbuffer.cpp | 14 ++++++++++++++ src/gl/data/gl_vertexbuffer.h | 2 ++ src/gl/system/gl_framebuffer.cpp | 1 + 3 files changed, 17 insertions(+) diff --git a/src/gl/data/gl_vertexbuffer.cpp b/src/gl/data/gl_vertexbuffer.cpp index 71bac435c..844ff9212 100644 --- a/src/gl/data/gl_vertexbuffer.cpp +++ b/src/gl/data/gl_vertexbuffer.cpp @@ -213,6 +213,20 @@ FFlatVertexBuffer::~FFlatVertexBuffer() map = nullptr; } +void FFlatVertexBuffer::OutputResized(int width, int height) +{ + vbo_shadowdata[4].Set(0, 0, 0, 0, 0); + vbo_shadowdata[5].Set(0, (float)height, 0, 0, 0); + vbo_shadowdata[6].Set((float)width, 0, 0, 0, 0); + vbo_shadowdata[7].Set((float)width, (float)height, 0, 0, 0); + + if (gl.buffermethod == BM_DEFERRED) + { + Map(); + memcpy(map, &vbo_shadowdata[0], mNumReserved * sizeof(FFlatVertex)); + Unmap(); + } +} void FFlatVertexBuffer::BindVBO() { diff --git a/src/gl/data/gl_vertexbuffer.h b/src/gl/data/gl_vertexbuffer.h index 1e9692f48..596de35d9 100644 --- a/src/gl/data/gl_vertexbuffer.h +++ b/src/gl/data/gl_vertexbuffer.h @@ -131,6 +131,8 @@ public: FFlatVertexBuffer(int width, int height); ~FFlatVertexBuffer(); + void OutputResized(int width, int height); + void BindVBO(); void CreateVBO(); diff --git a/src/gl/system/gl_framebuffer.cpp b/src/gl/system/gl_framebuffer.cpp index a61d139c0..07d8abaef 100644 --- a/src/gl/system/gl_framebuffer.cpp +++ b/src/gl/system/gl_framebuffer.cpp @@ -192,6 +192,7 @@ void OpenGLFrameBuffer::Update() { Resize(clientWidth, clientHeight); V_OutputResized(Width, Height); + GLRenderer->mVBO->OutputResized(Width, Height); } } From 7c2886e8ea336c831cb926ff51da7fbfdb9f5587 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 16 Sep 2016 08:10:19 +0200 Subject: [PATCH 2/7] - fixed the last commit: The altered vertices must always be copied to the actual buffer and it's not necessary to copy everything, copying the 4 changed ones is sufficient. --- src/gl/data/gl_vertexbuffer.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/gl/data/gl_vertexbuffer.cpp b/src/gl/data/gl_vertexbuffer.cpp index 844ff9212..b18b367c3 100644 --- a/src/gl/data/gl_vertexbuffer.cpp +++ b/src/gl/data/gl_vertexbuffer.cpp @@ -220,12 +220,9 @@ void FFlatVertexBuffer::OutputResized(int width, int height) vbo_shadowdata[6].Set((float)width, 0, 0, 0, 0); vbo_shadowdata[7].Set((float)width, (float)height, 0, 0, 0); - if (gl.buffermethod == BM_DEFERRED) - { - Map(); - memcpy(map, &vbo_shadowdata[0], mNumReserved * sizeof(FFlatVertex)); - Unmap(); - } + Map(); + memcpy(map, &vbo_shadowdata[4], 4 * sizeof(FFlatVertex)); + Unmap(); } void FFlatVertexBuffer::BindVBO() From 66d20726c260c6fee8a21a7df815acaf65602155 Mon Sep 17 00:00:00 2001 From: Major Cooke Date: Fri, 16 Sep 2016 11:45:58 -0500 Subject: [PATCH 3/7] Reintroduced flat sprites once more. - Take note, current flat sprites will change. With no pitch involved, sprites are now flat across the ground. --- src/gl/scene/gl_sprite.cpp | 59 +++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index 200541eba..2482588c9 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -363,8 +363,48 @@ void GLSprite::Draw(int pass) gl_RenderState.Apply(); FVector3 v[4]; - if (actor != nullptr && (actor->renderflags & RF_SPRITETYPEMASK) == RF_FLATSPRITE) + if (actor != nullptr) { + if ((actor->renderflags & RF_SPRITETYPEMASK) == RF_FLATSPRITE) + { + Matrix3x4 mat; + mat.MakeIdentity(); + + float cx, cy, cz = z; + if ((actor->renderflags & RF_ROLLCENTER)) + { + cx = (x1 + x2) * 0.5; + cy = (y1 + y2) * 0.5; + } + else + { + cx = x; + cy = y; + } + + // [MC] Rotate around the center or offsets given to the sprites. + // Counteract any existing rotations, then rotate the angle. + // Tilt the actor up or down based on pitch (increase 'somersaults' forward). + // Then counteract the roll and DO A BARREL ROLL. + + FAngle pitch = (float)-actor->Angles.Pitch.Degrees; + pitch.Normalized180(); + + mat.Translate(cx, cz, cy); + mat.Rotate(0, 1, 0, 270. - actor->Angles.Yaw.Degrees + 90); + mat.Rotate(0, 0, 1, pitch.Degrees); + mat.Rotate(0, 1, 0, 270. - actor->Angles.Roll.Degrees); + mat.Translate(-cx, -cz, -cy); + v[0] = mat * FVector3(x1, z, y2); + v[1] = mat * FVector3(x2, z, y2); + v[2] = mat * FVector3(x1, z, y1); + v[3] = mat * FVector3(x2, z, y1); + + } + else + { + CalculateVertices(v); + } } else { @@ -595,7 +635,7 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal) sector_t * rendersector; // Don't waste time projecting sprites that are definitely not visible. - if (thing == NULL || thing->sprite == 0 || !thing->IsVisibleToPlayer()) + if (thing == nullptr || thing->sprite == 0 || !thing->IsVisibleToPlayer()) { return; } @@ -728,7 +768,8 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal) float rightfac = -r.left; float leftfac = rightfac - r.width; - + float bottomfac = -r.top; + float topfac = bottomfac - r.height; z1 = z - r.top; z2 = z1 - r.height; @@ -753,11 +794,15 @@ void GLSprite::Process(AActor* thing, sector_t * sector, int thruportal) y1 = y + viewvecX*leftfac; y2 = y + viewvecX*rightfac; break; - + case RF_FLATSPRITE: - // needs careful rethinking - return; - + { + x1 = x + leftfac; + x2 = x + rightfac; + y1 = y - topfac; + y2 = y - bottomfac; + } + break; case RF_WALLSPRITE: viewvecX = thing->Angles.Yaw.Cos(); viewvecY = thing->Angles.Yaw.Sin(); From d01b0e061e60dd82a09390328baa0fd0bf378ca3 Mon Sep 17 00:00:00 2001 From: Major Cooke Date: Fri, 16 Sep 2016 12:07:01 -0500 Subject: [PATCH 4/7] Moved flatsprite code into CalculateVertices. --- src/gl/scene/gl_sprite.cpp | 88 +++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 49 deletions(-) diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index 2482588c9..765e11969 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -107,6 +107,43 @@ static const float LARGE_VALUE = 1e19f; void GLSprite::CalculateVertices(FVector3 *v) { + if (actor != nullptr && (actor->renderflags & RF_SPRITETYPEMASK) == RF_FLATSPRITE) + { + Matrix3x4 mat; + mat.MakeIdentity(); + + float cx, cy, cz = z; + if ((actor->renderflags & RF_ROLLCENTER)) + { + cx = (x1 + x2) * 0.5; + cy = (y1 + y2) * 0.5; + } + else + { + cx = x; + cy = y; + } + + // [MC] Rotate around the center or offsets given to the sprites. + // Counteract any existing rotations, then rotate the angle. + // Tilt the actor up or down based on pitch (increase 'somersaults' forward). + // Then counteract the roll and DO A BARREL ROLL. + + FAngle pitch = (float)-actor->Angles.Pitch.Degrees; + pitch.Normalized180(); + + mat.Translate(cx, cz, cy); + mat.Rotate(0, 1, 0, 270. - actor->Angles.Yaw.Degrees + 90); + mat.Rotate(0, 0, 1, pitch.Degrees); + mat.Rotate(0, 1, 0, 270. - actor->Angles.Roll.Degrees); + mat.Translate(-cx, -cz, -cy); + v[0] = mat * FVector3(x1, z, y2); + v[1] = mat * FVector3(x2, z, y2); + v[2] = mat * FVector3(x1, z, y1); + v[3] = mat * FVector3(x2, z, y1); + return; + } + // [BB] Billboard stuff const bool drawWithXYBillboard = ((particle && gl_billboard_particles) || (!(actor && actor->renderflags & RF_FORCEYBILLBOARD) //&& GLRenderer->mViewActor != NULL @@ -363,55 +400,8 @@ void GLSprite::Draw(int pass) gl_RenderState.Apply(); FVector3 v[4]; - if (actor != nullptr) - { - if ((actor->renderflags & RF_SPRITETYPEMASK) == RF_FLATSPRITE) - { - Matrix3x4 mat; - mat.MakeIdentity(); - - float cx, cy, cz = z; - if ((actor->renderflags & RF_ROLLCENTER)) - { - cx = (x1 + x2) * 0.5; - cy = (y1 + y2) * 0.5; - } - else - { - cx = x; - cy = y; - } - - // [MC] Rotate around the center or offsets given to the sprites. - // Counteract any existing rotations, then rotate the angle. - // Tilt the actor up or down based on pitch (increase 'somersaults' forward). - // Then counteract the roll and DO A BARREL ROLL. - - FAngle pitch = (float)-actor->Angles.Pitch.Degrees; - pitch.Normalized180(); - - mat.Translate(cx, cz, cy); - mat.Rotate(0, 1, 0, 270. - actor->Angles.Yaw.Degrees + 90); - mat.Rotate(0, 0, 1, pitch.Degrees); - mat.Rotate(0, 1, 0, 270. - actor->Angles.Roll.Degrees); - mat.Translate(-cx, -cz, -cy); - v[0] = mat * FVector3(x1, z, y2); - v[1] = mat * FVector3(x2, z, y2); - v[2] = mat * FVector3(x1, z, y1); - v[3] = mat * FVector3(x2, z, y1); - - } - else - { - CalculateVertices(v); - } - } - else - { - CalculateVertices(v); - } - - + CalculateVertices(v); + FQuadDrawer qd; qd.Set(0, v[0][0], v[0][1], v[0][2], ul, vt); qd.Set(1, v[1][0], v[1][1], v[1][2], ur, vt); From d99d43aebaf55f8ad1fbf870faff011714ebd602 Mon Sep 17 00:00:00 2001 From: Gaerzi Date: Fri, 16 Sep 2016 14:34:41 -0400 Subject: [PATCH 5/7] Fixes to fuzz shaders --- wadsrc/static/shaders/glsl/fuzz_noise.fp | 4 ++-- wadsrc/static/shaders/glsl/fuzz_standard.fp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/wadsrc/static/shaders/glsl/fuzz_noise.fp b/wadsrc/static/shaders/glsl/fuzz_noise.fp index 9f5da5f25..b11f1800c 100644 --- a/wadsrc/static/shaders/glsl/fuzz_noise.fp +++ b/wadsrc/static/shaders/glsl/fuzz_noise.fp @@ -6,8 +6,8 @@ vec4 ProcessTexel() vec2 texCoord = vTexCoord.st; vec4 basicColor = getTexel(texCoord); - texCoord.x = float( int(texCoord.x * 128.0) ) / 128.0; - texCoord.y = float( int(texCoord.y * 128.0) ) / 128.0; + texCoord.x = float( int(texCoord.x * texSize.x) ) / texSize.x; + texCoord.y = float( int(texCoord.y * texSize.y) ) / texSize.y; float texX = sin(mod(texCoord.x * 100.0 + timer*5.0, 3.489)) + texCoord.x / 4.0; float texY = cos(mod(texCoord.y * 100.0 + timer*5.0, 3.489)) + texCoord.y / 4.0; diff --git a/wadsrc/static/shaders/glsl/fuzz_standard.fp b/wadsrc/static/shaders/glsl/fuzz_standard.fp index fd87eaa46..02624073e 100644 --- a/wadsrc/static/shaders/glsl/fuzz_standard.fp +++ b/wadsrc/static/shaders/glsl/fuzz_standard.fp @@ -6,8 +6,8 @@ vec4 ProcessTexel() vec2 texCoord = vTexCoord.st; vec4 basicColor = getTexel(texCoord); - texCoord.x = float( int(texCoord.x * 128.0) ) / 128.0; - texCoord.y = float( int(texCoord.y * 128.0) ) / 128.0; + texCoord.x = float( int(texCoord.x * texSize.x) ) / texSize.x; + texCoord.y = float( int(texCoord.y * texSize.y) ) / texSize.y; float texX = texCoord.x / 3.0 + 0.66; float texY = 0.34 - texCoord.y / 3.0; From f2a3b8978d37ef7ac2295a1c0dd29906f800bb43 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Fri, 16 Sep 2016 15:05:16 -0400 Subject: [PATCH 6/7] Added declaration in the shader that was missing --- wadsrc/static/shaders/glsl/fuzz_noise.fp | 1 + wadsrc/static/shaders/glsl/fuzz_standard.fp | 1 + 2 files changed, 2 insertions(+) diff --git a/wadsrc/static/shaders/glsl/fuzz_noise.fp b/wadsrc/static/shaders/glsl/fuzz_noise.fp index b11f1800c..17f15d03b 100644 --- a/wadsrc/static/shaders/glsl/fuzz_noise.fp +++ b/wadsrc/static/shaders/glsl/fuzz_noise.fp @@ -5,6 +5,7 @@ vec4 ProcessTexel() { vec2 texCoord = vTexCoord.st; vec4 basicColor = getTexel(texCoord); + ivec2 texSize = textureSize(tex, 0); texCoord.x = float( int(texCoord.x * texSize.x) ) / texSize.x; texCoord.y = float( int(texCoord.y * texSize.y) ) / texSize.y; diff --git a/wadsrc/static/shaders/glsl/fuzz_standard.fp b/wadsrc/static/shaders/glsl/fuzz_standard.fp index 02624073e..95ba52431 100644 --- a/wadsrc/static/shaders/glsl/fuzz_standard.fp +++ b/wadsrc/static/shaders/glsl/fuzz_standard.fp @@ -5,6 +5,7 @@ vec4 ProcessTexel() { vec2 texCoord = vTexCoord.st; vec4 basicColor = getTexel(texCoord); + ivec2 texSize = textureSize(tex, 0); texCoord.x = float( int(texCoord.x * texSize.x) ) / texSize.x; texCoord.y = float( int(texCoord.y * texSize.y) ) / texSize.y; From bec17bd222f775147bf617d54c6d080bc27f46e1 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 17 Sep 2016 08:26:30 +0200 Subject: [PATCH 7/7] - FLATSPRITE fixes. --- src/gl/scene/gl_sprite.cpp | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/gl/scene/gl_sprite.cpp b/src/gl/scene/gl_sprite.cpp index 765e11969..b63732e3b 100644 --- a/src/gl/scene/gl_sprite.cpp +++ b/src/gl/scene/gl_sprite.cpp @@ -112,18 +112,6 @@ void GLSprite::CalculateVertices(FVector3 *v) Matrix3x4 mat; mat.MakeIdentity(); - float cx, cy, cz = z; - if ((actor->renderflags & RF_ROLLCENTER)) - { - cx = (x1 + x2) * 0.5; - cy = (y1 + y2) * 0.5; - } - else - { - cx = x; - cy = y; - } - // [MC] Rotate around the center or offsets given to the sprites. // Counteract any existing rotations, then rotate the angle. // Tilt the actor up or down based on pitch (increase 'somersaults' forward). @@ -132,11 +120,24 @@ void GLSprite::CalculateVertices(FVector3 *v) FAngle pitch = (float)-actor->Angles.Pitch.Degrees; pitch.Normalized180(); - mat.Translate(cx, cz, cy); - mat.Rotate(0, 1, 0, 270. - actor->Angles.Yaw.Degrees + 90); + mat.Translate(x, z, y); + mat.Rotate(0, 1, 0, 270. - actor->Angles.Yaw.Degrees); mat.Rotate(0, 0, 1, pitch.Degrees); - mat.Rotate(0, 1, 0, 270. - actor->Angles.Roll.Degrees); - mat.Translate(-cx, -cz, -cy); + + if (actor->renderflags & RF_ROLLCENTER) + { + float cx = (x1 + x2) * 0.5; + float cy = (y1 + y2) * 0.5; + + mat.Translate(cx - x, 0, cy - y); + mat.Rotate(0, 1, 0, - actor->Angles.Roll.Degrees); + mat.Translate(-cx, -z, -cy); + } + else + { + mat.Rotate(0, 1, 0, - actor->Angles.Roll.Degrees); + mat.Translate(-x, -z, -y); + } v[0] = mat * FVector3(x1, z, y2); v[1] = mat * FVector3(x2, z, y2); v[2] = mat * FVector3(x1, z, y1);