예제 #1
0
 def makeTextureBuffer(name, xSize, ySize, tex = None, toRam = False, fbp = None):
   """Copied from graphicsOutput.cxx and pythonified."""
   if fbp == None:
     fbp = FrameBufferProperties()
     fbp.setRgbColor(1)
     fbp.setDepthBits(1)
   
   flags = GraphicsPipe.BFRefuseWindow;
   if hasattr(GraphicsPipe, "BFSizePower2") and Texture.getTexturesPower2() != ATSNone:
     flags |= GraphicsPipe.BFSizePower2
   if tex != None and tex.getTextureType() == Texture.TTCubeMap:
     flags |= GraphicsPipe.BFSizeSquare
   
   buffer = WindowManager.gsg.getEngine().makeOutput(base.pipe, name, 0,
              fbp, WindowProperties.size(xSize, ySize), flags, WindowManager.gsg)
   if WindowManager.gsg == None:
     WindowManager.gsg = buffer.getGsg()
   
   if buffer != None:
     if toRam:
       buffer.addRenderTexture(tex, RTMCopyRam);
     else:
       buffer.addRenderTexture(tex, RTMBindOrCopy);
     return buffer
   
   return None
예제 #2
0
 def init_wp(window_type, size):
     """ Initial / default WindowProperties """
     if window_type == 'onscreen':
         wp = WindowProperties.getDefault()
         wp.setSize(size[0], size[1])
     elif window_type == 'offscreen':
         wp = WindowProperties.size(size[0], size[1])
     return wp
def createOffscreenBuffer(sort):
    winprops = WindowProperties.size(SIZE, SIZE)
    props = FrameBufferProperties()
    props.setRgbColor(1)
    props.setAlphaBits(1)
    props.setDepthBits(1)
    return base.graphicsEngine.makeOutput(
        base.pipe, "offscreenBuffer", sort, props, winprops, GraphicsPipe.BFRefuseWindow, base.win.getGsg(), base.win
    )
def createOffscreenBuffer(sort):
    winprops = WindowProperties.size(SIZE, SIZE)
    props = FrameBufferProperties()
    props.setRgbColor(1)
    props.setAlphaBits(1)
    props.setDepthBits(1)
    return base.graphicsEngine.makeOutput(base.pipe, "offscreenBuffer", sort,
                                          props, winprops,
                                          GraphicsPipe.BFRefuseWindow,
                                          base.win.getGsg(), base.win)
예제 #5
0
    def __init__(self, _base):
        
        self._base = _base
        
        self._base.cam.node().setActive(0)
        
        # window properties
        self.winprops = WindowProperties.size(base.win.getXSize(),base.win.getYSize())
        self.props = FrameBufferProperties()
        self.props.setDepthBits(1)
        self.props.setColorBits(1) 
        self.props.setAlphaBits(1) 
        
        # buffers creation
        self.geom_buffer = self.make_FBO("geom buffer",3)
        self.light_buffer = self.make_FBO("light buffer",0)
        self.transparency_buffer = self.make_FBO("transparency buffer",0)
        
        # cameras creation
        self.geom_cam = self._base.makeCamera(self.geom_buffer)
        self.light_cam = self._base.makeCamera(self.light_buffer)
        self.transparency_cam = self._base.makeCamera(self.transparency_buffer)
        
        # cameras setup
        self.geom_cam.node().getDisplayRegion(0).setClearColorActive(1) 
        self.geom_cam.node().getDisplayRegion(0).setClearColor(Vec4(1,0,0,1)) 
        self.geom_cam.node().getDisplayRegion(0).setClearDepthActive(1) 
        
        self.light_cam.node().getDisplayRegion(0).setClearColorActive(1) 
        self.geom_cam.node().getDisplayRegion(0).setClearColor(Vec4(0,1,0,1)) 
        self.light_cam.node().getDisplayRegion(0).setClearDepthActive(1) 
        
        self.transparency_cam.node().getDisplayRegion(0).setClearColorActive(1) 
        self.transparency_cam.node().getDisplayRegion(0).setClearDepthActive(1) 
        
        self.geom_cam.node().getLens().setNear(0.1)
        self.light_cam.node().getLens().setNear(0.1)
        self.transparency_cam.node().getLens().setNear(0.1)
        
        self.geom_cam.node().getLens().setFov(90)
        self.light_cam.node().getLens().setFov(90)
        self._base.cam.node().getLens().setFov(90)
        self.transparency_cam.node().getLens().setFov(90)
                
        # cameras masks
        self.geom_mask = BitMask32(1)
        self.light_mask = BitMask32(2)    
        self.transparency_mask = BitMask32(4) 
        
        self.light_cam.node().setCameraMask(self.light_mask)
        self.geom_cam.node().setCameraMask(self.geom_mask)
        self.transparency_cam.node().setCameraMask(self.transparency_mask)
        
        RENDER_NODES['LIGHTS'].hide(self.geom_mask)
        RENDER_NODES['GEOMS'].hide(self.light_mask)
        RENDER_NODES['TRANSPS'].hide(self.geom_mask)
        
        # link cameras
        self.geom_cam.node().setScene(RENDER_NODES['GEOMS'])
        self.light_cam.node().setScene(RENDER_NODES['LIGHTS'])
        self.transparency_cam.node().setScene(RENDER_NODES['TRANSPS'])
        
        # buffers rendering order
        self.light_buffer.setSort(0)
        self.geom_buffer.setSort(-50)
        self.transparency_buffer.setSort(50)
        self._base.win.setSort(-100)   

        # shadows cube creation
        self.shadow_cube = RENDER_NODES['GEOMS'].attachNewNode("cubemap")
        self.shadow_cube.setPos(0, 0, 0)
        buffer_cube_shadow = self._base.win.makeCubeMap("cube 1", 512, self.shadow_cube, camera_mask = self.geom_mask, to_ram = False, fbp = self.props)
        self.shadow_cube_texture = buffer_cube_shadow.getTexture()

        cameras = []
        for camera in self.shadow_cube.getChildren():
            cameras.append(camera)
            camera.node().getLens().setFov(90)
            camera.node().getLens().setNearFar(0.1 ,10.0)
            camera.node().setCameraMask(self.geom_mask)
            cameraInit = NodePath(PandaNode("cube camera initiator"))
            cameraInit.setShader(Shader.load('shaders/point_lights_cube.sha'))
            cameraInit.setShaderInput("light2", self.shadow_cube)
            cameraInit.setShaderInput("lightCamera", camera)
            cameraInit.setShaderInput("lensFar", Vec4(camera.node().getLens().getFar()))
            cameraInit.setShaderInput("transparency", Vec4(1))
            camera.node().setInitialState(cameraInit.getState())
            
        # reflections cube creation                    
        self.reflection_cube = RENDER_NODES['GEOMS'].attachNewNode("cubemap pivot")
        self.buffer_reflection_cube = self._base.win.makeCubeMap("cube 2", 512, self.reflection_cube, camera_mask = self.geom_mask, to_ram = False, fbp = self.props)
        self.reflection_cube_texture = self.buffer_reflection_cube.getTexture()

        for camera in self.reflection_cube.getChildren():
            camera.node().getLens().setNearFar(0.1 ,500.0)

        # shader rendering normal maps
        normal_shader = ShaderAttrib.make()
        normal_shader = normal_shader.setShader(Shader.load(CG_NORMALMAP))

        # shader rendering light
        light_shader = ShaderAttrib.make()
        light_shader = light_shader.setShader(Shader.load(CG_LIGHT))
        
        # link states with cameras
        self.geom_cam.node().setTagStateKey(SHADER_TAGS['g-buffer'])
        self.geom_cam.node().setTagState("True", RenderState.make(normal_shader))
        self.light_cam.node().setTagStateKey(SHADER_TAGS['compute light'])
        self.light_cam.node().setTagState("True", RenderState.make(light_shader))
        
        # render textures creation
        self.albedo_map = Texture()
        self.normal_map = Texture()
        self.depth_map = Texture()  
        self.specular_map = Texture()
        self.misc_map = Texture()
        self.light_map = Texture()
        self.transparency_map = Texture() 
        self.transparency_depth_map = Texture()
             
        # render textures   
        self.transparency_buffer.addRenderTexture(self.transparency_map, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPColor)
        self.transparency_buffer.addRenderTexture(self.transparency_depth_map, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPDepth)
        
        self.geom_buffer.addRenderTexture(self.normal_map, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPColor)
        self.geom_buffer.addRenderTexture(self.depth_map, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPDepth)
        self.geom_buffer.addRenderTexture(self.albedo_map, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPAuxRgba0)      
        self.geom_buffer.addRenderTexture(self.specular_map, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPAuxRgba1)
        self.geom_buffer.addRenderTexture(self.misc_map, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPAuxRgba2)
        
        self.light_buffer.addRenderTexture(self.light_map, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPColor)  
 
        taskMgr.add(self.update,'update reflections cubemap')
