cocos creater3.1 effect shader 添加uniform float 变量报错



添加noiseValue变量就会报错,删掉就正常。请问是怎么问题,代码如下

// Effect Syntax Guide: https://github.com/cocos-creator/docs-3d/blob/master/zh/material-system/effect-syntax.md

CCEffect %{
techniques:

  • name: opaque
    passes:

    • vert: general-vs:vert # builtin header
      frag: unlit-fs:frag
      properties: &props
      mainTexture: { value: white }
      noiseTexture: { value: white }
      mainColor: { value: [1, 1, 1, 1], editor: { type: color } }
      noiseValue: { value: 0.5 }
  • name: transparent
    passes:

    • vert: general-vs:vert # builtin header
      frag: unlit-fs:frag
      blendState:
      targets:
      • blend: true
        blendSrc: src_alpha
        blendDst: one_minus_src_alpha
        blendSrcAlpha: src_alpha
        blendDstAlpha: one_minus_src_alpha
        properties: *props
        }%

CCProgram unlit-fs %{
precision highp float;
#include
#include

in vec2 v_uv;
uniform sampler2D mainTexture;
uniform sampler2D noiseTexture;
uniform float noiseValue;

uniform Constant {
vec4 mainColor;
};

vec4 frag () {
float r = texture(noiseTexture, v_uv);

vec4 col = mainColor * texture(mainTexture, v_uv) ;

CC_APPLY_FOG(col);
return CCFragOutput(col);

}
}%

声明在 Constant里试试

谢谢,这样是可以的,
没明白纹理不放在这里为啥可以使用,浮点却不行?

试试声明为 vec4 uniform,最小单位是 vec4,不是 float