Esempio n. 1
0
    def shader(self, value):
        self._shader = value
        if value is None:
            self.filter_manager.cleanup()
            self.filter_manager = None
            if self.filter_quad:
                self.filter_quad.removeNode()
                # print('removed shader')
            return None

        shader = value
        if hasattr(value, '_shader'):
            shader = value._shader

        if not self.filter_manager:
            self.filter_manager = FilterManager(base.win, base.cam)
            self.render_texture = PandaTexture()
            self.depth_texture = PandaTexture()
            self.normals_texture = PandaTexture()
            self.filter_quad = self.filter_manager.renderSceneInto(
                colortex=self.render_texture, depthtex=self.depth_texture)
            # from panda3d.core import AuxBitplaneAttrib
            # self.filter_quad = self.filter_manager.renderSceneInto(colortex=self.render_texture, depthtex=self.depth_texture, auxtex=self.normal_texture, auxbits=AuxBitplaneAttrib.ABOAuxNormal)
            self.filter_quad.setShaderInput("tex", self.render_texture)
            self.filter_quad.setShaderInput("dtex", self.depth_texture)
            # self.filter_quad.setShaderInput("ntex", self.normals_texture)

        self.filter_quad.setShader(shader)

        if hasattr(value, 'default_input'):
            for key, value in value.default_input.items():
                self.set_shader_input(key, value)

        print('set camera shader to:', shader)
Esempio n. 2
0
 def reset(self):
     self.manager.cleanup()
     self.filter_tex = {}
     self.manager = FilterManager(base.win, base.cam)
     self.filters = {}
     self.window_x = float(base.win.getXSize())
     self.window_y = float(base.win.getYSize())
Esempio n. 3
0
    def __init__(self, base):
        # Load shader sources to avoid model path problems
        for src_set in all_shader_sources:
            for i, filename in enumerate(src_set):
                with open(filename, 'r') as fin:
                    src_set[i] = fin.read()

        base.render.set_shader_auto()
        base.render.set_attrib(p3d.LightRampAttrib.make_identity())
        pbr_shader = p3d.Shader.make(p3d.Shader.SL_GLSL, *material_shader_sources)
        base.render.set_shader(pbr_shader)

        manager = FilterManager(base.win, base.cam)
        aa_tex = p3d.Texture()
        self.post_tex = p3d.Texture()
        self.post_tex.set_component_type(p3d.Texture.T_float)
        aa_quad = manager.renderSceneInto(colortex=self.post_tex)
        post_quad = manager.renderQuadInto(colortex=aa_tex)

        aa_quad.set_shader(p3d.Shader.make(p3d.Shader.SL_GLSL, *antialias_shader_sources))
        aa_quad.set_shader_input('source', aa_tex)
        aa_quad.set_shader_input('viewport', base.win.get_size())

        post_quad.set_shader(p3d.Shader.make(p3d.Shader.SL_GLSL, *post_shader_sources))
        post_quad.set_shader_input('tex', self.post_tex)
Esempio n. 4
0
    def shader(self, value):
        if value is None:
            if self.filter_quad:
                self.filter_quad.removeNode()
            return None

        self._shader = value
        shader = value
        if hasattr(value, '_shader'):
            shader = value._shader

        if not self.filter_manager:
            self.filter_manager = FilterManager(base.win, base.cam)
            self.render_texture = PandaTexture()
            self.depth_texture = PandaTexture()
            self.filter_quad = self.filter_manager.renderSceneInto(
                colortex=self.render_texture, depthtex=self.depth_texture)
            self.filter_quad.setShaderInput("tex", self.render_texture)
            self.filter_quad.setShaderInput("dtex", self.depth_texture)

        self.filter_quad.setShader(shader)

        if hasattr(value, 'default_input'):
            for key, value in value.default_input.items():
                self.set_shader_input(key, value)

        print('set camera shader to:', shader)
Esempio n. 5
0
    def setup_shaders(self, render_node):
        shader_dir = os.path.dirname(__file__)

        # Do not force power-of-two textures
        p3d.Texture.set_textures_power_2(p3d.ATS_none)

        # PBR shader
        pbrshader = p3d.Shader.load(
            p3d.Shader.SL_GLSL,
            vertex=os.path.join(shader_dir, 'simplepbr.vert'),
            fragment=os.path.join(shader_dir, 'simplepbr.frag')
        )
        render_node.set_shader(pbrshader)

        # Tonemapping
        manager = FilterManager(base.win, base.cam)
        tonemap_tex = p3d.Texture()
        tonemap_tex.set_component_type(p3d.Texture.T_float)
        tonemap_quad = manager.render_scene_into(colortex=tonemap_tex)
        tonemap_shader = p3d.Shader.load(
            p3d.Shader.SL_GLSL,
            vertex=os.path.join(shader_dir, 'post.vert'),
            fragment=os.path.join(shader_dir, 'tonemap.frag')
        )
        tonemap_quad.set_shader(tonemap_shader)
        tonemap_quad.set_shader_input('tex', tonemap_tex)
Esempio n. 6
0
        def resetup_tonemap():
            # Destroy previous buffers so we can re-create
            self.manager.cleanup()

            # Create a new FilterManager instance
            self.manager = FilterManager(self.window, self.camera_node)
            self._setup_tonemapping()
Esempio n. 7
0
    def __init__(self, base):
        # Load shader sources to avoid model path problems
        for src_set in all_shader_sources:
            for i, filename in enumerate(src_set):
                with open(filename, 'r') as fin:
                    src_set[i] = fin.read()

        base.render.set_shader_auto()
        base.render.set_attrib(p3d.LightRampAttrib.make_identity())
        pbr_shader = p3d.Shader.make(p3d.Shader.SL_GLSL, *material_shader_sources)
        base.render.set_shader(pbr_shader)

        manager = FilterManager(base.win, base.cam)
        aa_tex = p3d.Texture()
        self.post_tex = p3d.Texture()
        self.post_tex.set_component_type(p3d.Texture.T_float)
        aa_quad = manager.renderSceneInto(colortex=self.post_tex)
        post_quad = manager.renderQuadInto(colortex=aa_tex)

        aa_quad.set_shader(p3d.Shader.make(p3d.Shader.SL_GLSL, *antialias_shader_sources))
        aa_quad.set_shader_input('source', aa_tex)
        aa_quad.set_shader_input('viewport', base.win.get_size())

        post_quad.set_shader(p3d.Shader.make(p3d.Shader.SL_GLSL, *post_shader_sources))
        post_quad.set_shader_input('tex', self.post_tex)
Esempio n. 8
0
    def __init__(self):
        self.filter_tex = {}
        self.manager = FilterManager(base.win, base.cam)
        self.filters = {}

        self.window_x = float(base.win.getXSize())
        self.window_y = float(base.win.getYSize())
Esempio n. 9
0
    def enable(self):
        '''
        Enables the filter. It is assumed that after this operation the rendering operation
        has been altered such that the filter effects will be visible. 
        '''
        if self.isEnabled():
            return

        shader = self.game.getResources().loadShader(self.shader)
        if shader is not None:
            self.postProcess = FilterManager(
                self.game.getView().getWindow(),
                self.game.getView().panoRenderer.getCamera())
            self.postProcess.windowEvent(self.game.getView().getWindow(
            ))  # auto resize buffers when window resizes
            tex = Texture()
            self.screenQuad = self.postProcess.renderSceneInto(colortex=tex)
            self.screenQuad.setShader(shader)
            self.screenQuad.setShaderInput("tex", tex)
            self._applyShaderInputs()
            self.enabled = True
        else:
            self.log.error(
                'failed to set screen filter BlackAndWhite because shader %s was not found'
                % self.shader)
Esempio n. 10
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)  # call in window instead
        # 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.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_x=self.aspect_ratio,
                              color=color.clear,
                              eternal=True,
                              z=-99)

        self.filter_manager = FilterManager(base.win, base.cam)
        self.render_texture = PandaTexture()
        self.filter_quad = None
