1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-09 23:49:53 +00:00

nil raytracer now works correctly with hex nil

This commit is contained in:
Zeno Rogue 2024-06-10 01:34:55 +02:00
parent 86c4f18812
commit e2247eaf15
2 changed files with 58 additions and 11 deletions

View File

@ -878,7 +878,8 @@ void geometry_information::compute_cornerbonus() { }
// Make a wall // Make a wall
hyperpoint ray_kleinize(hyperpoint h, int id, ld pz) { hyperpoint ray_kleinize(hyperpoint h, int id, ld pz) {
if(nil && among(id, 2, 5)) h[2] = 0; if(nil && nilv::nil_structure_index == 0 && among(id, 2, 5)) h[2] = 0;
if(nil && nilv::nil_structure_index == 2 && among(id, 6, 7)) h[2] = 0;
#if CAP_BT #if CAP_BT
if(hyperbolic && bt::in()) { if(hyperbolic && bt::in()) {
// ld co = vid.binary_width / log(2) / 4; // ld co = vid.binary_width / log(2) / 4;

View File

@ -129,7 +129,7 @@ EX bool available() {
return true; return true;
if(sphere && pmodel == mdPerspective && !rotspace) if(sphere && pmodel == mdPerspective && !rotspace)
return true; return true;
if(nil && S7 == 8) if(nil && nilv::nil_structure_index == 1)
return false; return false;
if((sn::in() || nil || sl2) && pmodel == mdGeodesic) if((sn::in() || nil || sl2) && pmodel == mdGeodesic)
return true; return true;
@ -880,15 +880,33 @@ void raygen::move_forward() {
} }
} }
if(nil) fmain += string hnilw = to_glsl(nilv::nilwidth / 2);
"mediump float rz = (abs(nposition.x) > abs(nposition.y) ? -nposition.x*nposition.y : 0.) + nposition.z;\n"; string hnilw2 = to_glsl(nilv::nilwidth * nilv::nilwidth / 2);
string hnilw3 = to_glsl(nilv::nilwidth * nilv::nilwidth * sqrt(3) / 8);
string hsqrt3 = to_glsl(sqrt(3)/2);
if(nil && nilv::nil_structure_index == 0) {
fmain +=
"mediump float rz = (abs(nposition.x) > abs(nposition.y) ? -nposition.x*nposition.y : 0.) + nposition.z;\n";
fmain += "rz += nposition.x * nposition.y * " + comu + ";";
}
if(nil && nilv::nil_structure_index == 2) {
fmain += "mediump float x0 = nposition.x; mediump float y0 = nposition.y;\n";
fmain +=
"mediump float x1 = nposition.x * .5 + nposition.y * " + hsqrt3 + ";\n"
"mediump float y1 = nposition.y * .5 - nposition.x * " + hsqrt3 + ";\n";
fmain +=
"mediump float x2 = nposition.x * .5 - nposition.y * " + hsqrt3 + ";\n"
"mediump float y2 = nposition.y * .5 + nposition.x * " + hsqrt3 + ";\n";
fmain += "mediump float rz =\n"
"((abs(x0) > abs(x1) && abs(x0) > abs(x2)) ? -x0*y0/2. :\n"
"(abs(x1) > abs(x2)) ? -x1*y1/2. : -x2*y2/2.) + nposition.z;\n";
fmain += "rz -= nposition.x * nposition.y * " + to_glsl(nilv::model_used) + ";";
}
fmain += fmain +=
"if(next >= minstep) {\n"; "if(next >= minstep) {\n";
string hnilw = to_glsl(nilv::nilwidth / 2);
string hnilw2 = to_glsl(nilv::nilwidth * nilv::nilwidth / 2);
if(reg) fmain += "if(which != -1) {\n"; if(reg) fmain += "if(which != -1) {\n";
else if(embedded_plane) { else if(embedded_plane) {
string s = sol ? "-2" : ""; string s = sol ? "-2" : "";
@ -918,8 +936,10 @@ void raygen::move_forward() {
"if(abs(nposition.x) > uBinaryWidth || abs(nposition.y) > uBinaryWidth || abs(nposition.z) > .5) {\n"; "if(abs(nposition.x) > uBinaryWidth || abs(nposition.y) > uBinaryWidth || abs(nposition.z) > .5) {\n";
else if(sol) fmain += else if(sol) fmain +=
"if(abs(nposition.x) > uBinaryWidth || abs(nposition.y) > uBinaryWidth || abs(nposition.z) > log(2.)/2.) {\n"; "if(abs(nposition.x) > uBinaryWidth || abs(nposition.y) > uBinaryWidth || abs(nposition.z) > log(2.)/2.) {\n";
else fmain += else if(nil && nilv::nil_structure_index == 0) fmain +=
"if(abs(nposition.x) > "+hnilw+" || abs(nposition.y) > "+hnilw+" || abs(rz) > "+hnilw2+") {\n"; "if(abs(nposition.x) > "+hnilw+" || abs(nposition.y) > "+hnilw+" || abs(rz) > "+hnilw2+") {\n";
else if(nil && nilv::nil_structure_index == 2) fmain +=
"if(abs(nposition.x) > "+hnilw+" || abs(nposition.x/2. + nposition.y*"+hsqrt3+") > "+hnilw+" || abs(nposition.x/2. - nposition.y*"+hsqrt3+") > "+hnilw+" || abs(rz) > "+hnilw3+") {\n";
fmain += fmain +=
"next = dist / 2.; continue;\n" "next = dist / 2.; continue;\n"
@ -969,13 +989,22 @@ void raygen::move_forward() {
"if(nposition.z > log(2.)/2.) which = nposition.x > 0. ? 3 : 2;\n" "if(nposition.z > log(2.)/2.) which = nposition.x > 0. ? 3 : 2;\n"
"if(nposition.z <-log(2.)/2.) which = nposition.y > 0. ? 7 : 6;\n"; "if(nposition.z <-log(2.)/2.) which = nposition.y > 0. ? 7 : 6;\n";
} }
else if(nil) fmain += else if(nil && nilv::nil_structure_index == 0) fmain +=
"if(nposition.x > "+hnilw+") which = 3;\n" "if(nposition.x > "+hnilw+") which = 3;\n"
"if(nposition.x <-"+hnilw+") which = 0;\n" "if(nposition.x <-"+hnilw+") which = 0;\n"
"if(nposition.y > "+hnilw+") which = 4;\n" "if(nposition.y > "+hnilw+") which = 4;\n"
"if(nposition.y <-"+hnilw+") which = 1;\n" "if(nposition.y <-"+hnilw+") which = 1;\n"
"if(rz > "+hnilw2+") which = 5;\n" "if(rz > "+hnilw2+") which = 5;\n"
"if(rz <-"+hnilw2+") which = 2;\n"; "if(rz <-"+hnilw2+") which = 2;\n";
else if(nil && nilv::nil_structure_index == 2) fmain +=
"if(nposition.x > "+hnilw+") which = 0;\n"
"if(nposition.x <-"+hnilw+") which = 3;\n"
"if(nposition.x/2.+nposition.y*"+hsqrt3+" > "+hnilw+") which = 5;\n"
"if(nposition.x/2.+nposition.y*"+hsqrt3+" <-"+hnilw+") which = 2;\n"
"if(nposition.x/2.-nposition.y*"+hsqrt3+" > "+hnilw+") which = 1;\n"
"if(nposition.x/2.-nposition.y*"+hsqrt3+" <-"+hnilw+") which = 4;\n"
"if(rz > "+hnilw3+") which = 7;\n"
"if(rz <-"+hnilw3+") which = 6;\n";
fmain += fmain +=
"next = maxstep;\n" "next = maxstep;\n"
@ -1378,7 +1407,8 @@ void raygen::emit_iterate(int gid1) {
if(!(levellines && disable_texture)) { if(!(levellines && disable_texture)) {
fmain += " mediump vec4 pos = position;\n"; fmain += " mediump vec4 pos = position;\n";
if(nil) fmain += "if(which == 2 || which == 5) pos.z = 0.;\n"; if(nil && nilv::nil_structure_index == 0) fmain += "if(which == 2 || which == 5) pos.z = 0.;\n";
if(nil && nilv::nil_structure_index == 2) fmain += "if(which == 6 || which == 7) pos.z = 0.;\n";
else if(hyperbolic && bt::in()) fmain += else if(hyperbolic && bt::in()) fmain +=
"pos = deparabolici13(pos);\n" "pos = deparabolici13(pos);\n"
"pos.xyz = pos.zxy;\n"; "pos.xyz = pos.zxy;\n";
@ -1410,9 +1440,25 @@ void raygen::emit_iterate(int gid1) {
if(!volumetric::on) fmain += if(!volumetric::on) fmain +=
" col.xyz = col.xyz * d + uFogColor.xyz * (1.-d);\n"; " col.xyz = col.xyz * d + uFogColor.xyz * (1.-d);\n";
if(nil) fmain += if(nil && nilv::nil_structure_index == 0) fmain +=
" if(abs(abs(position.x)-abs(position.y)) < .005) col.xyz /= 2.;\n"; " if(abs(abs(position.x)-abs(position.y)) < .005) col.xyz /= 2.;\n";
if(nil && nilv::nil_structure_index == 2) {
string hsqrt3 = to_glsl(sqrt(3)/2);
fmain += "mediump float x0 = position.x; mediump float y0 = position.y;\n";
fmain +=
"mediump float x1 = position.x * .5 + position.y * " + hsqrt3 + ";\n";
fmain +=
"mediump float x2 = position.x * .5 - position.y * " + hsqrt3 + ";\n";
fmain +=
" if(abs(abs(x0)-abs(x1)) < .005 && abs(x0) > abs(x2)) col.xyz /= 2.;\n";
fmain +=
" if(abs(abs(x0)-abs(x2)) < .005 && abs(x0) > abs(x1)) col.xyz /= 2.;\n";
fmain +=
" if(abs(abs(x1)-abs(x2)) < .005 && abs(x1) > abs(x0)) col.xyz /= 2.;\n";
}
if(use_reflect) fmain += if(use_reflect) fmain +=
" if(col.w == 1.) {\n" " if(col.w == 1.) {\n"
" col.w = " + to_glsl(1-reflect_val)+";\n" " col.w = " + to_glsl(1-reflect_val)+";\n"