disk model in Euclidean and hyperbolic

This commit is contained in:
Zeno Rogue 2020-12-28 22:00:56 +01:00
parent 266e4e43c4
commit 38eb8c5122
3 changed files with 64 additions and 1 deletions

View File

@ -298,6 +298,7 @@ struct GLprogram {
GLint uFog, uFogColor, uColor, tTexture, tInvExpTable, tAirMap, uMV, uProjection, uAlpha, uFogBase, uPP;
GLint uPRECX, uPRECY, uPRECZ, uIndexSL, uIterations, uLevelLines, uSV, uRadarTransform;
GLint uRotSin, uRotCos, uRotNil;
GLint uDepthScaling, uCamera, uDepth;
flagtype shader_flags;
@ -364,6 +365,7 @@ GLprogram::GLprogram(string vsh, string fsh) {
uAlpha = -1;
uLevelLines = -1;
uFogColor = -1;
uDepthScaling = uCamera = uDepth = -1;
uColor = tTexture = tInvExpTable = tAirMap = -1;
uFogBase = -1;
@ -426,6 +428,10 @@ GLprogram::GLprogram(string vsh, string fsh) {
tInvExpTable = glGetUniformLocation(_program, "tInvExpTable");
tAirMap = glGetUniformLocation(_program, "tAirMap");
uDepth = glGetUniformLocation(_program, "uDepth");
uDepthScaling = glGetUniformLocation(_program, "uDepthScaling");
uCamera = glGetUniformLocation(_program, "uCamera");
uPRECX = glGetUniformLocation(_program, "PRECX");
uPRECY = glGetUniformLocation(_program, "PRECY");
uPRECZ = glGetUniformLocation(_program, "PRECZ");

View File

@ -411,7 +411,7 @@ EX void apply_other_model(shiftpoint H_orig, hyperpoint& ret, eModel md) {
case mdBall: {
ld zlev = find_zlev(H);
ld zl = vid.depth-geom3::factor_to_lev(zlev);
ld zl = vid.depth-geom3::factor_to_lev(zlev) * pconf.depth_scaling;
ballmodel(ret, atan2(H), hdist0(H), zl);
break;
@ -434,6 +434,25 @@ EX void apply_other_model(shiftpoint H_orig, hyperpoint& ret, eModel md) {
ret[3] = 1;
break;
}
if(vrhr::state == 2) {
ld zlev = find_zlev(H);
ld zl = vid.depth-geom3::factor_to_lev(zlev) * pconf.depth_scaling;
ld d = hdist0(H);
ld dd = hypot_d(2, H);
hyperpoint H1 = ypush(vid.camera) * xpush(d) * ypush0(zl);
ld tzh = pconf.alpha + H1[2];
ld ax = H1[0] / tzh;
ld ay = H1[1] / tzh;
ret[0] = ax * H[0] / dd;
ret[1] = ax * H[1] / dd;
ret[2] = ay;
models::apply_vr(ret[2], ret[1]);
return;
}
ld tz = get_tz(H);
if(!pconf.camera_angle) {
ret[0] = H[0] / tz;

View File

@ -155,6 +155,35 @@ shared_ptr<glhr::GLprogram> write_shader(flagtype shader_flags) {
}
else if(!vid.consider_shader_projection) {
shader_flags |= SF_PIXELS;
}
else if(among(pmodel, mdDisk, mdBall) && GDIM == 2 && vrhr::state == 2 && !sphere) {
shader_flags |= SF_DIRECT | SF_BOX;
vsh += "uniform mediump float uAlpha, uDepth, uDepthScaling, uCamera;";
if(hyperbolic) coordinator +=
"float zlev = sqrt(t.z*t.z-t.x*t.x-t.y*t.y);\n"
"float zl = uDepth - uDepthScaling * (uDepth - atanh(tanh(uDepth)/zlev));\n"
"float dd = sqrt(t.x*t.x+t.y*t.y);\n"
"float d = acosh(t.z/zlev);\n"
"float uz = uAlpha + cosh(zl) * cosh(d) * cosh(uCamera) + sinh(zl) * sinh(uCamera);\n"
"float ux = cosh(zl) * sinh(d) / uz;\n"
"t.xy = ux * t.xy / dd;\n"
"t.z = (sinh(zl) * cosh(uCamera) + sinh(uCamera) * cosh(zl) * cosh(d)) / uz;\n"
;
else if(euclid) coordinator +=
"t.z = uDepth * (1. - (t.z - 1.) * uDepthScaling) + uAlpha + uCamera;\n";
else if(sphere) coordinator +=
"float zlev = sqrt(t.z*t.z+t.x*t.x+t.y*t.y);\n"
"float zl = uDepth - uDepthScaling * (uDepth - atan(tan(uDepth)/zlev));\n"
"float dd = sqrt(t.x*t.x+t.y*t.y);\n"
"float d = acos(t.z/zlev);\n"
"float uz = uAlpha + cos(zl) * cos(d) * cos(uCamera) + sin(zl) * sin(uCamera);\n"
"float ux = cos(zl) * sin(d) / uz;\n"
"t.xy = ux * t.xy / dd;\n"
"t.z = (sin(uCamera) * cos(zl) * cos(d) - sin(zl) * cos(uCamera)) / uz;\n"
;
}
else if(pmodel == mdDisk && MDIM == 3 && !spherespecial && !prod) {
shader_flags |= SF_DIRECT;
@ -615,6 +644,15 @@ void display_data::set_projection(int ed, ld shift) {
if(selected->uAlpha != -1)
glhr::set_ualpha(pconf.alpha);
if(selected->uDepth != -1)
glUniform1f(selected->uDepth, vid.depth);
if(selected->uCamera != -1)
glUniform1f(selected->uCamera, vid.camera);
if(selected->uDepthScaling != -1)
glUniform1f(selected->uDepthScaling, pconf.depth_scaling);
if(selected->uLevelLines != -1) {
glUniform1f(selected->uLevelLines, levellines);
}