TTLG|Thief|Bioshock|System Shock|Deus Ex|Mobile
Results 1 to 11 of 11

Thread: Creating cubemap reflections in NewDark

  1. #1
    Member
    Registered: Aug 2012
    Location: Seattle

    Creating cubemap reflections in NewDark

    Greetings, editors! After resolving the issues from this post, I've decided to turn it into a mini-tutorial on getting cubemap (3D environment map) reflections working in NewDark. (2D envmap textures have a slightly different process; see Renzatic's posts in this thread.) Note that, as has been pointed out below, the cubemap feature is not suitable for sharp, detailed reflections that need precise geometric alignment.

    • Create a reflective surface with a dedicated texture. I made mine in terrain, though an object is also possible. I created fam\newmetal\bronze_mirror, a copy of bronz128.
    • IMPORTANT: If you usually use a widescreen aspect ratio, either switch to a standard aspect ratio or temporarily enable the widescreen_lock_hfov option in cam_ext.cfg.
    • In DromEd game mode, position the camera just above or to the side of the reflective surface. To ensure accuracy, I used vm_teleport to position the camera, edited the Garrett archetype to remove its gravity, then entered game mode and avoided touching the mouse.
    • Run the following command: envbox {size} {filename}. The {size} (of the output bitmaps) is optional and should be a power of 2; the default is 256. The {filename} is required and is just a prefix. I used envbox 512 mirror.
    • Six bitmap images have been created in the Thief directory. Mine were 512x512 and named mirrorb.bmp, mirrore.bmp, etc.
    • In an image editor, assemble the six images according to your DDS plugin's instructions. Be sure to rotate the top and bottom images 90 and 270 degrees, respectively. I use GIMP, and wrote a GIMP script that uses the gimp-dds plugin and automates this step.
    • Export the image to DDS as a cubemap. I created tex\map\mirror.dds with DXT3 compression.
    • Add a material file for the texture to create the reflection. The env_map shorthand seems to have some issues, so try the full form instead. Mine, shown here, is fam\newmetal\bronze_mirror.mtl and uses location-based envmaps. To use a predefined envmap, replace the use_location_envtex 2 line with texture {filename}. You may want a different alpha value, too.
      Code:
      render_pass
      {
      	use_location_envtex 2
      	alpha 0.25
      	blend SRC_ALPHA ONE
      	uv_source ENVIRONMENT
      	uv_mod SCALE 1 1
      }
    • If you are using location-based envmaps, open the Mission Variables -> Environment Maps dialog and set the texture for the appropriate zone to the one you have created. I set the global texture to tex\map\mirror.


    Original questions:
    I'm currently working on a demo mission where I decided to use a cubemap reflection. (The demo itself is not related to material effects.) After a good bit of trial and error, I got something resembling a reflection, but I had two issues:
    • The images generated by the new envbox DromEd command aren't seamless: between any two, there is an overlap region that appears in both. This has been fixed; see FOV-related step above.
    • When I move towards or away from the mirror, the reflection responds oddly: objects in the mirror (seem to) get larger as I move away from it. They actually stay the same size in pixels, just like real-life reflections don't change size, but unlike in real life they wind up taking up the entire mirror surface. For example, the reflection of a statue in front of the mirror (about a quarter of the mirror's width) fills the whole mirror when I step a few feet away. (Left-to-right motion tracks correctly.) I've tried a few combinations of uv_source and uv_mod settings, with no improvement.

    Does anyone recognize these issues from working with cubemaps in other engines? I might have gotten one of the many settings for this wrong, or this might be a bug/bugs in NewDark. Any ideas would be appreciated.
    Last edited by kdau; 2nd Jul 2013 at 15:35. Reason: fix to first issue, thanks to ZB; reformat

  2. #2
    Member
    Registered: Oct 2004
    Location: Ireland/Poland
    As for the first issue - I think all the envbox command does is taking 6 renders in six directions. They would need to be stitched properly to remove the seam - I'm sure there is some software to do it. The fact that they overlap will help here - if there were some gaps, that would be a bigger problem.
    You might also try to stitch them yourself in photoshop, using some warping transform tools.

    The second issue - I actually remember some observation from years ago. I was standing in a room, looking through the window at a block of appartments opposite my house. When standing close, I could see entire building and much more above and in front of it. When I did a number of steps back - I was able to see only 4 or 5 storeys of that building, giving me impression, that those windows were much bigger now. But that was only in relation to the window I was looking through, which was framing my view - same as your mirror does.
    But do not have too high expectations from that sort of cubical reflection maps. After all you're dealing with fake reflections, calculated for one point in space only. They would appear most correctly when you had a let's say chrome sphere in the middle of a room, with reflections map rendered from the center of that sphere. Any other situation makes the cheat more or less obvious. Your reflection map seem to be rendered from behind the statue - so this is completely different situation compared to the reflection you would get standing in the opposite room, in front of the statue.

    That sort of technique is meant to be used only as rather blurry, vague reflection impression - not a correct sharp, mirror reflections.

  3. #3
    Member
    Registered: Aug 2012
    Location: Seattle
    Quote Originally Posted by PinkDot View Post
    As for the first issue - I think all the envbox command does is taking 6 renders in six directions. They would need to be stitched properly to remove the seam - I'm sure there is some software to do it. The fact that they overlap will help here - if there were some gaps, that would be a bigger problem.
    You might also try to stitch them yourself in photoshop, using some warping transform tools.
    Ah. The NewDark docs seem to imply that the envbox output can be dumped right into a DDS cubemap, but I suppose that is a bit much to ask for.

    Quote Originally Posted by PinkDot View Post
    The second issue - I actually remember some observation from years ago. I was standing in a room, looking through the window at a block of appartments opposite my house. When standing close, I could see entire building and much more above and in front of it. When I did a number of steps back - I was able to see only 4 or 5 storeys of that building, giving me impression, that those windows were much bigger now. But that was only in relation to the window I was looking through, which was framing my view - same as your mirror does.
    But do not have too high expectations from that sort of cubical reflection maps. After all you're dealing with fake reflections, calculated for one point in space only. They would appear most correctly when you had a let's say chrome sphere in the middle of a room, with reflections map rendered from the center of that sphere. Any other situation makes the cheat more or less obvious. Your reflection map seem to be rendered from behind the statue - so this is completely different situation compared to the reflection you would get standing in the opposite room, in front of the statue.

    That sort of technique is meant to be used only as rather blurry, vague reflection impression - not a correct sharp, mirror reflections.
    I know that the framing effect does really happen, but the amount happening here is far beyond what it should be. But you're right, of course, I'm expecting too much from the feature. I suppose that two vague reflections will be enough to demonstrate the script. I'll leave trying the fancier bits to someone more experienced with materials.

  4. #4
    I had similar problems with cubemaps in TDS. They work best on static meshes, rather than BSP, and flat surfaces aren't the best place to use them. Using DDS cubemap is relatively easy, you just need Gimp with .dds plugin, and you have to name your layers +x, -x, +y, -y etc. so the plugin recognizes them correctly. You'll also have to mirror them horizontally (for convex shapes) and in some cases might need to turn some of the layers left/right/upside down to get it all right. IMO best way to figure it out for sure is to make a room with distinctive colors and objects on each wall and place the ball in the middle, like here: http://youtu.be/q52q1Z8RjMk?t=30s

    You probably won't need that in a long run, since as PinkDot said, cubemaps are not really good for sharp 1:1 reflections, but at least you'll know where the problem is.

  5. #5
    Member
    Registered: Aug 2012
    Location: Seattle
    Quote Originally Posted by Judith View Post
    I had similar problems with cubemaps in TDS. They work best on static meshes, rather than BSP, and flat surfaces aren't the best place to use them. Using DDS cubemap is relatively easy, you just need Gimp with .dds plugin, and you have to name your layers +x, -x, +y, -y etc. so the plugin recognizes them correctly. You'll also have to mirror them horizontally (for convex shapes) and in some cases might need to turn some of the layers left/right/upside down to get it all right. IMO best way to figure it out for sure is to make a room with distinctive colors and objects on each wall and place the ball in the middle, like here: http://youtu.be/q52q1Z8RjMk?t=30s

    You probably won't need that in a long run, since as PinkDot said, cubemaps are not really good for sharp 1:1 reflections, but at least you'll know where the problem is.
    Hmm...a convex static mesh? Perhaps a crystal ball whose cubemap is of some place you can view psychically. Thanks for the pointers.

    Since I don't use Windows, I can't use Nvidia's Photoshop plugin in Gimp, but there's gimp-dds which does similar. I actually wrote a Gimp script that automates the conversion of the NewDark envbox output to a DDS, though I'll need to expand it at some point to deal with the seams.

  6. #6
    ZylonBane
    Registered: Sep 2000
    Location: ZylonBane
    Have you tried shooting your cubemaps in both widescreen and standard aspect ratios? Maybe it doesn't know how to deal with more modern resolutions.

  7. #7
    Member
    Registered: Aug 2012
    Location: Seattle
    Quote Originally Posted by ZylonBane View Post
    Have you tried shooting your cubemaps in both widescreen and standard aspect ratios? Maybe it doesn't know how to deal with more modern resolutions.
    Thanks, that was it! The canvas briefly switches to match the output image size while it's generating the images, so I didn't think the ratio would be an issue. But the envbox command doesn't turn off the FOV adjustment for widescreen ratios. I just tried both switching to a standard-ratio resolution and manually altering the FOV correction with the widescreen_lock_hfov option in cam_ext.cfg. Both of them produce seamless output, though of course the second issue is still there since it seems to be inherent.

  8. #8
    ZylonBane
    Registered: Sep 2000
    Location: ZylonBane
    Quote Originally Posted by kdau View Post
    Both of them produce seamless output, though of course the second issue is still there since it seems to be inherent.
    Yes, environment maps are very similar to skyboxes in that the texture scale is globally fixed, essentially rendering at "infinity" distance. So for nearby/indoors reflections, hazy and indistinct is the way to go.

  9. #9
    Member
    Registered: Oct 2003
    Location: Nampa, Idaho
    Both Photoshop and PSP used to have plugins to generate skyboxes (cube maps). Cubing the Sphere, is freeware that can handle resolutions up to 2048x2048.

    I found that single surface reflections (floor, e.g.) work well in simple rooms, but not where there are a lot of cells. A did a cathedral floor, and even after Full Process, you could see where all the cells were defined in the floor. They kept flashing.

  10. #10
    ZylonBane
    Registered: Sep 2000
    Location: ZylonBane
    I've been playing around with cubemaps recently, and needed a workflow that didn't rely on a plugin. This is what I've come up with.

    SETUP

    MAKING AN ENVBOX
    • If you have HUD scaling enabled, disable it (d3d_disp_scaled_2d_overlay in cam_ext.cfg).
    • Start DromEd and load your mission.
    • Enter game mode and go to where you want your envbox rendered from. You should generally capture the envbox from just above ground level (the player camera height), and near the center of the (player-accessible) area the envbox will be used in.
    • Bring up the console (Shift-;).
    • Type "envbox [size] name". Size is optional. If omitted, envbox textures will be 256x256.
      For example: envbox dungeon
      Or: envbox 1024 stars
    • The envbox texture files will be written to the root of the Thief/SS2 install folder. Move them to your work folder.
    • In your paint program of choice, create a "cube cross" from the generated cube sides. Three of the textures must be rotated clockwise by the indicated degrees. For 256x256 textures your cube cross would be 768x1024. Save as flattened PNG.

    Code:
            +-----+
            |  T  |
            |  90 |
      +-----+-----+-----+
      |  E  |  S  |  W  |
      |     |     |     |
      +-----+-----+-----+
            |  B  |
            | 270 |
            +-----+
            |  N  |
            | 180 |
            +-----+
    • Run CubeMapGen and click "Load Cube Cross" in the green menu.
    • Click and drag in the central area to look around and examine your envbox. You can also check "Skybox" in the blue menu to preview as a skybox.
    • Set "Output Cube Size" in the red menu. You'll want to stick to the 256 - 32 range here (unless you're creating a skybox). The higher the resolution, the more mirrored the surface will appear, unless you also apply filtering. 256 per side would be appropriate for mirrored surfaces, but more diffuse surfaces would look better with 64 or even 32. Lower resolution also helps obscure that these aren't realtime reflections. Note that the lower the resolution, the more filtering you'll have to add to avoid visible pixelation.
    • Set the "Output Cube Format" in the olive menu to "8-bit RGB".
    • Click "Save Cubemap (.dds)" in the green menu.

    This process could be streamlined with something like an ImageMagick script and using CubeMapGen in batch mode, but for now, this works.
    Last edited by ZylonBane; 21st Dec 2019 at 15:58.

  11. #11
    Member
    Registered: Sep 1999
    Location: Texas, hhhwweeee hawww
    Excellent stuff ZB, thank you. This will be handy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •