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


Python core.Shader类代码示例

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


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

示例1: setShaders

    def setShaders(self):
        shaderCoC = Shader.load(Shader.SLGLSL, 
            "Shader/DefaultPostProcess.vertex",
            "Shader/DoF/DoFCoC.fragment")
        self.targetCoC.setShader(shaderCoC)
        
        # shaderSprites = Shader.load(Shader.SLGLSL, 
        #     "Shader/DoF/DoFSprite.vertex",
        #     "Shader/DoF/DoFSprite.fragment")
        # self.targetSpawnSprites.setShader(shaderSprites)

        shaderBlurV = Shader.load(Shader.SLGLSL, 
            "Shader/DefaultPostProcess.vertex",
            "Shader/DoF/DoFBlurV.fragment")
        self.targetBlurV.setShader(shaderBlurV)

        shaderBlurH = Shader.load(Shader.SLGLSL, 
            "Shader/DefaultPostProcess.vertex",
            "Shader/DoF/DoFBlurH.fragment")
        self.targetBlurH.setShader(shaderBlurH)

        shaderCombine = Shader.load(Shader.SLGLSL, 
            "Shader/DefaultPostProcess.vertex",
            "Shader/DoF/DoFCombine.fragment")
        self.targetCombine.setShader(shaderCombine)        
        
        return [shaderCoC, shaderBlurV, shaderBlurH, shaderCombine]
开发者ID:cesarmarinhorj,项目名称:RenderPipeline,代码行数:27,代码来源:DOFPass.py

示例2: __init__

    def __init__(self, N, sourceTex, normalizationFactor):
        """ Creates a new fft instance. The source texture has to specified
        from the begining, as the shaderAttributes are pregenerated for
        performance reasons """
        DebugObject.__init__(self, "GPU-FFT")

        self.size = N
        self.log2Size = int(math.log(N, 2))
        self.normalizationFactor = normalizationFactor

        # Create a ping and a pong texture, because we can't write to the
        # same texture while reading to it (that would lead to unexpected
        # behaviour, we could solve that by using an appropriate thread size,
        # but it works fine so far)
        self.pingTexture = Texture("FFTPing")
        self.pingTexture.setup2dTexture(
            self.size, self.size, Texture.TFloat, Texture.FRgba32)
        self.pongTexture = Texture("FFTPong")
        self.pongTexture.setup2dTexture(
            self.size, self.size, Texture.TFloat, Texture.FRgba32)
        self.sourceTex = sourceTex

        for tex in [self.pingTexture, self.pongTexture, sourceTex]:
            tex.setMinfilter(Texture.FTNearest)
            tex.setMagfilter(Texture.FTNearest)
            tex.setWrapU(Texture.WMClamp)
            tex.setWrapV(Texture.WMClamp)

        # Pregenerate weights & indices for the shaders
        self._computeWeighting()

        # Pre generate the shaders, we have 2 passes: Horizontal and Vertical
        # which both execute log2(N) times with varying radii
        self.horizontalFFTShader = Shader.loadCompute(Shader.SLGLSL,
            "Shader/Water/HorizontalFFT.compute")
        self.horizontalFFT = NodePath("HorizontalFFT")
        self.horizontalFFT.setShader(self.horizontalFFTShader)
        self.horizontalFFT.setShaderInput(
            "precomputedWeights", self.weightsLookupTex)
        self.horizontalFFT.setShaderInput("N", LVecBase2i(self.size))

        self.verticalFFTShader = Shader.loadCompute(Shader.SLGLSL,
            "Shader/Water/VerticalFFT.compute")
        self.verticalFFT = NodePath("VerticalFFT")
        self.verticalFFT.setShader(self.verticalFFTShader)
        self.verticalFFT.setShaderInput(
            "precomputedWeights", self.weightsLookupTex)
        self.verticalFFT.setShaderInput("N", LVecBase2i(self.size))

        # Create a texture where the result is stored
        self.resultTexture = Texture("Result")
        self.resultTexture.setup2dTexture(
            self.size, self.size, Texture.TFloat, Texture.FRgba16)
        self.resultTexture.setMinfilter(Texture.FTLinear)
        self.resultTexture.setMagfilter(Texture.FTLinear)

        # Prepare the shader attributes, so we don't have to regenerate them
        # every frame -> That is VERY slow (3ms per fft instance)
        self._prepareAttributes()
开发者ID:pennomi,项目名称:RenderPipeline,代码行数:59,代码来源:GPUFFT.py

