An open API service indexing awesome lists of open source software.

https://github.com/w23/iced-fragment-shader-widget-example

Minimalistic example of drawing iced custom shader widget using a single fragment shader
https://github.com/w23/iced-fragment-shader-widget-example

custom-widget fragment-shader iced rust wgpu wgpu-rs wgsl wgsl-shader widget

Last synced: 5 months ago
JSON representation

Minimalistic example of drawing iced custom shader widget using a single fragment shader

Awesome Lists containing this project

README

          

# Custom fragment shader widget example for iced

A minimalistic example of making [iced](https://iced.rs/) custom shader widget draw its contents using just a fragment shader. This provides reasonably fast access to writing arbitrary pixels into widget's canvas, something that iced custom canvas widget struggles with.

This example consists of:
- Iced boilerplate code for creating, updating, and drawing custom shader widget.
- [Wgpu](https://wgpu.rs/) pipeline creation for a simple single-triangle pipeline without any buffers for vertex data.
- [Wgsl](https://www.w3.org/TR/WGSL/) shader file including both vertex and fragment shader code.
- vertex shader generates 3 vertices coordinates based on `vertex_index` to make a triangle that fills the entire viewport.
- fragment shader draws a pannable/zoomable mandelbrot set as a trivial example
- Mouse event handling that updates widget state. This state is then passed into the shader as uniform data.