-
Notifications
You must be signed in to change notification settings - Fork 7
/
lighting_raymarching_pbrLittle.frag
69 lines (53 loc) · 2.09 KB
/
lighting_raymarching_pbrLittle.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
// Copyright Patricio Gonzalez Vivo, 2021 - http://patriciogonzalezvivo.com/
#ifdef GL_ES
precision highp float;
#endif
uniform samplerCube u_cubeMap;
uniform vec3 u_SH[9];
uniform vec3 u_camera;
uniform vec3 u_light;
uniform vec2 u_resolution;
uniform float u_time;
varying vec2 v_texcoord;
#define RESOLUTION u_resolution
#define CAMERA_POSITION u_camera
#define LIGHT_COLOR vec3(1.0)
#define LIGHT_DIRECTION u_light
#define LOOK_AT_RIGHT_HANDED
#define RAYMARCH_MULTISAMPLE 4
#define SCENE_CUBEMAP u_cubeMap
// #include "lygia/lighting/atmosphere.glsl"
// #define ENVMAP_FNC(N, R, M) atmosphere(normalize(N), normalize(u_light))
#define RAYMARCH_BACKGROUND envMap(rayDirection, 0.0, 0.0).rgb
#define RAYMARCH_AMBIENT envMap(worldNormal, 0.0, 0.0).rgb
#define RAYMARCH_SHADING_FNC pbrLittle
#include "lygia/space/ratio.glsl"
#include "lygia/sdf.glsl"
#include "lygia/lighting/envMap.glsl"
#include "lygia/lighting/raymarch/softShadow.glsl"
#include "lygia/lighting/pbrLittle.glsl"
#include "lygia/lighting/raymarch.glsl"
#include "lygia/color/space/linear2gamma.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);
}
Material raymarchMap( in vec3 pos ) {
float check = 0.5 + checkBoard(pos.xz, vec2(1.0, 1.0)) * 0.5;
Material res = materialNew(vec3(check), 0.0, 0.5, planeSDF(pos));
float roughness = 0.0001 + (floor(pos.x + 0.5) * 0.25) + 0.5;
float metallic = 0.0 + (floor(pos.z + 0.5) * 0.25) + 0.4;
pos = opRepeat(pos + vec3(0.5, 0.2, 0.5), vec3(-2.0, 0.0, -2.0), vec3(2.0, 0.0, 2.0), 1.0) - 0.5;
res = opUnion( res, materialNew( vec3(0.5), roughness, metallic, sphereSDF(pos, 0.3 ) ) );
return res;
}
void main(void) {
vec4 color = vec4(0.0, 0.0, 0.0, 1.0);
vec2 pixel = 1.0/u_resolution;
vec2 st = v_texcoord;
vec2 uv = ratio(st, u_resolution);
vec3 cam = u_camera * 0.11;
color.rgb += raymarch(cam, vec3(0.0), uv).rgb;
color = linear2gamma(color);
gl_FragColor = color;
}