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


Python Shader.uniformi方法代码示例

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


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

示例1: ShaderWindow

# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import uniformi [as 别名]

#.........这里部分代码省略.........
        self.p.append(permutation[i % len(permutation)])

  def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
    self.x -= dx * self.zoom;
    self.y -= dy * self.zoom;
    
  def on_mouse_release(self, x, y, button, modifiers):
    print "x: {}, y: {}, z: {}, zoom: {}, octs: {}, freq: {}".format(self.x, self.y, self.z, self.zoom, self.octives, self.freq)

  def on_mouse_scroll(self, x, y, scroll_x, scroll_y):
    self.zoom -= scroll_y * 0.0025;
    print "x: {}, y: {}, z: {}, zoom: {}, octs: {}, freq: {}".format(self.x, self.y, self.z, self.zoom, self.octives, self.freq)

  def on_key_release(self, symbol, modifiers):
    if symbol == pyglet.window.key.F2:
      self.saveFromShader()
    elif symbol == pyglet.window.key.Q:
      self.x += 0.1;
    elif symbol == pyglet.window.key.A:
      self.x -= 0.1;
    elif symbol == pyglet.window.key.W:
      self.y += 0.1;
    elif symbol == pyglet.window.key.S:
      self.y -= 0.1;
    elif symbol == pyglet.window.key.E:
      self.z += 0.01;
    elif symbol == pyglet.window.key.D:
      self.z -= 0.01;
    elif symbol == pyglet.window.key.R:
      self.zoom += 0.0025;
    elif symbol == pyglet.window.key.F:
      self.zoom -= 0.0025;
    elif symbol == pyglet.window.key.T:
      self.octives += 1;
    elif symbol == pyglet.window.key.G:
      self.octives -= 1;
    elif symbol == pyglet.window.key.Y:
      self.freq += 0.01;
    elif symbol == pyglet.window.key.H:
      self.freq -= 0.01;
    print "x: {}, y: {}, z: {}, zoom: {}, octs: {}, freq: {}".format(self.x, self.y, self.z, self.zoom, self.octives, self.freq)
    
  def saveFromShader(self):
    a = (GLubyte * (4 * self.w * self.h))(0)
    glReadPixels(0, 0, self.w, self.h, GL_RGBA, GL_UNSIGNED_BYTE, a)
    image = pyglet.image.ImageData(self.w, self.h, 'RGBA', a)
    scriptPath = os.path.dirname(os.path.realpath(__file__))
    filePath = scriptPath + "/TESTSAVE_" + time.strftime("%Y%m%d_%H%M%S") + ".png"
    print "save to {}".format(filePath)
    image.save(filePath)

  def getPermutation(self):
    return [
      151,160,137, 91, 90, 15,131, 13,201, 95, 96, 53,194,233,  7,225,
      140, 36,103, 30, 69,142,  8, 99, 37,240, 21, 10, 23,190,  6,148,
      247,120,234, 75,  0, 26,197, 62, 94,252,219,203,117, 35, 11, 32,
       57,177, 33, 88,237,149, 56, 87,174, 20,125,136,171,168, 68,175,
       74,165, 71,134,139, 48, 27,166, 77,146,158,231, 83,111,229,122,
       60,211,133,230,220,105, 92, 41, 55, 46,245, 40,244,102,143, 54,
       65, 25, 63,161,  1,216, 80, 73,209, 76,132,187,208, 89, 18,169,
      200,196,135,130,116,188,159, 86,164,100,109,198,173,186,  3, 64,
       52,217,226,250,124,123,  5,202, 38,147,118,126,255, 82, 85,212,
      207,206, 59,227, 47, 16, 58, 17,182,189, 28, 42,223,183,170,213,
      119,248,152,  2, 44,154,163, 70,221,153,101,155,167, 43,172,  9,
      129, 22, 39,253, 19, 98,108,110, 79,113,224,232,178,185,112,104,
      218,246, 97,228,251, 34,242,193,238,210,144, 12,191,179,162,241,
       81, 51,145,235,249, 14,239,107, 49,192,214, 31,181,199,106,157,
      184, 84,204,176,115,121, 50, 45,127,  4,150,254,138,236,205, 93,
      222,114, 67, 29, 24, 72,243,141,128,195, 78, 66,215, 61,156,180,
    ]

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

    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()

    self.shader.bind()
    self.shader.uniformi('p', *self.p)
    self.shader.uniformf('x', *[self.x])
    self.shader.uniformf('y', *[self.y])
    self.shader.uniformf('z', *[self.z])
    self.shader.uniformf('zoom', *[self.zoom])
    self.shader.uniformi('octives', *[self.octives])
    self.shader.uniformf('freq', *[self.freq])

    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:MichaelReel,项目名称:pyxamples,代码行数:104,代码来源:run_procedural_shader.py

示例2: __init__

# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import uniformi [as 别名]
class Unwrapper:
    """
    This unwrapper takes an image path and a parsed frame and fulfills
    the operations required to draw the unwrapped image.

    The draw operations MUST be called inside of the "on_draw" callback
    passed to "start_unwrap_window" in order to be fulfilled.  This class
    cannot function without an OpenGL window.
    """
    def __init__(self):

        # Create the shader.
        self.shader = Shader(vertex_shader, fragment_shader)

        # Set the texture unit.
        self.shader.bind()
        self.shader.uniformi('tex0', 0)
        self.shader.unbind()

        # Create a quad geometry to fit the whole window that will be the target of our drawing.
        self.batch = pyglet.graphics.Batch()
        self.batch.add(4, GL_QUADS, None, ('v2i', (0,0, 1,0, 1,1, 0,1)), ('t2f', (0,0, 1,0, 1,1, 0,1)))

    def update(self, img_path, frame):
        """
        Update the texture to the given image path, and update the shaders with the new
        frame information to unwrap the given image correctly.
        """

        # Recalculate the variables required to unwrap the new image.
        projector = PolygonProjector(frame.center_point, frame.center_vertices)
        angle_bounds = [v.angle for v in projector.vertices]
        radii = [p.center_dist for p in projector.projectors]
        angles = [p.center_angle for p in projector.projectors]

        # Load the new image, and update the size variables.
        self.texture = pyglet.image.load(img_path).get_texture()
        region_w, region_h = self.texture.width, self.texture.height
        actual_w, actual_h = self.texture.owner.width, self.texture.owner.height

        # Update the shader variables.
        self.shader.bind()
        self.shader.uniformf('region_size', region_w, region_h)
        self.shader.uniformf('actual_size', actual_w, actual_h)
        self.shader.uniformfv('angle_bounds', 1, angle_bounds)
        self.shader.uniformfv('radii', 1, radii)
        self.shader.uniformfv('angles', 1, angles)
        self.shader.uniformi('count', len(radii))
        self.shader.unbind()

    def draw(self):
        """Draw the unwrapped image to the window."""
        glBindTexture(self.texture.target, self.texture.id)
        self.shader.bind()
        self.batch.draw()
        self.shader.unbind()
        glBindTexture(self.texture.target, 0)

    def save_image(self, filename):
        """Save the current window image to the given filename."""
        pyglet.image.get_buffer_manager().get_color_buffer().save(filename)

    def get_fps(self):
        """Get the current framerate in frames per second."""
        return pyglet.clock.get_fps()
开发者ID:shaunlebron,项目名称:super-hexagon-unwrapper,代码行数:67,代码来源:unwrap.py

示例3: __init__

# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import uniformi [as 别名]
class Kostka:
    SHADER = True
    def __init__(self, terrain):
        self.position   = [25, 0, 25]
        self._direction = [ 1, 0, 0 ]
        self.speed      =   0
        self.t          =   terrain
        self.yrot       =   90.
        self.input      = [ False, False ]

        textureSurface = image.load('data/rockbump.jpg')
        self.text0 = textureSurface.get_mipmapped_texture()

        textureSurface = image.load('data/rockbump.tga')
        self.nmap = textureSurface.get_mipmapped_texture()

        self.model = cube();

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

    def _calcYrot(self,dt):
        if self.input[0] :
            self.yrot += 100.*dt
        if self.input[1] :
            self.yrot -= 100.*dt

    def calcDirection(self,dt):
        self._calcYrot(dt)
        x = sin(radians(self.yrot))
        z = cos(radians(self.yrot))
        self._direction = x, 0, z

    def update(self, dt):
        self.calcDirection(dt)
        x, y, z = self.position
        dx = self._direction[0] * self.speed * dt
        dz = self._direction[2] * self.speed * dt
        self.position = x+dx, y, z+dz
    def setMaterial(self):
        glDisable(GL_CLIP_PLANE0)
        glEnable(GL_TEXTURE_2D)
        glActiveTexture(GL_TEXTURE0); 
        glBindTexture(GL_TEXTURE_2D, self.text0.id); 
        if Kostka.SHADER :
            glActiveTexture(GL_TEXTURE1); 
            glBindTexture(GL_TEXTURE_2D, self.nmap.id);
            self.cubeShader.uniformi("tex0", 0 )
            self.cubeShader.uniformi("nmap", 1 )

        #glDisable(GL_BLEND)
        
    def draw(self):
        x, y, z = self.position
        y = self.t.Height(x, z, floating=True)
        from math import floor
        xf = int( floor(x) )
        zf = int( floor(z) )
        
        glColor3f(0,0,1)
        sizes = (GLfloat*10)()
        step = (GLfloat*1)()
        glGetFloatv(GL_POINT_SIZE_RANGE,sizes);
        glGetFloatv(GL_POINT_SIZE_GRANULARITY, step);
        curSize = sizes[0] + 5*step[0]
        glPointSize(curSize);
    
        if xf >= 0 and xf < self.t.a-1 \
        and zf >= 0 and zf < self.t.a-1 :
            glBegin(GL_POINTS)
            # (x, self.hm[z][x], z )
            glVertex3f(xf  , self.t.hm[zf  ][xf  ], zf  )
            glVertex3f(xf+1, self.t.hm[zf  ][xf+1], zf  )
            glVertex3f(xf  , self.t.hm[zf+1][xf  ], zf+1)
            glVertex3f(xf+1, self.t.hm[zf+1][xf+1], zf+1)

            glEnd()
        #glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
        # cube
        if Kostka.SHADER : self.cubeShader.Use()
        self.setMaterial()
        glTranslatef(x, y, z)
        glColor3f(1,1,1)
        self.model.draw(GL_TRIANGLES)
        if Kostka.SHADER : self.cubeShader.Unuse()
        glTranslatef(-x, -y, -z)
开发者ID:Dejmas,项目名称:Terrain,代码行数:93,代码来源:main.py

示例4: Terrain

# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import uniformi [as 别名]

#.........这里部分代码省略.........
        glDepthFunc(GL_LEQUAL);
        glShadeModel(GL_SMOOTH);
        glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, vec(.34, .34, .34, 1))
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, vec(.3, .3, .3, 1))
        glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, vec(0.6, 0.6, 0.6, 1))
        glMaterialfv(GL_FRONT, GL_COLOR_INDEXES, vec(0.5, 1, 1))
        glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 45)
        #glColor4f(0.1,0.6,.6,0.4)
        glEnable(GL_TEXTURE_2D)
        glActiveTexture(GL_TEXTURE0); 
        glBindTexture(GL_TEXTURE_2D, self.text0.id); 
        glActiveTexture(GL_TEXTURE1); 
        glBindTexture(GL_TEXTURE_2D, self.text1.id);
        glActiveTexture(GL_TEXTURE2); 
        glBindTexture(GL_TEXTURE_2D, self.text2.id);
        glActiveTexture(GL_TEXTURE3); 
        glBindTexture(GL_TEXTURE_2D, self.text3.id);
    
        def m3dTransformVector3(vOut3f, v3f, m33f):
            vOut3f[0] = m33f[0] * v3f[0] + m33f[4] * v3f[1] + m33f[8] *  v3f[2] + m33f[12]
            vOut3f[1] = m33f[1] * v3f[0] + m33f[5] * v3f[1] + m33f[9] *  v3f[2] + m33f[13]
            vOut3f[2] = m33f[2] * v3f[0] + m33f[6] * v3f[1] + m33f[10] * v3f[2] + m33f[14]

        lightPos0Eye = [0,0,0,0]
        mv = (GLfloat * 16)()
        glPushMatrix();
        self.lightRotation = (self.lightRotation + 0.3) % 360;
        glRotatef(self.lightRotation, 0.0, 0.0, 1.0);
        glGetFloatv(GL_MODELVIEW_MATRIX, mv);
        m3dTransformVector3(lightPos0Eye, vec(50, 100, 50), mv);
        glPopMatrix();

        if SHADER:
            self.gridShader.uniformi("blendTexture", 0) 
            self.gridShader.uniformi("text1", 1)
            self.gridShader.uniformi("text2", 2)
            self.gridShader.uniformi("text3", 3)
            #self.gridShader.uniformf("lightPos[0]", *lightPos0Eye[:3])
            #self.gridShader.uniformf("density", 1 )

    def drawHeightGrid( self ) :
        if SHADER: self.gridShader.Use()
        self.setMaterial()
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST )
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR )
        if not 'terrain' in self.dlists :
            self.dlists['terrain'] = glGenLists(1)
            glNewList(self.dlists['terrain'], GL_COMPILE )
            self.vertex_list . draw( pyglet.gl.GL_TRIANGLES )
            glEndList()

        glCallList(self.dlists['terrain'])
        if SHADER: self.gridShader.Unuse()
        glDisable(GL_TEXTURE_2D)

    def draw( self, cam_height ):
        glFogf(GL_FOG_DENSITY, 0)
        # Draw the terrain above water
        if cam_height < self.water_line :
            glFogfv(GL_FOG_COLOR, vec(*self.water_color))
            glFogf(GL_FOG_DENSITY, .1)
            glEnable(GL_FOG)
        glPushAttrib(GL_STENCIL_BUFFER_BIT | GL_TRANSFORM_BIT | GL_CURRENT_BIT)
        glColor3f(.3, .59, .11)
        glClipPlane(GL_CLIP_PLANE0, (ctypes.c_double * 4)(0, 1, 0, -self.water_line))
        glEnable(GL_CLIP_PLANE0)
开发者ID:Dejmas,项目名称:Terrain,代码行数:70,代码来源:terrain.py

示例5: vec3

# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import uniformi [as 别名]
        // kill if we do not have either 3 or 2 neighbours
        current *= vec3(equal(neighbours, vec3(2.0))) + vec3(equal(neighbours, vec3(3.0)));

        // fade the current pixel as it ages
        current -= vec3(greaterThan(current, vec3(0.4)))*0.05;

        // write out the pixel
        gl_FragColor = vec4(current, 1.0);
    }
}
'''])
 
# bind our shader
shader.bind()
# set the correct texture unit
shader.uniformi('tex0', 0)
# unbind the shader
shader.unbind()
 
# create the texture
# texture = pyglet.image.Texture.create(window.width, window.height, GL_RGBA) # Blank texture
texture = pyglet.image.load('game_of_life_init.png').get_texture()

# create a fullscreen quad
batch = pyglet.graphics.Batch()
batch.add(4, GL_QUADS, None, ('v2i', (0,0, 1,0, 1,1, 0,1)), ('t2f', (0,0, 1.0,0, 1.0,1.0, 0,1.0)))

# utility function to copy the framebuffer into a texture
def copyFramebuffer(tex, *size):
    # if we are given a new size
    if len(size) == 2:
开发者ID:MichaelReel,项目名称:pyxamples,代码行数:33,代码来源:game_of_life.py

示例6: open

# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import uniformi [as 别名]
    # texture_p holds pointer mask
    # ----------------------------
    D = np.ones((8,8,4),dtype=np.ubyte)*0
    #D[4:12:,4:12] = 0
    image = pyglet.image.ImageData(D.shape[1],D.shape[0],'RGBA',D.ctypes.data)
    sprite = pyglet.sprite.Sprite(image)


    # Reaction-diffusion shader
    # -------------------------
    vertex_shader   = open('./reaction-diffusion.vert').read()
    fragment_shader = open('./reaction-diffusion.frag').read()
    reaction_shader = Shader(vertex_shader, fragment_shader)

    reaction_shader.bind()
    reaction_shader.uniformi('texture', 0)
    reaction_shader.uniformi('params',  1)
    reaction_shader.uniformi('display', 2)
    reaction_shader.uniformf('dt', dt)
    reaction_shader.uniformf('dx', 1.0/width)
    reaction_shader.uniformf('dy', 1.0/height)
    reaction_shader.uniformf('dd', dd)
    reaction_shader.unbind()

    # Color shader
    # ------------
    vertex_shader   = open('./color.vert').read()
    fragment_shader = open('./color.frag').read()
    color_shader    = Shader(vertex_shader, fragment_shader)

    color_shader.bind()
开发者ID:rougier,项目名称:grayscott,代码行数:33,代码来源:grayscott.py

示例7: GLRender

# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import uniformi [as 别名]
class GLRender(object):
	
	scale = 1
	angles = [0,0,0]
	mol = None
	envTex = None
	
	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)
	
	def applySceneTransforms(self):
		gluLookAt(0, 0, 2*self.mol.radius, 0, 0, 0, 0, 1, 0); # Push molecule away from the origin along -Z direction.
		glScalef(self.scale,self.scale,self.scale);
		def mouse_rotate(xAngle, yAngle, zAngle):
			glRotatef(xAngle, 1.0, 0.0, 0.0);
			glRotatef(yAngle, 0.0, 1.0, 0.0);
			glRotatef(zAngle, 0.0, 0.0, 1.0);
		mouse_rotate(self.angles[0],self.angles[1],self.angles[2]);
		glTranslatef(-self.mol.x, -self.mol.y, -self.mol.z); # Bring molecue center to origin
		
	def set_molecule(self, mol):
		self.mol = mol
		
	def set_envmap(self, envmap):
		if self.envTex: glDeleteTextures(self.envTex)
		self.envTex = glGenTextures(1);
		glBindTexture(GL_TEXTURE_2D, self.envTex);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, envmap.shape[0], envmap.shape[1], 0, 
			GL_RGB, GL_FLOAT, envmap);
		glBindTexture(GL_TEXTURE_2D, 0);

	def render(self):
		glEnable(GL_TEXTURE_2D)
		glBindTexture(GL_TEXTURE_2D, self.envTex)
		self.applySceneTransforms()
		self.shader.bind()
		#self.shader.uniformf('scale',self.scale)
		self.shader.uniformf('scale', 1)
		self.shader.uniformi('tex', 0)
		self.shader.uniformi('envMapping', 1)

		# Draw all the sphere
		for sphere in self.mol.spheres:
			glColor3f(sphere.r, sphere.g, sphere.b);
			glPushMatrix()
			glTranslatef(sphere.x, sphere.y, sphere.z);
			q = gluNewQuadric()
			gluSphere(q, sphere.radius,20,20)
			#glutSolidSphere(sphere.radius,20,20);
			glPopMatrix()
		self.shader.unbind()
		glBindTexture(GL_TEXTURE_2D, 0)
		glDisable(GL_TEXTURE_2D)
开发者ID:amiller,项目名称:graphicsii,代码行数:68,代码来源:glrender.py


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