def __init__(self, width, height): self.width = width self.height = height self.framebuffer = Framebuffer() self.tex1 = Texture(width, height, filter=GL_NEAREST, format=GL_RGBA32F, clamp='st') self.tex2 = Texture(width, height, filter=GL_NEAREST, format=GL_RGBA32F, clamp='st') self.tex3 = Texture(width, height, filter=GL_NEAREST, format=GL_RGBA32F, clamp='st') self.program = ShaderProgram( FragmentShader.open('shaders/ripples.frag'), offsets=(1.0 / width, 1.0 / height), tex2=Sampler2D(GL_TEXTURE1), tex3=Sampler2D(GL_TEXTURE2), )
def __init__(self, application): Node.__init__(self, self.label, application) self.op1 = InputSlot(self).append_to(self.column) inout = Area().append_to(self.column).add_class('inout') self.op2 = InputSlot(self).append_to(inout) self.output = Output(self).append_to(inout) self.shader = application.shader(self.shader) self.shader.vars.op1 = Sampler2D(GL_TEXTURE0) self.shader.vars.op2 = Sampler2D(GL_TEXTURE1) self.updated = False self.sources = dict( op1 = self.op1, op2 = self.op2, )
def __init__(self, application): Base.__init__(self, application) self.repeat = LabelSlider('Repeat', start=0.0).insert_before(self.inout) self.weight = LabelInput('Weight', self).insert_before(self.inout) self._parameters['repeat'] = self.repeat self.last_repeat = 0 self.last_source_revision = None self.shader.vars.texture = Sampler2D(GL_TEXTURE0) self.shader.vars.filter_weight = Sampler2D(GL_TEXTURE1) self.sources['weight'] = self.weight self._parameters = dict( repeat = self.repeat, ) self.optional = ['weight']
def __init__(self, application): Node.__init__(self, self.label, application) self.inout = Area().append_to(self.column).add_class('inout') self.input = InputSlot(self).append_to(self.inout) self.output = Output(self).append_to(self.inout) self.updated = False self.shader = application.shader(self.shader) self.shader.vars.texture = Sampler2D(GL_TEXTURE0) self.shader.vars.offsets = 1.0/self.texture.width, 1.0/self.texture.height self.sources = dict( input = self.input, )
def __init__(self, application): Node.__init__(self, 'Adjust', application) self.inout = Area().append_to(self.column).add_class('inout') self.input = InputSlot(self).append_to(self.inout) self.output = Output(self).append_to(self.inout) self.shader = application.shader('adjust.frag') self.shader.vars.texture = Sampler2D(GL_TEXTURE0) self.invert = LabelCheckbox('Invert').insert_before(self.inout) self.clamp = LabelCheckbox('Clamp').insert_before(self.inout) self.factor = LabelSlider('Factor', start=0.5).insert_before(self.inout) self.offset = LabelSlider('Offset', start=0.5).insert_before(self.inout) self._parameters = dict( factor=self.factor, offset=self.offset, clamp=self.clamp, invert=self.invert, ) self.sources = dict(input=self.input, )
from gletools import ShaderProgram, FragmentShader, Texture, Framebuffer, Sampler2D from gletools.gl import * from lif_parser import LifParser window = pyglet.window.Window(fullscreen=True, vsync=False) framebuffer = Framebuffer() front = Texture(window.width, window.height, format=GL_RGB, filter=GL_NEAREST) back = Texture(window.width, window.height, format=GL_RGB, filter=GL_NEAREST) framebuffer.textures[0] = front program = ShaderProgram(FragmentShader.open('shader.frag'), ) program.vars.width = float(front.width) program.vars.height = float(front.height) program.vars.texture = Sampler2D(GL_TEXTURE0) def quad(): glBegin(GL_QUADS) glTexCoord2f(1.0, 1.0) glVertex3f(window.width, window.height, 0.0) glTexCoord2f(1.0, 0.0) glVertex3f(window.width, 0.0, 0.0) glTexCoord2f(0.0, 0.0) glVertex3f(0.0, 0.0, 0.0) glTexCoord2f(0.0, 1.0) glVertex3f(0.0, window.height, 0.0) glEnd()
filter=GL_LINEAR_MIPMAP_LINEAR, clamp='st', unit=GL_TEXTURE0, ) terrain = Texture.raw_open( 'data/patches/snowy_mountains.terrain', width=size, height=size, format=GL_RGBA32F, unit=GL_TEXTURE1, clamp='st', ) program = ShaderProgram.open( 'terrain.shader', diffuse=Sampler2D(GL_TEXTURE0), terrain=Sampler2D(GL_TEXTURE1), ) normals = ShaderProgram.open('normals.shader') vbo = make_triangles(128, 128, terrain) fps = pyglet.clock.ClockDisplay(color=(144.0 / 255.0, 195.0 / 255.0, 6.0 / 255.0, 0.5)) @window.event def on_draw(): window.clear() model = Matrix().rotatex(-0.25).translate(-0.5, -0.5, 0.0)
{ depth = -(gl_ModelViewMatrix * gl_Vertex).z; gl_TexCoord[0] = gl_MultiTexCoord0; gl_Position = ftransform(); gl_FrontColor = gl_Color; } ''') blur = ShaderProgram( depth_shader, FragmentShader.open('shader.frag'), ) blur.vars.width = float(window.width) blur.vars.height = float(window.height) blur.vars.texture = Sampler2D(GL_TEXTURE0) blur.vars.depthmap = Sampler2D(GL_TEXTURE1) depth = ShaderProgram( depth_shader, FragmentShader(''' varying float depth; uniform sampler2D texture; void main(){ vec4 color = texture2D(texture, gl_TexCoord[0].st); gl_FragData[0] = color; gl_FragData[1] = color; gl_FragData[2] = vec4(depth, depth, depth, 1.0); } '''), )