ShaderGen: Fix per pixel lighting.
This commit is contained in:
parent
248d56d930
commit
f6d65a636e
|
@ -18,15 +18,12 @@
|
||||||
#ifndef _LIGHTINGSHADERGEN_H_
|
#ifndef _LIGHTINGSHADERGEN_H_
|
||||||
#define _LIGHTINGSHADERGEN_H_
|
#define _LIGHTINGSHADERGEN_H_
|
||||||
|
|
||||||
#include <typeinfo>
|
|
||||||
|
|
||||||
#include "ShaderGenCommon.h"
|
#include "ShaderGenCommon.h"
|
||||||
#include "NativeVertexFormat.h"
|
#include "NativeVertexFormat.h"
|
||||||
#include "XFMemory.h"
|
#include "XFMemory.h"
|
||||||
|
|
||||||
// uid_data needs to have a struct named lighting_uid
|
template<class T>
|
||||||
template<class T,class UidDataT>
|
static void GenerateLightShader(T& object, LightingUidData& uid_data, int index, int litchan_index, const char* lightsName, int coloralpha)
|
||||||
static void GenerateLightShader(T& object, UidDataT& uid_data, int index, int litchan_index, const char* lightsName, int coloralpha)
|
|
||||||
{
|
{
|
||||||
const LitChannel& chan = (litchan_index > 1) ? xfregs.alpha[litchan_index-2] : xfregs.color[litchan_index];
|
const LitChannel& chan = (litchan_index > 1) ? xfregs.alpha[litchan_index-2] : xfregs.color[litchan_index];
|
||||||
const char* swizzle = "xyzw";
|
const char* swizzle = "xyzw";
|
||||||
|
@ -93,8 +90,8 @@ static void GenerateLightShader(T& object, UidDataT& uid_data, int index, int li
|
||||||
// materials name is I_MATERIALS in vs and I_PMATERIALS in ps
|
// materials name is I_MATERIALS in vs and I_PMATERIALS in ps
|
||||||
// inColorName is color in vs and colors_ in ps
|
// inColorName is color in vs and colors_ in ps
|
||||||
// dest is o.colors_ in vs and colors_ in ps
|
// dest is o.colors_ in vs and colors_ in ps
|
||||||
template<class T, class UidDataT>
|
template<class T>
|
||||||
static void GenerateLightingShader(T& object, UidDataT& uid_data, int components, const char* materialsName, const char* lightsName, const char* inColorName, const char* dest)
|
static void GenerateLightingShader(T& object, LightingUidData& uid_data, int components, const char* materialsName, const char* lightsName, const char* inColorName, const char* dest)
|
||||||
{
|
{
|
||||||
for (unsigned int j = 0; j < xfregs.numChan.numColorChans; j++)
|
for (unsigned int j = 0; j < xfregs.numChan.numColorChans; j++)
|
||||||
{
|
{
|
||||||
|
@ -187,7 +184,7 @@ static void GenerateLightingShader(T& object, UidDataT& uid_data, int components
|
||||||
{
|
{
|
||||||
if (mask & (1<<i))
|
if (mask & (1<<i))
|
||||||
{
|
{
|
||||||
GenerateLightShader<T,UidDataT>(object, uid_data, i, j, lightsName, 3);
|
GenerateLightShader<T>(object, uid_data, i, j, lightsName, 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -197,9 +194,9 @@ static void GenerateLightingShader(T& object, UidDataT& uid_data, int components
|
||||||
for (int i = 0; i < 8; ++i)
|
for (int i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
if (!(mask&(1<<i)) && (color.GetFullLightMask() & (1<<i)))
|
if (!(mask&(1<<i)) && (color.GetFullLightMask() & (1<<i)))
|
||||||
GenerateLightShader<T,UidDataT>(object, uid_data, i, j, lightsName, 1);
|
GenerateLightShader<T>(object, uid_data, i, j, lightsName, 1);
|
||||||
if (!(mask&(1<<i)) && (alpha.GetFullLightMask() & (1<<i)))
|
if (!(mask&(1<<i)) && (alpha.GetFullLightMask() & (1<<i)))
|
||||||
GenerateLightShader<T,UidDataT>(object, uid_data, i, j+2, lightsName, 2);
|
GenerateLightShader<T>(object, uid_data, i, j+2, lightsName, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (color.enablelighting || alpha.enablelighting)
|
else if (color.enablelighting || alpha.enablelighting)
|
||||||
|
@ -213,7 +210,7 @@ static void GenerateLightingShader(T& object, UidDataT& uid_data, int components
|
||||||
for (int i = 0; i < 8; ++i)
|
for (int i = 0; i < 8; ++i)
|
||||||
{
|
{
|
||||||
if (workingchannel.GetFullLightMask() & (1<<i))
|
if (workingchannel.GetFullLightMask() & (1<<i))
|
||||||
GenerateLightShader<T,UidDataT>(object, uid_data, i, lit_index, lightsName, coloralpha);
|
GenerateLightShader<T>(object, uid_data, i, lit_index, lightsName, coloralpha);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
object.Write("%s%d = mat * saturate(lacc);\n", dest, j);
|
object.Write("%s%d = mat * saturate(lacc);\n", dest, j);
|
||||||
|
|
|
@ -479,10 +479,10 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u
|
||||||
out.Write("\tfloat4 mat, lacc;\n"
|
out.Write("\tfloat4 mat, lacc;\n"
|
||||||
"\tfloat3 ldir, h;\n"
|
"\tfloat3 ldir, h;\n"
|
||||||
"\tfloat dist, dist2, attn;\n");
|
"\tfloat dist, dist2, attn;\n");
|
||||||
/// TODO
|
|
||||||
out.SetConstantsUsed(C_PLIGHTS, C_PLIGHTS+39); // TODO: Can be optimized further
|
out.SetConstantsUsed(C_PLIGHTS, C_PLIGHTS+39); // TODO: Can be optimized further
|
||||||
out.SetConstantsUsed(C_PMATERIALS, C_PMATERIALS+3);
|
out.SetConstantsUsed(C_PMATERIALS, C_PMATERIALS+3);
|
||||||
/// p = GenerateLightingShader(p, components, I_PMATERIALS, I_PLIGHTS, "colors_", "colors_");
|
GenerateLightingShader<T>(out, uid_data.lighting, components, I_PMATERIALS, I_PLIGHTS, "colors_", "colors_");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numTexgen < 7)
|
if (numTexgen < 7)
|
||||||
|
|
|
@ -187,6 +187,8 @@ struct pixel_shader_uid_data
|
||||||
u32 bHasIndStage : 16;
|
u32 bHasIndStage : 16;
|
||||||
|
|
||||||
u32 xfregs_numTexGen_numTexGens : 4;
|
u32 xfregs_numTexGen_numTexGens : 4;
|
||||||
|
|
||||||
|
LightingUidData lighting;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef ShaderUid<pixel_shader_uid_data> PixelShaderUid;
|
typedef ShaderUid<pixel_shader_uid_data> PixelShaderUid;
|
||||||
|
|
|
@ -153,4 +153,17 @@ static void DeclareUniform(T& object, API_TYPE api_type, bool using_ubos, const
|
||||||
object.Write(";\n");
|
object.Write(";\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct LightingUidData
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
u32 matsource : 1;
|
||||||
|
u32 enablelighting : 1;
|
||||||
|
u32 ambsource : 1;
|
||||||
|
u32 diffusefunc : 2;
|
||||||
|
u32 attnfunc : 2;
|
||||||
|
u32 light_mask : 8;
|
||||||
|
} lit_chans[4];
|
||||||
|
};
|
||||||
|
|
||||||
#endif // _SHADERGENCOMMON_H
|
#endif // _SHADERGENCOMMON_H
|
||||||
|
|
|
@ -270,7 +270,7 @@ static void GenerateVertexShader(T& out, u32 components, API_TYPE api_type)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This probably isn't necessary if pixel lighting is enabled.
|
// TODO: This probably isn't necessary if pixel lighting is enabled.
|
||||||
GenerateLightingShader<T,vertex_shader_uid_data>(out, uid_data, components, I_MATERIALS, I_LIGHTS, "color", "o.colors_");
|
GenerateLightingShader<T>(out, uid_data.lighting, components, I_MATERIALS, I_LIGHTS, "color", "o.colors_");
|
||||||
|
|
||||||
if (xfregs.numChan.numColorChans < 2)
|
if (xfregs.numChan.numColorChans < 2)
|
||||||
{
|
{
|
||||||
|
|
|
@ -79,7 +79,6 @@ const s_svar VSVar_Loc[] = { {I_POSNORMALMATRIX, C_POSNORMALMATRIX, 6 },
|
||||||
#pragma pack(4)
|
#pragma pack(4)
|
||||||
|
|
||||||
struct vertex_shader_uid_data
|
struct vertex_shader_uid_data
|
||||||
|
|
||||||
{
|
{
|
||||||
u32 components;
|
u32 components;
|
||||||
u32 numColorChans : 2;
|
u32 numColorChans : 2;
|
||||||
|
@ -100,14 +99,8 @@ struct vertex_shader_uid_data
|
||||||
struct {
|
struct {
|
||||||
u32 enabled : 1;
|
u32 enabled : 1;
|
||||||
} dualTexTrans;
|
} dualTexTrans;
|
||||||
struct {
|
|
||||||
u32 matsource : 1;
|
LightingUidData lighting;
|
||||||
u32 enablelighting : 1;
|
|
||||||
u32 ambsource : 1;
|
|
||||||
u32 diffusefunc : 2;
|
|
||||||
u32 attnfunc : 2;
|
|
||||||
u32 light_mask : 8;
|
|
||||||
} lit_chans[4];
|
|
||||||
};
|
};
|
||||||
#pragma pack()
|
#pragma pack()
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,7 @@ struct VideoConfig
|
||||||
int iAdapter;
|
int iAdapter;
|
||||||
|
|
||||||
// Debugging
|
// Debugging
|
||||||
bool bEnableShaderDebugging; // TODO: Obsolete?
|
bool bEnableShaderDebugging;
|
||||||
|
|
||||||
// Static config per API
|
// Static config per API
|
||||||
// TODO: Move this out of VideoConfig
|
// TODO: Move this out of VideoConfig
|
||||||
|
|
Loading…
Reference in New Issue