Browse Source

Refactored soft particle handling to not use unique renderpath files. Closes #1670.

Lasse Öörni 9 years ago
parent
commit
a04bf5629a

+ 3 - 4
Docs/Reference.dox

@@ -1591,14 +1591,13 @@ The ForwardDepth.xml render path does the same, but using a linear depth rendert
 
 \section RenderPaths_SoftParticles Soft particles rendering
 
-Soft particles rendering is a practical example of utilizing scene depth reading. Renderpaths whose name ends with "SP" enable soft particles by adding the SOFTPARTICLES shader compile define for the alpha pass. This is recognized by the LitParticle & UnlitParticle shaders.
+Soft particles rendering is a practical example of utilizing scene depth reading. The default renderpaths that expose a readable depth bind the depth texture in the alpha pass. This is utilized by the UnlitParticle & LitParticle shaders when the SOFTPARTICLES shader compilation define is included. The particle techniques containing "Soft" in their name in Bin/CoreData/Techniques use this. Note that they expect a readable depth and will not work with the plain forward renderpath!
 
 Soft particles can be implemented in two contrasting approaches: "shrinking" and "expanding". In the shrinking approach (default) depth test can be left on and the soft particle shader starts to reduce particle opacity when the particle geometry approaches solid geometry. In the expanding approach the particles should have depth test off, and the shader instead starts to reduce the particle opacity when the particle geometry overshoots the solid geometry.
 
-For the expanding mode, see the "Expand" family of particle techniques in Bin/CoreData/Techniques. The downside is that performance can be lower due to not being able to use the hardware depth test, and the same technique can not be used when readable depth is not available, as otherwise the particles would clip through any solid geometry.
+For the expanding mode, see the "SoftExpand" family of particle techniques in Bin/CoreData/Techniques. The downside is that performance can be lower due to not being able to use the hardware depth test, and the same technique can not be used when readable depth is not available, as otherwise the particles would clip through any solid geometry.
 
-Note the SoftParticleFadeScale shader parameter which can be used to control the distance over which the fade
-will take effect. The renderpath sets the default value (1) but it can be adjusted by materials.
+Finally note the SoftParticleFadeScale shader parameter which is needed to control the distance over which the fade will take effect. This is defined in example materials using soft particles (SmokeSoft.xml & LitSmokeSoft.xml)
 
 \section RenderPaths_ForwardLighting Forward lighting special considerations
 

+ 3 - 1
bin/CoreData/RenderPaths/Deferred.xml

@@ -18,6 +18,8 @@
     <command type="scenepass" pass="refract">
         <texture unit="environment" name="viewport" />
     </command>
-    <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" />
+    <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha">
+        <texture unit="depth" name="depth" />
+    </command>
     <command type="scenepass" pass="postalpha" sort="backtofront" />
 </renderpath>

+ 3 - 1
bin/CoreData/RenderPaths/DeferredHWDepth.xml

@@ -18,6 +18,8 @@
     <command type="scenepass" pass="refract" depthstencil="depth">
         <texture unit="environment" name="viewport" />
     </command>
-    <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" depthstencil="depth" />
+    <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" depthstencil="depth" psdefines="HWDEPTH">
+        <texture unit="depth" name="depth" />
+    </command>
     <command type="scenepass" pass="postalpha" sort="backtofront" depthstencil="depth" />
 </renderpath>

+ 0 - 8
bin/CoreData/RenderPaths/DeferredHWDepthSP.xml

@@ -1,8 +0,0 @@
-<renderpath inherit="RenderPaths/DeferredHWDepth.xml">
-    <replace sel="/renderpath/command[@type='scenepass' and @pass='alpha']">
-        <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" depthstencil="depth" vsdefines="SOFTPARTICLES" psdefines="SOFTPARTICLES HWDEPTH" >
-            <parameter name="SoftParticleFadeScale" value="1" />
-            <texture unit="depth" name="depth" />
-        </command>
-    </replace>
-</renderpath>

+ 0 - 27
bin/CoreData/RenderPaths/DeferredSP.xml

