cocoscreator 3.0升级到3.2出现的effect问题

// 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: water-fs:frag

      properties: &props

      mainTexture: { value: white }

      mainColor: { value: [1, 1, 1, 1], editor: { type: color } }

      occlusion: { value: 1.0, target: pbrParams.x, editor: { parent: USE_LIGHT } }

      roughness: { value: 0.1, target: pbrParams.y, editor: { parent: USE_LIGHT } }

      metallic: { value: 0, target: pbrParams.z, editor: { parent: USE_LIGHT } }

      normalStrenth: { value: 0.5, target: normalParams.x, editor: { parent: USE_NORMAL_MAP } }

      normalMap: { value: normal, editor: { parent: USE_NORMAL_MAP } }

      shallowColor: { value: [1, 1, 1, 1], editor: { type: color } }

      deepColor: { value: [0, 0, 0, 0] , editor: { type: color } }

      waveVisuals: { value: [ 0.167, 7, 0.54, 1 ], editor: { parent: USE_WAVE } }

      waveDirections: { value: [ 0, 0.3, 0.6, 0.67 ], editor: { parent: USE_WAVE } }

      causticDepth: { value: 1, target: causticParams2.x, editor: { parent: USE_CAUSTIC } }

      causticColor: { value: [1, 1, 1], target: causticParams2.yzw, editor: { parent: USE_CAUSTIC, type: color } }

      causticTexture: { value: white, editor: { parent: USE_CAUSTIC } }

      surfaceWaterDepth: { value: white , editor: { parent: USE_DEPTH }}

      depthGradientShallow: { value: [0.325, 0.807, 0.971, 0.725], editor: { type: color, parent: USE_DEPTH }}

      depthGradientDeep: { value: [0.086, 0.407, 1, 0.749], editor: { type: color, parent: USE_DEPTH}}

      depthMaxDistance: { value: 1.0 , editor: { parent: USE_DEPTH }}

  • name: transparent

    passes:

    • vert: water-vs:vert # builtin header

      frag: water-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 shared-ubos %{

#define pi 3.14

#if USE_LIGHT

uniform Light {

vec4 pbrParams;

};

#endif

uniform Water {

vec4 normalParams;

vec4 shallowColor;

vec4 deepColor;

vec4 waveVisuals;

vec4 waveDirections;

vec4 foamParams;

vec4 causticParams1;

vec4 causticParams2;

};

}%

