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)
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)
def __init__(self, value): if isinstance(value, str): value = Path(value) if isinstance(value, Path): self.path = Path(value) self._texture = loader.loadTexture(Filename.fromOsSpecific(str(value))) self._cached_image = None # for get_pixel() method elif isinstance(value, PandaTexture): self._texture = value else: from PIL import Image image = value self._texture = PandaTexture() self._texture.setup2dTexture(image.width, image.height, PandaTexture.TUnsignedByte, PandaTexture.FRgba) self._texture.setRamImageAs(image.transpose(Image.FLIP_TOP_BOTTOM).tobytes(), image.mode) self._cached_image = image.transpose(Image.FLIP_TOP_BOTTOM) self.path = None self.filtering = Texture.default_filtering # None/'bilinear'/'mipmap' default: 'bilinear'
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
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
def new(size, color=(255,255,255)): img = PNMImage(*size) if len(color) == 4: img.addAlpha() img.fill(*color) panda_tex = PandaTexture('texture') panda_tex.load(img) return Texture(panda_tex)
def __init__(self, path): if 'Image' in str(type(path)): # print('passing pil image!') image = path self._texture = PandaTexture() self._texture.setup2dTexture(image.width, image.height, PandaTexture.TUnsignedByte, PandaTexture.FRgba) self._texture.setRamImageAs(image.transpose(Image.FLIP_TOP_BOTTOM).tobytes(), image.mode) self._cached_image = image.transpose(Image.FLIP_TOP_BOTTOM) self.path = None elif type(path) == PandaTexture: self._texture = path else: self.path = Path(path) self._texture = loader.loadTexture(Filename.fromOsSpecific(path)) self._cached_image = None # for get_pixel() method self.filtering = Texture.default_filtering