-
Notifications
You must be signed in to change notification settings - Fork 6
/
lighting_position.frag
70 lines (52 loc) · 1.59 KB
/
lighting_position.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
// Copyright Patricio Gonzalez Vivo, 2022 - http://patriciogonzalezvivo.com/
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D u_scene;
uniform sampler2D u_sceneDepth;
uniform sampler2D u_sceneNormal;
uniform sampler2D u_scenePosition;
uniform mat4 u_viewMatrix;
uniform mat4 u_projectionMatrix;
uniform mat4 u_inverseProjectionMatrix;
uniform vec3 u_camera;
uniform float u_cameraFarClip;
uniform float u_cameraNearClip;
uniform vec2 u_resolution;
uniform vec2 u_mouse;
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
#ifdef MODEL_VERTEX_TANGENT
varying vec4 v_tangent;
varying mat3 v_tangentToWorld;
#endif
#include "lygia/math/inverse.glsl"
#define INVERSE_CAMERA_PROJECTION_MATRIX inverse(u_projectionMatrix)
#include "lygia/sample/viewPosition.glsl"
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;
#if defined(POSTPROCESSING)
vec4 viewPosFromBuffer = texture2D(u_scenePosition, st);
vec4 viewPosFromDepth = sampleViewPosition(u_sceneDepth, st, u_cameraNearClip, u_cameraFarClip);
color.rgb = mix(viewPosFromBuffer.xyz,
viewPosFromDepth.xyz,
step(0.5, st.x) );
#else
#ifdef MODEL_VERTEX_COLOR
color = v_color;
#endif
#if defined(FLOOR)
#endif
#endif
gl_FragColor = color;
}