1
0
forked from 0ad/0ad

Fixes LOS flickering because of float precision. Fixes #6546

Tested By: Langbart
Differential Revision: https://code.wildfiregames.com/D4684
This was SVN commit r26922.
This commit is contained in:
Vladislav Belov 2022-06-06 20:48:18 +00:00
parent b0c29b8676
commit ffe4ea24ab
7 changed files with 19 additions and 6 deletions

View File

@ -149,6 +149,8 @@ TEX tex, v_tex, texture[0], 2D;
#if !IGNORE_LOS
// Multiply everything by the LOS texture
TEX tex.r, v_los, texture[2], 2D;
SUB tex.r, tex.r, 0.03;
MUL tex.r, tex.r, 0.97;
MUL color.rgb, color, tex.r;
#endif

View File

@ -19,6 +19,8 @@ TEX mask, fragment.texcoord[0], texture[1], 2D;
// Multiply RGB by LOS texture (red channel)
TEMP los;
TEX los, fragment.texcoord[1], texture[2], 2D;
SUB los.r, los.r, 0.03;
MUL los.r, los.r, 0.97;
MUL result.color.rgb, color, los.r;
#endif

View File

@ -17,6 +17,8 @@ MUL color.rgb, color, tex;
// Multiply everything by the LOS texture
TEX losTex, v_los, texture[1], 2D;
SUB losTex.r, losTex.r, 0.03;
MUL losTex.r, losTex.r, 0.97;
MUL result.color.rgb, color, losTex.r;
MUL result.color.a, tex, fragment.color;

View File

@ -88,6 +88,8 @@ TEX color, fragment.texcoord[0], texture[0], 2D;
// Multiply everything by the LOS texture
TEX tex.r, fragment.texcoord[3], texture[3], 2D;
SUB tex.r, tex.r, 0.03;
MUL tex.r, tex.r, 0.97;
MUL color.rgb, color, tex.r;
#if DECAL

View File

@ -11,6 +11,8 @@ MUL diffuse, diffuse, color;
TEMP los;
TEX los, v_losCoords, texture[1], 2D;
SUB los.r, los.r, 0.03;
MUL los.r, los.r, 0.97;
MUL diffuse, diffuse, los.r;
MOV result.color, diffuse;

View File

@ -22,6 +22,8 @@
#include "graphics/ShaderManager.h"
#include "lib/bits.h"
#include "lib/config2.h"
#include "lib/timer.h"
#include "maths/MathUtil.h"
#include "ps/CLogger.h"
#include "ps/CStrInternStatic.h"
#include "ps/Game.h"
@ -132,6 +134,8 @@ void CLOSTexture::InterpolateLOS(Renderer::Backend::IDeviceCommandContext* devic
if (m_Dirty)
{
RecomputeTexture(deviceCommandContext);
m_LastTextureRecomputeTime = timer_Time();
m_WhichTexture = 1u - m_WhichTexture;
m_Dirty = false;
}
@ -150,11 +154,11 @@ void CLOSTexture::InterpolateLOS(Renderer::Backend::IDeviceCommandContext* devic
deviceCommandContext->SetTexture(
shader->GetBindingSlot(str_losTex1), m_Texture.get());
deviceCommandContext->SetTexture(
shader->GetBindingSlot(str_losTex2), m_SmoothTextures[m_WhichTexture].get());
shader->GetBindingSlot(str_losTex2), m_SmoothTextures[1u - m_WhichTexture].get());
deviceCommandContext->SetUniform(
shader->GetBindingSlot(str_delta),
static_cast<float>(g_Renderer.GetTimeManager().GetFrameDelta() * 4.0f));
const float delta = Clamp<float>(
(timer_Time() - m_LastTextureRecomputeTime) * 2.0f, 0.0f, 1.0f);
deviceCommandContext->SetUniform(shader->GetBindingSlot(str_delta), delta);
const SViewPort oldVp = g_Renderer.GetViewport();
const SViewPort vp =
@ -208,8 +212,6 @@ void CLOSTexture::InterpolateLOS(Renderer::Backend::IDeviceCommandContext* devic
deviceCommandContext->SetFramebuffer(
deviceCommandContext->GetDevice()->GetCurrentBackbuffer());
m_WhichTexture = 1u - m_WhichTexture;
}

View File

@ -98,6 +98,7 @@ private:
m_Texture, m_SmoothTextures[2];
uint32_t m_WhichTexture = 0;
double m_LastTextureRecomputeTime = 0.0;
// We update textures once a frame, so we change a Framebuffer once a frame.
// That allows us to use two ping-pong FBOs instead of checking completeness