1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-12-24 17:10:36 +00:00

ray:: set depth to match primitive-based shader

This commit is contained in:
Zeno Rogue 2019-10-26 14:11:44 +02:00
parent 852c45e429
commit 3c4fe13fac
2 changed files with 34 additions and 4 deletions

View File

@ -180,7 +180,12 @@ EX glmatrix& as_glmatrix(GLfloat o[16]) {
return tmp;
}
EX glmatrix frustum(ld x, ld y, ld vnear IS(1e-3), ld vfar IS(1e9)) {
#if HDR
constexpr ld vnear_default = 1e-3;
constexpr ld vfar_default = 1e9;
#endif
EX glmatrix frustum(ld x, ld y, ld vnear IS(vnear_default), ld vfar IS(vfar_default)) {
GLfloat frustum[16] = {
GLfloat(1 / x), 0, 0, 0,
0, GLfloat(1 / y), 0, 0,

View File

@ -418,9 +418,28 @@ void enable_raycaster() {
" reflect = true;\n"
" }\n";
ld vnear = glhr::vnear_default;
ld vfar = glhr::vfar_default;
fmain +=
" gl_FragColor.xyz += left * col.xyz * col.w;\n"
" if(col.w == 1.) return;\n"
" if(col.w == 1.) {\n";
if(hyperbolic) fmain +=
" float z = at0.z * sinh(go);\n"
" float w = 1.;\n";
else fmain +=
" float z = at0.z * go;\n"
" float w = 1.;\n";
fmain +=
" gl_FragDepth = (-float("+fts(vnear+vfar)+")+w*float("+fts(2*vnear*vfar)+")/z)/float("+fts(vnear-vfar)+");\n"
" gl_FragDepth = (gl_FragDepth + 1.) / 2.;\n"
// " gl_FragColor.r = gl_FragDepth * gl_FragDepth;\n"
// " gl_FragColor.g = gl_FragDepth * gl_FragDepth;\n"
// " gl_FragColor.b = gl_FragDepth * gl_FragDepth;\n"
" return;\n"
" }\n"
" left *= (1. - col.w);\n"
" }\n";
@ -440,7 +459,8 @@ void enable_raycaster() {
" }\n";
fmain +=
" }"
" }\n"
" gl_FragDepth = 1.;\n"
" }";
fsh += fmain;
@ -629,7 +649,12 @@ EX void cast() {
bind_array(texturemap, o->tTextureMap, txTextureMap, 5);
glVertexAttribPointer(hr::aPosition, 4, GL_FLOAT, GL_FALSE, sizeof(glvertex), &screen[0]);
if(ray::comparison_mode)
glhr::set_depthtest(false);
else {
glhr::set_depthtest(true);
glhr::set_depthwrite(true);
}
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glActiveTexture(GL_TEXTURE0 + 0);