Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save patriciogonzalezvivo/93959808404aebc0c365cae5132f18b0 to your computer and use it in GitHub Desktop.
Save patriciogonzalezvivo/93959808404aebc0c365cae5132f18b0 to your computer and use it in GitHub Desktop.
// Great example of the use of Lygia samplers functions https://github.com/patriciogonzalezvivo/lygia/tree/main/sample
// and GlslViewer https://github.com/patriciogonzalezvivo/glslViewer
// on the Looking Glass Display
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D u_buffer0;
uniform sampler2D u_buffer1;
uniform sampler2D u_scene;
uniform sampler2D u_sceneDepth;
uniform vec3 u_camera;
uniform float u_cameraFarClip;
uniform float u_cameraNearClip;
uniform vec3 u_holoPlayTile;
uniform vec4 u_holoPlayCalibration; // dpi, pitch, slope, center
uniform vec2 u_holoPlayRB; // ri, bi
uniform vec3 u_light;
uniform vec2 u_resolution;
varying vec4 v_position;
varying vec4 v_color;
varying vec3 v_normal;
varying vec2 v_texcoord;
#ifdef LIGHT_SHADOWMAP
uniform sampler2D u_lightShadowMap;
uniform mat4 u_lightMatrix;
varying vec4 v_lightCoord;
#endif
#ifdef MODEL_VERTEX_TANGENT
varying mat3 v_tangentToWorld;
varying vec4 v_tangent;
#endif
#include "lygia/space/linearizeDepth.glsl"
// #define TEXTUREDOF_DEBUG
#define TEXTUREDOF_DEPTH_FNC(UV) linearizeDepth(texture2D(texDepth,UV).r, u_cameraNearClip, u_cameraFarClip * 0.002)
#include "lygia/sample/textureDoF.glsl"
#include "lygia/sample/textureShadow.glsl"
#define TEXTUREQUILT_SAMPLE_FNC(UV) textureDoF(u_scene, u_sceneDepth, UV, .835, 10.)
#include "lygia/sample/textureQuilt.glsl"
void main(void) {
vec3 color = vec3(0.0);
vec2 uv = v_texcoord;
vec2 st = gl_FragCoord.xy/u_resolution.xy;
vec2 pixel = 1./u_resolution.xy;
#ifdef BACKGROUND
color.rgb += uv.y * 0.2;
#elif defined(POSTPROCESSING)
color = textureQuilt(u_scene, u_holoPlayCalibration, u_holoPlayTile, st, u_resolution);
#else
color += v_color;
float shade = smoothstep(-1.0, 1.0, dot(v_normal, normalize(u_light)));
#ifdef LIGHT_SHADOWMAP
shade *= 1.0 - step(textureShadow(u_lightShadowMap, v_lightCoord), v_lightCoord.z - 0.005) * 0.5;
#endif
color *= shade;
#endif
gl_FragColor = vec4(color, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment