Esempio n. 1
0
    def __init__(self, name, reso, height, planeVec, reflection = False, needDepth = False):
        fbp = FrameBufferProperties()
        fbp.clear()
        fbp.set_depth_bits( 8 )
        fbp.set_force_hardware( True )
        fbp.set_rgba_bits( 8, 8, 8, 8 )
        fbp.set_stencil_bits( 0 )
        fbp.set_float_color( False )
        fbp.set_float_depth( False )
        fbp.set_stereo( False )
        fbp.set_accum_bits( 0 )
        fbp.set_aux_float( 0 )
        fbp.set_aux_rgba( 0 )
        fbp.set_aux_hrgba( 0 )
        fbp.set_coverage_samples( 0 )
        fbp.set_multisamples( 0 )
        
        buffer = base.win.makeTextureBuffer(name, reso, reso, None, False, fbp)
        buffer.setSort(-10000)
        buffer.disableClears()
        buffer.setClearDepthActive(True)

        self.buffer = buffer
        
        self.camera = base.makeCamera(buffer)
        self.camera.node().setLens(base.camLens)
        self.camera.node().setCameraMask(CIGlobals.ReflectionCameraBitmask)

        self.texture = buffer.getTexture()
        self.texture.setWrapU(Texture.WMClamp)
        self.texture.setWrapV(Texture.WMClamp)
        self.texture.setMinfilter(Texture.FTLinearMipmapLinear)

        if needDepth:
            depthTex = Texture(name + "_depth")
            depthTex.setWrapU(Texture.WMClamp)
            depthTex.setWrapV(Texture.WMClamp)
            depthTex.setMinfilter(Texture.FTLinearMipmapLinear)

            buffer.addRenderTexture(depthTex, GraphicsOutput.RTMBindOrCopy,
                                    GraphicsOutput.RTPDepth)

            self.depthTex = depthTex

        self.plane = Plane(planeVec, Point3(0, 0, height))
        self.planeNode = PlaneNode(name + "_plane", self.plane)
        self.planeNP = render.attachNewNode(self.planeNode)
        tmpnp = NodePath("StateInitializer")
        tmpnp.setClipPlane(self.planeNP)
        if reflection:
            tmpnp.setAttrib(CullFaceAttrib.makeReverse())
        else:
            tmpnp.setAttrib(CullFaceAttrib.makeDefault())
        # As an optimization, disable any kind of shaders (mainly the ShaderGenerator) on the
        # reflected/refracted scene.
        #tmpnp.setShaderOff(10)
        tmpnp.setLightOff(10)
        tmpnp.setAntialias(0, 10)
        self.camera.node().setInitialState(tmpnp.getState())

        self.disable()