Beispiel #1
0
 def __init__(self):
     DirectObject.__init__(self)
     self.base = ShowBase()
     resolution = (1024, 768)
     wp = WindowProperties()
     wp.setSize(int(resolution[0]), int(resolution[1]))
     wp.setOrigin(0, 0)
     self.base.win.requestProperties(wp)
     # depth completely doesn't matter for this, since just 2d, and no layers
     self.depth = 0
     self.base.setBackgroundColor(115 / 255, 115 / 255, 115 / 255)
     # set up a 2d camera
     camera = self.base.camList[0]
     lens = OrthographicLens()
     lens.setFilmSize(int(resolution[0]), int(resolution[1]))
     lens.setNearFar(-100, 100)
     camera.node().setLens(lens)
     camera.reparentTo(self.base.render)
     self.accept("escape", sys.exit)
     # spread out some positions
     self.positions = [(-200, 0, -200),
                       (0, 0, -200),
                       (200, 0, -200),
                       (-200, 0, 0),
                       (0, 0, 0),
                       (200, 0, 0),
                       (-200, 0, 200),
                       (0, 0, 200),
                       (200, 0, 200)]
     self.all_smiles()
Beispiel #2
0
    def create(self):
        self.camera = Camera("PSSMDistShadowsESM")
        self.cam_lens = OrthographicLens()
        self.cam_lens.set_film_size(12000, 12000)
        self.cam_lens.set_near_far(10.0, self.sun_distance * 2)
        self.camera.set_lens(self.cam_lens)
        self.cam_node = Globals.base.render.attach_new_node(self.camera)

        self.target = self.create_target("ShadowMap")
        self.target.size = self.resolution
        self.target.add_depth_attachment(bits=32)
        self.target.prepare_render(self.cam_node)

        self.target_convert = self.create_target("ConvertToESM")
        self.target_convert.size = self.resolution
        self.target_convert.add_color_attachment(bits=(32, 0, 0, 0))
        self.target_convert.prepare_buffer()
        self.target_convert.set_shader_input("SourceTex", self.target.depth_tex)

        self.target_blur_v = self.create_target("BlurVert")
        self.target_blur_v.size = self.resolution
        self.target_blur_v.add_color_attachment(bits=(32, 0, 0, 0))
        self.target_blur_v.prepare_buffer()
        self.target_blur_v.set_shader_input("SourceTex", self.target_convert.color_tex)
        self.target_blur_v.set_shader_input("direction", LVecBase2i(1, 0))

        self.target_blur_h = self.create_target("BlurHoriz")
        self.target_blur_h.size = self.resolution
        self.target_blur_h.add_color_attachment(bits=(32, 0, 0, 0))
        self.target_blur_h.prepare_buffer()
        self.target_blur_h.set_shader_input("SourceTex", self.target_blur_v.color_tex)
        self.target_blur_h.set_shader_input("direction", LVecBase2i(0, 1))

        # Register shadow camera
        self._pipeline.tag_mgr.register_camera("shadow", self.camera)
class SkyAOCaptureStage(RenderStage):

    """ This stage captures the sky ao by rendering the scene from above """

    required_inputs = []
    required_pipes = []

    @property
    def produced_pipes(self):
        return {"SkyAOHeight": self.target_convert.color_tex}

    @property
    def produced_inputs(self):
        return {"SkyAOCapturePosition": self.pta_position}

    def __init__(self, pipeline):
        RenderStage.__init__(self, pipeline)
        self.pta_position = PTALVecBase3f.empty_array(1)
        self.resolution = 512
        self.capture_height = 100.0
        self.max_radius = 100.0

    def create(self):
        self.camera = Camera("SkyAOCaptureCam")
        self.cam_lens = OrthographicLens()
        self.cam_lens.set_film_size(self.max_radius, self.max_radius)
        self.cam_lens.set_near_far(0, self.capture_height)
        self.camera.set_lens(self.cam_lens)
        self.cam_node = Globals.base.render.attach_new_node(self.camera)
        self.cam_node.look_at(0, 0, -1)
        self.cam_node.set_r(0)

        self.target = self.create_target("SkyAOCapture")
        self.target.size = self.resolution
        self.target.add_depth_attachment(bits=16)
        self.target.prepare_render(self.cam_node)

        self.target_convert = self.create_target("ConvertDepth")
        self.target_convert.size = self.resolution
        self.target_convert.add_color_attachment(bits=(16, 0, 0, 0))
        self.target_convert.prepare_buffer()

        self.target_convert.set_shader_inputs(
            DepthTex=self.target.depth_tex,
            position=self.pta_position)

        # Register camera
        self._pipeline.tag_mgr.register_camera("shadow", self.camera)

    def update(self):
        snap_size = self.max_radius / self.resolution
        cam_pos = Globals.base.camera.get_pos(Globals.base.render)
        self.cam_node.set_pos(
            cam_pos.x - cam_pos.x % snap_size,
            cam_pos.y - cam_pos.y % snap_size,
            self.capture_height / 2.0)
        self.pta_position[0] = self.cam_node.get_pos()

    def reload_shaders(self):
        self.target_convert.shader = self.load_plugin_shader("convert_depth.frag.glsl")
Beispiel #4
0
    def create(self):
        # Create voxelize camera
        self.voxelizeCamera = Camera("VoxelizeCamera")
        self.voxelizeCamera.setCameraMask(BitMask32.bit(4))
        self.voxelizeCameraNode = Globals.render.attachNewNode(
            self.voxelizeCamera)
        self.voxelizeLens = OrthographicLens()
        self.voxelizeLens.setFilmSize(self.voxelGridSize * 2,
                                      self.voxelGridSize * 2)
        self.voxelizeLens.setNearFar(0.0, self.voxelGridSize * 2)
        self.voxelizeCamera.setLens(self.voxelizeLens)
        self.voxelizeCamera.setTagStateKey("VoxelizePassShader")
        Globals.render.setTag("VoxelizePassShader", "Default")

        # Create voxelize tareet
        self.target = RenderTarget("VoxelizePass")
        self.target.setSize(self.voxelGridResolution *
                            self.gridResolutionMultiplier)

        if self.pipeline.settings.useDebugAttachments:
            self.target.addColorTexture()
        else:
            self.target.setColorWrite(False)

        self.target.setCreateOverlayQuad(False)
        self.target.setSource(self.voxelizeCameraNode, Globals.base.win)
        self.target.prepareSceneRender()
        self.target.setActive(False)
Beispiel #5
0
    def set_up(self):
        self.display_region = base.camNode.get_display_region(0)
        win = self.display_region.get_window()

        self.perspective_lens = PerspectiveLens()
        self.perspective_lens = base.camLens  # use panda3d's default for automatic aspect ratio on window resize
        self.lens = self.perspective_lens
        self.perspective_lens.set_aspect_ratio(window.aspect_ratio)
        self.perspective_lens_node = LensNode('perspective_lens_node',
                                              self.perspective_lens)
        self.lens_node = self.perspective_lens_node

        self.orthographic_lens = OrthographicLens()
        self.orthographic_lens.set_film_size(self.fov * window.aspect_ratio,
                                             self.fov)
        self.orthographic_lens_node = LensNode('orthographic_lens_node',
                                               self.orthographic_lens)

        application.base.cam.node().set_lens(self.lens)

        self.orthographic = False
        self.fov = 40  # horizontal fov
        # self.fov = 22.5
        self.clip_plane_near = 0.1
        self.clip_plane_far = 10000

        self.ui_display_region = win.make_display_region()
        self.ui_display_region.set_sort(20)

        self.ui_camera = NodePath(PandaCamera('ui_camera'))
        self.ui_lens = OrthographicLens()
        # moved set_film_size() to window module for correct aspect ratio after setting window size
        self.ui_lens.set_near_far(-1000, 1000)
        self.ui_camera.node().set_lens(self.ui_lens)
        self._ui_lens_node = LensNode('_ui_lens_node', self.ui_lens)

        self.ui_render = NodePath('ui_render')
        self.ui_render.set_depth_test(0)
        self.ui_render.set_depth_write(0)
        self.ui_camera.reparent_to(self.ui_render)
        self.ui_display_region.set_camera(self.ui_camera)
        scene.ui_camera = self.ui_camera

        self.ui = Entity(eternal=True,
                         name='ui',
                         parent=self.ui_camera,
                         scale=(self.ui_size * .5, self.ui_size * .5))
        self.overlay = Entity(parent=self.ui,
                              model='quad',
                              scale=99,
                              color=color.clear,
                              eternal=True,
                              z=-99)

        # these get created when setting a shader
        self.filter_manager = None
        self.filter_quad = None
        self.render_texture = None
        self.filter_quad = None
        self.depth_texture = None
