Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace noise textures with hashing #2833

Merged
merged 4 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions projects/msvc/GLideN64.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ copy /Y "$(OutDir)$(TargetName).*" "$(Mupen64PluginsDir_x64)")</Command>
<ExcludedFromBuild Condition="'$(Configuration)'=='Debug_qt' Or '$(Configuration)'=='Debug_wtl' Or '$(Configuration)'=='Release_qt' Or '$(Configuration)'=='Release_wtl'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\N64.cpp" />
<ClCompile Include="..\..\src\NoiseTexture.cpp" />
<ClCompile Include="..\..\src\PaletteTexture.cpp" />
<ClCompile Include="..\..\src\Performance.cpp" />
<ClCompile Include="..\..\src\PostProcessor.cpp" />
Expand Down Expand Up @@ -520,7 +519,6 @@ copy /Y "$(OutDir)$(TargetName).*" "$(Mupen64PluginsDir_x64)")</Command>
<ExcludedFromBuild Condition="'$(Configuration)'=='Debug_qt' Or '$(Configuration)'=='Debug_wtl' Or '$(Configuration)'=='Release_qt' Or '$(Configuration)'=='Release_wtl'">true</ExcludedFromBuild>
</ClInclude>
<ClInclude Include="..\..\src\N64.h" />
<ClInclude Include="..\..\src\NoiseTexture.h" />
<ClInclude Include="..\..\src\PaletteTexture.h" />
<ClInclude Include="..\..\src\Performance.h" />
<ClInclude Include="..\..\src\Platform.h" />
Expand Down
6 changes: 0 additions & 6 deletions projects/msvc/GLideN64.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,6 @@
<ClCompile Include="..\..\src\Graphics\OpenGLContext\GLSL\glsl_CombinerInputs.cpp">
<Filter>Source Files\Graphics\OpenGL\GLSL</Filter>
</ClCompile>
<ClCompile Include="..\..\src\NoiseTexture.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ZlutTexture.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down Expand Up @@ -610,9 +607,6 @@
<ClInclude Include="..\..\src\Graphics\OpenGLContext\GLSL\glsl_CombinerInputs.h">
<Filter>Header Files\Graphics\OpenGL\GLSL</Filter>
</ClInclude>
<ClInclude Include="..\..\src\NoiseTexture.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Graphics\ShaderProgram.h">
<Filter>Header Files\Graphics</Filter>
</ClInclude>
Expand Down
3 changes: 1 addition & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ set(GLideN64_SOURCES
gSP.cpp
Log.cpp
N64.cpp
NoiseTexture.cpp
PaletteTexture.cpp
Performance.cpp
PostProcessor.cpp
Expand Down Expand Up @@ -192,7 +191,7 @@ if( NOT CMAKE_BUILD_TYPE)
set( CMAKE_BUILD_TYPE Release)
endif( NOT CMAKE_BUILD_TYPE)

if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR
CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set(GLIDEN64_BUILD_TYPE Release)
elseif(CMAKE_BUILD_TYPE STREQUAL "Debug")
Expand Down
9 changes: 5 additions & 4 deletions src/Graphics/FramebufferTextureFormats.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ namespace graphics {
DatatypeParam lutType;
u32 lutFormatBytes;

InternalColorFormatParam noiseInternalFormat;
ColorFormatParam noiseFormat;
DatatypeParam noiseType;
u32 noiseFormatBytes;
// Used for font atlas
InternalColorFormatParam fontInternalFormat;
ColorFormatParam fontFormat;
DatatypeParam fontType;
u32 fontFormatBytes;

virtual ~FramebufferTextureFormats() {}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1003,26 +1003,18 @@ class ShaderNoise : public ShaderPart
public:
ShaderNoise(const opengl::GLInfo & _glinfo)
{
if (_glinfo.isGLES2) {
m_part =
"uniform sampler2D uTexNoise; \n"
"lowp float snoise() \n"
"{ \n"
" mediump vec2 texSize = vec2(640.0, 580.0); \n"
" mediump vec2 coord = gl_FragCoord.xy/uScreenScale/texSize; \n"
" return texture2D(uTexNoise, coord).r; \n"
"} \n"
;
} else {
m_part =
"uniform sampler2D uTexNoise; \n"
"lowp float snoise() \n"
"{ \n"
" ivec2 coord = ivec2(gl_FragCoord.xy/uScreenScale); \n"
" return texelFetch(uTexNoise, coord, 0).r; \n"
"} \n"
;
}
m_part =
"uniform float uNoiseSeed; \n"
"lowp float snoise() \n"
"{ \n"
" mediump vec2 coord = floor(gl_FragCoord.xy/uScreenScale); \n"
" mediump vec3 p3 = vec3(uNoiseSeed, coord); \n"
// hash13 from https://www.shadertoy.com/view/4djSRW
" p3 = fract(p3 * .1031); \n"
" p3 += dot(p3, p3.zyx + 31.32); \n"
" return fract((p3.x + p3.y) * p3.z); \n"
"} \n"
;
}
};

Expand Down Expand Up @@ -1067,7 +1059,6 @@ class ShaderDither : public ShaderPart
"} \n"
"lowp vec3 snoiseRGB() \n"
"{ \n"
" mediump vec2 texSize = vec2(640.0, 580.0); \n"
;
if (config.generalEmulation.enableHiresNoiseDithering != 0)
// multiplier for higher res noise effect
Expand All @@ -1077,19 +1068,15 @@ class ShaderDither : public ShaderPart
m_part +=
" lowp float mult = 1.0; \n";
m_part +=
" mediump vec2 coordR = mult * ((gl_FragCoord.xy)/uScreenScale/texSize);\n"
" mediump vec2 coordG = mult * ((gl_FragCoord.xy + vec2( 0.0, texSize.y / 2.0 ))/uScreenScale/texSize);\n"
" mediump vec2 coordB = mult * ((gl_FragCoord.xy + vec2( texSize.x / 2.0, 0.0))/uScreenScale/texSize);\n"
// Only red channel of noise texture contains noise.
" lowp float r = texture(uTexNoise,coordR).r; \n"
" lowp float g = texture(uTexNoise,coordG).r; \n"
" lowp float b = texture(uTexNoise,coordB).r; \n"
" \n"
" return vec3(r,g,b); \n"
"} \n"
" mediump vec2 coord = floor(mult * (gl_FragCoord.xy/uScreenScale)); \n"
" mediump vec3 p3 = vec3(uNoiseSeed, coord); \n"
// hash33 from https://www.shadertoy.com/view/4djSRW
" p3 = fract(p3 * vec3(.1031, .1030, .0973)); \n"
" p3 += dot(p3, p3.yxz+33.33); \n"
" return fract((p3.xxy + p3.yxx)*p3.zyx); \n"
"} \n"
"lowp float snoiseA() \n"
"{ \n"
" mediump vec2 texSize = vec2(640.0, 580.0); \n"
;
if (config.generalEmulation.enableHiresNoiseDithering != 0)
// multiplier for higher res noise effect
Expand All @@ -1100,10 +1087,12 @@ class ShaderDither : public ShaderPart
" lowp float mult = 1.0; \n";
m_part +=
" \n"
" mediump vec2 coord = mult * ((gl_FragCoord.xy)/uScreenScale/texSize);\n"
" \n"
// Only red channel of noise texture contains noise.
" return texture(uTexNoise,coord).r; \n"
" mediump vec2 coord = floor(mult * (gl_FragCoord.xy/uScreenScale)); \n"
" mediump vec3 p3 = vec3(uNoiseSeed, coord); \n"
// hash13 from https://www.shadertoy.com/view/4djSRW
" p3 = fract(p3 * .1031); \n"
" p3 += dot(p3, p3.zyx + 31.32); \n"
" return fract((p3.x + p3.y) * p3.z); \n"
"} \n"
;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void CombinerProgramUniformFactory::buildUniforms(GLuint _program,
const CombinerKey &_key,
UniformGroups &_uniforms) {

_addNoiseTex(_program, _uniforms);
_addNoiseSeed(_program, _uniforms);
_addScreenSpaceTriangleInfo(_program, _uniforms);
_addRasterInfo(_program, _uniforms);
_addViewportInfo(_program, _uniforms);
Expand Down Expand Up @@ -71,7 +71,7 @@ void CombinerProgramUniformFactory::buildUniforms(GLuint _program,

_addBlendCvg(_program, _uniforms);

_addDitherMode(_program, _uniforms, _inputs.usesNoise());
_addDitherMode(_program, _uniforms);

_addScreenScale(_program, _uniforms);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class CombinerProgramUniformFactory {
UniformGroups &_uniforms);

private:
virtual void _addNoiseTex(GLuint _program, UniformGroups &_uniforms) const = 0;
virtual void _addNoiseSeed(GLuint _program, UniformGroups &_uniforms) const = 0;

virtual void _addScreenSpaceTriangleInfo(GLuint _program, UniformGroups &_uniforms) const = 0;

Expand Down Expand Up @@ -55,7 +55,7 @@ class CombinerProgramUniformFactory {

virtual void _addBlendCvg(GLuint _program, UniformGroups &_uniforms) const = 0;

virtual void _addDitherMode(GLuint _program, UniformGroups &_uniforms, bool _usesNoise) const = 0;
virtual void _addDitherMode(GLuint _program, UniformGroups &_uniforms) const = 0;

virtual void _addScreenScale(GLuint _program, UniformGroups &_uniforms) const = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <Graphics/Context.h>

#include <Textures.h>
#include <NoiseTexture.h>
#include <FrameBuffer.h>
#include <DisplayWindow.h>
#include <RSP.h>
Expand All @@ -15,20 +14,21 @@ namespace {
using namespace glsl;
/*---------------UniformGroup-------------*/

class UNoiseTex : public UniformGroup
class UNoiseSeed : public UniformGroup
{
public:
UNoiseTex(GLuint _program) {
LocateUniform(uTexNoise);
UNoiseSeed(GLuint _program) {
LocateUniform(uNoiseSeed);
}

void update(bool _force) override
{
uTexNoise.set(int(graphics::textureIndices::NoiseTex), _force);
u32 counter = dwnd().getBuffersSwapCount();
uNoiseSeed.set(counter & 0xff, _force);
}

private:
iUniform uTexNoise;
fUniform uNoiseSeed;
};

class UDepthTex : public UniformGroup
Expand Down Expand Up @@ -323,8 +323,7 @@ class UBlendCvg : public UniformGroup
class UDitherMode : public UniformGroup
{
public:
UDitherMode(GLuint _program, bool _usesNoise)
: m_usesNoise(_usesNoise)
UDitherMode(GLuint _program)
{
LocateUniform(uAlphaCompareMode);
LocateUniform(uAlphaDitherMode);
Expand All @@ -343,18 +342,12 @@ class UDitherMode : public UniformGroup
uAlphaDitherMode.set(0, _force);
uColorDitherMode.set(0, _force);
}

bool updateNoiseTex = m_usesNoise;
updateNoiseTex |= (gDP.otherMode.cycleType < G_CYC_COPY) && (gDP.otherMode.colorDither == G_CD_NOISE || gDP.otherMode.alphaDither == G_AD_NOISE || gDP.otherMode.alphaCompare == G_AC_DITHER);
if (updateNoiseTex)
g_noiseTexture.update();
}

private:
iUniform uAlphaCompareMode;
iUniform uAlphaDitherMode;
iUniform uColorDitherMode;
bool m_usesNoise;
};

class UScreenScale : public UniformGroup
Expand Down Expand Up @@ -770,9 +763,9 @@ class ULights : public UniformGroup
/*---------------CombinerProgramUniformFactoryCommon-------------*/
namespace glsl {

void CombinerProgramUniformFactoryCommon::_addNoiseTex(GLuint _program, UniformGroups &_uniforms) const
void CombinerProgramUniformFactoryCommon::_addNoiseSeed(GLuint _program, UniformGroups &_uniforms) const
{
_uniforms.emplace_back(new UNoiseTex(_program));
_uniforms.emplace_back(new UNoiseSeed(_program));
}

void CombinerProgramUniformFactoryCommon::_addScreenSpaceTriangleInfo(GLuint _program, UniformGroups &_uniforms) const
Expand Down Expand Up @@ -845,9 +838,9 @@ void CombinerProgramUniformFactoryCommon::_addBlendCvg(GLuint _program, UniformG
_uniforms.emplace_back(new UBlendCvg(_program));
}

void CombinerProgramUniformFactoryCommon::_addDitherMode(GLuint _program, UniformGroups &_uniforms, bool _usesNoise) const
void CombinerProgramUniformFactoryCommon::_addDitherMode(GLuint _program, UniformGroups &_uniforms) const
{
_uniforms.emplace_back(new UDitherMode(_program, _usesNoise));
_uniforms.emplace_back(new UDitherMode(_program));
}

void CombinerProgramUniformFactoryCommon::_addScreenScale(GLuint _program, UniformGroups &_uniforms) const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class CombinerProgramUniformFactoryCommon : public CombinerProgramUniformFactory
CombinerProgramUniformFactoryCommon(const opengl::GLInfo & _glInfo);

private:
void _addNoiseTex(GLuint _program, UniformGroups &_uniforms) const override;
void _addNoiseSeed(GLuint _program, UniformGroups &_uniforms) const override;

void _addScreenSpaceTriangleInfo(GLuint _program, UniformGroups &_uniforms) const override;

Expand Down Expand Up @@ -130,7 +130,7 @@ class CombinerProgramUniformFactoryCommon : public CombinerProgramUniformFactory

void _addBlendCvg(GLuint _program, UniformGroups &_uniforms) const override;

void _addDitherMode(GLuint _program, UniformGroups &_uniforms, bool _usesNoise) const override;
void _addDitherMode(GLuint _program, UniformGroups &_uniforms) const override;

void _addScreenScale(GLuint _program, UniformGroups &_uniforms) const override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ struct FramebufferTextureFormatsGLES2 : public graphics::FramebufferTextureForma
colorFormatBytes = 2;
}

noiseInternalFormat = graphics::internalcolorFormat::LUMINANCE;
noiseFormat = graphics::colorFormat::LUMINANCE;
noiseType = GL_UNSIGNED_BYTE;
noiseFormatBytes = 1;
fontInternalFormat = graphics::internalcolorFormat::LUMINANCE;
fontFormat = graphics::colorFormat::LUMINANCE;
fontType = GL_UNSIGNED_BYTE;
fontFormatBytes = 1;
}
};

Expand Down Expand Up @@ -339,10 +339,10 @@ struct FramebufferTextureFormatsGLES3 : public graphics::FramebufferTextureForma
lutType = GL_UNSIGNED_INT;
lutFormatBytes = 4;

noiseInternalFormat = GL_R8;
noiseFormat = GL_RED;
noiseType = GL_UNSIGNED_BYTE;
noiseFormatBytes = 1;
fontInternalFormat = GL_R8;
fontFormat = GL_RED;
fontType = GL_UNSIGNED_BYTE;
fontFormatBytes = 1;
}
};

Expand Down Expand Up @@ -379,10 +379,10 @@ struct FramebufferTextureFormatsOpenGL : public graphics::FramebufferTextureForm
lutType = GL_UNSIGNED_INT;
lutFormatBytes = 4;

noiseInternalFormat = GL_R8;
noiseFormat = GL_RED;
noiseType = GL_UNSIGNED_BYTE;
noiseFormatBytes = 1;
fontInternalFormat = GL_R8;
fontFormat = GL_RED;
fontType = GL_UNSIGNED_BYTE;
fontFormatBytes = 1;
}
};

