unlimited planar reflections & refraction (update)

(crichards) #121

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.

(socker) #122

8800 GTS 512 MB
Intel Core 2 Duo 2.2 GHz

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

(musikai) #123

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.

(MoonlightSonata) #124

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

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


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

#culling front faces as the camera is scaled to -1

#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])

    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


#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])

    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
#restoreing visibility for the water surface
own.visible = True


(sparazza) #125

The water…

Omg… i feel sick… :wink:

(martinsh) #126

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

(sparazza) #127

Wanna moooooooooooore! :smiley:

(martinsh) #128

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.

WASD + mouse, LMB - sungrab
P - exit game (my “Esc” key is dead)

(laser blaster) #129

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.

(sparazza) #130

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!


(martinsh) #131

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

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

(sparazza) #132

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


(agoose77) #133

Here’s a slightly better quality video.

(SolarLune) #134

Great video - nice and high-quality.

(skykooler) #135

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

(MrPutuLips) #136

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:

(GraphiX) #137

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.

(skykooler) #138

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

Any ideas?

(1808) #139


(Rubbernuke) #140

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!