@@ -1,27 +0,0 @@
-<renderpath>
-    <rendertarget name="albedo" sizedivisor="1 1" format="rgba" />
-    <rendertarget name="normal" sizedivisor="1 1" format="rgba" />
-    <rendertarget name="depth" sizedivisor="1 1" format="lineardepth" />
-    <command type="clear" color="1 1 1 1" output="depth" />
-    <command type="clear" color="fog" depth="1.0" stencil="0" />
-    <command type="scenepass" pass="deferred" marktostencil="true" vertexlights="true" metadata="gbuffer">
-        <output index="0" name="viewport" />
-        <output index="1" name="albedo" />
-        <output index="2" name="normal" />
-        <output index="3" name="depth" />
-    </command>
-    <command type="lightvolumes" vs="DeferredLight" ps="DeferredLight">
-        <texture unit="albedo" name="albedo" />
-        <texture unit="normal" name="normal" />
-        <texture unit="depth" name="depth" />
-    </command>
-    <command type="scenepass" pass="postopaque" />
-    <command type="scenepass" pass="refract">
-        <texture unit="environment" name="viewport" />
-    </command>
-    <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" vsdefines="SOFTPARTICLES" psdefines="SOFTPARTICLES" >
-        <parameter name="SoftParticleFadeScale" value="1" />
-        <texture unit="depth" name="depth" />
-    </command>
-    <command type="scenepass" pass="postalpha" sort="backtofront" />
-</renderpath>

+ 3 - 1
bin/CoreData/RenderPaths/ForwardDepth.xml

@@ -9,6 +9,8 @@
     <command type="scenepass" pass="refract">
         <texture unit="environment" name="viewport" />
     </command>
-    <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" />
+    <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha">
+        <texture unit="depth" name="depth" />
+    </command>
     <command type="scenepass" pass="postalpha" sort="backtofront" />
 </renderpath>

+ 0 - 8
bin/CoreData/RenderPaths/ForwardDepthSP.xml

@@ -1,8 +0,0 @@
-<renderpath inherit="RenderPaths/ForwardDepth.xml">
-    <replace sel="/renderpath/command[@type='scenepass' and @pass='alpha']">
-        <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" vsdefines="SOFTPARTICLES" psdefines="SOFTPARTICLES" >
-            <parameter name="SoftParticleFadeScale" value="1" />
-            <texture unit="depth" name="depth" />
-        </command>
-    </replace>
-</renderpath>

+ 3 - 1
bin/CoreData/RenderPaths/ForwardHWDepth.xml

@@ -7,6 +7,8 @@
     <command type="scenepass" pass="refract" depthstencil="depth">
         <texture unit="environment" name="viewport" />
     </command>
-    <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" depthstencil="depth"  />
+    <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" depthstencil="depth" psdefines="HWDEPTH">
+        <texture unit="depth" name="depth" />
+    </command>
     <command type="scenepass" pass="postalpha" sort="backtofront" depthstencil="depth" />
 </renderpath>

+ 0 - 8
bin/CoreData/RenderPaths/ForwardHWDepthSP.xml

@@ -1,8 +0,0 @@
-<renderpath inherit="RenderPaths/ForwardHWDepth.xml">
-    <replace sel="/renderpath/command[@type='scenepass' and @pass='alpha']">
-        <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" depthstencil="depth" vsdefines="SOFTPARTICLES" psdefines="SOFTPARTICLES HWDEPTH" >
-            <parameter name="SoftParticleFadeScale" value="1" />
-            <texture unit="depth" name="depth" />
-        </command>
-    </replace>
-</renderpath>

+ 3 - 1
bin/CoreData/RenderPaths/PBRDeferred.xml

@@ -25,6 +25,8 @@
     <command type="scenepass" pass="refract">
         <texture unit="environment" name="viewport" />
     </command>
-    <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" />
+    <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha">
+        <texture unit="depth" name="depth" />
+    </command>
     <command type="scenepass" pass="postalpha" sort="backtofront" />
 </renderpath>

+ 3 - 1
bin/CoreData/RenderPaths/PBRDeferredHWDepth.xml

@@ -24,6 +24,8 @@
     <command type="scenepass" pass="refract" depthstencil="depth">
         <texture unit="environment" name="viewport" />
     </command>
-    <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" depthstencil="depth" />
+    <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" depthstencil="depth" psdefines="HWDEPTH">
+        <texture unit="depth" name="depth" />
+    </command>
     <command type="scenepass" pass="postalpha" sort="backtofront" depthstencil="depth" />
 </renderpath>

+ 0 - 8
bin/CoreData/RenderPaths/PBRDeferredHWDepthSP.xml

@@ -1,8 +0,0 @@
-<renderpath inherit="RenderPaths/PBRDeferredHWDepth.xml">
-    <replace sel="/renderpath/command[@type='scenepass' and @pass='alpha']">
-        <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" depthstencil="depth" vsdefines="SOFTPARTICLES" psdefines="SOFTPARTICLES HWDEPTH" >
-            <parameter name="SoftParticleFadeScale" value="1" />
-            <texture unit="depth" name="depth" />
-        </command>
-    </replace>
-</renderpath>

