From 5d9fdd83a8040fb19c90607612cf04ac2c5913cf Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Wed, 26 Feb 2020 01:27:04 +0100 Subject: [PATCH] fixed ODS; non-isotropic ODS --- drawing.cpp | 20 ++++++++++++++++---- shaders.cpp | 17 ++++++++++++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/drawing.cpp b/drawing.cpp index 126fbd8a..e712094e 100644 --- a/drawing.cpp +++ b/drawing.cpp @@ -1170,9 +1170,14 @@ EX namespace ods { ld phi = atan2(y, x) - atan2(y0, x0) + M_PI; - // ld delta = euclid ? hypot(y0,z) : atan2_auto(z / sin(theta), t / cos_auto(vid.ipd/2)); - ld p = z / sin(theta) / t * cos_auto(vid.ipd / 2); - ld delta = (p > 1) ? 13 : (p < -1) ? -13 : atanh(p); + ld delta; + if(euclid) delta = hypot(y0, z); + else if(sphere) delta = atan2_auto(z / sin(theta), t / cos_auto(vid.ipd/2)); + else { + // ld delta = euclid ? hypot(y0,z) : atan2_auto(z / sin(theta), t / cos_auto(vid.ipd/2)); + ld p = z / sin(theta) / t * cos_auto(vid.ipd / 2); + delta = (p > 1) ? 13 : (p < -1) ? -13 : atanh(p); + } if(euclid || hyperbolic) phi -= M_PI; if(hyperbolic) delta = -delta; @@ -1221,7 +1226,14 @@ EX namespace ods { for(int j=0; j<3; j++) { hyperpoint o = p->V * glhr::gltopoint((*p->tab)[p->offset+i+j]); - if(!project(o, h[j], h[j+3], global_projection == -1)) + if(nonisotropic || prod) { + o = lp_apply(inverse_exp(o, iTable, false)); + o[3] = 1; + dynamicval g(geometry, gEuclid); + if(!project(o, h[j], h[j+3], global_projection == -1)) + goto next_i; + } + else if(!project(o, h[j], h[j+3], global_projection == -1)) goto next_i; } diff --git a/shaders.cpp b/shaders.cpp index 2cddc5ec..301794e1 100644 --- a/shaders.cpp +++ b/shaders.cpp @@ -28,6 +28,7 @@ constexpr flagtype SF_HALFPLANE = 8192; constexpr flagtype SF_ORIENT = 16384; constexpr flagtype SF_BOX = 32768; constexpr flagtype SF_ZFOG = 65536; +constexpr flagtype SF_ODSBOX = (1<<17); #endif #if HDR @@ -98,7 +99,12 @@ shared_ptr write_shader(flagtype shader_flags) { bool skip_t = false; - if(pmodel == mdPixel) { + if(vid.stereo_mode == sODS) { + shader_flags |= SF_DIRECT | SF_ODSBOX; + vmain += "// this is ODS shader\n"; + distfun = "aPosition.z"; + } + else if(pmodel == mdPixel) { vmain += "mediump vec4 pos = aPosition; pos[3] = 1.0;\n"; vmain += "pos = uMV * pos;\n"; if(shader_flags & GF_LEVELS) vmain += "vPos = pos;\n"; @@ -355,7 +361,8 @@ void display_data::set_projection(int ed) { if(vid.stretch != 1 && (shader_flags & SF_DIRECT)) glhr::projection_multiply(glhr::scale(vid.stretch, 1, 1)); - eyewidth_translate(ed); + if(vid.stereo_mode != sODS) + eyewidth_translate(ed); auto ortho = [&] (ld x, ld y) { glhr::glmatrix M = glhr::ortho(x, y, 1); @@ -371,7 +378,7 @@ void display_data::set_projection(int ed) { glhr::projection_multiply(M); if(nisot::local_perspective_used() && (shader_flags & SF_BOX)) glhr::projection_multiply(glhr::tmtogl_transpose(NLP)); - if(ed) { + if(ed && vid.stereo_mode != sODS) { glhr::glmatrix m = glhr::id; m[2][0] -= ed; glhr::projection_multiply(m); @@ -381,6 +388,10 @@ void display_data::set_projection(int ed) { if(shader_flags & SF_PIXELS) ortho(cd->xsize/2, -cd->ysize/2); else if(shader_flags & SF_BOX) ortho(cd->xsize/current_display->radius/2, -cd->ysize/current_display->radius/2); + else if(shader_flags & SF_ODSBOX) { + ortho(M_PI, M_PI); + glhr::fog_max(1/sightranges[geometry], darkena(backcolor, 0, 0xFF)); + } else if(shader_flags & SF_PERS3) { glhr::projection_multiply(glhr::frustum(current_display->tanfov, current_display->tanfov * cd->ysize / cd->xsize)); glhr::projection_multiply(glhr::scale(1, -1, -1));