in roboschool/cpp-household/render-ssao.cpp [164:230]
void ContextViewport::_hbao_prepare(const float* proj_matrix)
{
#if 0
float p1, p2, p3, testy;
testy = 1.0;
FILE* f = fopen("ssao.params", "rt");
if (f) {
int r = fscanf(f, "%f %f %f %f", &p1, &p2, &p3, &testy);
fclose(f);
if (r==4) {
ssao_radius = p1;
ssao_intensity = p2;
ssao_bias = p3;
}
}
cx->useful->hbaoUbo._pad0[0] = testy;
#endif
const float* P = proj_matrix;
cx->useful->hbaoUbo.projOrtho = ortho;
float projScale;
if (ortho) {
cx->useful->hbaoUbo.projInfo[0] = 20.0f / ( P[4*0+0]); // ((x) * R - L)
cx->useful->hbaoUbo.projInfo[1] = 20.0f / ( P[4*1+1]); // ((y) * T - B)
cx->useful->hbaoUbo.projInfo[2] = -( 1.0f + P[4*3+0]) / P[4*0+0]; // L
cx->useful->hbaoUbo.projInfo[3] = -( 1.0f - P[4*3+1]) / P[4*1+1]; // B
projScale = float(side) / cx->useful->hbaoUbo.projInfo[1];
} else {
cx->useful->hbaoUbo.projInfo[0] = 2.0f / (P[4*0+0]); // (x) * (R - L)/N
cx->useful->hbaoUbo.projInfo[1] = 2.0f / (P[4*1+1]); // (y) * (T - B)/N
cx->useful->hbaoUbo.projInfo[2] = -( 1.0f - P[4*2+0]) / P[4*0+0]; // L/N
cx->useful->hbaoUbo.projInfo[3] = -( 1.0f + P[4*2+1]) / P[4*1+1]; // B/N
projScale = float(side) / (tanf(hfov * nv_to_rad * 0.5f) * 2.0f);
}
// radius
float R = ssao_radius;
cx->useful->hbaoUbo.R2 = R * R;
cx->useful->hbaoUbo.NegInvR2 = -1.0f / cx->useful->hbaoUbo.R2;
cx->useful->hbaoUbo.RadiusToScreen = R * 0.5f * projScale;
// ao
cx->useful->hbaoUbo.PowExponent = std::max(ssao_intensity, 0.0f);
cx->useful->hbaoUbo.NDotVBias = std::min(std::max(0.0f, ssao_bias), 1.0f);
cx->useful->hbaoUbo.AOMultiplier = 1.0f / (1.0f - cx->useful->hbaoUbo.NDotVBias);
// resolution
int quarterW = ((W+3)/4);
int quarterH = ((H+3)/4);
cx->useful->hbaoUbo.InvQuarterResolution[0] = 1.0f/float(quarterW);
cx->useful->hbaoUbo.InvQuarterResolution[1] = 1.0f/float(quarterH);
cx->useful->hbaoUbo.InvFullResolution[0] = 1.0f/float(W);
cx->useful->hbaoUbo.InvFullResolution[1] = 1.0f/float(H);
for (int i = 0; i < HBAO_RANDOM_ELEMENTS; i++){
cx->useful->hbaoUbo.float2Offsets[4*i+0] = float(i % 4) + 0.5f;
cx->useful->hbaoUbo.float2Offsets[4*i+1] = float(i / 4) + 0.5f;
cx->useful->hbaoUbo.float2Offsets[4*i+2] = 0;
cx->useful->hbaoUbo.float2Offsets[4*i+3] = 0;
cx->useful->hbaoUbo.jitters[4*i+0] = cx->useful->hbaoRandom[i][0];
cx->useful->hbaoUbo.jitters[4*i+1] = cx->useful->hbaoRandom[i][1];
cx->useful->hbaoUbo.jitters[4*i+2] = cx->useful->hbaoRandom[i][2];
cx->useful->hbaoUbo.jitters[4*i+3] = cx->useful->hbaoRandom[i][3];
}
}