Beispiel #6
0
def makeBufferRelCent(np, size=256):
    #we get a handle to the default window
    mainWindow = base.win

    #we now get buffer thats going to hold the texture of our new scene
    altBuffer = mainWindow.makeTextureBuffer("hello", size, size)
    altBuffer.setClearColor(Vec4(0.5, 0.5, 0.5, 0))
    #now we have to setup a new scene graph to make this scene
    altRender = NodePath("new render")

    #this takes care of setting up ther camera properly
    altCam = base.makeCamera(altBuffer)
    altCam.reparentTo(altRender)

    #get the teapot and rotates it for a simple animation
    teapot = NodePath("dummy")
    np.instanceTo(teapot)
    pos, rel, cent = makePosRelCent(teapot)
    lens = OrthographicLens()
    lens.setFilmSize(*rel)
    altCam.setPos(pos)
    altCam.node().setLens(lens)

    teapot.reparentTo(altRender)
    altBuffer.setOneShot(True)
    return altBuffer, rel, cent
Beispiel #7
0
    def create(self):
        self.camera = Camera("SkyAOCaptureCam")
        self.cam_lens = OrthographicLens()
        self.cam_lens.set_film_size(200, 200)
        self.cam_lens.set_near_far(0.0, 500.0)
        self.camera.set_lens(self.cam_lens)
        self.cam_node = Globals.base.render.attach_new_node(self.camera)
        self.cam_node.look_at(0, 0, -1)
        self.cam_node.set_r(0)

        self.target = self.create_target("SkyAOCapture")
        self.target.size = 1024
        self.target.add_depth_attachment(bits=16)
        self.target.prepare_render(self.cam_node)

        self.target_convert = self.create_target("ConvertDepth")
        self.target_convert.size = 1024
        self.target_convert.add_color_attachment(bits=(16, 0, 0, 0))
        self.target_convert.prepare_buffer()

        self.target_convert.set_shader_input("DepthTex", self.target.depth_tex)
        self.target_convert.set_shader_input("position", self.pta_position)

        # Register camera
        self._pipeline.tag_mgr.register_camera("shadow", self.camera)
Beispiel #8
0
 def setupCamera(self, _pos, _rot, _filmsize):
     # Setup lens, position and rotation
     lens = OrthographicLens()
     lens.setFilmSize(_filmsize[0], _filmsize[1])
     #base.cam.node().setLens(lens)
     base.cam.setPos(_pos)
     base.cam.setHpr(_rot)
Beispiel #9
0
    def __init__(self):
        super().__init__()

        x = float(base.win.get_x_size())
        y = float(base.win.get_y_size())
        y_aspect = y / x
        inventory_base_width = INVENTORY_VERTICAL_FRACTION * y_aspect
        inventory_half_width = inventory_base_width * INVENTORY_HORIZONTAL_FACTOR * 0.5
        
        self.region = base.win.make_display_region(
            0.5 - inventory_half_width,  # left
            0.5 + inventory_half_width,  # right
            0.0,  # bottom
            INVENTORY_VERTICAL_FRACTION,  # top
        )
        self.region.set_sort(INVENTORY_DISPLAY_REGION_SORT)

        self.cam_node = p3d.Camera('inventory_cam')
        lens = OrthographicLens()
        lens.set_film_size(INVENTORY_HORIZONTAL_FACTOR, 1)
        self.cam_node.set_lens(lens)
        self.cam_np = NodePath(self.cam_node)
        self.region.set_camera(self.cam_np)

        self.inventory = NodePath('inventory')
        self.cam_np.reparentTo(self.inventory)

        background_maker = CardMaker('inventory')
        background_maker.set_frame(-INVENTORY_HORIZONTAL_FACTOR / 2.0, INVENTORY_HORIZONTAL_FACTOR / 2.0, 0, 1)
        background = p3d.NodePath(background_maker.generate())
        background.reparent_to(self.inventory)
        background.set_pos(0, 5, -0.5)
Beispiel #10
0
 def enable(self):
     camNode = Camera('shadowCam')
     camNode.setCameraMask(CIGlobals.ShadowCameraBitmask)
     self.shadowLens = OrthographicLens()
     self.shadowLens.setFilmSize(60 * 4, 60 * 4)
     camNode.setLens(self.shadowLens)
     self.shadowCamArm = camera.attachNewNode('shadowCamArm')
     self.shadowCam = self.shadowCamArm.attachNewNode(camNode)
     self.shadowCamArm.setPos(0, 40, 0)
     self.shadowCam.setPos(0, -40, 0)
     self.shadowTex = Texture('shadow')
     self.shadowTex.setBorderColor(self.clearColor)
     self.shadowTex.setWrapU(Texture.WMBorderColor)
     self.shadowTex.setWrapV(Texture.WMBorderColor)
     self.casterState = NodePath('temp')
     self.casterState.setColorScaleOff(10)
     self.casterState.setColor(self.shadowColor, self.shadowColor,
                               self.shadowColor, 1, 10)
     self.casterState.setTextureOff(10)
     self.casterState.setLightOff(10)
     self.casterState.setFogOff(10)
     camNode.setInitialState(self.casterState.getState())
     render.hide(CIGlobals.ShadowCameraBitmask)
     self.shadowStage = TextureStage('shadow')
     self.shadowStage.setSort(1000)
     self.turnOnShadows()
Beispiel #11
0
class SkyAOCaptureStage(RenderStage):
    """ This stage captures the sky ao by rendering the scene from above """

    required_inputs = []
    required_pipes = []

    @property
    def produced_pipes(self):
        return {"SkyAOHeight": self.target_convert.color_tex}

    @property
    def produced_inputs(self):
        return {"SkyAOCapturePosition": self.pta_position}

    def __init__(self, pipeline):
        RenderStage.__init__(self, pipeline)
        self.pta_position = PTALVecBase3f.empty_array(1)
        self.resolution = 512
        self.capture_height = 100.0
        self.max_radius = 100.0

    def create(self):
        self.camera = Camera("SkyAOCaptureCam")
        self.cam_lens = OrthographicLens()
        self.cam_lens.set_film_size(self.max_radius, self.max_radius)
        self.cam_lens.set_near_far(0, self.capture_height)
        self.camera.set_lens(self.cam_lens)
        self.cam_node = Globals.base.render.attach_new_node(self.camera)
        self.cam_node.look_at(0, 0, -1)
        self.cam_node.set_r(0)

        self.target = self.create_target("SkyAOCapture")
        self.target.size = self.resolution
        self.target.add_depth_attachment(bits=16)
        self.target.prepare_render(self.cam_node)

        self.target_convert = self.create_target("ConvertDepth")
        self.target_convert.size = self.resolution
        self.target_convert.add_color_attachment(bits=(16, 0, 0, 0))
        self.target_convert.prepare_buffer()

        self.target_convert.set_shader_inputs(DepthTex=self.target.depth_tex,
                                              position=self.pta_position)

        # Register camera
        self._pipeline.tag_mgr.register_camera("shadow", self.camera)

    def update(self):
        snap_size = self.max_radius / self.resolution
        cam_pos = Globals.base.camera.get_pos(Globals.base.render)
        self.cam_node.set_pos(cam_pos.x - cam_pos.x % snap_size,
                              cam_pos.y - cam_pos.y % snap_size,
                              self.capture_height / 2.0)
        self.pta_position[0] = self.cam_node.get_pos()

    def reload_shaders(self):
        self.target_convert.shader = self.load_plugin_shader(
            "convert_depth.frag.glsl")
Beispiel #12
0
def orthographic():
    global PERSPECTIVE
    PERSPECTIVE = False
    sandbox.base.disableMouse()
    sandbox.base.camera.setPos(0, 0, 3000)
    sandbox.base.camera.setHpr(0, -90, 0)
    lens = OrthographicLens()
    lens.setFilmSize(10)
    sandbox.base.cam.node().setLens(lens)
Beispiel #13
0
    def set_up(self, use_filters=True):
        self.display_region = base.camNode.get_display_region(0)

        win = self.display_region.get_window()

        self.perspective_lens = PerspectiveLens()
        self.lens = self.perspective_lens
        self.perspective_lens.set_aspect_ratio(window.aspect_ratio)
        self.perspective_lens.set_focal_length(50)
        self.perspective_lens_node = LensNode('perspective_lens_node',
                                              self.perspective_lens)
        self.lens_node = self.perspective_lens_node

        self.orthographic_lens = OrthographicLens()
        self.orthographic_lens.set_film_size(self.fov * window.aspect_ratio,
                                             self.fov)
        self.orthographic_lens_node = LensNode('orthographic_lens_node',
                                               self.orthographic_lens)

        application.base.cam.node().set_lens(self.lens)

        self.orthographic = False
        self.fov = 40
        self.clip_plane_near = 0.0001
        self.clip_plane_far = 70000000

        self.ui_display_region = win.make_display_region()
        self.ui_display_region.set_sort(20)

        self.ui_camera = NodePath(PandaCamera('ui_camera'))
        self.ui_lens = OrthographicLens()
        self.ui_lens.set_film_size(self.ui_size * .5 * self.aspect_ratio,
                                   self.ui_size * .5)
        self.ui_lens.set_near_far(-1000, 70000)
        self.ui_camera.node().set_lens(self.ui_lens)
        self._ui_lens_node = LensNode('_ui_lens_node', self.ui_lens)

        self.ui_render = NodePath('ui_render')
        self.ui_render.set_depth_test(0)
        self.ui_render.set_depth_write(0)
        self.ui_camera.reparent_to(self.ui_render)
        self.ui_display_region.set_camera(self.ui_camera)
        scene.ui_camera = self.ui_camera
        # ui_camera.hide()

        # self.black_bars_display_region = win.make_display_region()
        # self.black_bars_display_region.set_sort(-100)

        self.ui = Entity(eternal=True,
                         name='ui',
                         parent=self.ui_camera,
                         scale=(self.ui_size * .5, self.ui_size * .5))
        scene.ui = self.ui
        if (use_filters):
            self.filter_manager = FilterManager(base.win, base.cam)
        self.render_texture = PandaTexture()
        self.filter_quad = None
Beispiel #14
0
def orthographic():
    global PERSPECTIVE
    PERSPECTIVE = False
    sandbox.base.disableMouse()
    sandbox.base.camera.setPos(0, 0, 3000)
    sandbox.base.camera.setHpr(0, -90, 0)
    lens = OrthographicLens()
    lens.setFilmSize(10)
    sandbox.base.cam.node().setLens(lens)
Beispiel #15
0
 def setup(self,task):
   
   lens = OrthographicLens()
   lens.setFilmSize(25,20)
   base.camNode.setLen(lens)
   
   self.player = 
   self.marioGfx
   self.marioGfx
     return Task.done
class PSSMCameraRig(object):

    """ PSSM is not really supported in python yet (too slow), so this is a stub,
    supporting only one cascade """

    def __init__(self, num_splits):
        self._split_count = num_splits
        self._mvps = PTALMatrix4f.empty_array(num_splits)
        self._nearfar = PTALVecBase2f.empty_array(num_splits)
        for i in range(num_splits):
            self._nearfar[i] = Vec2(20, 1000)
            mat = Mat4()
            mat.fill(0)
            self._mvps[i] = mat
        self._lens = OrthographicLens()
        self._lens.set_near_far(20, 1000)
        self._lens.set_film_size(100, 100)
        self._camera = Camera("PSSMDummy", self._lens)
        self._cam_node = NodePath(self._camera)
        self._parent = None

    def update(self, cam_node, light_vector):
        cam_pos = cam_node.get_pos()
        self._cam_node.set_pos(cam_pos + light_vector * 500)
        self._cam_node.look_at(cam_pos)

        transform = self._parent.get_transform(self._cam_node).get_mat()
        self._mvps[0] = transform * self._lens.get_projection_mat()

    def get_camera(self, index): # pylint: disable=W0613
        return self._cam_node

    def reparent_to(self, parent):
        self._cam_node.reparent_to(parent)
        self._parent = parent

    def get_mvp_array(self):
        return self._mvps

    def get_nearfar_array(self):
        return self._nearfar

    # Stubs
    def _stub(self, *args, **kwargs):
        pass

    set_pssm_distance = _stub
    set_sun_distance = _stub
    set_resolution = _stub
    set_use_stable_csm = _stub
    set_logarithmic_factor = _stub
    set_border_bias = _stub
    set_use_fixed_film_size = _stub
    reset_film_size_cache = _stub
Beispiel #17
0
 def setupOrtographicLens(self, near=0.1, far=100.0, filmSize=(512, 512)):
     """ Setups a OrtographicLens with a given near plane, far plane
     and film size. The film size is a tuple in the format (filmWidth, filmHeight)
     in world space. """
     self.lens = OrthographicLens()
     self.lens.setNearFar(near, far)
     self.lens.setFilmSize(*filmSize)
     self.camera.setLens(self.lens)
     self.nearPlane = near
     self.farPlane = far
     self.rebuildMatrixCache()
Beispiel #18
0
    def __init__(self, map):
        self.node, self.mapData = importTiledMap('data/tiled/maps/'+map)
        self.node.reparentTo(render)

        self.player = Player()

        lens = OrthographicLens()
        lens.setFilmSize(20, 15)
        base.cam.node().setLens(lens)
        base.cam.setPos((0,0,50))
        base.cam.setHpr((0,-90,0))
Beispiel #19
0
    def set_up(self):
        self.display_region = base.camNode.get_display_region(0)
        win = self.display_region.get_window()

        self.perspective_lens = PerspectiveLens()
        self.lens = self.perspective_lens
        self.perspective_lens.set_aspect_ratio(window.aspect_ratio)
        self.perspective_lens.set_focal_length(50)
        self.perspective_lens_node = LensNode('perspective_lens_node',
                                              self.perspective_lens)
        self.lens_node = self.perspective_lens_node

        self.orthographic_lens = OrthographicLens()
        self.orthographic_lens.set_film_size(self.fov * window.aspect_ratio,
                                             self.fov)
        self.orthographic_lens_node = LensNode('orthographic_lens_node',
                                               self.orthographic_lens)

        application.base.cam.node().set_lens(self.lens)

        self.orthographic = False
        self.fov = 40
        self.clip_plane_near = 0.0001
        self.clip_plane_far = 10000

        self.ui_display_region = win.make_display_region()
        self.ui_display_region.set_sort(20)

        self.ui_camera = NodePath(PandaCamera('ui_camera'))
        self.ui_lens = OrthographicLens()
        self.ui_lens.set_film_size(self.ui_size * .5 * self.aspect_ratio,
                                   self.ui_size * .5)
        self.ui_lens.set_near_far(-1000, 1000)
        self.ui_camera.node().set_lens(self.ui_lens)
        self._ui_lens_node = LensNode('_ui_lens_node', self.ui_lens)

        self.ui_render = NodePath('ui_render')
        self.ui_render.set_depth_test(0)
        self.ui_render.set_depth_write(0)
        self.ui_camera.reparent_to(self.ui_render)
        self.ui_display_region.set_camera(self.ui_camera)
        scene.ui_camera = self.ui_camera
        # ui_camera.hide()

        # self.black_bars_display_region = win.make_display_region()
        # self.black_bars_display_region.set_sort(-100)

        self.ui = Entity()
        self.ui.eternal = True
        self.ui.name = 'ui'
        self.ui.parent = self.ui_camera
        self.ui.scale = (self.ui_size * .5, self.ui_size * .5)
        # self.ui.model = 'quad'
        scene.ui = self.ui
    def setup(self, task):
        lens = OrthographicLens()
        lens.setFilmSize(25,20)
        base.camNode.setLens(lens)

        node = self.scene.find("root/camera1")
        node.remove()

        self.player = self.scene.find("root/mario")
        self.setupCollision()
        return Task.done
Beispiel #21
0
    def init_camera(self):

        print("-- init camera")

        self.disableMouse()

        lens = OrthographicLens()
        lens.setFilmSize(20, 15)  # Or whatever is appropriate for your scene

        self.cam.node().setLens(lens)
        self.cam.setPos(0, -20, 0)
        self.cam.lookAt(0, 0, 0)
Beispiel #22
0
    def init_camera(self):

        print("-- init camera")

        self.disableMouse()

        lens = OrthographicLens()
        lens.setFilmSize(20, 15)  # Or whatever is appropriate for your scene

        self.cam.node().setLens(lens)
        self.cam.setPos(0, -20, 0)
        self.cam.lookAt(0, 0, 0)
Beispiel #23
0
    def setupCamera(self):

        self.game.disableMouse()
        self.game.camera.setPos(self.playerActor.getPos() + 50)

        self.lens = OrthographicLens()
        self.lens.setFilmSize(
            45 + self.zoomLevel,
            35 + self.zoomLevel)  # Or whatever is appropriate for your scene

        self.game.cam.node().setLens(self.lens)

        self.game.camLens.setFov(120)
