From a6545788a68e5348fcf6b142501207631a4b674b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 7 Jun 2020 22:06:47 +0200 Subject: [PATCH] - do RR's lightning flash as a postprocessing effect. --- source/build/include/polymost.h | 1 - source/build/src/polymost.cpp | 3 --- source/glbackend/gl_shader.cpp | 3 +-- source/glbackend/gl_shader.h | 1 - source/glbackend/glbackend.cpp | 7 +++++-- source/glbackend/glbackend.h | 5 ----- source/glbackend/pm_renderstate.h | 3 +-- wadsrc/static/engine/shaders/glsl/polymost.fp | 2 -- wadsrc/static/shaders/pp/colormap.fp | 11 ++++++++--- 9 files changed, 15 insertions(+), 21 deletions(-) diff --git a/source/build/include/polymost.h b/source/build/include/polymost.h index f43d1aa01..b79345cd2 100644 --- a/source/build/include/polymost.h +++ b/source/build/include/polymost.h @@ -47,7 +47,6 @@ enum { extern float curpolygonoffset; -extern int32_t r_scenebrightness; extern int32_t polymostcenterhoriz; extern int16_t globalpicnum; diff --git a/source/build/src/polymost.cpp b/source/build/src/polymost.cpp index 750337b7a..02610d16f 100644 --- a/source/build/src/polymost.cpp +++ b/source/build/src/polymost.cpp @@ -67,7 +67,6 @@ static float dxb1[MAXWALLSB], dxb2[MAXWALLSB]; #define SOFTROTMAT 0 static int32_t r_pogoDebug = 0; -int32_t r_scenebrightness = 0; static float gviewxrange; static float ghoriz, ghoriz2; @@ -3066,8 +3065,6 @@ void polymost_drawrooms() GLInterface.EnableDepthTest(true); GLInterface.SetDepthFunc(Depth_LessEqual); - GLInterface.SetBrightness(r_scenebrightness); - gvrcorrection = viewingrange*(1.f/65536.f); //if (glprojectionhacks == 2) { diff --git a/source/glbackend/gl_shader.cpp b/source/glbackend/gl_shader.cpp index 7b6ad7bfd..e9c86a853 100644 --- a/source/glbackend/gl_shader.cpp +++ b/source/glbackend/gl_shader.cpp @@ -137,8 +137,7 @@ bool PolymostShader::Load(const char * name, const char * vert_prog, const char Flags.Init(hShader, "u_flags"); NPOTEmulationFactor.Init(hShader, "u_npotEmulationFactor"); NPOTEmulationXOffset.Init(hShader, "u_npotEmulationXOffset"); - Brightness.Init(hShader, "u_brightness"); - + TextureMode.Init(hShader, "uTextureMode"); FogColor.Init(hShader, "uFogColor"); muFogEnabled.Init(hShader, "uFogEnabled"); diff --git a/source/glbackend/gl_shader.h b/source/glbackend/gl_shader.h index 10860632b..40cc4da4b 100644 --- a/source/glbackend/gl_shader.h +++ b/source/glbackend/gl_shader.h @@ -29,7 +29,6 @@ public: FBufferedUniform1i Flags; FBufferedUniform1f NPOTEmulationFactor; FBufferedUniform1f NPOTEmulationXOffset; - FBufferedUniform1f Brightness; FBufferedUniformPalEntry FogColor; FBufferedUniform1i TextureMode; diff --git a/source/glbackend/glbackend.cpp b/source/glbackend/glbackend.cpp index e0b4a5936..bd75f7d52 100644 --- a/source/glbackend/glbackend.cpp +++ b/source/glbackend/glbackend.cpp @@ -546,7 +546,6 @@ void PolymostRenderState::Apply(PolymostShader* shader, GLState& oldState) shader->NPOTEmulationFactor.Set(NPOTEmulationFactor); shader->NPOTEmulationXOffset.Set(NPOTEmulationXOffset); shader->AlphaThreshold.Set(AlphaTest ? AlphaThreshold : -1.f); - shader->Brightness.Set(Brightness); shader->FogColor.Set((Flags& RF_MapFog)? PalEntry(0x999999) : FogColor); float lightattr[] = { ShadeDiv / (numshades - 2), VisFactor, (Flags & RF_MapFog) ? -5.f : 0.f , ShadeDiv >= 1 / 1000.f? Shade : 0 }; shader->muLightParms.Set(lightattr); @@ -725,6 +724,8 @@ void DrawRateStuff() } } +int32_t r_scenebrightness = 0; + void videoShowFrame(int32_t w) { static GLenum buffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2 }; @@ -742,8 +743,10 @@ void videoShowFrame(int32_t w) glDrawBuffers(1, buffers); } + float Brightness = 8.f / (r_scenebrightness + 8.f); + OpenGLRenderer::GLRenderer->mBuffers->BlitSceneToTexture(); // Copy the resulting scene to the current post process texture - screen->PostProcessScene(false, 0, 1.f, []() { + screen->PostProcessScene(false, 0, Brightness, []() { GLInterface.Draw2D(&twodpsp); // draws the weapon sprites }); screen->Update(); diff --git a/source/glbackend/glbackend.h b/source/glbackend/glbackend.h index d05f9e6a6..da742736c 100644 --- a/source/glbackend/glbackend.h +++ b/source/glbackend/glbackend.h @@ -431,11 +431,6 @@ public: renderState.Flags &= ~RF_MapFog; } - void SetBrightness(int brightness) - { - renderState.Brightness = 8.f / (brightness + 8.f); - } - void SetTinting(int flags, PalEntry color, PalEntry overlayColor) { renderState.hictint = color; diff --git a/source/glbackend/pm_renderstate.h b/source/glbackend/pm_renderstate.h index 2b689a49d..aeb727761 100644 --- a/source/glbackend/pm_renderstate.h +++ b/source/glbackend/pm_renderstate.h @@ -57,8 +57,7 @@ struct PolymostRenderState int LayerFlags = 0; float NPOTEmulationFactor = 1.f; float NPOTEmulationXOffset; - float Brightness = 1.f; - float AlphaThreshold = 0.5f; + float AlphaThreshold = 0.5f; bool AlphaTest = true; float Color[4] = { 1,1,1,1 }; short matrixIndex[NUMMATRICES] = { 0 }; diff --git a/wadsrc/static/engine/shaders/glsl/polymost.fp b/wadsrc/static/engine/shaders/glsl/polymost.fp index ab126a1c4..135ccb426 100644 --- a/wadsrc/static/engine/shaders/glsl/polymost.fp +++ b/wadsrc/static/engine/shaders/glsl/polymost.fp @@ -35,7 +35,6 @@ uniform int u_flags; uniform float u_npotEmulationFactor; uniform float u_npotEmulationXOffset; -uniform float u_brightness; in vec4 v_color; in float v_distance; @@ -263,7 +262,6 @@ void main() if ((iz & 64) == 1) color.b = 0; */ - color.rgb = pow(color.rgb, vec3(u_brightness)); fragColor = color; fragFog = vec4(0.0, 0.0, 0.0, 1.0); // Does build have colored fog? vec3 normal = normalize(cross(dFdx(v_eyeCoordPosition.xyz), dFdy(v_eyeCoordPosition.xyz))); diff --git a/wadsrc/static/shaders/pp/colormap.fp b/wadsrc/static/shaders/pp/colormap.fp index 43cc28b25..a60f4cfab 100644 --- a/wadsrc/static/shaders/pp/colormap.fp +++ b/wadsrc/static/shaders/pp/colormap.fp @@ -6,8 +6,13 @@ layout(binding=0) uniform sampler2D SceneTexture; void main() { vec4 frag = texture(SceneTexture, TexCoord); - float gray = (frag.r * 0.3 + frag.g * 0.56 + frag.b * 0.14); - vec4 cm = uFixedColormapStart + gray * uFixedColormapRange; - FragColor = vec4(clamp(cm.rgb, 0.0, 1.0), frag.a); + frag.rgb = clamp(pow(frag.rgb, vec3(uFixedColormapStart.a)), 0.0, 1.0); + if (uFixedColormapRange.a == 0) + { + float gray = (frag.r * 0.3 + frag.g * 0.56 + frag.b * 0.14); + vec4 cm = uFixedColormapStart + gray * uFixedColormapRange; + frag.rgb = clamp(cm.rgb, 0.0, 1.0); + } + FragColor = frag; }