float xll_saturate_f( float x) { return clamp( x, 0.0, 1.0); } vec2 xll_saturate_vf2( vec2 x) { return clamp( x, 0.0, 1.0); } vec3 xll_saturate_vf3( vec3 x) { return clamp( x, 0.0, 1.0); } vec4 xll_saturate_vf4( vec4 x) { return clamp( x, 0.0, 1.0); } mat2 xll_saturate_mf2x2(mat2 m) { return mat2( clamp(m[0], 0.0, 1.0), clamp(m[1], 0.0, 1.0)); } mat3 xll_saturate_mf3x3(mat3 m) { return mat3( clamp(m[0], 0.0, 1.0), clamp(m[1], 0.0, 1.0), clamp(m[2], 0.0, 1.0)); } mat4 xll_saturate_mf4x4(mat4 m) { return mat4( clamp(m[0], 0.0, 1.0), clamp(m[1], 0.0, 1.0), clamp(m[2], 0.0, 1.0), clamp(m[3], 0.0, 1.0)); } #line 4 struct v2f_ao { vec4 pos; vec2 uv; vec2 uvr; }; #line 10 uniform sampler2D _CameraDepthNormalsTexture; uniform sampler2D _RandomTexture; uniform vec4 _Params; uniform vec4 _ProjectionParams; #line 15 #line 36 #line 83 #line 25 float DecodeFloatRG( in vec2 enc ) { #line 27 vec2 kDecodeDot = vec2( 1.0, 0.003921569); return dot( enc, kDecodeDot); } #line 15 vec3 DecodeViewNormalStereo( in vec4 enc4 ) { float kScale = 1.7777; vec3 nn = ((enc4.xyz * vec3( (2.0 * kScale), (2.0 * kScale), 0.0)) + vec3( (-kScale), (-kScale), 1.0)); #line 19 float g = (2.0 / dot( nn.xyz, nn.xyz)); vec3 n; n.xy = (g * nn.xy); n.z = (g - 1.0); #line 23 return n; } #line 30 void DecodeDepthNormal( in vec4 enc, out float depth, out vec3 normal ) { #line 32 depth = DecodeFloatRG( enc.zw); normal = DecodeViewNormalStereo( enc); } #line 36 float frag_ao( in v2f_ao i, in int sampleCount, in vec3 samples[8] ) { vec3 randN = ((texture2D( _RandomTexture, i.uvr).xyz * 2.0) - 1.0); #line 42 vec4 depthnormal = texture2D( _CameraDepthNormalsTexture, i.uv); vec3 viewNorm; float depth; DecodeDepthNormal( depthnormal, depth, viewNorm); #line 46 depth *= _ProjectionParams.z; float scale = (_Params.x / depth); #line 50 float occ = 0.0; int s = 0; for ( ; (s < sampleCount); (++s)) { #line 54 vec3 randomDir = reflect( samples[s], randN); float flip = (( (dot( viewNorm, randomDir) < 0.0) ) ? ( 1.0 ) : ( -1.0 )); #line 58 randomDir *= (-flip); randomDir += (viewNorm * 0.3); #line 62 vec2 offset = (randomDir.xy * scale); float sD = (depth - (randomDir.z * _Params.x)); #line 66 vec4 sampleND = texture2D( _CameraDepthNormalsTexture, (i.uv + offset)); float sampleD; vec3 sampleN; DecodeDepthNormal( sampleND, sampleD, sampleN); #line 70 sampleD *= _ProjectionParams.z; float zd = xll_saturate_f((sD - sampleD)); if ((zd > _Params.y)){ #line 74 occ += pow( (1.0 - zd), _Params.z); } } #line 79 occ /= float(sampleCount); return (1.0 - occ); } #line 83 vec4 xlat_main( in v2f_ao i ) { vec3 RAND_SAMPLES[8]; RAND_SAMPLES[0] = vec3( 0.01305719, 0.5872321, -0.119337); RAND_SAMPLES[1] = vec3( 0.3230782, 0.02207272, -0.4188725); RAND_SAMPLES[2] = vec3( -0.310725, -0.191367, 0.05613686); RAND_SAMPLES[3] = vec3( -0.4796457, 0.09398766, -0.5802653); RAND_SAMPLES[4] = vec3( 0.1399992, -0.3357702, 0.5596789); RAND_SAMPLES[5] = vec3( -0.2484578, 0.2555322, 0.3489439); RAND_SAMPLES[6] = vec3( 0.1871898, -0.702764, -0.2317479); RAND_SAMPLES[7] = vec3( 0.8849149, 0.2842076, 0.368524); #line 95 return vec4( frag_ao( i, 8, RAND_SAMPLES)); } varying vec2 xlv_TEXCOORD0; varying vec2 xlv_TEXCOORD1; void main() { vec4 xl_retval; v2f_ao xlt_i; xlt_i.pos = vec4(0.0); xlt_i.uv = vec2(xlv_TEXCOORD0); xlt_i.uvr = vec2(xlv_TEXCOORD1); xl_retval = xlat_main( xlt_i); gl_FragData[0] = vec4(xl_retval); } // uniforms: // _CameraDepthNormalsTexture: type 25 arrsize 0 // _Params: type 12 arrsize 0 // _ProjectionParams: type 12 arrsize 0 // _RandomTexture: type 25 arrsize 0