def _init_shader(self): vertex_code = """ #version 120 attribute float particle_size; void main() { gl_PointSize = particle_size; gl_Position = ftransform(); gl_FrontColor = gl_Color; } """ frag_code = """ #version 120 uniform sampler2D sprite_texture; void main() { gl_FragColor = gl_Color * texture2D(sprite_texture, gl_PointCoord); } """ self.sprite_shader = ShaderProgram.simple_program( 'sprite', vertex_code, frag_code) self.particle_size_idx = gl.glGetAttribLocation( self.sprite_shader.program, b'particle_size')
def _init_shader(self): vertex_code = """ #version 120 attribute float particle_size; void main() { gl_PointSize = particle_size; gl_Position = ftransform(); gl_FrontColor = gl_Color; } """ frag_code = """ #version 120 uniform sampler2D sprite_texture; void main() { gl_FragColor = gl_Color * texture2D(sprite_texture, gl_PointCoord); } """ self.sprite_shader = ShaderProgram.simple_program('sprite', vertex_code, frag_code) self.particle_size_idx = gl.glGetAttribLocation(self.sprite_shader.program, b'particle_size')
uniform sampler2D u_texture; float rand(vec2 co) { return fract(sin(dot(co.xy ,vec2(92.,80.))) + cos(dot(co.xy ,vec2(41.,62.))) * 5.1); } void main() { vec2 rnd = vec2(0.0); rnd = vec2(rand(v_texCoord),rand(v_texCoord)); glFragColor = texture2D(u_texture, v_texCoord+rnd*0.05); } """ from cocos.shader import ShaderProgram ShaderProgram.simple_program("frost", vert_shader, frag_shader) class Zen(cocos.layer.Layer): def __init__(self): super(Zen, self).__init__() sprite = cocos.sprite.Sprite("pebbleconcrete.jpg") sprite.position = (100, 100) self.add(sprite) cocos.director.director.init(width=1024, height=768) layer = Zen() scene = cocos.scene.Scene(layer) cocos.director.director.run(scene)