Mirror shaders

From GameStudio Wiki

Jump to: navigation, search

Using render target bitmaps for realtime reflections

For creating realtime mirrors or refelcting water surfaces, quite often you'll use a mirror view to render onto a bmap that is then used for a shader texture. However, in that case the same restrictions as for camera portals apply. Because the mirror view often is looking from within a solid block onto the scene, you'll otherwise get problems with artifacts and missing entities in the mirror.

Some Hints:

- The mirror view must have no obstacles in the way, and must look through a 'hole' in the wall or floor. For instance when implementing a water pool, leave it's bottom open in the level, and use a map entity for the pool's floor and side walls up to the water surface.

- Alternatively you could use the nocull flag for the mirror view, but this has the disadvantage of a lower frame rate.

- No model, sprite or terrain must penetrate the mirror surface.

- Set the mirror view layer at -1 in order to render it before the camera view is rendered. Otherwise you'll add one frame lag to the mirror.

- For testing your mirror view, comment out its bmap and set its layer at 1. This way you'll see its content in the upper left corner.

- For adding a clipping plane to your view, use a surface with mirror flag just for a normal mirror, and set it's portalclip flag. The plane runs through its view.portal_x, portal_y, and portal_z position vector. Its normal is given by view.pnormal_x, pnormal_y, pnormal_z. The plane is automatically set when a mirror surface comes into view. Note that due to a bug in DirectX9's clipping planes algorithm, the clipping is performed per software on level geometry only. No entities must penetrate the clipping plane. Only clipping planes parallel to the X, Y, or Z axes are supported.

Personal tools