Gamma Gradients¶
This notebook generates a green gradient signifying the difference between gamma encoded and not.
In [2]:
import brushcue
from IPython.display import Image, display
OUTPUT_LINEAR_PATH = "/home/dito/dev/monorepo/writing/graphics/chapters/numbers/assets/green_gradient_linear.png"
OUTPUT_GAMMA_PATH = "/home/dito/dev/monorepo/writing/graphics/chapters/numbers/assets/green_gradient_gamma.png"
ctx = brushcue.Context()
def gradient_painter(fill: brushcue.Fill) -> brushcue.Composition:
painter = brushcue.Painter.new()
painter = painter.add_rectangle_with_render_style(
brushcue.Point2f.from_components(500, 0),
brushcue.Vector2f.from_components(1000, 400),
0,
brushcue.RenderStyle.fill_only(fill),
brushcue.Transform2.identity().to_list()
)
composition = brushcue.Composition.painter(painter)
return composition
fill_gamma = brushcue.Fill.custom(
"""
let gamma_encoded = canvas_position.x / 1000.0;
let linear = select(
pow((gamma_encoded + 0.055) / 1.055, 2.4),
gamma_encoded / 12.92,
gamma_encoded <= 0.04045,
);
return vec4<f32>(0.0, linear, 0.0, 1.0);
""",
"",
brushcue.Dictionary.create()
)
fill_linear = brushcue.Fill.custom(
"return vec4<f32>(0, canvas_position.x / 1000, 0, 1);",
"",
brushcue.Dictionary.create()
)
painter = gradient_painter(fill_gamma)
image_bytes = painter.execute(ctx).to_image_bytes(ctx)
with open(OUTPUT_GAMMA_PATH, "wb") as f:
f.write(image_bytes)
display(Image(OUTPUT_GAMMA_PATH))
painter = gradient_painter(fill_linear)
image_bytes = painter.execute(ctx).to_image_bytes(ctx)
with open(OUTPUT_LINEAR_PATH, "wb") as f:
f.write(image_bytes)
display(Image(OUTPUT_LINEAR_PATH))
new pipeline: painter_Tessellated_custom_fill_3950020432936449483_no_brush_sample_true_rgba8unorm
new pipeline: painter_Tessellated_custom_fill_10263099226769712530_no_brush_sample_true_rgba8unorm