-
Notifications
You must be signed in to change notification settings - Fork 7
/
lighting_sphereMap.frag
54 lines (41 loc) · 1.34 KB
/
lighting_sphereMap.frag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright Patricio Gonzalez Vivo, 2022 - http://patriciogonzalezvivo.com/
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D u_tex0;
uniform vec3 u_camera;
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
varying vec4 v_position;
varying vec3 v_normal;
#ifdef MODEL_VERTEX_TEXCOORD
varying vec2 v_texcoord;
#endif
#ifdef LIGHT_SHADOWMAP
uniform sampler2D u_lightShadowMap;
uniform mat4 u_lightMatrix;
varying vec4 v_lightCoord;
#endif
#include "lygia/sample/shadowPCF.glsl"
#include "lygia/lighting/sphereMap.glsl"
float checkBoard(vec2 uv, vec2 _scale) {
uv = floor(fract(uv * _scale) * 2.0);
return min(1.0, uv.x + uv.y) - (uv.x * uv.y);
}
void main(void) {
vec4 color = vec4(0.0, 0.0, 0.0, 1.0);
vec2 pixel = 1.0/u_resolution;
vec2 st = gl_FragCoord.xy * pixel;
// Floor Pattern
#if defined(FLOOR) && defined(MODEL_VERTEX_TEXCOORD)
color.rgb = vec3(0.5) + checkBoard(v_texcoord, vec2(8.0)) * 0.5;
#else
color = sphereMap(u_tex0, v_normal, u_camera);
#endif
// Shadow
#if defined(LIGHT_SHADOWMAP) && defined(LIGHT_SHADOWMAP_SIZE)
color.rgb *= sampleShadowPCF(u_lightShadowMap, vec2(LIGHT_SHADOWMAP_SIZE), v_lightCoord.xy, v_lightCoord.z - 0.005) * 0.8 + 0.2;
#endif
gl_FragColor = color;
}