Implemented transforming of normals on PS2.

This commit is contained in:
Angelo Papenhoff 2015-01-28 21:15:49 +01:00
parent 5247d1c26e
commit 652c82424a
6 changed files with 55 additions and 35 deletions

View File

@ -14,7 +14,7 @@ ASFLAGS = -c -xassembler-with-cpp
LDFLAGS = -mno-crt0 $(LIBPATH) LDFLAGS = -mno-crt0 $(LIBPATH)
OUT=test OUT=test
C_SRC=main.cpp gs.cpp dma.cpp math.cpp mesh.cpp C_SRC=main.cpp gs.cpp dma.cpp math.cpp
#S_SRC=crt0.s low.s #S_SRC=crt0.s low.s
HEADER=dma.h ee_regs.h gif.h gs.h mips_regs.h ps2.h math.h mesh.h HEADER=dma.h ee_regs.h gif.h gs.h mips_regs.h ps2.h math.h mesh.h
OBJ=$(C_SRC:.cpp=.o) $(S_SRC:.s=.o) vu.o defaultpipe.o skinpipe.o OBJ=$(C_SRC:.cpp=.o) $(S_SRC:.s=.o) vu.o defaultpipe.o skinpipe.o

View File

@ -10,7 +10,8 @@
.equ outSize, ((vertexTop-outBuf1-2)/2) .equ outSize, ((vertexTop-outBuf1-2)/2)
.equ outBuf2, (outBuf1+outSize) .equ outBuf2, (outBuf1+outSize)
.equ lightDir, 0x3d0 .equ lightMat, 0x3d0
.equ lightDir, 0x3d4
.equ matrix, 0x3f0 .equ matrix, 0x3f0
.equ screenOffset, 0x3f9 .equ screenOffset, 0x3f9
.equ gifTag, 0x3fa .equ gifTag, 0x3fa
@ -40,6 +41,9 @@ Cnt:
NOP SQ VF01, 0(VI12) NOP SQ VF01, 0(VI12)
NOP ISW.x VI05, 0(VI12) NOP ISW.x VI05, 0(VI12)
NOP IADDIU VI03, VI12, 1 ; output pointer NOP IADDIU VI03, VI12, 1 ; output pointer
NOP LQ VF18, lightMat(VI00)
NOP LQ VF19, lightMat+1(VI00)
NOP LQ VF20, lightMat+2(VI00)
Loop: Loop:
NOP LQI VF01, (VI02++) ; vertex NOP LQI VF01, (VI02++) ; vertex
@ -47,7 +51,7 @@ Loop:
NOP LQI VF02, (VI02++) ; color NOP LQI VF02, (VI02++) ; color
NOP LQI VF03, (VI02++) ; normal NOP LQI VF03, (VI02++) ; normal
MULAw.xyzw ACC, VF31, VF00w NOP MULAw.xyzw ACC, VF31, VF00w NOP ; transform vertex
MADDAx.xyzw ACC, VF28, VF01x NOP MADDAx.xyzw ACC, VF28, VF01x NOP
MADDAy.xyzw ACC, VF29, VF01y NOP MADDAy.xyzw ACC, VF29, VF01y NOP
MADDz.xyzw VF01, VF30, VF01z NOP MADDz.xyzw VF01, VF30, VF01z NOP
@ -61,15 +65,15 @@ Loop:
NOP NOP NOP NOP
NOP NOP NOP NOP
SUB.w VF01, VF01, VF01 NOP SUB.w VF01, VF01, VF01 NOP
NOP SQ VF03, -1(VI02) ; store scaled normal MULAx.xyz ACC, VF18, VF03x NOP ; transform normal
NOP NOP MADDAy.xyz ACC, VF19, VF03y NOP
NOP NOP MADDz.xyz VF03, VF20, VF03z NOP
ADD.xy VF01, VF01, VF25 NOP ADD.xy VF01, VF01, VF25 NOP
NOP NOP NOP NOP
NOP NOP NOP NOP
FTOI0 VF02, VF02 NOP FTOI0 VF02, VF02 NOP
FTOI4 VF01, VF01 NOP FTOI4 VF01, VF01 NOP
NOP NOP NOP SQ VF03, -1(VI02) ; store normal
NOP IADDI VI01, VI01, -1 NOP IADDI VI01, VI01, -1
NOP SQI VF02, (VI03++) ; color NOP SQI VF02, (VI03++) ; color
NOP SQI VF01, (VI03++) ; vertex NOP SQI VF01, (VI03++) ; vertex

View File