+ 0 - 8
bin/CoreData/RenderPaths/PBRDeferredSP.xml

@@ -1,8 +0,0 @@
-<renderpath inherit="RenderPaths/PBRDeferred.xml">
-    <replace sel="/renderpath/command[@type='scenepass' and @pass='alpha']">
-        <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" vsdefines="SOFTPARTICLES" psdefines="SOFTPARTICLES" >
-            <parameter name="SoftParticleFadeScale" value="1" />
-            <texture unit="depth" name="depth" />
-        </command>
-    </replace>
-</renderpath>

+ 3 - 1
bin/CoreData/RenderPaths/Prepass.xml

@@ -19,6 +19,8 @@
     <command type="scenepass" pass="refract">
         <texture unit="environment" name="viewport" />
     </command>
-    <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" />
+    <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha">
+        <texture unit="depth" name="depth" />
+    </command>
     <command type="scenepass" pass="postalpha" sort="backtofront" />
 </renderpath>

+ 3 - 1
bin/CoreData/RenderPaths/PrepassHWDepth.xml

@@ -16,6 +16,8 @@
     <command type="scenepass" pass="refract" depthstencil="depth">
         <texture unit="environment" name="viewport" />
     </command>
-    <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" depthstencil="depth" />
+    <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" depthstencil="depth" psdefines="HWDEPTH">
+        <texture unit="depth" name="depth" />
+    </command>
     <command type="scenepass" pass="postalpha" sort="backtofront" depthstencil="depth" />
 </renderpath>

+ 0 - 8
bin/CoreData/RenderPaths/PrepassHWDepthSP.xml

@@ -1,8 +0,0 @@
-<renderpath inherit="RenderPaths/PrepassHWDepth.xml">
-    <replace sel="/renderpath/command[@type='scenepass' and @pass='alpha']">
-        <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" depthstencil="depth" vsdefines="SOFTPARTICLES" psdefines="SOFTPARTICLES HWDEPTH" >
-            <parameter name="SoftParticleFadeScale" value="1" />
-            <texture unit="depth" name="depth" />
-        </command>
-    </replace>
-</renderpath>

+ 0 - 28
bin/CoreData/RenderPaths/PrepassSP.xml

@@ -1,28 +0,0 @@
-<renderpath>
-    <rendertarget name="light" sizedivisor="1 1"  format="rgba" />
-    <rendertarget name="normal" sizedivisor="1 1" format="rgba" />
-    <rendertarget name="depth" sizedivisor="1 1"  format="lineardepth" />
-    <command type="clear" color="1 1 1 1" output="depth" />
-    <command type="clear" color="fog" depth="1.0" stencil="0" />
-    <command type="scenepass" pass="prepass" marktostencil="true" metadata="gbuffer">
-        <output index="0" name="normal" />
-        <output index="1" name="depth" />
-    </command>
-    <command type="clear" color="0 0 0 0" output="light" />
-    <command type="lightvolumes" vs="PrepassLight" ps="PrepassLight" output="light">
-        <texture unit="normal" name="normal" />
-        <texture unit="depth" name="depth" />
-    </command>
-    <command type="scenepass" pass="material" vertexlights="true">
-        <texture unit="light" name="light" />
-    </command>
-    <command type="scenepass" pass="postopaque" />
-    <command type="scenepass" pass="refract">
-        <texture unit="environment" name="viewport" />
-    </command>
-    <command type="scenepass" pass="alpha" vertexlights="true" sort="backtofront" metadata="alpha" vsdefines="SOFTPARTICLES" psdefines="SOFTPARTICLES" >
-        <parameter name="SoftParticleFadeScale" value="1" />
-        <texture unit="depth" name="depth" />
-    </command>
-    <command type="scenepass" pass="postalpha" sort="backtofront" />
-</renderpath>

+ 5 - 5
bin/CoreData/Techniques/DiffLitParticleAlphaExpand.xml → bin/CoreData/Techniques/DiffLitParticleAlphaSoft.xml

