unlimited planar reflections & refraction (update)

Ah, thank you. Yes, that’s the one. I should also add that I’m utilizing a 64 bit processor. As for the crashes upon exit of the GE, I only notice that happening when I’m unsure if my cursor (which isn’t visible) might have moved outside of the window currently running the GE when I press ESC. It’s more of a personal superstition than anything. :slight_smile:

Unfortunately, I can’t provide any real help with this. I can only tell you my experiences and hopefully others might be able to replicate them to their benefit.

On a side note, I’m psyched to see the ocean shader in action.

8800 GTS 512 MB
Intel Core 2 Duo 2.2 GHz
1 GB RAM

The FPS counter is OVER 9000!!!
Nah jk lol, runs at 60 fps without lags or anything, THIS IS JUST AMAZING :smiley:

Ah thank you HG1. This is the 1st 2.62 blender build that works with textures and doesn’t crash on exiting the GE. The blenderplayer isn’t working correct like you said but meanwhile I found the autoplay function in blender GE :slight_smile:

But I have a technical question: Is it that the watershader can only be used at one height level? So if I wanted to uses 2 waterlevels it is impossible to get according reflections and refraction? I have put 2 waterplanes next to eachother and shifted the height of one and the reflections seem to be absolute. Before breaking my head on the shader code I thought I better ask.

thanks for a great shader. I am using in 2.62 in a scene which was reloaded and unfortunately it CTD when it reloaded due to the reflection and refraction attributes in watertexture.py being stored in bge.logic

I modified the code to make their scope local - works for me (I have however changed the viewer and camera assignments formy application)


from bge import logic as g
from bge import texture
from mathutils import *
from math import *
import bgl

cont = g.getCurrentController()
own = cont.owner
scene = g.getCurrentScene()
objlist = scene.objects

reflsize = 512 #reflection tex dimensions
refrsize = 512 #refraction tex dimensions
offset = 0.2 #geometry clipping offset

#texture background color - the blue
bgR = 0.63
bgG = 0.84
bgB = 1.0
bgA = 0.0

activecam = scene.active_camera
#viewer = objlist['Camera.temp']
viewer = activecam#objlist['camera']
watercamera = objlist['watercamera'] #camera used for rendering the water
#camera = objlist['Camera']
camera = activecam#objlist['camera']

#setting lens and projection to watercamera
watercamera.lens = activecam.lens
watercamera.projection_matrix = activecam.projection_matrix

#rotation and mirror matrices
m1=Matrix(own.orientation)
m2=Matrix(own.orientation)
m2.invert()

r180 = Matrix.Rotation(radians(180),3,'Y')
unmir = Matrix.Scale(-1,3,Vector([1,0,0]))

#disable visibility for the water surface during texture rendering
own.visible = False

###REFLECTION####################

#initializing camera for reflection pass
pos = (viewer.position - own.position)*m1
watercamera.position = own.position + pos*r180*unmir*m2     
ori = Matrix(viewer.orientation)
ori.transpose()
ori = ori*m1*r180*unmir*m2
ori.transpose()
watercamera.orientation = ori

#culling front faces as the camera is scaled to -1
bgl.glCullFace(bgl.GL_FRONT)

#plane equation
normal = own.getAxisVect((0.0, 0.0, 1.0)) #plane normals Z=front

D = -own.position.project(normal).magnitude #closest distance from center to plane
V = (activecam.position-own.position).normalized().dot(normal) #VdotN to get frontface/backface

#invert normals when backface
if V<0:
    normal = -normal

        
#making a clipping plane buffer
plane = bgl.Buffer(bgl.GL_DOUBLE, [4], [-normal[0], -normal[1], -normal[2], -D+offset])
bgl.glClipPlane(bgl.GL_CLIP_PLANE0,plane)
bgl.glEnable(bgl.GL_CLIP_PLANE0)


try:
    own['reflection'].refresh(True)
except:
    reflection = texture.Texture(own, 0, 0)
    reflection.source = texture.ImageRender(scene,watercamera)
    reflection.source.capsize = [reflsize,reflsize]
    reflection.source.background = [int(bgR*255),int(bgG*255),int(bgB*255),int(bgA*255)]
    own['reflection'] = reflection

#restoring face culling to normal and disabling the geometry clipping
bgl.glCullFace(bgl.GL_BACK)
bgl.glDisable(bgl.GL_CLIP_PLANE0)

###REFRACTION####################

#initializing camera for refraction pass
watercamera.position = viewer.position
watercamera.orientation = viewer.orientation

#making another clipping plane buffer
plane = bgl.Buffer(bgl.GL_DOUBLE, [4], [normal[0], normal[1], normal[2], -D+offset])
bgl.glClipPlane(bgl.GL_CLIP_PLANE1,plane)
bgl.glEnable(bgl.GL_CLIP_PLANE1)


try:
    own['refraction'].refresh(True)
except:
    refraction = texture.Texture(own, 0, 1)
    refraction.source = texture.ImageRender(scene,watercamera)
    refraction.source.capsize = [refrsize,refrsize]
    refraction.source.background = [int(bgR*255),int(bgG*255),int(bgB*255),int(bgA*255)]
    own['refraction'] = refraction

#disabling the geometry clipping
bgl.glDisable(bgl.GL_CLIP_PLANE1) 
#restoreing visibility for the water surface
own.visible = True

HTH
Neil.

Reflection…
Dispersion…
The water…
THE WATER!!!

Omg… i feel sick… :wink:

A video of my planar reflections and water/underwater shader in action:

Wanna moooooooooooore! :smiley:

Wanna moooooooooooore!

alrighty: 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)

Very cool looking, martinsh. Great work!

However, I’m a bit concerned that we’ll never be able to use this in any trunk builds of Blender, as HG1’s patch hasn’t been added, as far as I know. It’s kind of dissappointing, as this is really the only way to have good looking water reflections in BGE. I don’t know anything about the Blender development process, but might it be possible to add HG1’s patch into the Candy branch? That would be great.

Core dumped at opening :frowning:
(my config is a dual xeon with a quadro 4000, Ubuntu 64 bit. I’ve tried only with Blender 2.63.13 svn 48659)
I’ll wait patiently for the next progress

Really appreciate your work!

Sparazza

weird. re-saved it and uploaded again. Try downloading in few minutes.

laser blaster - yeah, I will be working on that.

I’m sorry but it’s all my fault! I’ve used the svn version but with official 2.63a goes well!

Sparazza

Here’s a slightly better quality video.

Great video - nice and high-quality.

Wow. Martinsh, you are my hero. I can’t wait to see what my flight sim looks like with this for water!

Tested on AMD Radeon 5970 - 12.7 Catalyst drivers, and I get between 400 and 600 FPS at 1920x1080 8xMSAA with no graphical glitches. It looks amazing :slight_smile:

WHAT! HOLY S##T! How did I just find this. I F’ing love you Martinsh. Get this in trunk, NOW! No matter, is that caustics? Also, as of late, whenever I open up the run a game with a mouselook script, the camera starts going crazy and just flipping all over at warp 8.

I notice there is some sort of bleeding going on around the edges of things:


Any ideas?

Incredible!

My part of the UK is experiencing floods, its nice o have such pretty water for a change-incredible work, Martinsh!

I cannot seem to be able to alter the position of the sun though- but I suppose, who cares? I’m happy having a paddle!

OK, got control of the sun and have some nice Hawaiian sunsets…this HAS to go into Blender somehow!