mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-05-18 01:33:58 +12:00
fix: depth transform
This commit is contained in:
parent
b8e155bd4a
commit
5741de2cad
1 changed files with 12 additions and 10 deletions
|
@ -149,6 +149,16 @@ struct DepthUniforms {
|
||||||
bool depthMapEnable;
|
bool depthMapEnable;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: check this
|
||||||
|
float transformZ(float z, float w, constant DepthUniforms& depthUniforms) {
|
||||||
|
z = z / w * depthUniforms.depthScale + depthUniforms.depthOffset;
|
||||||
|
if (!depthUniforms.depthMapEnable) {
|
||||||
|
z *= w;
|
||||||
|
}
|
||||||
|
|
||||||
|
return z * w;
|
||||||
|
}
|
||||||
|
|
||||||
vertex DrawVertexOutWithClip vertexDraw(DrawVertexIn in [[stage_in]], constant PicaRegs& picaRegs [[buffer(0)]], constant VertTEV& tev [[buffer(1)]], constant DepthUniforms& depthUniforms [[buffer(2)]]) {
|
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;
|
||||||
|
|
||||||
|
@ -156,18 +166,9 @@ vertex DrawVertexOutWithClip vertexDraw(DrawVertexIn in [[stage_in]], constant P
|
||||||
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;
|
||||||
out.position.xy /= out.position.w;
|
|
||||||
|
|
||||||
// Apply depth uniforms
|
// Apply depth uniforms
|
||||||
out.position.z = out.position.z * depthUniforms.depthScale + depthUniforms.depthOffset;
|
out.position.z = transformZ(out.position.z, out.position.w, depthUniforms);
|
||||||
// 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;
|
|
||||||
|
|
||||||
// Color
|
// Color
|
||||||
out.color = min(abs(in.color), 1.0);
|
out.color = min(abs(in.color), 1.0);
|
||||||
|
@ -205,6 +206,7 @@ vertex DrawVertexOutWithClip vertexDraw(DrawVertexIn in [[stage_in]], constant P
|
||||||
);
|
);
|
||||||
|
|
||||||
// There's also another, always-on clipping plane based on vertex z
|
// There's also another, always-on clipping plane based on vertex z
|
||||||
|
// TODO: transform
|
||||||
outWithClip.clipDistance[0] = -in.position.z;
|
outWithClip.clipDistance[0] = -in.position.z;
|
||||||
outWithClip.clipDistance[1] = dot(clipData, in.position);
|
outWithClip.clipDistance[1] = dot(clipData, in.position);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue