// Effect Syntax Guide: https://docs.cocos.com/creator/manual/zh/shader/index.html CCEffect %{ techniques: - name: opaque passes: - vert: standard-vs # builtin header frag: unlit-fs:fragFront rasterizerState: cullMode: back depthStencilState: depthTest: true depthWrite: false stencilTest: true stencilFunc: not_equal stencilPassOp: replace stencilRef: 0x80 # only use the leftmost bit stencilReadMask: 0x80 stencilWriteMask: 0x80 blendState: targets: - blend: true blendSrc: zero blendDst: one - vert: standard-vs frag: standard-fs properties: &props mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } } mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, linear: true, editor: { displayName: Albedo, type: color } } albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz } alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST, slide: true, range: [0, 1.0], step: 0.001 } } roughness: { value: 0.8, target: pbrParams.y, editor: { slide: true, range: [0, 1.0], step: 0.001 } } metallic: { value: 0.6, target: pbrParams.z, editor: { slide: true, range: [0, 1.0], step: 0.001 } } rasterizerState: cullMode: front depthStencilState: stencilTest: true stencilFunc: equal stencilRef: 0x80 depthFunc: greater blendState: targets: - blend: true blendSrc: one blendDst: zero # - &forward-add # vert: standard-vs # frag: standard-fs # phase: forward-add # propertyIndex: 0 # embeddedMacros: { CC_FORWARD_ADD: true } # depthStencilState: # depthFunc: equal # depthTest: true # depthWrite: false # blendState: # targets: # - blend: true # blendSrc: one # blendDst: one # blendSrcAlpha: zero # blendDstAlpha: one # - &shadow-caster # vert: shadow-caster-vs # frag: shadow-caster-fs # phase: shadow-caster # propertyIndex: 0 # rasterizerState: # cullMode: front # properties: # mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, editor: { displayName: Albedo, type: color } } # albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz } # alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } } # mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } } }% CCProgram shared-ubos %{ uniform Constants { vec4 albedo; vec4 albedoScaleAndCutoff; vec4 pbrParams; }; }% CCProgram macro-remapping %{ // ui displayed macros #pragma define-meta USE_TWOSIDE #pragma define-meta USE_VERTEX_COLOR #define CC_SURFACES_USE_TWO_SIDED USE_TWOSIDE #define CC_SURFACES_USE_VERTEX_COLOR USE_VERTEX_COLOR }% CCProgram surface-vertex %{ #define CC_SURFACES_VERTEX_MODIFY_WORLD_POS vec3 SurfacesVertexModifyWorldPos(in SurfacesStandardVertexIntermediate In) { return In.worldPos; } #define CC_SURFACES_VERTEX_MODIFY_WORLD_NORMAL vec3 SurfacesVertexModifyWorldNormal(in SurfacesStandardVertexIntermediate In) { return In.worldNormal.xyz; } #define CC_SURFACES_VERTEX_MODIFY_UV void SurfacesVertexModifyUV(inout SurfacesStandardVertexIntermediate In) { } }% CCProgram surface-fragment %{ #if USE_ALBEDO_MAP uniform sampler2D albedoMap; #pragma define-meta ALBEDO_UV options([v_uv, v_uv1]) #endif #if USE_ALPHA_TEST #pragma define-meta ALPHA_TEST_CHANNEL options([a, r]) #endif #define CC_SURFACES_FRAGMENT_MODIFY_BASECOLOR_AND_TRANSPARENCY vec4 SurfacesFragmentModifyBaseColorAndTransparency() { vec4 baseColor = albedo; #if USE_ALBEDO_MAP vec4 texColor = texture(albedoMap, ALBEDO_UV); texColor.rgb = SRGBToLinear(texColor.rgb); baseColor *= texColor; #endif #if USE_ALPHA_TEST if (baseColor.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard; #endif baseColor.rgb *= albedoScaleAndCutoff.xyz; return baseColor; } #define CC_SURFACES_FRAGMENT_ALPHA_CLIP_ONLY void SurfacesFragmentAlphaClipOnly() { #if USE_ALPHA_TEST float alpha = albedo.ALPHA_TEST_CHANNEL; #if USE_VERTEX_COLOR alpha *= FSInput_vertexColor.a; #endif #if USE_ALBEDO_MAP alpha = texture(albedoMap, ALBEDO_UV).ALPHA_TEST_CHANNEL; #endif if (alpha < albedoScaleAndCutoff.w) discard; #endif } #define CC_SURFACES_FRAGMENT_MODIFY_WORLD_NORMAL vec3 SurfacesFragmentModifyWorldNormal() { // 背面法线方向是反的,所以挖洞时需要在这里取反 return normalize(-FSInput_worldNormal); } #define CC_SURFACES_FRAGMENT_MODIFY_EMISSIVE vec3 SurfacesFragmentModifyEmissive() { return vec3(0.0, 0.0, 0.0); } #define CC_SURFACES_FRAGMENT_MODIFY_PBRPARAMS vec4 SurfacesFragmentModifyPBRParams() { // ao, roughness, metallic, specularIntensity return vec4(1.0, pbrParams.y, pbrParams.z, 0.5); } }% CCProgram standard-vs %{ precision highp float; // 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros #include #include // 2. common include with corresponding shader stage, include before surface functions #include // 3. user surface functions that can use user (effect) parameters (ubo Constants) // see surfaces/default-functions/xxx.chunk #include #include // 4. surface include with corresponding shader stage and shading-model (optional) #include // 5. shader entry with corresponding shader stage and technique usage/type #include }% CCProgram shadow-caster-vs %{ precision highp float; #include #include #include #include #include }% CCProgram standard-fs %{ // shading-model : standard // lighting-model : standard (isotropy / anisotropy pbr) // shader stage : fs // technique usage/type : render-to-scene precision highp float; // 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros #include #include // 2. common include with corresponding shader stage, include before surface functions #include // 3. user surface functions that can use user (effect) parameters (ubo Constants) // see surfaces/default-functions/xxx.chunk #include #include // 4. lighting-model (optional) #include // 5. surface include with corresponding shader stage and shading-model (optional) #include // 6. shader entry with corresponding shader stage and technique usage/type #include }% CCProgram shadow-caster-fs %{ precision highp float; #include #include #include #include #include }% CCProgram unlit-fs %{ precision highp float; #include vec4 fragFront() { return vec4(1.0, 0.0, 1.0, 1.0); } }%