Fix PBR material demo to operate similarly on AS, Lua, C++. Remove forcing of alpha to 1 from Zone::SetAmbientColor() & Zone::SetFogColor(). Change "Enable HDR" to "HDR rendering" in editor settings dialog for consistency.

This commit is contained in:
Lasse Öörni 2016-07-29 16:44:57 +03:00
parent de24325bcc
commit 812afaeb8f
7 changed files with 71 additions and 12 deletions

View File

@ -26,6 +26,7 @@
#include <Urho3D/Graphics/Graphics.h>
#include <Urho3D/Graphics/RenderPath.h>
#include <Urho3D/Graphics/StaticModel.h>
#include <Urho3D/Graphics/Zone.h>
#include <Urho3D/Input/Input.h>
#include <Urho3D/Resource/ResourceCache.h>
#include <Urho3D/Scene/Scene.h>
@ -49,7 +50,8 @@ PBRMaterials::PBRMaterials(Context* context) :
Sample(context),
dynamicMaterial_(0),
roughnessLabel_(0),
metallicLabel_(0)
metallicLabel_(0),
ambientLabel_(0)
{
}
@ -110,6 +112,9 @@ void PBRMaterials::CreateScene()
StaticModel* staticModel = sphereWithDynamicMatNode->GetComponent<StaticModel>();
dynamicMaterial_ = staticModel->GetMaterial(0);
Node* zoneNode = scene_->GetChild("Zone");
zone_ = zoneNode->GetComponent<Zone>();
// Create the camera (not included in the scene file)
cameraNode_ = scene_->CreateChild("Camera");
cameraNode_->CreateComponent<Camera>();
@ -148,6 +153,11 @@ void PBRMaterials::CreateUI()
metallicLabel_->SetPosition(370, 100);
metallicLabel_->SetTextEffect(TE_SHADOW);
ambientLabel_ = ui->GetRoot()->CreateChild<Text>();
ambientLabel_->SetFont(cache->GetResource<Font>("Fonts/Anonymous Pro.ttf"), 15);
ambientLabel_->SetPosition(370, 150);
ambientLabel_->SetTextEffect(TE_SHADOW);
Slider* roughnessSlider = ui->GetRoot()->CreateChild<Slider>();
roughnessSlider->SetStyleAuto();
roughnessSlider->SetPosition(50, 50);
@ -163,6 +173,14 @@ void PBRMaterials::CreateUI()
metallicSlider->SetRange(1.0f); // 0 - 1 range
SubscribeToEvent(metallicSlider, E_SLIDERCHANGED, URHO3D_HANDLER(PBRMaterials, HandleMetallicSliderChanged));
metallicSlider->SetValue(0.5f);
Slider* ambientSlider = ui->GetRoot()->CreateChild<Slider>();
ambientSlider->SetStyleAuto();
ambientSlider->SetPosition(50, 150);
ambientSlider->SetSize(300, 20);
ambientSlider->SetRange(10.0f); // 0 - 10 range
SubscribeToEvent(ambientSlider, E_SLIDERCHANGED, URHO3D_HANDLER(PBRMaterials, HandleAmbientSliderChanged));
ambientSlider->SetValue(zone_->GetAmbientColor().a_);
}
void PBRMaterials::HandleRoughnessSliderChanged(StringHash eventType, VariantMap& eventData)
@ -179,6 +197,14 @@ void PBRMaterials::HandleMetallicSliderChanged(StringHash eventType, VariantMap&
metallicLabel_->SetText("Metallic: " + String(newValue));
}
void PBRMaterials::HandleAmbientSliderChanged(StringHash eventType, VariantMap& eventData)
{
float newValue = eventData[SliderChanged::P_VALUE].GetFloat();
Color col = Color(0.0, 0.0, 0.0, newValue);
zone_->SetAmbientColor(col);
ambientLabel_->SetText("Ambient HDR Scale: " + String(zone_->GetAmbientColor().a_));
}
void PBRMaterials::SetupViewport()
{
ResourceCache* cache = GetSubsystem<ResourceCache>();
@ -192,7 +218,6 @@ void PBRMaterials::SetupViewport()
// Add post-processing effects appropriate with the example scene
SharedPtr<RenderPath> effectRenderPath = viewport->GetRenderPath()->Clone();
effectRenderPath->Append(cache->GetResource<XMLFile>("PostProcess/BloomHDR.xml"));
effectRenderPath->Append(cache->GetResource<XMLFile>("PostProcess/FXAA2.xml"));
effectRenderPath->Append(cache->GetResource<XMLFile>("PostProcess/GammaCorrection.xml"));

View File

@ -30,6 +30,7 @@ namespace Urho3D
class Drawable;
class Node;
class Scene;
class Zone;
}
@ -69,6 +70,8 @@ private:
void HandleRoughnessSliderChanged(StringHash eventType, VariantMap& eventData);
/// Handle the metallic slider drag event.
void HandleMetallicSliderChanged(StringHash eventType, VariantMap& eventData);
/// Handle the ambient HDR scale slider drag event.
void HandleAmbientSliderChanged(StringHash eventType, VariantMap& eventData);
/// Dynamic material.
Material* dynamicMaterial_;
@ -76,4 +79,8 @@ private:
Text* roughnessLabel_;
/// Metallic label.
Text* metallicLabel_;
/// Ambient HDR scale label.
Text* ambientLabel_;
/// Zone component in scene.
WeakPtr<Zone> zone_;
};

View File

