Planar reflections in the BGE

After some request about reflection in the Blender Game Engine (BGE) I decided to write a small post about it.

There are three techniques to achieve this effect in the BGE, as far as I know, which are listed below:

  • Shader based (fragment viewport coordinates – GPU expensive)
  • Render to texture (with texture.ImageMirror() )
  • Duplicated and mirrored geometry
So, lets have a look on each method.

Shader based reflections is the method that modern game engines uses to render planar reflections. Martinsh has developed a demo in the BGE that uses fragment viewport coordinates instead geometry UV map , wich according to his description  the reflecting surface size can be unlimited with this method, but take into account that you will need a decent Video Card to run this.

Here is the link to the Blenderartist forums where you can see the Martinsh post about this, with videos and sample files.


Render to texture  module allows us to manipulate textures during the game.

Several sources for texture are possible: video files, image files, video capture, memory buffer, camera render or a mix of that.

The video and image files can be loaded from the internet using an URL instead of a file name.

In addition, you can apply filters on the images before sending them to the GPU, allowing video effect: blue screen, color band, gray, normal map.

bge.texture uses FFmpeg to load images and videos. All the formats and codecs that FFmpeg supports are supported by this module, including but not limited to:

  •  AVI
  •  Ogg
  •  Xvid
  •  Theora
  •  dv1394 camera
  •  video4linux capture card (this includes many webcams)
  •  videoForWindows capture card (this includes many webcams)
  •  JPG

(source & more info)

And watch this video and read the description inthe youtube page (thanks maykon!)

Monster (BlenderArtist forum member) has developed a more friendly module that allow us to manage more easily the video texture module, grab the blend file here with demo and have a look.

More tutorials about this here:

Video Texture ImageMirror: flip

Render to Texture


And the last method is by duplicating geometry and mirroring as simple as that, maybe is not the most fancy method but I think is widely used in mobile platforms due to hardware restrictions and optimizations.

fake_reflections

Grab sample file here

Hope you fin this useful, thanks!

Edit:
Esay Game Addon can help you too!

You may also like...

6 Responses

  1. ok, thanks
    third is only one really clear (of course…) 🙁

    second method seems good enough but video quality is too bad to understand steps… (It’s no clear how get video-reflection to use in texture)

    monster works seems great! (I already saw that) … but there are no step by step tutorial for a beginner.

    so, good start, now I’ll try to create some useful tools for beginner

    • Mata says:

      Yes, first two methods are not so friendly for newcomers or non programer people, altough Monster modules are quite more easy to understand.

      Anyway, maybe with some environment / reflection maps you can get some interesting results, not every game uses realtime reflection maps because are gpu expensive 🙂

  2. Pier Carlo Ricci says:

    ok… perfect mirror solved… z-transparent is a good solution in some cases… and I agree on real high quality reflection shader (They are too much “professional” in this fase but a good example of possibilities targets)..

    now I try to create a simple cube mapping projection… I search a lot but I can’t find a working method.
    this is best tutorial http://mattline1.blogspot.it/2014/07/custom-glsl-shaders-in-bge-view.html but also his sample file doesn’t works 🙁

    I able to create cube map source image and save it in .png but I can’t find a working python shader to apply … this is very frustrating…

  3. Yes, of course, BPCEM shader seems really great! I’ve been working days on this file to extract a generic python shader to reuse but nothing… it’s too much complex for me.

  1. May 21, 2015

    […] Addon By Mpan3 in which you can archieve some nice effects in a very easy way, like reflections, post processing among […]

Leave a Reply

Your email address will not be published. Required fields are marked *