tag:blogger.com,1999:blog-1791631495483462759.post3048770790460683793..comments2024-03-25T07:29:21.225-07:00Comments on 3DWorld: Building Mirror ReflectionsFrank Gennarihttp://www.blogger.com/profile/02815853731800103017noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-1791631495483462759.post-58973351939251144842020-11-05T11:39:25.899-08:002020-11-05T11:39:25.899-08:00When I wrote "The rendering pipeline is much ...When I wrote "The rendering pipeline is much simpler [for portals] though," I didn't really mean the rendering pipeline. There are two things that are simpler for game mode and portals. #1, all of the objects and geometry is generated at scene load time rather than dynamically, so you don't need to worry about on-the-fly procedural content generation in the middle of the rendering.<br /><br />#2, the number of total objects in game mode is small enough that you can simply iterate over a big flat list to determine what to draw. In tiled terrain mode there are far too many objects to do this. Instead there's some nesting such as for each city => for each tile in that city => for each building => for each floor => for each room. So the scene graph traversal is much more complex, and expensive to perform multiple times per frame.Frank Gennarihttps://www.blogger.com/profile/02815853731800103017noreply@blogger.comtag:blogger.com,1999:blog-1791631495483462759.post-37517269120344594912020-11-05T11:27:55.580-08:002020-11-05T11:27:55.580-08:00I guess it's similar to how you wouldn't n...I guess it's similar to how you wouldn't necessarily use the same engine for an arena-like indoor FPS vs. a large open world exploration game.<br /><br />The indoor building lighting does work the same though. I simply create a finite bounds some distance around the camera and "clip that out" to put into the game mode flow that expects a small limited area.Frank Gennarihttps://www.blogger.com/profile/02815853731800103017noreply@blogger.comtag:blogger.com,1999:blog-1791631495483462759.post-59358859195529123912020-11-05T11:23:59.819-08:002020-11-05T11:23:59.819-08:00It's not interior vs. exterior. It's game ...It's not interior vs. exterior. It's game mode vs. tiled terrain mode. Cities/buildings are all placed in my infinite tiled terrain system. These are static objects with no physics/interactivity where the data is all sent to the GPU once and stored there. This is very scalable.<br /><br />Gameplay mode is for smaller limited bounds scenes. Since everything is generally physics enabled and destructible, it's mostly stored on the CPU side and the geometry is streamed to the GPU each frame. All of the objects are also kept in bounding volume hierarchies and sorted for back to front drawing to handle transparency.<br /><br />They're completely different systems. They use the same vertex/shader/framebuffer rendering system, but everything above that level is different. I'm not sure how it would be possible to unify them as their goals are very different. Right now the only code shared between teleporters/portals and building mirrors is the render-to-texture, matrix math, view frustum, screen space clipping, shaders, etc. The rest is different, including the higher level scene management, material system, and object batching.Frank Gennarihttps://www.blogger.com/profile/02815853731800103017noreply@blogger.comtag:blogger.com,1999:blog-1791631495483462759.post-91382791177589542962020-11-05T10:57:20.985-08:002020-11-05T10:57:20.985-08:00Huh. Seems like unifying your interior and exterio...Huh. Seems like unifying your interior and exterior rendering code is the next big refactor. Then you could make every mirror a portal into the mirror world!Paul Spoonerhttps://www.blogger.com/profile/17640871289041630907noreply@blogger.comtag:blogger.com,1999:blog-1791631495483462759.post-65075194039165707132020-11-05T10:20:28.446-08:002020-11-05T10:20:28.446-08:00Mirrors are already rendered to textures, but they...Mirrors are already rendered to textures, but they're done before the main draw pass to avoid lag. I don't think it would help to defer them to the next frame. Draw time is mostly limited by fragment shader processing of all the light sources. The current flow clips the drawn area to the screen space of the mirror so that it can be done at full resolution but only for visible reflected pixels. I later added occlusion culling of models, and that helped a lot, so mirrors are almost free in terms of frame time now.<br /><br />I you mean caching across multiple frames, that doesn't work. I already tried it. The parallax effect is wrong and the player model won't show up properly. Or are you talking about caching the view out a window so that it can be drawn as a texture in the reflection? That would work, but some bathrooms have multiple windows, and that could get expensive very quickly. There's also a parallax effect involved that would look wrong because the window isn't a pinhole camera. As you move around within a room, you see a different view outside the window, and this also applies when looking through a mirror. Caching would require render to texture with a very large FOV and calculating the proper reprojected texture coordinates in the shader, which sounds complex and expensive. I doubt it would be overall better than what I have now.<br /><br />Note that the portal system I have for teleporters does allow for realtime infinite reflections if you place two mirror teleporters next to each other. The rendering pipeline is much simpler though, and a portal is generally small in screen space.<br /><br />I haven't figured out what to do with bathroom window refractions yet. Maybe that can use the same system, or maybe it needs something different. I can't even get alpha blending to work with bathroom windows.Frank Gennarihttps://www.blogger.com/profile/02815853731800103017noreply@blogger.comtag:blogger.com,1999:blog-1791631495483462759.post-53321414884072282332020-11-05T09:49:43.281-08:002020-11-05T09:49:43.281-08:00Oooh, very neat. Yeah, you're really getting i...Oooh, very neat. Yeah, you're really getting into the weeds here with the render pipeline.<br />One approach you could consider for rendering exterior views, no idea if this would work, but it just occurred to me. Could you cache the rendered view out a window/mirror to a texture? Then you could just use that texture in the next frame for further windows/reflections. There would be a slight lag in update, like with video feedback, but it should allow infinite reflections and looking through buildings and out the far window, as well as allowing you to defer the refraction map for bathroom windows to a later time slot when that portion of the pipeline isn't busy drawing the next frame.Paul Spoonerhttps://www.blogger.com/profile/17640871289041630907noreply@blogger.com