Skip to content

Commit 8c1e86d

Browse files
Improve layout and styling for 'getting-started'
1 parent 970b660 commit 8c1e86d

File tree

3 files changed

+103
-47
lines changed

3 files changed

+103
-47
lines changed

source/_includes/layouts/content_page.jinja

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<meta name="twitter:description" content="{{ description }}" />
2626
<meta name="twitter:image" content="{{ homepage_url }}/images/branding/social.png" />
2727

28+
<link href="/styles/content_page.css" rel="stylesheet">
2829
<link href="/styles/tailwind.css" rel="stylesheet">
2930

3031
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/obsidian.min.css">
@@ -74,7 +75,7 @@
7475
</header>
7576

7677
<main class="ml-[auto] mr-[auto] max-w-[1000px] py-[72px] px-[48px] text-[#FFFFFFBB]">
77-
<div class="prose prose-invert prose-lg max-w-none prose-headings:text-white prose-h1:text-3xl prose-h2:text-2xl prose-h3:text-xl prose-h4:text-lg prose-strong:text-white prose-code:text-blue-300 prose-pre:bg-gray-800">
78+
<div class="content max-w-none">
7879
{{ content }}
7980
</div>
8081
</main>

source/getting-started.md

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,42 @@
11
---
22
title: Getting Started with Flutter Shaders
3-
description: Learn how to create stunning visual effects and performant graphics directly in your Flutter applications with this comprehensive guide.
3+
description: Learn how to create stunning visual effects and performant graphics directly in your
4+
Flutter applications with this comprehensive guide.
45
layout: layouts/content_page.jinja
56
directory: getting-started/
67
---
78

89
# Getting Started with Flutter Shaders
10+
Shaders in Flutter allow you to create stunning visual effects and performant graphics directly in
11+
your Flutter applications. This guide will take you from basic concepts to implementing real shader
12+
effects in your apps.
913

10-
Shaders in Flutter allow you to create stunning visual effects and performant graphics directly in your Flutter applications. This guide will take you from basic concepts to implementing real shader effects in your apps.
14+
## Integrating Shaders from FlutterShaders.com
15+
TL;DR: To use a shader from this website:
1116

12-
## What Are Fragment Shaders?
17+
1. **Copy the shader code** from the shader page
18+
2. **Save it** as a `.frag` file in `assets/shaders/`
19+
3. **Add it to your pubspec.yaml** under `flutter: shaders:`
20+
4. **Identify the uniforms** the shader expects
21+
5. **Create a CustomPainter** similar to the example above
22+
6. **Set the required uniforms** in the `paint` method
1323

14-
Fragment shaders are small GPU programs that determine the color of each pixel on the screen. Think of them as functions that run in parallel for every pixel, where:
24+
## What Are Fragment Shaders?
25+
Fragment shaders are small GPU programs that determine the color of each pixel on the screen. Think
26+
of them as functions that run in parallel for every pixel, where:
1527

1628
- **Input**: The pixel's position (coordinates) and custom parameters called uniforms
1729
- **Output**: A single color value for that pixel
1830

19-
**NOTE**: Shaders run on the GPU, making them incredibly fast. Fragment shaders are typically the final step in the graphics pipeline, which is why they're so efficient for real-time effects.
31+
**NOTE**: Shaders run on the GPU, making them incredibly fast. Fragment shaders are typically the
32+
final step in the graphics pipeline, which is why they're so efficient for real-time effects.
2033

2134
## Flutter + Fragment Shaders
22-
23-
Flutter is hardware-accelerated, meaning it leverages GPU shaders for rendering. Every widget you see - from a simple `Container` to complex blur effects - is ultimately rendered using optimized shaders. This is what makes Flutter so smooth and performant across platforms.
35+
Flutter is hardware-accelerated, meaning it leverages GPU shaders for rendering. Every widget you
36+
see - from a simple `Container` to complex blur effects - is ultimately rendered using optimized
37+
shaders. This is what makes Flutter so smooth and performant across platforms.
2438

2539
## Types of Shader Usage in Flutter
26-
2740
There are three main ways to use custom shaders in Flutter:
2841

2942
### 1. Paint from Scratch
@@ -46,7 +59,6 @@ Modify content behind widgets:
4659

4760

4861
## Step-by-Step Setup
49-
5062
Follow these steps to create your first Flutter shader project:
5163

