mirror of
				https://github.com/zenorogue/hyperrogue.git
				synced 2025-10-31 05:52:59 +00:00 
			
		
		
		
	various changes and fixes to make coolfog and sky work correctly in VR
This commit is contained in:
		| @@ -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); |   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); |   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | ||||||
|    |    | ||||||
|   #if CAP_VR |  | ||||||
|   vrhr::clear(); |  | ||||||
|   #endif |  | ||||||
|  |  | ||||||
|   GLERR("setGLProjection #1"); |   GLERR("setGLProjection #1"); | ||||||
|  |  | ||||||
|   glEnable(GL_BLEND); |   glEnable(GL_BLEND); | ||||||
|   | |||||||
| @@ -2178,11 +2178,6 @@ void dqi_line::draw_back() { | |||||||
|   } |   } | ||||||
|  |  | ||||||
| EX void sort_drawqueue() { | EX void sort_drawqueue() { | ||||||
|  |  | ||||||
|   #if MAXMDIM >= 4 && CAP_GL |  | ||||||
|   if(WDIM == 2 && GDIM == 3 && hyperbolic) make_air(); |  | ||||||
|   #endif |  | ||||||
|  |  | ||||||
|   DEBBI(DF_GRAPH, ("sort_drawqueue")); |   DEBBI(DF_GRAPH, ("sort_drawqueue")); | ||||||
|    |    | ||||||
|   for(int a=0; a<PMAX; a++) qp[a] = 0; |   for(int a=0; a<PMAX; a++) qp[a] = 0; | ||||||
| @@ -2387,6 +2382,10 @@ EX void drawqueue() { | |||||||
|   #if CAP_WRL |   #if CAP_WRL | ||||||
|   if(wrl::in) { wrl::render(); return; } |   if(wrl::in) { wrl::render(); return; } | ||||||
|   #endif |   #endif | ||||||
|  |  | ||||||
|  |   #if MAXMDIM >= 4 && CAP_GL | ||||||
|  |   if(WDIM == 2 && GDIM == 3 && hyperbolic && !vrhr::rendering()) make_air(); | ||||||
|  |   #endif | ||||||
|    |    | ||||||
|   #if CAP_VR |   #if CAP_VR | ||||||
|   if(vrhr::should_render() == 1) {  |   if(vrhr::should_render() == 1) {  | ||||||
|   | |||||||
| @@ -5193,6 +5193,11 @@ EX void drawscreen() { | |||||||
| #if CAP_GL | #if CAP_GL | ||||||
|   if(vid.usingGL) setGLProjection(); |   if(vid.usingGL) setGLProjection(); | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|  | #if CAP_VR | ||||||
|  |   vrhr::clear(); | ||||||
|  | #endif | ||||||
|  |  | ||||||
|    |    | ||||||
|   #if CAP_SDL |   #if CAP_SDL | ||||||
|   // SDL_LockSurface(s); |   // SDL_LockSurface(s); | ||||||
|   | |||||||
							
								
								
									
										19
									
								
								shaders.cpp
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								shaders.cpp
									
									
									
									
									
								
							| @@ -132,6 +132,8 @@ shared_ptr<glhr::GLprogram> write_shader(flagtype shader_flags) { | |||||||
|    |    | ||||||
|   bool skip_t = false; |   bool skip_t = false; | ||||||
|    |    | ||||||
|  |   bool azi_hyperbolic = false; | ||||||
|  |    | ||||||
|   if(vid.stereo_mode == sODS) { |   if(vid.stereo_mode == sODS) { | ||||||
|     shader_flags |= SF_DIRECT | SF_ODSBOX; |     shader_flags |= SF_DIRECT | SF_ODSBOX; | ||||||
|     vmain += "// this is ODS shader\n"; |     vmain += "// this is ODS shader\n"; | ||||||
| @@ -304,6 +306,8 @@ shared_ptr<glhr::GLprogram> write_shader(flagtype shader_flags) { | |||||||
|     shader_flags |= SF_PERS3 | SF_DIRECT; |     shader_flags |= SF_PERS3 | SF_DIRECT; | ||||||
|     #if CAP_VR |     #if CAP_VR | ||||||
|     if(vrhr::rendering() && hyperbolic && vrhr::eyes != vrhr::eEyes::truesim) { |     if(vrhr::rendering() && hyperbolic && vrhr::eyes != vrhr::eEyes::truesim) { | ||||||
|  |       azi_hyperbolic = true; | ||||||
|  |       coordinator += "mediump vec4 orig_t = t;\n"; | ||||||
|       coordinator +=  |       coordinator +=  | ||||||
|         "t = t * acosh(t[3]) / length(t.xyz);\n" |         "t = t * acosh(t[3]) / length(t.xyz);\n" | ||||||
|         "t[3] = 1.;\n"; |         "t[3] = 1.;\n"; | ||||||
| @@ -312,7 +316,7 @@ shared_ptr<glhr::GLprogram> write_shader(flagtype shader_flags) { | |||||||
|     else  |     else  | ||||||
|     #endif |     #endif | ||||||
|     if(hyperbolic) |     if(hyperbolic) | ||||||
|       distfun = "acosh(t[3])", treset = true; |       distfun = "acosh(t[3])"; | ||||||
|     else if(euclid || nonisotropic || stretch::in() || (sphere && ray::in_use)) |     else if(euclid || nonisotropic || stretch::in() || (sphere && ray::in_use)) | ||||||
|       distfun = "length(t.xyz)", treset = true; |       distfun = "length(t.xyz)", treset = true; | ||||||
|     else { |     else { | ||||||
| @@ -345,11 +349,7 @@ shared_ptr<glhr::GLprogram> write_shader(flagtype shader_flags) { | |||||||
|   if(!skip_t) { |   if(!skip_t) { | ||||||
|     vmain += "mediump vec4 t = uMV * aPosition;\n"; |     vmain += "mediump vec4 t = uMV * aPosition;\n"; | ||||||
|     vmain += coordinator; |     vmain += coordinator; | ||||||
|     bool ok = true; |     if(GDIM == 3 && WDIM == 2 && hyperbolic && context_fog && pmodel == mdPerspective) { | ||||||
|     #if CAP_VR |  | ||||||
|     if(vrhr::active()) ok = false; |  | ||||||
|     #endif |  | ||||||
|     if(GDIM == 3 && WDIM == 2 && hyperbolic && context_fog && ok && pmodel == mdPerspective) { |  | ||||||
|       vsh +=  |       vsh +=  | ||||||
|         "uniform mediump mat4 uRadarTransform;\n" |         "uniform mediump mat4 uRadarTransform;\n" | ||||||
|         "uniform mediump sampler2D tAirMap;\n" |         "uniform mediump sampler2D tAirMap;\n" | ||||||
| @@ -363,8 +363,13 @@ shared_ptr<glhr::GLprogram> write_shader(flagtype shader_flags) { | |||||||
|         "    return texture2D(tAirMap, pt.xy);\n" |         "    return texture2D(tAirMap, pt.xy);\n" | ||||||
|         "    }\n"; |         "    }\n"; | ||||||
|        |        | ||||||
|  |        | ||||||
|  |       if(azi_hyperbolic) vmain +=  | ||||||
|  |         "vec4 ending = uRadarTransform * orig_t;\n"; | ||||||
|  |       else vmain +=  | ||||||
|  |         "vec4 ending = uRadarTransform * t;\n"; | ||||||
|  |  | ||||||
|       vmain +=  |       vmain +=  | ||||||
|         "vec4 ending = uRadarTransform * t;\n" |  | ||||||
|         "float len = acosh(ending.w);\n" |         "float len = acosh(ending.w);\n" | ||||||
|         "float eulen = length(ending.xyz);\n" |         "float eulen = length(ending.xyz);\n" | ||||||
|         "ending.xyz /= eulen;\n" |         "ending.xyz /= eulen;\n" | ||||||
|   | |||||||
							
								
								
									
										26
									
								
								sky.cpp
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								sky.cpp
									
									
									
									
									
								
							| @@ -138,13 +138,8 @@ void compute_skyvertices(const vector<sky_item>& sky) { | |||||||
| void dqi_sky::draw() { | void dqi_sky::draw() { | ||||||
|   if(!vid.usingGL || sky.empty()) return; |   if(!vid.usingGL || sky.empty()) return; | ||||||
|    |    | ||||||
|   if(centerover != sky_centerover) { |   transmatrix s = (vrhr::rendering() ? vrhr::master_cview : cview()).T * inverse(sky_cview.T); | ||||||
|     sky_centerover = centerover; |      | ||||||
|     sky_cview = cview(); |  | ||||||
|     compute_skyvertices(sky); |  | ||||||
|     } |  | ||||||
|   transmatrix s = cview().T * inverse(sky_cview.T); |  | ||||||
|    |  | ||||||
|   for(int ed = current_display->stereo_active() ? -1 : 0; ed<2; ed+=2) { |   for(int ed = current_display->stereo_active() ? -1 : 0; ed<2; ed+=2) { | ||||||
|     if(global_projection && global_projection != ed) continue; |     if(global_projection && global_projection != ed) continue; | ||||||
|     current_display->next_shader_flags = GF_VARCOLOR; |     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))); |       glhr::projection_multiply(glhr::tmtogl(xpush(-vid.ipd * global_projection/2))); | ||||||
|       glapplymatrix(xpush(vid.ipd * global_projection/2) * s); |       glapplymatrix(xpush(vid.ipd * global_projection/2) * s); | ||||||
|       } |       } | ||||||
|     else |     else { | ||||||
|       glapplymatrix(s); |       glapplymatrix(s); | ||||||
|  |       } | ||||||
|     glhr::prepare(skyvertices); |     glhr::prepare(skyvertices); | ||||||
|     glhr::set_fogbase(1.0 + 5 / sightranges[geometry]); |     glhr::set_fogbase(1.0 + 5 / sightranges[geometry]); | ||||||
|     glhr::set_depthtest(model_needs_depth() && prio < PPR::SUPERLINE); |     glhr::set_depthtest(model_needs_depth() && prio < PPR::SUPERLINE); | ||||||
| @@ -382,7 +378,15 @@ EX struct renderbuffer *airbuf; | |||||||
|  |  | ||||||
| EX void make_air() { | EX void make_air() { | ||||||
|   if(!sky) return; |   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; |   const int AIR_TEXTURE = 512; | ||||||
|   if(!airbuf) { |   if(!airbuf) { | ||||||
|     airbuf = new renderbuffer(AIR_TEXTURE, AIR_TEXTURE, true); |     airbuf = new renderbuffer(AIR_TEXTURE, AIR_TEXTURE, true); | ||||||
| @@ -394,6 +398,10 @@ EX void make_air() { | |||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |   #if CAP_VR | ||||||
|  |   dynamicval<int> i(vrhr::state, 0); | ||||||
|  |   #endif | ||||||
|  |  | ||||||
|   if(1) { |   if(1) { | ||||||
|     //shot::take("airtest.png", drawqueue);  |     //shot::take("airtest.png", drawqueue);  | ||||||
|     dynamicval<videopar> v(vid, vid);     |     dynamicval<videopar> v(vid, vid);     | ||||||
|   | |||||||
							
								
								
									
										13
									
								
								vr.cpp
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								vr.cpp
									
									
									
									
									
								
							| @@ -1005,23 +1005,24 @@ EX void gen_mv() { | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | EX shiftmatrix master_cview; | ||||||
|  |  | ||||||
| EX void render() { | EX void render() { | ||||||
|   track_poses();   |   track_poses();   | ||||||
|   resetbuffer rb; |   resetbuffer rb; | ||||||
|   state = 2; |   state = 2; | ||||||
|    |    | ||||||
|   // eyes = lshiftclick ? eEyes::truesim : eEyes::equidistant; |  | ||||||
|    |  | ||||||
|   // cscr = lshiftclick ? eCompScreen::eyes : eCompScreen::single; |   // cscr = lshiftclick ? eCompScreen::eyes : eCompScreen::single; | ||||||
|  |  | ||||||
|   for(int i=0; i<3; i++) { |   for(int i=0; i<3; i++) { | ||||||
|  |  | ||||||
|     if(1) { |     if(1) { | ||||||
|       make_actual_view(); |       make_actual_view(); | ||||||
|       shiftmatrix Tv = cview(); |       master_cview = cview(); | ||||||
|       dynamicval<transmatrix> tN(NLP, NLP); |       dynamicval<transmatrix> tN(NLP, NLP); | ||||||
|       dynamicval<transmatrix> tV(View, View); |       dynamicval<transmatrix> tV(View, View); | ||||||
|       dynamicval<transmatrix> tC(current_display->which_copy, current_display->which_copy); |       dynamicval<transmatrix> tC(current_display->which_copy, current_display->which_copy); | ||||||
|  |       dynamicval<transmatrix> trt(radar_transform); | ||||||
|        |        | ||||||
|       if(hsm == eHeadset::rotation_only) { |       if(hsm == eHeadset::rotation_only) { | ||||||
|         transmatrix T = hmd_at; |         transmatrix T = hmd_at; | ||||||
| @@ -1038,10 +1039,8 @@ EX void render() { | |||||||
|         } |         } | ||||||
|  |  | ||||||
|       make_actual_view(); |       make_actual_view(); | ||||||
|       hmd_pre = hmd_pre_for[i] = cview().T * inverse(Tv.T); |       hmd_pre = hmd_pre_for[i] = cview().T * inverse(master_cview.T); | ||||||
|       // inverse_shift(Tv, cview()); |       radar_transform = trt.backup * inverse(hmd_pre); | ||||||
|       // View * inverse(Tv.T); |  | ||||||
|       // inverse(inverse_shift(cview(), Tv)); |  | ||||||
|        |        | ||||||
|       if(1) { |       if(1) { | ||||||
|         gen_mv(); |         gen_mv(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Zeno Rogue
					Zeno Rogue