예제 #6
0
파일: Main.py 프로젝트: tanuva/fortytons
    def setupShaderLighting(self):
        loadPrcFileData("", "prefer-parasite-buffer #f")

        # Preliminary capabilities check.
        if (base.win.getGsg().getSupportsBasicShaders()==0):
            print "[err] Video driver reports that shaders are not supported."
            return
        if (base.win.getGsg().getSupportsDepthTexture()==0):
            print "[err] Video driver reports that depth textures are not supported."
            return

        # creating the offscreen buffer.
        winprops = WindowProperties.size(2048,2048)
        props = FrameBufferProperties()
        props.setRgbColor(1)
        props.setAlphaBits(1)
        props.setDepthBits(1)
        LBuffer = base.graphicsEngine.makeOutput(
                 base.pipe, "offscreen buffer", -2,
                 props, winprops,
                 GraphicsPipe.BFRefuseWindow,
                 base.win.getGsg(), base.win)

        if (LBuffer == None):
           print "[err] Video driver cannot create an offscreen buffer."
           return

        # Adding a color texture is totally unnecessary, but it helps with debugging.
        Lcolormap = Texture()
        LBuffer.addRenderTexture(Lcolormap, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPColor)

        self.LCam = base.makeCamera(LBuffer)
        self.LCam.reparentTo(render)
        self.LCam.node().setScene(render)
        self.LCam.node().getLens().setFov(30)
        self.LCam.node().getLens().setNearFar(277, 305)
        #self.LCam.node().getLens().setFilmSize(100, 100)
        self.LCam.setPos(0, 0, 300)
        self.LCam.setP(-90)
        self.LCam.lookAt(0, 0, 0)
        #self.createFrustumNode(self.LCam)

        # default values
        self.pushBias=0.50
        self.ambient=0.20
        self.cameraSelection = 0
        self.lightSelection = 0

        # Put a shader on the Main camera.
        # Some video cards have special hardware for shadow maps.
        # If the card has that, use it.  If not, use a different
        # shader that does not require hardware support.

        mci = NodePath(PandaNode("Main Camera Initializer"))
        if (base.win.getGsg().getSupportsShadowFilter()):
            mci.setShader(Shader.load(self.datadir + 'shaders/shadow.sha'))
        else:
            print "[wrn] No shadow shader support found, using shadow-nosupport.sha"
            mci.setShader(Shader.load(self.datadir + 'shaders/shadow-nosupport.sha'))
        base.cam.node().setInitialState(mci.getState())
    
        # setting up shader
        render.setShaderInput('light',self.LCam)
        render.setShaderInput('Ldepthmap',Lcolormap)
        render.setShaderInput('ambient',self.ambient,0,0,1.0)
        render.setShaderInput('texDisable',0,0,0,0)
        render.setShaderInput('scale',1,1,1,1)

        render.setShaderInput('push',0.20,0.20,0.20,0)

        # Put a shader on the Light camera.
        lci = NodePath(PandaNode("Light Camera Initializer"))
        lci.setShader(Shader.load(self.datadir + 'shaders/caster.sha'))
        self.LCam.node().setInitialState(lci.getState())

        self.adjustPushBias(self.pushBias)