From 0ea37718f0a9003cb576d0383d7071757e0eab35 Mon Sep 17 00:00:00 2001 From: ? Date: Fri, 22 Feb 2019 21:01:01 +0100 Subject: [PATCH] shaderside projection for DIM==3 --- basegraph.cpp | 10 ++++++++-- hyper.h | 2 +- polygons.cpp | 11 +++++++---- shaders.cpp | 13 +++++++++++-- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/basegraph.cpp b/basegraph.cpp index 75af207c..e629999e 100644 --- a/basegraph.cpp +++ b/basegraph.cpp @@ -212,19 +212,21 @@ void display_data::set_projection(int ed, bool apply_models) { shaderside_projection = false; glhr::new_shader_projection = glhr::shader_projection::standard; if(vid.consider_shader_projection) { - if(pmodel == mdDisk && !spherespecial && !(hyperbolic && vid.alpha <= -1)) + if(pmodel == mdDisk && !spherespecial && !(hyperbolic && vid.alpha <= -1) && DIM == 2) shaderside_projection = true; if(pmodel == mdBand && hyperbolic && apply_models) shaderside_projection = true, glhr::new_shader_projection = glhr::shader_projection::band; if(pmodel == mdHalfplane && hyperbolic && apply_models) shaderside_projection = true, glhr::new_shader_projection = glhr::shader_projection::halfplane; + if(DIM == 3) + shaderside_projection = true, glhr::new_shader_projection = glhr::shader_projection::standard3; } start_projection(ed, shaderside_projection); auto cd = current_display; - if(!shaderside_projection) { + if(!shaderside_projection && DIM != 3) { glhr::projection_multiply(glhr::ortho(cd->xsize/2, -cd->ysize/2, abs(current_display->scrdist) + 30000)); if(ed) { glhr::glmatrix m = glhr::id; @@ -255,6 +257,10 @@ void display_data::set_projection(int ed, bool apply_models) { if(ed) glhr::projection_multiply(glhr::translate(vid.ipd * ed/2, 0, 0)); current_display->scrdist_text = cd->ysize * sc / 2; + + if(glhr::new_shader_projection == glhr::shader_projection::standard3) { + glhr::fog_max(1/binary::btrange); + } if(glhr::new_shader_projection == glhr::shader_projection::band) { glhr::projection_multiply(model_orientation_gl()); diff --git a/hyper.h b/hyper.h index d30ec9fb..b470647c 100644 --- a/hyper.h +++ b/hyper.h @@ -3797,7 +3797,7 @@ namespace glhr { const GLfloat* as_array() const { return a[0]; } }; - enum class shader_projection { standard, band, halfplane, MAX }; + enum class shader_projection { standard, band, halfplane, standard3, MAX }; extern shader_projection new_shader_projection; diff --git a/polygons.cpp b/polygons.cpp index 7733e6b5..4e682531 100644 --- a/polygons.cpp +++ b/polygons.cpp @@ -490,11 +490,15 @@ vector line_vertices; #endif void glapplymatrix(const transmatrix& V) { - #if DIM == 3 - glhr::set_modelview(glhr::id); - #else GLfloat mat[16]; int id = 0; + if(DIM == 3) { + for(int y=0; y<4; y++) { + for(int x=0; x<4; x++) mat[id++] = V[x][y]; + } + glhr::set_modelview(glhr::as_glmatrix(mat)); + return; + } for(int y=0; y<3; y++) { for(int x=0; x<3; x++) mat[id++] = V[x][y]; @@ -512,7 +516,6 @@ void glapplymatrix(const transmatrix& V) { conformal::apply_orientation(mat[a*4], mat[a*4+1]); glhr::set_modelview(glhr::as_glmatrix(mat)); - #endif } void dqi_poly::gldraw() { diff --git a/shaders.cpp b/shaders.cpp index 5085b549..32a3fa8e 100644 --- a/shaders.cpp +++ b/shaders.cpp @@ -491,6 +491,7 @@ void init() { bool mps = j != 0; bool band = (sp == shader_projection::band); bool hp = (sp == shader_projection::halfplane); + bool s3 = (sp == shader_projection::standard3); programs[i][j] = new GLprogram(stringbuilder( @@ -521,9 +522,13 @@ void init() { 1, " }", 1, "float asinh(float x) {", - 1, " return log(sqrt(1.0 + x*x) + x);", + 1, " return log(sqrt(x*x + 1.0) + x);", 1, " }", - + + 1, "float acosh(float x) {", + 1, " return log(sqrt(x*x - 1.0) + x);", + 1, " }", + 1, "float zlevel(vec4 h) {", 1, " return (h[2] < 0.0 ? -1.0 : 1.0) * sqrt(h[2]*h[2] - h[0]*h[0] - h[1]*h[1]);", 1, " }", @@ -549,6 +554,10 @@ void init() { hp, "float rads = t.x * t.x + t.y * t.y; ", hp, "t.x /= -rads; t.y /= -rads; t.z = 1.0; t[3] = 1.0;", + s3, "vec4 t = uMV * aPosition;", + s3, "vColor.xyz = vColor.xyz * (1.0 - acosh(t[3]) / uFog);", + s3, "t[3] = 1.0;", + band || hp,"gl_Position = uP * t;", 1, "}"),