Esempio n. 11
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
Esempio n. 12
0
 def setup_post_effect(self):
     self.manager = FilterManager(base.win, base.cam)
     tex = Texture()
     dtex = Texture()
     quad = self.manager.renderSceneInto(colortex=tex, depthtex=dtex)
     quad.setShader(
         Shader.load(Shader.SL_GLSL, "vertex.glsl", "fragment.glsl"))
     quad.setShaderInput("tex", tex)
     quad.setShaderInput("dtex", dtex)
Esempio n. 13
0
 def setup_post_effect(self):
     self.manager = FilterManager(base.win, base.cam2d)
     tex = Texture()
     #tex = loader.load_texture("assets/noise.png")
     self.quad = self.manager.renderSceneInto(colortex=tex)
     self.quad.setShader(Shader.load(Shader.SL_GLSL, "crt.vert","crt.frag"))
     self.quad.setShaderInput("iResolution", (base.win.getXSize(), base.win.getYSize()))
     self.quad.setShaderInput("pattern", base.loader.load_texture("assets/crt.png"))
     self.quad.get_texture().set_wrap_u(SamplerState.WM_clamp)
     self.quad.get_texture().set_wrap_v(SamplerState.WM_clamp)
     base.accept("window-event", self.on_window_event)
 def __init__(self):
     ShowBase.__init__(self)
     depth = Texture("depth")
     depth.setWrapU(Texture.WMClamp)
     depth.setWrapV(Texture.WMClamp)
     self.fmgr = FilterManager(self.win, self.cam)
     depthQuad = self.fmgr.renderQuadInto(depthtex=depth)
     #depthQuad.hide()
     smiley = loader.loadModel("models/smiley.egg.pz")
     smiley.reparentTo(render)
     img = OnscreenImage(image=depth, scale=0.3, pos=(0, 0, -0.7))
Esempio n. 15
0
File: filters.py Progetto: wezu/a4p
 def reset(self):
     self.manager.cleanup()
     self.filter_tex={}
     self.manager=FilterManager(base.win, base.cam)
     self.filters={}
     self.window_x=float(base.win.getXSize())
     self.window_y=float(base.win.getYSize())
     if cfg['glsl-blur'] or cfg['glsl-distortion'] or cfg['glsl-flare'] or cfg['glsl-glare'] or cfg['glsl-lut']:
         self.setupFilters()
     elif cfg['use-fxaa']:
         self.setupFxaa()
Esempio n. 16
0
def check_and_create_rendering_buffers(showbase):
    if not settings.render_scene_to_buffer:
        return

    if not settings.buffer_texture:
        print("Render to buffer not supported")
        return

    print("Render scene to buffer")

    buffer_multisamples = 0
    if settings.render_scene_to_buffer and not settings.disable_multisampling and settings.use_multisampling and settings.multisamples > 0:
        buffer_multisamples = settings.multisamples

    manager = FilterManager(showbase.win, showbase.cam)
    color_buffer = Texture()
    if settings.use_inverse_z:
        render.set_attrib(DepthTestAttrib.make(DepthTestAttrib.M_greater))
        depth_buffer = Texture()
        showbase.win.set_clear_depth(0)
        float_depth = True
        depth_bits = 24
    else:
        depth_buffer = None
        float_depth = False
        depth_bits = 1
    if settings.render_scene_to_float:
        if settings.floating_point_buffer:
            rgba_bits = (32, 32, 32, 32)
            float_colors = True
        else:
            print(
                "Floating point buffer not available, sRBG conversion will show artifacts"
            )
            rgba_bits = (1, 1, 1, 1)
            float_colors = False
    else:
        rgba_bits = (1, 1, 1, 1)
        float_colors = False
    textures = {'color': color_buffer, 'depth': depth_buffer}
    fbprops = FrameBufferProperties()
    fbprops.setFloatColor(float_colors)
    fbprops.setRgbaBits(*rgba_bits)
    fbprops.setSrgbColor(settings.srgb_buffer)
    fbprops.setDepthBits(depth_bits)
    fbprops.setFloatDepth(float_depth)
    fbprops.setMultisamples(buffer_multisamples)
    final_quad = manager.render_scene_into(textures=textures, fbprops=fbprops)
    final_quad_shader = PostProcessShader(
        gamma_correction=settings.software_srgb,
        hdr=settings.use_hdr).create_shader()
    final_quad.set_shader(final_quad_shader)
    final_quad.set_shader_input("color_buffer", color_buffer)
    final_quad.set_shader_input("exposure", 2)
Esempio n. 17
0
    def __init__(self, base):
        self.base = base
        self.base.render.set_shader_auto()

        p3d.Texture.setTexturesPower2(p3d.ATS_none)

        manager = FilterManager(base.win, base.cam)
        self.post_tex = p3d.Texture()
        post_quad = manager.renderSceneInto(colortex=self.post_tex)
        post_quad.set_shader(
            p3d.Shader.make(p3d.Shader.SL_GLSL, _SRGB_VERT, _SRGB_FRAG))
        post_quad.set_shader_input('tex', self.post_tex)
Esempio n. 18
0
    def __init__(self):
        ShowBase.__init__(self)
        manager = FilterManager(base.win, base.cam)
        tex = Texture()
        quad = manager.renderSceneInto(colortex=tex)
        quad.setShader(Shader.load("myfilter.sha"))
        quad.setShaderInput("tex", tex)
 
        # Disable the camera trackball controls.
        self.disableMouse()
 
        # Load the environment model.
        self.environ = self.loader.loadModel("models/environment")
        # Reparent the model to render.
        self.environ.reparentTo(self.render)
        # Apply scale and position transforms on the model.
        self.environ.setScale(0.25, 0.25, 0.25)
        self.environ.setPos(-8, 42, 0)
 
        # Add the spinCameraTask procedure to the task manager.
        self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
 
        # Load and transform the panda actor.
        self.pandaActor = Actor("models/panda-model",
                                {"walk": "models/panda-walk4"})
        self.pandaActor.setScale(0.005, 0.005, 0.005)
        self.pandaActor.reparentTo(self.render)
        # Loop its animation.
        self.pandaActor.loop("walk")
 
        # Create the four lerp intervals needed for the panda to
        # walk back and forth.
        pandaPosInterval1 = self.pandaActor.posInterval(13,
                                                        Point3(0, -10, 0),
                                                        startPos=Point3(0, 10, 0))
        pandaPosInterval2 = self.pandaActor.posInterval(13,
                                                        Point3(0, 10, 0),
                                                        startPos=Point3(0, -10, 0))
        pandaHprInterval1 = self.pandaActor.hprInterval(3,
                                                        Point3(180, 0, 0),
                                                        startHpr=Point3(0, 0, 0))
        pandaHprInterval2 = self.pandaActor.hprInterval(3,
                                                        Point3(0, 0, 0),
                                                        startHpr=Point3(180, 0, 0))
 
        # Create and play the sequence that coordinates the intervals.
        self.pandaPace = Sequence(pandaPosInterval1,
                                  pandaHprInterval1,
                                  pandaPosInterval2,
                                  pandaHprInterval2,
                                  name="pandaPace")
        self.pandaPace.loop()
Esempio n. 19
0
    def __init__(self, base):
        import panda3d.core as p3d
        from direct.filter.FilterManager import FilterManager

        self.base = base
        self.base.render.set_shader_auto()

        manager = FilterManager(base.win, base.cam)
        self.post_tex = p3d.Texture()
        post_quad = manager.renderSceneInto(colortex=self.post_tex)
        post_quad.set_shader(
            p3d.Shader.make(p3d.Shader.SL_GLSL, _srgb_vert, _srgb_frag))
        post_quad.set_shader_input('tex', self.post_tex)
Esempio n. 20
0
File: filters.py Progetto: wezu/a4p
    def __init__(self):
        self.filter_tex={}
        self.manager=FilterManager(base.win, base.cam)
        self.filters={}

        self.window_x=float(base.win.getXSize())
        self.window_y=float(base.win.getYSize())
        render.setShaderInput('screen_size',Vec2(self.window_x,self.window_y))
        log.debug('Filters: FilterManager started at '+str(base.win.getXSize())+'x'+str(base.win.getYSize()))
        if cfg['use-filters']:
            self.setupFilters()
        elif cfg['use-fxaa']:
            self.setupFxaa()
Esempio n. 21
0
    def __init__(self,
                 *,
                 render_node=None,
                 window=None,
                 camera_node=None,
                 msaa_samples=4,
                 max_lights=8,
                 use_normal_maps=False,
                 use_emission_maps=False,
                 exposure=1.0,
                 enable_shadows=False,
                 enable_fog=False,
                 use_occlusion_maps=False):
        if render_node is None:
            render_node = base.render

        if window is None:
            window = base.win

        if camera_node is None:
            camera_node = base.cam

        self._shader_ready = False
        self.render_node = render_node
        self.window = window
        self.camera_node = camera_node
        self.max_lights = max_lights
        self.use_normal_maps = use_normal_maps
        self.use_emission_maps = use_emission_maps
        self.enable_shadows = enable_shadows
        self.enable_fog = enable_fog
        self.exposure = exposure
        self.msaa_samples = msaa_samples
        self.use_occlusion_maps = use_occlusion_maps

        # Create a FilterManager instance
        self.manager = FilterManager(window, camera_node)

        # Do not force power-of-two textures
        p3d.Texture.set_textures_power_2(p3d.ATS_none)

        # Make sure we have AA for if/when MSAA is enabled
        self.render_node.set_antialias(p3d.AntialiasAttrib.M_auto)

        # PBR Shader
        self._recompile_pbr()

        # Tonemapping
        self._setup_tonemapping()

        self._shader_ready = True
Esempio n. 22
0
    def __init__(self):
        ShowBase.__init__(self)
        self.render.setAntialias(AntialiasAttrib.MMultisample, 1)

        model = self.loader.loadModel("models/panda")
        model.reparent_to(self.render)
        self.cam.set_pos(50, 50, 0)
        self.cam.look_at(model)

        self._manager = FilterManager(self.win, self.cam)
        tex = Texture()
        self.quad = self._manager.renderSceneInto(colortex=tex)
        self.quad.setShader(Shader.load("./mono.sha"))
        self.quad.setShaderInput("tex", tex)
Esempio n. 23
0
    def __init__(self, base):

        base.render.set_shader_auto()
        base.render.set_attrib(p3d.LightRampAttrib.make_identity())
        pbr_shader = p3d.Shader.make(p3d.Shader.SL_GLSL, pbr_vert, pbr_frag)
        base.render.set_shader(pbr_shader)

        manager = FilterManager(base.win, base.cam)
        tex = p3d.Texture()
        quad = manager.renderSceneInto(colortex=tex)
        quad.set_shader(p3d.Shader.make(p3d.Shader.SL_GLSL, hdr_vert,
                                        hdr_frag))
        quad.set_shader_input('tex', tex)

        self.base = base
Esempio n. 24
0
 def reset(self):
     self.manager.cleanup()
     self.filter_tex={}        
     self.manager=FilterManager(base.win, base.cam)
     self.filters={}        
     self.window_x=float(base.win.getXSize())
     self.window_y=float(base.win.getYSize())
Esempio n. 25
0
 def __init__(self):
     self.filter_tex={}        
     self.manager=FilterManager(base.win, base.cam)
     self.filters={}
     
     self.window_x=float(base.win.getXSize())
     self.window_y=float(base.win.getYSize())
Esempio n. 26
0
def makeFXAA(manager=None, span_max=8.0, reduce_mul=8.0, subpixel_shift=4.0):
    wp=base.win.getProperties()
    winX = wp.getXSize()
    winY = wp.getYSize()
    tex = Texture()
    if manager==None:
        manager = FilterManager(base.win, base.cam)
    quad = manager.renderSceneInto(colortex=tex)
    quad.setShader(Shader.load(Shader.SLGLSL, "shaders/fxaa_v.glsl", "shaders/fxaa_f.glsl"))
    quad.setShaderInput("tex0", tex)
    quad.setShaderInput("rt_w",winX)
    quad.setShaderInput("rt_h",winY)
    quad.setShaderInput("FXAA_SPAN_MAX" , float(span_max))
    quad.setShaderInput("FXAA_REDUCE_MUL", float(1.0/reduce_mul))
    quad.setShaderInput("FXAA_SUBPIX_SHIFT", float(1.0/subpixel_shift))
    return manager
Esempio n. 27
0
    def __init__(self):
        self.manager = FilterManager(base.win, base.cam)

        # Gonna use a Tuple for now
        # This list should be stored somewhere else ultimately, probably like in a globals file
        # [Friendly LUT Name, LUT Filepath]
        self.LUTList = (
            ["Default", "phase_3/luts/def_lut.png"],
            ["LSD", "phase_3/luts/lsd_lut.png"],
            ["Sunset", "phase_3/luts/sunset_lut.png"],
            ["Natural Pop", "phase_3/luts/pop_lut.png"],
            ["Red+Black", "phase_3/luts/2_lut.png"]
        )
        self.vertexShader = "phase_3/shaders/lut-vert.glsl"
        self.fragmentShader = "phase_3/shaders/lut-frag.glsl"
        self.setupLUT(self.LUTList[0][1])
