def prepareSceneRender(self): self.debug("Preparing scene render for", self._name) # Init buffer object self._createBuffer() # Prepare fullscreen quad self._quad = self._makeFullscreenQuad() # Prepare initial state cs = NodePath("InitialStateDummy") cs.setState(self._sourceCam.node().getInitialState()) if self.hasTarget(RenderTargetType.Aux0): cs.setAttrib(AuxBitplaneAttrib.make(self._auxBits), 20) cs.setAttrib(StencilAttrib.makeOff(), 20) if not self._enableTransparency: cs.setAttrib(TransparencyAttrib.make(TransparencyAttrib.MNone), 20) self._sourceCam.node().setInitialState(cs.getState()) # Set new camera bufferCam = self._makeFullscreenCam() bufferCamNode = self._quad.attachNewNode(bufferCam) self._region.setCamera(bufferCamNode) self._region.setSort(5) # Set clears bufferRegion = self._buffer.getInternalBuffer().getDisplayRegion(0) self._correctClears() bufferRegion.setClearStencilActive(False) # self._sourceWindow.setClearStencilActive(False) # Set aux clears targetCheck = [ (RenderTargetType.Aux0, GraphicsOutput.RTPAuxRgba0), (RenderTargetType.Aux1, GraphicsOutput.RTPAuxRgba1), (RenderTargetType.Aux2, GraphicsOutput.RTPAuxRgba2), (RenderTargetType.Aux3, GraphicsOutput.RTPAuxRgba3), ] for target, targetBindPos in targetCheck: if self.hasTarget(target): bufferRegion.setClearActive(targetBindPos, 1) bufferRegion.setClearValue(targetBindPos, Vec4(0.5, 0.5, 1.0, 0.0)) self._region.disableClears() bufferRegion.setCamera(self._sourceCam) bufferRegion.setActive(1) # bufferRegion.setClearDepthActive(False) bufferRegion.setSort(20) self._setSizeShaderInput()
def renderSceneInto(self, depthtex=None, colortex=None, auxtex=None, auxbits=0, textures=None): if textures: colortex = textures.get('color', None) depthtex = textures.get('depth', None) auxtex = textures.get('aux', None) auxtex0 = textures.get('aux0', auxtex) auxtex1 = textures.get('aux1', None) else: auxtex0 = auxtex auxtex1 = None if colortex == None: colortex = Texture('filter-base-color') colortex.setWrapU(Texture.WMClamp) colortex.setWrapV(Texture.WMClamp) texgroup = (depthtex, colortex, auxtex0, auxtex1) winx, winy = self.getScaledSize(1, 1, 1) buffer = self.createBuffer('filter-base', winx, winy, texgroup) if buffer == None: return cm = CardMaker('filter-base-quad') cm.setFrameFullscreenQuad() quad = NodePath(cm.generate()) quad.setDepthTest(0) quad.setDepthWrite(0) quad.setTexture(colortex) quad.setColor(1, 0.5, 0.5, 1) cs = NodePath('dummy') cs.setState(self.camstate) if auxbits: cs.setAttrib(AuxBitplaneAttrib.make(auxbits)) self.camera.node().setInitialState(cs.getState()) quadcamnode = Camera('filter-quad-cam') lens = OrthographicLens() lens.setFilmSize(2, 2) lens.setFilmOffset(0, 0) lens.setNearFar(-1000, 1000) quadcamnode.setLens(lens) quadcam = quad.attachNewNode(quadcamnode) self.region.setCamera(quadcam) self.setStackedClears(buffer, self.rclears, self.wclears) if auxtex0: buffer.setClearActive(GraphicsOutput.RTPAuxRgba0, 1) buffer.setClearValue(GraphicsOutput.RTPAuxRgba0, (0.5, 0.5, 1.0, 0.0)) if auxtex1: buffer.setClearActive(GraphicsOutput.RTPAuxRgba1, 1) self.region.disableClears() if self.isFullscreen(): self.win.disableClears() dr = buffer.makeDisplayRegion() dr.disableClears() dr.setCamera(self.camera) dr.setActive(1) self.buffers.append(buffer) self.sizes.append((1, 1, 1)) return quad
def prepare_render(self, camera_np): """ Prepares to render a scene """ self.create_default_region = False self._create_buffer() self._source_region = self._internal_buffer.get_display_region(0) if camera_np: initial_state = NodePath("rtis") initial_state.set_state(camera_np.node().get_initial_state()) if self._aux_count: initial_state.set_attrib( AuxBitplaneAttrib.make(self._aux_bits), 20) initial_state.set_attrib( TransparencyAttrib.make(TransparencyAttrib.M_none), 20) if max(self._color_bits) == 0: initial_state.set_attrib( ColorWriteAttrib.make(ColorWriteAttrib.C_off), 20) # Disable existing regions of the camera for region in camera_np.node().get_display_regions(): region.set_active(False) # Remove the existing display region of the camera for region in self._source_window.get_display_regions(): if region.get_camera() == camera_np: self._source_window.remove_display_region(region) camera_np.node().set_initial_state(initial_state.get_state()) self._source_region.set_camera(camera_np) self._internal_buffer.disable_clears() self._source_region.disable_clears() self._source_region.set_active(True) self._source_region.set_sort(20) # Reenable depth-clear, usually desireable self._source_region.set_clear_depth_active(True) self._source_region.set_clear_depth(1.0) self._active = True
def prepare_render(self, camera_np): """ Prepares to render a scene """ self.create_default_region = False self._create_buffer() self._source_region = self._internal_buffer.get_display_region(0) if camera_np: initial_state = NodePath("rtis") initial_state.set_state(camera_np.node().get_initial_state()) if self._aux_count: initial_state.set_attrib(AuxBitplaneAttrib.make(self._aux_bits), 20) initial_state.set_attrib(TransparencyAttrib.make(TransparencyAttrib.M_none), 20) if max(self._color_bits) == 0: initial_state.set_attrib(ColorWriteAttrib.make(ColorWriteAttrib.C_off), 20) # Disable existing regions of the camera for region in camera_np.node().get_display_regions(): region.set_active(False) # Remove the existing display region of the camera for region in self._source_window.get_display_regions(): if region.get_camera() == camera_np: self._source_window.remove_display_region(region) camera_np.node().set_initial_state(initial_state.get_state()) self._source_region.set_camera(camera_np) self._internal_buffer.disable_clears() self._source_region.disable_clears() self._source_region.set_active(True) self._source_region.set_sort(20) # Reenable depth-clear, usually desireable self._source_region.set_clear_depth_active(True) self._source_region.set_clear_depth(1.0) self._active = True
def renderSceneInto(self, depthtex=None, colortex=None, auxtex=None, auxbits=0, textures=None, fbprops=None): """ Causes the scene to be rendered into the supplied textures instead of into the original window. Puts a fullscreen quad into the original window to show the render-to-texture results. Returns the quad. Normally, the caller would then apply a shader to the quad. To elaborate on how this all works: * An offscreen buffer is created. It is set up to mimic the original display region - it is the same size, uses the same clear colors, and contains a DisplayRegion that uses the original camera. * A fullscreen quad and an orthographic camera to render that quad are both created. The original camera is removed from the original window, and in its place, the orthographic quad-camera is installed. * The fullscreen quad is textured with the data from the offscreen buffer. A shader is applied that tints the results pink. * Automatic shader generation NOT enabled. If you have a filter that depends on a render target from the auto-shader, you either need to set an auto-shader attrib on the main camera or scene, or, you need to provide these outputs in your own shader. * All clears are disabled on the original display region. If the display region fills the whole window, then clears are disabled on the original window as well. It is assumed that rendering the full-screen quad eliminates the need to do clears. Hence, the original window which used to contain the actual scene, now contains a pink-tinted quad with a texture of the scene. It is assumed that the user will replace the shader on the quad with a more interesting filter. """ if (textures): colortex = textures.get("color", None) depthtex = textures.get("depth", None) auxtex = textures.get("aux", None) auxtex0 = textures.get("aux0", auxtex) auxtex1 = textures.get("aux1", None) else: auxtex0 = auxtex auxtex1 = None if (colortex == None): colortex = Texture("filter-base-color") colortex.setWrapU(Texture.WMClamp) colortex.setWrapV(Texture.WMClamp) texgroup = (depthtex, colortex, auxtex0, auxtex1) # Choose the size of the offscreen buffer. (winx, winy) = self.getScaledSize(1, 1, 1) if fbprops is not None: buffer = self.createBuffer("filter-base", winx, winy, texgroup, fbprops=fbprops) else: buffer = self.createBuffer("filter-base", winx, winy, texgroup) if (buffer == None): return None cm = CardMaker("filter-base-quad") cm.setFrameFullscreenQuad() quad = NodePath(cm.generate()) quad.setDepthTest(0) quad.setDepthWrite(0) quad.setTexture(colortex) quad.setColor(1, 0.5, 0.5, 1) cs = NodePath("dummy") cs.setState(self.camstate) # Do we really need to turn on the Shader Generator? #cs.setShaderAuto() if (auxbits): cs.setAttrib(AuxBitplaneAttrib.make(auxbits)) self.camera.node().setInitialState(cs.getState()) quadcamnode = Camera("filter-quad-cam") lens = OrthographicLens() lens.setFilmSize(2, 2) lens.setFilmOffset(0, 0) lens.setNearFar(-1000, 1000) quadcamnode.setLens(lens) quadcam = quad.attachNewNode(quadcamnode) self.region.setCamera(quadcam) self.setStackedClears(buffer, self.rclears, self.wclears) if (auxtex0): buffer.setClearActive(GraphicsOutput.RTPAuxRgba0, 1) buffer.setClearValue(GraphicsOutput.RTPAuxRgba0, (0.5, 0.5, 1.0, 0.0)) if (auxtex1): buffer.setClearActive(GraphicsOutput.RTPAuxRgba1, 1) self.region.disableClears() if (self.isFullscreen()): self.win.disableClears() dr = buffer.makeDisplayRegion() dr.disableClears() dr.setCamera(self.camera) dr.setActive(1) self.buffers.append(buffer) self.sizes.append((1, 1, 1)) return quad
def prepareSceneRender(self, earlyZ=False, earlyZCam=None): """ Renders the scene of the source camera to the buffer. See the documentation of this class for further information """ self.debug("Preparing scene render") # Init buffer object self._createBuffer() # Prepare initial state cs = NodePath("InitialStateDummy") cs.setState(self._sourceCam.node().getInitialState()) if self.hasTarget(RenderTargetType.Aux0): cs.setAttrib(AuxBitplaneAttrib.make(self._auxBits), 20) cs.setAttrib(StencilAttrib.makeOff(), 20) if not self._enableTransparency: cs.setAttrib(TransparencyAttrib.make(TransparencyAttrib.MNone), 100) if not self._writeColor: cs.setAttrib(ColorWriteAttrib.make(ColorWriteAttrib.COff), 100) self._sourceCam.node().setInitialState(cs.getState()) if earlyZ: self._earlyZRegion = self._internalBuffer.makeDisplayRegion() self._earlyZRegion.setSort(-10) self._earlyZRegion.setCamera(earlyZCam) self._node = NodePath("RTRoot") # Prepare fullscreen quad if self._createOverlayQuad: self._quad = self._makeFullscreenQuad() self._quad.reparentTo(self._node) bufferCam = self._makeFullscreenCam() self._camera = self._node.attachNewNode(bufferCam) self._region.setCamera(self._camera) self._region.setSort(5) # Set clears bufferRegion = self._internalBuffer.getDisplayRegion(0) self._correctClears() bufferRegion.setClearStencilActive(False) # self._sourceWindow.setClearStencilActive(False) # Set aux clears targetCheck = [ (RenderTargetType.Aux0, GraphicsOutput.RTPAuxRgba0), (RenderTargetType.Aux1, GraphicsOutput.RTPAuxRgba1), (RenderTargetType.Aux2, GraphicsOutput.RTPAuxRgba2), (RenderTargetType.Aux3, GraphicsOutput.RTPAuxRgba3), ] for target, targetBindPos in targetCheck: if self.hasTarget(target): bufferRegion.setClearActive(targetBindPos, 1) bufferRegion.setClearValue(targetBindPos, Vec4(0.5, 0.5, 1.0, 0.0)) self._region.disableClears() bufferRegion.setCamera(self._sourceCam) bufferRegion.setActive(1) bufferRegion.setClearDepthActive(False) bufferRegion.setSort(20) if earlyZ: self._earlyZRegion.disableClears() self._earlyZRegion.setClearDepthActive(True) self._earlyZRegion.setActive(1) self._setSizeShaderInput() self._active = True self._registerBuffer()
def prepareSceneRender(self): """ Renders the scene of the source camera to the buffer. See the documentation of this class for further information """ self.debug("Preparing scene render") # Init buffer object self._createBuffer() # Prepare fullscreen quad self._quad = self._makeFullscreenQuad() # Prepare initial state cs = NodePath("InitialStateDummy") cs.setState(self._sourceCam.node().getInitialState()) if self.hasTarget(RenderTargetType.Aux0): cs.setAttrib(AuxBitplaneAttrib.make(self._auxBits), 20) cs.setAttrib(StencilAttrib.makeOff(), 20) if not self._enableTransparency: cs.setAttrib(TransparencyAttrib.make(TransparencyAttrib.MNone), 100) if not self._writeColor: cs.setAttrib(ColorWriteAttrib.make(ColorWriteAttrib.COff), 100) self._sourceCam.node().setInitialState(cs.getState()) # Set new camera bufferCam = self._makeFullscreenCam() bufferCamNode = self._quad.attachNewNode(bufferCam) self._region.setCamera(bufferCamNode) self._region.setSort(5) # Set clears bufferRegion = self._buffer.getInternalBuffer().getDisplayRegion(0) self._correctClears() bufferRegion.setClearStencilActive(False) # self._sourceWindow.setClearStencilActive(False) # Set aux clears targetCheck = [ (RenderTargetType.Aux0, GraphicsOutput.RTPAuxRgba0), (RenderTargetType.Aux1, GraphicsOutput.RTPAuxRgba1), (RenderTargetType.Aux2, GraphicsOutput.RTPAuxRgba2), (RenderTargetType.Aux3, GraphicsOutput.RTPAuxRgba3), ] for target, targetBindPos in targetCheck: if self.hasTarget(target): bufferRegion.setClearActive(targetBindPos, 1) bufferRegion.setClearValue( targetBindPos, Vec4(0.5, 0.5, 1.0, 0.0)) self._region.disableClears() bufferRegion.setCamera(self._sourceCam) bufferRegion.setActive(1) # bufferRegion.setClearDepthActive(False) bufferRegion.setSort(20) self._setSizeShaderInput()
def renderSceneInto(self, depthtex=None, colortex=None, auxtex=None, auxbits=0, textures=None, fbprops=None, clamping=None): """ overload direct.filters.FilterManager.renderSceneInto :param depthtex: :param colortex: :param auxtex: :param auxbits: :param textures: :param fbprops: :param clamping: :return: """ if (textures): colortex = textures.get("color", None) depthtex = textures.get("depth", None) auxtex = textures.get("aux", None) auxtex0 = textures.get("aux0", auxtex) auxtex1 = textures.get("aux1", None) else: auxtex0 = auxtex auxtex1 = None if (colortex == None): colortex = Texture("filter-base-color") colortex.setWrapU(Texture.WMClamp) colortex.setWrapV(Texture.WMClamp) texgroup = (depthtex, colortex, auxtex0, auxtex1) # Choose the size of the offscreen buffer. (winx, winy) = self.getScaledSize(1, 1, 1) if fbprops is not None: buffer = self.createBuffer("filter-base", winx, winy, texgroup, fbprops=fbprops) else: buffer = self.createBuffer("filter-base", winx, winy, texgroup) if (buffer == None): return None cm = CardMaker("filter-base-quad") cm.setFrameFullscreenQuad() quad = NodePath(cm.generate()) quad.setDepthTest(0) quad.setDepthWrite(0) quad.setTexture(colortex) quad.setColor(1, 0.5, 0.5, 1) cs = NodePath("dummy") cs.setState(self.camstate) # Do we really need to turn on the Shader Generator? # cs.setShaderAuto() if (auxbits): cs.setAttrib(AuxBitplaneAttrib.make(auxbits)) if clamping is False: # Disables clamping in the shader generator. cs.setAttrib(LightRampAttrib.make_identity()) self.camera.node().setInitialState(cs.getState()) quadcamnode = Camera("filter-quad-cam") lens = OrthographicLens() lens.setFilmSize(2, 2) lens.setFilmOffset(0, 0) lens.setNearFar(-1000, 1000) quadcamnode.setLens(lens) quadcam = quad.attachNewNode(quadcamnode) self.region.setCamera(quadcam) self.setStackedClears(buffer, self.rclears, self.wclears) if (auxtex0): buffer.setClearActive(GraphicsOutput.RTPAuxRgba0, 1) buffer.setClearValue(GraphicsOutput.RTPAuxRgba0, (0.5, 0.5, 1.0, 0.0)) if (auxtex1): buffer.setClearActive(GraphicsOutput.RTPAuxRgba1, 1) self.region.disableClears() if (self.isFullscreen()): self.win.disableClears() dr = buffer.makeDisplayRegion() dr.disableClears() dr.setCamera(self.camera) dr.setActive(1) self.buffers.append(buffer) self.sizes.append((1, 1, 1)) return quad
def renderSceneInto(self, depthtex=None, colortex=None, auxtex=None, auxbits=0, textures=None): """ Causes the scene to be rendered into the supplied textures instead of into the original window. Puts a fullscreen quad into the original window to show the render-to-texture results. Returns the quad. Normally, the caller would then apply a shader to the quad. To elaborate on how this all works: * An offscreen buffer is created. It is set up to mimic the original display region - it is the same size, uses the same clear colors, and contains a DisplayRegion that uses the original camera. * A fullscreen quad and an orthographic camera to render that quad are both created. The original camera is removed from the original window, and in its place, the orthographic quad-camera is installed. * The fullscreen quad is textured with the data from the offscreen buffer. A shader is applied that tints the results pink. * Automatic shader generation NOT enabled. If you have a filter that depends on a render target from the auto-shader, you either need to set an auto-shader attrib on the main camera or scene, or, you need to provide these outputs in your own shader. * All clears are disabled on the original display region. If the display region fills the whole window, then clears are disabled on the original window as well. It is assumed that rendering the full-screen quad eliminates the need to do clears. Hence, the original window which used to contain the actual scene, now contains a pink-tinted quad with a texture of the scene. It is assumed that the user will replace the shader on the quad with a more interesting filter. """ if (textures): colortex = textures.get("color", None) depthtex = textures.get("depth", None) auxtex = textures.get("aux", None) auxtex0 = textures.get("aux0", auxtex) auxtex1 = textures.get("aux1", None) else: auxtex0 = auxtex auxtex1 = None if (colortex == None): colortex = Texture("filter-base-color") colortex.setWrapU(Texture.WMClamp) colortex.setWrapV(Texture.WMClamp) texgroup = (depthtex, colortex, auxtex0, auxtex1) # Choose the size of the offscreen buffer. (winx, winy) = self.getScaledSize(1,1,1) buffer = self.createBuffer("filter-base", winx, winy, texgroup) if (buffer == None): return None cm = CardMaker("filter-base-quad") cm.setFrameFullscreenQuad() quad = NodePath(cm.generate()) quad.setDepthTest(0) quad.setDepthWrite(0) quad.setTexture(colortex) quad.setColor(1, 0.5, 0.5, 1) cs = NodePath("dummy") cs.setState(self.camstate) # Do we really need to turn on the Shader Generator? #cs.setShaderAuto() if (auxbits): cs.setAttrib(AuxBitplaneAttrib.make(auxbits)) self.camera.node().setInitialState(cs.getState()) quadcamnode = Camera("filter-quad-cam") lens = OrthographicLens() lens.setFilmSize(2, 2) lens.setFilmOffset(0, 0) lens.setNearFar(-1000, 1000) quadcamnode.setLens(lens) quadcam = quad.attachNewNode(quadcamnode) self.region.setCamera(quadcam) self.setStackedClears(buffer, self.rclears, self.wclears) if (auxtex0): buffer.setClearActive(GraphicsOutput.RTPAuxRgba0, 1) buffer.setClearValue(GraphicsOutput.RTPAuxRgba0, (0.5, 0.5, 1.0, 0.0)) if (auxtex1): buffer.setClearActive(GraphicsOutput.RTPAuxRgba1, 1) self.region.disableClears() if (self.isFullscreen()): self.win.disableClears() dr = buffer.makeDisplayRegion() dr.disableClears() dr.setCamera(self.camera) dr.setActive(1) self.buffers.append(buffer) self.sizes.append((1, 1, 1)) return quad