So what did I want to ask is- why do martinsh watershader crash when I go to the scene with water, switch to other scene, than return back to scene with water. When I return to the scene, blender just closes. How to resolve that.
Martinsh made several water shader scenes that he posted online. which one did you use?
I think I used v1.0 or v1.1. I used the one which works for me(doesn’t put the buffer as blue plane, but as a bonus texture. It hasn’t got the underwater shader…
For example- I would like to get the 0.95, but it looks like fully grey(no refraction and reflection) except underwater and in while looking at it from angle 1-3 degrees(when buffer layers is off).
No, crap! I used v1.1:D Others doesn’t work for me…
Hello! I’ve the same bug. You should report it to the bug tracker https://developer.blender.org/maniphest/task/create/?project=30&type=Bug with a simple .blend example (apparently it’s related to libpng…). If you can test with other versions of Blender to see when the bug appeared for the first time.
Is this a bug with the latest version only? It runs fine for me under 2.72.
I just tested with 2.69 and it crashes too on my computer (windows 8.1 blender 64 bits). I’ll test with 32 bits to see if it works… No… I get (sometimes) this warning before the crash: libpng warning: iCCP: known incorrect sRGB profile (I don’t know if it is relevant)
Tested with this .blend: http://www.mediafire.com/download/a47mh539kr8q8a8/water_surface_1.1test.blend
(space to switch beetween scenes)
Tested also with 2.72b: same crash
I tested it on both- 2.73a and 2.72b aswell as 2.7 and they all has the same bug… I have Linux 64-bit…
Yes I think you can report the bug
It seems to be a videotexture problem.
Edit:
I found the fault. The problem is that martins has used a global variable to initialized the videotexture.
If the scene is switched the global variable still exist but the videotexture is freed.
You need to use a property which will be reseed to get this working.
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
bgR = 0.63
bgG = 0.84
bgB = 1.0
bgA = 0.0
activecam = scene.active_camera
viewer = activecam
#if 'initcam' not in own:
# cam = bpy.data.cameras.new('rendercamera')
# cam_ob = bpy.data.objects.new('watercamera', cam)
# bpy.context.scene.objects.link(cam_ob)
# own['initcam'] = 1
rendercamera = objlist['rendercamera'] #camera used for rendering the textures
#setting lens and projection to rendercamera same as active camera
rendercamera.lens = activecam.lens
rendercamera.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
pos = own.position + pos*r180*unmir*m2
ori = Matrix(viewer.orientation)
ori.transpose()
ori = ori*m1*r180*unmir*m2
ori.transpose()
#delay reduction using delta offset
if 'oldori' not in own:
own['oldori'] = ori
own['oldpos'] = pos
own['deltaori'] = own['oldori']-ori
own['deltapos'] = own['oldpos']-pos
own['deltaori'] = own['oldori']-ori
own['deltapos'] = own['oldpos']-pos
#orienting and positioning the reflection rendercamera
rendercamera.orientation = ori - own['deltaori']
rendercamera.position = pos - own['deltapos']
#storing the old orientation and position of the camera
own['oldori'] = ori
own['oldpos'] = pos
#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)
#rendering the reflection texture in tex channel 0
if 'reflection' not in own:
own['reflection'] = True
g.reflection = texture.Texture(own, 0, 0)
g.reflection.source = texture.ImageRender(scene,rendercamera)
g.reflection.source.capsize = [reflsize,reflsize]
g.reflection.source.background = [int(bgR*255),int(bgG*255),int(bgB*255),int(bgA*255)]
g.reflection.refresh(True)
#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
pos = viewer.position
ori = Matrix(viewer.orientation)
#delay reduction using delta offset
if 'oldori1' not in own:
own['oldori1'] = own.orientation
own['oldpos1'] = own.position
own['deltaori1'] = own['oldori1']-viewer.orientation
own['deltapos1'] = own['oldpos1']-viewer.position
own['deltaori1'] = own['oldori1']-ori
own['deltapos1'] = own['oldpos1']-pos
#orienting and positioning the refraction rendercamera
rendercamera.orientation = ori - own['deltaori1']
rendercamera.position = pos - own['deltapos1']
#storing the old orientation and position of the camera
own['oldori1'] = ori
own['oldpos1'] = pos
#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)
#rendering the refraction texture in tex channel 1
if 'refraction' not in own:
own['refraction'] = True
g.refraction = texture.Texture(own, 0, 1)
g.refraction.source = texture.ImageRender(scene,rendercamera)
g.refraction.source.capsize = [refrsize,refrsize]
g.refraction.source.background = [int(bgR*255),int(bgG*255),int(bgB*255),int(bgA*255)]
g.refraction.refresh(True)
#disabling the geometry clipping
bgl.glDisable(bgl.GL_CLIP_PLANE1)
#restoreing visibility for the water surface
own.visible = True
Thanks HG1, it works!
Ok Thanks!