Beispiel #24
0
    def makeLens(self):
        lens = OrthographicLens()
        lens.setNearFar(-100000, 100000)
        lens.setViewHpr(self.getViewHpr())
        lens.setFilmSize(100, 100)

        return lens
Beispiel #25
0
    def build_offscreen_camera(
        self,
        name: str,
        mask: int,
        width: int,
        height: int,
        resolution: float,
    ) -> Renderer.OffscreenCamera:
        """Generates a new offscreen camera."""
        # setup buffer
        win_props = WindowProperties.size(width, height)
        fb_props = FrameBufferProperties()
        fb_props.setRgbColor(True)
        fb_props.setRgbaBits(8, 8, 8, 1)
        # XXX: Though we don't need the depth buffer returned, setting this to 0
        #      causes undefined behavior where the ordering of meshes is random.
        fb_props.setDepthBits(8)

        buffer = self._showbase_instance.win.engine.makeOutput(
            self._showbase_instance.pipe,
            "{}-buffer".format(name),
            -100,
            fb_props,
            win_props,
            GraphicsPipe.BFRefuseWindow,
            self._showbase_instance.win.getGsg(),
            self._showbase_instance.win,
        )
        buffer.setClearColor((0, 0, 0, 0))  # Set background color to black

        # setup texture
        tex = Texture()
        region = buffer.getDisplayRegion(0)
        region.window.addRenderTexture(tex, GraphicsOutput.RTM_copy_ram,
                                       GraphicsOutput.RTP_color)

        # setup camera
        lens = OrthographicLens()
        lens.setFilmSize(width * resolution, height * resolution)

        camera_np = self._showbase_instance.makeCamera(buffer,
                                                       camName=name,
                                                       scene=self._root_np,
                                                       lens=lens)
        camera_np.reparentTo(self._root_np)

        # mask is set to make undesirable objects invisible to this camera
        camera_np.node().setCameraMask(camera_np.node().getCameraMask() & mask)

        return Renderer.OffscreenCamera(camera_np, buffer, tex, self)
Beispiel #26
0
    def __init__(self):

        base.disableMouse()

        lens = OrthographicLens()
        lens.setFilmSize(34.2007, 25.6505)
        lens.setNear(-10)
        lens.setFar(100)
        base.cam.node().setLens(lens)

        self.container = render.attachNewNode('camContainer')
        base.camera.reparentTo(self.container)
        base.camera.setPos(-40, 0, 23)
        base.camera.lookAt(0, 0, 3)
        self.container.setHpr(45, 0, 0)

        self.zoomed = True
        self.r = False

        # Load sounds
        self.toggle_r_snd = base.loader.loadSfx(GAME +
                                                '/sounds/camera_toggle_r.ogg')
        self.rotate_snd = base.loader.loadSfx(GAME +
                                              '/sounds/camera_rotate.ogg')

        self.acceptAll()
        self.windowEvent(base.win)
Beispiel #27
0
    def setupCamera2d(self,
                      sort=10,
                      displayRegion=(0, 1, 0, 1),
                      coords=(-1, 1, -1, 1)):
        dr = self.win.makeMonoDisplayRegion(*displayRegion)
        dr.setSort(10)

        # Enable clearing of the depth buffer on this new display
        # region (see the comment in setupRender2d, above).
        dr.setClearDepthActive(1)

        # Make any texture reloads on the gui come up immediately.
        dr.setIncompleteRender(False)

        left, right, bottom, top = coords

        # Now make a new Camera node.
        cam2dNode = Camera('cam2d')

        lens = OrthographicLens()
        lens.setFilmSize(right - left, top - bottom)
        lens.setFilmOffset((right + left) * 0.5, (top + bottom) * 0.5)
        lens.setNearFar(-1000, 1000)
        cam2dNode.setLens(lens)

        # self.camera2d is the analog of self.camera, although it's
        # not as clear how useful it is.
        self.camera2d = self.render2d.attachNewNode('camera2d')

        camera2d = self.camera2d.attachNewNode(cam2dNode)
        dr.setCamera(camera2d)

        self.cam2d = camera2d

        return camera2d
Beispiel #28
0
    def __init__(self, app):
        self.app = app
        self.do = DirectObject()

        self.running = False
        self.displayRegion = None
        self.root = NodePath('creditsRender')
        self.camera = Camera('creditsCam')
        self.cameraNP = NodePath(self.camera)

        # Set parameters to match those of render2d
        self.root.setDepthTest(0)
        self.root.setDepthWrite(0)
        self.root.setMaterialOff(1)
        self.root.setTwoSided(1)

        self.aspect2d = self.root  # self.root.attachNewNode('creditsAspect')

        lens = OrthographicLens()
        lens.setFilmSize(2, 2)
        lens.setFilmOffset(0, 0)
        lens.setNearFar(-1000, 1000)
        self.camera.setLens(lens)

        self.cameraNP.reparentTo(self.root)

        self.scrollTask = None
        self.lastTime = None
        self.creditsFileLoaded = False
Beispiel #29
0
 def renderQuadInto(self, mul=1, div=1, align=1, depthtex=None, colortex=None, auxtex0=None, auxtex1=None):
     texgroup = (
      depthtex, colortex, auxtex0, auxtex1)
     winx, winy = self.getScaledSize(mul, div, align)
     depthbits = bool(depthtex != None)
     buffer = self.createBuffer('filter-stage', winx, winy, texgroup, depthbits)
     if buffer == None:
         return
     cm = CardMaker('filter-stage-quad')
     cm.setFrameFullscreenQuad()
     quad = NodePath(cm.generate())
     quad.setDepthTest(0)
     quad.setDepthWrite(0)
     quad.setColor(1, 0.5, 0.5, 1)
     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)
     dr = buffer.makeDisplayRegion((0, 1, 0, 1))
     dr.disableClears()
     dr.setCamera(quadcam)
     dr.setActive(True)
     dr.setScissorEnabled(False)
     buffer.setClearColor((0, 0, 0, 1))
     buffer.setClearColorActive(True)
     self.buffers.append(buffer)
     self.sizes.append((mul, div, align))
     return quad
Beispiel #30
0
    def create(self):
        self.camera = Camera("PSSMSceneSunShadowCam")
        self.cam_lens = OrthographicLens()
        self.cam_lens.set_film_size(400, 400)
        self.cam_lens.set_near_far(100.0, 1800.0)
        self.camera.set_lens(self.cam_lens)
        self.cam_node = Globals.base.render.attach_new_node(self.camera)

        self.target = self.create_target("ShadowMap")
        self.target.size = self.resolution
        self.target.add_depth_attachment(bits=32)
        self.target.prepare_render(self.cam_node)

        # Register shadow camera
        self._pipeline.tag_mgr.register_camera("shadow", self.camera)
