mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-20 23:52:40 +08:00
9f83fb1ae9
* Add specular intensity for DCC effects effect data migrates for include decode-base and specular intensity * update compiled shaders
74 lines
1.7 KiB
Plaintext
74 lines
1.7 KiB
Plaintext
// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
|
|
|
|
CCEffect %{
|
|
techniques:
|
|
- passes:
|
|
- vert: planar-shadow-vs:vert
|
|
frag: planar-shadow-fs:frag
|
|
phase: planarShadow
|
|
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
|
|
}%
|
|
|
|
CCProgram planar-shadow-vs %{
|
|
precision highp float;
|
|
#include <input>
|
|
#include <cc-global>
|
|
#include <decode-base>
|
|
#include <cc-local-batch>
|
|
#include <cc-shadow>
|
|
|
|
out float v_dist;
|
|
|
|
vec4 vert () {
|
|
vec4 position;
|
|
CCVertInput(position);
|
|
|
|
mat4 matWorld;
|
|
CCGetWorldMatrix(matWorld);
|
|
|
|
vec3 P = (matWorld * position).xyz;
|
|
vec3 L = cc_mainLitDir.xyz;
|
|
vec3 N = cc_planarNDInfo.xyz;
|
|
float d = cc_planarNDInfo.w + 0.001;
|
|
float dist = (-d - dot(P, N)) / (dot(L, N) + 0.0001);
|
|
vec3 shadowPos = P + L * dist;
|
|
|
|
// avoid z-fighting with shadow plane
|
|
vec3 view = normalize(cc_cameraPos.xyz - shadowPos);
|
|
float viewLength = length(cc_cameraPos.xyz - shadowPos);
|
|
shadowPos += view * min(1.0, 0.005 * viewLength);
|
|
|
|
position = cc_matProj * cc_matView * vec4(shadowPos, 1.0);
|
|
v_dist = dist;
|
|
return position;
|
|
}
|
|
}%
|
|
|
|
CCProgram planar-shadow-fs %{
|
|
precision mediump float;
|
|
#include <cc-shadow>
|
|
#include <output>
|
|
|
|
in float v_dist;
|
|
|
|
vec4 frag () {
|
|
if(v_dist < 0.0)
|
|
discard;
|
|
return CCFragOutput(cc_shadowColor);
|
|
}
|
|
}%
|