mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-05-13 23:35:06 +12:00
implement depth uniforms
This commit is contained in:
parent
e8727d5dbd
commit
13439699ee
2 changed files with 28 additions and 5 deletions
src
|
@ -369,6 +369,16 @@ void RendererMTL::drawVertices(PICA::PrimType primType, std::span<const PICA::Ve
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Depth uniforms
|
||||||
|
struct {
|
||||||
|
float depthScale;
|
||||||
|
float depthOffset;
|
||||||
|
bool depthMapEnable;
|
||||||
|
} depthUniforms;
|
||||||
|
depthUniforms.depthScale = Floats::f24::fromRaw(regs[PICA::InternalRegs::DepthScale] & 0xffffff).toFloat32();
|
||||||
|
depthUniforms.depthOffset = Floats::f24::fromRaw(regs[PICA::InternalRegs::DepthOffset] & 0xffffff).toFloat32();
|
||||||
|
depthUniforms.depthMapEnable = regs[PICA::InternalRegs::DepthmapEnable] & 1;
|
||||||
|
|
||||||
// -------- Pipeline --------
|
// -------- Pipeline --------
|
||||||
Metal::PipelineHash pipelineHash{colorRenderTarget->format, DepthFmt::Unknown1};
|
Metal::PipelineHash pipelineHash{colorRenderTarget->format, DepthFmt::Unknown1};
|
||||||
if (depthStencilRenderTarget) {
|
if (depthStencilRenderTarget) {
|
||||||
|
@ -436,6 +446,7 @@ void RendererMTL::drawVertices(PICA::PrimType primType, std::span<const PICA::Ve
|
||||||
bindTexturesToSlots(renderCommandEncoder);
|
bindTexturesToSlots(renderCommandEncoder);
|
||||||
renderCommandEncoder->setVertexBytes(®s[0x48], (0x200 - 0x48) * sizeof(regs[0]), 0);
|
renderCommandEncoder->setVertexBytes(®s[0x48], (0x200 - 0x48) * sizeof(regs[0]), 0);
|
||||||
renderCommandEncoder->setFragmentBytes(®s[0x48], (0x200 - 0x48) * sizeof(regs[0]), 0);
|
renderCommandEncoder->setFragmentBytes(®s[0x48], (0x200 - 0x48) * sizeof(regs[0]), 0);
|
||||||
|
renderCommandEncoder->setVertexBytes(&depthUniforms, sizeof(depthUniforms), 2);
|
||||||
renderCommandEncoder->setFragmentBytes(&logicOp, sizeof(logicOp), 2);
|
renderCommandEncoder->setFragmentBytes(&logicOp, sizeof(logicOp), 2);
|
||||||
|
|
||||||
renderCommandEncoder->drawPrimitives(toMTLPrimitiveType(primType), NS::UInteger(0), NS::UInteger(vertices.size()));
|
renderCommandEncoder->drawPrimitives(toMTLPrimitiveType(primType), NS::UInteger(0), NS::UInteger(vertices.size()));
|
||||||
|
|
|
@ -143,17 +143,31 @@ float decodeFP(uint hex, uint E, uint M) {
|
||||||
return as_type<float>(hex);
|
return as_type<float>(hex);
|
||||||
}
|
}
|
||||||
|
|
||||||
vertex DrawVertexOutWithClip vertexDraw(DrawVertexIn in [[stage_in]], constant PicaRegs& picaRegs [[buffer(0)]], constant VertTEV& tev [[buffer(1)]]) {
|
struct DepthUniforms {
|
||||||
|
float depthScale;
|
||||||
|
float depthOffset;
|
||||||
|
bool depthMapEnable;
|
||||||
|
};
|
||||||
|
|
||||||
|
vertex DrawVertexOutWithClip vertexDraw(DrawVertexIn in [[stage_in]], constant PicaRegs& picaRegs [[buffer(0)]], constant VertTEV& tev [[buffer(1)]], constant DepthUniforms& depthUniforms [[buffer(2)]]) {
|
||||||
DrawVertexOut out;
|
DrawVertexOut out;
|
||||||
|
|
||||||
// Position
|
// Position
|
||||||
out.position = in.position;
|
out.position = in.position;
|
||||||
// Flip the y position
|
// Flip the y position
|
||||||
out.position.y = -out.position.y;
|
out.position.y = -out.position.y;
|
||||||
// in.position.z is in range of [-1 ... 1], convert it to [0 ... 1]
|
|
||||||
out.position.xyz /= out.position.w;
|
out.position.xyz /= out.position.w;
|
||||||
|
|
||||||
|
// Apply depth uniforms
|
||||||
|
out.position.z = out.position.z * depthUniforms.depthScale + depthUniforms.depthOffset;
|
||||||
|
// TODO: is this correct?
|
||||||
|
if (!depthUniforms.depthMapEnable) { // Divide z by w if depthmap enable == 0 (ie using W-buffering)
|
||||||
|
out.position.z /= out.position.w;
|
||||||
|
}
|
||||||
|
|
||||||
|
// in.position.z is in range of [-1, 1], convert it to [0, 1]
|
||||||
|
out.position.z = (out.position.z + 1.0) * 0.5;
|
||||||
out.position.w = 1.0;
|
out.position.w = 1.0;
|
||||||
out.position.z = (-out.position.z + 1.0) * 0.5;
|
|
||||||
|
|
||||||
// Color
|
// Color
|
||||||
out.color = min(abs(in.color), 1.0);
|
out.color = min(abs(in.color), 1.0);
|
||||||
|
@ -560,8 +574,6 @@ fragment float4 fragmentDraw(DrawVertexOut in [[stage_in]], float4 prevColor [[c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: depth
|
|
||||||
|
|
||||||
float4 color = performLogicOp(logicOp, globals.tevSources[15], prevColor);
|
float4 color = performLogicOp(logicOp, globals.tevSources[15], prevColor);
|
||||||
|
|
||||||
// Perform alpha test
|
// Perform alpha test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue