Fix pixel lighting.

This commit is contained in:
NeoBrainX 2011-09-29 21:21:09 +02:00
parent 1f8a8268c6
commit ca7e8a9e88
5 changed files with 36 additions and 18 deletions

View File

@ -21,6 +21,21 @@
#define WRITE p+=sprintf #define WRITE p+=sprintf
int GetLightingShaderId(u32* out)
{
for (int i = 0; i < xfregs.numChan.numColorChans; ++i)
{
out[i] = xfregs.color[i].enablelighting ?
(u32)xfregs.color[i].hex :
(u32)xfregs.color[i].matsource;
out[i] |= (xfregs.alpha[i].enablelighting ?
(u32)xfregs.alpha[i].hex :
(u32)xfregs.alpha[i].matsource) << 15;
}
_assert_(xfregs.numChan.numColorChans <= 2);
return xfregs.numChan.numColorChans;
}
// coloralpha - 1 if color, 2 if alpha // coloralpha - 1 if color, 2 if alpha
char *GenerateLightShader(char *p, int index, const LitChannel& chan, const char* lightsName, int coloralpha) char *GenerateLightShader(char *p, int index, const LitChannel& chan, const char* lightsName, int coloralpha)
{ {

View File

@ -18,6 +18,9 @@
#ifndef _LIGHTINGSHADERGEN_H_ #ifndef _LIGHTINGSHADERGEN_H_
#define _LIGHTINGSHADERGEN_H_ #define _LIGHTINGSHADERGEN_H_
#include "CommonTypes.h"
int GetLightingShaderId(u32* out);
char *GenerateLightingShader(char *p, int components, const char* materialsName, const char* lightsName, const char* inColorName, const char* dest); char *GenerateLightingShader(char *p, int components, const char* materialsName, const char* lightsName, const char* inColorName, const char* dest);
#endif // _LIGHTINGSHADERGEN_H_ #endif // _LIGHTINGSHADERGEN_H_

View File

@ -125,16 +125,11 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode)
if (alphaPreTest == 1 || (alphaPreTest && !DepthTextureEnable && dstAlphaMode == DSTALPHA_ALPHA_PASS)) if (alphaPreTest == 1 || (alphaPreTest && !DepthTextureEnable && dstAlphaMode == DSTALPHA_ALPHA_PASS))
{ {
// Courtesy of PreAlphaTest, we're done already ;) // Courtesy of PreAlphaTest, we're done already ;)
// TODO: There's a comment including bpmem.genmode.numindstages.. shouldnt really bother about that though. // NOTE: The comment header of generated shaders depends on the value of bpmem.genmode.numindstages.. shouldnt really bother about that though.
uid->num_values = 1; uid->num_values = 1;
return; return;
} }
if (enablePL)
{
// TODO: Include register states for lighting shader
}
for (unsigned int i = 0; i < bpmem.genMode.numtexgens; ++i) for (unsigned int i = 0; i < bpmem.genMode.numtexgens; ++i)
{ {
if (18+i < 32) if (18+i < 32)
@ -194,7 +189,12 @@ void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode)
ptr[0] |= bpmem.fogRange.Base.Enabled << 17; // 1 ptr[0] |= bpmem.fogRange.Base.Enabled << 17; // 1
} }
} }
uid->num_values = (ptr+1) - uid->values;
++ptr;
if (enablePL)
ptr += GetLightingShaderId(ptr);
uid->num_values = ptr - uid->values;
} }
void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode) void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode)
@ -212,6 +212,10 @@ void GetSafePixelShaderId(PIXELSHADERUIDSAFE *uid, DSTALPHA_MODE dstAlphaMode)
if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting)
{ {
// TODO: Include register states for lighting shader // TODO: Include register states for lighting shader
*ptr++ = xfregs.color[0].hex;
*ptr++ = xfregs.alpha[0].hex;
*ptr++ = xfregs.color[1].hex;
*ptr++ = xfregs.alpha[1].hex;
} }
for (unsigned int i = 0; i < 8; ++i) for (unsigned int i = 0; i < 8; ++i)

View File

@ -44,8 +44,8 @@
#define C_PLIGHTS (C_FOG + 3) #define C_PLIGHTS (C_FOG + 3)
#define C_PMATERIALS (C_PLIGHTS + 40) #define C_PMATERIALS (C_PLIGHTS + 40)
#define C_PENVCONST_END (C_PMATERIALS + 4) #define C_PENVCONST_END (C_PMATERIALS + 4)
#define PIXELSHADERUID_MAX_VALUES 67 #define PIXELSHADERUID_MAX_VALUES 69
#define PIXELSHADERUID_MAX_VALUES_SAFE 115 #define PIXELSHADERUID_MAX_VALUES_SAFE 117
// DO NOT make anything in this class virtual. // DO NOT make anything in this class virtual.
template<bool safe> template<bool safe>

View File

@ -37,14 +37,9 @@ void GetVertexShaderId(VERTEXSHADERUID *uid, u32 components)
(xfregs.numChan.numColorChans << 27) | (xfregs.numChan.numColorChans << 27) |
(xfregs.dualTexTrans.enabled << 29); (xfregs.dualTexTrans.enabled << 29);
for (int i = 0; i < xfregs.numChan.numColorChans; ++i) { // TODO: If pixel lighting is enabled, do we even have to bother about storing lighting related registers here?
uid->values[1+i] = xfregs.color[i].enablelighting ? GetLightingShaderId(&uid->values[1]);
(u32)xfregs.color[i].hex :
(u32)xfregs.color[i].matsource;
uid->values[1+i] |= (xfregs.alpha[i].enablelighting ?
(u32)xfregs.alpha[i].hex :
(u32)xfregs.alpha[i].matsource) << 15;
}
uid->values[2] |= (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) << 31; uid->values[2] |= (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) << 31;
u32 *pcurvalue = &uid->values[3]; u32 *pcurvalue = &uid->values[3];
for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) { for (unsigned int i = 0; i < xfregs.numTexGen.numTexGens; ++i) {
@ -307,6 +302,7 @@ const char *GenerateVertexShaderCode(u32 components, API_TYPE api_type)
WRITE(p, "o.colors_0 = float4(1.0f, 1.0f, 1.0f, 1.0f);\n"); WRITE(p, "o.colors_0 = float4(1.0f, 1.0f, 1.0f, 1.0f);\n");
} }
// TODO: This probably isn't necessary if pixel lighting is enabled.
p = GenerateLightingShader(p, components, I_MATERIALS, I_LIGHTS, "color", "o.colors_"); p = GenerateLightingShader(p, components, I_MATERIALS, I_LIGHTS, "color", "o.colors_");
if(xfregs.numChan.numColorChans < 2) if(xfregs.numChan.numColorChans < 2)