Difference between revisions of "Shading Technique - Linear Depth Buffer"
(New page: {| border="0" | {{ContentBlock|width=800|color=white |content={{!!}} == Overview == '''Why using a custom Depth buffer?''' The default depth buffer generated by Horde3D is a non-linear...) |
(Change creation date to the good one) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 11: | Line 11: | ||
== The shader == | == The shader == | ||
− | |||
'''Vertex shader:''' | '''Vertex shader:''' | ||
Here, you can change the max distance constant. It determine the range and the precision of the depth buffer. | Here, you can change the max distance constant. It determine the range and the precision of the depth buffer. | ||
− | As you can see, there is two ways to calculate the depth of a vertex. The first one is to take the view space position of the vertex, and with this, you can take the Z value to get the depth. The second way is to create a vector from the view position to the vertex position, wich gave a | + | As you can see, there is two ways to calculate the depth of a vertex. The first one is to take the view space position of the vertex, and with this, you can take the Z value to get the depth. The second way is to create a vector from the view position to the vertex position, wich gave a slightly different result. |
{{CppSourceCode| | {{CppSourceCode| | ||
Line 27: | Line 26: | ||
// Depth vertex color | // Depth vertex color | ||
varying vec4 vVertexColor; // Black/near --> White/far | varying vec4 vVertexColor; // Black/near --> White/far | ||
− | + | ||
− | |||
− | |||
− | |||
− | |||
const float MAX_DISTANCE = 1000.0; | const float MAX_DISTANCE = 1000.0; | ||
Line 41: | Line 36: | ||
// Calculate view space position | // Calculate view space position | ||
vec4 vsPos = calcViewPos( pos ); | vec4 vsPos = calcViewPos( pos ); | ||
− | |||
− | |||
− | |||
// Calculate Depth | // Calculate Depth | ||
Line 62: | Line 54: | ||
<source lang="cpp" line="1"> | <source lang="cpp" line="1"> | ||
varying vec4 vVertexColor; | varying vec4 vVertexColor; | ||
− | |||
void main( void ) | void main( void ) | ||
Line 69: | Line 60: | ||
} | } | ||
</source>}} | </source>}} | ||
+ | |||
+ | == Pipeline integration == | ||
+ | |||
+ | First of all, you need to add a buffer in the setup tag: | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <Setup> | ||
+ | <RenderTarget id="VERTDEPTHBUF" depthBuf="true" numColBufs="1" format="RGBA16F" scale="1.0" /> | ||
+ | </Setup> | ||
+ | </source> | ||
+ | |||
+ | Then, you need to add the depth buffer pass: | ||
+ | |||
+ | <source lang="xml"> | ||
+ | <Stage id="VertexDepth"> | ||
+ | <SwitchTarget target="VERTDEPTHBUF" /> | ||
+ | <ClearTarget depthBuf="true" colBuf0="true" /> | ||
+ | <DrawGeometry context="DEPTH" class="~Translucent" /> | ||
+ | </Stage> | ||
+ | </source> | ||
+ | |||
+ | With this, you only have to bind the VERTDEPTHBUF to any stage you want. | ||
+ | |||
+ | I have called the depth pass DEPTH, but you can call it whatever you want. Don't forget to put the shader pass in EACH shaders that need to be affected by the depth buffer. | ||
== How to use it == | == How to use it == | ||
− | You must put the shader in EACH shaders that need to be affected by the depth buffer. | + | You must put the shader pass in EACH shaders that need to be affected by the depth buffer. |
== Example Result == | == Example Result == | ||
Line 78: | Line 93: | ||
== Pictures == | == Pictures == | ||
− | + | http://img255.imageshack.us/img255/7348/customdepthqi6.png | |
== To-Do List for this Article == | == To-Do List for this Article == | ||
- Add an exemple <br /> | - Add an exemple <br /> | ||
− | |||
− | |||
}} | }} | ||
Line 92: | Line 105: | ||
|version = 1.0 | |version = 1.0 | ||
|horde3dversion = 1.0 beta | |horde3dversion = 1.0 beta | ||
− | |released = 2008- | + | |released = 2008-09-06 |
|author = [http://www.horde3d.org/forums/memberlist.php?mode=viewprofile&u=154 Mikmacer]| | |author = [http://www.horde3d.org/forums/memberlist.php?mode=viewprofile&u=154 Mikmacer]| | ||
}} | }} | ||
|} | |} | ||
[[category: Technique]] | [[category: Technique]] |
Latest revision as of 03:03, 7 September 2008
|
|