diff --git a/drawing.cpp b/drawing.cpp index 568ca870..bb880e66 100644 --- a/drawing.cpp +++ b/drawing.cpp @@ -1882,6 +1882,11 @@ EX void draw_main() { } } else { + if(ray::in_use && !ray::comparison_mode) { + ray::cast(); + reset_projection(); + } + for(auto& ptd: ptds) if(ptd->prio == PPR::OUTCIRCLE) ptd->draw(); @@ -1892,6 +1897,13 @@ EX void draw_main() { ptd->draw(); } glflush(); + + if(ray::in_use && ray::comparison_mode) { + glDepthFunc(GL_LEQUAL); + glClearDepth(1.0f); + glClear(GL_DEPTH_BUFFER_BIT); + ray::cast(); + } } } diff --git a/floorshapes.cpp b/floorshapes.cpp index 0c16f73a..2936647d 100644 --- a/floorshapes.cpp +++ b/floorshapes.cpp @@ -1027,6 +1027,8 @@ void geometry_information::make_floor_textures_here() { gv.emplace_back(+1, +1, 1, 1, 1); gv.emplace_back(-1, +1, 1, 1, 1); + dynamicval riu(ray::in_use, false); + if(1) { current_display->next_shader_flags = GF_VARCOLOR; dynamicval m(pmodel, mdPixel); diff --git a/graph.cpp b/graph.cpp index b9a4d41d..6c2dfc21 100644 --- a/graph.cpp +++ b/graph.cpp @@ -4437,7 +4437,6 @@ EX void drawthemap() { profile_start(1); make_actual_view(); currentmap->draw(); - if(ray::in_use && !ray::comparison_mode) ray::cast(); drawWormSegments(); drawBlizzards(); drawArrowTraps(); @@ -4703,13 +4702,6 @@ EX void drawfullmap() { drawqueue(); #endif - if(ray::in_use && ray::comparison_mode) { - glDepthFunc(GL_LEQUAL); - glClearDepth(1.0f); - glClear(GL_DEPTH_BUFFER_BIT); - ray::cast(); - } - profile_stop(2); } diff --git a/raycaster.cpp b/raycaster.cpp index 956fa497..4c820f1a 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -85,7 +85,7 @@ EX bool requested() { } struct raycaster : glhr::GLprogram { - GLint uStart, uStartid, uM, uLength, uFovX, uFovY, uIPD; + GLint uStart, uStartid, uM, uLength, uFovX, uFovY, uIPD, uShift; GLint uWallstart, uWallX, uWallY; GLint tConnections, tWallcolor, tTextureMap; GLint uBinaryWidth, uPLevel, uLP, uStraighten, uReflectX, uReflectY; @@ -100,6 +100,7 @@ struct raycaster : glhr::GLprogram { uLength = glGetUniformLocation(_program, "uLength"); uFovX = glGetUniformLocation(_program, "uFovX"); uFovY = glGetUniformLocation(_program, "uFovY"); + uShift = glGetUniformLocation(_program, "uShift"); uIPD = glGetUniformLocation(_program, "uIPD"); uWallstart = glGetUniformLocation(_program, "uWallstart"); @@ -117,6 +118,8 @@ struct raycaster : glhr::GLprogram { uExpDecay = glGetUniformLocation(_program, "uExpDecay"); uExpStart = glGetUniformLocation(_program, "uExpStart"); + uShift = glGetUniformLocation(_program, "uShift"); + uBLevel = glGetUniformLocation(_program, "uBLevel"); tConnections = glGetUniformLocation(_program, "tConnections"); @@ -141,10 +144,10 @@ void enable_raycaster() { string vsh = "attribute mediump vec4 aPosition;\n" - "uniform mediump float uFovX, uFovY;\n" + "uniform mediump float uFovX, uFovY, uShift;\n" "varying mediump vec4 at;\n" "void main() { \n" - " gl_Position = aPosition; at = aPosition;\n" + " gl_Position = aPosition; at = aPosition; at.x += uShift;\n" #if IN_ODS " at[0] *= PI; at[1] *= PI; \n" #else @@ -801,9 +804,17 @@ EX void cast() { glhr::makevertex(+1, -1, 1), glhr::makevertex(+1, +1, 1) }; + + ld d = current_display->eyewidth(); + if(vid.stereo_mode == sLR) d = 2 * d - 1; + else d = -d; + + glUniform1f(o->uShift, -global_projection * d); auto& cd = current_display; - glUniform1f(o->uFovX, cd->tanfov); + cd->set_viewport(global_projection); + cd->set_mask(global_projection); + glUniform1f(o->uFovX, cd->tanfov / (vid.stereo_mode == sLR ? 2 : 1)); glUniform1f(o->uFovY, cd->tanfov * cd->ysize / cd->xsize); deg = S7; @@ -817,6 +828,10 @@ EX void cast() { cell *cs = centerover; transmatrix T = cview(); + + if(global_projection) + T = xpush(vid.ipd * global_projection/2) * T; + if(nonisotropic) T = NLP * T; T = inverse(T);