Added possibility to disable the litbase pass optimization in RenderPath, if an ambient-only pass is needed.

This commit is contained in:
Lasse Öörni 2013-01-02 23:38:39 +00:00
parent 42598f54ce
commit 9d759300fe
7 changed files with 26 additions and 6 deletions

View File

@ -713,7 +713,7 @@ The render path XML definition looks like this:
<texture unit="unit" name="viewport|RTName|TextureName" />
<shaderparameter name="ParameterName" value="x y z w" />
</command>
<command type="forwardlights" output="viewport|RTName" />
<command type="forwardlights" uselitbase="true|false" output="viewport|RTName" />
<command type="lightvolumes" vs="VertexShaderName" ps="PixelShaderName" output="viewport|RTName" />
<texture unit="unit" name="viewport|RTName|TextureName" />
</command>
@ -728,6 +728,7 @@ Otherwise fully customized scene render passes can be specified, but there are a
- The "light" and "litbase" passes will be automatically rendered by the forwardlights command, interleaved with shadow map rendering as necessary.
- The "litalpha" pass for transparent objects is automatically merged with the "alpha" pass, if it exists in the render path definition. The idea is that all transparent objects are sorted back to front, and their base passes (the actual "alpha" pass) are rendered first, followed by their additive pixel-lit passes. The "usescissor" flag in the scenepass command should be set to true, so that scissor rectangles limit the effect of lights on transparent objects.
- The forwardlights command can optionally disable the "litbase" pass optimization without having to touch the material techniques, if a separate opaque ambient-only base pass is needed. By default the optimization is enabled.
\page Lights Lights and shadows

View File

@ -1668,6 +1668,7 @@ Properties:<br>
- bool useFogColor
- bool markToStencil
- bool vertexLights
- bool useLitBase
- bool useScissor
- String vertexShaderName
- String pixelShaderName

View File

@ -318,6 +318,7 @@ static void RegisterRenderPath(asIScriptEngine* engine)
engine->RegisterObjectProperty("RenderPathCommand", "bool useFogColor", offsetof(RenderPathCommand, useFogColor_));
engine->RegisterObjectProperty("RenderPathCommand", "bool markToStencil", offsetof(RenderPathCommand, markToStencil_));
engine->RegisterObjectProperty("RenderPathCommand", "bool vertexLights", offsetof(RenderPathCommand, vertexLights_));
engine->RegisterObjectProperty("RenderPathCommand", "bool useLitBase", offsetof(RenderPathCommand, useLitBase_));
engine->RegisterObjectProperty("RenderPathCommand", "bool useScissor", offsetof(RenderPathCommand, useScissor_));
engine->RegisterObjectProperty("RenderPathCommand", "String vertexShaderName", offsetof(RenderPathCommand, vertexShaderName_));
engine->RegisterObjectProperty("RenderPathCommand", "String pixelShaderName", offsetof(RenderPathCommand, pixelShaderName_));

View File

@ -125,6 +125,11 @@ void RenderPathCommand::LoadParameters(const XMLElement& element)
useScissor_ = element.GetBool("usescissor");
break;
case CMD_FORWARDLIGHTS:
if (element.HasAttribute("uselitbase"))
useLitBase_ = element.GetBool("uselitbase");
break;
case CMD_LIGHTVOLUMES:
case CMD_QUAD:
vertexShaderName_ = element.GetAttribute("vs");

View File

@ -97,6 +97,7 @@ struct RenderPathCommand
active_(true),
useFogColor_(false),
markToStencil_(false),
useLitBase_(true),
useScissor_(false),
vertexLights_(false)
{
@ -148,6 +149,8 @@ struct RenderPathCommand
bool markToStencil_;
/// Vertex lights flag.
bool vertexLights_;
/// Use lit base pass optimization for forward per-pixel lights.
bool useLitBase_;
/// Scissor optimization flag.
bool useScissor_;
/// Vertex shader name.

View File

@ -687,6 +687,15 @@ void View::GetBatches()
PODVector<Light*> vertexLights;
BatchQueue* alphaQueue = batchQueues_.Contains(PASS_ALPHA) ? &batchQueues_[PASS_ALPHA] : (BatchQueue*)0;
// Check whether to use the lit base pass optimization
bool useLitBase = true;
for (unsigned i = 0; i < renderPath_->commands_.Size(); ++i)
{
const RenderPathCommand& command = renderPath_->commands_[i];
if (command.type_ == CMD_FORWARDLIGHTS)
useLitBase = command.useLitBase_;
}
// Process lit geometries and shadow casters for each light
{
PROFILE(ProcessLights);
@ -820,7 +829,7 @@ void View::GetBatches()
// If drawable limits maximum lights, only record the light, and check maximum count / build batches later
if (!drawable->GetMaxLights())
GetLitBatches(drawable, lightQueue, alphaQueue);
GetLitBatches(drawable, lightQueue, alphaQueue, useLitBase);
else
maxLightsDrawables_.Insert(drawable);
}
@ -872,7 +881,7 @@ void View::GetBatches()
// Find the correct light queue again
LightBatchQueue* queue = light->GetLightQueue();
if (queue)
GetLitBatches(drawable, *queue, alphaQueue);
GetLitBatches(drawable, *queue, alphaQueue, useLitBase);
}
}
}
@ -1059,7 +1068,7 @@ void View::UpdateGeometries()
queue->Complete();
}
void View::GetLitBatches(Drawable* drawable, LightBatchQueue& lightQueue, BatchQueue* alphaQueue)
void View::GetLitBatches(Drawable* drawable, LightBatchQueue& lightQueue, BatchQueue* alphaQueue, bool useLitBase)
{
Light* light = lightQueue.light_;
Zone* zone = GetZone(drawable);
@ -1068,7 +1077,7 @@ void View::GetLitBatches(Drawable* drawable, LightBatchQueue& lightQueue, BatchQ
bool hasAmbientGradient = zone->GetAmbientGradient() && zone->GetAmbientStartColor() != zone->GetAmbientEndColor();
// Shadows on transparencies can only be rendered if shadow maps are not reused
bool allowTransparentShadows = !renderer_->GetReuseShadowMaps();
bool allowLitBase = light == drawable->GetFirstLight() && drawable->GetVertexLights().Empty() && !hasAmbientGradient;
bool allowLitBase = useLitBase && light == drawable->GetFirstLight() && drawable->GetVertexLights().Empty() && !hasAmbientGradient;
for (unsigned i = 0; i < batches.Size(); ++i)
{

View File

@ -138,7 +138,7 @@ private:
/// Update geometries and sort batches.
void UpdateGeometries();
/// Get pixel lit batches for a certain light and drawable.
void GetLitBatches(Drawable* drawable, LightBatchQueue& lightQueue, BatchQueue* alphaQueue);
void GetLitBatches(Drawable* drawable, LightBatchQueue& lightQueue, BatchQueue* alphaQueue, bool useLitBase);
/// Execute render commands.
void ExecuteRenderPathCommands();
/// Set rendertargets for current render command.