CCProgram water-vs %{

precision highp float;

#include

#include

#include

#include

#include

#include

out vec3 v_position;

out vec4 v_projPos;

out vec2 v_uv;

out vec3 v_normal;

out float v_fog_factor;

#if USE_NORMAL_MAP

out vec3 v_tangent;

out vec3 v_bitangent;

#endif

vec3 gerstner(vec3 position, float steepness, float wavelength, float speed, float direction, inout vec3 tangent, inout vec3 binormal)

{

direction = direction * 2. - 1.;

vec2 d = normalize(vec2(cos(pi * direction), sin(pi * direction)));

float s = steepness;

float k = 2. * pi / wavelength;                                                      

float f = k * (dot(d, position.xz) - speed * cc_time.x);

float a = s / k;

tangent += vec3(

  -d.x * d.x * s * sin(f),

  d.x * s * cos(f), 

  -d.x * d.y * s * sin(f)

);

binormal += vec3(

  -d.x * d.y * s * sin(f),

  d.y * s * cos(f),

  -d.y * d.y * s * sin(f)

);

return vec3(

  d.x * a * cos(f),

  a * sin(f),

  d.y * a * cos(f)

);

}

void gerstnerWaves(vec3 p, vec3 visuals, vec4 directions, out vec3 offset, out vec3 normal, out vec3 T, out vec3 B)

{

  float steepness = visuals.x ;

  float wavelength = visuals.y;

  float speed = visuals.z;

  offset = vec3(0,0,0);

  vec3 tangent = vec3(1, 0, 0);

  vec3 binormal = vec3(0, 0, 1);

  offset += gerstner(p, steepness, wavelength, speed, directions.x, tangent, binormal);

  offset += gerstner(p, steepness, wavelength, speed, directions.y, tangent, binormal);

  offset += gerstner(p, steepness, wavelength, speed, directions.z, tangent, binormal);

  offset += gerstner(p, steepness, wavelength, speed, directions.w, tangent, binormal);

  normal = normalize(cross(binormal, tangent));

  T = tangent;

  B = binormal;

}

vec4 vert () {

StandardVertInput In;

CCVertInput(In);

mat4 matWorld, matWorldIT;

CCGetWorldMatrixFull(matWorld, matWorldIT);

vec4 worldPos = matWorld * In.position;

#if USE_WAVE

  vec3 offset;

  vec3 tangent;

  vec3 bitangent;

  gerstnerWaves(worldPos.xyz, waveVisuals.xyz, waveDirections, offset, v_normal, tangent, bitangent);

  worldPos.xyz += offset;

  #if USE_NORMAL_MAP

    v_tangent = tangent;

    v_bitangent = bitangent;

  #endif

#endif

v_position = worldPos.xyz;

v_projPos = cc_matProj * cc_matView * worldPos;

#if !USE_WAVE

  v_normal = normalize((matWorldIT * vec4(In.normal, 0.0)).xyz);

  #if USE_NORMAL_MAP

    v_tangent = normalize((matWorld * vec4(In.tangent.xyz, 0.0)).xyz);

    v_bitangent = cross(v_normal, v_tangent) * In.tangent.w; // note the cross order

  #endif

#endif

v_uv = a_texCoord;

v_fog_factor = CC_TRANSFER_FOG(worldPos);

CC_TRANSFER_SHADOW(worldPos);

return v_projPos;

}

}%

CCProgram water-fs %{

precision highp float;

#include

#include

#include

#include

#include

#include

#include

in vec3 v_position;

in vec4 v_projPos;

in vec2 v_uv;

in vec3 v_normal;

in float v_fog_factor;

#if USE_FOAM

#endif

#if USE_CAUSTIC

uniform sampler2D causticTexture;

#endif

#if USE_NORMAL_MAP

in vec3 v_tangent;

in vec3 v_bitangent;

uniform sampler2D normalMap;

#endif

#if USE_DEPTH

uniform FsConstant {

  vec4 depthGradientShallow;

  vec4 depthGradientDeep;

  float depthMaxDistance;

};

uniform sampler2D surfaceWaterDepth;

#endif

vec3 normalBlend(vec3 A, vec3 B)

{

return normalize(vec3(A.rg + B.rg, A.b * B.b));

}

#if USE_CAUSTIC

vec2 panner(vec2 uv, float direction, float speed, vec2 offset, float tiling)

{

  direction = direction * 2. - 1.;

  vec2 dir = normalize(vec2(cos(pi * direction), sin(pi * direction)));

  return  (dir * cc_time.x * speed) + offset + (uv * tiling);

}

vec3 rgbSplit(float split, sampler2D tex, vec2 uv)

{

  vec2 UVR = uv + vec2(split, split);

  vec2 UVG = uv + vec2(split, -split);

  vec2 UVB = uv + vec2(-split, -split);

  float r = texture(tex, UVR).r;

  float g = texture(tex, UVG).g;

  float b = texture(tex, UVB).b;

  return vec3(r,g,b);

}

vec3 caustic()

{

vec2 uv = v_position.xz;

float strength = causticParams1.x;

float split = causticParams1.w * 0.01;

float speed = causticParams1.z;

float scale = causticParams1.y;

vec3 texture1 = rgbSplit(split, causticTexture, panner(uv, 1., speed, vec2(0., 0.), 1./scale));

vec3 texture2 = rgbSplit(split, causticTexture, panner(uv, 1., speed, vec2(0., 0.), -1./scale));

vec3 textureCombined = min(texture1, texture2);

return strength * 10. * textureCombined;

}

#endif

vec4 alphaBlend(vec4 top, vec4 bottom)

{

vec3 color = (top.rgb * top.a) + (bottom.rgb * (1. - top.a));

float alpha = top.a + bottom.a * (1. - top.a);

return vec4(color, alpha);

}

#if USE_LIGHT

vec4 surf (vec4 albedo) {

StandardSurface s;

s.albedo = albedo;

s.normal = v_normal;

#if USE_NORMAL_MAP

  float normalStrenth = normalParams.x;

  vec2 normalUV = v_uv * normalParams.y;

  vec2 moveUV = normalUV + normalParams.zw * cc_time.x / 40.;

  vec3 nmmp = normalBlend(texture(normalMap, moveUV).xyz - vec3(.5), texture(normalMap, normalUV).xyz - vec3(.5));

  s.normal =

    (nmmp.x * normalStrenth) * normalize(v_tangent) +

    (nmmp.y * normalStrenth) * normalize(v_bitangent) +

    nmmp.z * normalize(s.normal);

#endif

s.position = v_position;

vec4 pbr = pbrParams;

s.occlusion = clamp(pbr.x, 0.0, 0.96);

s.roughness = clamp(pbr.y, 0.04, 1.0);

s.metallic = pbr.z;

return CCStandardShading(s);

}

#endif

vec4 frag () {

vec4 waterColor = shallowColor;

vec4 finalFoamColor = vec4(0.);

#if USE_FOAM

#endif

vec4 finalCausticColor = vec4(0.);

#if USE_CAUSTIC

  float causticDepth = causticParams2.x;

  vec3 causticColor = causticParams2.yzw;

  finalCausticColor.rgb = caustic() * causticColor;

#endif

#if USE_DEPTH

  float waterDepth = texture(surfaceWaterDepth, v_uv).r;

  float depth = clamp(1. - waterDepth / depthMaxDistance, 0., 1.);

  vec4 depthColor = mix(depthGradientShallow, depthGradientDeep, depth);

  waterColor = alphaBlend(depthColor, waterColor);

#endif

vec4 finalColor = waterColor + finalFoamColor + finalCausticColor;

finalColor = CC_APPLY_FOG(finalColor);

#if USE_LIGHT

finalColor = surf(finalColor);

finalColor = CCFragOutput(finalColor);

#endif

return finalColor;

}

}%

