mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-29 02:55:36 -05:00
143 lines
2.6 KiB
Text
143 lines
2.6 KiB
Text
struct v2f {
|
|
vec4 pos;
|
|
vec2 uv;
|
|
};
|
|
uniform vec4 _ZBufferParams;
|
|
uniform sampler2D _CameraNormalsTexture;
|
|
uniform sampler2D _CameraDepthTexture;
|
|
float Linear01Depth (
|
|
in float z
|
|
)
|
|
{
|
|
return (1.0 / ((_ZBufferParams.x * z) + _ZBufferParams.y));
|
|
}
|
|
|
|
vec2 EncodeViewNormalStereo (
|
|
in vec3 n
|
|
)
|
|
{
|
|
vec2 enc;
|
|
float kScale;
|
|
float tmpvar_1;
|
|
tmpvar_1 = 1.7777;
|
|
kScale = tmpvar_1;
|
|
vec2 tmpvar_2;
|
|
tmpvar_2 = (n.xy / (n.z + 1.0));
|
|
enc = tmpvar_2;
|
|
vec2 tmpvar_3;
|
|
tmpvar_3 = (enc / kScale);
|
|
enc = tmpvar_3;
|
|
vec2 tmpvar_4;
|
|
tmpvar_4 = ((enc * 0.5) + 0.5);
|
|
enc = tmpvar_4;
|
|
return enc;
|
|
}
|
|
|
|
vec2 EncodeFloatRG (
|
|
in float v
|
|
)
|
|
{
|
|
vec2 enc;
|
|
float kEncodeBit;
|
|
vec2 kEncodeMul;
|
|
vec2 tmpvar_1;
|
|
tmpvar_1 = vec2(1.0, 255.0);
|
|
kEncodeMul = tmpvar_1;
|
|
float tmpvar_2;
|
|
tmpvar_2 = 0.00392157;
|
|
kEncodeBit = tmpvar_2;
|
|
vec2 tmpvar_3;
|
|
tmpvar_3 = (kEncodeMul * v);
|
|
enc = tmpvar_3;
|
|
vec2 tmpvar_4;
|
|
tmpvar_4 = fract (enc);
|
|
vec2 tmpvar_5;
|
|
tmpvar_5 = tmpvar_4;
|
|
enc = tmpvar_5;
|
|
float tmpvar_6;
|
|
tmpvar_6 = (enc.x - (enc.y * kEncodeBit));
|
|
enc.x = tmpvar_6;
|
|
return enc;
|
|
}
|
|
|
|
vec4 EncodeDepthNormal (
|
|
in float depth,
|
|
in vec3 normal
|
|
)
|
|
{
|
|
vec4 enc;
|
|
vec2 tmpvar_1;
|
|
tmpvar_1 = EncodeViewNormalStereo (normal);
|
|
vec2 tmpvar_2;
|
|
tmpvar_2 = tmpvar_1;
|
|
enc.xy = tmpvar_2.xy.xy;
|
|
vec2 tmpvar_3;
|
|
tmpvar_3 = EncodeFloatRG (depth);
|
|
vec2 tmpvar_4;
|
|
tmpvar_4 = tmpvar_3;
|
|
enc.zw = tmpvar_4.xxxy.zw;
|
|
return enc;
|
|
}
|
|
|
|
vec4 frag (
|
|
in v2f i
|
|
)
|
|
{
|
|
vec4 n;
|
|
float d;
|
|
vec4 tmpvar_1;
|
|
tmpvar_1 = texture2D (_CameraDepthTexture, i.uv);
|
|
float tmpvar_2;
|
|
tmpvar_2 = tmpvar_1.x;
|
|
d = tmpvar_2;
|
|
vec4 tmpvar_3;
|
|
tmpvar_3 = texture2D (_CameraNormalsTexture, i.uv);
|
|
vec4 tmpvar_4;
|
|
tmpvar_4 = tmpvar_3;
|
|
n = tmpvar_4;
|
|
float tmpvar_5;
|
|
tmpvar_5 = Linear01Depth (d);
|
|
float tmpvar_6;
|
|
tmpvar_6 = tmpvar_5;
|
|
d = tmpvar_6;
|
|
vec3 tmpvar_7;
|
|
tmpvar_7 = ((n.xyz * 2.0) - 1.0);
|
|
n.xyz = tmpvar_7.xyz.xyz;
|
|
float tmpvar_8;
|
|
tmpvar_8 = -(n.z);
|
|
n.z = vec3(tmpvar_8).z;
|
|
vec4 tmpvar_9;
|
|
if ((d < 0.999985)) {
|
|
vec4 tmpvar_10;
|
|
tmpvar_10 = EncodeDepthNormal (d, n.xyz);
|
|
tmpvar_9 = tmpvar_10;
|
|
} else {
|
|
tmpvar_9 = vec4(0.5, 0.5, 1.0, 1.0);
|
|
};
|
|
return tmpvar_9;
|
|
}
|
|
|
|
void main ()
|
|
{
|
|
v2f xlt_i;
|
|
vec4 xl_retval;
|
|
vec4 tmpvar_1;
|
|
tmpvar_1 = vec4(0.0, 0.0, 0.0, 0.0);
|
|
xlt_i.pos = tmpvar_1;
|
|
vec2 tmpvar_2;
|
|
tmpvar_2 = gl_TexCoord[0].xy;
|
|
vec2 tmpvar_3;
|
|
tmpvar_3 = tmpvar_2;
|
|
xlt_i.uv = tmpvar_3;
|
|
vec4 tmpvar_4;
|
|
tmpvar_4 = frag (xlt_i);
|
|
vec4 tmpvar_5;
|
|
tmpvar_5 = tmpvar_4;
|
|
xl_retval = tmpvar_5;
|
|
vec4 tmpvar_6;
|
|
tmpvar_6 = xl_retval.xyzw;
|
|
vec4 tmpvar_7;
|
|
tmpvar_7 = tmpvar_6;
|
|
gl_FragData[0] = tmpvar_7;
|
|
}
|
|
|