Fixes to lighting, display list base pointer, misc
This commit is contained in:
parent
7f15f02a56
commit
b43dfebb10
7 changed files with 76 additions and 36 deletions
|
@ -282,6 +282,31 @@ void sceKernelIcacheInvalidateAll()
|
|||
}
|
||||
|
||||
|
||||
|
||||
struct SystemStatus {
|
||||
SceSize size;
|
||||
SceUInt status;
|
||||
SceUInt clockPart1;
|
||||
SceUInt clockPart2;
|
||||
SceUInt perfcounter1;
|
||||
SceUInt perfcounter2;
|
||||
SceUInt perfcounter3;
|
||||
};
|
||||
|
||||
|
||||
u32 sceKernelReferSystemStatus(u32 statusPtr)
|
||||
{
|
||||
DEBUG_LOG(HLE, "sceKernelReferSystemStatus(%08x)", statusPtr);
|
||||
if (Memory::IsValidAddress(statusPtr)) {
|
||||
SystemStatus status;
|
||||
memset(&status, 0, sizeof(SystemStatus));
|
||||
status.size = sizeof(SystemStatus);
|
||||
Memory::WriteStruct(statusPtr, &status);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const HLEFunction ThreadManForUser[] =
|
||||
{
|
||||
{0x55C20A00,sceKernelCreateEventFlag, "sceKernelCreateEventFlag"},
|
||||
|
@ -368,7 +393,7 @@ const HLEFunction ThreadManForUser[] =
|
|||
{0x369ed59d,sceKernelGetSystemTimeLow,"sceKernelGetSystemTimeLow"},
|
||||
|
||||
{0x8218B4DD,0,"sceKernelReferGlobalProfiler"},
|
||||
{0x627E6F3A,0,"sceKernelReferSystemStatus"},
|
||||
{0x627E6F3A,&WrapU_U<sceKernelReferSystemStatus>,"sceKernelReferSystemStatus"},
|
||||
{0x64D4540E,0,"sceKernelReferThreadProfiler"},
|
||||
|
||||
//Fifa Street 2 uses alarms
|
||||
|
|
|
@ -341,7 +341,7 @@ public:
|
|||
{
|
||||
if (handle < handleOffset || handle >= handleOffset+maxCount || !occupied[handle-handleOffset])
|
||||
{
|
||||
ERROR_LOG(HLE, "Kernel: Bad object handle");
|
||||
ERROR_LOG(HLE, "Kernel: Bad object handle %i (%08x)", handle, handle);
|
||||
outError = T::GetMissingErrorCode(); // ?
|
||||
return 0;
|
||||
}
|
||||
|
@ -350,7 +350,7 @@ public:
|
|||
T* t = dynamic_cast<T*>(pool[handle - handleOffset]);
|
||||
if (t == 0)
|
||||
{
|
||||
ERROR_LOG(HLE, "Kernel: Wrong type object");
|
||||
ERROR_LOG(HLE, "Kernel: Wrong type object %i (%08x)", handle, handle);
|
||||
outError = T::GetMissingErrorCode(); //FIX
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -259,12 +259,12 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff)
|
|||
break;
|
||||
|
||||
case GE_CMD_VADDR: /// <<8????
|
||||
gstate.vertexAddr = (gstate.base<<8)|data;
|
||||
gstate.vertexAddr = ((gstate.base & 0x00FF0000) << 8)|data;
|
||||
DEBUG_LOG(G3D,"DL VADDR: %06x", gstate.vertexAddr);
|
||||
break;
|
||||
|
||||
case GE_CMD_IADDR:
|
||||
gstate.indexAddr = (gstate.base<<8)|data;
|
||||
gstate.indexAddr = ((gstate.base & 0x00FF0000) << 8)|data;
|
||||
DEBUG_LOG(G3D,"DL IADDR: %06x", gstate.indexAddr);
|
||||
break;
|
||||
|
||||
|
@ -317,7 +317,7 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff)
|
|||
|
||||
case GE_CMD_JUMP:
|
||||
{
|
||||
u32 target = ((gstate.base << 8) | (op & 0xFFFFFC)) & 0x0FFFFFFF;
|
||||
u32 target = (((gstate.base & 0x00FF0000) << 8) | (op & 0xFFFFFC)) & 0x0FFFFFFF;
|
||||
DEBUG_LOG(G3D,"DL CMD JUMP - %08x to %08x", dcontext.pc, target);
|
||||
dcontext.pc = target - 4; // pc will be increased after we return, counteract that
|
||||
}
|
||||
|
@ -327,7 +327,7 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff)
|
|||
{
|
||||
u32 retval = dcontext.pc + 4;
|
||||
stack[stackptr++] = retval;
|
||||
u32 target = ((gstate.base << 8) | (op & 0xFFFFFC)) & 0xFFFFFFF;
|
||||
u32 target = (((gstate.base & 0x00FF0000) << 8) | (op & 0xFFFFFC)) & 0xFFFFFFF;
|
||||
DEBUG_LOG(G3D,"DL CMD CALL - %08x to %08x, ret=%08x", dcontext.pc, target, retval);
|
||||
dcontext.pc = target - 4; // pc will be increased after we return, counteract that
|
||||
}
|
||||
|
@ -354,12 +354,12 @@ void GLES_GPU::ExecuteOp(u32 op, u32 diff)
|
|||
|
||||
case GE_CMD_BJUMP:
|
||||
// bounding box jump. Let's just not jump, for now.
|
||||
DEBUG_LOG(G3D,"DL BBOX JUMP - unimplemented");
|
||||
ERROR_LOG(G3D,"DL BBOX JUMP - unimplemented");
|
||||
break;
|
||||
|
||||
case GE_CMD_BOUNDINGBOX:
|
||||
// bounding box test. Let's do nothing.
|
||||
DEBUG_LOG(G3D,"DL BBOX TEST - unimplemented");
|
||||
ERROR_LOG(G3D,"DL BBOX TEST - unimplemented");
|
||||
break;
|
||||
|
||||
case GE_CMD_ORIGIN:
|
||||
|
|
|
@ -73,13 +73,16 @@ char *GenerateFragmentShader()
|
|||
WRITE(p, "#version 130\n");
|
||||
#endif
|
||||
|
||||
int lmode = gstate.lmode & 1;
|
||||
lmode = 0; /// for now
|
||||
|
||||
if (gstate.textureMapEnable & 1)
|
||||
WRITE(p, "uniform sampler2D tex;\n");
|
||||
if (gstate.alphaTestEnable & 1)
|
||||
WRITE(p, "uniform vec4 u_alpharef;\n");
|
||||
WRITE(p, "uniform vec4 u_texenv;\n");
|
||||
WRITE(p, "varying vec4 v_color0;\n");
|
||||
if (gstate.lmode & 1)
|
||||
if (lmode)
|
||||
WRITE(p, "varying vec4 v_color1;\n");
|
||||
WRITE(p, "varying vec2 v_texcoord;\n");
|
||||
|
||||
|
@ -92,9 +95,12 @@ char *GenerateFragmentShader()
|
|||
else
|
||||
{
|
||||
const char *secondary = "";
|
||||
if (gstate.lmode & 1) {
|
||||
WRITE(p, " vec4 s = vec4(0.0, 0.0, 0.0, 0.0);\n"); // Secondary color, TODO
|
||||
if (lmode) {
|
||||
WRITE(p, "vec4 s = v_color1;");
|
||||
secondary = " + s";
|
||||
} else {
|
||||
WRITE(p, " vec4 s = vec4(0.0, 0.0, 0.0, 0.0);\n"); // Secondary color, TODO
|
||||
secondary = "";
|
||||
}
|
||||
|
||||
if (gstate.textureMapEnable & 1) {
|
||||
|
@ -103,8 +109,8 @@ char *GenerateFragmentShader()
|
|||
WRITE(p, " vec4 p = clamp(v_color0, 0.0, 1.0);\n");
|
||||
} else {
|
||||
// No texture mapping
|
||||
WRITE(p, " vec4 t = v_color0;\n"); //, secondary);
|
||||
WRITE(p, " vec4 p = t;\n"); // , secondary);
|
||||
WRITE(p, " vec4 t = vec4(1.0, 1.0, 1.0, 1.0);\n"); //, secondary);
|
||||
WRITE(p, " vec4 p = clamp(v_color0, 0.0, 1.0);\n"); // , secondary);
|
||||
}
|
||||
|
||||
// Color doubling
|
||||
|
|
|
@ -48,13 +48,15 @@ GLuint glprim[8] =
|
|||
GL_TRIANGLES,
|
||||
GL_TRIANGLE_STRIP,
|
||||
GL_TRIANGLE_FAN,
|
||||
GL_TRIANGLES, // With OpenGL ES we have to expand into triangles, tripling the data instead of doubling. sigh. OpenGL ES, Y U NO SUPPORT GL_QUADS?
|
||||
GL_TRIANGLES, // With OpenGL ES we have to expand sprites into triangles, tripling the data instead of doubling. sigh. OpenGL ES, Y U NO SUPPORT GL_QUADS?
|
||||
};
|
||||
|
||||
DecodedVertex decoded[65536];
|
||||
TransformedVertex transformed[65536];
|
||||
uint16_t indexBuffer[65536]; // Unused
|
||||
|
||||
// TODO: This should really return 2 colors, one for specular and one for diffuse.
|
||||
|
||||
void Light(float colorOut[4], const float colorIn[4], Vec3 pos, Vec3 normal, float dots[4])
|
||||
{
|
||||
// could cache a lot of stuff, such as ambient, across vertices...
|
||||
|
@ -110,9 +112,7 @@ void Light(float colorOut[4], const float colorIn[4], Vec3 pos, Vec3 normal, flo
|
|||
|
||||
float specCoef = getFloat24(gstate.materialspecularcoef);
|
||||
|
||||
norm.Normalize();
|
||||
|
||||
Vec3 viewer(gstate.viewMatrix[8], gstate.viewMatrix[9], gstate.viewMatrix[10]);
|
||||
Vec3 viewer(-gstate.viewMatrix[9], -gstate.viewMatrix[10], -gstate.viewMatrix[11]);
|
||||
|
||||
Color4 lightSum = globalAmbient * ambient + emissive;
|
||||
|
||||
|
@ -122,30 +122,27 @@ void Light(float colorOut[4], const float colorIn[4], Vec3 pos, Vec3 normal, flo
|
|||
for (int l = 0; l < 4; l++)
|
||||
{
|
||||
// can we skip this light?
|
||||
if ((gstate.lightEnable[l] & 1) == 0) // && !doShadeMapping)
|
||||
continue;
|
||||
//if ((gstate.lightEnable[l] & 1) == 0) // && !doShadeMapping)
|
||||
// continue;
|
||||
|
||||
GELightComputation comp = (GELightComputation)(gstate.ltype[l]&3);
|
||||
GELightType type = (GELightType)((gstate.ltype[l]>>8)&3);
|
||||
Vec3 toLight;
|
||||
|
||||
if (type == GE_LIGHTTYPE_DIRECTIONAL)
|
||||
toLight = Vec3(gstate.lightpos[l]);
|
||||
toLight = Vec3(gstate.lightpos[l]); // lightdir is for spotlights
|
||||
else
|
||||
toLight = Vec3(gstate.lightpos[l]) - pos;
|
||||
|
||||
Vec3 dir = Vec3(gstate.lightdir[l]);
|
||||
|
||||
bool doSpecular = (comp != GE_LIGHTCOMP_ONLYDIFFUSE);
|
||||
bool poweredDiffuse = comp == GE_LIGHTCOMP_BOTHWITHPOWDIFFUSE;
|
||||
|
||||
float distance = toLight.Normalize();
|
||||
|
||||
float lightScale = 1.0f;
|
||||
if (type != GE_LIGHTTYPE_DIRECTIONAL)
|
||||
{
|
||||
float distance = toLight.Normalize();
|
||||
lightScale = 1.0f / (gstate.lightatt[l][0] + gstate.lightatt[l][1]*distance + gstate.lightatt[l][2]*distance*distance);
|
||||
if (lightScale>1.0f) lightScale=1.0f;
|
||||
if (lightScale > 1.0f) lightScale = 1.0f;
|
||||
}
|
||||
|
||||
float dot = toLight * norm;
|
||||
|
@ -156,13 +153,18 @@ void Light(float colorOut[4], const float colorIn[4], Vec3 pos, Vec3 normal, flo
|
|||
if (poweredDiffuse)
|
||||
dot = powf(dot, specCoef);
|
||||
|
||||
Color4 diff = (gstate.lightColor[1][l] * diffuse) * (dot*lightScale);
|
||||
Color4 diff = (gstate.lightColor[1][l] * diffuse) * (dot * lightScale);
|
||||
Color4 spec(0,0,0,0);
|
||||
|
||||
// Real PSP specular
|
||||
Vec3 toViewer(0,0,1);
|
||||
// Better specular
|
||||
//Vec3 toViewer = (viewer - pos).Normalized();
|
||||
|
||||
if (doSpecular)
|
||||
{
|
||||
Vec3 halfVec = toLight;
|
||||
halfVec += viewer.Normalized();
|
||||
halfVec += toViewer;
|
||||
halfVec.Normalize();
|
||||
|
||||
dot = halfVec * norm;
|
||||
|
@ -269,11 +271,11 @@ void TransformAndDrawPrim(void *verts, void *inds, int prim, int vertexCount, Li
|
|||
for (int j=0; j<2; j++)
|
||||
uv[j] = decoded[index].uv[j];
|
||||
|
||||
//Rescale UV?
|
||||
// Rescale UV?
|
||||
}
|
||||
else
|
||||
{
|
||||
//We do software T&L for now
|
||||
// We do software T&L for now
|
||||
float out[3], norm[3];
|
||||
if ((gstate.vertType & GE_VTYPE_WEIGHT_MASK) == GE_VTYPE_WEIGHT_NONE)
|
||||
{
|
||||
|
@ -312,14 +314,14 @@ void TransformAndDrawPrim(void *verts, void *inds, int prim, int vertexCount, Li
|
|||
else
|
||||
{
|
||||
// no lighting? copy the color.
|
||||
for (int j=0; j<4; j++)
|
||||
for (int j = 0; j < 4; j++)
|
||||
c[j] = decoded[index].color[j];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// no color in the fragment program???
|
||||
for (int j=0; j<4; j++)
|
||||
for (int j = 0; j < 4; j++)
|
||||
c[j] = decoded[index].color[j];
|
||||
}
|
||||
|
||||
|
|
|
@ -294,7 +294,7 @@ void VertexDecoder::DecodeVerts(DecodedVertex *decoded, const void *verts, const
|
|||
}
|
||||
}
|
||||
|
||||
if (gstate.reversenormals)
|
||||
if (gstate.reversenormals & 0xFFFFFF)
|
||||
{
|
||||
for (int j = 0; j < 3; j++)
|
||||
normal[j] = -normal[j];
|
||||
|
|
|
@ -59,19 +59,26 @@ char *GenerateVertexShader()
|
|||
WRITE("#version 130");
|
||||
#endif
|
||||
|
||||
int lmode = gstate.lmode & 1;
|
||||
lmode = 0; // TODO: support separate specular
|
||||
|
||||
WRITE("attribute vec4 a_position;");
|
||||
WRITE("attribute vec2 a_texcoord;");
|
||||
WRITE("attribute vec4 a_color0;");
|
||||
if (lmode)
|
||||
WRITE("attribute vec4 a_color1;");
|
||||
|
||||
WRITE("uniform mat4 u_proj;");
|
||||
|
||||
WRITE("varying vec4 v_color0;");
|
||||
if (lmode)
|
||||
WRITE("varying vec4 v_color1;");
|
||||
WRITE("varying vec2 v_texcoord;");
|
||||
|
||||
WRITE("void main() {");
|
||||
WRITE("v_color0 = a_color0;");
|
||||
WRITE("v_color1 = a_color0;");
|
||||
if (lmode)
|
||||
WRITE("v_color1 = a_color1;");
|
||||
WRITE("v_texcoord = a_texcoord;");
|
||||
WRITE("gl_Position = u_proj * a_position;");
|
||||
WRITE("}");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue