mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-25 17:18:12 -05:00
242 lines
6.9 KiB
Text
242 lines
6.9 KiB
Text
#version 300 es
|
|
struct v2f_ao {
|
|
highp vec4 pos;
|
|
highp vec2 uv;
|
|
highp vec2 uvr;
|
|
};
|
|
layout(location=0) out mediump vec4 _glesFragData[4];
|
|
uniform highp vec4 _ProjectionParams;
|
|
uniform highp vec2 _NoiseScale;
|
|
uniform highp vec4 _CameraDepthNormalsTexture_ST;
|
|
uniform sampler2D _CameraDepthNormalsTexture;
|
|
uniform sampler2D _RandomTexture;
|
|
uniform highp vec4 _Params;
|
|
in highp vec2 xlv_TEXCOORD0;
|
|
in highp vec2 xlv_TEXCOORD1;
|
|
mediump float xll_saturate_f (
|
|
in mediump float x_1
|
|
)
|
|
{
|
|
mediump float tmpvar_2;
|
|
tmpvar_2 = clamp (x_1, 0.0, 1.0);
|
|
return tmpvar_2;
|
|
}
|
|
|
|
float DecodeFloatRG (
|
|
in highp vec2 enc_3
|
|
)
|
|
{
|
|
highp vec2 kDecodeDot_4;
|
|
mediump vec2 tmpvar_5;
|
|
tmpvar_5 = vec2(1.0, 0.00392157);
|
|
kDecodeDot_4 = tmpvar_5;
|
|
highp float tmpvar_6;
|
|
tmpvar_6 = dot (enc_3, kDecodeDot_4);
|
|
return tmpvar_6;
|
|
}
|
|
|
|
vec3 DecodeViewNormalStereo (
|
|
in highp vec4 enc4_7
|
|
)
|
|
{
|
|
highp vec3 n_8;
|
|
highp float g_9;
|
|
highp vec3 nn_10;
|
|
highp float kScale_11;
|
|
mediump float tmpvar_12;
|
|
tmpvar_12 = 1.7777;
|
|
kScale_11 = tmpvar_12;
|
|
highp vec3 tmpvar_13;
|
|
tmpvar_13.z = 0.0;
|
|
tmpvar_13.x = (2.0 * kScale_11);
|
|
tmpvar_13.y = (2.0 * kScale_11);
|
|
highp vec3 tmpvar_14;
|
|
tmpvar_14.z = 1.0;
|
|
tmpvar_14.x = -(kScale_11);
|
|
tmpvar_14.y = -(kScale_11);
|
|
highp vec3 tmpvar_15;
|
|
tmpvar_15 = ((enc4_7.xyz * tmpvar_13) + tmpvar_14);
|
|
nn_10 = tmpvar_15;
|
|
highp float tmpvar_16;
|
|
tmpvar_16 = dot (nn_10.xyz, nn_10.xyz);
|
|
highp float tmpvar_17;
|
|
tmpvar_17 = (2.0 / tmpvar_16);
|
|
g_9 = tmpvar_17;
|
|
highp vec2 tmpvar_18;
|
|
tmpvar_18 = (g_9 * nn_10.xy);
|
|
n_8.xy = tmpvar_18.xy.xy;
|
|
highp float tmpvar_19;
|
|
tmpvar_19 = (g_9 - 1.0);
|
|
n_8.z = vec3(tmpvar_19).z;
|
|
return n_8;
|
|
}
|
|
|
|
void DecodeDepthNormal (
|
|
in highp vec4 enc_20,
|
|
out highp float depth_21,
|
|
out highp vec3 normal_22
|
|
)
|
|
{
|
|
highp float tmpvar_23;
|
|
tmpvar_23 = DecodeFloatRG (enc_20.zw);
|
|
highp float tmpvar_24;
|
|
tmpvar_24 = tmpvar_23;
|
|
depth_21 = tmpvar_24;
|
|
highp vec3 tmpvar_25;
|
|
tmpvar_25 = DecodeViewNormalStereo (enc_20);
|
|
highp vec3 tmpvar_26;
|
|
tmpvar_26 = tmpvar_25;
|
|
normal_22 = tmpvar_26;
|
|
}
|
|
|
|
mediump float frag_ao (
|
|
in v2f_ao i_27,
|
|
in int sampleCount_28,
|
|
in highp vec3 samples_29[8]
|
|
)
|
|
{
|
|
int s_30;
|
|
highp float occ_31;
|
|
highp float scale_32;
|
|
highp float depth_33;
|
|
highp vec3 viewNorm_34;
|
|
highp vec4 depthnormal_35;
|
|
mediump vec3 randN_36;
|
|
lowp vec4 tmpvar_37;
|
|
tmpvar_37 = texture (_RandomTexture, i_27.uvr);
|
|
lowp vec3 tmpvar_38;
|
|
tmpvar_38 = ((tmpvar_37.xyz * 2.0) - 1.0);
|
|
randN_36 = tmpvar_38;
|
|
lowp vec4 tmpvar_39;
|
|
tmpvar_39 = texture (_CameraDepthNormalsTexture, i_27.uv);
|
|
lowp vec4 tmpvar_40;
|
|
tmpvar_40 = tmpvar_39;
|
|
depthnormal_35 = tmpvar_40;
|
|
DecodeDepthNormal (depthnormal_35, depth_33, viewNorm_34);
|
|
highp float tmpvar_41;
|
|
tmpvar_41 = (depth_33 * _ProjectionParams.z);
|
|
depth_33 = tmpvar_41;
|
|
highp float tmpvar_42;
|
|
tmpvar_42 = (_Params.x / depth_33);
|
|
scale_32 = tmpvar_42;
|
|
mediump float tmpvar_43;
|
|
tmpvar_43 = 0.0;
|
|
occ_31 = tmpvar_43;
|
|
int tmpvar_44;
|
|
tmpvar_44 = 0;
|
|
s_30 = tmpvar_44;
|
|
while (true) {
|
|
highp float zd_45;
|
|
highp vec3 sampleN_46;
|
|
highp float sampleD_47;
|
|
highp vec4 sampleND_48;
|
|
highp float sD_49;
|
|
highp vec2 offset_50;
|
|
mediump float flip_51;
|
|
mediump vec3 randomDir_52;
|
|
if (!((s_30 < sampleCount_28))) {
|
|
break;
|
|
};
|
|
highp vec3 tmpvar_53;
|
|
tmpvar_53 = reflect (samples_29[s_30], randN_36);
|
|
highp vec3 tmpvar_54;
|
|
tmpvar_54 = tmpvar_53;
|
|
randomDir_52 = tmpvar_54;
|
|
highp float tmpvar_55;
|
|
tmpvar_55 = dot (viewNorm_34, randomDir_52);
|
|
mediump float tmpvar_56;
|
|
if ((tmpvar_55 < 0.0)) {
|
|
tmpvar_56 = 1.0;
|
|
} else {
|
|
tmpvar_56 = -(1.0);
|
|
};
|
|
mediump float tmpvar_57;
|
|
tmpvar_57 = tmpvar_56;
|
|
flip_51 = tmpvar_57;
|
|
mediump vec3 tmpvar_58;
|
|
tmpvar_58 = (randomDir_52 * -(flip_51));
|
|
randomDir_52 = tmpvar_58;
|
|
highp vec3 tmpvar_59;
|
|
tmpvar_59 = (randomDir_52 + (viewNorm_34 * 0.3));
|
|
randomDir_52 = tmpvar_59;
|
|
highp vec2 tmpvar_60;
|
|
tmpvar_60 = (randomDir_52.xy * scale_32);
|
|
offset_50 = tmpvar_60;
|
|
highp float tmpvar_61;
|
|
tmpvar_61 = (depth_33 - (randomDir_52.z * _Params.x));
|
|
sD_49 = tmpvar_61;
|
|
lowp vec4 tmpvar_62;
|
|
tmpvar_62 = texture (_CameraDepthNormalsTexture, (i_27.uv + offset_50));
|
|
lowp vec4 tmpvar_63;
|
|
tmpvar_63 = tmpvar_62;
|
|
sampleND_48 = tmpvar_63;
|
|
DecodeDepthNormal (sampleND_48, sampleD_47, sampleN_46);
|
|
highp float tmpvar_64;
|
|
tmpvar_64 = (sampleD_47 * _ProjectionParams.z);
|
|
sampleD_47 = tmpvar_64;
|
|
mediump float tmpvar_65;
|
|
tmpvar_65 = xll_saturate_f ((sD_49 - sampleD_47));
|
|
mediump float tmpvar_66;
|
|
tmpvar_66 = tmpvar_65;
|
|
zd_45 = tmpvar_66;
|
|
if ((zd_45 > _Params.y)) {
|
|
highp float tmpvar_67;
|
|
tmpvar_67 = pow ((1.0 - zd_45), _Params.z);
|
|
highp 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;
|
|
};
|
|
highp float tmpvar_70;
|
|
tmpvar_70 = (occ_31 / float(sampleCount_28));
|
|
occ_31 = tmpvar_70;
|
|
return (1.0 - occ_31);
|
|
}
|
|
|
|
mediump vec4 frag (
|
|
in v2f_ao i_71
|
|
)
|
|
{
|
|
highp vec3 RAND_SAMPLES_72[8] = vec3[8](vec3(0.0130572, 0.587232, -0.119337), vec3(0.323078, 0.0220727, -0.418873), vec3(-0.310725, -0.191367, 0.0561369), vec3(-0.479646, 0.0939877, -0.580265), vec3(0.139999, -0.33577, 0.559679), vec3(-0.248458, 0.255532, 0.348944), vec3(0.18719, -0.702764, -0.231748), vec3(0.884915, 0.284208, 0.368524));
|
|
vec3 tmpvar_73[8];
|
|
tmpvar_73 = vec3[8](vec3(0.0130572, 0.587232, -0.119337), vec3(0.323078, 0.0220727, -0.418873), vec3(-0.310725, -0.191367, 0.0561369), vec3(-0.479646, 0.0939877, -0.580265), vec3(0.139999, -0.33577, 0.559679), vec3(-0.248458, 0.255532, 0.348944), vec3(0.18719, -0.702764, -0.231748), vec3(0.884915, 0.284208, 0.368524));
|
|
RAND_SAMPLES_72 = tmpvar_73;
|
|
mediump float tmpvar_74;
|
|
tmpvar_74 = frag_ao (i_71, 8, vec3[8](vec3(0.0130572, 0.587232, -0.119337), vec3(0.323078, 0.0220727, -0.418873), vec3(-0.310725, -0.191367, 0.0561369), vec3(-0.479646, 0.0939877, -0.580265), vec3(0.139999, -0.33577, 0.559679), vec3(-0.248458, 0.255532, 0.348944), vec3(0.18719, -0.702764, -0.231748), vec3(0.884915, 0.284208, 0.368524)));
|
|
mediump vec4 tmpvar_75;
|
|
tmpvar_75 = vec4(tmpvar_74);
|
|
return tmpvar_75;
|
|
}
|
|
|
|
void main ()
|
|
{
|
|
v2f_ao xlt_i_76;
|
|
mediump vec4 xl_retval_77;
|
|
mediump vec4 tmpvar_78;
|
|
tmpvar_78 = vec4(0.0, 0.0, 0.0, 0.0);
|
|
xlt_i_76.pos = tmpvar_78;
|
|
highp vec2 tmpvar_79;
|
|
tmpvar_79 = xlv_TEXCOORD0.xy;
|
|
highp vec2 tmpvar_80;
|
|
tmpvar_80 = tmpvar_79;
|
|
xlt_i_76.uv = tmpvar_80;
|
|
highp vec2 tmpvar_81;
|
|
tmpvar_81 = xlv_TEXCOORD1.xy;
|
|
highp vec2 tmpvar_82;
|
|
tmpvar_82 = tmpvar_81;
|
|
xlt_i_76.uvr = tmpvar_82;
|
|
mediump vec4 tmpvar_83;
|
|
tmpvar_83 = frag (xlt_i_76);
|
|
mediump vec4 tmpvar_84;
|
|
tmpvar_84 = tmpvar_83;
|
|
xl_retval_77 = tmpvar_84;
|
|
mediump vec4 tmpvar_85;
|
|
tmpvar_85 = xl_retval_77.xyzw;
|
|
mediump vec4 tmpvar_86;
|
|
tmpvar_86 = tmpvar_85;
|
|
_glesFragData[0] = tmpvar_86;
|
|
}
|
|
|