How to use the panda3d.core.Texture function in Panda3D

To help you get started, we’ve selected a few Panda3D examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tobspr / RenderPipeline / Code / GUI / ExposureWidget.py View on Github external
def _create_components(self):
        """ Internal method to init the widgets components """

        self._node.hide()

        # Create the texture where the gui component is rendered inside
        self._storage_tex = Image.create_2d("ExposureDisplay", 140, 20, Texture.T_unsigned_byte, Texture.F_rgba8)
        self._storage_tex.set_clear_color(Vec4(0.2, 0.6, 1.0, 1.0))
        self._storage_tex.clear_image()

        self._bg_frame = DirectFrame(parent=self._node, frameColor=(0.1, 0.1, 0.1, 1.0),
                                     frameSize=(200, 0, -10, -85), pos=(0, 0, 0))

        self._display_img = BetterOnscreenImage(
            image=self._storage_tex, parent=self._node, w=140, h=20, x=20, y=50)

        self._display_txt = BetterOnscreenText(
            text="Current Exposure".upper(), parent=self._node, x=160, y=40, size=13,
            color=Vec3(0.8), align="right")

        # Create the shader which generates the visualization texture
        self._cshader_node = ComputeNode("ExposureWidget")
        self._cshader_node.add_dispatch(140 // 10, 20 // 4, 1)
github tobspr / RenderPipeline / Data / default_cubemap / filter.py View on Github external
cubemap = loader.loadCubeMap(pth)
        node = NodePath("")
        node.set_shader(compute_shader)
        node.set_shader_input("SourceCubemap", cubemap)
        node.set_shader_input("size", size)
        node.set_shader_input("blurSize", blur_size)
        node.set_shader_input("effectiveSize", effective_size)

        final_img = PNMImage(size, size, 3)

        for i in range(6):
            face_dest = dst_pth.replace("#", str(i))
            dst = Texture("Face-" + str(i))
            dst.setup_2d_texture(effective_size, effective_size,
                                 Texture.T_float, Texture.F_rgba16)

            # Execute compute shader
            node.set_shader_input("faceIndex", i)
            node.set_shader_input("DestTex", dst)
            attr = node.get_attrib(ShaderAttrib)
            base.graphicsEngine.dispatch_compute(( (effective_size+15) // 16,
                                                   (effective_size+15) // 16, 1),
                                                 attr, base.win.get_gsg())

            base.graphicsEngine.extract_texture_data(dst, base.win.get_gsg())
            img = PNMImage(effective_size, effective_size, 3)
            dst.store(img)
            img.gaussian_filter(blur_size)
            final_img.copy_sub_image(img, 0, 0, blur_size, blur_size, size, size)
            final_img.write(face_dest)
github panda3d / panda3d / tests / display / test_glsl_shader.py View on Github external
def test_glsl_sampler(gsg):
    tex1 = core.Texture("")
    tex1.setup_1d_texture(1, core.Texture.T_unsigned_byte, core.Texture.F_rgba8)
    tex1.set_clear_color((0, 2 / 255.0, 1, 1))

    tex2 = core.Texture("")
    tex2.setup_2d_texture(1, 1, core.Texture.T_float, core.Texture.F_rgba32)
    tex2.set_clear_color((1.0, 2.0, -3.14, 0.0))

    preamble = """
    uniform sampler1D tex1;
    uniform sampler2D tex2;
    """
    code = """
    assert(texelFetch(tex1, 0, 0) == vec4(0, 2 / 255.0, 1, 1));
    assert(texelFetch(tex2, ivec2(0, 0), 0) == vec4(1.0, 2.0, -3.14, 0.0));
    """
    run_glsl_test(gsg, code, preamble, {'tex1': tex1, 'tex2': tex2})
github tobspr / RenderPipeline / Plugins / Clouds / CloudStage.py View on Github external
def create(self):

        # Construct the voxel texture
        self._cloud_voxels = Image.create_3d("CloudVoxels", self._voxel_res_xy, self._voxel_res_xy, self._voxel_res_z,
            Texture.T_unsigned_byte, Texture.F_rgba8)
        self._cloud_voxels.set_wrap_u(SamplerState.WM_repeat)
        self._cloud_voxels.set_wrap_v(SamplerState.WM_repeat)
        self._cloud_voxels.set_wrap_w(SamplerState.WM_border_color)
        self._cloud_voxels.set_border_color(Vec4(0, 0, 0, 0))
        # self._cloud_voxels.set_border_color(Vec4(1, 0, 0, 1))

        # Construct the target which populates the voxel texture
        self._grid_target = self.make_target("Clouds:CreateGrid")
        self._grid_target.size = self._voxel_res_xy, self._voxel_res_xy
        self._grid_target.prepare_offscreen_buffer()
        self._grid_target.quad.set_instance_count(self._voxel_res_z)
        self._grid_target.set_shader_input("CloudVoxels", self._cloud_voxels)

        # Construct the target which shades the voxels
        self._shade_target = self.make_target("Clouds:ShadeVoxels")
        self._shade_target.size = self._voxel_res_xy, self._voxel_res_xy
github tobspr / RenderPipeline / Samples / 02-Roaming-Ralph / Tut-Roaming-Ralph.py View on Github external
def prepareSRGB(self, np):
        """ Sets the correct texture format for all textures found in  """
        for tex in np.findAllTextures():

            baseFormat = tex.getFormat()

            if baseFormat == Texture.FRgb:
                tex.setFormat(Texture.FSrgb)
            elif baseFormat == Texture.FRgba:
                tex.setFormat(Texture.FSrgbAlpha)
            else:
                print "Unkown texture format:", baseFormat
                print "\tTexture:", tex

            # tex.setMinfilter(Texture.FTLinearMipmapLinear)
            # tex.setMagfilter(Texture.FTLinear)
            tex.setAnisotropicDegree(16)
github tobspr / RenderPipeline / rpcore / render_target2.py View on Github external
def _setup_textures(self):
        """ Preparse all bound textures """
        for i in range(self._aux_count):
            self._targets["aux_{}".format(i)] = Texture(
                self.debug_name + "_aux{}".format(i))
        for name, tex in iteritems(self._targets):
            tex.set_wrap_u(SamplerState.WM_clamp)
            tex.set_wrap_v(SamplerState.WM_clamp)
            tex.set_anisotropic_degree(0)
            tex.set_x_size(self._size.x)
            tex.set_y_size(self._size.y)
            tex.set_minfilter(SamplerState.FT_linear)
            tex.set_magfilter(SamplerState.FT_linear)
github tobspr / RenderPipeline / Code / RenderTarget.py View on Github external
if target == RenderTargetType.Color:
                if colorIsFloat:
                    handle.setComponentType(Texture.TFloat)

                if self._colorBits == 8:
                    if self._haveColorAlpha:
                        handle.setFormat(Texture.FRgba8)
                    else:
                        handle.setFormat(Texture.FRgb8)

                elif self._colorBits == 16:
                    if self._haveColorAlpha:
                        handle.setFormat(Texture.FRgba16)
                    else:
                        handle.setFormat(Texture.FRgb16)

                elif self._colorBits == 32:
                    if self._haveColorAlpha:
                        handle.setFormat(Texture.FRgba32)
                    else:
                        handle.setFormat(Texture.FRgb32)
            else:
                if auxIsFloat:
                    handle.setComponentType(Texture.TFloat)

                if self._auxBits == 8:
                    handle.setFormat(Texture.FRgba8)
                elif self._auxBits == 16:
                    handle.setFormat(Texture.FRgba16)
                elif self._auxBits == 32:
                    handle.setFormat(Texture.FRgba32)
github cosmonium / cosmonium / cosmonium / procedural / generator.py View on Github external
def make_buffer(self, width, height, texture_format):
        self.width = width
        self.height = height
        self.root = NodePath("root")
        props = FrameBufferProperties()
        props.set_srgb_color(False)
        if texture_format == Texture.F_rgb:
            props.set_float_color(False)
            props.set_rgba_bits(8, 8, 8, 0)
        elif texture_format == Texture.F_rgba:
            props.set_float_color(False)
            props.set_rgba_bits(8, 8, 8, 8)
        elif texture_format == Texture.F_r32:
            props.set_float_color(True)
            props.set_rgba_bits(32, 0, 0, 0)
        elif texture_format == Texture.F_rgb32:
            props.set_float_color(True)
            props.set_rgba_bits(32, 32, 32, 0)
        elif texture_format == Texture.F_rgba32:
            props.set_float_color(True)
            props.set_rgba_bits(32, 32, 32, 32)
        self.buffer = base.win.make_texture_buffer("generatorBuffer", width, height, to_ram=True, fbp=props)
        #print(self.buffer.get_fb_properties(), self.buffer.get_texture())
github pycollada / pycollada / examples / panda_display_collada.py View on Github external
if prim_material:
        for prop in prim_material.supported:
            value = getattr(prim_material, prop)
            if value is None:
                continue
            
            if type(value) is tuple:
                val4 = value[3] if len(value) > 3 else 1.0
                value = VBase4(value[0], value[1], value[2], val4)
            
            if isinstance(value, collada.material.Map):
                image_data = value.sampler.surface.image.data
                if image_data:
                    myImage = PNMImage()
                    myImage.read(StringStream(image_data), posixpath.basename(value.sampler.surface.image.path))
                    myTexture = Texture(value.sampler.surface.image.id)
                    myTexture.load(myImage)
                    state = state.addAttrib(TextureAttrib.make(myTexture))
            elif prop == 'emission':
                mat.setEmission(value)
            elif prop == 'ambient':
                mat.setAmbient(value)
            elif prop == 'diffuse':
                mat.setDiffuse(value)
            elif prop == 'specular':
                #mat.setSpecular(value)
                pass
            elif prop == 'shininess':
                mat.setShininess(value)
            elif prop == 'reflective':
                pass
            elif prop == 'reflectivity':
github tobspr / RenderPipeline / rpcore / render_target.py View on Github external
def _setup_textures(self):
        """ Prepares all bound textures """
        for i in range(self._aux_count):
            self._targets["aux_{}".format(i)] = Texture(
                self.debug_name + "_aux{}".format(i))
        for tex in itervalues(self._targets):
            tex.set_wrap_u(SamplerState.WM_clamp)
            tex.set_wrap_v(SamplerState.WM_clamp)
            tex.set_anisotropic_degree(0)
            tex.set_x_size(self._size.x)
            tex.set_y_size(self._size.y)
            tex.set_minfilter(SamplerState.FT_linear)
            tex.set_magfilter(SamplerState.FT_linear)