forked from patriciogonzalezvivo/lygia_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lighting_raymarching_volume.frag
52 lines (38 loc) · 1.23 KB
/
lighting_raymarching_volume.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
// 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 vec3 u_lightColor;
uniform vec2 u_resolution;
varying vec2 v_texcoord;
#include "lygia/math/saturate.glsl"
#include "lygia/space/ratio.glsl"
#include "lygia/generative/fbm.glsl"
#include "lygia/color/space/linear2gamma.glsl"
#include "lygia/sdf/boxFrameSDF.glsl"
#define LIGHT_COLOR vec3(0.5, 0.8, 0.9)
#define RAYMARCH_RENDER_FNC(RO, RD) raymarchVolume(RO, RD)
vec4 raymarchVolume( in vec3 ro, in vec3 rd );
#include "lygia/lighting/raymarch.glsl"
#include "lygia/lighting/raymarch/volume.glsl"
vec4 raymarchMap(in vec3 pos) {
vec4 res = vec4(1.);
vec3 p = pos.xzy;
res.a = boxFrameSDF(pos, vec3(1.0), 0.1);
res.a *= (fbm(pos * 2.0) * 0.5 + 0.5);
res.a *= 2.0;
return saturate(res);
}
void main(void) {
vec3 color = vec3(0.0);
vec2 pixel = 1.0/u_resolution;
vec2 st = v_texcoord;
vec2 uv = ratio(st, u_resolution);
color.rgb += raymarch(u_camera, uv).rgb;
color = linear2gamma(color);
gl_FragColor = vec4(color, 1.0);
}