From fe7e122613b0ce892d25e508a282156c0aa0d7fc Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Thu, 30 Nov 2023 12:38:30 +0100 Subject: [PATCH] ray:: improved ODS --- raycaster.cpp | 212 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 152 insertions(+), 60 deletions(-) diff --git a/raycaster.cpp b/raycaster.cpp index 103ea5ce..2b940308 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -15,7 +15,7 @@ EX namespace ray { #if CAP_RAY /** texture IDs */ -GLuint txConnections = 0, txWallcolor = 0, txTextureMap = 0, txVolumetric = 0, txM = 0, txWall = 0, txPortalConnections = 0; +GLuint txConnections = 0, txWallcolor = 0, txTextureMap = 0, txVolumetric = 0, txM = 0, txWall = 0, txPortalConnections = 0, txStart = 0; EX bool in_use; EX bool comparison_mode; @@ -97,8 +97,6 @@ ld& maxstep_current() { return maxstep_nil; } -#define IN_ODS 0 - eGeometry last_geometry; vector> used_sample_list() { @@ -162,9 +160,9 @@ EX bool requested() { #if HDR struct raycaster : glhr::GLprogram { - GLint uStart, uStartid, uM, uLength, uIPD; + GLint uStart, uStartid, uM, uLength; GLint uWallstart, uWallX, uWallY; - GLint tConnections, tWallcolor, tTextureMap, tVolumetric; + GLint tConnections, tWallcolor, tTextureMap, tVolumetric, tStart; GLint uBinaryWidth, uPLevel, uLP, uStraighten, uReflectX, uReflectY; GLint uLinearSightRange, uExpStart, uExpDecay; GLint uBLevel; @@ -204,7 +202,6 @@ raycaster::raycaster(string vsh, string fsh) : GLprogram(vsh, fsh) { uM = glGetUniformLocation(_program, "uM"); uLength = glGetUniformLocation(_program, "uLength"); uProjection = glGetUniformLocation(_program, "uProjection"); - uIPD = glGetUniformLocation(_program, "uIPD"); uWallstart = glGetUniformLocation(_program, "uWallstart"); uWallX = glGetUniformLocation(_program, "uWallX"); @@ -228,6 +225,7 @@ raycaster::raycaster(string vsh, string fsh) : GLprogram(vsh, fsh) { tWallcolor = glGetUniformLocation(_program, "tWallcolor"); tTextureMap = glGetUniformLocation(_program, "tTextureMap"); tVolumetric = glGetUniformLocation(_program, "tVolumetric"); + tStart = glGetUniformLocation(_program, "tStart"); tPortalConnections = glGetUniformLocation(_program, "tPortalConnections"); @@ -1255,15 +1253,6 @@ void raygen::emit_iterate(int gid1) { if(in_e2xe() && !eyes) fmain += "tangent.w = position.w = 0.;\n"; - if(IN_ODS) fmain += - " if(go == 0.) {\n" - " mediump float best = "+f_len()+"(position);\n" - " for(int i=0; i& wallx, vector& wally, vectortype; a++) + if(hdist(currentmap->ray_iadj(cs, a) * T * C0, TC0) < hdist(T * C0, TC0)) { + T = currentmap->iadj(cs, a) * T; + if(our_raycaster->uToOrig != -1) { + transmatrix HT = currentmap->adj(cs, a); + HT = stretch::itranslate(tC0(HT)) * HT; + msm = HT * msm; + } + cs = cs->move(a); + ray_fixes++; + if(ray_fixes > 100) { + println(hlog, "major ray error"); + return; + } + goto back; + } + if(ray_fixes >= ray_fixes_warn_from) println(hlog, "ray error x", ray_fixes, " centerover = ", ocs, " -> ", cs); + } + +EX int ods_prec = 8192; + EX void cast() { // may call itself recursively in case of bugs -- just in case... dynamicval dn(nesting, nesting+1); @@ -2538,7 +2572,7 @@ EX void cast() { auto& o = our_raycaster; - if(need_many_cell_types() && o->uWallOffset == -1) { + if(need_many_cell_types() && o->uWallOffset == -1 && vid.stereo_mode != sODS) { reset_raycaster(); cast(); return; @@ -2599,43 +2633,20 @@ EX void cast() { transmatrix T = cview().T; if(global_projection) - T = xpush(vid.ipd * global_projection/2) * T; + T = xpush(vid.ipd * global_projection/2) * T; // todo fix for intra if(nonisotropic) T = NLP * T; T = inverse(T); virtualRebase(cs, T); - int ray_fixes = 0; - transmatrix msm = stretch::mstretch_matrix; - hyperpoint TC0 = tile_center(); - - back: - for(int a=0; atype; a++) - if(hdist(currentmap->ray_iadj(cs, a) * T * C0, TC0) < hdist(T * C0, TC0)) { - T = currentmap->iadj(cs, a) * T; - if(o->uToOrig != -1) { - transmatrix HT = currentmap->adj(cs, a); - HT = stretch::itranslate(tC0(HT)) * HT; - msm = HT * msm; - } - cs = cs->move(a); - ray_fixes++; - if(ray_fixes > 100) { - println(hlog, "major ray error"); - return; - } - goto back; - } - if(ray_fixes) println(hlog, "ray error x", ray_fixes, " centerover = ", centerover, " -> ", cs); + rayfix(cs, T, msm); - glUniformMatrix4fv(o->uStart, 1, 0, glhr::tmtogl_transpose3(T).as_array()); + if(vid.stereo_mode != sODS) glUniformMatrix4fv(o->uStart, 1, 0, glhr::tmtogl_transpose3(T).as_array()); if(o->uLP != -1) glUniformMatrix4fv(o->uLP, 1, 0, glhr::tmtogl_transpose3(inverse(NLP)).as_array()); GLERR("uniform mediump startid"); - glUniform1f(o->uIPD, vid.ipd); - GLERR("uniform mediump IPD"); if(o->uITOA != -1) { glUniformMatrix4fv(o->uITOA, 1, 0, glhr::tmtogl_transpose3(stretch::m_itoa).as_array()); @@ -2757,7 +2768,7 @@ EX void cast() { } // we may learn about this now... - if(need_many_cell_types() && o->uWallOffset == -1) { + if(need_many_cell_types() && o->uWallOffset == -1 && vid.stereo_mode != sODS) { reset_raycaster(); cast(); return; @@ -2766,7 +2777,88 @@ EX void cast() { GLERR("uniform mediump start"); if(!o) { cast(); return; } - uniform2(o->uStartid, rmap->enc(rmap->ids[cs], 0)); + + if(vid.stereo_mode == sODS) { + + vector> tstart(ods_prec * 32); + + for(int y=0; y<2; y++) + for(int x=0; x ok + + int xb = x + y * ods_prec * 16; + + dynamicval tco(centerover); + dynamicval tfd(walking::floor_dir); + dynamicval tof(walking::on_floor_of); + dynamicval tis(intra::scale); + dynamicval tN(NLP, NLP); + dynamicval tV(View, View); + dynamicval tC(current_display->which_copy, current_display->which_copy); + dynamicval trt(current_display->radar_transform); + + int id = intra::current; + cell *cov = centerover; + finalizer fin([&] { + if(intra::current != id) { + intra::switch_to(id); + } + centerover = cov; + }); + + auto T1 = T; + + View = inverse(T1); + // if(nonisotropic) View = inverse(NLP) * View; + + centerover = cs; + ld eye = y == 0 ? vid.ipd / 2. : -vid.ipd / 2.; + rotate_view(cspin(0, 2, -lambda)); + shift_view(xtangent(eye)); + + if(nonisotropic) { + auto T = View; + transmatrix T2 = eupush( tC0(view_inverse(T)) ); + NLP = T * T2; + } + + T1 = inverse(View); + virtualRebase(centerover, T1); + rayfix(centerover, T1, msm); + + T1 = protect_prod(T1); + + for(int a=0; a<4; a++) + for(int b=0; b<4; b++) { + tstart[xb + a * ods_prec][b] = T1[a][b]/ray_scale + .5; + } + + auto mLP = protect_prod(inverse(NLP)); + + for(int a=0; a<4; a++) + for(int b=0; b<4; b++) { + tstart[xb + (a+4) * ods_prec][b] = mLP[a][b]/ray_scale + .5; + } + + auto enc = rmap->enc(rmap->ids[centerover], 0); + + tstart[xb + 8 * ods_prec][0] = enc[0]; + tstart[xb + 8 * ods_prec][1] = enc[1]; + + int wo1 = intra::full_wall_offset(centerover); + int sides = centerover->type + (WDIM == 2 ? 2 : 0); + + tstart[xb + 8 * ods_prec][3] = (wo1 * 1. / max_wall_offset) + (sides + .5) * 1. / max_wall_offset / max_celltype; + } + + if(vid.stereo_mode != sODS) glUniformMatrix4fv(o->uStart, 1, 0, glhr::tmtogl_transpose3(T).as_array()); + bind_array(tstart, o->tStart, txStart, 10, ods_prec); + } + else + uniform2(o->uStartid, rmap->enc(rmap->ids[cs], 0)); } #if CAP_VERTEXBUFFER