mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 05:19:56 +00:00
Use the light computation/type GE accessors.
This commit is contained in:
parent
988614f6d0
commit
abd9dc6137
@ -415,8 +415,7 @@ void LinkedShader::updateUniforms() {
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (dirtyUniforms & (DIRTY_LIGHT0 << i)) {
|
||||
GELightType type = (GELightType)((gstate.ltype[i] >> 8) & 3);
|
||||
if (type == GE_LIGHTTYPE_DIRECTIONAL) {
|
||||
if (gstate.isDirectionalLight(i)) {
|
||||
// Prenormalize
|
||||
float x = gstate_c.lightpos[i][0];
|
||||
float y = gstate_c.lightpos[i][1];
|
||||
|
@ -117,7 +117,7 @@ void TransformDrawEngine::ApplyDrawState(int prim) {
|
||||
// TODO: All this setup is soon so expensive that we'll need dirty flags, or simply do it in the command writes where we detect dirty by xoring. Silly to do all this work on every drawcall.
|
||||
|
||||
if (gstate_c.textureChanged) {
|
||||
if (gstate.textureMapEnable & 1) {
|
||||
if (gstate.isTextureMapEnabled()) {
|
||||
textureCache_->SetTexture();
|
||||
}
|
||||
gstate_c.textureChanged = false;
|
||||
|
@ -276,11 +276,10 @@ void Lighter::Light(float colorOut0[4], float colorOut1[4], const float colorIn[
|
||||
for (int l = 0; l < 4; l++)
|
||||
{
|
||||
// can we skip this light?
|
||||
if ((gstate.lightEnable[l] & 1) == 0)
|
||||
if (!gstate.isLightChanEnabled(l))
|
||||
continue;
|
||||
|
||||
GELightComputation comp = (GELightComputation)(gstate.ltype[l] & 3);
|
||||
GELightType type = (GELightType)((gstate.ltype[l] >> 8) & 3);
|
||||
GELightType type = gstate.getLightType(l);
|
||||
|
||||
Vec3 toLight(0,0,0);
|
||||
Vec3 lightDir(0,0,0);
|
||||
@ -290,8 +289,8 @@ void Lighter::Light(float colorOut0[4], float colorOut1[4], const float colorIn[
|
||||
else
|
||||
toLight = Vec3(gstate_c.lightpos[l]) - pos;
|
||||
|
||||
bool doSpecular = (comp != GE_LIGHTCOMP_ONLYDIFFUSE);
|
||||
bool poweredDiffuse = comp == GE_LIGHTCOMP_BOTHWITHPOWDIFFUSE;
|
||||
bool doSpecular = gstate.isUsingSpecularLight(l);
|
||||
bool poweredDiffuse = gstate.isUsingPoweredDiffuseLight(l);
|
||||
|
||||
float distanceToLight = toLight.Length();
|
||||
float dot = 0.0f;
|
||||
@ -348,7 +347,7 @@ void Lighter::Light(float colorOut0[4], float colorOut1[4], const float colorIn[
|
||||
}
|
||||
}
|
||||
|
||||
if (gstate.lightEnable[l] & 1)
|
||||
if (gstate.isLightChanEnabled(l))
|
||||
{
|
||||
Color4 lightAmbient(gstate_c.lightColor[0][l], 0.0f);
|
||||
lightSum0 += (lightAmbient * *ambient + diff) * lightScale;
|
||||
@ -922,7 +921,7 @@ int TransformDrawEngine::EstimatePerVertexCost() {
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (gstate.lightEnable[i] & 1)
|
||||
if (gstate.isLightChanEnabled(i))
|
||||
cost += 10;
|
||||
}
|
||||
if (gstate.getUVGenMode() != 0) {
|
||||
|
@ -93,12 +93,12 @@ void ComputeVertexShaderID(VertexShaderID *id, int prim, bool useHWTransform) {
|
||||
if (gstate.isLightingEnabled() || gstate.getUVGenMode() == 2) {
|
||||
// Light bits
|
||||
for (int i = 0; i < 4; i++) {
|
||||
id->d[1] |= (gstate.ltype[i] & 3) << (i * 4);
|
||||
id->d[1] |= ((gstate.ltype[i] >> 8) & 3) << (i * 4 + 2);
|
||||
id->d[1] |= gstate.getLightComputation(i) << (i * 4);
|
||||
id->d[1] |= gstate.getLightType(i) << (i * 4 + 2);
|
||||
}
|
||||
id->d[1] |= (gstate.materialupdate & 7) << 16;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
id->d[1] |= (gstate.lightEnable[i] & 1) << (20 + i);
|
||||
id->d[1] |= (gstate.isLightChanEnabled(i) & 1) << (20 + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -159,7 +159,7 @@ void GenerateVertexShader(int prim, char *buffer, bool useHWTransform) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (i == shadeLight0 || i == shadeLight1)
|
||||
doLight[i] = LIGHT_SHADE;
|
||||
if ((gstate.lightingEnable & 1) && (gstate.lightEnable[i] & 1))
|
||||
if (gstate.isLightingEnabled() && gstate.isLightChanEnabled(i))
|
||||
doLight[i] = LIGHT_FULL;
|
||||
}
|
||||
}
|
||||
@ -222,7 +222,7 @@ void GenerateVertexShader(int prim, char *buffer, bool useHWTransform) {
|
||||
if (doLight[i] == LIGHT_FULL) {
|
||||
// These are needed for the full thing
|
||||
WRITE(p, "uniform mediump vec3 u_lightdir%i;\n", i);
|
||||
GELightType type = (GELightType)((gstate.ltype[i] >> 8) & 3);
|
||||
GELightType type = gstate.getLightType(i);
|
||||
|
||||
if (type != GE_LIGHTTYPE_DIRECTIONAL)
|
||||
WRITE(p, "uniform mediump vec3 u_lightatt%i;\n", i);
|
||||
@ -234,8 +234,7 @@ void GenerateVertexShader(int prim, char *buffer, bool useHWTransform) {
|
||||
WRITE(p, "uniform lowp vec3 u_lightambient%i;\n", i);
|
||||
WRITE(p, "uniform lowp vec3 u_lightdiffuse%i;\n", i);
|
||||
|
||||
GELightComputation comp = (GELightComputation)(gstate.ltype[i] & 3);
|
||||
if (comp != GE_LIGHTCOMP_ONLYDIFFUSE)
|
||||
if (gstate.isUsingSpecularLight(i))
|
||||
WRITE(p, "uniform lowp vec3 u_lightspecular%i;\n", i);
|
||||
}
|
||||
}
|
||||
@ -399,10 +398,9 @@ void GenerateVertexShader(int prim, char *buffer, bool useHWTransform) {
|
||||
if (doLight[i] != LIGHT_FULL)
|
||||
continue;
|
||||
diffuseIsZero = false;
|
||||
GELightComputation comp = (GELightComputation)(gstate.ltype[i] & 3);
|
||||
if (comp != GE_LIGHTCOMP_ONLYDIFFUSE)
|
||||
if (gstate.isUsingSpecularLight(i))
|
||||
specularIsZero = false;
|
||||
GELightType type = (GELightType)((gstate.ltype[i] >> 8) & 3);
|
||||
GELightType type = gstate.getLightType(i);
|
||||
if (type != GE_LIGHTTYPE_DIRECTIONAL)
|
||||
distanceNeeded = true;
|
||||
}
|
||||
@ -427,8 +425,7 @@ void GenerateVertexShader(int prim, char *buffer, bool useHWTransform) {
|
||||
if (doLight[i] != LIGHT_FULL)
|
||||
continue;
|
||||
|
||||
GELightComputation comp = (GELightComputation)(gstate.ltype[i] & 3);
|
||||
GELightType type = (GELightType)((gstate.ltype[i] >> 8) & 3);
|
||||
GELightType type = gstate.getLightType(i);
|
||||
|
||||
if (type == GE_LIGHTTYPE_DIRECTIONAL) {
|
||||
// We prenormalize light positions for directional lights.
|
||||
@ -439,8 +436,8 @@ void GenerateVertexShader(int prim, char *buffer, bool useHWTransform) {
|
||||
WRITE(p, " toLight /= distance;\n");
|
||||
}
|
||||
|
||||
bool doSpecular = (comp != GE_LIGHTCOMP_ONLYDIFFUSE);
|
||||
bool poweredDiffuse = comp == GE_LIGHTCOMP_BOTHWITHPOWDIFFUSE;
|
||||
bool doSpecular = gstate.isUsingSpecularLight(i);
|
||||
bool poweredDiffuse = gstate.isUsingPoweredDiffuseLight(i);
|
||||
|
||||
if (poweredDiffuse) {
|
||||
WRITE(p, " mediump float dot%i = pow(dot(toLight, worldnormal), u_matspecular.a);\n", i);
|
||||
|
@ -249,13 +249,15 @@ struct GPUgstate
|
||||
|
||||
// Lighting
|
||||
bool isLightingEnabled() const { return lightingEnable & 1; }
|
||||
bool isLightChanEnabled(int chan) const { return lightEnable[chan] & 1;}
|
||||
bool isUsingPoweredDiffuseLight(int chan) const { return (ltype[chan] & 0x3) == 0x2; }
|
||||
bool isUsingSpecularLight(int chan) const { return (ltype[chan] & 0x3) == 0x1 || (ltype[chan] & 0x3) == 0x2; }
|
||||
bool isLightChanEnabled(int chan) const { return lightEnable[chan] & 1; }
|
||||
GELightComputation getLightComputation(int chan) const { return static_cast<GELightComputation>(ltype[chan] & 0x3); }
|
||||
bool isUsingPoweredDiffuseLight(int chan) const { return getLightComputation(chan) == GE_LIGHTCOMP_BOTHWITHPOWDIFFUSE; }
|
||||
bool isUsingSpecularLight(int chan) const { return getLightComputation(chan) != GE_LIGHTCOMP_ONLYDIFFUSE; }
|
||||
bool isUsingSecondaryColor() const { return lmode & 1; }
|
||||
bool isDirectionalLight(int chan) const { return ((ltype[chan] & 0x30)>>8) == 0; }
|
||||
bool isPointLight(int chan) const { return ((ltype[chan] & 0x30)>>8) == 1; }
|
||||
bool isSpotLight(int chan) const { return ((ltype[chan] & 0x30)>>8) == 2; }
|
||||
GELightType getLightType(int chan) const { return static_cast<GELightType>((ltype[chan] >> 8) & 3); }
|
||||
bool isDirectionalLight(int chan) const { return getLightType(chan) == GE_LIGHTTYPE_DIRECTIONAL; }
|
||||
bool isPointLight(int chan) const { return getLightType(chan) == GE_LIGHTTYPE_POINT; }
|
||||
bool isSpotLight(int chan) const { return getLightType(chan) == GE_LIGHTTYPE_SPOT; }
|
||||
|
||||
unsigned int getAmbientR() const { return ambientcolor&0xFF; }
|
||||
unsigned int getAmbientG() const { return (ambientcolor>>8)&0xFF; }
|
||||
|
@ -340,7 +340,7 @@ enum GEComparison
|
||||
|
||||
enum GELightType
|
||||
{
|
||||
GE_LIGHTTYPE_DIRECTIONAL=0,
|
||||
GE_LIGHTTYPE_DIRECTIONAL = 0,
|
||||
GE_LIGHTTYPE_POINT = 1,
|
||||
GE_LIGHTTYPE_SPOT = 2
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user