mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-14 18:15:28 -04:00
Merge pull request #1332 from whatsavalue3/master
Improve PS1 Rendering
This commit is contained in:
commit
a07478f468
@ -39,8 +39,10 @@ extern cc_string Game_Mppass;
|
|||||||
|
|
||||||
#if defined CC_BUILD_N64
|
#if defined CC_BUILD_N64
|
||||||
#define DEFAULT_VIEWDIST 20
|
#define DEFAULT_VIEWDIST 20
|
||||||
#elif defined CC_BUILD_NDS || defined CC_BUILD_PS1 || defined CC_BUILD_SATURN
|
#elif defined CC_BUILD_NDS || defined CC_BUILD_SATURN
|
||||||
#define DEFAULT_VIEWDIST 192
|
#define DEFAULT_VIEWDIST 192
|
||||||
|
#elif defined CC_BUILD_PS1
|
||||||
|
#define DEFAULT_VIEWDIST 64
|
||||||
#else
|
#else
|
||||||
#define DEFAULT_VIEWDIST 512
|
#define DEFAULT_VIEWDIST 512
|
||||||
#endif
|
#endif
|
||||||
|
@ -486,7 +486,16 @@ static void PreprocessTexturedVertices(void) {
|
|||||||
dst->z = XYZFixed(src->z);
|
dst->z = XYZFixed(src->z);
|
||||||
|
|
||||||
u = src->U * 0.99f;
|
u = src->U * 0.99f;
|
||||||
v = src->V == 1.0f ? 0.99f : src->V;
|
if(src->V == 1.0f)
|
||||||
|
{
|
||||||
|
v = 0.99f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
v = src->V;
|
||||||
|
}
|
||||||
|
//u = src->U * 0.99f;
|
||||||
|
//v = src->V == 1.0f ? 0.99f : src->V;
|
||||||
|
|
||||||
dst->u = UVFixed(u);
|
dst->u = UVFixed(u);
|
||||||
dst->v = UVFixed(v);
|
dst->v = UVFixed(v);
|
||||||
@ -707,6 +716,26 @@ static int Transform(IVec3* result, struct PS1VertexTextured* a) {
|
|||||||
result->y = (y * -120 / w) + 120;
|
result->y = (y * -120 / w) + 120;
|
||||||
result->z = (z * OT_LENGTH / w);
|
result->z = (z * OT_LENGTH / w);
|
||||||
|
|
||||||
|
if(result->x > 640)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if(result->x < -320)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(result->y > 480)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if(result->y < -240)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*SVECTOR coord;
|
/*SVECTOR coord;
|
||||||
POLY_FT4 poly;
|
POLY_FT4 poly;
|
||||||
coord.vx = a->x; coord.vy = a->y; coord.vz = a->z;
|
coord.vx = a->x; coord.vy = a->y; coord.vz = a->z;
|
||||||
@ -831,7 +860,29 @@ static void DrawTexturedQuad(struct PS1VertexTextured* v0, struct PS1VertexTextu
|
|||||||
|
|
||||||
static CC_NOINLINE void SubdivideQuad(struct PS1VertexTextured* v0, struct PS1VertexTextured* v1,
|
static CC_NOINLINE void SubdivideQuad(struct PS1VertexTextured* v0, struct PS1VertexTextured* v1,
|
||||||
struct PS1VertexTextured* v2, struct PS1VertexTextured* v3, int level) {
|
struct PS1VertexTextured* v2, struct PS1VertexTextured* v3, int level) {
|
||||||
if (level > 2) return;
|
if (level > 5) return;
|
||||||
|
int v1short = 0;
|
||||||
|
int v3short = 0;
|
||||||
|
int diff = v0->x - v1->x;
|
||||||
|
int mask = diff>>31;
|
||||||
|
int vertsize = (diff^mask)-mask;
|
||||||
|
diff = v0->y - v1->y;
|
||||||
|
mask = diff>>31;
|
||||||
|
vertsize += (diff^mask)-mask;
|
||||||
|
diff = v0->z - v1->z;
|
||||||
|
mask = diff>>31;
|
||||||
|
vertsize += (diff^mask)-mask;
|
||||||
|
if(vertsize < 128) v1short = 1;
|
||||||
|
diff = v0->x - v3->x;
|
||||||
|
mask = diff>>31;
|
||||||
|
vertsize = (diff^mask)-mask;
|
||||||
|
diff = v0->y - v3->y;
|
||||||
|
mask = diff>>31;
|
||||||
|
vertsize += (diff^mask)-mask;
|
||||||
|
diff = v0->z - v3->z;
|
||||||
|
mask = diff>>31;
|
||||||
|
vertsize += (diff^mask)-mask;
|
||||||
|
if(vertsize < 128) v3short = 1;
|
||||||
struct PS1VertexTextured m01, m02, m03, m12, m32;
|
struct PS1VertexTextured m01, m02, m03, m12, m32;
|
||||||
|
|
||||||
// v0 --- m01 --- v1
|
// v0 --- m01 --- v1
|
||||||
@ -842,18 +893,54 @@ static CC_NOINLINE void SubdivideQuad(struct PS1VertexTextured* v0, struct PS1Ve
|
|||||||
// | \ | \ |
|
// | \ | \ |
|
||||||
// v3 ----m32---- v2
|
// v3 ----m32---- v2
|
||||||
|
|
||||||
CalcMidpoint(m01, v0, v1);
|
if(v1short)
|
||||||
CalcMidpoint(m02, v0, v2);
|
{
|
||||||
|
if(v3short)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
CalcMidpoint(m03, v0, v3);
|
CalcMidpoint(m03, v0, v3);
|
||||||
CalcMidpoint(m12, v1, v2);
|
CalcMidpoint(m12, v1, v2);
|
||||||
|
|
||||||
|
DrawTexturedQuad( v0, v1, &m12, &m03, level);
|
||||||
|
DrawTexturedQuad(&m03, &m12, v2, v3, level);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(v3short)
|
||||||
|
{
|
||||||
|
CalcMidpoint(m01, v0, v1);
|
||||||
CalcMidpoint(m32, v3, v2);
|
CalcMidpoint(m32, v3, v2);
|
||||||
|
|
||||||
|
DrawTexturedQuad( v0, &m01, &m32, v3, level);
|
||||||
|
DrawTexturedQuad(&m01, v1, v2, &m32, level);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CalcMidpoint(m02, v0, v2);
|
||||||
|
CalcMidpoint(m01, v0, v1);
|
||||||
|
CalcMidpoint(m32, v3, v2);
|
||||||
|
CalcMidpoint(m03, v0, v3);
|
||||||
|
CalcMidpoint(m12, v1, v2);
|
||||||
|
|
||||||
DrawTexturedQuad( v0, &m01, &m02, &m03, level);
|
DrawTexturedQuad( v0, &m01, &m02, &m03, level);
|
||||||
DrawTexturedQuad(&m01, v1, &m12, &m02, level);
|
DrawTexturedQuad(&m01, v1, &m12, &m02, level);
|
||||||
DrawTexturedQuad(&m02, &m12, v2, &m32, level);
|
DrawTexturedQuad(&m02, &m12, v2, &m32, level);
|
||||||
DrawTexturedQuad(&m03, &m02, &m32, v3, level);
|
DrawTexturedQuad(&m03, &m02, &m32, v3, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CrossProduct(IVec3* a, IVec3* b, IVec3* out)
|
||||||
|
{
|
||||||
|
out->x = (a->y*b->z-a->z*b->y) >> 9;
|
||||||
|
out->y = (a->z*b->x-a->x*b->z) >> 9;
|
||||||
|
out->z = (a->x*b->y-a->y*b->x) >> 9;
|
||||||
|
}
|
||||||
|
|
||||||
static CC_INLINE void DrawTexturedQuad(struct PS1VertexTextured* v0, struct PS1VertexTextured* v1,
|
static CC_INLINE void DrawTexturedQuad(struct PS1VertexTextured* v0, struct PS1VertexTextured* v1,
|
||||||
struct PS1VertexTextured* v2, struct PS1VertexTextured* v3, int level) {
|
struct PS1VertexTextured* v2, struct PS1VertexTextured* v3, int level) {
|
||||||
IVec3 coords[4];
|
IVec3 coords[4];
|
||||||
@ -862,9 +949,36 @@ static CC_INLINE void DrawTexturedQuad(struct PS1VertexTextured* v0, struct PS1V
|
|||||||
clipped |= Transform(&coords[1], v1);
|
clipped |= Transform(&coords[1], v1);
|
||||||
clipped |= Transform(&coords[2], v2);
|
clipped |= Transform(&coords[2], v2);
|
||||||
clipped |= Transform(&coords[3], v3);
|
clipped |= Transform(&coords[3], v3);
|
||||||
if (clipped) return;//{ SubdivideQuad(v0, v1, v2, v3, level + 1); return; }
|
|
||||||
|
|
||||||
int p = (coords[0].z + coords[1].z + coords[2].z + coords[3].z) / 4;
|
IVec3 crossprod[2];
|
||||||
|
IVec3 normal;
|
||||||
|
crossprod[0].x = coords[1].x-coords[0].x;
|
||||||
|
crossprod[0].y = coords[1].y-coords[0].y;
|
||||||
|
crossprod[0].z = coords[1].z-coords[0].z;
|
||||||
|
crossprod[1].x = coords[2].x-coords[0].x;
|
||||||
|
crossprod[1].y = coords[2].y-coords[0].y;
|
||||||
|
crossprod[1].z = coords[2].z-coords[0].z;
|
||||||
|
CrossProduct(&crossprod[0],&crossprod[1],&normal);
|
||||||
|
if((normal.x*coords[0].x+normal.y*coords[0].y+normal.z*coords[0].z) > 0) return;
|
||||||
|
|
||||||
|
if (clipped) { SubdivideQuad(v0, v1, v2, v3, level + 1); return; }
|
||||||
|
//int p = (coords[0].z + coords[1].z + coords[2].z + coords[3].z) / 4;
|
||||||
|
|
||||||
|
int p = coords[3].z;
|
||||||
|
if (p < coords[0].z)
|
||||||
|
{
|
||||||
|
p = coords[0].z;
|
||||||
|
}
|
||||||
|
if (p < coords[1].z)
|
||||||
|
{
|
||||||
|
p = coords[1].z;
|
||||||
|
}
|
||||||
|
if (p < coords[2].z)
|
||||||
|
{
|
||||||
|
p = coords[2].z;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (p < 0 || p >= OT_LENGTH) return;
|
if (p < 0 || p >= OT_LENGTH) return;
|
||||||
|
|
||||||
struct CC_POLY_FT4* poly = new_primitive(sizeof(struct CC_POLY_FT4));
|
struct CC_POLY_FT4* poly = new_primitive(sizeof(struct CC_POLY_FT4));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user