DepthMask

From Unify Community Wiki
Revision as of 12:45, 28 May 2006 by NCarter (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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 { Lighting Off ZTest LEqual ZWrite On ColorMask A Pass {} } } </shaderlab>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox