mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-12-13 01:31:39 -05:00
310 lines
7.8 KiB
Text
310 lines
7.8 KiB
Text
|
struct v2f_ao {
|
||
|
vec4 pos;
|
||
|
vec2 uv;
|
||
|
vec2 uvr;
|
||
|
};
|
||
|
uniform vec4 _ProjectionParams;
|
||
|
uniform vec2 _NoiseScale;
|
||
|
uniform vec4 _CameraDepthNormalsTexture_ST;
|
||
|
uniform sampler2D _CameraDepthNormalsTexture;
|
||
|
uniform sampler2D _RandomTexture;
|
||
|
uniform vec4 _Params;
|
||
|
varying vec2 xlv_TEXCOORD0;
|
||
|
varying vec2 xlv_TEXCOORD1;
|
||
|
float xll_saturate_f (
|
||
|
in float x_1
|
||
|
)
|
||
|
{
|
||
|
float tmpvar_2;
|
||
|
tmpvar_2 = clamp (x_1, 0.0, 1.0);
|
||
|
return tmpvar_2;
|
||
|
}
|
||
|
|
||
|
float DecodeFloatRG (
|
||
|
in vec2 enc_3
|
||
|
)
|
||
|
{
|
||
|
vec2 kDecodeDot_4;
|
||
|
vec2 tmpvar_5;
|
||
|
tmpvar_5 = vec2(1.0, 0.00392157);
|
||
|
kDecodeDot_4 = tmpvar_5;
|
||
|
float tmpvar_6;
|
||
|
tmpvar_6 = dot (enc_3, kDecodeDot_4);
|
||
|
return tmpvar_6;
|
||
|
}
|
||
|
|
||
|
vec3 DecodeViewNormalStereo (
|
||
|
in vec4 enc4_7
|
||
|
)
|
||
|
{
|
||
|
vec3 n_8;
|
||
|
float g_9;
|
||
|
vec3 nn_10;
|
||
|
float kScale_11;
|
||
|
float tmpvar_12;
|
||
|
tmpvar_12 = 1.7777;
|
||
|
kScale_11 = tmpvar_12;
|
||
|
vec3 tmpvar_13;
|
||
|
tmpvar_13.z = 0.0;
|
||
|
tmpvar_13.x = (2.0 * kScale_11);
|
||
|
tmpvar_13.y = (2.0 * kScale_11);
|
||
|
vec3 tmpvar_14;
|
||
|
tmpvar_14.z = 1.0;
|
||
|
tmpvar_14.x = -(kScale_11);
|
||
|
tmpvar_14.y = -(kScale_11);
|
||
|
vec3 tmpvar_15;
|
||
|
tmpvar_15 = ((enc4_7.xyz * tmpvar_13) + tmpvar_14);
|
||
|
nn_10 = tmpvar_15;
|
||
|
float tmpvar_16;
|
||
|
tmpvar_16 = dot (nn_10.xyz, nn_10.xyz);
|
||
|
float tmpvar_17;
|
||
|
tmpvar_17 = (2.0 / tmpvar_16);
|
||
|
g_9 = tmpvar_17;
|
||
|
vec2 tmpvar_18;
|
||
|
tmpvar_18 = (g_9 * nn_10.xy);
|
||
|
n_8.xy = tmpvar_18.xy.xy;
|
||
|
float tmpvar_19;
|
||
|
tmpvar_19 = (g_9 - 1.0);
|
||
|
n_8.z = vec3(tmpvar_19).z;
|
||
|
return n_8;
|
||
|
}
|
||
|
|
||
|
void DecodeDepthNormal (
|
||
|
in vec4 enc_20,
|
||
|
out float depth_21,
|
||
|
out vec3 normal_22
|
||
|
)
|
||
|
{
|
||
|
float tmpvar_23;
|
||
|
tmpvar_23 = DecodeFloatRG (enc_20.zw);
|
||
|
float tmpvar_24;
|
||
|
tmpvar_24 = tmpvar_23;
|
||
|
depth_21 = tmpvar_24;
|
||
|
vec3 tmpvar_25;
|
||
|
tmpvar_25 = DecodeViewNormalStereo (enc_20);
|
||
|
vec3 tmpvar_26;
|
||
|
tmpvar_26 = tmpvar_25;
|
||
|
normal_22 = tmpvar_26;
|
||
|
}
|
||
|
|
||
|
float frag_ao (
|
||
|
in v2f_ao i_27,
|
||
|
in int sampleCount_28,
|
||
|
in vec3 samples_29[24]
|
||
|
)
|
||
|
{
|
||
|
int s_30;
|
||
|
float occ_31;
|
||
|
float scale_32;
|
||
|
float depth_33;
|
||
|
vec3 viewNorm_34;
|
||
|
vec4 depthnormal_35;
|
||
|
vec3 randN_36;
|
||
|
vec4 tmpvar_37;
|
||
|
tmpvar_37 = texture2D (_RandomTexture, i_27.uvr);
|
||
|
vec3 tmpvar_38;
|
||
|
tmpvar_38 = ((tmpvar_37.xyz * 2.0) - 1.0);
|
||
|
randN_36 = tmpvar_38;
|
||
|
vec4 tmpvar_39;
|
||
|
tmpvar_39 = texture2D (_CameraDepthNormalsTexture, i_27.uv);
|
||
|
vec4 tmpvar_40;
|
||
|
tmpvar_40 = tmpvar_39;
|
||
|
depthnormal_35 = tmpvar_40;
|
||
|
DecodeDepthNormal (depthnormal_35, depth_33, viewNorm_34);
|
||
|
float tmpvar_41;
|
||
|
tmpvar_41 = (depth_33 * _ProjectionParams.z);
|
||
|
depth_33 = tmpvar_41;
|
||
|
float tmpvar_42;
|
||
|
tmpvar_42 = (_Params.x / depth_33);
|
||
|
scale_32 = tmpvar_42;
|
||
|
float tmpvar_43;
|
||
|
tmpvar_43 = 0.0;
|
||
|
occ_31 = tmpvar_43;
|
||
|
int tmpvar_44;
|
||
|
tmpvar_44 = 0;
|
||
|
s_30 = tmpvar_44;
|
||
|
while (true) {
|
||
|
float zd_45;
|
||
|
vec3 sampleN_46;
|
||
|
float sampleD_47;
|
||
|
vec4 sampleND_48;
|
||
|
float sD_49;
|
||
|
vec2 offset_50;
|
||
|
float flip_51;
|
||
|
vec3 randomDir_52;
|
||
|
if (!((s_30 < sampleCount_28))) {
|
||
|
break;
|
||
|
};
|
||
|
vec3 tmpvar_53;
|
||
|
tmpvar_53 = reflect (samples_29[s_30], randN_36);
|
||
|
vec3 tmpvar_54;
|
||
|
tmpvar_54 = tmpvar_53;
|
||
|
randomDir_52 = tmpvar_54;
|
||
|
float tmpvar_55;
|
||
|
tmpvar_55 = dot (viewNorm_34, randomDir_52);
|
||
|
float tmpvar_56;
|
||
|
if ((tmpvar_55 < 0.0)) {
|
||
|
tmpvar_56 = 1.0;
|
||
|
} else {
|
||
|
tmpvar_56 = -(1.0);
|
||
|
};
|
||
|
float tmpvar_57;
|
||
|
tmpvar_57 = tmpvar_56;
|
||
|
flip_51 = tmpvar_57;
|
||
|
vec3 tmpvar_58;
|
||
|
tmpvar_58 = (randomDir_52 * -(flip_51));
|
||
|
randomDir_52 = tmpvar_58;
|
||
|
vec3 tmpvar_59;
|
||
|
tmpvar_59 = (randomDir_52 + (viewNorm_34 * 0.3));
|
||
|
randomDir_52 = tmpvar_59;
|
||
|
vec2 tmpvar_60;
|
||
|
tmpvar_60 = (randomDir_52.xy * scale_32);
|
||
|
offset_50 = tmpvar_60;
|
||
|
float tmpvar_61;
|
||
|
tmpvar_61 = (depth_33 - (randomDir_52.z * _Params.x));
|
||
|
sD_49 = tmpvar_61;
|
||
|
vec4 tmpvar_62;
|
||
|
tmpvar_62 = texture2D (_CameraDepthNormalsTexture, (i_27.uv + offset_50));
|
||
|
vec4 tmpvar_63;
|
||
|
tmpvar_63 = tmpvar_62;
|
||
|
sampleND_48 = tmpvar_63;
|
||
|
DecodeDepthNormal (sampleND_48, sampleD_47, sampleN_46);
|
||
|
float tmpvar_64;
|
||
|
tmpvar_64 = (sampleD_47 * _ProjectionParams.z);
|
||
|
sampleD_47 = tmpvar_64;
|
||
|
float tmpvar_65;
|
||
|
tmpvar_65 = xll_saturate_f ((sD_49 - sampleD_47));
|
||
|
float tmpvar_66;
|
||
|
tmpvar_66 = tmpvar_65;
|
||
|
zd_45 = tmpvar_66;
|
||
|
if ((zd_45 > _Params.y)) {
|
||
|
float tmpvar_67;
|
||
|
tmpvar_67 = pow ((1.0 - zd_45), _Params.z);
|
||
|
float tmpvar_68;
|
||
|
tmpvar_68 = (occ_31 + tmpvar_67);
|
||
|
occ_31 = tmpvar_68;
|
||
|
};
|
||
|
int tmpvar_69;
|
||
|
tmpvar_69 = (s_30 + 1);
|
||
|
s_30 = tmpvar_69;
|
||
|
};
|
||
|
float tmpvar_70;
|
||
|
tmpvar_70 = (occ_31 / float(sampleCount_28));
|
||
|
occ_31 = tmpvar_70;
|
||
|
return (1.0 - occ_31);
|
||
|
}
|
||
|
|
||
|
vec4 frag (
|
||
|
in v2f_ao i_71
|
||
|
)
|
||
|
{
|
||
|
vec3 RAND_SAMPLES_72[24];
|
||
|
vec3 tmpvar_73;
|
||
|
tmpvar_73 = vec3(0.0130572, 0.587232, -0.119337);
|
||
|
RAND_SAMPLES_72[0] = tmpvar_73;
|
||
|
vec3 tmpvar_74;
|
||
|
tmpvar_74 = vec3(0.323078, 0.0220727, -0.418873);
|
||
|
RAND_SAMPLES_72[1] = tmpvar_74;
|
||
|
vec3 tmpvar_75;
|
||
|
tmpvar_75 = vec3(-0.310725, -0.191367, 0.0561369);
|
||
|
RAND_SAMPLES_72[2] = tmpvar_75;
|
||
|
vec3 tmpvar_76;
|
||
|
tmpvar_76 = vec3(-0.479646, 0.0939877, -0.580265);
|
||
|
RAND_SAMPLES_72[3] = tmpvar_76;
|
||
|
vec3 tmpvar_77;
|
||
|
tmpvar_77 = vec3(0.139999, -0.33577, 0.559679);
|
||
|
RAND_SAMPLES_72[4] = tmpvar_77;
|
||
|
vec3 tmpvar_78;
|
||
|
tmpvar_78 = vec3(-0.248458, 0.255532, 0.348944);
|
||
|
RAND_SAMPLES_72[5] = tmpvar_78;
|
||
|
vec3 tmpvar_79;
|
||
|
tmpvar_79 = vec3(0.18719, -0.702764, -0.231748);
|
||
|
RAND_SAMPLES_72[6] = tmpvar_79;
|
||
|
vec3 tmpvar_80;
|
||
|
tmpvar_80 = vec3(0.884915, 0.284208, 0.368524);
|
||
|
RAND_SAMPLES_72[7] = tmpvar_80;
|
||
|
vec3 tmpvar_81;
|
||
|
tmpvar_81 = vec3(0.0130572, 0.587232, -0.119337);
|
||
|
RAND_SAMPLES_72[8] = tmpvar_81;
|
||
|
vec3 tmpvar_82;
|
||
|
tmpvar_82 = vec3(0.323078, 0.0220727, -0.418873);
|
||
|
RAND_SAMPLES_72[9] = tmpvar_82;
|
||
|
vec3 tmpvar_83;
|
||
|
tmpvar_83 = vec3(-0.310725, -0.191367, 0.0561369);
|
||
|
RAND_SAMPLES_72[10] = tmpvar_83;
|
||
|
vec3 tmpvar_84;
|
||
|
tmpvar_84 = vec3(-0.479646, 0.0939877, -0.580265);
|
||
|
RAND_SAMPLES_72[11] = tmpvar_84;
|
||
|
vec3 tmpvar_85;
|
||
|
tmpvar_85 = vec3(0.139999, -0.33577, 0.559679);
|
||
|
RAND_SAMPLES_72[12] = tmpvar_85;
|
||
|
vec3 tmpvar_86;
|
||
|
tmpvar_86 = vec3(-0.248458, 0.255532, 0.348944);
|
||
|
RAND_SAMPLES_72[13] = tmpvar_86;
|
||
|
vec3 tmpvar_87;
|
||
|
tmpvar_87 = vec3(0.18719, -0.702764, -0.231748);
|
||
|
RAND_SAMPLES_72[14] = tmpvar_87;
|
||
|
vec3 tmpvar_88;
|
||
|
tmpvar_88 = vec3(0.884915, 0.284208, 0.368524);
|
||
|
RAND_SAMPLES_72[15] = tmpvar_88;
|
||
|
vec3 tmpvar_89;
|
||
|
tmpvar_89 = vec3(0.0130572, 0.587232, -0.119337);
|
||
|
RAND_SAMPLES_72[16] = tmpvar_89;
|
||
|
vec3 tmpvar_90;
|
||
|
tmpvar_90 = vec3(0.323078, 0.0220727, -0.418873);
|
||
|
RAND_SAMPLES_72[17] = tmpvar_90;
|
||
|
vec3 tmpvar_91;
|
||
|
tmpvar_91 = vec3(-0.310725, -0.191367, 0.0561369);
|
||
|
RAND_SAMPLES_72[18] = tmpvar_91;
|
||
|
vec3 tmpvar_92;
|
||
|
tmpvar_92 = vec3(-0.479646, 0.0939877, -0.580265);
|
||
|
RAND_SAMPLES_72[19] = tmpvar_92;
|
||
|
vec3 tmpvar_93;
|
||
|
tmpvar_93 = vec3(0.139999, -0.33577, 0.559679);
|
||
|
RAND_SAMPLES_72[20] = tmpvar_93;
|
||
|
vec3 tmpvar_94;
|
||
|
tmpvar_94 = vec3(-0.248458, 0.255532, 0.348944);
|
||
|
RAND_SAMPLES_72[21] = tmpvar_94;
|
||
|
vec3 tmpvar_95;
|
||
|
tmpvar_95 = vec3(0.18719, -0.702764, -0.231748);
|
||
|
RAND_SAMPLES_72[22] = tmpvar_95;
|
||
|
vec3 tmpvar_96;
|
||
|
tmpvar_96 = vec3(0.884915, 0.284208, 0.368524);
|
||
|
RAND_SAMPLES_72[23] = tmpvar_96;
|
||
|
float tmpvar_97;
|
||
|
tmpvar_97 = frag_ao (i_71, 24, RAND_SAMPLES_72);
|
||
|
vec4 tmpvar_98;
|
||
|
tmpvar_98 = vec4(tmpvar_97);
|
||
|
return tmpvar_98;
|
||
|
}
|
||
|
|
||
|
void main ()
|
||
|
{
|
||
|
v2f_ao xlt_i_99;
|
||
|
vec4 xl_retval_100;
|
||
|
vec4 tmpvar_101;
|
||
|
tmpvar_101 = vec4(0.0, 0.0, 0.0, 0.0);
|
||
|
xlt_i_99.pos = tmpvar_101;
|
||
|
vec2 tmpvar_102;
|
||
|
tmpvar_102 = xlv_TEXCOORD0.xy;
|
||
|
vec2 tmpvar_103;
|
||
|
tmpvar_103 = tmpvar_102;
|
||
|
xlt_i_99.uv = tmpvar_103;
|
||
|
vec2 tmpvar_104;
|
||
|
tmpvar_104 = xlv_TEXCOORD1.xy;
|
||
|
vec2 tmpvar_105;
|
||
|
tmpvar_105 = tmpvar_104;
|
||
|
xlt_i_99.uvr = tmpvar_105;
|
||
|
vec4 tmpvar_106;
|
||
|
tmpvar_106 = frag (xlt_i_99);
|
||
|
vec4 tmpvar_107;
|
||
|
tmpvar_107 = tmpvar_106;
|
||
|
xl_retval_100 = tmpvar_107;
|
||
|
vec4 tmpvar_108;
|
||
|
tmpvar_108 = xl_retval_100.xyzw;
|
||
|
vec4 tmpvar_109;
|
||
|
tmpvar_109 = tmpvar_108;
|
||
|
gl_FragData[0] = tmpvar_109;
|
||
|
}
|
||
|
|