diff --git a/Source/Core/VideoCommon/ConstantManager.h b/Source/Core/VideoCommon/ConstantManager.h index de1f346ed3..149599b1d5 100644 --- a/Source/Core/VideoCommon/ConstantManager.h +++ b/Source/Core/VideoCommon/ConstantManager.h @@ -24,14 +24,14 @@ struct PixelShaderConstants // For pixel lighting int4 plight_colors[8]; float4 plights[32]; - float4 pmaterials[4]; + int4 pmaterials[4]; }; struct VertexShaderConstants { float4 posnormalmatrix[6]; float4 projection[4]; - float4 materials[4]; + int4 materials[4]; int4 light_colors[8]; // 8 lights float4 lights[32]; // 8 lights * 4 parameters float4 texmatrices[24]; diff --git a/Source/Core/VideoCommon/LightingShaderGen.h b/Source/Core/VideoCommon/LightingShaderGen.h index 485d020b2f..b068f46a3e 100644 --- a/Source/Core/VideoCommon/LightingShaderGen.h +++ b/Source/Core/VideoCommon/LightingShaderGen.h @@ -136,7 +136,7 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com } else // from color { - object.Write("mat = %s[%d];\n", materialsName, j+2); + object.Write("mat = float4(%s[%d])/255.0;\n", materialsName, j+2); } uid_data.enablelighting |= xfregs.color[j].enablelighting << j; @@ -157,7 +157,7 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com } else // from color { - object.Write("lacc = %s[%d];\n", materialsName, j); + object.Write("lacc = float4(%s[%d])/255.0;\n", materialsName, j); } } else @@ -179,7 +179,7 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com } else // from color { - object.Write("mat.w = %s[%d].w;\n", materialsName, j+2); + object.Write("mat.w = float(%s[%d].w) / 255.0;\n", materialsName, j+2); } } @@ -199,7 +199,7 @@ static void GenerateLightingShader(T& object, LightingUidData& uid_data, int com } else // from color { - object.Write("lacc.w = %s[%d].w;\n", materialsName, j); + object.Write("lacc.w = float(%s[%d].w) / 255.0;\n", materialsName, j); } } else diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index 915cfc2176..6c89e88272 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -296,7 +296,7 @@ static inline void GeneratePixelShader(T& out, DSTALPHA_MODE dstAlphaMode, API_T // For pixel lighting - TODO: Should only be defined when per pixel lighting is enabled! DeclareUniform(out, ApiType, C_PLIGHT_COLORS, "int4", I_PLIGHT_COLORS"[8]"); DeclareUniform(out, ApiType, C_PLIGHTS, "float4", I_PLIGHTS"[32]"); - DeclareUniform(out, ApiType, C_PMATERIALS, "float4", I_PMATERIALS"[4]"); + DeclareUniform(out, ApiType, C_PMATERIALS, "int4", I_PMATERIALS"[4]"); if (ApiType == API_OPENGL) out.Write("};\n"); diff --git a/Source/Core/VideoCommon/PixelShaderManager.cpp b/Source/Core/VideoCommon/PixelShaderManager.cpp index b9418b4afd..8999247f24 100644 --- a/Source/Core/VideoCommon/PixelShaderManager.cpp +++ b/Source/Core/VideoCommon/PixelShaderManager.cpp @@ -326,10 +326,10 @@ void PixelShaderManager::SetMaterialColorChanged(int index, u32 color) { if (g_ActiveConfig.bEnablePixelLighting && g_ActiveConfig.backend_info.bSupportsPixelLighting) { - constants.pmaterials[index][0] = ((color >> 24) & 0xFF) / 255.0f; - constants.pmaterials[index][1] = ((color >> 16) & 0xFF) / 255.0f; - constants.pmaterials[index][2] = ((color >> 8) & 0xFF) / 255.0f; - constants.pmaterials[index][3] = ( color & 0xFF) / 255.0f; + constants.pmaterials[index][0] = (color >> 24) & 0xFF; + constants.pmaterials[index][1] = (color >> 16) & 0xFF; + constants.pmaterials[index][2] = (color >> 8) & 0xFF; + constants.pmaterials[index][3] = (color) & 0xFF; dirty = true; } } diff --git a/Source/Core/VideoCommon/VertexShaderGen.cpp b/Source/Core/VideoCommon/VertexShaderGen.cpp index 6310f6ceba..1707b15773 100644 --- a/Source/Core/VideoCommon/VertexShaderGen.cpp +++ b/Source/Core/VideoCommon/VertexShaderGen.cpp @@ -87,7 +87,7 @@ static inline void GenerateVertexShader(T& out, u32 components, API_TYPE api_typ DeclareUniform(out, api_type, C_POSNORMALMATRIX, "float4", I_POSNORMALMATRIX"[6]"); DeclareUniform(out, api_type, C_PROJECTION, "float4", I_PROJECTION"[4]"); - DeclareUniform(out, api_type, C_MATERIALS, "float4", I_MATERIALS"[4]"); + DeclareUniform(out, api_type, C_MATERIALS, "int4", I_MATERIALS"[4]"); DeclareUniform(out, api_type, C_LIGHT_COLORS, "int4", I_LIGHT_COLORS"[8]"); DeclareUniform(out, api_type, C_LIGHTS, "float4", I_LIGHTS"[32]"); DeclareUniform(out, api_type, C_TEXMATRICES, "float4", I_TEXMATRICES"[24]"); diff --git a/Source/Core/VideoCommon/VertexShaderManager.cpp b/Source/Core/VideoCommon/VertexShaderManager.cpp index d1264a68ba..06fff792e2 100644 --- a/Source/Core/VideoCommon/VertexShaderManager.cpp +++ b/Source/Core/VideoCommon/VertexShaderManager.cpp @@ -295,10 +295,10 @@ void VertexShaderManager::SetConstants() if (nMaterialsChanged & (1 << i)) { u32 data = *(xfregs.ambColor + i); - constants.materials[i][0] = ((data >> 24) & 0xFF) / 255.0f; - constants.materials[i][1] = ((data >> 16) & 0xFF) / 255.0f; - constants.materials[i][2] = ((data >> 8) & 0xFF) / 255.0f; - constants.materials[i][3] = ( data & 0xFF) / 255.0f; + constants.materials[i][0] = (data >> 24) & 0xFF; + constants.materials[i][1] = (data >> 16) & 0xFF; + constants.materials[i][2] = (data >> 8) & 0xFF; + constants.materials[i][3] = data & 0xFF; } } @@ -307,10 +307,10 @@ void VertexShaderManager::SetConstants() if (nMaterialsChanged & (1 << (i + 2))) { u32 data = *(xfregs.matColor + i); - constants.materials[i+2][0] = ((data >> 24) & 0xFF) / 255.0f; - constants.materials[i+2][1] = ((data >> 16) & 0xFF) / 255.0f; - constants.materials[i+2][2] = ((data >> 8) & 0xFF) / 255.0f; - constants.materials[i+2][3] = ( data & 0xFF) / 255.0f; + constants.materials[i+2][0] = (data >> 24) & 0xFF; + constants.materials[i+2][1] = (data >> 16) & 0xFF; + constants.materials[i+2][2] = (data >> 8) & 0xFF; + constants.materials[i+2][3] = data & 0xFF; } } dirty = true;