Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions doc/tutorials/shader_inputs/basic_shader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self):
super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
self.center_window()
self.background_color = arcade.color.ALMOND

# GL geometry that will be used to pass pixel coordinates to the shader
# It has the same dimensions as the screen
self.quad_fs = arcade.gl.geometry.quad_2d_fs()
Expand Down Expand Up @@ -40,7 +40,7 @@ def on_draw(self):
# Draw a simple circle
self.clear()
arcade.draw_circle_filled(
SCREEN_WIDTH / 2,
SCREEN_WIDTH / 2,
SCREEN_HEIGHT / 2,
100,
arcade.color.AFRICAN_VIOLET
Expand All @@ -49,7 +49,13 @@ def on_draw(self):
# Run the shader and render to screen
# The shader code is run once for each pixel coordinate in quad_fs
# and the fragColor output added to the screen
self.quad_fs.render(self.prog)
# Because the fragColor has a varying transparency we need to enable
# blending. When blending is disabled each pixel's color is exactly
# equal to fragColor, but with blending enabled the pixel's final
# color is a mix of the original color and fragColor based on the
# alpha values.
with self.ctx.enabled(self.ctx.BLEND):
self.quad_fs.render(self.prog)


app = MyWindow()
Expand Down
11 changes: 6 additions & 5 deletions doc/tutorials/shader_inputs/texture_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self):
super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
self.center_window()
self.background_color = arcade.color.ALMOND

# GL geometry that will be used to pass pixel coordinates to the shader
# It has the same dimensions as the screen
self.quad_fs = arcade.gl.geometry.quad_2d_fs()
Expand All @@ -23,7 +23,7 @@ def __init__(self):
self.fbo.clear(color=arcade.color.ALMOND)
with self.fbo:
arcade.draw_circle_filled(
SCREEN_WIDTH / 2,
SCREEN_WIDTH / 2,
SCREEN_HEIGHT / 2,
100,
arcade.color.AFRICAN_VIOLET
Expand All @@ -36,7 +36,7 @@ def __init__(self):
in vec2 in_vert;
void main()
{
gl_Position = vec4(in_vert, 0., 1.);
gl_Position = vec4(in_vert, 0.0, 1.0);
}
""",
fragment_shader="""
Expand All @@ -63,8 +63,9 @@ def on_draw(self):
self.tex.use(0)

# Run the shader and render to the framebuffer
self.quad_fs.render(self.prog)

with self.ctx.enabled(self.ctx.BLEND):
self.quad_fs.render(self.prog)

# Copy the framebuffer to the screen to display
self.ctx.copy_framebuffer(self.fbo, self.ctx.screen)

Expand Down
11 changes: 6 additions & 5 deletions doc/tutorials/shader_inputs/textures.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self):
super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
self.center_window()
self.background_color = arcade.color.ALMOND

# GL geometry that will be used to pass pixel coordinates to the shader
# It has the same dimensions as the screen
self.quad_fs = arcade.gl.geometry.quad_2d_fs()
Expand Down Expand Up @@ -53,8 +53,8 @@ def __init__(self):
{
// Set pixel color as a combination of the two textures
fragColor = mix(
texture(t0, uv),
texture(t1, uv),
texture(t0, uv),
texture(t1, uv),
smoothstep(0.0, 1.0, uv.x));
// Set the alpha based on time
fragColor.w = sin(time);
Expand All @@ -77,7 +77,7 @@ def on_draw(self):
# Draw a simple circle
self.clear()
arcade.draw_circle_filled(
SCREEN_WIDTH / 2,
SCREEN_WIDTH / 2,
SCREEN_HEIGHT / 2,
100,
arcade.color.AFRICAN_VIOLET
Expand All @@ -93,7 +93,8 @@ def on_draw(self):
# Run the shader and render to screen
# The shader code is run once for each pixel coordinate in quad_fs
# and the fragColor output added to the screen
self.quad_fs.render(self.prog)
with self.ctx.enabled(self.ctx.BLEND):
self.quad_fs.render(self.prog)


app = MyWindow()
Expand Down
12 changes: 9 additions & 3 deletions doc/tutorials/shader_inputs/uniforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self):
super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)
self.center_window()
self.background_color = arcade.color.ALMOND

# GL geometry that will be used to pass pixel coordinates to the shader
# It has the same dimensions as the screen
self.quad_fs = arcade.gl.geometry.quad_2d_fs()
Expand Down Expand Up @@ -49,7 +49,7 @@ def on_draw(self):
# Draw a simple circle
self.clear()
arcade.draw_circle_filled(
SCREEN_WIDTH / 2,
SCREEN_WIDTH / 2,
SCREEN_HEIGHT / 2,
100,
arcade.color.AFRICAN_VIOLET
Expand All @@ -61,7 +61,13 @@ def on_draw(self):
# Run the shader and render to screen
# The shader code is run once for each pixel coordinate in quad_fs
# and the fragColor output added to the screen
self.quad_fs.render(self.prog)
# Because the fragColor has a varying transparency we need to enable
# blending. When blending is disabled each pixel's color is exactly
# equal to fragColor, but with blending enabled the pixel's final
# color is a mix of the original color and fragColor based on the
# alpha values.
with self.ctx.enabled(self.ctx.BLEND):
self.quad_fs.render(self.prog)


app = MyWindow()
Expand Down
Loading