summaryrefslogtreecommitdiff
path: root/tools/ps2test/vu/setup_persp.vu
diff options
context:
space:
mode:
authorclaude-bot <[email protected]>2026-07-13 12:40:03 +0000
committerclaude-bot <[email protected]>2026-07-13 12:40:03 +0000
commit847962910f0bff071f3bf07c9abb87764fb6cac3 (patch)
treeddcd429e134c7fd5f72ddc97ced175de8d66fcd0 /tools/ps2test/vu/setup_persp.vu
downloadlibrw-847962910f0bff071f3bf07c9abb87764fb6cac3.tar.gz
librw-847962910f0bff071f3bf07c9abb87764fb6cac3.zip
Import aap/librw @ masterHEADmaster
Snapshot for re3/reVC vendoring, per @lzcnt. Source: https://github.com/aap/librw (master).
Diffstat (limited to 'tools/ps2test/vu/setup_persp.vu')
-rw-r--r--tools/ps2test/vu/setup_persp.vu39
1 files changed, 39 insertions, 0 deletions
diff --git a/tools/ps2test/vu/setup_persp.vu b/tools/ps2test/vu/setup_persp.vu
new file mode 100644
index 0000000..b9ea42f
--- /dev/null
+++ b/tools/ps2test/vu/setup_persp.vu
@@ -0,0 +1,39 @@
+/* This is the the projection matrix we start with:
+ * 1/2w 0 ox/2w + 1/2 -ox/2w
+ * 0 -1/2h -oy/2h + 1/2 oy/2h
+ * 0 0 1 0
+ * 0 0 1 0
+ * To get rid of the +1/2 in the combined matrix we
+ * subtract the z-row/2 from the x- and y-rows.
+ *
+ * The z-row is then set to [0 0 0 1] such that multiplication
+ * by XYZscale gives [0 0 0 zScale]. After perspective division
+ * and addition of XYZoffset we then get zScale/w + zShift for z.
+ *
+ * XYZScale scales xy to the resolution and z by zScale.
+ * XYZOffset translates xy to the GS coordinate system (where
+ * [2048, 2048] is the center of the frame buffer) and add zShift to z.
+ */
+
+; constant:
+; VF28-VF31 transformation matrix
+; VF25 XYZ offset
+
+
+ SUB.z VF28, VF28, VF28 LOI 0.5 ; right.z = 0
+ SUB.z VF29, VF29, VF29 LQ VF28, matrix(VI00) ; up.z = 0 - load matrix
+ SUB.z VF30, VF30, VF30 LQ VF29, matrix+1(VI00) ; at.z = 0 - load matrix
+ ADDw.z VF31, VF00, VF00 LQ VF30, matrix+2(VI00) ; at.z = 1 - load matrix
+ NOP LQ VF31, matrix+3(VI00) ; - load matrix
+ MULi.w VF20, VF28, I LQ.xyz VF01, XYZScale(VI00) ; fix matrix - load scale
+ MULi.w VF21, VF29, I NOP ; fix matrix
+ MULi.w VF22, VF30, I NOP ; fix matrix
+ MULi.w VF23, VF31, I NOP ; fix matrix
+ SUBw.xy VF28, VF28, VF20 NOP ; fix matrix
+ SUBw.xy VF29, VF29, VF21 NOP ; fix matrix
+ SUBw.xy VF30, VF30, VF22 NOP ; fix matrix
+ SUBw.xy VF31, VF31, VF23 NOP ; fix matrix
+ MUL.xy VF28, VF28, VF01 LQ.xyz VF25, XYZOffset(VI00) ; scale matrix
+ MUL.xy VF29, VF29, VF01 IADDIU VI12, VI00, outBuf1 ; scale matrix
+ MUL.xy VF30, VF30, VF01 IADDIU VI13, VI00, outBuf2 ; scale matrix
+ MUL.xyz VF31, VF31, VF01 NOP ; scale matrix