@ -13,12 +13,14 @@
#include "gs.h" #include "gs.h"
#include "math.h" #include "math.h"
#include "mesh.h"
using namespace std; using namespace std;
Matrix projMat, viewMat, worldMat;
extern uint32 MyDmaPacket[]; extern uint32 MyDmaPacket[];
extern Matrix vuMat; extern Matrix vuMat;
extern Matrix vuLightMat;
extern float vuOffset[]; extern float vuOffset[];
extern uint64 vuGIFtag[]; extern uint64 vuGIFtag[];
extern float vuMatcolor[]; extern float vuMatcolor[];
@ -38,22 +40,27 @@ drawAtomic(rw::Atomic *atomic)
assert(geo->instData != NULL); assert(geo->instData != NULL);
rw::ps2::InstanceDataHeader *instData = rw::ps2::InstanceDataHeader *instData =
(rw::ps2::InstanceDataHeader*)geo->instData; (rw::ps2::InstanceDataHeader*)geo->instData;
rw::MeshHeader *meshHeader = geo->meshHeader;
rw::Mesh *mesh;
uint8 *color;
atomic->frame->updateLTM(); atomic->frame->updateLTM();
matCopy(vuLightMat, atomic->frame->ltm);
matMult(vuMat, atomic->frame->ltm); matMult(vuMat, atomic->frame->ltm);
rw::Skin *skin = *PLUGINOFFSET(rw::Skin*, geo, rw::skinGlobals.offset);
for(int i = 0; i < instData->numMeshes; i++){ for(int i = 0; i < instData->numMeshes; i++){
if(instData->instanceMeshes[i].arePointersFixed == 0) if(instData->instanceMeshes[i].arePointersFixed == 0)
rw::ps2::fixDmaOffsets(&instData->instanceMeshes[i]); rw::ps2::fixDmaOffsets(&instData->instanceMeshes[i]);
geometryCall[1] = (uint32)instData->instanceMeshes[i].data; geometryCall[1] = (uint32)instData->instanceMeshes[i].data;
mesh = &meshHeader->mesh[i];
color = mesh->material->color;
vuGIFtag[0] = MAKE_GIF_TAG(0,1,1,0xC,0,2); vuGIFtag[0] = MAKE_GIF_TAG(0,1,1,0xC,0,2);
vuGIFtag[1] = 0x41; vuGIFtag[1] = 0x41;
vuMatcolor[0] = 1.0f; vuMatcolor[0] = color[0]/255.0f;
vuMatcolor[1] = 1.0f; vuMatcolor[1] = color[1]/255.0f;
vuMatcolor[2] = 1.0f; vuMatcolor[2] = color[2]/255.0f;
vuMatcolor[3] = 0.5f; vuMatcolor[3] = color[3]/2.0f/255.0f;
rw::Skin *skin =
*PLUGINOFFSET(rw::Skin*, geo, rw::skinGlobals.offset);
if(rw::skinGlobals.offset && skin){ if(rw::skinGlobals.offset && skin){
geometryCall[3] = 0x020000DC; geometryCall[3] = 0x020000DC;
mpgCall[1] = (uint32)skinPipe; mpgCall[1] = (uint32)skinPipe;
@ -79,17 +86,16 @@ draw(void)
gsClear(); gsClear();
matMakeIdentity(mathModelViewMat); matMakeIdentity(viewMat);
matTranslate(mathModelViewMat, 0.0f, 0.0f, -34.0f); // matTranslate(viewMat, 0.0f, 0.0f, -34.0f);
// matTranslate(mathModelViewMat, 0.0f, 0.0f, -10.0f); // matTranslate(viewMat, 0.0f, 0.0f, -10.0f);
// matTranslate(mathModelViewMat, 0.0f, 0.0f, -8.0f); matTranslate(viewMat, 0.0f, 0.0f, -8.0f);
matRotateX(mathModelViewMat, rot); matRotateX(viewMat, rot);
matRotateY(mathModelViewMat, rot); matRotateY(viewMat, rot);
matRotateZ(mathModelViewMat, rot); matRotateZ(viewMat, rot);
matInverse(mathNormalMat, mathModelViewMat);
matCopy(vuMat, mathProjectionMat); matCopy(vuMat, projMat);
matMult(vuMat, mathModelViewMat); matMult(vuMat, viewMat);
for(int i = 0; i < clump->numAtomics; i++){ for(int i = 0; i < clump->numAtomics; i++){
char *name = PLUGINOFFSET(char, clump->atomicList[i]->frame, char *name = PLUGINOFFSET(char, clump->atomicList[i]->frame,
@ -138,8 +144,8 @@ main()
// rw::StreamFile in; // rw::StreamFile in;
// in.open("host:player-vc-ps2.dff", "rb"); // in.open("host:player-vc-ps2.dff", "rb");
// FILE *cf = fopen("host:player-vc-ps2.dff", "rb"); FILE *cf = fopen("host:player-vc-ps2.dff", "rb");
FILE *cf = fopen("host:od_newscafe_dy-ps2.dff", "rb"); // FILE *cf = fopen("host:od_newscafe_dy-ps2.dff", "rb");
// FILE *cf = fopen("host:admiral-ps2.dff", "rb"); // FILE *cf = fopen("host:admiral-ps2.dff", "rb");
assert(cf != NULL); assert(cf != NULL);
fseek(cf, 0, SEEK_END); fseek(cf, 0, SEEK_END);
@ -194,7 +200,7 @@ main()
// matPerspective(mathProjectionMat, 60.0f, (float)gss.width/gss.dh, // matPerspective(mathProjectionMat, 60.0f, (float)gss.width/gss.dh,
// matPerspective(mathProjectionMat, 60.0f, 4.0/3.0, 1.0f, 100.0f); // matPerspective(mathProjectionMat, 60.0f, 4.0/3.0, 1.0f, 100.0f);
// matPerspective(mathProjectionMat, 60.0f, 16.0/9.0, 1.0f, 100.0f); // matPerspective(mathProjectionMat, 60.0f, 16.0/9.0, 1.0f, 100.0f);
matPerspective2(mathProjectionMat, 60.0f, 4.0/3.0, gss.width,gss.height, matPerspective2(projMat, 60.0f, 4.0/3.0, gss.width,gss.height,
1.0f, 100.0f, 16777216, 1); 1.0f, 100.0f, 16777216, 1);
for(;;){ for(;;){

View File

@ -3,9 +3,9 @@
#include <math.h> #include <math.h>
#include "math.h" #include "math.h"
Matrix mathModelViewMat; //Matrix mathModelViewMat;
Matrix mathNormalMat; //Matrix mathNormalMat;
Matrix mathProjectionMat; //Matrix mathProjectionMat;
void void
matDump(Matrix m) matDump(Matrix m)

View File

@ -10,7 +10,8 @@
.equ outSize, ((vertexTop-outBuf1-2)/2) .equ outSize, ((vertexTop-outBuf1-2)/2)
.equ outBuf2, (outBuf1+outSize) .equ outBuf2, (outBuf1+outSize)
.equ lightDir, 0x3d0 .equ lightMat, 0x3d0
.equ lightDir, 0x3d4
.equ matrix, 0x3f0 .equ matrix, 0x3f0
.equ screenOffset, 0x3f9 .equ screenOffset, 0x3f9
.equ gifTag, 0x3fa .equ gifTag, 0x3fa
@ -40,6 +41,9 @@ Cnt:
NOP SQ VF01, 0(VI12) NOP SQ VF01, 0(VI12)
NOP ISW.x VI05, 0(VI12) NOP ISW.x VI05, 0(VI12)
NOP IADDIU VI03, VI12, 1 ; output pointer NOP IADDIU VI03, VI12, 1 ; output pointer
NOP LQ VF18, lightMat(VI00)
NOP LQ VF19, lightMat+1(VI00)
NOP LQ VF20, lightMat+2(VI00)
Loop: Loop:
NOP LQI VF01, (VI02++) ; vertex NOP LQI VF01, (VI02++) ; vertex
@ -62,15 +66,15 @@ Loop:
NOP NOP NOP NOP
NOP NOP NOP NOP
SUB.w VF01, VF01, VF01 NOP SUB.w VF01, VF01, VF01 NOP
NOP SQ VF03, -2(VI02) ; store scaled normal MULAx.xyz ACC, VF18, VF03x NOP ; transform normal
NOP NOP MADDAy.xyz ACC, VF19, VF03y NOP
NOP NOP MADDz.xyz VF03, VF20, VF03z NOP
ADD.xy VF01, VF01, VF25 NOP ADD.xy VF01, VF01, VF25 NOP
NOP NOP NOP NOP
NOP NOP NOP NOP
FTOI0 VF02, VF02 NOP FTOI0 VF02, VF02 NOP
FTOI4 VF01, VF01 NOP FTOI4 VF01, VF01 NOP
NOP NOP NOP SQ VF03, -2(VI02) ; store normal
NOP IADDI VI01, VI01, -1 NOP IADDI VI01, VI01, -1
NOP SQI VF02, (VI03++) ; color NOP SQI VF02, (VI03++) ; color
NOP SQI VF01, (VI03++) ; vertex NOP SQI VF01, (VI03++) ; vertex

View File

@ -1,5 +1,6 @@
.data .data
.global MyDmaPacket .global MyDmaPacket
.global vuLightMat
.global vuMat .global vuMat
.global vuOffset .global vuOffset
.global vuGIFtag .global vuGIFtag
@ -20,6 +21,11 @@ DMAcall *, 0 ;vuProg
DMAcnt * DMAcnt *
UNPACK 4, 4, V4_32, 0x3d0, * UNPACK 4, 4, V4_32, 0x3d0, *
vuLightMat:
.float 1.0, 0.0, 0.0, 0.0
.float 0.0, 1.0, 0.0, 0.0
.float 0.0, 0.0, 1.0, 0.0
.float 0.0, 0.0, 0.0, 1.0
lightDir: lightDir:
.float 0.5, -0.5, -0.70710, 0.0 .float 0.5, -0.5, -0.70710, 0.0
.EndUnpack .EndUnpack