From abde070f63f62a784dcb59fadd0e72013fa03acf Mon Sep 17 00:00:00 2001 From: NeoBrainX Date: Wed, 10 Apr 2013 14:25:18 +0200 Subject: [PATCH] LightingShaderGen: Use a float4 array for lights instead of a struct (uniform management in the non-UBO path is a mess otherwise). Also fix a small bug (cf. revision 154c533e7632). --- .../Core/VideoCommon/Src/LightingShaderGen.h | 20 +++++++++---------- .../Core/VideoCommon/Src/PixelShaderGen.cpp | 3 +-- Source/Core/VideoCommon/Src/ShaderGenCommon.h | 2 +- .../Core/VideoCommon/Src/VertexShaderGen.cpp | 5 ++--- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Source/Core/VideoCommon/Src/LightingShaderGen.h b/Source/Core/VideoCommon/Src/LightingShaderGen.h index 2a354aaf8d..b534d767cc 100644 --- a/Source/Core/VideoCommon/Src/LightingShaderGen.h +++ b/Source/Core/VideoCommon/Src/LightingShaderGen.h @@ -24,36 +24,36 @@ static const char* LightCol(const char* lightsName, unsigned int index, const char* swizzle) { - static char result[16]; - snprintf(result, sizeof(result), "%s[%d].col.%s", lightsName, index, swizzle); + static char result[32]; + snprintf(result, sizeof(result), "%s[5*%d].%s", lightsName, index, swizzle); return result; } static const char* LightCosAtt(const char* lightsName, unsigned int index) { - static char result[16]; - snprintf(result, sizeof(result), "%s[%d].cosatt", lightsName, index); + static char result[32]; + snprintf(result, sizeof(result), "%s[5*%d+1]", lightsName, index); return result; } static const char* LightDistAtt(const char* lightsName, unsigned int index) { - static char result[16]; - snprintf(result, sizeof(result), "%s[%d].distatt", lightsName, index); + static char result[32]; + snprintf(result, sizeof(result), "%s[5*%d+2]", lightsName, index); return result; } static const char* LightPos(const char* lightsName, unsigned int index) { - static char result[16]; - snprintf(result, sizeof(result), "%s[%d].pos", lightsName, index); + static char result[32]; + snprintf(result, sizeof(result), "%s[5*%d+3]", lightsName, index); return result; } static const char* LightDir(const char* lightsName, unsigned int index) { - static char result[16]; - snprintf(result, sizeof(result), "%s[%d].dir", lightsName, index); + static char result[32]; + snprintf(result, sizeof(result), "%s[5*%d+4]", lightsName, index); return result; } diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index 2d9121856c..4dbb56b320 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -338,8 +338,7 @@ void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType, u out.Write("\t%sfloat4 " I_FOG"[3] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_FOG)); // For pixel lighting - TODO: Should only be defined when per pixel lighting is enabled! - out.Write("struct Light { float4 col; float4 cosatt; float4 distatt; float4 pos; float4 dir; };\n"); - out.Write("\t%sLight " I_PLIGHTS"[8] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_PLIGHTS)); + out.Write("\t%sfloat4 " I_PLIGHTS"[40] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_PLIGHTS)); out.Write("\t%sfloat4 " I_PMATERIALS"[4] %s;\n", WriteLocation(ApiType), WriteRegister(ApiType, "c", C_PMATERIALS)); if (g_ActiveConfig.backend_info.bSupportsGLSLUBO) diff --git a/Source/Core/VideoCommon/Src/ShaderGenCommon.h b/Source/Core/VideoCommon/Src/ShaderGenCommon.h index 07af93c295..8356b7defe 100644 --- a/Source/Core/VideoCommon/Src/ShaderGenCommon.h +++ b/Source/Core/VideoCommon/Src/ShaderGenCommon.h @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include #include diff --git a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp index 7c1553890b..52c3aeaf30 100644 --- a/Source/Core/VideoCommon/Src/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/VertexShaderGen.cpp @@ -106,8 +106,7 @@ static void GenerateVertexShader(T& out, u32 components, API_TYPE api_type) DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_POSNORMALMATRIX, "float4", I_POSNORMALMATRIX"[6]"); DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_PROJECTION, "float4", I_PROJECTION"[4]"); DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_MATERIALS, "float4", I_MATERIALS"[4]"); - out.Write("struct Light { float4 col; float4 cosatt; float4 distatt; float4 pos; float4 dir; };\n"); - DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_LIGHTS, "Light", I_LIGHTS"[8]"); + DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_LIGHTS, "float4", I_LIGHTS"[40]"); DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_TEXMATRICES, "float4", I_TEXMATRICES"[24]"); DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_TRANSFORMMATRICES, "float4", I_TRANSFORMMATRICES"[64]"); DeclareUniform(out, api_type, g_ActiveConfig.backend_info.bSupportsGLSLUBO, C_NORMALMATRICES, "float4", I_NORMALMATRICES"[32]"); @@ -337,7 +336,7 @@ static void GenerateVertexShader(T& out, u32 components, API_TYPE api_type) // transform the light dir into tangent space uid_data.texMtxInfo[i].embosslightshift = xfregs.texMtxInfo[i].embosslightshift; uid_data.texMtxInfo[i].embosssourceshift = xfregs.texMtxInfo[i].embosssourceshift; - out.Write("ldir = normalize(" I_LIGHTS"[%d].pos.xyz - pos.xyz);\n", texinfo.embosslightshift); + out.Write("ldir = normalize(%s.xyz - pos.xyz);\n", LightPos(I_LIGHTS, texinfo.embosslightshift)); out.Write("o.tex%d.xyz = o.tex%d.xyz + float3(dot(ldir, _norm1), dot(ldir, _norm2), 0.0f);\n", i, texinfo.embosssourceshift); } else