mirror of
				https://github.com/zenorogue/hyperrogue.git
				synced 2025-10-26 03:17:39 +00:00 
			
		
		
		
	semidirect rendering
This commit is contained in:
		
							
								
								
									
										10
									
								
								drawing.cpp
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								drawing.cpp
									
									
									
									
									
								
							| @@ -509,7 +509,15 @@ void addpoly(const shiftmatrix& V, const vector<glvertex> &tab, int ofs, int cnt | |||||||
|     } |     } | ||||||
|   tofix.clear(); knowgood = false; |   tofix.clear(); knowgood = false; | ||||||
|   if(in_perspective()) { |   if(in_perspective()) { | ||||||
|     if(poly_flags & POLY_TRIANGLES) { |     if(get_shader_flags() & SF_SEMIDIRECT) { | ||||||
|  |       dynamicval<bool> d(computing_semidirect, true); | ||||||
|  |       for(int i=ofs; i<ofs+cnt; i++) { | ||||||
|  |         hyperpoint Hscr; | ||||||
|  |         applymodel(V * glhr::gltopoint(tab[i]), Hscr); | ||||||
|  |         add1(Hscr); | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     else if(poly_flags & POLY_TRIANGLES) { | ||||||
|       for(int i=ofs; i<ofs+cnt; i+=3) { |       for(int i=ofs; i<ofs+cnt; i+=3) { | ||||||
|         shiftpoint h0 = V * glhr::gltopoint(tab[i]); |         shiftpoint h0 = V * glhr::gltopoint(tab[i]); | ||||||
|         shiftpoint h1 = V * glhr::gltopoint(tab[i+1]); |         shiftpoint h1 = V * glhr::gltopoint(tab[i+1]); | ||||||
|   | |||||||
							
								
								
									
										16
									
								
								hypgraph.cpp
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								hypgraph.cpp
									
									
									
									
									
								
							| @@ -378,7 +378,14 @@ EX ld signed_sqrt(ld x) { return x > 0 ? sqrt(x) : -sqrt(-x); } | |||||||
|  |  | ||||||
| EX int axial_x, axial_y; | EX int axial_x, axial_y; | ||||||
|  |  | ||||||
|  | /** in perspective projections, compute inverse_exp (or similar) on CPU, but perspective on GPU (needs consider_shader_projection off) */ | ||||||
|  | EX bool semidirect_rendering = false; | ||||||
|  |  | ||||||
|  | /** flag for semidirect_rendering */ | ||||||
|  | EX bool computing_semidirect = false; | ||||||
|  |  | ||||||
| EX void apply_perspective(const hyperpoint& H, hyperpoint& ret) { | EX void apply_perspective(const hyperpoint& H, hyperpoint& ret) { | ||||||
|  |   if(computing_semidirect) { ret = H; ret[3] = 1; return; } | ||||||
|   if(H[2] == 0) { ret[0] = 1e6; ret[1] = 1e6; ret[2] = 0; return; } |   if(H[2] == 0) { ret[0] = 1e6; ret[1] = 1e6; ret[2] = 0; return; } | ||||||
|   ld ratio = vid.xres / current_display->tanfov / current_display->radius / 2; |   ld ratio = vid.xres / current_display->tanfov / current_display->radius / 2; | ||||||
|   ret[0] = H[0]/H[2] * ratio; |   ret[0] = H[0]/H[2] * ratio; | ||||||
| @@ -620,13 +627,14 @@ EX void apply_other_model(shiftpoint H_orig, hyperpoint& ret, eModel md) { | |||||||
|     case mdPerspective: { |     case mdPerspective: { | ||||||
|       if(gproduct) H = product::inverse_exp(H); |       if(gproduct) H = product::inverse_exp(H); | ||||||
|       apply_nil_rotation(H); |       apply_nil_rotation(H); | ||||||
|       H = lp_apply(H); |       if(!computing_semidirect) H = lp_apply(H); | ||||||
|       apply_perspective(H, ret); |       apply_perspective(H, ret); | ||||||
|       return;       |       return;       | ||||||
|       } |       } | ||||||
|  |  | ||||||
|     case mdGeodesic: { |     case mdGeodesic: { | ||||||
|       auto S = lp_apply(inverse_exp(H_orig, pNORMAL | pfNO_DISTANCE)); |       auto S = inverse_exp(H_orig, pNORMAL | pfNO_DISTANCE); | ||||||
|  |       if(!computing_semidirect) S = lp_apply(S); | ||||||
|       apply_perspective(S, ret); |       apply_perspective(S, ret); | ||||||
|       return; |       return; | ||||||
|       } |       } | ||||||
| @@ -645,7 +653,7 @@ EX void apply_other_model(shiftpoint H_orig, hyperpoint& ret, eModel md) { | |||||||
|       #if MAXMDIM >= 4 |       #if MAXMDIM >= 4 | ||||||
|       S[3] = 1; |       S[3] = 1; | ||||||
|       #endif |       #endif | ||||||
|       S = lp_apply(S); |       if(!computing_semidirect) S = lp_apply(S); | ||||||
|       if(hyperbolic) { |       if(hyperbolic) { | ||||||
|         models::apply_orientation(ret[1], ret[0]); |         models::apply_orientation(ret[1], ret[0]); | ||||||
|         models::apply_orientation_yz(ret[2], ret[1]); |         models::apply_orientation_yz(ret[2], ret[1]); | ||||||
| @@ -657,7 +665,7 @@ EX void apply_other_model(shiftpoint H_orig, hyperpoint& ret, eModel md) { | |||||||
|     #if MAXMDIM >= 4 |     #if MAXMDIM >= 4 | ||||||
|     case mdRelPerspective: { |     case mdRelPerspective: { | ||||||
|       auto S = rel_log(H_orig, true); S[3] = 1; |       auto S = rel_log(H_orig, true); S[3] = 1; | ||||||
|       S = lp_apply(S); |       if(!computing_semidirect) S = lp_apply(S); | ||||||
|       apply_perspective(S, ret); |       apply_perspective(S, ret); | ||||||
|       return; |       return; | ||||||
|       } |       } | ||||||
|   | |||||||
| @@ -32,6 +32,8 @@ constexpr flagtype SF_ORIENT       = 16384; | |||||||
| constexpr flagtype SF_BOX          = 32768; | constexpr flagtype SF_BOX          = 32768; | ||||||
| constexpr flagtype SF_ZFOG         = 65536; | constexpr flagtype SF_ZFOG         = 65536; | ||||||
| constexpr flagtype SF_ODSBOX       = (1<<17); | constexpr flagtype SF_ODSBOX       = (1<<17); | ||||||
|  |  | ||||||
|  | constexpr flagtype SF_SEMIDIRECT   = (1<<18); | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| EX bool solv_all; | EX bool solv_all; | ||||||
| @@ -236,6 +238,11 @@ shared_ptr<glhr::GLprogram> write_shader(flagtype shader_flags) { | |||||||
|     skip_t = true; |     skip_t = true; | ||||||
|     shader_flags |= SF_DIRECT; |     shader_flags |= SF_DIRECT; | ||||||
|     } |     } | ||||||
|  |   else if(!vid.consider_shader_projection && semidirect_rendering && models::is_perspective(pmodel)) { | ||||||
|  |     vmain += "// this\n"; | ||||||
|  |     distfun = "length(t.xyz)"; | ||||||
|  |     shader_flags |= SF_PERS3 | SF_SEMIDIRECT; | ||||||
|  |     } | ||||||
|   else if(!vid.consider_shader_projection) { |   else if(!vid.consider_shader_projection) { | ||||||
|     shader_flags |= SF_PIXELS; |     shader_flags |= SF_PIXELS; | ||||||
|     }         |     }         | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Zeno Rogue
					Zeno Rogue