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


Python shader.Shader类代码示例

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


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

示例1: __init__

    def __init__(self, width, height, scale=2):
        """
        width, height:
            size of the window in pixels.
        scale:
            the size of the texture is (width//scale) x (height//scale).
        """
        pyglet.window.Window.__init__(self, width, height, caption='GrayScott Simulation',
                                      visible=False, vsync=False)
        self.reaction_shader = Shader('./glsl/default.vert', './glsl/reaction.frag')
        self.render_shader = Shader('./glsl/default.vert', './glsl/render.frag')
        self.pattern = DEFAULT_PATTERN
        self.palette = DEFAULT_PALETTE
        self.tex_width = width // scale
        self.tex_height = height // scale
        self.uv_texture = create_uv_texture(width//scale, height//scale)
        gl.glActiveTexture(gl.GL_TEXTURE0)
        gl.glBindTexture(self.uv_texture.target, self.uv_texture.id)

        # use an invisible buffer to do the computation.
        with FrameBuffer() as self.fbo:
            self.fbo.attach_texture(self.uv_texture)

        # why do we need this? the reason is in the 'on_mouse_drag' function.
        self.mouse_down = False

        # put all patterns in a list for iterating over them.
        self._species = list(SPECIES.keys())

        # set the uniforms and attributes in the two shaders.
        self.init_reaction_shader()
        self.init_render_shader()
开发者ID:biddy,项目名称:pywonderland,代码行数:32,代码来源:main.py

示例2: __init__

 def __init__(self, use_lut=False, lighted=False, gridsize=(0.0,0.0,0.0), elevation=0.0):
     self._lighted = lighted
     self._gridsize = gridsize
     self._gridwidth = (1.0,1.0,1.0)
     self._elevation = elevation
     interpolation = read_shader('bicubic.txt')
     light         = read_shader('phong.txt')
     lut           = read_shader('lut.txt')
     vertex        = read_shader('vertex_bicubic.txt')
     fragment      = read_shader('fragment_bicubic.txt')
     lut_code = light_code = grid_code = height_code = ''
     if use_lut:
         lut_code = 'color = texture1D_lut(lut, color.a);'
     if lighted:
         light_code = read_shader('light_bicubic.txt')
     if self._gridsize[0] or self._gridsize[1] or self._gridsize[2]:
         grid_code = read_shader('grid.txt')
     if self._elevation:
         height_code = read_shader('height_bicubic.txt')
     fragment  = fragment % (lut_code,grid_code,light_code)
     vertex    = vertex % (height_code)
     Shader.__init__(self,
       vert = [interpolation] + [vertex],
       frag = [interpolation] + [light] + [lut] + [fragment])
     self.kernel = build_kernel()
开发者ID:matthew-brett,项目名称:miniglumpy,代码行数:25,代码来源:bicubic.py

示例3: getShader

def getShader( frag, seed ):
    with open ("shaders/basicvert.glsl", "r") as vertfile:
      vert = vertfile.read()

    with open ("shaders/noise.glsl", "r") as noisefile:
      noise = noisefile.read()

    with open ("shaders/utils.glsl", "r") as utilsfile:
      utils = utilsfile.read()

    with open ("shaders/header.glsl", "r") as headerfile:
      header = headerfile.read()

    fullfrag = header + noise + utils + frag

    with open( "Output/" + str( seed ) + "/" + str( seed ) + ".glsl", "w") as text_file:
        text_file.write( frag )

    with open( "Output/" + str( seed ) + "/" + str( seed ) + "full.glsl", "w") as text_file:
        text_file.write( fullfrag )

    shader = Shader( vert, fullfrag )
    shader.bind()
    shader.uniformf( "iResolution", x, y )
    return shader
开发者ID:innesmck,项目名称:shaderbot,代码行数:25,代码来源:quad.py

示例4: W

class W(pyglet.window.Window):
    def __init__(self, sprite):
        super(W, self).__init__()
        self.mouse = [0,0]
        self.sprite = sprite
        self.shader = Shader(open('pass.vert').read(), open('RGB2Lab.glsl').read())

    def on_draw(self):
        x, y = self.mouse
        # glEnable(GL_LINE_SMOOTH)
        # glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)

        # glMatrixMode(GL_PROJECTION)
        # glLoadIdentity()
        # glOrtho(-1., 1., 1., -1., 0., 1.)

        # glMatrixMode(GL_MODELVIEW)
        # glLoadIdentity()

        self.shader.bind()
        self.sprite.draw()

        #self.shader.uniformf('C', *self.C)

        self.shader.unbind()

    def on_mouse_motion(self, x, y, dx, dy):
        self.mouse = [x, y]

    def on_mouse_press(self, x, y, buttons, modifiers):
        # capture window contents to buffer
        buf = pyglet.image.get_buffer_manager().get_color_buffer()
        image = pyglet_to_pil(buf)
        image.show()
开发者ID:sv3,项目名称:gift,代码行数:34,代码来源:render.py

示例5: loadShader

    def loadShader(self):
        self.gridShader = None
        with open("shaders/heightGrid.vs") as vsf:
            with  open("shaders/heightGrid.fs") as fsf:
                self.gridShader = Shader(vs=vsf.read(), fs=fsf.read())

        with open("shaders/water.vs") as vsf:
            with  open("shaders/water.fs") as fsf:
                self.waterShader = Shader(vs=vsf.read(), fs=fsf.read())
开发者ID:Dejmas,项目名称:Terrain,代码行数:9,代码来源:terrain.py

示例6: __init__

class FloorSpots:
    def __init__(self, floor_color, background_color, y=0):
        self._floor_color = floor_color
        self._y = y
        self._display_list_id = None
        self._shader = Shader(
            radius = FLOOR_SPOT_RADIUS * 2 * FLOOR_GRID_SIZE * 1.5,
            background_color = background_color)

    def render(self, center_x, center_z, camera_x, camera_z):
        self._draw_floor_spots(
            center_x,
            center_z)
        self._shader.render(
            x=-camera_x,
            y=0,
            z=-camera_z)

    def _draw_floor_spots(self, center_x, center_z):
        cell_size = FLOOR_SPOT_RADIUS * 2
        quantified_center_x = int(center_x / cell_size / 2) * cell_size * 2
        quantified_center_z = int(center_z / cell_size) * cell_size
        for nx in range(FLOOR_GRID_SIZE):
            x = quantified_center_x + (nx - float(FLOOR_GRID_SIZE)/2 + 0.5) * cell_size
            if nx % 2 == 0:
                offset_z = 0
            else:
                offset_z = FLOOR_SPOT_RADIUS
            for nz in range(FLOOR_GRID_SIZE):
                z = offset_z + quantified_center_z + (nz - float(FLOOR_GRID_SIZE)/2 + 0.5) * cell_size
                self._draw_floor_spot(x=x, z=z)

    def _draw_floor_spot(self, x, z, y=0):
        if self._display_list_id is None:
            self._create_floor_spot_display_list()
        glPushMatrix()
        glTranslatef(x, y, z)
        glCallList(self._display_list_id)
        glPopMatrix()

    def _create_floor_spot_display_list(self, resolution=15):
        color_r, color_g, color_b, color_a = self._floor_color
        angle_increment = (float) (2 * math.pi / resolution);
        self._display_list_id = glGenLists(1)
        glNewList(self._display_list_id, GL_COMPILE)
        glBegin(GL_TRIANGLE_FAN)
        glColor4f(*self._floor_color)
        glVertex3f(0, 0, 0)
        glColor4f(color_r, color_g, color_b, 0)
        for i in range(resolution):
            angle1 = angle_increment * i
            angle2 = angle_increment * (i+1)
            glVertex3f(math.cos(angle1) * FLOOR_SPOT_RADIUS, 0, math.sin(angle1) * FLOOR_SPOT_RADIUS)
            glVertex3f(math.cos(angle2) * FLOOR_SPOT_RADIUS, 0, math.sin(angle2) * FLOOR_SPOT_RADIUS)
        glEnd()
        glEndList()
开发者ID:gaborpapp,项目名称:AIam,代码行数:56,代码来源:floor_spots.py

示例7: draw

    def draw(self):
        model = Matrix.identity()

        # translate
        model[3,0] = self.pos.x + (self.dir == -1 and 1.0 or 0.0)
        model[3,1] = self.pos.y
        model[0,0] = self.dir

        Shader.upload_model(model)
        self.texture.texture_bind()
        self.vbo.draw()
开发者ID:ext,项目名称:scfa,代码行数:11,代码来源:player.py

示例8: uiShaderGroup

class uiShaderGroup(uiGroup):
    
    def __init__(self, order, window, vertex_shader, fragment_shader, **kwargs):
        super(uiShaderGroup, self).__init__(order, window, **kwargs)

        self.shader = Shader(vertex_shader, fragment_shader)

    def set_state(self):
        self.shader.bind()
        #self.shader.uniform_matrixf('projection', camera.matrix * m)
    
    def unset_state(self):
        self.shader.unbind()
开发者ID:UIKit0,项目名称:pyglet-bits,代码行数:13,代码来源:ui2d.py

示例9: bind

 def bind(self, texture, lut=None):
     ''' Bind the program, i.e. use it. '''
     Shader.bind(self)
     if lut is not None:
         gl.glActiveTexture(gl.GL_TEXTURE1)
         gl.glBindTexture(lut.target, lut.id)
         self.uniformi('lut', 1)
     gl.glEnable(texture.target)
     gl.glActiveTexture(gl.GL_TEXTURE0)
     gl.glBindTexture(texture.target, texture.id)
     self.uniformi('texture', 0)
     self.uniformf('elevation', self._elevation)
     self.uniformf('pixel', 1.0/texture.width, 1.0/texture.height)
     self.uniformf('gridsize', *self._gridsize)
     self.uniformf('gridwidth', *self._gridwidth)
     self.uniformi('lighted', self._lighted)
开发者ID:matthew-brett,项目名称:miniglumpy,代码行数:16,代码来源:bilinear.py

示例10: __init__

	def __init__(self):
		super(JuliaWindow, self).__init__(caption = 'julia', width = 512, height = 512)

		self.C = (-0.70176, -0.3842)

		shader_path = 'julia'
		self.shader = Shader(''.join(open('%s.v.glsl' % shader_path)), ''.join(open('%s.f.glsl' % shader_path)))
开发者ID:msarch,项目名称:py,代码行数:7,代码来源:julia-explorer.py

示例11: __init__

class FloorGrid:
    def __init__(self, num_cells, size, floor_color, background_color, y=0):
        self._num_cells = num_cells
        self._size = size
        self._floor_color = floor_color
        self._y = y
        self._cell_size = float(self._size) / self._num_cells
        self._hypotenuse = math.sqrt(self._cell_size * self._cell_size * 2)
        self._shader = Shader(
            radius = math.sqrt(self._size * self._size * 2),
            background_color = background_color)

    def render(self, center_x, center_z, camera_x, camera_z):
        self._draw_grid(center_x, center_z)
        self._shader.render(-camera_x, 0, -camera_z)

    def _draw_grid(self, center_x, center_z):
        z1 = - self._size/2
        z2 = + self._size/2
        x1 = - self._size/2
        x2 = + self._size/2

        glColor4f(*self._floor_color)
        glLineWidth(1.4)

        quantified_center_x = int(center_x / self._hypotenuse) * self._hypotenuse
        quantified_center_z = int(center_z / self._hypotenuse) * self._hypotenuse
        glPushMatrix()
        glTranslatef(quantified_center_x, 0, quantified_center_z)
        glRotatef(45, 0, 1, 0)

        for n in range(self._num_cells):
            glBegin(GL_LINES)
            x = x1 + float(n) * self._cell_size
            glVertex3f(x, self._y, z1)
            glVertex3f(x, self._y, z2)
            glEnd()

        for n in range(self._num_cells):
            glBegin(GL_LINES)
            z = z1 + float(n) * self._cell_size
            glVertex3f(x1, self._y, z)
            glVertex3f(x2, self._y, z)
            glEnd()

        glPopMatrix()
开发者ID:gaborpapp,项目名称:AIam,代码行数:46,代码来源:floor_grid.py

示例12: __init__

	def __init__(self):
		# Setup the GLSL program
		with open('molgl.vert','r') as f:
			vert = f.readlines()
		with open('molgl.frag','r') as f:
			frag = f.readlines()
		self.shader = Shader(vert=vert, frag=frag)
		
		# Some parameters
		glEnable(GL_DEPTH_TEST)
		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)
