怎么实现textureLod的模糊效果?

  • Creator 版本: 2.4.3

  • 目标平台:

  • 重现方式:

  • 首个报错:

  • 之前哪个版本是正常的:

  • 手机型号:

  • 手机浏览器:

  • 编辑器操作系统:

  • 重现概率:

想要的效果
vec3 col = textureLod(iChannel0, UV, 4.).rgb;如图:

实际用的时候:
color = textureLod(texture,v_uv0,4.).xyz;

我直接用textureLod会参数错误,textureLod好像被编译成texture2DLod了
image

1赞

试试这个

'fragTextureLod' : no matching overloaded function found:
我的是2d的纹理,前两个参数直接传2d图和vec2么?

我这报错是因为参数还是需要包含什么头文件?

这个只能在顶点着色器里使用


现在这是在尝试翻译一个shadertoy的代码,他这里的textureLod是什么呢?这里应该不是顶点着色器吧,

opengles3.0才支持你试试在creator3.0写,似乎2.4.3只支持编译到opengles2.0

https://www.khronos.org/registry/OpenGL-Refpages/es3.0/html/textureLod.xhtml

需要包含一个文件image


我2.4.3的,你是啥版本的引擎?

2.4这样写


CCEffect %{
  techniques:
  - passes:
    - vert: vs
      frag: fs
      rasterizerState:
        cullMode: back
      depthStencilState:
        depthTest: true
        depthWrite: true
      properties:
        tex: { value: white }
        lod: { value: 1.0 }
}%


CCProgram vs %{
  precision highp float;

  #include <cc-global>
  #include <cc-local>

  in vec3 a_position;

  #if USE_TEXTURE
  in vec2 a_uv0;
  out vec2 v_uv0;
  #endif


  void main () {
    vec4 pos = vec4(a_position, 1.0);
    pos = cc_matViewProj * cc_matWorld * pos;

    #if USE_TEXTURE
    v_uv0 = a_uv0;
    #endif

    gl_Position = pos;
  }
}%


CCProgram fs %{
  #extension GL_EXT_shader_texture_lod : enable
  precision highp float;
  
  #if USE_TEXTURE
  in vec2 v_uv0;
  uniform sampler2D tex;
  uniform Lod {
    float lod;
  };
  #endif

  void main () {
    vec4 o = vec4(1.0, 1.0, 1.0, 1.0);

    #if USE_TEXTURE
      #ifdef GL_EXT_shader_texture_lod
        o =  texture2DLodEXT(tex,v_uv0,lod);
      #else
        o = texture2D(tex,v_uv0);
      #endif
    #endif

    gl_FragColor = o;
  }
}%

3.0这样写


CCEffect %{
  techniques:
  - name: opaque
    passes:
    - vert: general-vs:vert # builtin header
      frag: unlit-fs:frag
      properties: &props
        mainTexture:    { value: white }
        mainColor:      { value: [1, 1, 1, 1], editor: { type: color } }
        roughness: { value: 1.0 }
  - 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 %{
  
  #if __VERSION__ < 300
    #extension GL_EXT_shader_texture_lod : enable
  #endif
  
  precision highp float;

  #include <output>
  #include <cc-fog>

  in vec2 v_uv;
  uniform sampler2D mainTexture;
  in float factor_fog;

  uniform Constant {
    vec4 mainColor;
    float roughness;
  };

  vec4 frag () {
    #if __VERSION__ < 300
    #ifdef GL_EXT_shader_texture_lod
      vec4 color = texture2DLodEXT(mainTexture,v_uv, roughness);
    #else
      vec4 color = texture2D(mainTexture, v_uv);
    #endif
    #else
      vec4 color = textureLod(mainTexture, v_uv, roughness);
    #endif
    vec4 col = mainColor * color;
    col = CC_APPLY_FOG(col, factor_fog);
    return CCFragOutput(col);
  }
}%

2赞

感谢感谢!

3.0.0

该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。