mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 02:03:57 +02:00
Downsampling shader pass
This commit is contained in:
parent
5a0ce81516
commit
86d9ee56d2
1 changed files with 70 additions and 0 deletions
|
@ -0,0 +1,70 @@
|
|||
<@include gpu/Config.slh@>
|
||||
<$VERSION_HEADER$>
|
||||
// Generated on <$_SCRIBE_DATE$>
|
||||
//
|
||||
// Created by Sam Gateau on 6/3/16.
|
||||
// Copyright 2016 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
uniform sampler2D linearDepthMap;
|
||||
uniform sampler2D normalMap;
|
||||
|
||||
|
||||
vec2 signNotZero(vec2 v) {
|
||||
return vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);
|
||||
}
|
||||
|
||||
vec3 oct_to_float32x3(in vec2 e) {
|
||||
vec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y));
|
||||
if (v.z < 0) {
|
||||
v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);
|
||||
}
|
||||
return normalize(v);
|
||||
}
|
||||
|
||||
vec2 unorm8x3_to_snorm12x2(vec3 u) {
|
||||
u *= 255.0;
|
||||
u.y *= (1.0 / 16.0);
|
||||
vec2 s = vec2( u.x * 16.0 + floor(u.y),
|
||||
fract(u.y) * (16.0 * 256.0) + u.z);
|
||||
return clamp(s * (1.0 / 2047.0) - 1.0, vec2(-1.0), vec2(1.0));
|
||||
}
|
||||
vec3 unpackNormal(in vec3 p) {
|
||||
return oct_to_float32x3(unorm8x3_to_snorm12x2(p));
|
||||
}
|
||||
|
||||
in vec2 varTexCoord0;
|
||||
|
||||
out vec4 outLinearDepth;
|
||||
out vec4 outNormal;
|
||||
|
||||
void main(void) {
|
||||
float Zeye = texture(linearDepthMap, varTexCoord0).x;
|
||||
|
||||
ivec2 texpos = ivec2(gl_FragCoord.xy) * 2;
|
||||
|
||||
vec3 rawNormals[4];
|
||||
rawNormals[0] = texelFetch(normalMap, texpos, 0).xyz;
|
||||
rawNormals[1] = texelFetch(normalMap, texpos + ivec2(0, 1), 0).xyz;
|
||||
rawNormals[2] = texelFetch(normalMap, texpos + ivec2(1, 0), 0).xyz;
|
||||
rawNormals[3] = texelFetch(normalMap, texpos + ivec2(1, 1), 0).xyz;
|
||||
|
||||
vec3 normal = vec3(0.0);
|
||||
|
||||
normal += unpackNormal( rawNormals[0] );
|
||||
normal += unpackNormal( rawNormals[1] );
|
||||
normal += unpackNormal( rawNormals[2] );
|
||||
normal += unpackNormal( rawNormals[3] );
|
||||
|
||||
normal = normalize(normal);
|
||||
|
||||
outLinearDepth = vec4(Zeye, 0.0, 0.0, 0.0);
|
||||
outNormal = vec4((normal + vec3(1.0)) * 0.5, 0.0);
|
||||
}
|
||||
|
Loading…
Reference in a new issue