I have a simple Pyglet scene below. I would like to apply a postprocessing step to add bloom to the scene. How can this be done using pyglet?
I’ve tried looking through all the documentation for framebuffers and postprocessing steps but I can’t find any examples of how to do this in pyglet.
import pyglet
from pyglet.graphics.shader import Shader, ShaderProgram
from pyglet.gl import *
from pyglet.math import Mat4, Vec3
window = pyglet.window.Window(width=1280, height=720, caption="Hello Pyglet", resizable=True)
vertex_source = """
#version 330
in vec2 vertices;
uniform mat4 vp;
uniform mat4 model;
void main() {
gl_Position = vp * model * vec4(vertices, 0.0, 1.0);
}
"""
fragment_source = """
#version 330
out vec4 fragColor;
void main() {
vec3 col = vec3(1.0,1.0,1.0);
fragColor = vec4(col,1.0);
}
"""
vert_shader = Shader(vertex_source, "vertex")
frag_shader = Shader(fragment_source, "fragment")
program = ShaderProgram(vert_shader, frag_shader)
view_mat = Mat4.from_translation(Vec3(x=0, y=0, z=-1))
proj_mat = Mat4.orthogonal_projection(left=0, right=1280, bottom=0, top=720, z_near=0.1, z_far=100)
vp = proj_mat @ view_mat
program['vp'] = vp
translation_mat = Mat4.from_translation(Vec3(x=640,y=360,z=0))
program['model'] = translation_mat
batch = pyglet.graphics.Batch()
vertices = [(x - 1) * 100 for x in (-0.5, -0.5, 0.5, -0.5, 0.5, 0.5, -0.5, 0.5)]
vertices2 = [(x + 1) * 100 for x in (-0.5, -0.5, 0.5, -0.5, 0.5, 0.5, -0.5, 0.5)]
indices = (0, 1, 2, 2, 3, 0)
program.vertex_list_indexed(4, GL_TRIANGLES,
batch=batch,
indices=(0,1,2,2,3,0),
vertices=('f', vertices))
program.vertex_list_indexed(4, GL_TRIANGLES,
batch=batch,
indices=(0,1,2,2,3,0),
vertices=('f', vertices2))
@window.event
def on_draw():
window.clear()
batch.draw()
pyglet.app.run()