Difference between revisions of "Shading Technique - Linear Depth Buffer"
Line 16: | Line 16: | ||
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 27: | ||
// 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 65: | Line 61: | ||
} | } | ||
</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 wathever 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 == |
Revision as of 02:37, 7 September 2008
|
|