本文整理汇总了Python中shader.Shader.set_uniformf方法的典型用法代码示例。如果您正苦于以下问题:Python Shader.set_uniformf方法的具体用法?Python Shader.set_uniformf怎么用?Python Shader.set_uniformf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shader.Shader
的用法示例。
在下文中一共展示了Shader.set_uniformf方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GrayScott
# 需要导入模块: from shader import Shader [as 别名]
# 或者: from shader.Shader import set_uniformf [as 别名]
class GrayScott(pyglet.window.Window):
"""
----------------------------------------------------------
| This simulation uses mouse and keyboard to control the |
| patterns and colors. At any time you may click or drag |
| your mouse to draw on the screen. |
| |
| Keyboad control: |
| 1. press 'space' to clear the window to blank. |
| 2. press 'p' to change to a random palette. |
| 3. press 's' to change to another pattern. |
| 4. press 'Ctrl + r' to reset to default. |
| 5. press 'Ctrl + s' to save current config. |
| 6. press 'Ctrl + o' to load config from json file. |
| 7. press 'Enter' to take screenshots. |
| 8. press 'Esc' to exit. |
----------------------------------------------------------
"""
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()
def set_viewport(self, width, height):
gl.glViewport(0, 0, width, height)
gl.glMatrixMode(gl.GL_PROJECTION)
gl.glLoadIdentity()
gl.glOrtho(0, 1, 0, 1, -1, 1)
gl.glMatrixMode(gl.GL_MODELVIEW)
def on_draw(self):
gl.glClearColor(0, 0, 0, 0)
self.clear()
# since we are rendering to the invisible framebuffer,
# the size is the texture's size.
self.set_viewport(self.tex_width, self.tex_height)
with self.fbo:
with self.reaction_shader:
gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
# now we render to the actual window, hence the size is window's size.
self.set_viewport(self.width, self.height)
with self.render_shader:
gl.glDrawArrays(gl.GL_TRIANGLE_STRIP, 0, 4)
def use_pattern(self, pattern):
self.pattern = pattern
rU, rV, feed, kill = SPECIES[pattern]
with self.reaction_shader:
self.reaction_shader.set_uniformf('feed', feed)
self.reaction_shader.set_uniformf('kill', kill)
self.reaction_shader.set_uniformf('rU', rU)
self.reaction_shader.set_uniformf('rV', rV)
def use_palette(self, palette):
self.palette = palette
color1, color2, color3, color4, color5 = palette
with self.render_shader:
self.render_shader.set_uniformf('color1', *color1)
self.render_shader.set_uniformf('color2', *color2)
self.render_shader.set_uniformf('color3', *color3)
self.render_shader.set_uniformf('color4', *color4)
self.render_shader.set_uniformf('color5', *color5)
def init_reaction_shader(self):
with self.reaction_shader:
self.reaction_shader.set_uniformi('uv_texture', 0)
self.reaction_shader.set_uniformf('dx', 1.0/self.tex_width)
self.reaction_shader.set_uniformf('dy', 1.0/self.tex_height)
# the order of the vertices and texcoords matters,
#.........这里部分代码省略.........