Beispiel #31
0
 def make_buffer(self, width, height, texture_format):
     self.width = width
     self.height = height
     self.root = NodePath("root")
     props = FrameBufferProperties()
     props.set_srgb_color(False)
     if texture_format == Texture.F_rgb:
         props.set_float_color(False)
         props.set_rgba_bits(8, 8, 8, 0)
     elif texture_format == Texture.F_rgba:
         props.set_float_color(False)
         props.set_rgba_bits(8, 8, 8, 8)
     elif texture_format == Texture.F_r32:
         props.set_float_color(True)
         props.set_rgba_bits(32, 0, 0, 0)
     elif texture_format == Texture.F_rgb32:
         props.set_float_color(True)
         props.set_rgba_bits(32, 32, 32, 0)
     elif texture_format == Texture.F_rgba32:
         props.set_float_color(True)
         props.set_rgba_bits(32, 32, 32, 32)
     self.buffer = base.win.make_texture_buffer("generatorBuffer",
                                                width,
                                                height,
                                                to_ram=True,
                                                fbp=props)
     #print(self.buffer.get_fb_properties(), self.buffer.get_texture())
     self.buffer.setOneShot(True)
     #the camera for the buffer
     cam = base.makeCamera(win=self.buffer)
     cam.reparent_to(self.root)
     cam.set_pos(width / 2, height / 2, 100)
     cam.set_p(-90)
     lens = OrthographicLens()
     lens.set_film_size(width, height)
     cam.node().set_lens(lens)
     #plane with the texture
     cm = CardMaker("plane")
     cm.set_frame(0, width, 0, height)
     x_margin = 1.0 / width / 2.0
     y_margin = 1.0 / height / 2.0
     cm.set_uv_range((-x_margin, -y_margin), (1 + x_margin, 1 + y_margin))
     self.quad = self.root.attach_new_node(cm.generate())
     self.quad.look_at(0, 0, -1)
     taskMgr.add(self.check_generation, 'check_generation', sort=-10000)
     taskMgr.add(self.callback, 'callback', sort=-9999)
     print("Created offscreen buffer, size: %dx%d" % (width, height),
           "format:", Texture.formatFormat(texture_format))
    def create(self):
        # Create the voxel grid used to store the voxels
        self._voxel_grid = Image.create_3d(
            "Voxels", self._voxel_res, self._voxel_res, self._voxel_res, Texture.T_float, Texture.F_r11_g11_b10
        )
        self._voxel_grid.set_clear_color(Vec4(0))

        # Create the camera for voxelization
        self._voxel_cam = Camera("VoxelizeCam")
        self._voxel_cam.set_camera_mask(self._pipeline.tag_mgr.get_voxelize_mask())
        self._voxel_cam_lens = OrthographicLens()
        self._voxel_cam_lens.set_film_size(-self._voxel_ws, self._voxel_ws)
        self._voxel_cam_lens.set_near_far(0.0, 2.0 * self._voxel_ws)
        self._voxel_cam.set_lens(self._voxel_cam_lens)
        self._voxel_cam_np = Globals.base.render.attach_new_node(self._voxel_cam)
        self._pipeline.tag_mgr.register_voxelize_camera(self._voxel_cam)

        # Create the voxelization target
        self._voxel_target = self._create_target("VoxelizeScene")
        self._voxel_target.set_source(source_cam=self._voxel_cam_np, source_win=Globals.base.win)
        self._voxel_target.set_size(self._voxel_res, self._voxel_res)
        self._voxel_target.set_create_overlay_quad(False)
        self._voxel_target.prepare_scene_render()

        # Create the initial state used for rendering voxels
        initial_state = NodePath("VXInitialState")
        initial_state.set_attrib(CullFaceAttrib.make(CullFaceAttrib.M_cull_none), 100000)
        initial_state.set_attrib(DepthTestAttrib.make(DepthTestAttrib.M_none), 100000)
        initial_state.set_attrib(ColorWriteAttrib.make(ColorWriteAttrib.C_off), 100000)
        self._voxel_cam.set_initial_state(initial_state.get_state())

        Globals.base.render.set_shader_input("voxelGridPosition", self._pta_grid_pos)
        Globals.base.render.set_shader_input("voxelGridRes", self._pta_grid_res)
        Globals.base.render.set_shader_input("voxelGridSize", self._pta_grid_size)
        Globals.base.render.set_shader_input("VoxelGridDest", self._voxel_grid.texture)
Beispiel #33
0
 def makeOrthographic(parent, name, campos):
     v = Viewport(name, parent)
     v.lens = OrthographicLens()
     v.lens.setFilmSize(30)
     v.camPos = campos
     v.camLookAt = Point3(0, 0, 0)
     v.grid = DirectGrid(parent=render)
     if name == 'left':
         v.grid.setHpr(0, 0, 90)
         collPlane = CollisionNode('LeftGridCol')
         collPlane.addSolid(CollisionPlane(Plane(1, 0, 0, 0)))
         collPlane.setIntoCollideMask(BitMask32.bit(21))
         v.collPlane = NodePath(collPlane)
         v.collPlane.wrtReparentTo(v.grid)
         #v.grid.gridBack.findAllMatches("**/+GeomNode")[0].setName("_leftViewGridBack")
         LE_showInOneCam(v.grid, name)
     elif name == 'front':
         v.grid.setHpr(90, 0, 90)
         collPlane = CollisionNode('FrontGridCol')
         collPlane.addSolid(CollisionPlane(Plane(0, -1, 0, 0)))
         collPlane.setIntoCollideMask(BitMask32.bit(21))
         v.collPlane = NodePath(collPlane)
         v.collPlane.wrtReparentTo(v.grid)
         #v.grid.gridBack.findAllMatches("**/+GeomNode")[0].setName("_frontViewGridBack")
         LE_showInOneCam(v.grid, name)
     else:
         collPlane = CollisionNode('TopGridCol')
         collPlane.addSolid(CollisionPlane(Plane(0, 0, 1, 0)))
         collPlane.setIntoCollideMask(BitMask32.bit(21))
         v.collPlane = NodePath(collPlane)
         v.collPlane.reparentTo(v.grid)
         #v.grid.gridBack.findAllMatches("**/+GeomNode")[0].setName("_topViewGridBack")
         LE_showInOneCam(v.grid, name)
     return v
    def create(self):
        self.camera = Camera("PSSMDistShadowsESM")
        self.cam_lens = OrthographicLens()
        self.cam_lens.set_film_size(12000, 12000)
        self.cam_lens.set_near_far(10.0, self.sun_distance * 2)
        self.camera.set_lens(self.cam_lens)
        self.cam_node = Globals.base.render.attach_new_node(self.camera)

        self.target = self.create_target("ShadowMap")
        self.target.size = self.resolution
        self.target.add_depth_attachment(bits=32)
        self.target.prepare_render(self.cam_node)

        self.target_convert = self.create_target("ConvertToESM")
        self.target_convert.size = self.resolution
        self.target_convert.add_color_attachment(bits=(32, 0, 0, 0))
        self.target_convert.prepare_buffer()
        self.target_convert.set_shader_input("SourceTex", self.target.depth_tex)

        self.target_blur_v = self.create_target("BlurVert")
        self.target_blur_v.size = self.resolution
        self.target_blur_v.add_color_attachment(bits=(32, 0, 0, 0))
        self.target_blur_v.prepare_buffer()
        self.target_blur_v.set_shader_input("SourceTex", self.target_convert.color_tex)
        self.target_blur_v.set_shader_input("direction", LVecBase2i(1, 0))

        self.target_blur_h = self.create_target("BlurHoriz")
        self.target_blur_h.size = self.resolution
        self.target_blur_h.add_color_attachment(bits=(32, 0, 0, 0))
        self.target_blur_h.prepare_buffer()
        self.target_blur_h.set_shader_input("SourceTex", self.target_blur_v.color_tex)
        self.target_blur_h.set_shader_input("direction", LVecBase2i(0, 1))

        # Register shadow camera
        self._pipeline.tag_mgr.register_camera("shadow", self.camera)
Beispiel #35
0
    def create(self):
        winprops = WindowProperties.size(self.size, self.size)
        props = FrameBufferProperties()
        props.setRgbColor(0)
        props.setAlphaBits(0)
        props.setDepthBits(1)
        self.buffer = base.graphicsEngine.makeOutput(
            base.pipe, "shadowsBuffer", -2, props, winprops,
            GraphicsPipe.BFRefuseWindow, base.win.getGsg(), base.win)

        if not self.buffer:
            print("Video driver cannot create an offscreen buffer.")
            return
        self.depthmap = Texture()
        self.buffer.addRenderTexture(self.depthmap,
                                     GraphicsOutput.RTMBindOrCopy,
                                     GraphicsOutput.RTPDepthStencil)

        self.depthmap.setMinfilter(Texture.FTShadow)
        self.depthmap.setMagfilter(Texture.FTShadow)
        self.depthmap.setBorderColor(LColor(1, 1, 1, 1))
        self.depthmap.setWrapU(Texture.WMBorderColor)
        self.depthmap.setWrapV(Texture.WMBorderColor)

        self.cam = base.makeCamera(self.buffer, lens=OrthographicLens())
        self.cam.reparent_to(render)
        self.node = self.cam.node()
        self.node.setInitialState(
            RenderState.make(
                CullFaceAttrib.make_reverse(),
                ColorWriteAttrib.make(ColorWriteAttrib.M_none),
            ))
        self.node.setScene(render)
        if settings.debug_shadow_frustum:
            self.node.showFrustum()
    def create(self):
        # Create voxelize camera
        self.voxelizeCamera = Camera("VoxelizeCamera")
        self.voxelizeCamera.setCameraMask(BitMask32.bit(4))
        self.voxelizeCameraNode = Globals.render.attachNewNode(self.voxelizeCamera)
        self.voxelizeLens = OrthographicLens()
        self.voxelizeLens.setFilmSize(self.voxelGridSize * 2, self.voxelGridSize * 2)
        self.voxelizeLens.setNearFar(0.0, self.voxelGridSize * 2)
        self.voxelizeCamera.setLens(self.voxelizeLens)
        self.voxelizeCamera.setTagStateKey("VoxelizePassShader")
        Globals.render.setTag("VoxelizePassShader", "Default")

        # Create voxelize tareet
        self.target = RenderTarget("VoxelizePass")
        self.target.setSize(self.voxelGridResolution * self.gridResolutionMultiplier)

        if self.pipeline.settings.useDebugAttachments:
            self.target.addColorTexture()
        else:
            self.target.setColorWrite(False)

        self.target.setCreateOverlayQuad(False)
        self.target.setSource(self.voxelizeCameraNode, Globals.base.win)
        self.target.prepareSceneRender()
        self.target.setActive(False)
    def create(self):
        self.camera = Camera("SkyAOCaptureCam")
        self.cam_lens = OrthographicLens()
        self.cam_lens.set_film_size(200, 200)
        self.cam_lens.set_near_far(0.0, 500.0)
        self.camera.set_lens(self.cam_lens)
        self.cam_node = Globals.base.render.attach_new_node(self.camera)
        self.cam_node.look_at(0, 0, -1)
        self.cam_node.set_r(0)

        self.target = self.create_target("SkyAOCapture")
        self.target.size = 1024
        self.target.add_depth_attachment(bits=16)
        self.target.prepare_render(self.cam_node)

        self.target_convert = self.create_target("ConvertDepth")
        self.target_convert.size = 1024
        self.target_convert.add_color_attachment(bits=(16, 0, 0, 0))
        self.target_convert.prepare_buffer()

        self.target_convert.set_shader_input("DepthTex", self.target.depth_tex)
        self.target_convert.set_shader_input("position", self.pta_position)

        # Register camera
        self._pipeline.tag_mgr.register_camera("shadow", self.camera)
