Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need portal rendering support #5

Closed
jbaicoianu opened this issue Apr 1, 2016 · 7 comments
Closed

Need portal rendering support #5

jbaicoianu opened this issue Apr 1, 2016 · 7 comments

Comments

@jbaicoianu
Copy link
Owner

Portals currently act like hrefs on the web, click to visit. They should act like portals in JanusVR, where clicking a portal opens the new room and lets you walk back and forth between them.

@jbaicoianu
Copy link
Owner Author

Some progress - render to texture is working but need to figure out proper projection mapping

@jbaicoianu
Copy link
Owner Author

Good reference for portal culling: http://tower22.blogspot.com/2011/07/x-ray.html

@marciot
Copy link

marciot commented Jan 14, 2017

Interesting. So you are rendering to a texture in 3D space?

My first inclination would have been to render both 3D scenes to an off-screen buffer, from the identical point of view in each, with the portal done using a flat color. Then as a post-processing step, do a chromakey to blend the second framebuffer into the first only for the pixels corresponding to the portal.

I've never done this in WebGL, mind you, so it could well be impossible, but if it were possible, it would seem way easier than doing the texturing in 3D space.

-- Marcio

@jbaicoianu
Copy link
Owner Author

My first attempt used that approach yes, but it turned out to not look very good, projecting a 3d world onto a 2d plane in a 3d world is the equivalent of watching a 3d game on a 2d screen - it's not really 3d anymore.

The approach we've had the most success with is a stencil-based approach, where you draw your main scene and then use the stencil buffer to render the visible portals on top of your existing scene, with some additional work to ensure proper depth buffer handling between worlds. This allows you to maintain perspective when looking through portals, rather than feeling like you're looking at a TV - and it works for both eyes in VR mode, so you get full stereoscopic depth across portals.

@marciot
Copy link

marciot commented Jan 14, 2017

If I understand you correctly, the stencil based approach may be effectively the same as the chroma-key approach I am suggesting? Let me clarify: I would render the primary scene (scene A) twice, once for each eye, into two 2D framebuffers. Then I would render the scene on the other side of the portal (scene B) twice, once for each eye, into 2D framebuffers.

Now, in a post processing step, I would take both left eye framebuffers, take only the pixels corresponding to the portal in scene A and replace them with the pixels from scene B. I would do the same for the two framebuffers corresponding to the right eye to complete the stereo effect.

Is this what you are doing? I am vaguely familiar with the term stencil as it is used in WebGL, but I do not know the specifics of it. Chroma-key is a term from the cinematography world.

-- Marcio

@jbaicoianu
Copy link
Owner Author

It's effectively the same, but instead of using a specific color to indicate areas you want to replace, you just supply a mask which lets you render only to a specific area. This mask can be created by projecting any geometry, so you can use any shape where you want the other world to show through. So the mask is basically the same as your chromakey index, but we don't have to do an extra pass to blend the two scenes - using the stencil is more efficient because it lets the GPU discard any fragments which lie outside of the stencil, and we just render those parts on top of the old scene, so there's no additional image blending step.

@jbaicoianu
Copy link
Owner Author

Implemented in dev, will go out with next release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants