Chuyển đến nội dung chính

Bài đăng

Hiển thị các bài đăng có nhãn GPU

Fragment shaders in Flutter: the GPU escape hatch, and its costs

There is a category of visual effect that widgets simply cannot produce: per-pixel distortion, procedural gradients that animate without rebuilding, dissolves, ripples, chromatic aberration. You can approximate some of them with enough Transform and Opacity layers, and the result will be slow and wrong. Flutter’s answer is a GLSL fragment shader compiled at build time and executed on the GPU. It is a genuinely powerful escape hatch. It is also a different programming model with its own costs, and the honest version of this article covers both. The minimum viable shader A fragment shader is a program that runs once per pixel and returns a colour. Flutter’s dialect is GLSL ES with a small set of Flutter-specific helpers from flutter/runtime_effect.glsl . shaders/ripple.frag : #version 460 core #include <flutter/runtime_effect.glsl> precision highp float ; uniform vec2 uSize; uniform float uTime; uniform vec4 uColor; out vec4 fragColor; void main () { ...