Beispiel #38
0
    def _build_offscreen_camera(
        self,
        name: str,
        mask: int,
        width: int,
        height: int,
        resolution: float,
    ):
        # setup buffer
        win_props = WindowProperties.size(width, height)
        fb_props = FrameBufferProperties()
        fb_props.setRgbColor(True)
        fb_props.setRgbaBits(8, 8, 8, 1)
        fb_props.setDepthBits(0)

        buffer = self._showbase.win.engine.makeOutput(
            self._showbase.pipe,
            "{}-buffer".format(name),
            -100,
            fb_props,
            win_props,
            GraphicsPipe.BFRefuseWindow,
            self._showbase.win.getGsg(),
            self._showbase.win,
        )
        buffer.setClearColor((0, 0, 0, 0))  # Set background color to black

        # setup texture
        tex = Texture()
        region = buffer.getDisplayRegion(0)
        region.window.addRenderTexture(tex, GraphicsOutput.RTM_copy_ram,
                                       GraphicsOutput.RTP_color)

        # setup camera
        lens = OrthographicLens()
        lens.setFilmSize(width * resolution, height * resolution)

        camera_np = self._showbase.makeCamera(buffer,
                                              camName=name,
                                              scene=self._scene_np,
                                              lens=lens)
        camera_np.reparentTo(self._scene_np)

        # mask is set to make undesireable objects invisible to this camera
        camera_np.node().setCameraMask(camera_np.node().getCameraMask() & mask)

        return OffscreenCamera(camera_np, buffer, tex)
Beispiel #39
0
    def renderQuadInto(self,
                       mul=1,
                       div=1,
                       align=1,
                       depthtex=None,
                       colortex=None,
                       auxtex0=None,
                       auxtex1=None):
        """ Creates an offscreen buffer for an intermediate
        computation. Installs a quad into the buffer.  Returns
        the fullscreen quad.  The size of the buffer is initially
        equal to the size of the main window.  The parameters 'mul',
        'div', and 'align' can be used to adjust that size. """

        texgroup = (depthtex, colortex, auxtex0, auxtex1)

        winx, winy = self.getScaledSize(mul, div, align)

        depthbits = bool(depthtex != None)

        buffer = self.createBuffer("filter-stage", winx, winy, texgroup,
                                   depthbits)

        if (buffer == None):
            return None

        cm = CardMaker("filter-stage-quad")
        cm.setFrameFullscreenQuad()
        quad = NodePath(cm.generate())
        quad.setDepthTest(0)
        quad.setDepthWrite(0)
        quad.setColor(1, 0.5, 0.5, 1)

        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)

        dr = buffer.makeDisplayRegion((0, 1, 0, 1))
        dr.disableClears()
        dr.setCamera(quadcam)
        dr.setActive(True)
        dr.setScissorEnabled(False)

        # This clear stage is important if the buffer is padded, so that
        # any pixels accidentally sampled in the padded region won't
        # be reading from unititialised memory.
        buffer.setClearColor((0, 0, 0, 1))
        buffer.setClearColorActive(True)

        self.buffers.append(buffer)
        self.sizes.append((mul, div, align))

        return quad
 def _makeFullscreenCam(self):
     bufferCam = Camera("BufferCamera")
     lens = OrthographicLens()
     lens.setFilmSize(2, 2)
     lens.setFilmOffset(0, 0)
     lens.setNearFar(-1000, 1000)
     bufferCam.setLens(lens)
     bufferCam.setCullBounds(OmniBoundingVolume())
     return bufferCam
    def renderQuadInto(self, xsize, ysize, colortex=None, cmode = GraphicsOutput.RTMBindOrCopy, auxtex = None):

        buffer = self.createBuffer("filter-stage", xsize, ysize, colortex, cmode, auxtex)

        if (buffer == None):
            return None

        cm = CardMaker("filter-stage-quad")
        cm.setFrameFullscreenQuad()
        quad = NodePath(cm.generate())
        quad.setDepthTest(0)
        quad.setDepthWrite(0)
        quad.setColor(Vec4(1,0.5,0.5,1))

        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)
        
        buffer.getDisplayRegion(0).setCamera(quadcam)
        buffer.getDisplayRegion(0).setActive(1)

        return quad, buffer
Beispiel #42
0
    def __init__(self):

        base.disableMouse()

        lens = OrthographicLens()
        lens.setFilmSize(34.2007, 25.6505)
        lens.setNear(-10)
        lens.setFar(100)
        base.cam.node().setLens(lens)

        self.container = render.attachNewNode('camContainer')
        base.camera.reparentTo( self.container )
        base.camera.setPos( -40, 0, 23 )
        base.camera.lookAt(0, 0, 3)
        self.container.setHpr(45, 0, 0)

        self.zoomed = True
        self.r      = False
        
        # Load sounds
        self.toggle_r_snd = base.loader.loadSfx(GAME+'/sounds/camera_toggle_r.ogg')
        self.rotate_snd   = base.loader.loadSfx(GAME+'/sounds/camera_rotate.ogg')

        self.acceptAll()
        self.windowEvent(base.win)
Beispiel #43
0
    def __init__(self):

        base.disableMouse()

        lens = OrthographicLens()
        lens.setFilmSize(34.2007, 25.6505)
        lens.setNear(-10)
        lens.setFar(100)
        base.cam.node().setLens(lens)

        self.container = render.attachNewNode("camContainer")
        base.camera.reparentTo(self.container)
        base.camera.setPos(-40, 0, 23)
        base.camera.lookAt(0, 0, 3)
        self.container.setHpr(45, 0, 0)

        self.zoomed = True
        self.r = False
        self.phase = None

        # Load sounds
        self.toggle_r_snd = base.loader.loadSfx(GAME + "/sounds/camera_toggle_r.ogg")
        self.rotate_snd = base.loader.loadSfx(GAME + "/sounds/camera_rotate.ogg")

        self.accept("e", self.toggleZoom)
        self.accept("r", self.toggleR)
        self.accept("a", lambda: self.rotate(90))
        self.accept("z", lambda: self.rotate(-90))
        self.accept("window-event", self.windowEvent)
Beispiel #44
0
    def create(self):
        g_buffer = base.win.makeTextureBuffer(self._name, self._size, self._size)
        g_buffer.setClearColor(self._bg_color)
        self._texture = g_buffer.getTexture()
        g_buffer.setSort(-100)

        camera2d = NodePath(base.makeCamera(g_buffer))
        lens = OrthographicLens()
        lens.setFilmSize(2, 2)
        lens.setNearFar(-1000, 1000)
        camera2d.node().setLens(lens)

        self._render2d = NodePath("{0}-my-render2d".format(self._name))
        self._render2d.setDepthTest(False)
        self._render2d.setDepthWrite(False)
        camera2d.reparentTo(self._render2d)

        return self._render2d, self._texture
 def setupPerspectiveLens(self, near=0.1, far=100.0, fov=(90, 90)):
     """ Setups a PerspectiveLens with a given near plane, far plane
     and FoV. The FoV is a tuple in the format (Horizontal FoV, Vertical FoV) """
     self.lens = PerspectiveLens()
     self.lens.setNearFar(near, far)
     self.lens.setFov(fov[0], fov[1])
     self.camera.setLens(self.lens)
     self.nearPlane = near
     self.farPlane = far
     self.rebuildMatrixCache()
