Skip to content

Instantly share code, notes, and snippets.

@skrat
Created October 29, 2015 10:38
Show Gist options
  • Save skrat/a2d742f723ac004cbe2f to your computer and use it in GitHub Desktop.
Save skrat/a2d742f723ac004cbe2f to your computer and use it in GitHub Desktop.
float sdPlane(vec3 p, vec4 n) {
// n must be normalized
return dot(p, n.xyz) + n.w;
}
vec3 opTx(mat4 m, vec3 p) {
vec4 q = m * vec4(p, 1.0);
return q.xyz;
}
float opU(float d1, float d2) {
return min(d1, d2);
}
void main(){
vec2 uv = gl_FragCoord.xy/viewport;
vec4 eye_data = vec4(
texture2D(eye_normal, uv).rgb,
unpack16f(texture2D(eye_depth, uv).rg));
vec4 eye_data_floor = vec4(
texture2D(eye_normal_floor, uv).rgb,
unpack16f(texture2D(eye_depth_floor, uv).rg));
if (eye_data.w == 0.0) {
eye_data.w = 1000.0;
}
if (eye_data_floor.w == 0.0) {
eye_data_floor.w = 1000.0;
}
vec3 normal;
float depth;
if (eye_data.w < eye_data_floor.w) {
normal = eye_data.xyz;
depth = eye_data.w;
} else {
normal = eye_data_floor.xyz;
depth = eye_data_floor.w;
const vec4 gp = vec4(0.0, 1.0, 0.0, 0.0); // ground plane
float cps = 1.0 / (far - near);
/* depth = sdPlane( */
/* normalize( */
/* (inv_eye_view * inv_eye_proj * vec4(clip, 1.0, cps)).xyz), */
/* vec4(0.0, 1.0, 0.0, 0.0)); */
depth = sdPlane(opTx(inv_eye_view * inv_eye_proj, vec3(clip, 1.0)), gp);
depth = depth + cps*far;
}
/* depth = near + (depth * (far - near)); */
vec4 ro = inv_eye_proj * vec4(clip, 1.0, 1.0);
vec3 rd = normalize(ro.xyz);
vec3 eye_p = depth * rd;
vec3 p = (inv_eye_view * vec4(eye_p, 1.0)).xyz;
float occlusion = OcclusionVSM(p, normal);
float lambert = clamp((light_rot * normal).z, 0.0, 1.0);
float intensity = (occlusion*0.8+0.2) * lambert;
gl_FragColor = vec4(vec3(depth), 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment