New realtime refraction method!

Hey all!

Since I’ve asked a lot in the past weeks I thought I would have to give something back to the community,
here is the realtime refraction system I have developed, if you like it I will also release my realtime procedural grass script and the realtime terrain deformation…

So I am not 100% sure wether I am the first one to have found that way for refractions, but I did not see anything similar so far.
The refractions are based on a texture that is rendered from the current cameras perspective, but the texture is rendered without the refractive objects (objects with a “renderCulling” will be culled).
All refractive objects have material with projects that texture to it based on view coordinates.
That’s it basically!

Here are examples of what this can be used for:

  • Water
  • Glass
  • Heat hazes

Check out this .blend and let me know about how you like it and what you don’t like!

http://www.mediafire.com/?7htmimpt12ppp9t

Cheers, Lukas!

http://abload.de/img/fract19nzjd.png

http://abload.de/img/fract2glant.png

http://abload.de/img/fract3sfagr.png

This is great :smiley: thanks!
Just wondering how would you implement this into your own game?

This is quite simple, just append the render plane (the one under the room), the refraction_camera and an refraction object with the material you need to your scene!
If you want your own objects to be refractive, apply a refraction material to it and add a game property called “renderCulling” to it.

I’ve been searching for heat haze for so long, I even tried it myself using code snippets of already working refraction scripts and failing hard. I also tried to recreate it the way you did (camera to texture without the objects in view - but again failed hard ! T_T) thank you very much. I’ll try to combine that with my realtime fire. Will be a great outcome I hope.

great!! Thanks!

Dude! This is seriously awesome (and pretty fast too)!!! Now if only we could get a decent lights performance BGE would really rocknroll :slight_smile:

Lukas, that’s a great contribution and the demo blend really shows it off well. Thanks for sharing your hard work dude, it’s really appreciated! I’m looking forward to seeing what others do with this method particularly fire/heat haze combo sounds like an obvious next step.

I’ll no doubt be using this myself (or a variation of it) on my current projects if the resource hit is manageable.

wow this is great!! I was able to reverse engineer the method and I got to say, very well done! I will be using this method in a lot of games… thanks. :slight_smile:

Thanks for your great support, I am glad you like it!

I discovered some weird clipping in the refraction texture when changing the focal length (in this case set to 22mm).


I think you need to adjust one of the mapping or mix nodes

i’ve been dying for this. this is really great. thanks!

Looks so good! The way you make the glass is very effective, but, the reflection is strange- whan I look up I don’t see any sky, but I see it in reflection(I would reccomend to bake reflection texture in render and than use that image in game).

Cool, but I found a flaw. (screenshot) Anyway, thanks!


I don’t think that’s a flaw

How does the real time terrain deformation work?

Refraction camera must be attached to the object. But here, it is attached to the player. Due to this refraction works on all sites but there is this problem.

Excellent, I am pretty sure that I understand the script pretty well but I have one confusion…why can’t you use the same camera for both the view and as the refraction camera? I mean I know it doesn’t work but for what reason?

It’s a limitation of BGE. At the moment (for no particularly good reason) you can’t use bge.texture.ImageRender on the active camera. Yes, it bothers me.

Thanks for the quick reply…also one more thing, the objects are being made invisible and then visible in the same script, then why don’t they flicker? or is it happening REALLY fast?