@@ -1,5 +1,5 @@
-<technique vs="LitParticle" ps="LitParticle" psdefines="DIFFMAP EXPAND" >
-    <pass name="alpha" depthwrite="false" depthtest="false" blend="alpha" />
-    <pass name="litalpha" depthwrite="false" depthtest="false" blend="addalpha" />
-    <pass name="shadow" vs="Shadow" ps="Shadow" />
-</technique>
+<technique vs="LitParticle" ps="LitParticle" vsdefines="SOFTPARTICLES" psdefines="DIFFMAP SOFTPARTICLES" >
+    <pass name="alpha" depthwrite="false" depthtest="false" blend="alpha" />
+    <pass name="litalpha" depthwrite="false" depthtest="false" blend="addalpha" />
+    <pass name="shadow" vs="Shadow" ps="Shadow" />
+</technique>

+ 5 - 0
bin/CoreData/Techniques/DiffLitParticleAlphaSoftExpand.xml

@@ -0,0 +1,5 @@
+<technique vs="LitParticle" ps="LitParticle" vsdefines="SOFTPARTICLES" psdefines="DIFFMAP SOFTPARTICLES EXPAND" >
+    <pass name="alpha" depthwrite="false" depthtest="false" blend="alpha" />
+    <pass name="litalpha" depthwrite="false" depthtest="false" blend="addalpha" />
+    <pass name="shadow" vs="Shadow" ps="Shadow" />
+</technique>

+ 3 - 3
bin/CoreData/Techniques/DiffUnlitParticleAddExpand.xml → bin/CoreData/Techniques/DiffUnlitParticleAddSoft.xml

@@ -1,3 +1,3 @@
-<technique vs="UnlitParticle" ps="UnlitParticle" vsdefines="VERTEXCOLOR" psdefines="DIFFMAP VERTEXCOLOR ADDITIVE EXPAND">
-    <pass name="alpha" depthwrite="false" depthtest="false" blend="add" />
-</technique>
+<technique vs="UnlitParticle" ps="UnlitParticle" vsdefines="VERTEXCOLOR SOFTPARTICLES" psdefines="DIFFMAP VERTEXCOLOR ADDITIVE SOFTPARTICLES">
+    <pass name="alpha" depthwrite="false" depthtest="false" blend="add" />
+</technique>

+ 3 - 0
bin/CoreData/Techniques/DiffUnlitParticleAddSoftExpand.xml

@@ -0,0 +1,3 @@
+<technique vs="UnlitParticle" ps="UnlitParticle" vsdefines="VERTEXCOLOR SOFTPARTICLES" psdefines="DIFFMAP VERTEXCOLOR ADDITIVE SOFTPARTICLES EXPAND">
+    <pass name="alpha" depthwrite="false" depthtest="false" blend="add" />
+</technique>

+ 3 - 3
bin/CoreData/Techniques/DiffUnlitParticleAlphaExpand.xml → bin/CoreData/Techniques/DiffUnlitParticleAlphaSoft.xml

@@ -1,3 +1,3 @@
-<technique vs="UnlitParticle" ps="UnlitParticle" vsdefines="VERTEXCOLOR" psdefines="DIFFMAP VERTEXCOLOR EXPAND">
-    <pass name="alpha" depthwrite="false" depthtest="false" blend="alpha" />
-</technique>
+<technique vs="UnlitParticle" ps="UnlitParticle" vsdefines="VERTEXCOLOR SOFTPARTICLES" psdefines="DIFFMAP VERTEXCOLOR SOFTPARTICLES">
+    <pass name="alpha" depthwrite="false" depthtest="false" blend="alpha" />
+</technique>

+ 3 - 0
bin/CoreData/Techniques/DiffUnlitParticleAlphaSoftExpand.xml

@@ -0,0 +1,3 @@
+<technique vs="UnlitParticle" ps="UnlitParticle" vsdefines="VERTEXCOLOR SOFTPARTICLES" psdefines="DIFFMAP VERTEXCOLOR SOFTPARTICLES EXPAND">
+    <pass name="alpha" depthwrite="false" depthtest="false" blend="alpha" />
+</technique>

+ 6 - 0
bin/Data/Materials/LitSmokeSoft.xml

@@ -0,0 +1,6 @@
+<material>
+    <technique name="Techniques/DiffLitParticleAlphaSoft.xml" />
+    <parameter name="MatDiffColor" value="0.5 0.5 0.5 0.5" />
+    <parameter name="SoftParticleFadeScale" value="1" />
+    <texture unit="diffuse" name="Textures/Smoke.dds" />
+</material>

+ 5 - 0
bin/Data/Materials/SmokeSoft.xml

@@ -0,0 +1,5 @@
+<material>
+    <technique name="Techniques/DiffUnlitParticleAlphaSoft.xml" />
+    <parameter name="SoftParticleFadeScale" value="1" />
+    <texture unit="diffuse" name="Textures/Smoke.dds" />
+</material>