mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
Shader simplification: Get rid of lightSum1 when not needed.
This commit is contained in:
parent
b4c01c236b
commit
0ff8be1b1a
1 changed files with 27 additions and 5 deletions
|
@ -364,9 +364,22 @@ void GenerateVertexShader(int prim, char *buffer) {
|
|||
|
||||
if (gstate.isLightingEnabled()) {
|
||||
WRITE(p, " lowp vec4 lightSum0 = u_ambient * %s + vec4(u_matemissive, 0.0);\n", ambient);
|
||||
WRITE(p, " lowp vec3 lightSum1 = vec3(0.0);\n");
|
||||
}
|
||||
|
||||
bool lightSum1IsZero = true;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (doLight[i] != LIGHT_FULL)
|
||||
continue;
|
||||
GELightComputation comp = (GELightComputation)(gstate.ltype[i] & 3);
|
||||
if (comp != GE_LIGHTCOMP_ONLYDIFFUSE) {
|
||||
lightSum1IsZero = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!lightSum1IsZero) {
|
||||
WRITE(p, " lowp vec3 lightSum1 = vec3(0.0);\n");
|
||||
}
|
||||
|
||||
// Calculate lights if needed. If shade mapping is enabled, lights may need to be
|
||||
// at least partially calculated.
|
||||
|
@ -392,7 +405,7 @@ void GenerateVertexShader(int prim, char *buffer) {
|
|||
}
|
||||
|
||||
char timesLightScale[128];
|
||||
sprintf(timesLightScale, " * lightScale%i");
|
||||
sprintf(timesLightScale, " * lightScale%i", i);
|
||||
|
||||
// Attenuation
|
||||
switch (type) {
|
||||
|
@ -428,11 +441,20 @@ void GenerateVertexShader(int prim, char *buffer) {
|
|||
|
||||
if (gstate.isLightingEnabled()) {
|
||||
// Sum up ambient, emissive here.
|
||||
WRITE(p, " v_color0 = clamp(lightSum0, 0.0, 1.0);\n");
|
||||
if (lmode) {
|
||||
WRITE(p, " v_color1 = clamp(lightSum1, 0.0, 1.0);\n");
|
||||
WRITE(p, " v_color0 = clamp(lightSum0, 0.0, 1.0);\n");
|
||||
// v_color1 only exists when lmode = 1.
|
||||
if (lightSum1IsZero) {
|
||||
WRITE(p, " v_color1 = vec3(0.0);\n");
|
||||
} else {
|
||||
WRITE(p, " v_color1 = clamp(lightSum1, 0.0, 1.0);\n");
|
||||
}
|
||||
} else {
|
||||
WRITE(p, " v_color0 = clamp(v_color0 + vec4(lightSum1, 0.0), 0.0, 1.0);\n");
|
||||
if (lightSum1IsZero) {
|
||||
WRITE(p, " v_color0 = clamp(lightSum0, 0.0, 1.0);\n");
|
||||
} else {
|
||||
WRITE(p, " v_color0 = clamp(clamp(lightSum0, 0.0, 1.0) + vec4(lightSum1, 0.0), 0.0, 1.0);\n");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Lighting doesn't affect color.
|
||||
|
|
Loading…
Add table
Reference in a new issue