forked from patriciogonzalezvivo/lygia_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample_3Dsdf.frag
75 lines (57 loc) · 2.12 KB
/
sample_3Dsdf.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
73
74
75
// Copyright Patricio Gonzalez Vivo, 2022 - http://patriciogonzalezvivo.com/
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D u_tex0;
uniform sampler2D u_doubleBuffer0;
uniform vec3 u_camera;
uniform vec3 u_light;
uniform vec3 u_lightColor;
uniform vec2 u_resolution;
#define RESOLUTION u_resolution
#define LIGHT_DIRECTION u_light
#define LIGHT_COLOR vec3(0.95, 0.65, 0.5)
#define RAYMARCH_SAMPLES 250
#define RAYMARCH_MULTISAMPLE 4
#define RAYMARCHSOFTSHADOW_ITERATIONS 24
#define RAYMARCH_BACKGROUND ( vec3(0.7, 0.9, 1.0) + ray.y * 0.8 )
#define RAYMARCH_AMBIENT vec3(0.7, 0.9, 1.0)
#define SAMPLE2DCUBE_FLIP_Y
// #define SAMPLE2DCUBE_CELL_SIZE 64.0
// #define SAMPLE2DCUBE_CELLS_PER_SIDE 8.0
#define SAMPLE2DCUBE_FNC(TEX, UV) sampleBicubic(TEX, UV, vec2(512.0))
// #define SAMPLE2DCUBE_FNC(TEX, UV) sampleSmooth(TEX, UV, vec2(512.0))
// #define SAMPLE2DCUBE_FNC(TEX, UV) sampleNearest(TEX, UV, vec2(512.0))
#include "lygia/math/cubic.glsl"
#include "lygia/math/quartic.glsl"
#include "lygia/math/quintic.glsl"
#include "lygia/sdf.glsl"
#include "lygia/space/ratio.glsl"
#include "lygia/space/scale.glsl"
#include "lygia/sample/bicubic.glsl"
#include "lygia/sample/smooth.glsl"
#include "lygia/sample/nearest.glsl"
#include "lygia/sample/3DSdf.glsl"
#include "lygia/math/saturate.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);
}
vec4 raymarchMap( in vec3 pos ) {
vec4 res = vec4(1.);
res = opUnion(res, vec4( 1.0, 1.0, 1.0, sample3DSdf(u_tex0, pos) ));
float check = checkBoard(pos.xz, vec2(1.0));
res = opUnion( res, vec4( vec3( 0.5 + check * 0.5), planeSDF(pos + 1.0) ) );
return res;
}
void main() {
vec3 color = vec3(0.0);
vec2 pixel = 1.0/u_resolution;
vec2 st = gl_FragCoord.xy * pixel;
vec2 uv = ratio(st, u_resolution);
color = raymarch(u_camera, uv).rgb;
color = linear2gamma( color );
gl_FragColor = vec4( color, 1.0 );
}