Added lightmap multiplier to allow applying basic lighting on world geometry

This commit is contained in:
parax0 2016-01-10 06:17:12 -07:00
parent 444382c1a9
commit b768473b44
7 changed files with 36 additions and 11 deletions

View File

@ -329,6 +329,7 @@ bool CShaderGenerator::CreatePixelShader(const CMaterial& Mat)
<< " vec4 KonstColors[4];\n"
<< " vec4 TevColor;\n"
<< " vec4 TintColor;\n"
<< " float LightmapMultiplier;\n"
<< "};\n\n";
for (u32 iPass = 0; iPass < PassCount; iPass++)
@ -374,6 +375,11 @@ bool CShaderGenerator::CreatePixelShader(const CMaterial& Mat)
else if (PassType == "BLOL")
ShaderCode << ".rgbg";
// Apply lightmap multiplier
if ( (PassType == "DIFF") ||
(PassType == "CUST" && (Mat.Options() & CMaterial::eLightmap) && iPass == 0) )
ShaderCode << " * LightmapMultiplier";
ShaderCode << ";\n";
ShaderCode << " Konst = vec4(" << gkKonstColor[pPass->KColorSel()] << ", " << gkKonstAlpha[pPass->KAlphaSel()] << ");\n";
@ -398,7 +404,7 @@ bool CShaderGenerator::CreatePixelShader(const CMaterial& Mat)
<< ".rgb = ";
ShaderCode << "clamp(vec3(TevInD.rgb + ((1.0 - TevInC.rgb) * TevInA.rgb + TevInC.rgb * TevInB.rgb))";
if ((PassType == "CLR ") && (Lightmap)) ShaderCode << "* 2.0"; // Apply tevscale 2.0 on the color pass if lightmap is present
if ((PassType == "CLR ") && (Lightmap)) ShaderCode << "* (2.0 - (1.0 - LightmapMultiplier))"; // Apply tevscale 2.0 on the color pass if lightmap is present. Scale so we don't apply if lightmaps are off.
ShaderCode << ", vec3(0, 0, 0), vec3(1.0, 1.0, 1.0));\n";
ShaderCode << " // Alpha Combine\n"

View File

@ -166,8 +166,10 @@ void CGraphics::SetupAmbientColor()
{
if (sLightMode == eWorldLighting)
sVertexBlock.COLOR0_Amb = sAreaAmbientColor * sWorldLightMultiplier;
else
else if (sLightMode == eBasicLighting)
sVertexBlock.COLOR0_Amb = skDefaultAmbientColor;
else
sVertexBlock.COLOR0_Amb = CColor::skWhite;
}
void CGraphics::SetIdentityMVP()

View File

@ -56,6 +56,7 @@ public:
CColor Konst[4];
CColor TevColor;
CColor TintColor;
float LightmapMultiplier;
};
static SPixelBlock sPixelBlock;

View File

@ -405,15 +405,16 @@ void CMaterialLoader::CreateCorruptionPasses(CMaterial *pMat)
// Color Map (Diffuse)
if (Type == "CLR ")
{
pPass->SetRasSel(eRasColor0A0);
if (Lightmap)
{
pPass->SetColorInputs(eZeroRGB, eColor0RGB, eTextureRGB, ePrevRGB);
pPass->SetColorInputs(eZeroRGB, eColor0RGB, eTextureRGB, eZeroRGB);
}
else
{
pPass->SetColorInputs(eZeroRGB, eRasRGB, eTextureRGB, ePrevRGB);
pPass->SetRasSel(eRasColor0A0);
pPass->SetColorInputs(eZeroRGB, eRasRGB, eTextureRGB, eZeroRGB);
}
@ -439,7 +440,7 @@ void CMaterialLoader::CreateCorruptionPasses(CMaterial *pMat)
// Lightmap
else if (Type == "DIFF")
{
pPass->SetColorInputs(eZeroRGB, eKonstRGB, eTextureRGB, eZeroRGB);
pPass->SetColorInputs(eZeroRGB, eKonstRGB, eTextureRGB, eRasRGB);
pPass->SetAlphaInputs(eZeroAlpha, eZeroAlpha, eZeroAlpha, eKonstAlpha);
pPass->SetColorOutput(eColor0Reg);
pPass->SetAlphaOutput(eColor0Reg);

View File

@ -51,6 +51,7 @@ void CModelNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewInf
CGraphics::sPixelBlock.TevColor = CColor::skWhite;
CGraphics::sPixelBlock.TintColor = TintColor(ViewInfo);
CGraphics::sPixelBlock.LightmapMultiplier = 1.f;
LoadModelMatrix();
if (ComponentIndex < 0)

View File

@ -187,8 +187,8 @@ void CSceneNode::LoadLights(const SViewInfo& ViewInfo)
switch (Mode)
{
case CGraphics::eNoLighting:
// No lighting: default ambient color, no dynamic lights
CGraphics::sVertexBlock.COLOR0_Amb = CGraphics::skDefaultAmbientColor;
// No lighting: full white ambient, no dynamic lights
CGraphics::sVertexBlock.COLOR0_Amb = CColor::skWhite;
break;
case CGraphics::eBasicLighting:
@ -206,6 +206,7 @@ void CSceneNode::LoadLights(const SViewInfo& ViewInfo)
break;
}
CGraphics::sPixelBlock.LightmapMultiplier = (Mode == CGraphics::eWorldLighting ? 1.f : 0.f);
CGraphics::UpdateLightBlock();
}

View File

@ -49,12 +49,25 @@ void CStaticNode::Draw(FRenderOptions Options, int ComponentIndex, const SViewIn
if (!mpModel) return;
bool IsLightingEnabled = CGraphics::sLightMode == CGraphics::eWorldLighting || ViewInfo.GameMode;
CGraphics::sVertexBlock.COLOR0_Amb = (IsLightingEnabled ? CColor::skBlack : CColor::skWhite);
if (IsLightingEnabled)
{
CGraphics::sNumLights = 0;
CGraphics::sVertexBlock.COLOR0_Amb = CColor::skBlack;
CGraphics::sPixelBlock.LightmapMultiplier = 1.0f;
CGraphics::UpdateLightBlock();
}
else
{
LoadLights(ViewInfo);
if (CGraphics::sLightMode == CGraphics::eNoLighting)
CGraphics::sVertexBlock.COLOR0_Amb = CColor::skWhite;
}
float Mul = CGraphics::sWorldLightMultiplier;
CGraphics::sPixelBlock.TevColor = CColor(Mul,Mul,Mul);
CGraphics::sPixelBlock.TintColor = TintColor(ViewInfo);
CGraphics::sNumLights = 0;
CGraphics::UpdateLightBlock();
LoadModelMatrix();
if (ComponentIndex < 0)