当前位置: 首页>>代码示例>>Python>>正文


Python OrthographicLens.set_film_size方法代码示例

本文整理汇总了Python中panda3d.core.OrthographicLens.set_film_size方法的典型用法代码示例。如果您正苦于以下问题:Python OrthographicLens.set_film_size方法的具体用法?Python OrthographicLens.set_film_size怎么用?Python OrthographicLens.set_film_size使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在panda3d.core.OrthographicLens的用法示例。


在下文中一共展示了OrthographicLens.set_film_size方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SkyAOCaptureStage

# 需要导入模块: from panda3d.core import OrthographicLens [as 别名]
# 或者: from panda3d.core.OrthographicLens import set_film_size [as 别名]
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")
开发者ID:jakogut,项目名称:RenderPipeline,代码行数:62,代码来源:capture_stage.py

示例2: _make_fullscreen_cam

# 需要导入模块: from panda3d.core import OrthographicLens [as 别名]
# 或者: from panda3d.core.OrthographicLens import set_film_size [as 别名]
 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)
开发者ID:ELMERzark,项目名称:RenderPipeline,代码行数:13,代码来源:post_process_region.py

示例3: PSSMCameraRig

# 需要导入模块: from panda3d.core import OrthographicLens [as 别名]
# 或者: from panda3d.core.OrthographicLens import set_film_size [as 别名]
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
开发者ID:aimoonchen,项目名称:RenderPipeline,代码行数:56,代码来源:pssm_camera_rig.py

示例4: setup_display2

# 需要导入模块: from panda3d.core import OrthographicLens [as 别名]
# 或者: from panda3d.core.OrthographicLens import set_film_size [as 别名]
 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)
开发者ID:codedragon,项目名称:color_world,代码行数:23,代码来源:play_world.py

示例5: PSSMSceneShadowStage

# 需要导入模块: from panda3d.core import OrthographicLens [as 别名]
# 或者: from panda3d.core.OrthographicLens import set_film_size [as 别名]
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)
开发者ID:jakogut,项目名称:RenderPipeline,代码行数:89,代码来源:pssm_scene_shadow_stage.py

示例6: VoxelizationStage