Beispiel #46
0
	def __init__(self,base):

		self.base = base
		self.base.disableMouse()		

		x_win = self.base.win.getXSize()
		y_win = self.base.win.getYSize()
		aspect_win = float(x_win)/float(y_win)

		self.active_lens = 1

		self.ortho_lens = OrthographicLens()
		self.ortho_lens.setAspectRatio(aspect_win)
		self.ortho_lens.setNearFar(1.0,100.0)

		self.persp_lens = PerspectiveLens()
		self.persp_lens.setAspectRatio(aspect_win)
		self.persp_lens.setFov(5.0)
		self.persp_lens.setNearFar(1.0,100.0)

		self.lenses = [self.persp_lens, self.ortho_lens]

		self.set_lens(lens=self.active_lens)


		self.set_view(Vec3(50.0,50.0,50.0))

		self.old_x = None
		self.old_y = None

		self.zoom_speed = 0.05
		self.pan_speed = 0.005
		self.rotate_speed = 0.1

		#these are pointers
		self.keys = self.base.keyboard_reader.keys
		self.key_map = self.base.keyboard_reader.key_map

		#registering camera functions
		self.base.taskMgr.add(hold_caller_multikey(trigger=self.keys, indices=[self.key_map['shift'], self.key_map['mouse2']], values=[1,1], init_handle=None, loop_handle=self.pan_camera, cleanup_handle=self.mouse_delta_cleanup), 'pan_camera_task')
		self.base.taskMgr.add(hold_caller_multikey(trigger=self.keys, indices=[self.key_map['control'], self.key_map['shift'], self.key_map['mouse2']], values=[0, 0,1], init_handle=None, loop_handle=self.rotate_camera_fixed_pivot, cleanup_handle=self.mouse_delta_cleanup), 'rotate_camera_task')
		self.base.taskMgr.add(hold_caller_multikey(trigger=self.keys, indices=[self.key_map['control'], self.key_map['mouse2']], values=[1,1], init_handle=None, loop_handle=self.zoom_camera, cleanup_handle=self.mouse_delta_cleanup), 'rotate_camera_task')


		#register camera presets
		self.base.taskMgr.add( delta_caller(handle = self.set_viewpoint_front , trigger = self.keys, index = self.key_map['1'], value=1), 'camera_preset_front_task')
		self.base.taskMgr.add( delta_caller(handle = self.set_viewpoint_side , trigger = self.keys, index = self.key_map['2'], value=1), 'camera_preset_side_task')
		self.base.taskMgr.add( delta_caller(handle = self.set_viewpoint_top , trigger = self.keys, index = self.key_map['3'], value=1), 'camera_preset_top_task')

		#register switching perspective
		#TODO: currently disabled because perspective camera is stupid and should feel bad
		#self.base.taskMgr.add( delta_caller(handle = self.switch_perspective , trigger = self.keys, index = self.key_map['5'], value=1), 'camera_switch_perspective_task')

		#makes the zoom level of the orthographic camera more reasonable
		self.fixed_zoom_camera(10.0)
    def getRenderMapCam(self, rawTile, inputMaps, shader, size):
        """
        Sets up scene and cam for rendering the map
        Returns the cam
        """
        margin=texMargin(size)
        
        altRender=NodePath("newRender")

        # setup square orthographic cam
        altCam=NodePath(Camera("renderMapCam"))
        altCam.reparentTo(altRender)   
        altCam.setPos(.5,-1,.5) 

        oLens = OrthographicLens()
        oLens.setFilmSize(1+margin*2, 1+margin*2)
        altCam.node().setLens(oLens)
        
         # Make a card on which the shader will render the map
        c=CardMaker("MapCardMaker")
        c.setUvRange(0-margin,1+margin,0-margin,1+margin)
        c.setFrame(0-margin,1+margin,0-margin,1+margin)
        mapCard=NodePath(c.generate())
        
        mapCard.setPos(0,0,0)   
        mapCard.setShader(shader.shader)
        mapCard.setShaderInput("offset",rawTile.x,rawTile.y,0,0)
        mapCard.setShaderInput("scale",rawTile.scale,0,0,0)

        for m in inputMaps:
            texStage=TextureStage(m.name+"stage")
            mapCard.setTexture(texStage,m.tex)
        
        for p in shader.shaderTex:
            mapCard.setTexture(*p)
        
        mapCard.reparentTo(altRender)
        
        # Comment out this line to cause the bug with multiple textures requireing an extra frame to work properly
        altRender.prepareScene(base.win.getGsg())
        
        return altCam
 def setupOrtographicLens(self, near=0.1, far=100.0, filmSize=(512, 512)):
     """ Setups a OrtographicLens with a given near plane, far plane
     and film size. The film size is a tuple in the format (filmWidth, filmHeight)
     in world space. """
     self.lens = OrthographicLens()
     self.lens.setNearFar(near, far)
     self.lens.setFilmSize(*filmSize)
     self.camera.setLens(self.lens)
     self.nearPlane = near
     self.farPlane = far
     self.rebuildMatrixCache()
Beispiel #49
0
	def setupCamera(self):

		self.game.disableMouse()
		self.game.camera.setPos(self.playerActor.getPos()+50)

		self.lens = OrthographicLens()
		self.lens.setFilmSize(45+self.zoomLevel, 35+self.zoomLevel)  # Or whatever is appropriate for your scene

		self.game.cam.node().setLens(self.lens)

		self.game.camLens.setFov(120)
 def _makeFullscreenCam(self):
     """ Create a orthographic camera for this buffer """
     bufferCam = Camera("BufferCamera")
     lens = OrthographicLens()
     lens.setFilmSize(2, 2)
     lens.setFilmOffset(0, 0)
     lens.setNearFar(-1000, 1000)
     bufferCam.setLens(lens)
     bufferCam.setCullBounds(OmniBoundingVolume())
     return bufferCam
Beispiel #51
0
    def createPlayerDisplay(self, displayBox):
        """Create a 2D display region with camera to be used to
        show things like the speedo and points
        """

        displayRegion = self.base.win.makeDisplayRegion(*displayBox)
        displayRegion.setSort(20)

        camera2d = NodePath(Camera("player2dcam"))
        lens = OrthographicLens()
        lens.setFilmSize(2, 2)
        lens.setNearFar(-1000, 1000)
        camera2d.node().setLens(lens)

        render2d = NodePath("render2d")
        render2d.setDepthTest(False)
        render2d.setDepthWrite(False)
        camera2d.reparentTo(render2d)
        displayRegion.setCamera(camera2d)

        return render2d
Beispiel #52
0
 def setup_display2(self, display_node):
     print 'setup display2'
     props = WindowProperties()
     props.set_cursor_hidden(True)
     props.set_foreground(False)
     if self.config.get('resolution'):
         props.setSize(700, 700)
         props.setOrigin(-int(self.config['resolution'][0] - 5), 5)
     else:
         props.setSize(300, 300)
         props.setOrigin(10, 10)
     window2 = self.base.openWindow(props=props, aspectRatio=1)
     lens = OrthographicLens()
     lens.set_film_size(2, 2)
     lens.setNearFar(-100, 100)
     self.render2d = NodePath('render2d')
     self.render2d.attach_new_node(display_node)
     camera2d = self.base.makeCamera(window2)
     camera2d.setPos(0, -10, 0)
     camera2d.node().setLens(lens)
     camera2d.reparentTo(self.render2d)
 def _make_fullscreen_cam(self):
     """ Creates an orthographic camera for the buffer """
     buffer_cam = Camera("BufferCamera")
     lens = OrthographicLens()
     lens.set_film_size(2, 2)
     lens.set_film_offset(0, 0)
     lens.set_near_far(-100, 100)
     buffer_cam.set_lens(lens)
     buffer_cam.set_cull_bounds(OmniBoundingVolume())
     self._camera = self._node.attach_new_node(buffer_cam)
     self._region.set_camera(self._camera)
    def create(self):
        self.camera = Camera("PSSMSceneSunShadowCam")
        self.cam_lens = OrthographicLens()
        self.cam_lens.set_film_size(400, 400)
        self.cam_lens.set_near_far(100.0, 1800.0)
        self.camera.set_lens(self.cam_lens)
        self.cam_node = Globals.base.render.attach_new_node(self.camera)

        self.target = self.create_target("ShadowMap")
        self.target.size = self.resolution
        self.target.add_depth_attachment(bits=32)
        self.target.prepare_render(self.cam_node)

        # Register shadow camera
        self._pipeline.tag_mgr.register_camera("shadow", self.camera)
 def __init__(self, num_splits):
     self._split_count = num_splits
     self._mvps = PTALMatrix4f.empty_array(num_splits)
     self._nearfar = PTALVecBase2f.empty_array(num_splits)
     for i in range(num_splits):
         self._nearfar[i] = Vec2(20, 1000)
         mat = Mat4()
         mat.fill(0)
         self._mvps[i] = mat
     self._lens = OrthographicLens()
     self._lens.set_near_far(20, 1000)
     self._lens.set_film_size(100, 100)
     self._camera = Camera("PSSMDummy", self._lens)
     self._cam_node = NodePath(self._camera)
     self._parent = None
 def __init__(self, playerNode):
 
     self.playerNode = playerNode
     
     pregion = base.win.makeDisplayRegion()
     cam = NodePath(Camera('cam'))
     lens = OrthographicLens()
     lens.setFilmSize(2, 2)
     lens.setNearFar(-1000, 1000)
     cam.node().setLens(lens)
     
     myRender = NodePath('myRender')
     myRender.setDepthTest(False)
     myRender.setDepthWrite(False)
     cam.reparentTo(myRender)
     pregion.setCamera(cam)
     
     aspectRatio = base.getAspectRatio()
     self.myAspect = myRender.attachNewNode(PGTop('myAspect'))
     self.myAspect.setScale(1.0 / aspectRatio, 1.0, 1.0)
     self.myAspect.node().setMouseWatcher(base.mouseWatcherNode)
     
     frame = DirectFrame(frameColor=(0,0,0,.4), frameSize=(base.a2dLeft,base.a2dRight,-1,1), pos=(0,0,0))
     frame.reparentTo(self.myAspect)
    def renderQuadInto(self, mul=1, div=1, align=1, depthtex=None, colortex=None, auxtex0=None, auxtex1=None):

        """ Creates an offscreen buffer for an intermediate
        computation. Installs a quad into the buffer.  Returns
        the fullscreen quad.  The size of the buffer is initially
        equal to the size of the main window.  The parameters 'mul',
        'div', and 'align' can be used to adjust that size. """

        texgroup = (depthtex, colortex, auxtex0, auxtex1)

        winx, winy = self.getScaledSize(mul, div, align)
        
        depthbits = bool(depthtex != None)

        buffer = self.createBuffer("filter-stage", winx, winy, texgroup, depthbits)

        if (buffer == None):
            return None

        cm = CardMaker("filter-stage-quad")
        cm.setFrameFullscreenQuad()
        quad = NodePath(cm.generate())
        quad.setDepthTest(0)
        quad.setDepthWrite(0)
        quad.setColor(1, 0.5, 0.5, 1)

        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)

        dr = buffer.makeDisplayRegion((0, 1, 0, 1))
        dr.disableClears()
        dr.setCamera(quadcam)
        dr.setActive(True)
        dr.setScissorEnabled(False)

        # This clear stage is important if the buffer is padded, so that
        # any pixels accidentally sampled in the padded region won't
        # be reading from unititialised memory.
        buffer.setClearColor((0, 0, 0, 1))
        buffer.setClearColorActive(True)

        self.buffers.append(buffer)
        self.sizes.append((mul, div, align))
        
        return quad
    def create(self):

        self._camera = Camera("VXGISunShadowCam")
        self._cam_lens = OrthographicLens()
        self._cam_lens.set_film_size(400, 400)
        self._cam_lens.set_near_far(0.0, 800.0)
        self._camera.set_lens(self._cam_lens)
        self._cam_node = Globals.base.render.attach_new_node(self._camera)

        self._target = self.make_target("PSSMDistShadowMap")
        self._target.set_source(self._cam_node, Globals.base.win)
        self._target.size = self._resolution
        self._target.add_depth_texture(bits=32)
        self._target.create_overlay_quad = False
        self._target.color_write = False
        self._target.prepare_scene_render()

        # Register shadow camera
        self._pipeline.tag_mgr.register_shadow_camera(self._camera)
Beispiel #59
0
    def create(self):
        # Create voxelize camera
        self.voxelizeCamera = Camera("VoxelizeScene")
        self.voxelizeCamera.setCameraMask(BitMask32.bit(4))
        self.voxelizeCameraNode = Globals.render.attachNewNode(self.voxelizeCamera)
        self.voxelizeLens = OrthographicLens()
        self.voxelizeLens.setFilmSize(self.voxelGridSize.x*2, self.voxelGridSize.y*2)
        self.voxelizeLens.setNearFar(0.0, self.voxelGridSize.x*2)
        self.voxelizeCamera.setLens(self.voxelizeLens)
        self.voxelizeCamera.setTagStateKey("VoxelizePassShader")
        Globals.render.setTag("VoxelizePassShader", "Default")

        # Create voxelize tareet
        self.target = RenderTarget("VoxelizePass")
        self.target.setSize( self.voxelGridResolution.x * 4 )
        self.target.setColorWrite(False)
        self.target.setCreateOverlayQuad(False)
        self.target.setSource(self.voxelizeCameraNode, Globals.base.win)
        self.target.prepareSceneRender()
        self.target.setActive(False)

        self.target.getInternalRegion().setSort(-400)
        self.target.getInternalBuffer().setSort(-399)
class PSSMSceneShadowStage(RenderStage):

    """ This stage creates the shadow map which covers the whole important part
    of the scene. This is required because the shadow cascades only cover the
    view frustum, but many plugins (VXGI, EnvMaps) require a shadow map. """

    required_inputs = []
    required_pipes = []

    def __init__(self, pipeline):
        RenderStage.__init__(self, pipeline)
        self.resolution = 2048
        self.sun_vector = Vec3(0, 0, 1)
        self.sun_distance = 10.0
        self.pta_mvp = PTAMat4.empty_array(1)
        self.focus = None

        # Store last focus entirely for the purpose of being able to see
        # it in the debugger
        self.last_focus = None

    @property
    def produced_inputs(self):
        return {"PSSMSceneSunShadowMVP": self.pta_mvp}

    @property
    def produced_pipes(self):
        return {"PSSMSceneSunShadowMapPCF": (self.target.depth_tex, self.make_pcf_state())}

    def make_pcf_state(self):
        state = SamplerState()
        state.set_minfilter(SamplerState.FT_shadow)
        state.set_magfilter(SamplerState.FT_shadow)
        return state

    def request_focus(self, focus_point, focus_size):
        self.focus = (focus_point, focus_size)
        self.last_focus = self.focus

    @property
    def mvp(self):
        return Globals.base.render.get_transform(self.cam_node).get_mat() * \
            self.cam_lens.get_projection_mat()

    def update(self):
        if self._pipeline.task_scheduler.is_scheduled("pssm_scene_shadows"):
            if self.focus is None:
                # When no focus is set, there is no point in rendering the shadow map
                self.target.active = False
            else:
                focus_point, focus_size = self.focus

                self.cam_lens.set_near_far(0.0, 2 * (focus_size + self.sun_distance))
                self.cam_lens.set_film_size(2 * focus_size, 2 * focus_size)
                self.cam_node.set_pos(
                    focus_point + self.sun_vector * (self.sun_distance + focus_size))
                self.cam_node.look_at(focus_point)

                snap_shadow_map(self.mvp, self.cam_node, self.resolution)
                self.target.active = True
                self.pta_mvp[0] = self.mvp

                self.focus = None
        else:
            self.target.active = False

    def create(self):
        self.camera = Camera("PSSMSceneSunShadowCam")
        self.cam_lens = OrthographicLens()
        self.cam_lens.set_film_size(400, 400)
        self.cam_lens.set_near_far(100.0, 1800.0)
        self.camera.set_lens(self.cam_lens)
        self.cam_node = Globals.base.render.attach_new_node(self.camera)

        self.target = self.create_target("ShadowMap")
        self.target.size = self.resolution
        self.target.add_depth_attachment(bits=32)
        self.target.prepare_render(self.cam_node)

        # Register shadow camera
        self._pipeline.tag_mgr.register_camera("shadow", self.camera)

    def set_shader_input(self, *args):
        Globals.render.set_shader_input(*args)

    def set_shader_inputs(self, **kwargs):
        Globals.render.set_shader_inputs(**kwargs)