unlimited planar reflections & refraction (update)

The last file does not use nodes. It has a custom shader applied to it.

I finally finished proper reflection/refraction texture rendering.
Now the reflecting/refracting plane can be anywhere in any orientation.
Here are some of the uses of the technique:
blend: (Blender 2.6x only)

works fine in Blender 2.60
on old iMac 2006
Intel Core 2 Duo 2 GHz

I would like to hear how it works for you guys.

blend file has scenes:
“ground reflect” - tiled reflecting floor
“reflect” - just reflection of stained glass
“refract” - just refraction of stained glass
“refract_object” - refracting suzanne
“stained_glass” - stained glass
“stained_glass_2” - stained glass without diffuse texture
“wall_mirror” - simple vertical mirror

screenshots of each scene:

ocean is still in the making.

btw, yah it does some weird things in Blender 2.5x
I guess some stuff in bge.mathutils has changed since 2.5
So I strongly suggest you open the blend in 2.6x

oh and I accidently messed up the first file, thats why it was black for some of you. I have updated the demo.

screenshot how it should look like:

I love the way that the reflections distort the light. it’s extremely realistic. Amazing work.

Ô, well, yeah it is rather…

… eventually taking BGE to a Level that I always dreamt of.
I thank you very, very much for this, martinsh! : )

These Methods should be implemented as Standard Material/Texture Options. This is one of these exact Things that People want to see from a Game Engine, and imagine how much BGE could be pushed if such Effects one of the Basic Methods for every BGE Beginner (achieving good Graphics easily can be very motivating).

Yes I agreewith C.A. this is really perfect, its something, well just perfect… thanks a lot by sharing this with us!

+100 f*cking trillion on that! XD

Instead of the beautiful water I get this error on the console:
----Fragment shader error ----
0(39) : error C1105: cannot call a non-function
---- Fragment shader failed to compile ----

This is on Blender2.61 Win7 8800GT

I just downloaded 2.6 off the Blender site and tried to run your newest file, and what do you know, I got a bunch of shader errors in the console. Obviously, the shader doesn’t work. There are too many errors to type up, so here’s a picture:

…Something is very, very wrong:(

Any idea what the problem could be? Maybe I should update my gpu driver?

I get black meshes when I press ‘P’, maybe because I’m using a recent SVN build and not the official release (which I know there were some changes since 2.61).

My GeForce 8800GT works with GLSL and the 2D filters so it might be that this will need an update for the newer revisions.

Agreed. Perhaps if you enable Refraction in the material settings, much like the Minnaert and Buffer Shadow options work in the BGE?

Thanks laser blaster, this helps a lot. I think I fixed the issue. It was a small mistake, but I though my ATI card would point it out.
Now take a look at the files, please. I have replaced them with fixed ones (at least I hope so…)

C.A.ligári thanks. Yeah having real reflections and refractions for masses as a built-in function in materials options would be something awesome for BGE. Harmony branch will surely make this an easier task.

I still get a fault message from the fragmet shader in the planar_reflections_1.0.blend file.
The fault is in the script line 68 (fragmet shader line 39), because reflect is a 2D texture it is no function “vec2 rcoord = (reflect(vVec,nVec).st);”.

This is amazing, and it works in MultiTextured mode :smiley:
Could this ever be an add-on thats sits into the material tab in the Game Engine? :slight_smile:

you are right, thank you! Fixed it.
I have to remember not to call textures in function names :slight_smile:

It’s not a black plane anymore, but there are still issues for me. The first is that glClipPlane simply doesn’t work. Things that are below the water are reflected and things that are above it are refracted. The second issue is that I only get refractions, no reflections. If I swap the texture slots that the refractions and reflections render to, then I can get reflections to work instead of refractions. I’m not getting any errors in the console anymore.

Edit: I found the source of the problem. The fresnel term is coming out all black, all the time, so only the refraction is being shown.

everything seems to work, however the water demo you posted has an odd bug with the reflection. it looks like the reflection starts higher than the waters surface.

I should clarify, this only happens when an object is half submerged in the water.

Works just fine on my Macbook!

Amazing work. Very cool. :cool:

What i can say? After all amazing works it’s not a surprise, but i’m just astonished with the results.
Project the reflection in View Space is a clever trick, :smiley:
I can see 2012 will be a happy year for bge lovers xD

Congrats and really thanks for share!
Your work really adds a huge value to BGE

Amazingly nice! too bad isnt too flexible ,like applying to already made materials without “Shadeless” enabled, multiple textures and ramps.
I might be wrong tho.
Great Job anyway!