Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

重构 shader 里非标给 uniform 声明默认值逻辑 #2430

Open
1 task
lvisei opened this issue Apr 26, 2024 · 0 comments
Open
1 task

重构 shader 里非标给 uniform 声明默认值逻辑 #2430

lvisei opened this issue Apr 26, 2024 · 0 comments
Assignees

Comments

@lvisei
Copy link
Member

lvisei commented Apr 26, 2024

AntV Open Source Contribution Plan(可选)

  • 我同意将这个 Issue 参与 OSCP 计划

Issue 类型

中级任务

任务介绍

shader 里给 uniform 声明默认值是 glsl 非标准语法,设计之初用于方便运行时读取默认值,读取完成后再删除。

// line_vert.glsl
layout(std140) uniform commonUniorm {
  vec4 u_animate: [ 1., 2., 1.0, 0.2 ];
  vec4 u_dash_array;
  vec4 u_blur;
  vec4 u_sourceColor;
  vec4 u_targetColor;
  vec2 u_textSize;
  float u_icon_step: 100;
  float u_heightfixed: 0.0;
  float u_vertexScale: 1.0;
  float u_raisingHeight: 0.0;
  float u_strokeWidth: 0.0;
  float u_textureBlend;
  float u_line_texture;
  float u_linearDir: 1.0;
  float u_linearColor: 0;
  float u_time;
};

将所有 shader 中默认值给删除,在对应使用 shader 的 model 中声明默认值。

参考说明

比如 LineLayer 的 line model,line_frag.glsl 与 line_vert.glsl 给 uniform 声明默认值,将其删除

// packages/layers/src/line/shaders/line/line_vert.glsl
layout(std140) uniform commonUniorm {
-  vec4 u_animate: [ 1., 2., 1.0, 0.2 ];
+ vec4 u_animate;
  vec4 u_dash_array;
  vec4 u_blur;
  vec4 u_sourceColor;
  vec4 u_targetColor;
  vec2 u_textSize;
- float u_icon_step: 100;
+ float u_icon_step;
	...
};

删除默认值后,在对应的 model getCommonUniformsInfo 方法确保有设置默认值即可

// packages/layers/src/line/models/line.ts
const commonOptions = {
      u_animate: this.animateOption2Array(animateOption as IAnimateOption),
      u_dash_array,
      u_blur: blur,
      u_sourceColor: sourceColorArr,
      u_targetColor: targetColorArr,
      u_textSize: [1024, this.iconService.canvasHeight || 128],
      u_icon_step: iconStep,
      // 是否固定高度
      u_heightfixed: Number(heightfixed),
      // 顶点高度 scale
      u_vertexScale: vertexHeightScale,
      u_raisingHeight: Number(raisingHeight),
      // line border 参数
      u_strokeWidth: strokeWidth,
      u_textureBlend: textureBlend === TextureBlend.NORMAL ? 0.0 : 1.0,
      u_line_texture: lineTexture ? 1.0 : 0.0, // 传入线的标识
      u_linearDir: linearDir === LinearDir.VERTICAL ? 1.0 : 0.0,
      u_linearColor: useLinearColor,
      u_time: this.layer.getLayerAnimateTime() || 0,
    };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants