提交 86cc5819 编写于 作者: B Ben Houston (Clara.io) 提交者: Mr.doob

fix bug in invClipZ unpacking glsl code. (#8600)

上级 c9392974
......@@ -35,7 +35,7 @@
padding: 5px;
display: inline-block;
}
#error {
margin: auto;
margin-top: 40px;
......@@ -45,7 +45,7 @@
background: #CE0808;
}
</style>
<script id="post-vert" type="x-shader/x-vertex">
varying vec2 vUv;
......@@ -56,24 +56,20 @@
</script>
<script id="post-frag" type="x-shader/x-fragment">
#include <packing>
varying vec2 vUv;
uniform sampler2D tDiffuse;
uniform sampler2D tDepth;
uniform float cameraNear;
uniform float cameraFar;
float readDepth (sampler2D depthSampler, vec2 coord) {
float cameraFarPlusNear = cameraFar + cameraNear;
float cameraFarMinusNear = cameraFar - cameraNear;
float cameraCoef = 2.0 * cameraNear;
return cameraCoef / (cameraFarPlusNear - texture2D(depthSampler, coord).x * cameraFarMinusNear);
float fragCoordZ = texture2D(depthSampler, coord).x;
float viewZ = invClipZToViewZ( fragCoordZ, cameraNear, cameraFar );
return viewZToLinearClipZ( viewZ, cameraNear, cameraFar );
}
// float depthTexel = texture2D(tDepth, vUv).x;
// float depth = invClipZToViewZ(depthTexel, cameraNear, cameraFar);
// float linearClipZ = viewZToLinearClipZ(depth, cameraNear, cameraFar);
void main() {
vec3 diffuse = texture2D(tDiffuse, vUv).rgb;
float depth = readDepth(tDepth, vUv);
......
......@@ -32,5 +32,5 @@ float viewZToInvClipZ( const in float viewZ, const in float near, const in float
return (( near + viewZ ) * far ) / (( far - near ) * viewZ );
}
float invClipZToViewZ( const in float invClipZ, const in float near, const in float far ) {
return ( near * far ) / ( ( near - far ) * invClipZ - far );
return ( near * far ) / ( ( far - near ) * invClipZ - far );
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册