DepthMask

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Added DepthMask.shader, aka HullCover.shader)
 
(Links, and comments in the shader source.)
Line 1: Line 1:
Author: Neil Carter (NCarter)
+
Author: Neil Carter ([[:User:NCarter|NCarter]])
  
 
== Description ==
 
== Description ==
Line 24: Line 24:
 
----
 
----
  
''Note that the example project gives the shader the name 'HullCover.shader'.  See the discussion page regarding this.''
+
''Note that the example project gives the shader the name 'HullCover.shader'.  See the [[:Talk:DepthMask|discussion]] page regarding this.''
  
 
==ShaderLab - DepthMask.shader==
 
==ShaderLab - DepthMask.shader==
Line 31: Line 31:
 
Shader "DepthMask"
 
Shader "DepthMask"
 
{
 
{
SubShader
+
    SubShader
{
+
    {
Lighting Off
+
        // Turn off lighting, because it's expensive and the thing is supposed to be
ZTest LEqual
+
        // invisible anyway.
ZWrite On
+
 
ColorMask A
+
        Lighting Off
Pass {}
+
 
}
+
        // Draw into the depth buffer in the usual way.  This is probably the default,
 +
        // but it doesn't hurt to be explicit.
 +
 
 +
        ZTest LEqual
 +
        ZWrite On
 +
 
 +
        // Don't draw the RGB colour channels, just the alpha channel.  This means
 +
        // that nothing visible is drawn.  Ideally, I would have liked to set ColorMask
 +
        // to draw nothing at all, but it doesn't seem to be possible to say anything
 +
        // like ColorMask None.
 +
 
 +
        ColorMask A
 +
 
 +
        // Do nothing specific in the pass:
 +
 
 +
        Pass {}
 +
    }
 
}
 
}
 
</shaderlab>
 
</shaderlab>

Revision as of 12:59, 28 May 2006

Author: Neil Carter (NCarter)

Contents

Description

DepthMask.shader in use on the example project.

This shader draws faces which are invisible, but which still appear in the depth buffer. This makes it possible to prevent subsequently-drawn objects from appearing behind those faces.

Usage

The example project shows how to use the shader to cut a hole in a water plane to prevent the water from appearing inside a boat's hull.

It is necessary to use three cameras to force the rendering order:

  • The first draws the boat hull and all other normal objects.
  • The second draws a skin over the top of the boat's hull using the DepthMask shader. The skin objects must be in a special layer which only this camera draws.
  • The third draws only the water. The water must be in its own layer and is only drawn by this camera.

The second and third cameras do not clear the colour or depth buffers. Of course, all three cameras must also move as one, so you may want to put them in an empty GameObject to keep them together.

Example Project

boat_2.zip, 209KB


Note that the example project gives the shader the name 'HullCover.shader'. See the discussion page regarding this.

ShaderLab - DepthMask.shader

<shaderlab> Shader "DepthMask" {

   SubShader
   {
       // Turn off lighting, because it's expensive and the thing is supposed to be
       // invisible anyway.
       Lighting Off
       // Draw into the depth buffer in the usual way.  This is probably the default,
       // but it doesn't hurt to be explicit.
       ZTest LEqual
       ZWrite On
       // Don't draw the RGB colour channels, just the alpha channel.  This means
       // that nothing visible is drawn.  Ideally, I would have liked to set ColorMask
       // to draw nothing at all, but it doesn't seem to be possible to say anything
       // like ColorMask None.
       ColorMask A
       // Do nothing specific in the pass:
       Pass {}
   }

} </shaderlab>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox