| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409 |
- // Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd.
- CCEffect %{
- techniques:
- - name: opaque
- passes:
- - vert: standard-vs
- frag: standard-fs
- properties: &props
- vatSpeed: { value: 1.0, target: vatParams.x, editor: { displayName: AnimationSpeed } }
- vatFrameCount: { value: 0.0, target: vatParams.y, editor: { displayName: NumOfFrames } }
- vatDebugFrame: { value: 0.0, target: vatParams.z, editor: { displayName: DebugFrame, range: [0, 60], step: 1 } }
- vatPivMax: { value: 1.0, target: vatMaxMin.x, editor: { displayName: PivMax } }
- vatPivMin: { value: 1.0, target: vatMaxMin.y, editor: { displayName: PivMin } }
- vatPosMax: { value: 1.0, target: vatMaxMin.z, editor: { displayName: PosMax } }
- vatPosMin: { value: 1.0, target: vatMaxMin.w, editor: { displayName: PosMin } }
- 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: 0.0, target: pbrParams.x, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
- roughness: { value: 0.5, target: pbrParams.y, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
- metallic: { value: 0.0, 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 } }
- anisotropyIntensity: { 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 } }
- anisotropyMapResolutionHeight: { value: 0.0, target: anisotropyParam.w, editor: { parent: FIX_ANISOTROPIC_ROTATION_MAP } }
- mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
- normalMap: { value: normal }
- pbrMap: { value: grey }
- occlusionMap: { value: white }
- emissiveMap: { value: grey }
- anisotropyMap: { value: black, editor : { parent: IS_ANISOTROPY } }
- vatPositionMap: { value: grey, target: vatPositionTexture, editor: { displayName: PositionMap } }
- vatPosSignMap: { value: white, target: vatPosSignTexture, editor: { displayName: PosSignMap } }
- vatPosAlphaMap: { value: grey, target: vatPosAlphaTexture, editor: { displayName: PosAlphaMap } }
- vatRotationMap: { value: grey, target: vatRotationTexture, editor: { displayName: RotationMap } }
- vatRotSignMap: { value: white, target: vatRotSignTexture, editor: { displayName: RotSignMap } }
- vatRotAlphaMap: { value: grey, target: vatRotAlphaTexture, editor: { displayName: RotAlphaMap } }
- rasterizerState: &r1
- cullMode: none
- - &forward-add
- vert: standard-vs
- frag: standard-fs
- phase: forward-add
- propertyIndex: 0
- embeddedMacros: { CC_FORWARD_ADD: true }
- rasterizerState:
- cullMode: none
- 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 } }
- - &reflect-map
- vert: standard-vs
- frag: reflect-map-fs
- phase: reflect-map
- propertyIndex: 0
- - &deferred-forward
- vert: standard-vs
- frag: standard-fs
- phase: deferred-forward
- propertyIndex: 0
- rasterizerState: *r1
- - name: transparent
- passes:
- - vert: standard-vs
- frag: standard-fs
- embeddedMacros: { CC_FORCE_FORWARD_SHADING: true }
- depthStencilState: &d1
- depthTest: true
- depthWrite: false
- blendState: &b1
- targets:
- - blend: true
- blendSrc: src_alpha
- blendDst: one_minus_src_alpha
- blendDstAlpha: one_minus_src_alpha
- properties: *props
- - *forward-add
- - *shadow-caster
- - &deferred-forward
- vert: standard-vs
- frag: standard-fs
- phase: deferred-forward
- embeddedMacros: { CC_PIPELINE_TYPE: 0 }
- depthStencilState: *d1
- blendState: *b1
- propertyIndex: 0
- }%
- CCProgram shared-ubos %{
- uniform Constants {
- vec4 vatParams;
- vec4 vatMaxMin;
- vec4 albedo;
- vec4 albedoScaleAndCutoff;
- vec4 pbrParams;
- vec4 emissive;
- vec4 emissiveScaleParam;
- vec4 anisotropyParam;
- };
- }%
- CCProgram macro-remapping %{
- // ui displayed macros
- #pragma define-meta USE_TWOSIDE
- #pragma define-meta IS_ANISOTROPY
- #pragma define-meta USE_VERTEX_COLOR
- #define CC_SURFACES_USE_SECOND_UV 1
- #define CC_SURFACES_USE_TWO_SIDED USE_TWOSIDE
- #define CC_SURFACES_LIGHTING_ANISOTROPIC IS_ANISOTROPY
- #define CC_SURFACES_USE_VERTEX_COLOR USE_VERTEX_COLOR
- // depend on UI macros
- #if USE_NORMAL_MAP
- #define CC_SURFACES_USE_TANGENT_SPACE 1
- #endif
- #define CC_SURFACES_LIGHTING_ANISOTROPIC_ENVCONVOLUTION_COUNT 31
- }%
- CCProgram surface-vertex %{
- #include <common/mesh/vat-animation>
- #if CC_SURFACES_USE_SECOND_UV
- in vec2 a_texCoord2;
- in vec2 a_texCoord3;
- #endif
- uniform highp sampler2D vatPositionTexture;
- uniform highp sampler2D vatPosSignTexture;
- uniform highp sampler2D vatPosAlphaTexture;
- uniform highp sampler2D vatRotationTexture;
- uniform highp sampler2D vatRotSignTexture;
- uniform highp sampler2D vatRotAlphaTexture;
- #define CC_SURFACES_VERTEX_MODIFY_LOCAL_SHARED_DATA
- void SurfacesVertexModifyLocalSharedData(inout SurfacesStandardVertexIntermediate In)
- {
- vec2 originUV = In.texCoord, thisFrameUV, nextFrameUV;
- vec2 uv2 = originUV, uv3 = originUV;
- #if CC_SURFACES_USE_SECOND_UV
- originUV = In.texCoord1;
- uv2 = a_texCoord2;
- uv3 = a_texCoord3;
- #endif
- float numOfFrames = vatParams.y, speed = vatParams.x;
- float frameLerp = VATGetAnimUV(thisFrameUV, nextFrameUV, originUV, numOfFrames, speed, cc_time.x);
- // thisFrameUV = originUV + vec2(0.0, vatParams.z / numOfFrames);
- #if USE_VERTEX_COLOR
- vec4 color = In.color;
- #else
- vec4 color = vec4(0.0);
- #endif
- #if CC_SURFACES_USE_TANGENT_SPACE
- vec3 tangent = In.tangent.xzy;
- #else
- vec3 tangent = vec3(0.0);
- #endif
- VATGetLocalPositionRigidBody20_UE(In.position.xyz, In.normal.xyz, tangent, color, thisFrameUV,
- vatMaxMin.x, vatMaxMin.y, vatMaxMin.z, vatMaxMin.w,
- vatPositionTexture, vatPosSignTexture, vatPosAlphaTexture, vatRotationTexture, vatRotSignTexture, vatRotAlphaTexture);
- #if CC_SURFACES_USE_TANGENT_SPACE
- In.tangent.xyz = normalize(tangent);
- #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_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_MAP
- uniform sampler2D anisotropyMap;
- #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_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()
- {
- 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(out float isRotation)
- {
- float anisotropyRotation = anisotropyParam.y * PI;
- float anisotropyShape = anisotropyParam.x;
- #if IS_ANISOTROPY && USE_ANISOTROPY_MAP
- // Rotation angle should disable trilinear filtering
- vec4 tex = texture(anisotropyMap, DEFAULT_UV);
- anisotropyRotation = fract(anisotropyRotation * 0.5 + tex.y) * PI2;
- // less value is better for SP exported shape
- anisotropyShape *= tex.x;
- #endif
- isRotation = 1.0;
- return vec4(anisotropyShape, anisotropyRotation, 0.0, 0.0);
- }
- #define CC_SURFACES_FRAGMENT_MODIFY_EMISSIVE
- vec3 SurfacesFragmentModifyEmissive()
- {
- vec3 emissive = emissive.rgb;
- #if USE_EMISSIVE_MAP
- emissive = SRGBToLinear(texture(emissiveMap, EMISSIVE_UV).rgb);
- #endif
- return emissive * emissiveScaleParam.xyz;
- }
- #define CC_SURFACES_FRAGMENT_MODIFY_PBRPARAMS
- vec4 SurfacesFragmentModifyPBRParams()
- {
- vec4 pbr = pbrParams;
- pbr.x = 1.0;
- #if USE_PBR_MAP
- vec4 res = texture(pbrMap, DEFAULT_UV);
- pbr.x = mix(1.0, res.OCCLUSION_CHANNEL, pbrParams.x);
- pbr.y *= res.ROUGHNESS_CHANNEL;
- pbr.z *= res.METALLIC_CHANNEL;
- pbr.w *= res.SPECULAR_INTENSITY_CHANNEL;
- #endif
- #if USE_OCCLUSION_MAP
- pbr.x = mix(1.0, texture(occlusionMap, DEFAULT_UV).OCCLUSION_CHANNEL, pbrParams.x);
- #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 <macro-remapping>
- #include <surfaces/effect-macros/common-macros>
- // 2. common include with corresponding shader stage, include before surface functions
- #include <surfaces/includes/common-vs>
- // 3. user surface functions that can use user (effect) parameters (ubo Constants)
- // see surfaces/default-functions/xxx.chunk
- #include <shared-ubos>
- #include <surface-vertex>
- // 4. surface include with corresponding shader stage and shading-model (optional)
- #include <surfaces/includes/standard-vs>
- // 5. shader entry with corresponding shader stage and technique usage/type
- #include <shading-entries/main-functions/render-to-scene/vs>
- }%
- CCProgram shadow-caster-vs %{
- precision highp float;
- #include <macro-remapping>
- #include <surfaces/effect-macros/render-to-shadowmap>
- #include <surfaces/includes/common-vs>
- #include <shared-ubos>
- #include <surface-vertex>
- #include <shading-entries/main-functions/render-to-shadowmap/vs>
- }%
- 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 <macro-remapping>
- #include <surfaces/effect-macros/common-macros>
- // 2. common include with corresponding shader stage, include before surface functions
- #include <surfaces/includes/common-fs>
- // 3. user surface functions that can use user (effect) parameters (ubo Constants)
- // see surfaces/default-functions/xxx.chunk
- #include <shared-ubos>
- #include <surface-fragment>
- // 4. lighting-model (optional)
- #include <lighting-models/includes/standard>
- // 5. surface include with corresponding shader stage and shading-model (optional)
- #include <surfaces/includes/standard-fs>
- // 6. shader entry with corresponding shader stage and technique usage/type
- #include <shading-entries/main-functions/render-to-scene/fs>
- }%
- CCProgram shadow-caster-fs %{
- precision highp float;
- #include <macro-remapping>
- #include <surfaces/effect-macros/render-to-shadowmap>
- #include <surfaces/includes/common-fs>
- #include <shared-ubos>
- #include <surface-fragment>
- #include <shading-entries/main-functions/render-to-shadowmap/fs>
- }%
- CCProgram reflect-map-fs %{
- precision highp float;
- #include <macro-remapping>
- #include <surfaces/effect-macros/common-macros>
- #include <surfaces/includes/common-fs>
- #include <shared-ubos>
- #include <surface-fragment>
- #include <lighting-models/includes/standard>
- #include <surfaces/includes/standard-fs>
- #include <shading-entries/main-functions/render-to-reflectmap/fs>
- }%
|