# 需要导入模块: from panda3d.core import OrthographicLens [as 别名]
# 或者: from panda3d.core.OrthographicLens import set_film_size [as 别名]
class VoxelizationStage(RenderStage):

    """ This stage voxelizes the whole scene """

    required_inputs = ["DefaultEnvmap", "AllLightsData", "maxLightIndex"]
    required_pipes = []

    # The different states of voxelization
    S_disabled = 0
    S_voxelize_x = 1
    S_voxelize_y = 2
    S_voxelize_z = 3
    S_gen_mipmaps = 4

    def __init__(self, pipeline):
        RenderStage.__init__(self, pipeline)
        self.voxel_resolution = 256
        self.voxel_world_size = -1
        self.state = self.S_disabled
        self.create_ptas()

    def set_grid_position(self, pos):
        self.pta_next_grid_pos[0] = pos

    def create_ptas(self):
        self.pta_next_grid_pos = PTALVecBase3.empty_array(1)
        self.pta_grid_pos = PTALVecBase3.empty_array(1)

    @property
    def produced_inputs(self):
        return {"voxelGridPosition": self.pta_grid_pos}

    @property
    def produced_pipes(self):
        return {"SceneVoxels": self.voxel_grid}

    def create(self):
        # Create the voxel grid used to generate the voxels
        self.voxel_temp_grid = Image.create_3d(
            "VoxelsTemp", self.voxel_resolution, self.voxel_resolution,
            self.voxel_resolution, "RGBA8")
        self.voxel_temp_grid.set_clear_color(Vec4(0))
        self.voxel_temp_nrm_grid = Image.create_3d(
            "VoxelsTemp", self.voxel_resolution, self.voxel_resolution,
            self.voxel_resolution, "R11G11B10")
        self.voxel_temp_nrm_grid.set_clear_color(Vec4(0))

        # Create the voxel grid which is a copy of the temporary grid, but stable
        self.voxel_grid = Image.create_3d(
            "Voxels", self.voxel_resolution, self.voxel_resolution, self.voxel_resolution, "RGBA8")
        self.voxel_grid.set_clear_color(Vec4(0))
        self.voxel_grid.set_minfilter(SamplerState.FT_linear_mipmap_linear)

        # 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(
            -2.0 * self.voxel_world_size, 2.0 * self.voxel_world_size)
        self.voxel_cam_lens.set_near_far(0.0, 2.0 * self.voxel_world_size)
        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_camera("voxelize", self.voxel_cam)

        # Create the voxelization target
        self.voxel_target = self.create_target("VoxelizeScene")
        self.voxel_target.size = self.voxel_resolution
        self.voxel_target.prepare_render(self.voxel_cam_np)

        # Create the target which copies the voxel grid
        self.copy_target = self.create_target("CopyVoxels")
        self.copy_target.size = self.voxel_resolution
        self.copy_target.prepare_buffer()

        # TODO! Does not work with the new render target yet - maybe add option
        # to post process region for instances?
        self.copy_target.instance_count = self.voxel_resolution
        self.copy_target.set_shader_input("SourceTex", self.voxel_temp_grid)
        self.copy_target.set_shader_input("DestTex", self.voxel_grid)

        # Create the target which generates the mipmaps
        self.mip_targets = []
        mip_size, mip = self.voxel_resolution, 0
        while mip_size > 1:
            mip_size, mip = mip_size // 2, mip + 1
            mip_target = self.create_target("GenMipmaps:" + str(mip))
            mip_target.size = mip_size
            mip_target.prepare_buffer()
            mip_target.instance_count = mip_size
            mip_target.set_shader_input("SourceTex", self.voxel_grid)
            mip_target.set_shader_input("sourceMip", mip - 1)
            mip_target.set_shader_input("DestTex", self.voxel_grid, False, True, -1, mip, 0)
            self.mip_targets.append(mip_target)

        # Create the initial state used for rendering voxels
        initial_state = NodePath("VXGIInitialState")
        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())
#.........这里部分代码省略.........
开发者ID:croxis,项目名称:SpaceDrive,代码行数:103,代码来源:voxelization_stage.py

示例7: VoxelizationStage

# 需要导入模块: from panda3d.core import OrthographicLens [as 别名]
# 或者: from panda3d.core.OrthographicLens import set_film_size [as 别名]
class VoxelizationStage(RenderStage):

    """ This stage voxelizes the whole scene """

    required_inputs = []
    required_pipes = []

    # The different states of voxelization
    S_disabled = 0
    S_voxelize_x = 1
    S_voxelize_y = 2
    S_voxelize_z = 3
    S_gen_mipmaps = 4

    def __init__(self, pipeline):
        RenderStage.__init__(self, "VoxelizationStage", pipeline)
        self._voxel_res = 256
        self._voxel_ws = 50.0
        self._next_grid_position = Vec3(0)
        self._state = self.S_disabled
        self._create_ptas()

    def set_state(self, state):
        self._state = state

    def set_grid_position(self, pos):
        self._next_grid_position = pos

    def _create_ptas(self):
        self._pta_grid_pos = PTALVecBase3.empty_array(1)
        self._pta_grid_size = PTAFloat.empty_array(1)
        self._pta_grid_res = PTAInt.empty_array(1)
        self._pta_grid_size[0] = self._voxel_ws
        self._pta_grid_res[0] = self._voxel_res

    def get_produced_inputs(self):
        return {"VoxelGridPosition": self._pta_grid_pos}

    def get_produced_pipes(self):
        return {"SceneVoxels": self._voxel_grid}

    def get_produced_defines(self):
        return {"VOXEL_GRID_RES": self._voxel_res, "VOXEL_GRID_WS_SIZE": self._voxel_ws}

    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)

    def update(self):
        self._voxel_cam_np.show()
        self._voxel_target.set_active(True)

        # Voxelization disable
        if self._state == self.S_disabled:
            self._voxel_cam_np.hide()
            self._voxel_target.set_active(False)

        # Voxelization from X-Axis
        elif self._state == self.S_voxelize_x:
            self._voxel_cam_np.set_pos(self._next_grid_position + Vec3(self._voxel_ws, 0, 0))
            self._voxel_cam_np.look_at(self._next_grid_position)

        # Voxelization from Y-Axis
        elif self._state == self.S_voxelize_y:
            self._voxel_cam_np.set_pos(self._next_grid_position + Vec3(0, self._voxel_ws, 0))
            self._voxel_cam_np.look_at(self._next_grid_position)

        # Voxelization from Z-Axis
