From 56485f20a9de77446cd624bc9d355ad2b9deefc7 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Tue, 9 Mar 2021 13:12:53 +0100 Subject: [PATCH] various changes and fixes to make coolfog and sky work correctly in VR --- basegraph.cpp | 4 ---- drawing.cpp | 9 ++++----- graph.cpp | 5 +++++ shaders.cpp | 19 ++++++++++++------- sky.cpp | 26 +++++++++++++++++--------- vr.cpp | 13 ++++++------- 6 files changed, 44 insertions(+), 32 deletions(-) diff --git a/basegraph.cpp b/basegraph.cpp index b016b4d5..07377d73 100644 --- a/basegraph.cpp +++ b/basegraph.cpp @@ -343,10 +343,6 @@ EX void setGLProjection(color_t col IS(backcolor)) { glClearColor(part(col, 2) / 255.0, part(col, 1) / 255.0, part(col, 0) / 255.0, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - #if CAP_VR - vrhr::clear(); - #endif - GLERR("setGLProjection #1"); glEnable(GL_BLEND); diff --git a/drawing.cpp b/drawing.cpp index 2e26de41..992bfeea 100644 --- a/drawing.cpp +++ b/drawing.cpp @@ -2178,11 +2178,6 @@ void dqi_line::draw_back() { } EX void sort_drawqueue() { - - #if MAXMDIM >= 4 && CAP_GL - if(WDIM == 2 && GDIM == 3 && hyperbolic) make_air(); - #endif - DEBBI(DF_GRAPH, ("sort_drawqueue")); for(int a=0; a= 4 && CAP_GL + if(WDIM == 2 && GDIM == 3 && hyperbolic && !vrhr::rendering()) make_air(); + #endif #if CAP_VR if(vrhr::should_render() == 1) { diff --git a/graph.cpp b/graph.cpp index 4163fa51..f9ca7f12 100644 --- a/graph.cpp +++ b/graph.cpp @@ -5193,6 +5193,11 @@ EX void drawscreen() { #if CAP_GL if(vid.usingGL) setGLProjection(); #endif + +#if CAP_VR + vrhr::clear(); +#endif + #if CAP_SDL // SDL_LockSurface(s); diff --git a/shaders.cpp b/shaders.cpp index 219d19c6..7a27194d 100644 --- a/shaders.cpp +++ b/shaders.cpp @@ -132,6 +132,8 @@ shared_ptr write_shader(flagtype shader_flags) { bool skip_t = false; + bool azi_hyperbolic = false; + if(vid.stereo_mode == sODS) { shader_flags |= SF_DIRECT | SF_ODSBOX; vmain += "// this is ODS shader\n"; @@ -304,6 +306,8 @@ shared_ptr write_shader(flagtype shader_flags) { shader_flags |= SF_PERS3 | SF_DIRECT; #if CAP_VR if(vrhr::rendering() && hyperbolic && vrhr::eyes != vrhr::eEyes::truesim) { + azi_hyperbolic = true; + coordinator += "mediump vec4 orig_t = t;\n"; coordinator += "t = t * acosh(t[3]) / length(t.xyz);\n" "t[3] = 1.;\n"; @@ -312,7 +316,7 @@ shared_ptr write_shader(flagtype shader_flags) { else #endif if(hyperbolic) - distfun = "acosh(t[3])", treset = true; + distfun = "acosh(t[3])"; else if(euclid || nonisotropic || stretch::in() || (sphere && ray::in_use)) distfun = "length(t.xyz)", treset = true; else { @@ -345,11 +349,7 @@ shared_ptr write_shader(flagtype shader_flags) { if(!skip_t) { vmain += "mediump vec4 t = uMV * aPosition;\n"; vmain += coordinator; - bool ok = true; - #if CAP_VR - if(vrhr::active()) ok = false; - #endif - if(GDIM == 3 && WDIM == 2 && hyperbolic && context_fog && ok && pmodel == mdPerspective) { + if(GDIM == 3 && WDIM == 2 && hyperbolic && context_fog && pmodel == mdPerspective) { vsh += "uniform mediump mat4 uRadarTransform;\n" "uniform mediump sampler2D tAirMap;\n" @@ -363,8 +363,13 @@ shared_ptr write_shader(flagtype shader_flags) { " return texture2D(tAirMap, pt.xy);\n" " }\n"; + + if(azi_hyperbolic) vmain += + "vec4 ending = uRadarTransform * orig_t;\n"; + else vmain += + "vec4 ending = uRadarTransform * t;\n"; + vmain += - "vec4 ending = uRadarTransform * t;\n" "float len = acosh(ending.w);\n" "float eulen = length(ending.xyz);\n" "ending.xyz /= eulen;\n" diff --git a/sky.cpp b/sky.cpp index 42d61bd0..bd08396f 100644 --- a/sky.cpp +++ b/sky.cpp @@ -138,13 +138,8 @@ void compute_skyvertices(const vector& sky) { void dqi_sky::draw() { if(!vid.usingGL || sky.empty()) return; - if(centerover != sky_centerover) { - sky_centerover = centerover; - sky_cview = cview(); - compute_skyvertices(sky); - } - transmatrix s = cview().T * inverse(sky_cview.T); - + transmatrix s = (vrhr::rendering() ? vrhr::master_cview : cview()).T * inverse(sky_cview.T); + for(int ed = current_display->stereo_active() ? -1 : 0; ed<2; ed+=2) { if(global_projection && global_projection != ed) continue; current_display->next_shader_flags = GF_VARCOLOR; @@ -153,8 +148,9 @@ void dqi_sky::draw() { glhr::projection_multiply(glhr::tmtogl(xpush(-vid.ipd * global_projection/2))); glapplymatrix(xpush(vid.ipd * global_projection/2) * s); } - else + else { glapplymatrix(s); + } glhr::prepare(skyvertices); glhr::set_fogbase(1.0 + 5 / sightranges[geometry]); glhr::set_depthtest(model_needs_depth() && prio < PPR::SUPERLINE); @@ -382,7 +378,15 @@ EX struct renderbuffer *airbuf; EX void make_air() { if(!sky) return; - if(vrhr::active()) return; + + if(centerover != sky_centerover) { + sky_centerover = centerover; + sky_cview = cview(); + compute_skyvertices(sky->sky); + } + + if(!context_fog) return; + const int AIR_TEXTURE = 512; if(!airbuf) { airbuf = new renderbuffer(AIR_TEXTURE, AIR_TEXTURE, true); @@ -394,6 +398,10 @@ EX void make_air() { } } + #if CAP_VR + dynamicval i(vrhr::state, 0); + #endif + if(1) { //shot::take("airtest.png", drawqueue); dynamicval v(vid, vid); diff --git a/vr.cpp b/vr.cpp index 78f187fb..d3710dae 100644 --- a/vr.cpp +++ b/vr.cpp @@ -1005,23 +1005,24 @@ EX void gen_mv() { } } +EX shiftmatrix master_cview; + EX void render() { track_poses(); resetbuffer rb; state = 2; - // eyes = lshiftclick ? eEyes::truesim : eEyes::equidistant; - // cscr = lshiftclick ? eCompScreen::eyes : eCompScreen::single; for(int i=0; i<3; i++) { if(1) { make_actual_view(); - shiftmatrix Tv = cview(); + master_cview = cview(); dynamicval tN(NLP, NLP); dynamicval tV(View, View); dynamicval tC(current_display->which_copy, current_display->which_copy); + dynamicval trt(radar_transform); if(hsm == eHeadset::rotation_only) { transmatrix T = hmd_at; @@ -1038,10 +1039,8 @@ EX void render() { } make_actual_view(); - hmd_pre = hmd_pre_for[i] = cview().T * inverse(Tv.T); - // inverse_shift(Tv, cview()); - // View * inverse(Tv.T); - // inverse(inverse_shift(cview(), Tv)); + hmd_pre = hmd_pre_for[i] = cview().T * inverse(master_cview.T); + radar_transform = trt.backup * inverse(hmd_pre); if(1) { gen_mv();