forked from patriciogonzalezvivo/lygia_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlighting_gooch.frag
72 lines (54 loc) · 1.64 KB
/
lighting_gooch.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright Patricio Gonzalez Vivo, 2022 - http://patriciogonzalezvivo.com/
#ifdef GL_ES
precision mediump float;
#endif
uniform vec3 u_camera;
uniform vec3 u_light;
uniform vec3 u_lightColor;
#ifdef LIGHT_SHADOWMAP
uniform sampler2D u_lightShadowMap;
uniform mat4 u_lightMatrix;
varying vec4 v_lightCoord;
#endif
uniform vec2 u_resolution;
varying vec4 v_position;
#ifdef MODEL_VERTEX_COLOR
varying vec4 v_color;
#endif
#ifdef MODEL_VERTEX_NORMAL
varying vec3 v_normal;
#endif
#ifdef MODEL_VERTEX_TEXCOORD
varying vec2 v_texcoord;
#endif
varying vec4 v_tangent;
#define SURFACE_POSITION v_position
#define CAMERA_POSITION u_camera
#define LIGHT_DIRECTION u_light
#define GOOCH_SPECULAR u_lightColor
#define LIGHT_COORD v_lightCoord
#include "lygia/color/space/linear2gamma.glsl"
#include "lygia/lighting/gooch.glsl"
#include "lygia/lighting/material/new.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;
vec2 uv = st;
#if defined(MODEL_VERTEX_TEXCOORD)
uv = v_texcoord;
#endif
Material material = materialNew();
material.roughness = 0.3;
#if defined(FLOOR) && defined(MODEL_VERTEX_TEXCOORD)
material.albedo.rgb = vec3(0.5) + checkBoard(v_texcoord, vec2(8.0)) * 0.5;
#endif
color = gooch(material);
// color = linear2gamma(color);
// color += 1.0;
gl_FragColor = color;
}