开发者ID:amiller,项目名称:graphicsii,代码行数:11,代码来源:glrender.py

示例13: __init__

    def __init__(self, width, height, pattern, scale=2):
        '''
        width, height:
            size of the window in pixels.
        scale:
            the size of the texture is (width//scale) x (height//scale).
        pattern:
            a name in dict 'species'.
        '''
        pyglet.window.Window.__init__(self, width, height, caption='GrayScott Simulation',
                                      visible=False, vsync=False)

        # we will need two shaders, one for computing the reaction and diffusion,
        # and one for coloring the uv_texture.
        self.reaction_shader = Shader.from_files('default.vert', 'reaction.frag')
        self.render_shader = Shader.from_files('default.vert', 'render.frag')

        self.pattern = pattern
        self.palette = GrayScott.palette_default

        self.tex_width = width // scale
        self.tex_height = height // scale
        self.uv_texture = create_uv_texture(width // scale, height // scale)
        # the texture is bind to unit '0'.
        gl.glActiveTexture(gl.GL_TEXTURE0)
        gl.glBindTexture(self.uv_texture.target, self.uv_texture.id)

        # set the uniforms and attributes in the two shaders.
        self.init_reaction_shader()
        self.init_render_shader()

        # we need a framebuffer to do the offscreen rendering.
        # once we finished computing the reaction-diffusion step with the reaction_shader,
        # we render the result to this 'invisible' buffer since we do not want to show it.
        # the final image is further colored and will be rendered to the window.
        with FrameBuffer() as self.fbo:
            self.fbo.attach_texture(self.uv_texture)

        # why do we need this?
        # the reason is in the 'on_mouse_drag' function.
        self.mouse_down = False
开发者ID:hooloong,项目名称:gitpython,代码行数:41,代码来源:main.py

示例14: JuliaWindow

class JuliaWindow(pyglet.window.Window):
	def __init__(self):
		super(JuliaWindow, self).__init__(caption = 'julia', width = 512, height = 512)

		self.C = (-0.70176, -0.3842)

		shader_path = 'julia'
		self.shader = Shader(''.join(open('%s.v.glsl' % shader_path)), ''.join(open('%s.f.glsl' % shader_path)))

	def on_mouse_motion(self, x, y, dx, dy):
		self.C = (6. * ((float(x) / window.width) - .5), 6 * ((float(y) / window.height) - .5))

	def on_draw(self):
		glMatrixMode(GL_PROJECTION)
		glLoadIdentity()
		glOrtho(-1., 1., 1., -1., 0., 1.)

		glMatrixMode(GL_MODELVIEW)
		glLoadIdentity()

		self.shader.bind()
		self.shader.uniformf('C', *self.C)

		glBegin(GL_QUADS)
		glVertex2i(-1, -1)
		glTexCoord2i(-2, -2)
		glVertex2f(1, -1)
		glTexCoord2i(2, -2)
		glVertex2i(1,  1)
		glTexCoord2i(2, 2)
		glVertex2i(-1,  1)
		glTexCoord2i(-2, 2)
		glEnd()
		self.shader.unbind()
开发者ID:msarch,项目名称:py,代码行数:34,代码来源:julia-explorer.py

示例15: __init__

 def __init__(self, num_cells, size, floor_color, background_color,
              board_color1, board_color2, y=0):
     self._num_cells = num_cells
     self._size = size
     self._board_color1 = board_color1
     self._board_color2 = board_color2
     self._y = y
     self._cell_size = float(self._size) / self._num_cells
     self._hypotenuse = math.sqrt(self._cell_size * self._cell_size * 2)
     self._shader = Shader(
         radius = math.sqrt(self._size * self._size * 2) * 0.55,
         background_color = background_color)
     self._grid_display_list_id = None
开发者ID:gaborpapp,项目名称:AIam,代码行数:13,代码来源:floor_checkerboard.py


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