diff --git a/include/PICA/pica_frag_uniforms.hpp b/include/PICA/pica_frag_uniforms.hpp index 616f1882d..332acd4e4 100644 --- a/include/PICA/pica_frag_uniforms.hpp +++ b/include/PICA/pica_frag_uniforms.hpp @@ -16,5 +16,6 @@ namespace PICA { alignas(16) vec4 constantColors[tevStageCount]; alignas(16) vec4 tevBufferColor; + alignas(16) vec4 clipCoords; }; } // namespace PICA \ No newline at end of file diff --git a/src/core/PICA/shader_gen_glsl.cpp b/src/core/PICA/shader_gen_glsl.cpp index d4a4bf8ea..e135ac8eb 100644 --- a/src/core/PICA/shader_gen_glsl.cpp +++ b/src/core/PICA/shader_gen_glsl.cpp @@ -2,6 +2,18 @@ using namespace PICA; using namespace PICA::ShaderGen; +static constexpr const char* uniformDefinition = R"( + layout(std140) uniform FragmentUniforms { + int alphaReference; + float depthScale; + float depthOffset; + + vec4 constantColors[6]; + vec4 tevBufferColor; + vec4 clipCoords; + }; +)"; + std::string FragmentGenerator::getVertexShader(const PICARegs& regs) { std::string ret = ""; @@ -20,6 +32,8 @@ std::string FragmentGenerator::getVertexShader(const PICARegs& regs) { )"; } + ret += uniformDefinition; + ret += R"( layout(location = 0) in vec4 a_coords; layout(location = 1) in vec4 a_quaternion; @@ -39,7 +53,9 @@ std::string FragmentGenerator::getVertexShader(const PICARegs& regs) { out vec3 v_view; out vec2 v_texcoord2; - //out float gl_ClipDistance[2]; + #ifndef USING_GLES + out float gl_ClipDistance[2]; + #endif vec4 abgr8888ToVec4(uint abgr) { const float scale = 1.0 / 255.0; @@ -65,6 +81,11 @@ std::string FragmentGenerator::getVertexShader(const PICARegs& regs) { v_normal = normalize(rotateVec3ByQuaternion(vec3(0.0, 0.0, 1.0), a_quaternion)); v_tangent = normalize(rotateVec3ByQuaternion(vec3(1.0, 0.0, 0.0), a_quaternion)); v_bitangent = normalize(rotateVec3ByQuaternion(vec3(0.0, 1.0, 0.0), a_quaternion)); + + #ifndef USING_GLES + gl_ClipDistance[0] = -a_coords.z; + gl_ClipDistance[1] = dot(clipCoords, a_coords); + #endif } )"; @@ -109,17 +130,10 @@ std::string FragmentGenerator::generate(const PICARegs& regs) { #ifndef USING_GLES uniform sampler1DArray u_tex_lighting_lut; #endif - - layout(std140) uniform FragmentUniforms { - int alphaReference; - float depthScale; - float depthOffset; - - vec4 constantColors[6]; - vec4 tevBufferColor; - }; )"; + ret += uniformDefinition; + // Emit main function for fragment shader // When not initialized, source 13 is set to vec4(0.0) and 15 is set to the vertex colour ret += R"( diff --git a/src/core/renderer_gl/renderer_gl.cpp b/src/core/renderer_gl/renderer_gl.cpp index 207bfbe45..97b642c73 100644 --- a/src/core/renderer_gl/renderer_gl.cpp +++ b/src/core/renderer_gl/renderer_gl.cpp @@ -845,6 +845,13 @@ OpenGL::Program& RendererGL::getSpecializedShader() { uniforms.depthScale = f24::fromRaw(regs[PICA::InternalRegs::DepthScale] & 0xffffff).toFloat32(); uniforms.depthOffset = f24::fromRaw(regs[PICA::InternalRegs::DepthOffset] & 0xffffff).toFloat32(); + if (regs[InternalRegs::ClipEnable] & 1) { + uniforms.clipCoords[0] = f24::fromRaw(regs[PICA::InternalRegs::ClipData0] & 0xffffff).toFloat32(); + uniforms.clipCoords[1] = f24::fromRaw(regs[PICA::InternalRegs::ClipData1] & 0xffffff).toFloat32(); + uniforms.clipCoords[2] = f24::fromRaw(regs[PICA::InternalRegs::ClipData2] & 0xffffff).toFloat32(); + uniforms.clipCoords[3] = f24::fromRaw(regs[PICA::InternalRegs::ClipData3] & 0xffffff).toFloat32(); + } + // Set up the constant color for the 6 TEV stages for (int i = 0; i < 6; i++) { static constexpr std::array ioBases = {