#.........这里部分代码省略.........
开发者ID:MYheavyGo,项目名称:RenderPipeline,代码行数:103,代码来源:VoxelizationStage.py

示例8: PSSMDistShadowStage

# 需要导入模块: from panda3d.core import OrthographicLens [as 别名]
# 或者: from panda3d.core.OrthographicLens import set_film_size [as 别名]
class PSSMDistShadowStage(RenderStage):

    """ This stage generates a depth map using Variance Shadow Maps for very
    distant objects. """

    required_inputs = []

    def __init__(self, pipeline):
        RenderStage.__init__(self, pipeline)
        self.resolution = 2048
        self.clip_size = 500
        self.sun_distance = 8000
        self.sun_vector = Vec3(0, 0, 1)
        self.pta_mvp = PTAMat4.empty_array(1)

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

    @property
    def produced_pipes(self):
        return {"PSSMDistSunShadowMap": self.target_blur_h.color_tex}

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

    def update(self):
        self.target.active = False
        self.target_convert.active = False
        self.target_blur_v.active = False
        self.target_blur_h.active = False

        # Query scheduled tasks
        if self._pipeline.task_scheduler.is_scheduled("pssm_distant_shadows"):

            self.target.active = True

            # Reposition camera before we capture the scene
            cam_pos = Globals.base.cam.get_pos(Globals.base.render)
            self.cam_node.set_pos(cam_pos + self.sun_vector * self.sun_distance)
            self.cam_node.look_at(cam_pos)
            self.cam_lens.set_film_size(self.clip_size, self.clip_size)

            snap_shadow_map(self.mvp, self.cam_node, self.resolution)

        if self._pipeline.task_scheduler.is_scheduled("pssm_convert_distant_to_esm"):
            self.target_convert.active = True
        if self._pipeline.task_scheduler.is_scheduled("pssm_blur_distant_vert"):
            self.target_blur_v.active = True
        if self._pipeline.task_scheduler.is_scheduled("pssm_blur_distant_horiz"):
            self.target_blur_h.active = True

            # Only update the MVP as soon as the shadow map is available
            self.pta_mvp[0] = self.mvp

    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)

    def reload_shaders(self):
        self.target_convert.shader = self.load_plugin_shader("convert_to_esm.frag.glsl")
        self.target_blur_v.shader = self.load_plugin_shader("blur_esm.frag.glsl")
        self.target_blur_h.shader = self.load_plugin_shader("blur_esm.frag.glsl")

    def set_shader_input(self, *args):
        Globals.render.set_shader_input(*args)
开发者ID:croxis,项目名称:SpaceDrive,代码行数:102,代码来源:pssm_dist_shadow_stage.py

示例9: PSSMSceneShadowStage

# 需要导入模块: from panda3d.core import OrthographicLens [as 别名]
# 或者: from panda3d.core.OrthographicLens import set_film_size [as 别名]
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.pta_mvp = PTAMat4.empty_array(1)

    @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

    @property
    def sun_vector(self):
        return self._sun_vector

    @sun_vector.setter
    def sun_vector(self, direction):
        self._sun_vector = direction

        distance = 400.0
        cam_pos = Globals.base.cam.get_pos(Globals.base.render)
        self.cam_node.set_pos(cam_pos + self._sun_vector * distance)
        self.cam_node.look_at(cam_pos)

        # This snaps the source to its texel grids, so that there is no flickering
        # visible when the source moves. This works by projecting the
        # Point (0,0,0) to light space, compute the texcoord differences and
        # offset the light world space position by that.
        mvp = Mat4(self.mvp)
        base_point = mvp.xform(Point4(0, 0, 0, 1)) * 0.5 + 0.5
        texel_size = 1.0 / float(self.resolution)
        offset_x = base_point.x % texel_size
        offset_y = base_point.y % texel_size
        mvp.invert_in_place()
        new_base = mvp.xform(Point4(
            (base_point.x - offset_x) * 2.0 - 1.0,
            (base_point.y - offset_y) * 2.0 - 1.0,
            (base_point.z) * 2.0 - 1.0, 1))
        self.cam_node.set_pos(self.cam_node.get_pos() - Vec3(new_base.x, new_base.y, new_base.z))
        self.pta_mvp[0] = self.mvp

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

    def create(self):

        self.camera = Camera("PSSMSceneSunShadowCam")
        self.cam_lens = OrthographicLens()
        self.cam_lens.set_film_size(200, 200)
        self.cam_lens.set_near_far(100.0, 800.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_shadow_camera(self.camera)

    def set_shader_input(self, *args):
        Globals.render.set_shader_input(*args)
开发者ID:aimoonchen,项目名称:RenderPipeline,代码行数:86,代码来源:pssm_scene_shadow_stage.py

示例10: VXGISunShadowStage

# 需要导入模块: from panda3d.core import OrthographicLens [as 别名]
# 或者: from panda3d.core.OrthographicLens import set_film_size [as 别名]
class VXGISunShadowStage(RenderStage):

    """ This stage creates the shadow map which covers the whole voxel grid,
    to provide sun shadows for the GI """

    required_inputs = []

    def __init__(self, pipeline):
        RenderStage.__init__(self, "VXGISunShadowStage", pipeline)
        self._resolution = 2048
        self._sun_vector = Vec3(0, 0, 1)
        self._pta_mvp = PTAMat4.empty_array(1)

    def get_produced_inputs(self):
        return {"VXGISunShadowMVP": self._pta_mvp}

    def get_produced_pipes(self):
        return {"VXGISunShadowMap": (self._target['depth'], 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 set_resolution(self, res):
        self._resolution = res

    def set_sun_vector(self, direction):
        self._sun_vector = direction

        distance = 400.0
        cam_pos = Globals.base.cam.get_pos(Globals.base.render)
        self._cam_node.set_pos(cam_pos + self._sun_vector * distance)
        self._cam_node.look_at(cam_pos)

        # Compute MVP
        transform = Globals.base.render.get_transform(self._cam_node).get_mat()
        self._pta_mvp[0] = transform * self._cam_lens.get_projection_mat()

    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)

    def set_shader_input(self, *args):
        Globals.render.set_shader_input(*args)
开发者ID:wdmwdm,项目名称:RenderPipeline,代码行数:64,代码来源:VXGISunShadowStage.py

示例11: PSSMSceneShadowStage

# 需要导入模块: from panda3d.core import OrthographicLens [as 别名]
# 或者: from panda3d.core.OrthographicLens import set_film_size [as 别名]
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.pta_mvp = PTAMat4.empty_array(1)

    @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

    @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"):
            cam_pos = Globals.base.cam.get_pos(Globals.base.render)
            self.cam_node.set_pos(cam_pos + self.sun_vector * 900)
            self.cam_node.look_at(cam_pos)

            snap_shadow_map(self.mvp, self.cam_node, self.resolution)

            self.target.active = True
            self.pta_mvp[0] = self.mvp
        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_shadow_camera(self.camera)

    def set_shader_input(self, *args):
        Globals.render.set_shader_input(*args)
开发者ID:gitter-badger,项目名称:RenderPipeline,代码行数:67,代码来源:pssm_scene_shadow_stage.py


注:本文中的panda3d.core.OrthographicLens.set_film_size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。