water reflection

Is water reflection something done only with shaders? I just want to make a reflection of my sky on a flat water plane. I only know about cubemaps when it comes to reflection, but I dont think thats of any use in this case.

I’ve done shaderless water a long time ago. This code may help:

cm = CardMaker("water")
cm.setFrame(-1, 1, -1, 1)
self.water = render.attachNewNode(cm.generate())
self.water.setScale(4096)
self.water.lookAt(0, 0, -1)
self.water.setZ(62.365)
self.water.setShaderOff(1)
self.water.setLightOff(1)
self.water.setAlphaScale(0.5)
self.water.setTransparency(TransparencyAttrib.MAlpha)
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.water.hide(BitMask32.bit(1))
fir.hide(BitMask32.bit(1))
wtexture = wbuffer.getTexture()
wtexture.setWrapU(Texture.WMClamp)
wtexture.setWrapV(Texture.WMClamp)
wtexture.setMinfilter(Texture.FTLinearMipmapLinear)
self.wplane = Plane(Vec3(0, 0, 1), Point3(0, 0, self.water.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.water.projectTexture(TextureStage("reflection"), wtexture, self.wcamera)
#base.bufferViewer.toggleEnable()

Well Im glad there is a way.

Though it doesn’t work for me. I commented the line “fir.hide(BitMask32.bit(1))” and changed the Config.prc file by adding “framebuffer-stencil #t” and changing “stencil-bits 1” but the buffer viewer is blank and I dont see anything.

Well, you still need to adjust the water camera to be flipped over the plane, using something like this:

        taskMgr.add(self.update_camera, 'update-water', sort=45)

    def update_camera(self, task):
        mat = base.cam.getMat(self.wplanenp)
        mat *= self.wplane.getReflectionMat()
        self.wcamera.setMat(mat)
        return task.cont

I’m not sure why you’re messing with your stencil buffer. Reflections have nothing to do with the stencil buffer.

Either the posting dates are wrong for me or this is the second post that resurrects years-old threads. :stuck_out_tongue: