ShaderGen: Store material uniforms as integers.

This commit is contained in:
Tony Wasserka 2013-10-27 14:07:13 +01:00
parent 4bf57565e8
commit 78623871f9
6 changed files with 20 additions and 20 deletions

View File

@ -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];

View File

@ -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

View File

@ -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");

View File

@ -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;
}
}

View File

@ -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]");

View File

@ -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;