shaderside projection for DIM==3

This commit is contained in:
? 2019-02-22 21:01:01 +01:00 committed by Zeno Rogue
parent 56d628d4d8
commit 0ea37718f0
4 changed files with 27 additions and 9 deletions

View File

@ -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());

View File

@ -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;

View File

@ -490,11 +490,15 @@ vector<glvertex> 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() {

View File

@ -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, "}"),