mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-01-22 23:17:04 +00:00
various changes and fixes to make coolfog and sky work correctly in VR
This commit is contained in:
parent
9f5591249a
commit
56485f20a9
@ -343,10 +343,6 @@ EX void setGLProjection(color_t col IS(backcolor)) {
|
||||
glClearColor(part(col, 2) / 255.0, part(col, 1) / 255.0, part(col, 0) / 255.0, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
#if CAP_VR
|
||||
vrhr::clear();
|
||||
#endif
|
||||
|
||||
GLERR("setGLProjection #1");
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
|
@ -2178,11 +2178,6 @@ void dqi_line::draw_back() {
|
||||
}
|
||||
|
||||
EX void sort_drawqueue() {
|
||||
|
||||
#if MAXMDIM >= 4 && CAP_GL
|
||||
if(WDIM == 2 && GDIM == 3 && hyperbolic) make_air();
|
||||
#endif
|
||||
|
||||
DEBBI(DF_GRAPH, ("sort_drawqueue"));
|
||||
|
||||
for(int a=0; a<PMAX; a++) qp[a] = 0;
|
||||
@ -2387,6 +2382,10 @@ EX void drawqueue() {
|
||||
#if CAP_WRL
|
||||
if(wrl::in) { wrl::render(); return; }
|
||||
#endif
|
||||
|
||||
#if MAXMDIM >= 4 && CAP_GL
|
||||
if(WDIM == 2 && GDIM == 3 && hyperbolic && !vrhr::rendering()) make_air();
|
||||
#endif
|
||||
|
||||
#if CAP_VR
|
||||
if(vrhr::should_render() == 1) {
|
||||
|
@ -5193,6 +5193,11 @@ EX void drawscreen() {
|
||||
#if CAP_GL
|
||||
if(vid.usingGL) setGLProjection();
|
||||
#endif
|
||||
|
||||
#if CAP_VR
|
||||
vrhr::clear();
|
||||
#endif
|
||||
|
||||
|
||||
#if CAP_SDL
|
||||
// SDL_LockSurface(s);
|
||||
|
19
shaders.cpp
19
shaders.cpp
@ -132,6 +132,8 @@ shared_ptr<glhr::GLprogram> write_shader(flagtype shader_flags) {
|
||||
|
||||
bool skip_t = false;
|
||||
|
||||
bool azi_hyperbolic = false;
|
||||
|
||||
if(vid.stereo_mode == sODS) {
|
||||
shader_flags |= SF_DIRECT | SF_ODSBOX;
|
||||
vmain += "// this is ODS shader\n";
|
||||
@ -304,6 +306,8 @@ shared_ptr<glhr::GLprogram> write_shader(flagtype shader_flags) {
|
||||
shader_flags |= SF_PERS3 | SF_DIRECT;
|
||||
#if CAP_VR
|
||||
if(vrhr::rendering() && hyperbolic && vrhr::eyes != vrhr::eEyes::truesim) {
|
||||
azi_hyperbolic = true;
|
||||
coordinator += "mediump vec4 orig_t = t;\n";
|
||||
coordinator +=
|
||||
"t = t * acosh(t[3]) / length(t.xyz);\n"
|
||||
"t[3] = 1.;\n";
|
||||
@ -312,7 +316,7 @@ shared_ptr<glhr::GLprogram> write_shader(flagtype shader_flags) {
|
||||
else
|
||||
#endif
|
||||
if(hyperbolic)
|
||||
distfun = "acosh(t[3])", treset = true;
|
||||
distfun = "acosh(t[3])";
|
||||
else if(euclid || nonisotropic || stretch::in() || (sphere && ray::in_use))
|
||||
distfun = "length(t.xyz)", treset = true;
|
||||
else {
|
||||
@ -345,11 +349,7 @@ shared_ptr<glhr::GLprogram> write_shader(flagtype shader_flags) {
|
||||
if(!skip_t) {
|
||||
vmain += "mediump vec4 t = uMV * aPosition;\n";
|
||||
vmain += coordinator;
|
||||
bool ok = true;
|
||||
#if CAP_VR
|
||||
if(vrhr::active()) ok = false;
|
||||
#endif
|
||||
if(GDIM == 3 && WDIM == 2 && hyperbolic && context_fog && ok && pmodel == mdPerspective) {
|
||||
if(GDIM == 3 && WDIM == 2 && hyperbolic && context_fog && pmodel == mdPerspective) {
|
||||
vsh +=
|
||||
"uniform mediump mat4 uRadarTransform;\n"
|
||||
"uniform mediump sampler2D tAirMap;\n"
|
||||
@ -363,8 +363,13 @@ shared_ptr<glhr::GLprogram> write_shader(flagtype shader_flags) {
|
||||
" return texture2D(tAirMap, pt.xy);\n"
|
||||
" }\n";
|
||||
|
||||
|
||||
if(azi_hyperbolic) vmain +=
|
||||
"vec4 ending = uRadarTransform * orig_t;\n";
|
||||
else vmain +=
|
||||
"vec4 ending = uRadarTransform * t;\n";
|
||||
|
||||
vmain +=
|
||||
"vec4 ending = uRadarTransform * t;\n"
|
||||
"float len = acosh(ending.w);\n"
|
||||
"float eulen = length(ending.xyz);\n"
|
||||
"ending.xyz /= eulen;\n"
|
||||
|
26
sky.cpp
26
sky.cpp
@ -138,13 +138,8 @@ void compute_skyvertices(const vector<sky_item>& sky) {
|
||||
void dqi_sky::draw() {
|
||||
if(!vid.usingGL || sky.empty()) return;
|
||||
|
||||
if(centerover != sky_centerover) {
|
||||
sky_centerover = centerover;
|
||||
sky_cview = cview();
|
||||
compute_skyvertices(sky);
|
||||
}
|
||||
transmatrix s = cview().T * inverse(sky_cview.T);
|
||||
|
||||
transmatrix s = (vrhr::rendering() ? vrhr::master_cview : cview()).T * inverse(sky_cview.T);
|
||||
|
||||
for(int ed = current_display->stereo_active() ? -1 : 0; ed<2; ed+=2) {
|
||||
if(global_projection && global_projection != ed) continue;
|
||||
current_display->next_shader_flags = GF_VARCOLOR;
|
||||
@ -153,8 +148,9 @@ void dqi_sky::draw() {
|
||||
glhr::projection_multiply(glhr::tmtogl(xpush(-vid.ipd * global_projection/2)));
|
||||
glapplymatrix(xpush(vid.ipd * global_projection/2) * s);
|
||||
}
|
||||
else
|
||||
else {
|
||||
glapplymatrix(s);
|
||||
}
|
||||
glhr::prepare(skyvertices);
|
||||
glhr::set_fogbase(1.0 + 5 / sightranges[geometry]);
|
||||
glhr::set_depthtest(model_needs_depth() && prio < PPR::SUPERLINE);
|
||||
@ -382,7 +378,15 @@ EX struct renderbuffer *airbuf;
|
||||
|
||||
EX void make_air() {
|
||||
if(!sky) return;
|
||||
if(vrhr::active()) return;
|
||||
|
||||
if(centerover != sky_centerover) {
|
||||
sky_centerover = centerover;
|
||||
sky_cview = cview();
|
||||
compute_skyvertices(sky->sky);
|
||||
}
|
||||
|
||||
if(!context_fog) return;
|
||||
|
||||
const int AIR_TEXTURE = 512;
|
||||
if(!airbuf) {
|
||||
airbuf = new renderbuffer(AIR_TEXTURE, AIR_TEXTURE, true);
|
||||
@ -394,6 +398,10 @@ EX void make_air() {
|
||||
}
|
||||
}
|
||||
|
||||
#if CAP_VR
|
||||
dynamicval<int> i(vrhr::state, 0);
|
||||
#endif
|
||||
|
||||
if(1) {
|
||||
//shot::take("airtest.png", drawqueue);
|
||||
dynamicval<videopar> v(vid, vid);
|
||||
|
13
vr.cpp
13
vr.cpp
@ -1005,23 +1005,24 @@ EX void gen_mv() {
|
||||
}
|
||||
}
|
||||
|
||||
EX shiftmatrix master_cview;
|
||||
|
||||
EX void render() {
|
||||
track_poses();
|
||||
resetbuffer rb;
|
||||
state = 2;
|
||||
|
||||
// eyes = lshiftclick ? eEyes::truesim : eEyes::equidistant;
|
||||
|
||||
// cscr = lshiftclick ? eCompScreen::eyes : eCompScreen::single;
|
||||
|
||||
for(int i=0; i<3; i++) {
|
||||
|
||||
if(1) {
|
||||
make_actual_view();
|
||||
shiftmatrix Tv = cview();
|
||||
master_cview = cview();
|
||||
dynamicval<transmatrix> tN(NLP, NLP);
|
||||
dynamicval<transmatrix> tV(View, View);
|
||||
dynamicval<transmatrix> tC(current_display->which_copy, current_display->which_copy);
|
||||
dynamicval<transmatrix> trt(radar_transform);
|
||||
|
||||
if(hsm == eHeadset::rotation_only) {
|
||||
transmatrix T = hmd_at;
|
||||
@ -1038,10 +1039,8 @@ EX void render() {
|
||||
}
|
||||
|
||||
make_actual_view();
|
||||
hmd_pre = hmd_pre_for[i] = cview().T * inverse(Tv.T);
|
||||
// inverse_shift(Tv, cview());
|
||||
// View * inverse(Tv.T);
|
||||
// inverse(inverse_shift(cview(), Tv));
|
||||
hmd_pre = hmd_pre_for[i] = cview().T * inverse(master_cview.T);
|
||||
radar_transform = trt.backup * inverse(hmd_pre);
|
||||
|
||||
if(1) {
|
||||
gen_mv();
|
||||
|
Loading…
Reference in New Issue
Block a user