上面是我改的,但是一直报错,不知道是哪里错了。

[Asset DB] …/effect/water/effect.effect - water-fs:frag: Error EFX2302: fragment output location must be specified

at EffectImporter.import (D:\software\CocosDashboard\resources.editors\Creator\3.2.0\resources\app.asar\builtin\asset-db\dist\importer-3d\importers\effect.ccc:1:1725)

at ImportTask.importAsset (D:\software\CocosDashboard\resources.editors\Creator\3.2.0\resources\app.asar\node_modules@editor\asset-db\libs\task.ccc:1:2055)

at async ImportTask.exec (D:\software\CocosDashboard\resources.editors\Creator\3.2.0\resources\app.asar\node_modules@editor\asset-db\libs\task.ccc:1:548)

at async TaskQueue.import (D:\software\CocosDashboard\resources.editors\Creator\3.2.0\resources\app.asar\node_modules@editor\asset-db\libs\task.ccc:1:5024)

at async Promise.all (index 1)

at async D:\software\CocosDashboard\resources.editors\Creator\3.2.0\resources\app.asar\node_modules@editor\asset-db\libs\asset-db.ccc:1:7276

参考材质升级文档

https://docs.cocos.com/creator/3.1/manual/zh/material-system/Material-upgrade-documentation-for-v3.0-to-v3.1.html

这上面的我都改过了,但是还是报错,我想知道fragment output location must be specified 这个应该是改哪里

把你的 effect 贴一下吧

water.zip (4.3 KB)

这个是3.0.0的,最上面的是我改过的

,版本更新随口提了这句,然后3.1材质升级指南又没说怎么改,应该是这个问题。

解决了吗?我也遇到同样的问题了。我在shadow-caster-fs 输出了一个变量就会有这个问题。但不知道怎么改。