bgfx/3rdparty/glsl-optimizer/tests/fragment/zun-Hidden_Internal-CombineDepthNormals-in.txt

74 lines
1.8 KiB
Text
Raw Normal View History

2012-04-03 23:30:07 -04:00
struct v2f_vertex_lit {
vec2 uv;
vec4 diff;
vec4 spec;
};
struct v2f_img {
vec4 pos;
vec2 uv;
};
struct appdata_img {
vec4 vertex;
vec2 texcoord;
};
struct v2f {
vec4 pos;
vec2 uv;
};
struct appdata {
vec4 vertex;
vec2 texcoord;
};
uniform sampler2D _CameraDepthTexture;
uniform sampler2D _CameraNormalsTexture;
uniform vec4 _ZBufferParams;
float Linear01Depth( in float z );
vec2 EncodeViewNormalStereo( in vec3 n );
vec2 EncodeFloatRG( in float v );
vec4 EncodeDepthNormal( in float depth, in vec3 normal );
vec4 frag( in v2f i );
float Linear01Depth( in float z ) {
return (1.00000 / ((_ZBufferParams.x * z) + _ZBufferParams.y ));
}
vec2 EncodeViewNormalStereo( in vec3 n ) {
float kScale = 1.77770;
vec2 enc;
enc = (n.xy / (n.z + 1.00000));
enc /= kScale;
enc = ((enc * 0.500000) + 0.500000);
return enc;
}
vec2 EncodeFloatRG( in float v ) {
vec2 kEncodeMul = vec2( 1.00000, 255.000);
float kEncodeBit = 0.00392157;
vec2 enc;
enc = (kEncodeMul * v);
enc = fract( enc );
enc.x -= (enc.y * kEncodeBit);
return enc;
}
vec4 EncodeDepthNormal( in float depth, in vec3 normal ) {
vec4 enc;
enc.xy = EncodeViewNormalStereo( normal);
enc.zw = EncodeFloatRG( depth);
return enc;
}
vec4 frag( in v2f i ) {
float d;
vec4 n;
d = texture2D( _CameraDepthTexture, i.uv).x ;
n = texture2D( _CameraNormalsTexture, i.uv);
d = Linear01Depth( d);
n.xyz = ((n.xyz * 2.00000) - 1.00000);
n.z = ( -n.z );
return ( (d < 0.999985) ) ? ( EncodeDepthNormal( d, n.xyz ) ) : ( vec4( 0.500000, 0.500000, 1.00000, 1.00000) );
}
void main() {
vec4 xl_retval;
v2f xlt_i;
xlt_i.pos = vec4(0.0);
xlt_i.uv = vec2( gl_TexCoord[0]);
xl_retval = frag( xlt_i);
gl_FragData[0] = vec4( xl_retval);
}