Issue With Two Cameras and Reflections/Water effects

Hello I am working on a group project for a class and we are trying to get realistic looking water to work in a game. For this project we have Panda3D opening in two windows.

This is the function that was created for setting up the camera in our World class:

    def setupCamera(self):
        '''setupCamera(self)'''
        camera.reparentTo(self.players[0].ship)
        camera.setPos(Vec3(0,40,10))
        #camera.setHpr(self.players[0].ship.getH(),self.players[0].ship.getP()-30,self.players[0].ship.getR())
        camera.lookAt(self.players[0].ship)
        base.camList[1].reparentTo(self.players[1].ship)
        base.camList[1].setPos(Vec3(0,40,10))
        base.camList[1].lookAt(self.players[1].ship)
        self.myRender2d = NodePath('myRender2d')
        self.myCamera2d = base.makeCamera2d(self.win)
        self.myCamera2d.reparentTo(self.myRender2d)

We are basically using the code from the Yet another roaming Ralph that has been posted by gskfreenet here.

This is basically all the code for setting up the water taken from that example with minor alteration:

        world.waterNP = render.attachNewNode(maker.generate())
        world.waterNP.setHpr(0,-90,0)
        world.waterNP.setPos(0,0,z)
        world.waterNP.setTransparency(TransparencyAttrib.MAlpha )
        world.waterNP.setShader(loader.loadShader( 'shaders/water1.sha' ))
        world.waterNP.setShaderInput('wateranim', Vec4( 0.03, -0.015, 64.0, 0 )) # vx, vy, scale, skip
        # offset, strength, refraction factor (0=perfect mirror, 1=total refraction), refractivity
        world.waterNP.setShaderInput('waterdistort', Vec4( 0.4, 4.0, 0.4, 0.45 ))    

        # Reflection plane
        world.waterPlane = Plane( Vec3( 0, 0, z+1 ), Point3( 0, 0, z ) )
        
        planeNode = PlaneNode( 'waterPlane' )
        planeNode.setPlane( world.waterPlane )
        
        # Buffer and reflection camera
        buffer = base.win.makeTextureBuffer( 'waterBuffer', 512, 512 )
        buffer.setClearColor( Vec4( 0, 0, 0, 1 ) )

        cfa = CullFaceAttrib.makeReverse( )
        rs = RenderState.make(cfa)
        
        world.watercamNP1 = base.makeCamera( buffer )
        world.watercamNP1.reparentTo(world.players[0].ship)
        world.watercamNP2 = base.makeCamera( buffer )
        world.watercamNP2.reparentTo(world.players[1].ship)
        
        sa = ShaderAttrib.make()
        sa = sa.setShader(loader.loadShader('shaders/splut3Clipped.sha') )

        cam1 = world.watercamNP1.node()
        cam1.getLens( ).setFov( base.camLens.getFov( ) )
        cam1.getLens().setNear(1)
        cam1.getLens().setFar(5000)
        cam1.setInitialState( rs )
        cam1.setTagStateKey('Clipped1')
        cam1.setTagState('True', RenderState.make(sa)) 
        
        cam2 = world.watercamNP2.node()
        cam2.getLens( ).setFov( base.camLens.getFov( ) )
        cam2.getLens().setNear(1)
        cam2.getLens().setFar(5000)
        cam2.setInitialState( rs )
        cam2.setTagStateKey('Clipped2')
        cam2.setTagState('True', RenderState.make(sa)) 

        
        
        # ---- water textures ---------------------------------------------
        
        # reflection texture, created in realtime by the 'water camera'
        tex0 = buffer.getTexture( )
        tex0.setWrapU(Texture.WMClamp)
        tex0.setWrapV(Texture.WMClamp)
        ts0 = TextureStage( 'reflection' )
        world.waterNP.setTexture( ts0, tex0 ) 
        
        # distortion texture
        tex1 = loader.loadTexture('textures/water.png')
        ts1 = TextureStage('distortion')
        world.waterNP.setTexture(ts1, tex1)
        world.waterNP.reparentTo(render)

At the moment the water shows up on the first screen and the reflections for both the first and second screen show up on the first screen. The second screen has neither water nor reflections show up. We’d appreciate it if anyone could shed some light on this issue.

Welcome to the forums! :slight_smile:

Are the windows opened using the same GSG? Can you show us the code you use to open the windows?

I am not entirely sure but I think this was the code used to open the windows.

  wp = WindowProperties()
        wp.setSize(800, 600)
        wp.setOrigin(870, 50)
        self.win = base.openWindow(props=wp)

And it is from the World classes constructor.

You should try using the same GSG by passing the previous window to base.openWindow, like:

win2 = base.openWindow(props=wp, gsg=win1)

Okay, at the moment trying to implement it and so far have just gotten a third screen duplicating the first screen. How do I specify to only display things to certain windows?

Each window has its own camera; you can find the list of cameras in base.camList. By default, all cameras are parented to the same node (base.camera), so they all see the same thing. If you want the windows to look in different directions, or see different things, you can rotate the individual cameras, or parent one of them to a different node.

If you want the windows to look at the same scene but each view it in different states, that’s possible too, though it’s more complicated.

David