搜索插件、代码仓与 APP 分类

插件详情v0.5.2

flutter_gpu_shaders

用于 Flutter GPU 着色器包/库的构建工具。

AndroidiOSLinuxmacOSWindows
近 30 天下载
10.9万
喜欢数
21
Pub 分数
150

安装插件

flutter pub add flutter_gpu_shaders

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 包,提供创建和管理 GPU 着色器包及库的工具,支持高性能 3D 图形渲染。它可在 Android、iOS、Linux、macOS 和 Windows 等多个平台上与 Flutter 的渲染管线集成。该包专为需要低级别 GPU 控制的复杂视觉效果、游戏或数据可视化应用开发而设计。通过高效打包着色器,它简化了开发流程,并通过优化的着色器执行提升了性能。

适合场景

  • 3D 游戏开发
  • 实时数据可视化
  • 复杂的UI动画
  • 高性能图形渲染
  • 基于着色器的视觉效果

主要特点

  • 跨平台 GPU 着色器支持
  • 高效的着色器包管理
  • 与 Flutter 渲染管道的集成
  • 针对3D内容优化的性能
  • 用于着色器编译和打包的工具

适合对象

  • 开发3D应用的开发者
  • Flutter 中的游戏引擎创建者
  • 视觉效果专家
  • 高性能UI设计
  • 图形密集型应用构建器

使用建议

  • 需要了解 GLSL 或 HLSL
  • 仅限GPU加速渲染
  • 可能增加构建复杂性
  • 最适合高级用户
  • 平台特定的着色器行为可能有所不同

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Build tools for Flutter GPU shader bundles/libraries.

Features

Use native asset build hooks to import Flutter GPU shader bundle assets.

Getting started

  1. Place some Flutter GPU shaders in your project. For this example, we'll assume the existence of two shaders: shaders/my_cool_shader.vert and shaders/my_cool_shader.frag.
  2. Create a shader bundle manifest file in your project. The filename must end with .shaderbundle.json. For this example, we'll assume the following file is saved as my_cool_bundle.shaderbundle.json:
    {
        "CoolVertex": {
            "type": "vertex",
            "file": "shaders/my_cool_shader.vert"
        },
        "CoolFragment": {
            "type": "fragment",
            "file": "shaders/my_cool_shader.frag"
        }
    }
    
  3. Next, define a build hook in your project that builds the shader bundle using buildShaderBundleJson. The build hook must be named hook/build.dart in your project; this script will be automatically invoked by Flutter:
    import 'package:hooks/hooks.dart';
    import 'package:flutter_gpu_shaders/build.dart';
    
    void main(List<String> args) async {
      await build(args, (config, output) async {
        await buildShaderBundleJson(
            buildInput: config,
            buildOutput: output,
            manifestFileName: 'my_cool_bundle.shaderbundle.json');
      });
    }
    
    buildShaderBundleJson always declares the manifest and directly listed shader files as build dependencies. With Flutter SDKs whose impellerc supports --depfile for shader bundles, it also declares transitive #include dependencies from the generated depfile. Older impellerc builds continue to use the manifest scan fallback.
  4. In your project's pubspec.yaml, add the built shader bundle as an asset:
    flutter:
      assets:
        - build/shaderbundles/my_cool_bundle.shaderbundle
    
  5. If your Flutter toolchain supports Dart DataAssets, you can opt in to registering the generated bundle with the Flutter asset bundle instead of listing it in pubspec.yaml:
    await buildShaderBundleJson(
      buildInput: config,
      buildOutput: output,
      manifestFileName: 'my_cool_bundle.shaderbundle.json',
      assetMode: ShaderBundleAssetMode.dataAssetsIfAvailable,
    );
    
    With DataAssets enabled, the result's flutterAssetKey is the key to pass to gpu.ShaderLibrary.fromAsset. When DataAssets are unavailable, dataAssetsIfAvailable falls back to the legacy file output. Use ShaderBundleAssetMode.dataAssetsRequired to fail fast with guidance instead.
  6. You can now import the built shader bundle as a library using gpu.ShaderLibrary.fromAsset in your project. For example:
    import 'package:flutter_gpu/gpu.dart' as gpu;
    
    final String _kBaseShaderBundlePath =
        'build/shaderbundles/my_cool_bundle.shaderbundle';
    
    gpu.ShaderLibrary? _baseShaderLibrary;
    gpu.ShaderLibrary get baseShaderLibrary {
      if (_baseShaderLibrary != null) {
        return _baseShaderLibrary!;
      }
      _baseShaderLibrary = gpu.ShaderLibrary.fromAsset(_kBaseShaderBundlePath);
      if (_baseShaderLibrary != null) {
        return _baseShaderLibrary!;
      }
    
      throw Exception(
          "Failed to load base shader bundle! ($_kBaseShaderBundlePath)");
    }
    

所属分类

依赖

依赖清单 4 项

源码仓库

使用此插件的项目

暂无相关数据。

所在榜单