unlimited planar reflections & refraction (update)


(martinsh) #1

Hi,
Here is a method that usually every game engine uses to render planar reflections.
Well Blender has already texture.ImageMirror(), but it works fine unless you need a bigger reflecting surface like a lake or ocean.

My method uses fragment (viewport) coordinates instead of geometry UV map to project reflected image to. It means that the reflecting surface size can be unlimited.

Here are some screenshots of an ocean shader utilizing this method:
reflection and refraction texture size is 512 px:
http://dl.dropbox.com/u/11542084/water_wip3.jpg

http://dl.dropbox.com/u/11542084/water_wip2.jpg

http://dl.dropbox.com/u/11542084/water_wip1.jpg

https://youtu.be/zkdBGe8tfNw

update #02

https://youtu.be/UkskiSza4p0

update #03


ocean water/underwater demo v0.95
blend:
https://dl.dropbox.com/u/11542084/water_0.95_packed.blend

It is a work in progress, shader code is a big mess so I would not recommend using it for projects.
controls:
WASD + mouse, LMB - sungrab
P - exit game (my “Esc” key is dead)

ocean water/underwater demo v0.99 (in the the second video)
blend:
https://dl.dropboxusercontent.com/u/11542084/water_0.99_optimized.blend
http://www.blendswap.com/blends/view/68857

only planar reflections setup

All files are for Blender 2.6x only (due some changes in bge.mathutils)
and a blend file of the setup:
http://dl.dropbox.com/u/11542084/planar_reflections_1.0.blend
http://dl.dropbox.com/u/11542084/reflection.jpg

other uses of the technique (contains many scenes):
http://dl.dropbox.com/u/11542084/reflection_shaders_1.0.blend


update (june 22, 2013)
water surface demo (v1.1):
https://dl.dropboxusercontent.com/u/11542084/water_surface_1.1.blend

changes since 1.0:
• much easier to include in your project
• fixed geometry clipping issue experienced on nvidia cards

features:
• reflection & refraction
• normal map displacement (no real geometry displacement yet)
• water sunlight scattering
• chromatic aberration of refraction
• accurate fresnel term
• multi-frequency waves
• wave choppyness simulation
• bunch of tweakables to control all of this stuff

screenshots:
http://dl.dropbox.com/u/11542084/water_01.jpg

http://dl.dropbox.com/u/11542084/water_02.jpg

http://dl.dropbox.com/u/11542084/water_03.jpg

http://dl.dropbox.com/u/11542084/water_green.jpg


(agoose77) #2

This is too beautiful for the Game Engine. Remove it for sheer blasphemy.

EDIT:
Reported to the rest of the community for awesomeness.


(C.A.ligári) #3

First of all, the typical empty-sounding Words, but you know we all really mean it:
This is amazing!!! ʘ0ʘ

For me, the File doesn’t seem to refract, but as you say it’s WIP, I guess it just isn’t yet ATI-optimized.


(3dmedieval) #4

Yes, that’s crazy. Beautiful work.


(mokazon) #5

wow. just wow.


(Toxa17) #6

for ATI looks like this:


(martinsh) #7

Thanks guys!
yep it should look like that. Basic reflection and refraction texture, blended with fresnel term.

new demo:
http://dl.dropbox.com/u/11542084/planar_reflections_1.0.blend
this one uses custom shader for texture projection.

It also has a hacky camera setup, because the reflection and refraction textures are rendered 1 frame after the scene rendering, so it has a noticeable delay, so i delayed also the first person camera to match the reflections.

I have to polish the ocean shader and I will post it here also.


(JohnnyBlack) #8

I got amazed each time i see one of.your resources! Great stuff!


(The Red Hand) #9

Oh my god. A new age is upon us folks.


(laser blaster) #10

Huh, very strange… I get a bunch of errors in the console upon loading the file saying “Node type so-and-so(such as material, camera data, etc.) doesn’t exist anymore, removed”. Then I get a gray(1st version) or black(second version) plane where the water should be. Definitely not a gpu problem. Do I need to have 2.6 for this? Because I’m running 2.5. Your ocean shader look.

But anyway, your ocean shader looks absolutely amazing(in the screens), as good as almost any commercial game!

EDIT: I’ve found what the problem is: Blender is butchering your nodes setup, for whatever odd reason. I guess I’ll try it with 2.6


(JohnnyBlack) #11

Too bad it wont work, nice screens anyway.


(MrPutuLips) #12

You seem to be having lots of problems with your computer at the moment… Maybe you need to reinstall your drivers?


(MrPutuLips) #13

BTW can you please post the same blend as the one from the screen-shots with the amazing ocean?

Thanks :slight_smile:


(JohnnyBlack) #14

My result its the same as Toxa17, i guess this works on ATI only.


(agoose77) #15

It’s not a problem; He hasn’t released a version WITH the oceanshader yet. What you’re seeing is the reflection and refraction!
That alone is awesome!
He will release the shader when it’s finished, then you’ll see how good it is :wink:


(C.A.ligári) #16

For me, an ATI-User, it looks like on Toxa’s Screenshot and if it is officially stated to look like this, okay, but it just doesn’t initially show the Refraction. Reflection yes, but there is no obvious Refraction. I tried using a cloudy Normalmap of Mine for the so called »refraction« Texture and it still did not show any Changes, so I guess it must be handled in a different Way, but until I get to know or coincidentially find it out myself, I see no Refraction.


(Yoda Almighty) #17

Iam getting this issue on an nvidia card, so it’s not limited to ATI. I am curious if the issue is a mac/PC issue. let me do some tests…


(leonnn) #18

Great as allways martinsh, thanks for sharing this awesome script with us!


(Yoda Almighty) #19

ok nevermind, it’s OS inspecific. (doesn’t work on my windows 7 partition either.)


(laser blaster) #20

The issue with the nodes was definitely just specific to a certain build I was using(accidentally- I thought I was using standard Blender). After switching to the regular Blender 2.5, that issue has resolved itself.

Unfortunately, it still doesn’t work. I get an opaque black plane where the water should be. The issue lies in the “watershader” glsl shader script that you’re running.

After disabling that script by deleting the logic controller that activates it, I do get the reflections, but they’re tiled many times over the water plane in object or UV space(I attached an image). So RenderToTexture is working, however, your shader is not…

My gpu is an Nvidia Geforce 6800, which I believe(correct me if I’m wrong) should theoretically be able to handle any OpenGL effects that Blender can currently throw at it. I’m able to run all kinds of glsl effects with it, so I’m a bit puzzled as to why this one doesn’t work.


EDIT: By playing around with the nodes setup you had already made, I managed to get properly aligned reflections and refractions on the second .blend you posted. However, the clipping of geometry below the water line(for reflections) doesn’t work, for some reason(proabably due to the limitations of my gpu, nothing you could fix).