From 0ff4590404ce64f0408c1875c58e862df649d8eb Mon Sep 17 00:00:00 2001 From: WaluigiWare64 <68647953+WaluigiWare64@users.noreply.github.com> Date: Wed, 3 Feb 2021 18:43:27 +0000 Subject: [PATCH] Fix some OpenGL shaders --- src/GPU3D_OpenGL_shaders.h | 5 ++--- src/GPU_OpenGL.cpp | 2 +- src/GPU_OpenGL_shaders.h | 25 +++++++++++++------------ src/OpenGLSupport.h | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/GPU3D_OpenGL_shaders.h b/src/GPU3D_OpenGL_shaders.h index 894a1615..3a432bec 100644 --- a/src/GPU3D_OpenGL_shaders.h +++ b/src/GPU3D_OpenGL_shaders.h @@ -19,8 +19,7 @@ #ifndef GPU3D_OPENGL_SHADERS_H #define GPU3D_OPENGL_SHADERS_H -#define kShaderHeader "#version 300 es\nprecision mediump float;" - +#include "OpenGLSupport.h" const char* kClearVS = kShaderHeader R"( @@ -241,7 +240,7 @@ flat out ivec3 fPolygonAttr; const char* kRenderFSCommon = R"( -uniform mediump usampler2D TexMem; +uniform usampler2D TexMem; uniform sampler2D TexPalMem; layout(std140) uniform uConfig diff --git a/src/GPU_OpenGL.cpp b/src/GPU_OpenGL.cpp index 81532638..b5531fbf 100644 --- a/src/GPU_OpenGL.cpp +++ b/src/GPU_OpenGL.cpp @@ -24,7 +24,7 @@ #include "NDS.h" #include "GPU.h" #include "Config.h" -#include "OpenGLSupport.h" + #include "GPU_OpenGL_shaders.h" namespace GPU diff --git a/src/GPU_OpenGL_shaders.h b/src/GPU_OpenGL_shaders.h index 5e7641fb..3abcc7f2 100644 --- a/src/GPU_OpenGL_shaders.h +++ b/src/GPU_OpenGL_shaders.h @@ -19,7 +19,9 @@ #ifndef GPU_OPENGL_SHADERS_H #define GPU_OPENGL_SHADERS_H -#define kShaderHeader "#version 300 es\nprecision mediump float;" +#include "OpenGLSupport.h" + +#define kShaderHeader "#version 300 es\nprecision mediump float;\nprecision lowp usampler2D;" const char* kCompositorVS = kShaderHeader R"( @@ -45,7 +47,7 @@ const char* kCompositorFS_Nearest = kShaderHeader R"( uniform uint u3DScale; uniform int u3DXPos; -uniform mediump usampler2D ScreenTex; +uniform usampler2D ScreenTex; uniform sampler2D _3DTex; smooth in vec2 fTexcoord; @@ -76,7 +78,7 @@ void main() float xpos = fTexcoord.x + _3dxpos; float ypos = mod(fTexcoord.y, 192.0); - ivec4 _3dpix = ivec4(texelFetch(_3DTex, ivec2(int(xpos)*int(u3DScale), int(ypos)*int(u3DScale)), 0).bgra + ivec4 _3dpix = ivec4(texelFetch(_3DTex, ivec2(vec2(xpos, ypos)*float(u3DScale)), 0).bgra * vec4(63,63,63,31)); if (_3dpix.a > 0) @@ -97,7 +99,7 @@ void main() float xpos = fTexcoord.x + _3dxpos; float ypos = mod(fTexcoord.y, 192.0); - ivec4 _3dpix = ivec4(texelFetch(_3DTex, ivec2(int(xpos)*int(u3DScale), int(ypos)*int(u3DScale)), 0).bgra + ivec4 _3dpix = ivec4(texelFetch(_3DTex, ivec2(vec2(xpos, ypos)*float(u3DScale)), 0).bgra * vec4(63,63,63,31)); if (_3dpix.a > 0) @@ -117,7 +119,7 @@ void main() float xpos = fTexcoord.x + _3dxpos; float ypos = mod(fTexcoord.y, 192.0); - ivec4 _3dpix = ivec4(texelFetch(_3DTex, ivec2(int(xpos)*int(u3DScale), int(ypos)*int(u3DScale)), 0).bgra + ivec4 _3dpix = ivec4(texelFetch(_3DTex, ivec2(vec2(xpos, ypos)*float(u3DScale)), 0).bgra * vec4(63,63,63,31)); if (_3dpix.a > 0) @@ -180,8 +182,7 @@ out vec4 oColor; ivec4 Get3DPixel(vec2 pos) { - return ivec4(texelFetch(_3DTex, ivec2(pos*u3DScale), 0).bgra - * vec4(63,63,63,31)); + return ivec4(texelFetch(_3DTex, ivec2(pos*float(u3DScale)), 0).bgra * vec4(63,63,63,31)); } ivec4 GetFullPixel(ivec4 val1, ivec4 val2, ivec4 val3, ivec4 _3dpix) @@ -241,7 +242,7 @@ ivec4 GetFullPixel(ivec4 val1, ivec4 val2, ivec4 val3, ivec4 _3dpix) ivec4 imix(ivec4 a, ivec4 b, float x) { - return ivec4(vec4(a)*(1-x) + vec4(b)*x); + return ivec4(vec4(a)*(1.0-x) + vec4(b)*x); } void main() @@ -260,14 +261,14 @@ void main() float xfract = fract(fTexcoord.x); float yfract = fract(fTexcoord.y); - float xpos = val3.r + xfract; - float ypos = mod(fTexcoord.y, 192); + float xpos = float(val3.r) + xfract; + float ypos = mod(fTexcoord.y, 192.0); ivec4 _3dpix = Get3DPixel(vec2(xpos,ypos)); ivec4 p00 = GetFullPixel(val1, val2, val3, _3dpix); - int xdisp = 1 - int(step(255, fTexcoord.x)); - int ydisp = 1 - int(step(191, ypos)); + int xdisp = 1 - int(step(255.0, fTexcoord.x)); + int ydisp = 1 - int(step(191.0, ypos)); ivec4 p01 = GetFullPixel(ivec4(texelFetch(ScreenTex, ivec2(fTexcoord) + ivec2(xdisp+0 ,0), 0)), ivec4(texelFetch(ScreenTex, ivec2(fTexcoord) + ivec2(xdisp+256,0), 0)), diff --git a/src/OpenGLSupport.h b/src/OpenGLSupport.h index cbbb34e1..86bf650d 100644 --- a/src/OpenGLSupport.h +++ b/src/OpenGLSupport.h @@ -24,9 +24,9 @@ #include - #include "Platform.h" +#define kShaderHeader "#version 300 es\nprecision mediump float;\nprecision lowp usampler2D;" namespace OpenGL {