I bumped into a strange problem with rendering water.
In my scene I have a water plane rendered with a Cg shader and a sky dome rendered with a GLSL shader. Each one works ok on his own, but as soon as I put them both in a scene the water shader goes nuts.
I’m using the code for water that was reposted here on the forum again and again, not even sure who the original author was (drwr?)
#Create the plane geometry and add it to the scene
maker = CardMaker("grid")
maker.setFrame( 0, 2000, 0, 2000)
self.waterNP = NodePath('waterSurface')
node = self.waterNP.attachNewNode(maker.generate())
node.setHpr(0,-90,0)
node.setPos(-1000, -1000, 0)
self.waterNP.reparentTo(render)
#Add a buffer and camera that will render the reflection texture
wBuffer = base.win.makeTextureBuffer("water", 512, 512)
wBuffer.setClearColorActive(True)
wBuffer.setClearColor(base.win.getClearColor())
self.wCamera = base.makeCamera(wBuffer)
self.wCamera.reparentTo(render)
self.wCamera.node().setLens(base.camLens)
self.wCamera.node().setCameraMask(BitMask32.bit(1))
self.waterNP.hide(BitMask32.bit(1))
#Create this texture and apply settings
wTexture = wBuffer.getTexture()
wTexture.setWrapU(Texture.WMClamp)
wTexture.setWrapV(Texture.WMClamp)
wTexture.setMinfilter(Texture.FTLinearMipmapLinear)
#Create plane for clipping and for reflection matrix
self.wPlane = Plane(Vec3(0, 0, 1), Point3(0, 0, self.waterNP.getZ()))
wPlaneNP = render.attachNewNode(PlaneNode("water", self.wPlane))
tmpNP = NodePath("StateInitializer")
tmpNP.setClipPlane(wPlaneNP)
tmpNP.setAttrib(CullFaceAttrib.makeReverse())
self.wCamera.node().setInitialState(tmpNP.getState())
self.waterNP.projectTexture(TextureStage("reflection"), wTexture, self.wCamera)
But the moment I add my sky shader the clip plane stops working. Some screens:
No shader, clip plane works:
Shader on, clip plane works not:
The code is simplish, so are the shaders (attaching it all to this post, comment out line 22 to get what’s on screen #1). What can I do to make it work?
mini.zip (885 KB)