• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2[VS]
3#include "common.glsl:nop"
4 	varying vec3 v_shadowMapUv;
5
6#if defined(lightingFlag) && defined(shadowMapFlag)
7	uniform mat4 u_shadowMapProjViewTrans;
8
9	vec3 calcShadowMapUV(const in vec4 worldPos) {
10		vec4 spos = u_shadowMapProjViewTrans * worldPos;
11		v_shadowMapUv.xy = (spos.xy / spos.w) * 0.5 + 0.5;
12		v_shadowMapUv.z = min(spos.z * 0.5 + 0.5, 0.998);
13	}
14
15	#define passShadowMapUV(v) (v_shadowMapUV = v)
16#else
17	#define calcShadowMapUV(x) vec3(0.0)
18	#define passShadowMapUV(v) nop()
19#endif
20	#define pushShadowMapUV(v) (v_shadowMapUV = v)
21
22[FS]
23#if defined(lightingFlag) && defined(shadowMapFlag)
24 	uniform sampler2D u_shadowTexture;
25	uniform float u_shadowPCFOffset;
26	varying vec3 v_shadowMapUv;
27
28	float getShadowness(vec2 offset)
29	{
30	    const vec4 bitShifts = vec4(1.0, 1.0 / 255.0, 1.0 / 65025.0, 1.0 / 160581375.0);
31	    return step(v_shadowMapUv.z, dot(texture2D(u_shadowTexture, v_shadowMapUv.xy + offset), bitShifts));//+(1.0/255.0));
32	}
33
34	float getShadow()
35	{
36		return (//getShadowness(vec2(0,0)) +
37				getShadowness(vec2(u_shadowPCFOffset, u_shadowPCFOffset)) +
38				getShadowness(vec2(-u_shadowPCFOffset, u_shadowPCFOffset)) +
39				getShadowness(vec2(u_shadowPCFOffset, -u_shadowPCFOffset)) +
40				getShadowness(vec2(-u_shadowPCFOffset, -u_shadowPCFOffset))) * 0.20;
41	}
42#else
43	#define getShadowness(offset) (1.0)
44	#define getShadow() (1.0)
45#endif
46