Submitted by , posted on 01 September 2002



Image Description, by


This is a little system I put together for fast rendering of mirrors for (limited circumstance) in-game use. It's very simple indeed, but I don't recall seeing anything quite like it until the shots of Super Mario Sunshine, so I just had to figure it out (I've been trying for ages, and finally got it just about right -- it's the positioning/zooming code that was that hard part).

Each mirror has an associated camera, which is positioned 'opposite' the main viewing camera behind the mirror, and simply renders its view to the back buffer. This is then copied into the mirror's texture. Mirrors only render when the main camera is within a certain range, so they only affect frame rates when you can see them. There are a couple of limitations:
  • You can't have anything behind the mirror; not a problem if your level is designed around this (eg. a single-sided wall behind the mirror is fine, since its back can't be seen by the mirror's camera);

  • It's not 100% physically correct, so you get 'flattening' at shallow angles (which is avoided by the tried and tested method of... limiting where the player can go :)

  • It's limited to the size of the display mode here, since it renders to the back buffer (eg. asking or a 512 x 512 texture on a 640 x 480 screen will fail, though this example automatically creates a smaller texture). Bear this in mind when running the demo.
  • Anyway, it runs very well on modern machines (eg Geforce2/3 and up), and not too badly on low end (ATI Rage). It was developed on an ATI laptop, where it ran quite acceptably, but I've put frame-tweening code in for this public release, so it skips frames there :)

    Try it out here...

    http://www.hi-toro.com/misc/realmirrors.zip [640k]
    (Use cursors plus A and Z to move around; the mirror will follow you. Click and drag the mirror to move it manually.)

    Mail me if you need to know any more about it!



    [prev]
    Image of the Day Gallery
    www.flipcode.com

    [next]


     


    Copyright 1999-2008 (C) FLIPCODE.COM and/or the original content author(s). All rights reserved.
    Please read our Terms, Conditions, and Privacy information.