Expand Down
9 changes: 4 additions & 5 deletions src/Graphics/OpenGLContext/opengl_Parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ namespace graphics {

namespace textureIndices {
TextureUnitParam Tex[2] = { 0U, 1U };
TextureUnitParam NoiseTex(2U);
TextureUnitParam DepthTex(3U);
TextureUnitParam ZLUTTex(4U);
TextureUnitParam PaletteTex(5U);
TextureUnitParam MSTex[2] = { 6U, 7U };
TextureUnitParam DepthTex(2U);
TextureUnitParam ZLUTTex(3U);
TextureUnitParam PaletteTex(4U);
TextureUnitParam MSTex[2] = { 5U, 6U };
}

namespace textureImageUnits {
Expand Down
1 change: 0 additions & 1 deletion src/Graphics/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ namespace graphics {

namespace textureIndices {
extern TextureUnitParam Tex[2];
extern TextureUnitParam NoiseTex;
extern TextureUnitParam DepthTex;
extern TextureUnitParam ZLUTTex;
extern TextureUnitParam PaletteTex;
Expand Down
3 changes: 0 additions & 3 deletions src/GraphicsDrawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "Performance.h"
#include "TextureFilterHandler.h"
#include "PostProcessor.h"
#include "NoiseTexture.h"
#include "ZlutTexture.h"
#include "PaletteTexture.h"
#include "TextDrawer.h"
Expand Down Expand Up @@ -1959,7 +1958,6 @@ void GraphicsDrawer::_initData()
TFH.init();
PostProcessor::get().init();
g_zlutTexture.init();
g_noiseTexture.init();
g_paletteTexture.init();
perf.reset();
FBInfo::fbInfo.reset();
Expand All @@ -1983,7 +1981,6 @@ void GraphicsDrawer::_destroyData()
m_texrectDrawer.destroy();
g_paletteTexture.destroy();
g_zlutTexture.destroy();
g_noiseTexture.destroy();
PostProcessor::get().destroy();
if (TFH.optionsChanged())
TFH.shutdown();
Expand Down
Loading