| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- // Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
- CCEffect %{
- techniques:
- - name: opaque
- passes:
- - vert: unlit-vs:vert
- frag: unlit-fs:frag
- properties: &props
- mainTexture: { value: grey }
- tilingOffset: { value: [1, 1, 0, 0] }
- mainColor: { value: [1, 1, 1, 1], linear: true, editor: { type: color } }
- colorScale: { value: [1, 1, 1], target: colorScaleAndCutoff.xyz }
- alphaThreshold: { value: 0.5, target: colorScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } }
- color: { target: mainColor, linear: true, editor: { visible: false } } # backward compability
- migrations: &migs
- properties:
- mainColor: { formerlySerializedAs: color }
- - &planar-shadow
- vert: planar-shadow-vs:vert
- frag: planar-shadow-fs:frag
- phase: planar-shadow
- propertyIndex: 0
- depthStencilState:
- depthTest: true
- depthWrite: false
- stencilTestFront: true
- stencilFuncFront: not_equal
- stencilPassOpFront: replace
- stencilRef: 0x80 # only use the leftmost bit
- stencilReadMask: 0x80
- stencilWriteMask: 0x80
- blendState:
- targets:
- - blend: true
- blendSrc: src_alpha
- blendDst: one_minus_src_alpha
- blendDstAlpha: one_minus_src_alpha
- - &deferred-forward
- vert: unlit-vs:vert
- frag: unlit-fs:frag
- phase: deferred-forward
- propertyIndex: 0
- - name: transparent
- passes:
- - vert: unlit-vs:vert
- frag: unlit-fs:frag
- 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
- migrations: *migs
- - *planar-shadow
- - &deferred-forward-transparent
- vert: unlit-vs:vert
- frag: unlit-fs:frag
- phase: deferred-forward
- propertyIndex: 0
- migrations: *migs
- depthStencilState: *d1
- blendState: *b1
- - name: add
- passes:
- - vert: unlit-vs:vert
- frag: unlit-fs:frag
- rasterizerState: &r1 { cullMode: none }
- depthStencilState: *d1
- blendState: &b2
- targets:
- - blend: true
- blendSrc: src_alpha
- blendDst: one
- blendSrcAlpha: src_alpha
- blendDstAlpha: one
- properties: *props
- migrations: *migs
- - &deferred-forward-add
- vert: unlit-vs:vert
- frag: unlit-fs:frag
- phase: deferred-forward
- rasterizerState: *r1
- depthStencilState: *d1
- blendState: *b2
- propertyIndex: 0
- migrations: *migs
- - name: alpha-blend
- passes:
- - vert: unlit-vs:vert
- frag: unlit-fs:frag
- rasterizerState: *r1
- depthStencilState: *d1
- blendState: &b3
- targets:
- - blend: true
- blendSrc: src_alpha
- blendDst: one_minus_src_alpha
- blendSrcAlpha: src_alpha
- blendDstAlpha: one_minus_src_alpha
- properties: *props
- migrations: *migs
- - &deferred-forward-alpha-blend
- vert: unlit-vs:vert
- frag: unlit-fs:frag
- phase: deferred-forward
- rasterizerState: *r1
- depthStencilState: *d1
- blendState: *b3
- propertyIndex: 0
- migrations: *migs
- }%
- CCProgram unlit-vs %{
- precision highp float;
- #include <legacy/input>
- #include <builtin/uniforms/cc-global>
- #include <legacy/decode-base>
- #include <legacy/local-batch>
- #include <legacy/input>
- #include <legacy/fog-vs>
- #if USE_VERTEX_COLOR
- in lowp vec4 a_color;
- out lowp vec4 v_color;
- #endif
- #if USE_TEXTURE
- out vec2 v_uv;
- uniform TexCoords {
- vec4 tilingOffset;
- };
- #endif
- vec4 vert () {
- vec4 position;
- CCVertInput(position);
- mat4 matWorld;
- CCGetWorldMatrix(matWorld);
- #if USE_TEXTURE
- v_uv = a_texCoord * tilingOffset.xy + tilingOffset.zw;
- #if SAMPLE_FROM_RT
- CC_HANDLE_RT_SAMPLE_FLIP(v_uv);
- #endif
- #endif
- #if USE_VERTEX_COLOR
- v_color = a_color;
- #endif
- CC_TRANSFER_FOG(matWorld * position);
- #if CC_USE_2D
- return cc_matProj * cc_matView * position;
- #else
- return cc_matProj * (cc_matView * matWorld) * position;
- #endif
- }
- }%
- CCProgram unlit-fs %{
- precision highp float;
- #include <legacy/output-standard>
- #include <legacy/fog-fs>
- #if USE_ALPHA_TEST
- #pragma define-meta ALPHA_TEST_CHANNEL options([a, r, g, b])
- #endif
- #if USE_TEXTURE
- in vec2 v_uv;
- uniform sampler2D mainTexture;
- #endif
- uniform Constant {
- vec4 mainColor;
- vec4 colorScaleAndCutoff;
- };
- #if USE_VERTEX_COLOR
- in lowp vec4 v_color;
- #endif
- vec4 frag () {
- vec4 o = mainColor;
- o.rgb *= colorScaleAndCutoff.xyz;
- #if USE_VERTEX_COLOR
- o.rgb *= SRGBToLinear(v_color.rgb);//use linear
- o.a *= v_color.a;
- #endif
- #if USE_TEXTURE
- vec4 texColor = texture(mainTexture, v_uv);
- texColor.rgb = SRGBToLinear(texColor.rgb);
- o *= texColor;
- #endif
- #if USE_ALPHA_TEST
- if (o.ALPHA_TEST_CHANNEL < colorScaleAndCutoff.w) discard;
- #endif
- CC_APPLY_FOG(o);
- return CCFragOutput(o);
- }
- }%
- CCProgram planar-shadow-vs %{
- precision highp float;
- #include <legacy/input>
- #include <builtin/uniforms/cc-global>
- #include <legacy/decode-base>
- #include <legacy/local-batch>
- #include <builtin/uniforms/cc-shadow>
- #include <common/lighting/functions>
- out float v_dist;
- vec4 vert () {
- vec4 position;
- CCVertInput(position);
- // World Space
- mat4 matWorld, matWorldIT;
- CCGetWorldMatrixFull(matWorld, matWorldIT);
- vec3 worldPos = (matWorld * position).xyz;
- vec4 shadowPos = CalculatePlanarShadowPos(worldPos, cc_cameraPos.xyz, cc_mainLitDir.xyz, cc_planarNDInfo);
- position = CalculatePlanarShadowClipPos(shadowPos, cc_cameraPos.xyz, cc_matView, cc_matProj, cc_nearFar, cc_shadowWHPBInfo.w);
- v_dist = shadowPos.w;
- return position;
- }
- }%
- CCProgram planar-shadow-fs %{
- precision highp float;
- #include <builtin/uniforms/cc-shadow>
- #include <legacy/output>
- in float v_dist;
- vec4 frag () {
- if(v_dist < 0.0)
- discard;
- return CCFragOutput(cc_shadowColor);
- }
- }%
|