示例3: load_shaders

 def load_shaders(self):
     shaders = Shader.load(Shader.SL_GLSL,
                           'gas_giant_vertex.glsl',
                           'gas_giant_fragment.glsl',
                           '',
                           "Shader/DefaultShaders/Opaque/tesscontrol.glsl",
                           "Shader/DefaultShaders/Opaque/tesseval.glsl")
     shaders = Shader.load(Shader.SL_GLSL,
                           'gas_giant_vertex.glsl',
                           'gas_giant_fragment.glsl')
     #convertToPatches(self.node_path)
     self.node_path.set_shader(shaders, 51)
开发者ID:croxis,项目名称:Panda-Core-Technology,代码行数:12,代码来源:saturntest.py

示例4: setShaders

    def setShaders(self):
        shaderV = Shader.load(Shader.SLGLSL, 
            "Shader/DefaultPostProcess.vertex",
            "Shader/OcclusionBlurV.fragment")
        self.targetV.setShader(shaderV)

        shaderH = Shader.load(Shader.SLGLSL, 
            "Shader/DefaultPostProcess.vertex",
            "Shader/OcclusionBlurH.fragment")
        self.targetH.setShader(shaderH)

        return [shaderV, shaderH]
开发者ID:croxis,项目名称:RenderPipeline,代码行数:12,代码来源:OcclusionBlurPass.py

示例5: setShaders

    def setShaders(self):
        shader = Shader.load(Shader.SLGLSL, 
            "Shader/DefaultPostProcess.vertex",
            "Shader/MotionBlur.fragment")
        self.target.setShader(shader)

        shaderDilate = Shader.load(Shader.SLGLSL, 
            "Shader/DefaultPostProcess.vertex",
            "Shader/MotionBlurDilate.fragment")
        self.targetDilate0.setShader(shaderDilate)
        self.targetDilate1.setShader(shaderDilate)

        return [shader, shaderDilate]
开发者ID:cesarmarinhorj,项目名称:RenderPipeline,代码行数:13,代码来源:MotionBlurPass.py

示例6: setShaders

    def setShaders(self):
        shader = Shader.load(Shader.SLGLSL, "Shader/DefaultPostProcess.vertex", "Shader/BloomExtract.fragment")
        self.target.setShader(shader)

        shaderV = Shader.load(Shader.SLGLSL, "Shader/DefaultPostProcess.vertex", "Shader/BloomBlurV.fragment")
        self.targetV.setShader(shaderV)

        shaderH = Shader.load(Shader.SLGLSL, "Shader/DefaultPostProcess.vertex", "Shader/BloomBlurH.fragment")
        self.targetH.setShader(shaderH)

        shaderMerge = Shader.load(Shader.SLGLSL, "Shader/DefaultPostProcess.vertex", "Shader/BloomMerge.fragment")
        self.targetMerge.setShader(shaderMerge)

        return [shader, shaderV, shaderH]
开发者ID:quiettus,项目名称:RenderPipeline,代码行数:14,代码来源:BloomPass.py

示例7: reload_shader

 def reload_shader(self):
     self.model.set_shader(Shader.load(Shader.SL_GLSL,
                                       vertex = "shader.vert",
                                       tess_control = "shader.tesc",
                                       tess_evaluation = "shader.tese",
                                       geometry = "shader.geom",
                                       fragment = "shader.frag"))
开发者ID:TheCheapestPixels,项目名称:panda_examples,代码行数:7,代码来源:shader.py

示例8: setShaders

    def setShaders(self):
        shader = Shader.load(Shader.SLGLSL, 
            "Shader/DefaultPostProcess.vertex",
            "Shader/CombineOcclusion.fragment")
        self.target.setShader(shader)

        return [shader]
开发者ID:rimij405,项目名称:RenderPipeline,代码行数:7,代码来源:OcclusionCombinePass.py

示例9: _makeFontShader

    def _makeFontShader(self):
        self.fontShader = Shader.make(Shader.SLGLSL, """
            #version 150
            uniform mat4 p3d_ModelViewProjectionMatrix;
            in vec4 p3d_Vertex;
            in vec2 p3d_MultiTexCoord0;
            uniform float displData[100];
            out vec2 texcoord;
            uniform vec2 pos;
            uniform vec2 size;

            void main() {
                int rawDispl = int(displData[gl_InstanceID]);
                ivec2 offsetDispl = ivec2( rawDispl % 16, rawDispl / 16);
                vec2 offsetCoordReal = vec2(offsetDispl.x / 16.0, (5.0 - offsetDispl.y) / 6.0);

                texcoord = p3d_MultiTexCoord0 / vec2(16,6) + offsetCoordReal;
                vec4 offset = vec4(gl_InstanceID*size.x*0.55 , 0, 0, 0) + vec4(pos.x, 0, pos.y, 0);
                vec4 finalPos = p3d_Vertex * vec4(size.x, size.x, size.x, 1.0) + offset;
                gl_Position = p3d_ModelViewProjectionMatrix * finalPos;
            }
            """, """
            #version 150
            #pragma file FastText.fragment
            in vec2 texcoord;
            uniform sampler2D font;
            uniform vec3 color;
            out vec4 result;
            void main() {
                float textFactor = texture(font, texcoord).x;
                result = vec4(color, textFactor);

            } 
        """)
开发者ID:Happy-Ferret,项目名称:RenderPipeline,代码行数:34,代码来源:FastText.py

示例10: _makeShader

def _makeShader(shaderEffects, baseShader=None):
    """
    
    Generates shader source from effects and converts it into a Panda3D shader object
    baseShader is source to inject effects into
    
    """

    
    
    source=shadereffects.makeSource(shaderEffects, baseShader)
    key=source
    if key not in builtEffectsShaders:
        if useShaderFiles:
            # preflatten should not impact anything much, but lets us get the full names
            shaderEffects=[s.flatten() for s in shaderEffects]
            name='debug('+','.join([e.name for e in shaderEffects])+')'
            outLoc='ShadersOut/'+name+'.sha'
            print 'Making Shader: '+outLoc
            
        builtEffectsShaders[key]=Shader.make(source)
      
        if useShaderFiles:
            fOut=open(outLoc, 'w')
            fOut.write(source)
            fOut.close()
        
    return builtEffectsShaders[key]
开发者ID:Craig-Macomber,项目名称:Panda3D-Shader-Generator,代码行数:28,代码来源:pandautil.py

示例11: __init__

    def __init__(self, terrain_model="content/models/terrain.egg"):
        myShader = Shader.load(Shader.SLGLSL, "content/shaders/terr_vert.glsl",
                        "content/shaders/terr_frag.glsl")
        self.terrain = loader.loadModel("content/models/terrain.egg")
        self.terrain.reparentTo(render)
        def prepareTexture(tex):
            tex.setMinfilter(Texture.FTLinearMipmapLinear)

        self.terrain.setShaderInput("tilingFactor", 50)

        dirtTex = loader.loadTexture("content/textures/sand.jpg")
        prepareTexture(dirtTex)

        self.terrain.setShaderInput("region1ColorMap", dirtTex)

        dirtTex = loader.loadTexture("content/textures/dirt.JPG")
        prepareTexture(dirtTex)

        self.terrain.setShaderInput("region2ColorMap", dirtTex)

        dirtTex = loader.loadTexture("content/textures/rock.JPG")
        prepareTexture(dirtTex)

        self.terrain.setShaderInput("region3ColorMap", dirtTex)

        dirtTex = loader.loadTexture("content/textures/snow.JPG")
        prepareTexture(dirtTex)

        self.terrain.setShaderInput("region4ColorMap", dirtTex)
        print self.terrain.ls();
        self.collider = self.terrain.find('**/Terrain')
        self.terrain.setShader(myShader)
开发者ID:kzerot,项目名称:ShipsAndSand,代码行数:32,代码来源:Level.py

示例12: __init__

 def __init__(self):
     # The basics
     ShowBase.__init__(self)
     base.disableMouse()
     base.setBackgroundColor(0.1, 0.1, 0.1)
     base.setFrameRateMeter(True)
     self.accept("escape", sys.exit)
     # Camera
     self.camera_orbit = base.render.attach_new_node("Camera orbit")
     self.camera_pitch = self.camera_orbit.attach_new_node("Camera pitch")
     base.camera.reparent_to(self.camera_pitch)
     base.camera.set_pos(0, -5, 0)
     # Camera control
     self.camera_movement = (0, 0)
     self.accept("arrow_up",       self.change_camera_movement, [ 0, -1])
     self.accept("arrow_up-up",    self.change_camera_movement, [ 0,  1])
     self.accept("arrow_down",     self.change_camera_movement, [ 0,  1])
     self.accept("arrow_down-up",  self.change_camera_movement, [ 0, -1])
     self.accept("arrow_left",     self.change_camera_movement, [-1,  0])
     self.accept("arrow_left-up",  self.change_camera_movement, [ 1,  0])
     self.accept("arrow_right",    self.change_camera_movement, [ 1,  0])
     self.accept("arrow_right-up", self.change_camera_movement, [-1,  0])
     base.taskMgr.add(self.move_camera, "Move camera")
     # Object
     self.model = loader.loadModel("models/smiley")
     self.model.reparent_to(base.render)
     shader = Shader.make(
         Shader.SL_GLSL,
         vertex = vertex_shader,
         fragment = fragment_shader,
     )
     self.model.set_shader(shader)
开发者ID:TheCheapestPixels,项目名称:panda_examples,代码行数:32,代码来源:shader.py

示例13: load

    def load(self, *args):
        """ Loads a shader in the order: vertex, fragment,
        geometry, tesseval, tesscontrol """

        newArgs = []
        toHash = ""

        for arg in args:
            if len(arg) < 1:
                newArgs.append("")
                continue
            content = self._handleIncludes(arg)
            newArgs.append(content)
            toHash += content
            self._writeDebugShader("Shader-" + str(arg), content)
            self._clearIncludeStack()

        # Check if we already have the result cached
        hashed = hash(toHash)
        if hashed in self._ShaderCache:
            # Cache entry found
            return self._ShaderCache[hashed]

        shaderName = args[1].replace("Shader", "").split(".")[0].lstrip("/")

        result = Shader.make(Shader.SLGLSL, *newArgs)
        self._ShaderCache[hashed] = result
        return result
开发者ID:rasteron,项目名称:RenderPipeline,代码行数:28,代码来源:BetterShader.py

示例14: __init__

    def __init__(self):
        load_prc_file_data("", """
            textures-power-2 none
            window-type offscreen
            win-size 100 100
            gl-coordinate-system default
            notify-level-display error
            print-pipe-types #f
        """)

        ShowBase.__init__(self)

        dest_tex = Texture()
        dest_tex.setup_2d_texture(2048, 2048, Texture.T_unsigned_byte, Texture.F_rgba8)
        cshader = Shader.load_compute(Shader.SL_GLSL, "grain.compute.glsl")
        node = NodePath("")
        node.set_shader(cshader)
        node.set_shader_input("DestTex", dest_tex)
        attr = node.get_attrib(ShaderAttrib)
        self.graphicsEngine.dispatch_compute(
            (2048 // 16, 2048 // 16, 1), attr, self.win.get_gsg())

        base.graphicsEngine.extract_texture_data(dest_tex, base.win.get_gsg())

        # Convert to single channel
        img = PNMImage(2048, 2048, 1, 255)
        dest_tex.store(img)
        img.set_num_channels(1)

        tex = Texture()
        tex.load(img)
        tex.write("grain.txo.pz")
开发者ID:aimoonchen,项目名称:RenderPipeline,代码行数:32,代码来源:generate.py

示例15: create_model

 def create_model(self):
     # Set up the vertex arrays
     vformat = GeomVertexFormat.get_v3c4()
     vdata = GeomVertexData("Data", vformat, Geom.UHStatic)
     vertex = GeomVertexWriter(vdata, 'vertex')
     color = GeomVertexWriter(vdata, 'color')
     geom = Geom(vdata)
     # Vertex data
     vertex.addData3f(1.5, 0, -1)
     color.addData4f(1, 0, 0, 1)
     vertex.addData3f(-1.5, 0, -1)
     color.addData4f(0, 1, 0, 1)
     vertex.addData3f(0, 0, 1)
     color.addData4f(0, 0, 1, 1)
     # Primitive
     tri = GeomTriangles(Geom.UHStatic)
     tri.add_vertex(2)
     tri.add_vertex(1)
     tri.add_vertex(0)
     tri.close_primitive()
     geom.addPrimitive(tri)
     # Create the actual node
     node = GeomNode('geom_node')
     node.addGeom(geom)
     np = NodePath(node)
     # Shader and initial shader vars
     np.set_shader(Shader.load(Shader.SL_GLSL, "shader/shader.vert", "shader/shader.frag"))
     np.set_shader_input("time", 0.0)
     # No instancing necessary
     #np.set_instance_count(27)
     # return np
     np.reparent_to(base.render)
     self.model = np
开发者ID:TheCheapestPixels,项目名称:panda_examples,代码行数:33,代码来源:shader.py


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