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:
ocean water/underwater demo v0.95
It is a work in progress, shader code is a big mess so I would not recommend using it for projects.
WASD + mouse, LMB - sungrab
P - exit game (my “Esc” key is dead)
only planar reflections setup
other uses of the technique (contains many scenes):
update (june 22, 2013)
water surface demo (v1.1):
changes since 1.0:
• much easier to include in your project
• fixed geometry clipping issue experienced on nvidia cards
• 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
This is too beautiful for the Game Engine. Remove it for sheer blasphemy.
Reported to the rest of the community for awesomeness.
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.
Yes, that’s crazy. Beautiful work.
yep it should look like that. Basic reflection and refraction texture, blended with fresnel term.
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.
I got amazed each time i see one of.your resources! Great stuff!
Oh my god. A new age is upon us folks.
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
Too bad it wont work, nice screens anyway.
You seem to be having lots of problems with your computer at the moment… Maybe you need to reinstall your drivers?
BTW can you please post the same blend as the one from the screen-shots with the amazing ocean?
My result its the same as Toxa17, i guess this works on ATI only.
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
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.
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…
Great as allways martinsh, thanks for sharing this awesome script with us!
ok nevermind, it’s OS inspecific. (doesn’t work on my windows 7 partition either.)
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).