mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2024-12-25 01:20:37 +00:00
semidirect rendering
This commit is contained in:
parent
2e1e14c1a2
commit
e6738f6c20
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;
|
||||
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) {
|
||||
shiftpoint h0 = V * glhr::gltopoint(tab[i]);
|
||||
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;
|
||||
|
||||
/** 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) {
|
||||
if(computing_semidirect) { ret = H; ret[3] = 1; 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;
|
||||
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: {
|
||||
if(gproduct) H = product::inverse_exp(H);
|
||||
apply_nil_rotation(H);
|
||||
H = lp_apply(H);
|
||||
if(!computing_semidirect) H = lp_apply(H);
|
||||
apply_perspective(H, ret);
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
return;
|
||||
}
|
||||
@ -645,7 +653,7 @@ EX void apply_other_model(shiftpoint H_orig, hyperpoint& ret, eModel md) {
|
||||
#if MAXMDIM >= 4
|
||||
S[3] = 1;
|
||||
#endif
|
||||
S = lp_apply(S);
|
||||
if(!computing_semidirect) S = lp_apply(S);
|
||||
if(hyperbolic) {
|
||||
models::apply_orientation(ret[1], ret[0]);
|
||||
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
|
||||
case mdRelPerspective: {
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
@ -32,6 +32,8 @@ constexpr flagtype SF_ORIENT = 16384;
|
||||
constexpr flagtype SF_BOX = 32768;
|
||||
constexpr flagtype SF_ZFOG = 65536;
|
||||
constexpr flagtype SF_ODSBOX = (1<<17);
|
||||
|
||||
constexpr flagtype SF_SEMIDIRECT = (1<<18);
|
||||
#endif
|
||||
|
||||
EX bool solv_all;
|
||||
@ -236,6 +238,11 @@ shared_ptr<glhr::GLprogram> write_shader(flagtype shader_flags) {
|
||||
skip_t = true;
|
||||
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) {
|
||||
shader_flags |= SF_PIXELS;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user