// Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd. CCEffect %{ techniques: - name: opaque passes: - vert: standard-vs frag: standard-fs properties: &props tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] } 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 } } occlusion: { value: 1.0, target: pbrParams.x, editor: { 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 } } specularIntensity: { value: 0.5, target: pbrParams.w, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } } emissive: { value: [0.0, 0.0, 0.0, 1.0], linear: true, editor: { type: color } } emissiveScale: { value: [1.0, 1.0, 1.0], target: emissiveScaleParam.xyz } normalStrength: { value: 1.0, target: emissiveScaleParam.w, editor: { parent: USE_NORMAL_MAP, slide: true, range: [0, 5.0], step: 0.001 } } anisotropyShape: { value: 1.0, target: anisotropyParam.x, editor: { parent: IS_ANISOTROPY, slide : true, range : [0.0, 1.0] , step : 0.0001 } } anisotropyRotation: { value: 0.0, target: anisotropyParam.y, editor: { parent: IS_ANISOTROPY, slide : true, range : [0, 1.0] , step : 0.0001 } } mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } } normalMap: { value: normal } pbrMap: { value: grey } metallicRoughnessMap: { value: grey } occlusionMap: { value: white } emissiveMap: { value: grey } anisotropyRotationMap: { value: black, editor : { parent: IS_ANISOTROPY } } - &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: tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] } 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 } } - name: transparent passes: - vert: standard-vs frag: standard-fs embeddedMacros: { CC_FORCE_FORWARD_SHADING: true } depthStencilState: depthTest: true depthWrite: false blendState: targets: - blend: true blendSrc: src_alpha blendDst: one_minus_src_alpha blendDstAlpha: one_minus_src_alpha properties: *props - *forward-add - *shadow-caster }% CCProgram shared-ubos %{ uniform Constants { vec4 tilingOffset; vec4 albedo; vec4 albedoScaleAndCutoff; vec4 pbrParams; vec4 emissive; vec4 emissiveScaleParam; vec2 anisotropyParam; }; }% CCProgram macro-remapping %{ // ui displayed macros not used in this effect file #pragma define-meta HAS_SECOND_UV #pragma define-meta USE_TWOSIDE #pragma define-meta USE_REFLECTION_DENOISE #pragma define-meta IS_ANISOTROPY #define CC_SURFACES_USE_SECOND_UV HAS_SECOND_UV #define CC_SURFACES_USE_TWO_SIDED USE_TWOSIDE #define CC_SURFACES_USE_REFLECTION_DENOISE USE_REFLECTION_DENOISE #define CC_SURFACES_LIGHTING_ANISOTROPIC IS_ANISOTROPY // if disabled, simulate convoluted IBL without convolution #pragma define-meta USE_COMPATIBLE_LIGHTING #define CC_SURFACES_USE_LEGACY_COMPATIBLE_LIGHTING USE_COMPATIBLE_LIGHTING // ui displayed macros used in this effect file #define CC_SURFACES_USE_VERTEX_COLOR USE_VERTEX_COLOR #if IS_ANISOTROPY || USE_NORMAL_MAP #define CC_SURFACES_USE_TANGENT_SPACE 1 #endif // functionality for each effect #define CC_SURFACES_LIGHTING_ANISOTROPIC_ENVCONVOLUTION_COUNT 31 }% CCProgram surface-vertex %{ /*#define CC_SURFACES_VERTEX_MODIFY_WORLD_POS vec3 SurfacesVertexModifyWorldPos(in SurfacesStandardVertexIntermediate In) { vec3 worldPos = In.worldPos; worldPos.x += sin(cc_time.x * worldPos.z); worldPos.y += cos(cc_time.x * worldPos.z); return worldPos; } #define CC_SURFACES_VERTEX_MODIFY_WORLD_NORMAL vec3 SurfacesVertexModifyWorldNormal(in SurfacesStandardVertexIntermediate In) { vec3 worldNormal = In.worldNormal.xyz; worldNormal.x += sin(cc_time.x * 3.0); worldNormal.y += cos(cc_time.x * 3.0); return normalize(worldNormal); }*/ #define CC_SURFACES_VERTEX_MODIFY_UV void SurfacesVertexModifyUV(inout SurfacesStandardVertexIntermediate In) { In.texCoord = In.texCoord * tilingOffset.xy + tilingOffset.zw; #if CC_SURFACES_USE_SECOND_UV && !CC_SURFACES_USE_LIGHT_MAP In.texCoord1 = In.texCoord1 * tilingOffset.xy + tilingOffset.zw; #endif } }% CCProgram surface-fragment %{ #if USE_ALBEDO_MAP uniform sampler2D albedoMap; #pragma define-meta ALBEDO_UV options([v_uv, v_uv1]) #endif #if USE_NORMAL_MAP uniform sampler2D normalMap; #pragma define-meta NORMAL_UV options([v_uv, v_uv1]) #endif #pragma define-meta DEFAULT_UV options([v_uv, v_uv1]) #if USE_PBR_MAP uniform sampler2D pbrMap; #endif #if USE_METALLIC_ROUGHNESS_MAP uniform sampler2D metallicRoughnessMap; #endif #if USE_OCCLUSION_MAP uniform sampler2D occlusionMap; #endif #if USE_EMISSIVE_MAP uniform sampler2D emissiveMap; #pragma define-meta EMISSIVE_UV options([v_uv, v_uv1]) #endif #if IS_ANISOTROPY && USE_ANISOTROPY_ROTATION_MAP uniform sampler2D anisotropyRotationMap; #endif #pragma define OCCLUSION_CHANNEL r #pragma define ROUGHNESS_CHANNEL g #pragma define METALLIC_CHANNEL b #pragma define SPECULAR_INTENSITY_CHANNEL a #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_VERTEX_COLOR baseColor.rgb *= SRGBToLinear(FSInput_vertexColor.rgb); // use linear baseColor.a *= FSInput_vertexColor.a; #endif #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_MODIFY_WORLD_NORMAL vec3 SurfacesFragmentModifyWorldNormal() { vec3 normal = FSInput_worldNormal; #if USE_NORMAL_MAP vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5); normal = CalculateNormalFromTangentSpace(nmmp, emissiveScaleParam.w, normal.xyz, FSInput_worldTangent, FSInput_mirrorNormal); #endif return normalize(normal); } #define CC_SURFACES_FRAGMENT_MODIFY_ANISOTROPY_PARAMS vec4 SurfacesFragmentModifyAnisotropyParams() { float anisotropyRotation = anisotropyParam.y; float anisotropyShape = anisotropyParam.x; #if IS_ANISOTROPY && USE_ANISOTROPY_ROTATION_MAP anisotropyRotation = fract(anisotropyRotation + texture(anisotropyRotationMap, DEFAULT_UV).x); #endif return vec4(anisotropyRotation, anisotropyShape, 0.0, 0.0); } #define CC_SURFACES_FRAGMENT_MODIFY_EMISSIVE vec3 SurfacesFragmentModifyEmissive() { vec3 emissive = emissive.rgb * emissiveScaleParam.xyz; #if USE_EMISSIVE_MAP emissive *= SRGBToLinear(texture(emissiveMap, EMISSIVE_UV).rgb); #endif return emissive; } #define CC_SURFACES_FRAGMENT_MODIFY_PBRPARAMS vec4 SurfacesFragmentModifyPBRParams() { vec4 pbr = pbrParams; #if USE_PBR_MAP vec4 res = texture(pbrMap, DEFAULT_UV); pbr.x *= res.OCCLUSION_CHANNEL; pbr.y *= res.ROUGHNESS_CHANNEL; pbr.z *= res.METALLIC_CHANNEL; pbr.w *= res.SPECULAR_INTENSITY_CHANNEL; #endif #if USE_METALLIC_ROUGHNESS_MAP vec4 metallicRoughness = texture(metallicRoughnessMap, DEFAULT_UV); pbr.z *= metallicRoughness.METALLIC_CHANNEL; pbr.y *= metallicRoughness.ROUGHNESS_CHANNEL; #endif #if USE_OCCLUSION_MAP pbr.x *= texture(occlusionMap, DEFAULT_UV).OCCLUSION_CHANNEL; #endif return pbr; } }% 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 }%