mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-07 22:55:40 +12:00
Shadergen: Add clipping
This commit is contained in:
parent
c02b382262
commit
441aa2346c
3 changed files with 32 additions and 10 deletions
|
@ -16,5 +16,6 @@ namespace PICA {
|
||||||
|
|
||||||
alignas(16) vec4 constantColors[tevStageCount];
|
alignas(16) vec4 constantColors[tevStageCount];
|
||||||
alignas(16) vec4 tevBufferColor;
|
alignas(16) vec4 tevBufferColor;
|
||||||
|
alignas(16) vec4 clipCoords;
|
||||||
};
|
};
|
||||||
} // namespace PICA
|
} // namespace PICA
|
|
@ -2,6 +2,18 @@
|
||||||
using namespace PICA;
|
using namespace PICA;
|
||||||
using namespace PICA::ShaderGen;
|
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 FragmentGenerator::getVertexShader(const PICARegs& regs) {
|
||||||
std::string ret = "";
|
std::string ret = "";
|
||||||
|
|
||||||
|
@ -20,6 +32,8 @@ std::string FragmentGenerator::getVertexShader(const PICARegs& regs) {
|
||||||
)";
|
)";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret += uniformDefinition;
|
||||||
|
|
||||||
ret += R"(
|
ret += R"(
|
||||||
layout(location = 0) in vec4 a_coords;
|
layout(location = 0) in vec4 a_coords;
|
||||||
layout(location = 1) in vec4 a_quaternion;
|
layout(location = 1) in vec4 a_quaternion;
|
||||||
|
@ -39,7 +53,9 @@ std::string FragmentGenerator::getVertexShader(const PICARegs& regs) {
|
||||||
out vec3 v_view;
|
out vec3 v_view;
|
||||||
out vec2 v_texcoord2;
|
out vec2 v_texcoord2;
|
||||||
|
|
||||||
//out float gl_ClipDistance[2];
|
#ifndef USING_GLES
|
||||||
|
out float gl_ClipDistance[2];
|
||||||
|
#endif
|
||||||
|
|
||||||
vec4 abgr8888ToVec4(uint abgr) {
|
vec4 abgr8888ToVec4(uint abgr) {
|
||||||
const float scale = 1.0 / 255.0;
|
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_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_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));
|
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
|
#ifndef USING_GLES
|
||||||
uniform sampler1DArray u_tex_lighting_lut;
|
uniform sampler1DArray u_tex_lighting_lut;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
layout(std140) uniform FragmentUniforms {
|
|
||||||
int alphaReference;
|
|
||||||
float depthScale;
|
|
||||||
float depthOffset;
|
|
||||||
|
|
||||||
vec4 constantColors[6];
|
|
||||||
vec4 tevBufferColor;
|
|
||||||
};
|
|
||||||
)";
|
)";
|
||||||
|
|
||||||
|
ret += uniformDefinition;
|
||||||
|
|
||||||
// Emit main function for fragment shader
|
// 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
|
// When not initialized, source 13 is set to vec4(0.0) and 15 is set to the vertex colour
|
||||||
ret += R"(
|
ret += R"(
|
||||||
|
|
|
@ -845,6 +845,13 @@ OpenGL::Program& RendererGL::getSpecializedShader() {
|
||||||
uniforms.depthScale = f24::fromRaw(regs[PICA::InternalRegs::DepthScale] & 0xffffff).toFloat32();
|
uniforms.depthScale = f24::fromRaw(regs[PICA::InternalRegs::DepthScale] & 0xffffff).toFloat32();
|
||||||
uniforms.depthOffset = f24::fromRaw(regs[PICA::InternalRegs::DepthOffset] & 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
|
// Set up the constant color for the 6 TEV stages
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
static constexpr std::array<u32, 6> ioBases = {
|
static constexpr std::array<u32, 6> ioBases = {
|
||||||
|
|
Loading…
Add table
Reference in a new issue