Esempio n. 28
0
class PostEffect(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        self.disableMouse()
        base.setFrameRateMeter(True)
        self.accept("escape", sys.exit)
        self.setup_scene()
        self.setup_post_effect() 

    def setup_scene(self):
        # Environment
        self.environ = self.loader.loadModel("models/environment")
        self.environ.reparentTo(self.render)
        self.environ.set_scale(0.25)
        self.environ.set_pos(-8, 42, 0)
        # Camera
        self.taskMgr.add(self.spinCameraTask, "SpinCameraTask")
        # Panda
        self.pandaActor = Actor("models/panda-model",
                                {"walk": "models/panda-walk4"})
        self.pandaActor.setScale(0.005, 0.005, 0.005)
        self.pandaActor.reparentTo(self.render)
        self.pandaActor.loop("walk")
        pandaPosInterval1 = self.pandaActor.posInterval(13,
                                                        Point3(0, -10, 0),
                                                        startPos=Point3(0, 10, 0))
        pandaPosInterval2 = self.pandaActor.posInterval(13,
                                                        Point3(0, 10, 0),
                                                        startPos=Point3(0, -10, 0))
        pandaHprInterval1 = self.pandaActor.hprInterval(3,
                                                        Point3(180, 0, 0),
                                                        startHpr=Point3(0, 0, 0))
        pandaHprInterval2 = self.pandaActor.hprInterval(3,
                                                        Point3(0, 0, 0),
                                                        startHpr=Point3(180, 0, 0))
        self.panda_pace = Sequence(pandaPosInterval1,
                                  pandaHprInterval1,
                                  pandaPosInterval2,
                                  pandaHprInterval2,
                                  name="pandaPace")
        self.panda_pace.loop()

    # The post-processing effect is set up here.
    def setup_post_effect(self):
        self.manager = FilterManager(base.win, base.cam)
        tex = Texture()
        dtex = Texture()
        quad = self.manager.renderSceneInto(colortex=tex, depthtex=dtex)
        quad.setShader(Shader.load(Shader.SL_GLSL, "vertex.glsl", "fragment.glsl"))
        quad.setShaderInput("tex", tex)
        quad.setShaderInput("dtex", dtex)
 
    # Define a procedure to move the camera.
    def spinCameraTask(self, task):
        angleDegrees = task.time * 6.0
        angleRadians = angleDegrees * (pi / 180.0)
        self.camera.setPos(20 * sin(angleRadians), -20.0 * cos(angleRadians), 3)
        self.camera.setHpr(angleDegrees, 0, 0)
        return Task.cont
Esempio n. 29
0
 def setup_post_fx(self):
     self.filter_mgr = FilterManager(base.win, base.cam)
     col_tex = Texture()
     final_tex = Texture()
     final_quad = self.filter_mgr.renderSceneInto(colortex=col_tex)
     inter_quad = self.filter_mgr.renderQuadInto(colortex=final_tex)
     with open('yyagl/assets/shaders/filter.vert') as f:
         vert = f.read()
     with open('yyagl/assets/shaders/filter.frag') as f:
         frag = f.read()
     inter_quad.setShader(Shader.make(Shader.SLGLSL, vert, frag))
     inter_quad.setShaderInput('in_tex', col_tex)
     with open('yyagl/assets/shaders/pass.frag') as f:
         frag = f.read()
     final_quad.setShader(Shader.make(Shader.SLGLSL, vert, frag))
     final_quad.set_shader_input('gamma', self.gamma)
     final_quad.setShaderInput('in_tex', final_tex)
Esempio n. 30
0
 def setup_post_effect(self):
     self.manager = FilterManager(base.win, base.cam)
     tex = Texture()
     dtex = Texture()
     quad = self.manager.renderSceneInto(colortex=tex, depthtex=dtex)
     quad.setShader(Shader.load(Shader.SL_GLSL, "vertex.glsl", "fragment.glsl"))
     quad.setShaderInput("tex", tex)
     quad.setShaderInput("dtex", dtex)
Esempio n. 31
0
    def __init__(self):
        if DConfig.GetBool('textures-power-2', 1):
            # This is a workaround, if ^ is enabled, the game would only render in the bottom left corner of the window.
            self.notify.warning(
                "Cannot be initialized with texture-power-2 config enabled.")
            return
        """
        The FilterManager constructor requires you to provide a window which is rendering a scene,
        and the camera which is used by that window to render the scene.
        These are henceforth called the 'original window' and the 'original camera.'

        At the very moment ShaderManager only supports postprocessing shaders, which may be the reason why 2d gui is wonky w/ shaders.
        It seems that FilterManager is used for post processing shaders...?
        """
        self.manager = FilterManager(base.win, base.cam)
        # self.manager2d = None
        self.manager2d = FilterManager(base.win, base.cam2d)
        self.notify.info("Initialized ShaderManager")
Esempio n. 32
0
class ToontownLUTManager():
    def __init__(self):
        self.manager = FilterManager(base.win, base.cam)

        # Gonna use a Tuple for now
        # This list should be stored somewhere else ultimately, probably like in a globals file
        # [Friendly LUT Name, LUT Filepath]
        self.LUTList = (
            ["Default", "phase_3/luts/def_lut.png"],
            ["LSD", "phase_3/luts/lsd_lut.png"],
            ["Sunset", "phase_3/luts/sunset_lut.png"],
            ["Natural Pop", "phase_3/luts/pop_lut.png"],
            ["Red+Black", "phase_3/luts/2_lut.png"]
        )
        self.vertexShader = "phase_3/shaders/lut-vert.glsl"
        self.fragmentShader = "phase_3/shaders/lut-frag.glsl"
        self.setupLUT(self.LUTList[0][1])

    def setupLUT(self, lut_file):
        colortex = Texture()
        self.quad = self.manager.renderSceneInto(colortex = colortex)
        self.quad.setShader(Shader.load(Shader.SLGLSL, self.vertexShader, self.fragmentShader))
        self.quad.setShaderInput("colortex", colortex)
        lut = loader.loadTexture(lut_file)
        lut.setFormat(Texture.F_rgb16)
        lut.setWrapU(Texture.WMClamp)
        lut.setWrapV(Texture.WMClamp)
        self.quad.setShaderInput("lut", lut)

    def loadTUL(self, lut_file, format = Texture.F_rgb):
        lut = loader.loadTexture(lut_file)
        lut.setFormat(Texture.F_rgb16)
        lut.setWrapU(Texture.WMClamp)
        lut.setWrapV(Texture.WMClamp)
        self.quad.setShaderInput("lut", lut)

    def getLUTS(self):
        return self.LUTList

    def cleanup(self):
        self.manager.cleanup()
Esempio n. 33
0
class PostEffects(object):
    def __init__(self):
        self._manager = FilterManager(G.win, G.cam)
        self._quads = []
        self._turned_on = False
        self._c = 0

    def turn_on(self):
        if self._c < 30:
            self._c += 1
            return
        if self._turned_on:
            return
        self._turned_on = True

        # TODO 开启之后会报错 :display:gsg:glgsg(error): GL error GL_INVALID_OPERATION
        # 现象是没法儿和anti-alias一起用。config里面的anti-alias不开,就不报错。
        # 而且必须等程序跑一小会儿才能turn_on,否则会有异常,不知道啥原因,估计是P3D的bug.

        self.enable_fxaa()

    def enable_fxaa(self):
        tex1 = Texture()
        quad1 = self._manager.renderQuadInto(colortex=tex1)
        tex2 = Texture()
        self._quads.append(quad1)

        quad1.setShader(Shader.load("assets/shaders/post/fxaa.sha"))
        quad1.setShaderInput("color", tex1)
        quad1.setShaderInput("active", 1)

        quad2 = self._manager.renderSceneInto(colortex=tex2)
        self._quads.append(quad2)
        quad2.setShader(Shader.load("assets/shaders/post/color.sha"))
        quad2.setShaderInput("tex", tex2)

    def on_update(self, dt):
        pass
Esempio n. 34
0
    def __init__(self):
        ShowBase.__init__(self)
        pman.shim.init(self)
        basic = core.Filename.expand_from(
            '$MAIN_DIR/assets/textures/basic_1.exr')
        basic = self.loader.load_texture(basic)
        pipeline = simplematcap.init(basic,
                                     render_node=self.render,
                                     light_dir=core.Vec3(-1, -1,
                                                         0.5).normalized())

        fog = core.Fog("Fog Name")
        fog.set_color(0, 0, 0)
        fog.set_exp_density(0.04)
        self.render.set_fog(fog)
        self.disable_mouse()
        self.input = Input()
        self.accept('escape', sys.exit)
        self.accept('f1', self.toggle_wireframe)
        self.world = World(pipeline)
        self.set_background_color(util.srgb_color(0x000000))

        self.manager = FilterManager(self.win, self.cam)
        tex = core.Texture()
        depth = core.Texture()
        quad = self.manager.render_scene_into(colortex=tex, depthtex=depth)
        post_vert_str = load_shader_str('post.vert')
        post_frag_str = load_shader_str('post.frag')
        postshader = core.Shader.make(
            core.Shader.SL_GLSL,
            vertex=post_vert_str,
            fragment=post_frag_str,
        )
        quad.set_shader(postshader)
        quad.set_shader_input('tex', tex)
        quad.set_shader_input('blur', 2.5)
        quad.set_shader_input('depth', depth)
Esempio n. 35
0
class GameApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        pman.shim.init(self)
        basic = core.Filename.expand_from(
            '$MAIN_DIR/assets/textures/basic_1.exr')
        basic = self.loader.load_texture(basic)
        pipeline = simplematcap.init(basic,
                                     render_node=self.render,
                                     light_dir=core.Vec3(-1, -1,
                                                         0.5).normalized())

        fog = core.Fog("Fog Name")
        fog.set_color(0, 0, 0)
        fog.set_exp_density(0.04)
        self.render.set_fog(fog)
        self.disable_mouse()
        self.input = Input()
        self.accept('escape', sys.exit)
        self.accept('f1', self.toggle_wireframe)
        self.world = World(pipeline)
        self.set_background_color(util.srgb_color(0x000000))

        self.manager = FilterManager(self.win, self.cam)
        tex = core.Texture()
        depth = core.Texture()
        quad = self.manager.render_scene_into(colortex=tex, depthtex=depth)
        post_vert_str = load_shader_str('post.vert')
        post_frag_str = load_shader_str('post.frag')
        postshader = core.Shader.make(
            core.Shader.SL_GLSL,
            vertex=post_vert_str,
            fragment=post_frag_str,
        )
        quad.set_shader(postshader)
        quad.set_shader_input('tex', tex)
        quad.set_shader_input('blur', 2.5)
        quad.set_shader_input('depth', depth)
        #gt = self.loader.load_texture('textures/blot.png')
        #gt = self.loader.load_texture('video/loglo2.mp4')
        #gt.play()
        #quad.set_shader_input('bg', gt)

    def update(self, task):
        if task.time > self.nextclick:
            self.win.trigger_copy()
            self.nextclick = max(self.nextclick + 1.0 / self.clickrate,
                                 task.time)
        return task.cont
Esempio n. 36
0
File: app.py Progetto: rdb/hexima
    def setup_filters(self):
        fbprops = core.FrameBufferProperties()
        if self.quality >= 3:
            fbprops.multisamples = 16

        self.filters = FilterManager(base.win, base.cam)
        self.scene_tex = core.Texture()
        self.scene_tex.set_wrap_u(core.Texture.WM_clamp)
        self.scene_tex.set_wrap_v(core.Texture.WM_clamp)
        self.quad = self.filters.render_scene_into(colortex=self.scene_tex, fbprops=fbprops)

        if not self.quad and fbprops.multisamples:
            # Try without multisampling.
            fbprops.multisamples = None
            self.quad = self.filters.render_scene_into(colortex=self.scene_tex)
            if not self.quad:
                return

        if fbprops.multisamples:
            self.render.set_antialias(core.AntialiasAttrib.M_multisample)

        self.quad.clear_color()

        prev_tex = self.scene_tex

        if self.quality >= 3:
            intermediate_tex = core.Texture()
            intermediate_tex.set_minfilter(core.Texture.FT_linear)
            intermediate_tex.set_magfilter(core.Texture.FT_linear)
            intermediate_tex.set_wrap_u(core.Texture.WM_clamp)
            intermediate_tex.set_wrap_v(core.Texture.WM_clamp)
            intermediate_quad = self.filters.render_quad_into("blur-x", colortex=intermediate_tex)
            intermediate_quad.set_shader_input("image", prev_tex)
            intermediate_quad.set_shader_input("direction", (2, 0))
            intermediate_quad.set_shader_input("scale", self.blur_scale)
            intermediate_quad.set_shader(self.blur_shader)
            prev_tex = intermediate_tex

            intermediate_tex = core.Texture()
            intermediate_tex.set_minfilter(core.Texture.FT_linear)
            intermediate_tex.set_magfilter(core.Texture.FT_linear)
            intermediate_tex.set_wrap_u(core.Texture.WM_clamp)
            intermediate_tex.set_wrap_v(core.Texture.WM_clamp)
            intermediate_quad = self.filters.render_quad_into("blur-y", colortex=intermediate_tex)
            intermediate_quad.set_shader_input("image", prev_tex)
            intermediate_quad.set_shader_input("direction", (0, 2))
            intermediate_quad.set_shader_input("scale", self.blur_scale)
            intermediate_quad.set_shader(self.blur_shader)
            prev_tex = intermediate_tex

        intermediate_tex = core.Texture()
        intermediate_tex.set_minfilter(core.Texture.FT_linear)
        intermediate_tex.set_magfilter(core.Texture.FT_linear)
        intermediate_tex.set_wrap_u(core.Texture.WM_clamp)
        intermediate_tex.set_wrap_v(core.Texture.WM_clamp)
        intermediate_quad = self.filters.render_quad_into("blur-y", colortex=intermediate_tex)
        intermediate_quad.set_shader_input("image", prev_tex)
        intermediate_quad.set_shader_input("direction", (0, 4))
        intermediate_quad.set_shader_input("scale", self.blur_scale)
        intermediate_quad.set_shader(self.blur_shader)
        prev_tex = intermediate_tex

        self.blurred_tex = prev_tex
Esempio n. 37
0
class Postprocess():
    def __init__(self):
        self.filter_tex={}        
        self.manager=FilterManager(base.win, base.cam)
        self.filters={}
        
        self.window_x=float(base.win.getXSize())
        self.window_y=float(base.win.getYSize())
    
    def reset(self):
        self.manager.cleanup()
        self.filter_tex={}        
        self.manager=FilterManager(base.win, base.cam)
        self.filters={}        
        self.window_x=float(base.win.getXSize())
        self.window_y=float(base.win.getYSize())
                  
    def setupFilters(self, useFxaa=True):       
        colorTex = Texture()#the scene
        colorTex.setWrapU(Texture.WMClamp)
        colorTex.setWrapV(Texture.WMClamp)
        colorTex.setFormat(Texture.F_rgb16)
        auxTex = Texture() # r=blur, g=shadow, b=?, a=?
        composeTex=Texture()#the scene(colorTex) blured where auxTex.r>0 and with shadows (blurTex2.r) added
        self.filters={}
        final_quad = self.manager.renderSceneInto(colortex=colorTex, auxtex=auxTex)
        
        
        blurTex = Texture() #1/2 size of the shadows to be blured
        blurTex.setWrapU(Texture.WMClamp)
        blurTex.setWrapV(Texture.WMClamp)
        blurTex2 = Texture()
        blurTex2.setWrapU(Texture.WMClamp)
        blurTex2.setWrapV(Texture.WMClamp)
        glareTex = Texture()
        glareTex.setWrapU(Texture.WMClamp)
        glareTex.setWrapV(Texture.WMClamp)
        flareTex = Texture()
        flareTex.setWrapU(Texture.WMClamp)
        flareTex.setWrapV(Texture.WMClamp)
        flareTex2 = Texture()
        flareTex2.setWrapU(Texture.WMClamp)
        flareTex2.setWrapV(Texture.WMClamp)
        #blurr shadows #1
        interquad0 = self.manager.renderQuadInto(colortex=blurTex, div=8)
        interquad0.setShader(Shader.load(Shader.SLGLSL, path+"shaders/blur_v.glsl", path+"shaders/blur_f.glsl"))
        interquad0.setShaderInput("input_map", auxTex)
        interquad0.setShaderInput("sharpness", 0.008)
        self.filters['shadow']=interquad0
        #blurrscene
        interquad1 = self.manager.renderQuadInto(colortex=blurTex2, div=4)
        interquad1.setShader(Shader.load(Shader.SLGLSL, path+"shaders/blur_v.glsl", path+"shaders/blur_f.glsl"))
        interquad1.setShaderInput("input_map", colorTex)        
        interquad1.setShaderInput("sharpness", 0.005)
        self.filters['blur']=interquad1
        #glare
        interquad2 = self.manager.renderQuadInto(colortex=glareTex, div=2)
        interquad2.setShader(Shader.load(Shader.SLGLSL, path+"shaders/glare_v.glsl", path+"shaders/glare_f.glsl"))
        interquad2.setShaderInput("auxTex", auxTex)
        interquad2.setShaderInput("colorTex", blurTex2)
        interquad2.setShaderInput("blurTex", blurTex)
        self.filters['glare']=interquad2
        #lense flare
        interquad3 = self.manager.renderQuadInto(colortex=flareTex, div=2)
        #interquad3.setShader(Shader.load(path+"shaders/lens_flare.sha"))
        #interquad3.setShaderInput("tex0", glareTex)
        interquad3.setShader(Shader.load(Shader.SLGLSL, path+"shaders/flare_v.glsl", path+"shaders/flare_f.glsl"))
        interquad3.setShaderInput("glareTex", glareTex)        
        self.filters['flare']=interquad3
        interquad3a = self.manager.renderQuadInto(colortex=flareTex2, div=2)
        interquad3a.setShader(Shader.load(Shader.SLGLSL, path+"shaders/blur_v.glsl", path+"shaders/blur_f.glsl"))
        interquad3a.setShaderInput("input_map", flareTex)        
        interquad3a.setShaderInput("sharpness", 0.005)        
        self.filters['flare2']=interquad1        
        if useFxaa:
            #compose the scene        
            interquad4 = self.manager.renderQuadInto(colortex=composeTex)               
            interquad4.setShader(Shader.load(Shader.SLGLSL, path+"shaders/compose_v.glsl", path+"shaders/compose_f.glsl"))
            interquad4.setShaderInput("flareTex", flareTex2)
            interquad4.setShaderInput("glareTex", glareTex)
            interquad4.setShaderInput("colorTex", colorTex)
            interquad4.setShaderInput("blurTex", blurTex)
            interquad4.setShaderInput("blurTex2", blurTex2)
            interquad4.setShaderInput("auxTex", auxTex)
            interquad4.setShaderInput("noiseTex", loader.loadTexture(path+"data/noise2.png"))
            star_tex=loader.loadTexture(path+"data/star.png")
            star_tex.setWrapU(Texture.WM_mirror_once)
            star_tex.setWrapV(Texture.WM_mirror_once)
            interquad4.setShaderInput("starTex", star_tex)
            interquad4.setShaderInput('time', 0.0)
            interquad4.setShaderInput('screen_size', Vec2(float(base.win.getXSize()),float(base.win.getYSize())))           
            #fxaa
            final_quad.setShader(Shader.load(Shader.SLGLSL, path+"shaders/fxaa_v.glsl", path+"shaders/fxaa_f.glsl"))
            final_quad.setShaderInput("tex0", composeTex)
            final_quad.setShaderInput("rt_w",float(base.win.getXSize()))
            final_quad.setShaderInput("rt_h",float(base.win.getYSize()))
            final_quad.setShaderInput("FXAA_SPAN_MAX" , float(8.0))
            final_quad.setShaderInput("FXAA_REDUCE_MUL", float(1.0/8.0))
            final_quad.setShaderInput("FXAA_SUBPIX_SHIFT", float(1.0/4.0))
            self.filters['fxaa']=final_quad
        else:
            #compose the scene  
            final_quad.setShader(Shader.load(Shader.SLGLSL, path+"shaders/compose_v.glsl", path+"shaders/compose_f.glsl"))
            final_quad.setShaderInput("flareTex", flareTex2)
            final_quad.setShaderInput("glareTex", glareTex)
            final_quad.setShaderInput("colorTex", colorTex)
            final_quad.setShaderInput("blurTex", blurTex)
            final_quad.setShaderInput("blurTex2", blurTex2)
            final_quad.setShaderInput("auxTex", auxTex)
            final_quad.setShaderInput("noiseTex", loader.loadTexture(path+"data/noise2.png"))
            star_tex=loader.loadTexture(path+"data/star.png")
            star_tex.setWrapU(Texture.WM_mirror_once)
            star_tex.setWrapV(Texture.WM_mirror_once)
            final_quad.setShaderInput("starTex", star_tex)
            final_quad.setShaderInput('time', 0.0)
            final_quad.setShaderInput('screen_size', Vec2(float(base.win.getXSize()),float(base.win.getYSize())))            
            self.filters['compose']=final_quad     
        
    def setupFxaa(self):
        colorTex = Texture()#the scene
        final_quad = self.manager.renderSceneInto(colortex=colorTex)
        final_quad.setShader(Shader.load(Shader.SLGLSL, path+"shaders/fxaa_v.glsl", path+"shaders/fxaa_f.glsl"))
        final_quad.setShaderInput("tex0", colorTex)
        final_quad.setShaderInput("rt_w",float(base.win.getXSize()))
        final_quad.setShaderInput("rt_h",float(base.win.getYSize()))
        final_quad.setShaderInput("FXAA_SPAN_MAX" , float(8.0))
        final_quad.setShaderInput("FXAA_REDUCE_MUL", float(1.0/8.0))
        final_quad.setShaderInput("FXAA_SUBPIX_SHIFT", float(1.0/4.0))
        self.filters['fxaa']=final_quad
    
    def update(self):
        x=float(base.win.getXSize())
        y=float(base.win.getYSize()) 
        if self.filters:
            if 'fxaa' in self.filters:
                self.filters['fxaa'].setShaderInput("rt_w",x)         
                self.filters['fxaa'].setShaderInput("rt_h",y)
            if 'compose' in self.filters:
                self.filters['compose'].setShaderInput("screen_size",Vec2(x,y)) 
Esempio n. 38
0
File: filters.py Progetto: wezu/a4p
class Filters():
    def __init__(self):
        self.filter_tex={}
        self.manager=FilterManager(base.win, base.cam)
        self.filters={}

        self.window_x=float(base.win.getXSize())
        self.window_y=float(base.win.getYSize())
        render.setShaderInput('screen_size',Vec2(self.window_x,self.window_y))
        log.debug('Filters: FilterManager started at '+str(base.win.getXSize())+'x'+str(base.win.getYSize()))
        if cfg['use-filters']:
            self.setupFilters()
        elif cfg['use-fxaa']:
            self.setupFxaa()

    def reset(self):
        self.manager.cleanup()
        self.filter_tex={}
        self.manager=FilterManager(base.win, base.cam)
        self.filters={}
        self.window_x=float(base.win.getXSize())
        self.window_y=float(base.win.getYSize())
        if cfg['glsl-blur'] or cfg['glsl-distortion'] or cfg['glsl-flare'] or cfg['glsl-glare'] or cfg['glsl-lut']:
            self.setupFilters()
        elif cfg['use-fxaa']:
            self.setupFxaa()

    def setupFilters(self):
        colorTex = Texture()#the scene
        colorTex.setWrapU(Texture.WMClamp)
        colorTex.setWrapV(Texture.WMClamp)

        auxTex = Texture()
        auxTex.setWrapU(Texture.WMClamp)
        auxTex.setWrapV(Texture.WMClamp)

        composeTex = Texture()
        composeTex.setWrapU(Texture.WMClamp)
        composeTex.setWrapV(Texture.WMClamp)

        self.filters={}
        final_quad = self.manager.renderSceneInto(colortex=colorTex, auxtex=auxTex)

        if cfg['glsl-blur'] or cfg['glsl-distortion'] or cfg['glsl-glare'] or cfg['glsl-flare']:
            if cfg['glsl-blur']:
                #blur scene
                blurTex = Texture()
                blurTex.setWrapU(Texture.WMClamp)
                blurTex.setWrapV(Texture.WMClamp)
                interquad0 = self.manager.renderQuadInto(colortex=blurTex, div=2)
                interquad0.setShader(Shader.load(Shader.SLGLSL, path+'shaders/blur_v.glsl', path+'shaders/blur_f.glsl'))
                interquad0.setShaderInput('input_map', colorTex)
                interquad0.setShaderInput('sharpness', 0.008)
                self.filters['blur']=interquad0
            if cfg['glsl-flare'] or cfg['glsl-glare']:
                #blur aux
                blurTex2 = Texture()
                blurTex2.setWrapU(Texture.WMClamp)
                blurTex2.setWrapV(Texture.WMClamp)
                interquad0 = self.manager.renderQuadInto(colortex=blurTex2, div=2)
                interquad0.setShader(Shader.load(Shader.SLGLSL, path+'shaders/blur_ex_v.glsl', path+'shaders/blur_ex_f.glsl'))
                interquad0.setShaderInput('input_map', auxTex)
                #interquad0.setShaderInput('sharpness', 0.02)
                self.filters['blur_aux']=interquad0

                #glare
                glareTex = Texture()
                glareTex.setWrapU(Texture.WMClamp)
                glareTex.setWrapV(Texture.WMClamp)
                interquad2 = self.manager.renderQuadInto(colortex=glareTex)
                interquad2.setShader(Shader.load(Shader.SLGLSL, path+'shaders/glare_v.glsl', path+'shaders/glare_f.glsl'))
                interquad2.setShaderInput('auxTex', auxTex)
                interquad2.setShaderInput('colorTex', colorTex)
                interquad2.setShaderInput('blurAuxTex', blurTex2)
                self.filters['glare']=interquad2
            if cfg['glsl-flare']:
                #flare
                flareTex = Texture()
                flareTex.setWrapU(Texture.WMClamp)
                flareTex.setWrapV(Texture.WMClamp)
                flareTex2 = Texture()
                flareTex2.setWrapU(Texture.WMClamp)
                flareTex2.setWrapV(Texture.WMClamp)
                #lense flare
                interquad3 = self.manager.renderQuadInto(colortex=flareTex, div=2)
                #interquad3.setShader(Shader.load(path+'shaders/lens_flare.sha'))
                #interquad3.setShaderInput('tex0', glareTex)
                interquad3.setShader(Shader.load(Shader.SLGLSL, path+'shaders/flare_v.glsl', path+'shaders/flare_f.glsl'))
                interquad3.setShaderInput('glareTex', glareTex)
                self.filters['flare']=interquad3
                interquad3a = self.manager.renderQuadInto(colortex=flareTex2, div=2)
                interquad3a.setShader(Shader.load(Shader.SLGLSL, path+'shaders/blur_v.glsl', path+'shaders/blur_f.glsl'))
                interquad3a.setShaderInput('input_map', flareTex)
                interquad3a.setShaderInput('sharpness', 0.008)
                self.filters['flare2']=interquad3a

        if cfg['use-fxaa']:
            #compose the scene
            interquad4 = self.manager.renderQuadInto(colortex=composeTex)
            interquad4.setShader(Shader.load(Shader.SLGLSL, path+'shaders/compose_v.glsl', path+'shaders/compose_f.glsl'))
            interquad4.setShaderInput('colorTex', colorTex)
            interquad4.setShaderInput('auxTex', auxTex)
            if cfg['glsl-blur']:
                dof_tex=loader.loadTexture(path+'data/dof.png')
                dof_tex.setWrapU(Texture.WM_mirror_once)
                dof_tex.setWrapV(Texture.WM_mirror_once)
                interquad4.setShaderInput('dofTex', dof_tex)
                interquad4.setShaderInput('blurTex', blurTex)
            if cfg['glsl-glare']:
                interquad4.setShaderInput('glareTex', glareTex)
            if cfg['glsl-flare']:
                interquad4.setShaderInput('flareTex', flareTex2)
                star_tex=loader.loadTexture(path+'data/'+cfg['flare-tex'])
                star_tex.setWrapU(Texture.WM_mirror_once)
                star_tex.setWrapV(Texture.WM_mirror_once)
                interquad4.setShaderInput('starTex', star_tex)
            if cfg['glsl-lut']:
                lut_tex=loader.loadTexture(path+'data/'+cfg['lut-tex'])
                lut_tex.setFormat(Texture.F_rgb16)
                lut_tex.setWrapU(Texture.WMClamp)
                lut_tex.setWrapV(Texture.WMClamp)
                interquad4.setShaderInput('lut', lut_tex)
            interquad4.setShaderInput('screen_size', Vec2(float(base.win.getXSize()),float(base.win.getYSize())))
            self.filters['compose']=interquad4

            #fxaa
            final_quad.setShader(Shader.load(Shader.SLGLSL, path+'shaders/fxaa_v.glsl', path+'shaders/fxaa_f.glsl'))
            final_quad.setShaderInput('tex0', composeTex)
            final_quad.setShaderInput('rt_w',float(base.win.getXSize()))
            final_quad.setShaderInput('rt_h',float(base.win.getYSize()))
            final_quad.setShaderInput('FXAA_SPAN_MAX' , float(8.0))
            final_quad.setShaderInput('FXAA_REDUCE_MUL', float(1.0/8.0))
            final_quad.setShaderInput('FXAA_SUBPIX_SHIFT', float(1.0/4.0))
            self.filters['fxaa']=final_quad
            log.debug('Filters: Using post-process effects and FXAA')
        else:
            final_quad.setShader(Shader.load(Shader.SLGLSL, path+'shaders/compose_v.glsl', path+'shaders/compose_f.glsl'))
            final_quad.setShaderInput('colorTex', colorTex)
            final_quad.setShaderInput('auxTex', auxTex)
            if cfg['glsl-blur']:
                dof_tex=loader.loadTexture(path+'data/dof.png')
                dof_tex.setWrapU(Texture.WM_mirror_once)
                dof_tex.setWrapV(Texture.WM_mirror_once)
                final_quad.setShaderInput('dofTex', dof_tex)
                final_quad.setShaderInput('blurTex', blurTex)
            if cfg['glsl-glare']:
                final_quad.setShaderInput('glareTex', glareTex)
            if cfg['glsl-flare']:
                final_quad.setShaderInput('flareTex', flareTex2)
                star_tex=loader.loadTexture(path+'data/star.png')
                star_tex.setWrapU(Texture.WM_mirror_once)
                star_tex.setWrapV(Texture.WM_mirror_once)
                final_quad.setShaderInput('starTex', star_tex)
            if cfg['glsl-lut']:
                lut_tex=loader.loadTexture(path+'data/'+cfg['lut-tex'])
                lut_tex.setFormat(Texture.F_rgb16)
                lut_tex.setWrapU(Texture.WMClamp)
                lut_tex.setWrapV(Texture.WMClamp)
                final_quad.setShaderInput('lut', lut_tex)
            final_quad.setShaderInput('screen_size', Vec2(float(base.win.getXSize()),float(base.win.getYSize())))

            self.filters['compose']=final_quad
            log.debug('Filters: Using post-process effects without FXAA')

        for buff in self.manager.buffers:
            buff.setClearValue(GraphicsOutput.RTPAuxRgba0, (0.0, 0.0, 0.0, 1.0))

    def setupFxaa(self):
        colorTex = Texture()#the scene
        final_quad = self.manager.renderSceneInto(colortex=colorTex)
        final_quad.setShader(Shader.load(Shader.SLGLSL, path+'shaders/fxaa_v.glsl', path+'shaders/fxaa_f.glsl'))
        final_quad.setShaderInput('tex0', colorTex)
        final_quad.setShaderInput('rt_w',float(base.win.getXSize()))
        final_quad.setShaderInput('rt_h',float(base.win.getYSize()))
        final_quad.setShaderInput('FXAA_SPAN_MAX' , float(8.0))
        final_quad.setShaderInput('FXAA_REDUCE_MUL', float(1.0/8.0))
        final_quad.setShaderInput('FXAA_SUBPIX_SHIFT', float(1.0/4.0))
        self.filters['fxaa']=final_quad
        log.debug('Filters: Using FXAA only')

    def reloadShaders(self):
        for name, quad in self.filters.items():
            shader=quad.getShader()
            v_shader=shader.getFilename(Shader.ST_vertex)
            f_shader=shader.getFilename(Shader.ST_fragment)
            quad.setShader(Shader.load(Shader.SLGLSL, v_shader,f_shader))
        self.update()

    def update(self):
        x=float(base.win.getXSize())
        y=float(base.win.getYSize())
        render.setShaderInput('screen_size',Vec2(x,y))
        if self.filters:
            if 'fxaa' in self.filters:
                self.filters['fxaa'].setShaderInput('rt_w',x)
                self.filters['fxaa'].setShaderInput('rt_h',y)
            if 'compose' in self.filters:
                self.filters['compose'].setShaderInput('screen_size',Vec2(x,y))
Esempio n. 39
0
 def __init__(self, loadscreen, root):
     
     self.loadscreen=loadscreen
     
     
 
     #base.openMainWindow()
     if not config_safemode.getValue():  
         render.setShaderAuto()
     base.disableMouse()  
     #base.setBackgroundColor(0, 0, 0)
     if not config_safemode.getValue():
         if config_aa.getValue()>0:
             render.setAntialias(AntialiasAttrib.MMultisample)
         base.camLens.setNearFar(3, 40)   
     
     self.common={}
     self.common['root']=root
     self.common['safemode']=config_safemode.getValue()
     #print self.common['safemode']
     #keys
     self.common['keymap']={}
     self.common['keymap']['key_forward']=config_forward.getValue().split('|')
     self.common['keymap']['key_back']=config_back.getValue().split('|')
     self.common['keymap']['key_left']=config_left.getValue().split('|')
     self.common['keymap']['key_right']=config_right.getValue().split('|')
     self.common['keymap']['key_cam_left']=config_camera_left.getValue().split('|')
     self.common['keymap']['key_cam_right']=config_camera_right.getValue().split('|')
     self.common['keymap']['key_action1']=config_action1.getValue().split('|')
     self.common['keymap']['key_action2']=config_action2.getValue().split('|')
     self.common['keymap']['key_zoomin']=config_zoomin.getValue().split('|')
     self.common['keymap']['key_zoomout']=config_zoomout.getValue().split('|')      
     self.common['extra_ambient']=True
     self.common['nude']=config_nude.getValue()
     self.common['path']=path
     
     #load save
     levels=[]
     try:
         f = open(path+'save.dat', 'r')
         for line in f:        
             levels.append(line)
     except IOError:
         print "No save file"     
     self.common['max_level']=len(levels)
     
     
     self.common["key_icon"]=DirectFrame(frameSize=(-64, 0, 0, 64),
                                 frameColor=(1, 1, 1, 1),
                                 frameTexture="icon/icon_key2.png",
                                 parent=pixel2d)
     self.common["key_icon"].setPos(64,0,-64)
     self.common["key_icon"].setTransparency(TransparencyAttrib.MDual)
     self.common["key_icon"].hide()
     
     if config_bloom.getValue(): 
         self.common['extra_ambient']=False            
     if config_safemode.getValue():
         self.common['extra_ambient']=True
     #print "extra ambient:", self.common['extra_ambient']
     
     #audio 3d
     self.common['audio3d']=Audio3DManager.Audio3DManager(base.sfxManagerList[0], base.camera)        
     self.common['audio3d'].setListenerVelocityAuto()
     self.common['audio3d'].setDropOffFactor(0.2)
     self.common['soundPool']=SoundPool(self.common)
     base.sfxManagerList[0].setVolume(config_sfx.getValue()*0.01)
     self.common['click']=base.loader.loadSfx("sfx/click_stereo.ogg")
     
     #base.cTrav = CollisionTraverser()
     
     
     self.common['monsterList']=[]
     self.common['spawner']=Spawner(self.common)
     self.common['levelLoader']=LevelLoader(self.common)
     
     #self.common['PC']=PC(self.common)
     #self.common['PC'].node.setPos(-12, 0, 0)
         
     #spawner    
     #self.spawner=Spawner(self.common, monster_limit=5, tick=9.13)
     
     
     #music
     
     base.musicManager.setVolume(config_music.getValue()*0.01)
     self.common['musicVolume']=config_music.getValue()
     self.common['soundVolume']=config_sfx.getValue()
     #self.music =    [
     #                base.loadMusic("sfx/LuridDeliusion.ogg"),
     #                base.loadMusic("sfx/DefyingCommodus.ogg"),
     #                base.loadMusic("sfx/DarkDescent.ogg")
                     #base.loadMusic("sfx/DarkAmulet.ogg"),
                     #base.loadMusic("sfx/WastelandShowdown.ogg"),
                     #base.loadMusic("sfx/HeroicDemise.ogg")
     #                ]
     #self.musicSequence=Sequence()
     #for music in self.music:            
     #    self.musicSequence.append(SoundInterval(music))
     #self.musicSequence.loop()                  
     
     #Monster(data.monsters[2],self.common, self.testPC, (12, -4, 0))        
       
     
     #self.flask=Interactive(self.common, "flask", (-12, 4, 0), 0.15, "vfx/icon_flask.png", "heal")
     
     #self.health=Actor("models/health", {"anim":"models/health_anim"})
     #self.health.loop("anim")
     #self.health.reparentTo(render)
     #self.health.setPos(-12, 4, 0)
     #self.health.setScale(0.2)
     #self.health.setLightOff()
     
     self.common['traverser']=CollisionTraverser("playerTrav")
     self.common['traverser'].setRespectPrevTransform(True)        
     self.common['queue'] = CollisionHandlerQueue() 
     
     self.common['CharGen']=CharGen(self.common)
     
     base.openMainWindow(props = wp)
     
     #bloom 
     if not config_safemode.getValue():    
         if config_bloom.getValue(): 
             self.bloomBuffer=base.win.makeTextureBuffer("bloom", buff_size.getValue(), buff_size.getValue())
             self.bloomBuffer.setSort(-3)
             self.bloomBuffer.setClearColor(Vec4(0,0,0,1))
             self.bloomCamera=base.makeCamera(self.bloomBuffer, lens=base.cam.node().getLens())
             glowShader=loader.loadShader("glowShader.sha")
             tempnode = NodePath(PandaNode("temp node"))
             tempnode.setShader(glowShader)
             self.bloomCamera.node().setInitialState(tempnode.getState())
             self.blurBuffer=self.makeFilterBuffer(self.bloomBuffer,  "Blur X", -2, "blur.sha")            
             self.finalcard = self.blurBuffer.getTextureCard()            
             self.finalcard.reparentTo(render2d)
             self.finalcard.setAttrib(ColorBlendAttrib.make(ColorBlendAttrib.MAdd))            
         #shadow buffer
         self.shadowTexture=Texture()
         self.shadowTexture.setWrapU(Texture.WMBorderColor  )
         self.shadowTexture.setWrapV(Texture.WMBorderColor  )
         self.shadowTexture.setBorderColor(Vec4(1,1,1,1)) 
         self.shadowBuffer = base.win.makeTextureBuffer("Shadow Buffer",buff_size.getValue(), buff_size.getValue(), self.shadowTexture)
         self.shadowBuffer.setClearColor((1,1,1,1))
         self.shadowCamera = base.makeCamera(self.shadowBuffer)
         self.shadowNode  = render.attachNewNode('shadowNode')
         self.shadowNode.setP(-90)
         #self.shadowNode.setZ(18)
         self.shadowCamera.reparentTo(self.shadowNode)
         #self.shadowCamera.node().showFrustum() 
         self.shadow_lens = PerspectiveLens()
         self.shadow_lens.setFov(160)
         self.shadow_lens.setNearFar(0.01,4)         
         self.shadowCamera.node().setLens(self.shadow_lens)
         self.shadowCamera.node().setCameraMask(BitMask32.bit(1)) 
         self.initial = NodePath('initial')
         #self.initial.setTextureOff(2)
         #self.initial.setMaterialOff(2)
         self.initial.setLightOff(2)
         self.initial.setColor(0,0,0,1)
         self.shadowCamera.node().setInitialState(self.initial.getState())  
         shadow_manager = FilterManager(self.shadowBuffer, self.shadowCamera)            
         sh_tex1 = Texture()
         quad = shadow_manager.renderSceneInto(colortex=sh_tex1)
         quad.setShader(Shader.load("shadow.sha"))
         quad.setShaderInput("tex1", sh_tex1)                         
         self.shadow_ts=TextureStage('shadow')  
         
         self.common['shadowNode']=self.shadowNode
         self.common['shadow_ts']=self.shadow_ts
         self.common['shadowTexture']=self.shadowTexture
         self.common['shadowCamera']= self.shadowCamera 
         
     taskMgr.add(self.hideLoadscreen, 'hideLoadscreenTask')
     self.accept("x", self.screenshot)