@ -117,13 +117,13 @@ void Zone::SetBoundingBox(const BoundingBox& box)
void Zone::SetAmbientColor(const Color& color)
{
ambientColor_ = Color(color, 1.0f);
ambientColor_ = color;
MarkNetworkUpdate();
}
void Zone::SetFogColor(const Color& color)
{
fogColor_ = Color(color, 1.0f);
fogColor_ = color;
MarkNetworkUpdate();
}

View File

@ -10,6 +10,8 @@ require "LuaScripts/Utilities/Sample"
local dynamicMaterial = nil
local roughnessLabel = nil
local metallicLabel = nil
local ambientLabel = nil
local zone = nil
function Start()
-- Execute the common startup for samples
@ -57,6 +59,9 @@ function CreateScene()
local staticModel = sphereWithDynamicMatNode:GetComponent("StaticModel")
dynamicMaterial = staticModel:GetMaterial(0)
local zoneNode = scene_:GetChild("Zone");
zone = zoneNode:GetComponent("Zone");
-- Create the camera (not included in the scene file)
cameraNode = scene_:CreateChild("Camera")
cameraNode:CreateComponent("Camera")
@ -89,7 +94,12 @@ function CreateUI()
metallicLabel:SetFont(cache:GetResource("Font", "Fonts/Anonymous Pro.ttf"), 15)
metallicLabel:SetPosition(370, 100)
metallicLabel.textEffect = TE_SHADOW
ambientLabel = ui.root:CreateChild("Text")
ambientLabel:SetFont(cache:GetResource("Font", "Fonts/Anonymous Pro.ttf"), 15)
ambientLabel:SetPosition(370, 150)
ambientLabel.textEffect = TE_SHADOW
local roughnessSlider = ui.root:CreateChild("Slider")
roughnessSlider:SetStyleAuto()
roughnessSlider:SetPosition(50, 50)
@ -105,6 +115,14 @@ function CreateUI()
metallicSlider.range = 1.0 -- 0 - 1 range
SubscribeToEvent(metallicSlider, "SliderChanged", "HandleMetallicSliderChanged")
metallicSlider.value = 0.5
local ambientSlider = ui.root:CreateChild("Slider")
ambientSlider:SetStyleAuto()
ambientSlider:SetPosition(50, 150)
ambientSlider:SetSize(300, 20)
ambientSlider.range = 10.0 -- 0 - 10 range
SubscribeToEvent(ambientSlider, "SliderChanged", "HandleAmbientSliderChanged")
ambientSlider.value = zone.ambientColor.a
end
function HandleRoughnessSliderChanged(eventType, eventData)
@ -119,6 +137,13 @@ function HandleMetallicSliderChanged(eventType, eventData)
metallicLabel.text = "Metallic: " .. newValue
end
function HandleAmbientSliderChanged(eventType, eventData)
local newValue = eventData["Value"]:GetFloat()
local col = Color(0, 0, 0, newValue)
zone.ambientColor = col
ambientLabel.text = "Ambient HDR Scale: " .. zone.ambientColor.a
end
function SetupViewport()
renderer.hdrRendering = true;

View File

@ -11,6 +11,7 @@ Material@ dynamicMaterial;
Text@ roughnessLabel;
Text@ metallicLabel;
Text@ ambientLabel;
Zone@ zone;
void Start()
{
@ -58,6 +59,9 @@ void CreateScene()
StaticModel@ staticModel = sphereWithDynamicMatNode.GetComponent("StaticModel");
dynamicMaterial = staticModel.materials[0];
Node@ zoneNode = scene_.GetChild("Zone");
zone = zoneNode.GetComponent("Zone");
// Create the camera (not included in the scene file)
cameraNode = scene_.CreateChild("Camera");
cameraNode.CreateComponent("Camera");
@ -117,9 +121,9 @@ void CreateUI()
ambientSlider.SetStyleAuto();
ambientSlider.SetPosition(50, 150);
ambientSlider.SetSize(300, 20);
ambientSlider.range = 10.0f; // 0 - 1 range
ambientSlider.range = 10.0f; // 0 - 10 range
SubscribeToEvent(ambientSlider, "SliderChanged", "HandleAmbientSliderChanged");
ambientSlider.value = 5.0f;
ambientSlider.value = zone.ambientColor.a;
}
void HandleRoughnessSliderChanged(StringHash eventType, VariantMap& eventData)
@ -139,10 +143,8 @@ void HandleMetallicSliderChanged(StringHash eventType, VariantMap& eventData)
void HandleAmbientSliderChanged(StringHash eventType, VariantMap& eventData)
{
float newValue = eventData["Value"].GetFloat();
Node@ zoneNode = scene_.GetChild("Zone");
Zone@ zone = zoneNode.GetComponent("Zone");
Color col = Color(0.0, 0.0, 0.0, newValue);
zone.SetAttribute("Ambient Color", Variant(col));
zone.ambientColor = col;
ambientLabel.text = "Ambient HDR Scale: " + zone.ambientColor.a;
}

View File

@ -489,7 +489,7 @@ void SetGammaCorrection(bool enable)
void SetHDR(bool enable)
{
HDR = enable;
if (renderPath !is null)
if (renderer !is null)
renderer.hdrRendering = HDR;
}

View File

@ -350,7 +350,7 @@
<attribute name="Name" value="HDRToggle" />
</element>
<element type="Text">
<attribute name="Text" value="Enable HDR" />
<attribute name="Text" value="HDR rendering" />
</element>
</element>
<element style="ListRow">