Shader/Effect differences between Editor and Preview

I’m following the tutorial here: Tutorial: Cocos Shader Series - Use a Noise Map to Make a Dissolve Texture

And the effect works correctly/as expected in the editor, but when running the preview the scale of the dissolve texture is massively different.

Can anyone explain what is happening here?

I don’t know what settings could be affecting the scaling like this since it’s working in the editor so I assume the shader is working as intended? Is it something to do with the textures?

Have included the effect code here (a modified version of the builtin-sprite effect)

t// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
CCEffect %{
  techniques:
  - passes:
    - vert: sprite-vs:vert
      frag: sprite-fs:frag
      depthStencilState:
        depthTest: false
        depthWrite: false
      blendState:
        targets:
        - blend: true
          blendSrc: src_alpha
          blendDst: one_minus_src_alpha
          blendDstAlpha: one_minus_src_alpha
      rasterizerState:
        cullMode: none
      properties:
        alphaThreshold: { value: 0.5 }
        u_dissolveMap: {value: White, editor: {tooltip: 'Noise map'}}
        dissolveThreshold: { value: 0.5, editor: {range: [0, 1, 0.01], slide: true, tooltip: 'dissolve threshold'}}
        u_dissolveColor: { editor: { type: color } }
        dissolveEdgeThreshold: {value: 0.05, editor: {range: [0, 1, 0.01], slide: true}}
        uvTilingMultiplier: {value: [1, 1], editor: {type: vec2}}
}%

CCProgram sprite-vs %{
  precision highp float;

  #include <cc-global>
  #if USE_LOCAL
    #include <cc-local>
  #endif
  #if SAMPLE_FROM_RT
    #include <common>
  #endif
  in vec3 a_position;
  in vec2 a_texCoord;
  in vec4 a_color;

  out vec4 color;
  out vec2 uv0;

  vec4 vert () {

    vec4 pos = vec4(a_position, 1);

    #if USE_LOCAL
      pos = cc_matWorld * pos;
    #endif

    uv0 = a_texCoord;

    #if USE_PIXEL_ALIGNMENT
      pos = cc_matView * pos;
      pos.xyz = floor(pos.xyz);
      pos = cc_matProj * pos;
    #else
      pos = cc_matViewProj * pos;
    #endif

    uv0 = a_texCoord;
    #if SAMPLE_FROM_RT
      CC_HANDLE_RT_SAMPLE_FLIP(uv0);
    #endif
    color = a_color;

    return pos;
  }
}%

CCProgram sprite-fs %{
  precision highp float;
  #include <embedded-alpha>
  #include <alpha-test>

  in vec4 color;

  uniform Disslove{
    float dissolveThreshold;
    float dissolveEdgeThreshold;
  };

  uniform DissolveColor{
    vec4 u_dissolveColor;
  };

  uniform TilingMultiplier{
    vec2 uvTilingMultiplier;
  };


  #if USE_TEXTURE
    in vec2 uv0;

    uniform sampler2D u_dissolveMap;
    #pragma builtin(local)
    layout(set = 2, binding = 10) uniform sampler2D cc_spriteTexture;
  #endif

  vec4 frag () {
    vec4 o = color;

    float value = 1.0;

    vec2 mutlipliedUVs = uv0 * uvTilingMultiplier;

    #if USE_TEXTURE
      vec4 dissolveMap = texture(u_dissolveMap, mutlipliedUVs);
      value *= dissolveMap.r;
      #endif

      if (value < dissolveThreshold){
        discard;
      }
   
    #if USE_TEXTURE
    o *= texture(cc_spriteTexture, uv0);
    #endif

    o *= color;
    if (value <dissolveThreshold + dissolveEdgeThreshold){
      o = u_dissolveColor;
    }
    ALPHA_TEST(o);
    return o;
  }
}%

What version of Cocos Creator are you using? I can ask engineering to have a look.

I’m using version 3.3.1 on Mac OS Monterey

hi, I tested normal.
demo:
NewProject_9.zip (1.4 MB)
Maybe you didn’t uncheck packable


Or not remove the checkbox for this(CLEANUP_IMAGE_CACHE).

If you use a shader to manipulate the uv of a texture, you cannot use Dynamic Atlas.

1 Like

ticking CLEANUP_IMAGE_CACHE fixed it for me - thank you, I hadn’t seen any mention of that option before :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.