mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-11-23 13:30:02 +00:00
Merge pull request #1256 from raven02/patch-8
Match SW spotlight with hardware
This commit is contained in:
commit
93c9414664
@ -98,18 +98,20 @@ void Config::Load(const char *iniFileName)
|
||||
graphics->Get("FullScreen", &bFullScreen, false);
|
||||
graphics->Get("StretchToDisplay", &bStretchToDisplay, false);
|
||||
graphics->Get("TrueColor", &bTrueColor, true);
|
||||
#ifdef USING_GLES2
|
||||
graphics->Get("MipMap", &bMipMap, true);
|
||||
#else
|
||||
graphics->Get("MipMap", &bMipMap, false);
|
||||
|
||||
#endif
|
||||
IniFile::Section *sound = iniFile.GetOrCreateSection("Sound");
|
||||
sound->Get("Enable", &bEnableSound, true);
|
||||
|
||||
IniFile::Section *control = iniFile.GetOrCreateSection("Control");
|
||||
control->Get("ShowStick", &bShowAnalogStick, false);
|
||||
control->Get("ShowTouchControls", &bShowTouchControls,
|
||||
#ifdef USING_GLES2
|
||||
true);
|
||||
control->Get("ShowTouchControls", &bShowTouchControls, true);
|
||||
#else
|
||||
false);
|
||||
control->Get("ShowTouchControls", &bShowTouchControls,false);
|
||||
#endif
|
||||
control->Get("LargeControls", &bLargeControls, false);
|
||||
control->Get("KeyMapping",iMappingMap);
|
||||
|
@ -53,6 +53,10 @@ enum {
|
||||
TRANSFORMED_VERTEX_BUFFER_SIZE = 65536 * sizeof(TransformedVertex)
|
||||
};
|
||||
|
||||
inline float clamp(float in, float min, float max) {
|
||||
return in < min ? min : (in > max ? max : in);
|
||||
}
|
||||
|
||||
TransformDrawEngine::TransformDrawEngine()
|
||||
: collectedVerts(0),
|
||||
prevPrim_(-1),
|
||||
@ -276,6 +280,7 @@ void Lighter::Light(float colorOut0[4], float colorOut1[4], const float colorIn[
|
||||
GELightType type = (GELightType)((gstate.ltype[l] >> 8) & 3);
|
||||
|
||||
Vec3 toLight(0,0,0);
|
||||
Vec3 lightDir(0,0,0);
|
||||
|
||||
if (type == GE_LIGHTTYPE_DIRECTIONAL)
|
||||
toLight = Vec3(gstate_c.lightpos[l]); // lightdir is for spotlights
|
||||
@ -287,7 +292,9 @@ void Lighter::Light(float colorOut0[4], float colorOut1[4], const float colorIn[
|
||||
|
||||
float distanceToLight = toLight.Length();
|
||||
float dot = 0.0f;
|
||||
|
||||
float angle = 0.0f;
|
||||
float lightScale = 0.0f;
|
||||
|
||||
if (distanceToLight > 0.0f) {
|
||||
toLight /= distanceToLight;
|
||||
dot = toLight * norm;
|
||||
@ -298,20 +305,23 @@ void Lighter::Light(float colorOut0[4], float colorOut1[4], const float colorIn[
|
||||
if (poweredDiffuse)
|
||||
dot = powf(dot, specCoef_);
|
||||
|
||||
float lightScale = 1.0f;
|
||||
if (type != GE_LIGHTTYPE_DIRECTIONAL) {
|
||||
lightScale = 1.0f / (gstate_c.lightatt[l][0] + gstate_c.lightatt[l][1]*distanceToLight + gstate_c.lightatt[l][2]*distanceToLight*distanceToLight);
|
||||
if (lightScale > 1.0f) lightScale = 1.0f;
|
||||
}
|
||||
|
||||
if (type == GE_LIGHTTYPE_SPOT) {
|
||||
Vec3 lightDir = gstate_c.lightdir[l];
|
||||
lightDir.Normalize();
|
||||
float angle = toLight * lightDir;
|
||||
if (angle < gstate_c.lightangle[l])
|
||||
lightScale = 0.0f;
|
||||
else
|
||||
lightScale *= powf(angle, gstate_c.lightspotCoef[l]);
|
||||
// Attenuation
|
||||
switch (type) {
|
||||
case GE_LIGHTTYPE_DIRECTIONAL:
|
||||
lightScale = 1.0f;
|
||||
break;
|
||||
case GE_LIGHTTYPE_POINT:
|
||||
lightScale = clamp(1.0f / (gstate_c.lightatt[l][0] + gstate_c.lightatt[l][1]*distanceToLight + gstate_c.lightatt[l][2]*distanceToLight*distanceToLight), 0.0f, 1.0f);
|
||||
break;
|
||||
case GE_LIGHTTYPE_SPOT:
|
||||
lightDir = gstate_c.lightdir[l];
|
||||
angle = toLight.Normalize() * lightDir.Normalize();
|
||||
if (angle >= gstate_c.lightangle[l])
|
||||
lightScale = clamp(1.0f / (gstate_c.lightatt[l][0] + gstate_c.lightatt[l][1]*distanceToLight + gstate_c.lightatt[l][2]*distanceToLight*distanceToLight), 0.0f, 1.0f) * powf(angle, gstate_c.lightspotCoef[l]);
|
||||
break;
|
||||
default:
|
||||
// ILLEGAL
|
||||
break;
|
||||
}
|
||||
|
||||
Color4 lightDiff(gstate_c.lightColor[1][l], 0.0f);
|
||||
|
@ -334,6 +334,10 @@ void GenerateVertexShader(int prim, char *buffer) {
|
||||
bool poweredDiffuse = comp == GE_LIGHTCOMP_BOTHWITHPOWDIFFUSE;
|
||||
|
||||
WRITE(p, " float dot%i = dot(normalize(toLight%i), worldnormal);\n", i, i);
|
||||
WRITE(p, " float distance%i = length(toLight%i);\n", i, i);
|
||||
WRITE(p, " float lightScale%i = 0.0;\n", i);
|
||||
WRITE(p, " float angle%i = 0.0;\n", i);
|
||||
|
||||
if (poweredDiffuse) {
|
||||
WRITE(p, " dot%i = pow(dot%i, u_matspecular.a);\n", i, i);
|
||||
}
|
||||
@ -341,17 +345,14 @@ void GenerateVertexShader(int prim, char *buffer) {
|
||||
// Attenuation
|
||||
switch (type) {
|
||||
case GE_LIGHTTYPE_DIRECTIONAL:
|
||||
WRITE(p, " float lightScale%i = 1.0;\n", i);
|
||||
WRITE(p, " lightScale%i = 1.0;\n", i);
|
||||
break;
|
||||
case GE_LIGHTTYPE_POINT:
|
||||
WRITE(p, " float distance%i = length(toLight%i);\n", i, i);
|
||||
WRITE(p, " float lightScale%i = clamp(1.0 / dot(u_lightatt%i, vec3(1.0, distance%i, distance%i*distance%i)), 0.0, 1.0);\n", i, i, i, i, i);
|
||||
WRITE(p, " lightScale%i = clamp(1.0 / dot(u_lightatt%i, vec3(1.0, distance%i, distance%i*distance%i)), 0.0, 1.0);\n", i, i, i, i, i);
|
||||
break;
|
||||
case GE_LIGHTTYPE_SPOT:
|
||||
WRITE(p, " float lightScale%i = 0.0;\n", i);
|
||||
WRITE(p, " float angle%i = dot(normalize(u_lightdir%i), normalize(toLight%i));\n", i, i, i);
|
||||
WRITE(p, " angle%i = dot(normalize(u_lightdir%i), normalize(toLight%i));\n", i, i, i);
|
||||
WRITE(p, " if (angle%i >= u_lightangle%i) {\n", i, i);
|
||||
WRITE(p, " float distance%i = length(toLight%i);\n", i, i);
|
||||
WRITE(p, " lightScale%i = clamp(1.0 / dot(u_lightatt%i, vec3(1.0, distance%i, distance%i*distance%i)), 0.0, 1.0) * pow(angle%i, u_lightspotCoef%i);\n", i, i, i, i, i, i, i);
|
||||
WRITE(p, " }\n");
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user