5264
#### Step 1: Create a New Flutter Project
@@ -63,7 +75,6 @@ mkdir -p assets/shaders
6375
```
6476

6577
#### Step 3: Create Your First Shader File
66-
6778
Create a file `assets/shaders/animated_colors.frag` with the following content:
6879

6980
```glsl
@@ -92,7 +103,6 @@ void main() {
92103
```
93104

94105
#### Step 4: Register the Shader in pubspec.yaml
95-
96106
Add the shader to your `pubspec.yaml` file:
97107

98108
```yaml
@@ -234,12 +244,14 @@ You should see a colorful animated shader effect!
234244
#### 2. ImageFiltered + ImageFilter.shader
235245
- **Use Case**: Apply shader effects to child widgets
236246
- **Pros**: Easy to apply shader effects to any widget
237-
- **Cons**: Requires Impeller renderer; cannot control the first two uniforms (vec2 for texture size and sampler2D) as they are set by the Flutter engine
247+
- **Cons**: Requires Impeller renderer; cannot control the first two uniforms (vec2 for texture
248+
size and sampler2D) as they are set by the Flutter engine
238249

239250
#### 3. BackdropFilter + ImageFilter.shader
240251
- **Use Case**: Apply shader effects to background content
241252
- **Pros**: Easy backdrop shader effects
242-
- **Cons**: Requires Impeller renderer;cannot control the first two uniforms (vec2 for texture size and sampler2D) as they are set by the Flutter engine
253+
- **Cons**: Requires Impeller renderer;cannot control the first two uniforms (vec2 for texture
254+
size and sampler2D) as they are set by the Flutter engine
243255

244256
#### 4. flutter_shaders Package
245257
- **Use Case**: Simplified shader usage - easily transform any widget into a shader-compatible image
@@ -252,30 +264,38 @@ You should see a colorful animated shader effect!
252264
**ImageFilter.shader** (Native Flutter API):
253265

254266
* **Integration**: Built directly into the Flutter framework (`dart:ui`).
255-
* **Rendering Backend**: **Requires the Impeller rendering engine.** It will not work with other backends.
256-
* **BackdropFilter**: **Supports `BackdropFilter`**, allowing you to apply shader effects to the content behind a widget.
257-
* **API Flexibility**: Operates on a "convention over configuration" model. It simplifies the process by automatically providing and managing core uniforms (like the input texture), but this reduces flexibility as you have less control over the shader's direct inputs.
267+
* **Rendering Backend**: **Requires the Impeller rendering engine.** It will not work with other
268+
backends.
269+
* **BackdropFilter**: **Supports `BackdropFilter`**, allowing you to apply shader effects to the
270+
content behind a widget.
271+
* **API Flexibility**: Operates on a "convention over configuration" model. It simplifies the
272+
process by automatically providing and managing core uniforms (like the input texture), but this
273+
reduces flexibility as you have less control over the shader's direct inputs.
258274
* **Dependencies**: None, as it's part of the Flutter SDK.
259275

260276
**flutter_shaders** (Third-party Package):
261277

262278
* **Integration**: A community-created package that needs to be added as a dependency.
263-
* **Rendering Backend**: **Backend-agnostic**, making it compatible with various rendering backends, not just Impeller.
264-
* **BackdropFilter**: **Does not directly support `BackdropFilter`**. Its effects are generally limited to the widgets it's applied to.
265-
* **API Flexibility**: Provides more direct control over the `FragmentShader` object. You have full responsibility for declaring and managing all uniforms, which offers maximum flexibility and power at the cost of potentially more boilerplate code.
279+
* **Rendering Backend**: **Backend-agnostic**, making it compatible with various rendering
280+
backends, not just Impeller.
281+
* **BackdropFilter**: **Does not directly support `BackdropFilter`**. Its effects are generally
282+
limited to the widgets it's applied to.
283+
* **API Flexibility**: Provides more direct control over the `FragmentShader` object. You have
284+
full responsibility for declaring and managing all uniforms, which offers maximum flexibility and
285+
power at the cost of potentially more boilerplate code.
266286
* **Dependencies**: Requires adding the `flutter_shaders` package to your `pubspec.yaml`.
267287

268288
### Rendering Pipeline Performance Impact
269-
270-
A critical difference between these approaches lies in **when and how many times rendering occurs** during the Flutter frame lifecycle:
289+
A critical difference between these approaches lies in **when and how many times rendering occurs**
290+
during the Flutter frame lifecycle:
271291

272292
**ImageFilter.shader** (Native Flutter API):
273293
- Starts during the **build phase** and integrates directly with Flutter's compositing layer
274294
- Processes in **single-pass rendering** within the normal pipeline
275295
- **Does not trigger additional raster operations** beyond the standard frame rendering
276296

277-
278-
You'll notice in the timeline that this process doesn't trigger any additional raster operations beyond what's standard for a frame (compared to the below example).
297+
You'll notice in the timeline that this process doesn't trigger any additional raster operations
298+
beyond what's standard for a frame (compared to the below example).
279299

280300
![ImageFilter starts during build phase](using_image_filter_starts_during_build_phase.png)
281301

@@ -296,22 +316,18 @@ High-level view of the frame lifecycle:
296316

297317
![flutter_shaders triggers raster operation](using_flutter_shaders_starts_during_compositing_phase_and_does_trigger_raster_operation.png)
298318

299-
300-
301319
### When to use which?
302-
303320
* Use **ImageFilter.shader** for:
304321
* Applying shader effects as a BackdropFilter.
305322
* Projects where you can rely on the Impeller rendering engine.
306323
* Avoiding third-party dependencies.
307324
* Optimal performance with single-pass rendering.
308-
309325
* Use the **flutter_shaders** package for:
310326
* Broader compatibility across different Flutter rendering backends (Skia and Impeller).
311-
* Complex effects requiring fine-grained control over all shader uniforms (for example size unifrom).
327+
* Complex effects requiring fine-grained control over all shader uniforms (for example size
328+
unifrom).
312329

313330
## Impeller Status by Platform
314-
315331
**ImageFilter.shader** requires Impeller. Check platform availability:
316332

317333
- **iOS**: Impeller default (Flutter 3.29+)
@@ -324,7 +340,6 @@ For detailed status across Flutter versions, see the [official Flutter team spre
324340

325341

326342
## Example 1: CustomPainter + FragmentShader
327-
328343
**Creates visual effects from scratch using the GPU**
329344

330345
![Gradient Flow Effect](gradient_flow.gif)
@@ -418,7 +433,6 @@ class ShaderPainter extends CustomPainter {
418433

419434

420435
## Example 2: flutter_shaders Package
421-
422436
**Simplified shader usage with automatic texture management**
423437

424438
![Stripes Pattern Effect](stripes.gif)
@@ -514,7 +528,6 @@ class _FlutterShadersDemoState extends State<FlutterShadersDemo>
514528

515529

516530
## Example 3: ImageFilter.shader
517-
518531
**Apply shader effects to any widget** (Requires Impeller)
519532

520533
![Ripple Effect](ripple_effect.gif)
@@ -616,9 +629,7 @@ class _ImageFilterDemoState extends State<ImageFilterDemo>
616629
}
617630
```
618631

619-
620632
## Example 4: BackdropFilter
621-
622633
**Apply shader effects to background content** (Requires Impeller)
623634

624635
![Backdrop Effect](backdrop_effect.gif)
@@ -743,15 +754,3 @@ class _BackdropFilterDemoState extends State<BackdropFilterDemo>
743754
}
744755
}
745756
```
746-
747-
748-
## Integrating Shaders from FlutterShaders.com
749-
750-
To use a shader from this website:
751-
752-
1. **Copy the shader code** from the shader page
753-
2. **Save it** as a `.frag` file in `assets/shaders/`
754-
3. **Add it to your pubspec.yaml** under `flutter: shaders:`
755-
4. **Identify the uniforms** the shader expects
756-
5. **Create a CustomPainter** similar to the example above
757-
6. **Set the required uniforms** in the `paint` method

source/styles/content_page.scss

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
html, body {
2+
font-size: 14px;
3+
line-height: 1.4rem;
4+
}
5+
6+
.content {
7+
background: WHITE;
8+
padding: 24px;
9+
10+
color: BLACK;
11+
12+
& > :first-child {
13+
margin-top: 0;
14+
}
15+
16+
h1, h2, h3, h4, h5, h6 {
17+
margin-top: 2rem;
18+
}
19+
20+
h1, h2, h3, h4, h5, h6 {
21+
margin-bottom: 0.25rem;
22+
}
23+
24+
p, li {
25+
margin-bottom: 0.75rem;
26+
}
27+
28+
img, pre {
29+
margin-top: 0.75rem;
30+
margin-bottom: 0.75rem;
31+
}
32+
33+
h1 {
34+
font-size: 2em;
35+
}
36+
37+
h2 {
38+
font-size: 1.75rem;
39+
}
40+
41+
h3 {
42+
font-size: 1.5rem;
43+
}
44+
45+
h4 {
46+
font-size: 1.25rem;
47+
}
48+
49+
h5 {
50+
font-size: 1.15rem;
51+
}
52+
53+
h6 {
54+
font-size: 1rem;
55+
}
56+
}

0 commit comments

Comments
 (0)