Browse Source

Demonstrate Z fighting elimination by depth bias in 10_RenderToTexture sample. Closes #1543.

Lasse Öörni 9 years ago
parent
commit
b3964e21c5

+ 3 - 0
Source/Samples/10_RenderToTexture/RenderToTexture.cpp

@@ -189,6 +189,9 @@ void RenderToTexture::CreateScene()
             SharedPtr<Material> renderMaterial(new Material(context_));
             renderMaterial->SetTechnique(0, cache->GetResource<Technique>("Techniques/DiffUnlit.xml"));
             renderMaterial->SetTexture(TU_DIFFUSE, renderTexture);
+            // Since the screen material is on top of the box model and may Z-fight, use negative depth bias
+            // to push it forward (particularly necessary on mobiles with possibly less Z resolution)
+            renderMaterial->SetDepthBias(BiasParameters(-0.001f, 0.0f));
             screenObject->SetMaterial(renderMaterial);
 
             // Get the texture's RenderSurface object (exists when the texture has been created in rendertarget mode)

+ 3 - 0
bin/Data/LuaScripts/10_RenderToTexture.lua

@@ -132,6 +132,9 @@ function CreateScene()
     local renderMaterial = Material:new()
     renderMaterial:SetTechnique(0, cache:GetResource("Technique", "Techniques/DiffUnlit.xml"))
     renderMaterial:SetTexture(TU_DIFFUSE, renderTexture)
+    -- Since the screen material is on top of the box model and may Z-fight, use negative depth bias
+    -- to push it forward (particularly necessary on mobiles with possibly less Z resolution)
+    renderMaterial.depthBias = BiasParameters(-0.001, 0.0)
     screenObject.material = renderMaterial
 
     -- Get the texture's RenderSurface object (exists when the texture has been created in rendertarget mode)

+ 3 - 0
bin/Data/Scripts/10_RenderToTexture.as

@@ -141,6 +141,9 @@ void CreateScene()
             Material@ renderMaterial = Material();
             renderMaterial.SetTechnique(0, cache.GetResource("Technique", "Techniques/DiffUnlit.xml"));
             renderMaterial.textures[TU_DIFFUSE] = renderTexture;
+            // Since the screen material is on top of the box model and may Z-fight, use negative depth bias
+            // to push it forward (particularly necessary on mobiles with possibly less Z resolution)
+            renderMaterial.depthBias = BiasParameters(-0.001, 0.0);
             screenObject.material = renderMaterial;
 
             // Get the texture's RenderSurface object (exists when the texture has been created in rendertarget mode)