Cubemaps - What and how

Discussion in 'Mapping Questions & Discussion' started by Cameron:D, Dec 8, 2008.

  1. Cameron:D

    Cameron:D L6: Sharp Member

    Messages:
    363
    Positive Ratings:
    145
    What are cubemaps?
    To make it simple, predefined reflections for surfaces to well…. Reflect.

    Why are cubemaps used?
    To do real-time reflections the engine needs to take what the player sees, flip it up-side-down, distort it to make it look reflected, and then draw it to the surface. Doing this frame will take way too much processing power to be worth it…. So that is what cubemaps are used for.

    How do cubemaps work?
    A cubemap is a point entity (env_cubemap) that you place on your map…. They should be placed in the following areas:
    • Near reflective surfaces
      • Windows
      • Water (Should be tied to the water face, so it only applies to that face)
    • Near reflective entities
      Some examples:
      • Cap points
      • Direction signs
    • In areas of high contrast
      • If you have a dark room, you don’t want things reflecting the bright outside or vice-versa

    Using cubemaps
    Once you have the cubemaps in your map, you compile your map; however, the only things your cubemaps are reflecting are the default ones provided by the skybox, so whether your reflective surface in inside or out, it will be reflecting clouds.

    [​IMG]

    This is what a map looks like with NO env_cubemap entities… ewww, the black/purple checks are what get displayed then a texture can’t be found… and because there are not cubemaps, it doesn’t know that to reflect.


    [​IMG]

    But when we toss in some env_cubemap’s… this is what we get…. A little better.


    [​IMG]

    Notice though, how the water does not reflect the cube (That black mark in the water was me accidently shooting). Why? We haven’t yet done what is known as ‘building our cubemaps’.

    Building cubemaps
    The process of building your cubemaps is actually quite simple. In fact all it takes is one console command: ‘buildcubemaps’. However, before you do that you first need to set up your map, by typing the following commands into the console.
    1. Compile and load your map.
    2. mat_specular 0
      This turns off reflections.
    3. buildcubemaps
      The game will pause for a second, and lots of little pictures will flash up the top of the screen.
    4. disconnect
      If you are not using HDR, you can step to step 11
    5. mat_hdr_level 0
      Turn off HDR.
    6. map “your_map_name”
      Load the map again
    7. buildcubemaps
    8. disconnect
    9. mat_specular 1
    10. mat_hdr_level 2
    11. map “cp_dustbowl”
      We need to load another map, to clear the caches of your map contents, otherwise it will not reload any of the cubemaps.
    12. Disconnect again, and load up your map. Enjoy!


    [​IMG]

    Now the water looks much nicer, and if you look close enough, the cap point will reflect the sky.
     
    • Thanks Thanks x 77
    Last edited: Nov 27, 2009
  2. MangyCarface

    aa MangyCarface Mapper

    Messages:
    1,616
    Positive Ratings:
    1,275
    Very comprehensive. This is of course the #1 mapping mistake.
     
  3. TheDarkerSideofYourShadow

    TheDarkerSideofYourShadow L10: Glamorous Member

    Messages:
    792
    Positive Ratings:
    144
    You know, even after all the time I've spent on these forums, this is the best explanation I have seen of what is going on and what you need to do. Well done sir.
     
  4. Vander

    Vander L8: Fancy Shmancy Member

    Messages:
    507
    Positive Ratings:
    111
    Ditto, excellent reference. Already bookmarked!
     
  5. YM

    aa YM LVL100 YM

    Messages:
    7,099
    Positive Ratings:
    5,745
    I'd put it at #2, right after model textures.
    No matter how good at mapping you are you can always lose concentration and use a model texture by mistake, but once you know about cubemaps you never forget them before a release
     
  6. luxatile

    aa luxatile deer

    Messages:
    2,289
    Positive Ratings:
    1,349
    Great guide, explains it all very well.

    This is officially the second post I've thanked by accident. Enjoy your thanks, I guess?
     
  7. YM

    aa YM LVL100 YM

    Messages:
    7,099
    Positive Ratings:
    5,745
    You can remove your thanks you know, there is a little button to do so ;)
     
  8. Scotland Tom

    Scotland Tom L6: Sharp Member

    Messages:
    332
    Positive Ratings:
    64
    Finally! A simple, straightforward explanation of how to implement cubemaps! Thank God!
     
  9. Cameron:D

    Cameron:D L6: Sharp Member

    Messages:
    363
    Positive Ratings:
    145
    Thanks for all the feedback... I made the entire thing in about 2 hours :)
     
  10. Lss40

    Lss40 L1: Registered

    Messages:
    16
    Positive Ratings:
    4
    Finally someone explained it in language i know.
     
  11. Scruga

    Scruga L1: Registered

    Messages:
    39
    Positive Ratings:
    0
    Has this anything to do with this situation:
    when i place a big prop, which is half in the shadow and half in the light, it's totally dark or totally light. i have no idea how to solve this. any help?
     
  12. TheDarkerSideofYourShadow

    TheDarkerSideofYourShadow L10: Glamorous Member

    Messages:
    792
    Positive Ratings:
    144
    No, that is a different issue. Thats because the origin of the prop (which is where it samples light from) is in a dark spot. However, and before Youme gets on my ass, there are additional compile commands you can use to light things much more evenly. IT is suggested that you only do it during pretty compiles since it adds so much time.

    http://forums.tf2maps.net/showthread.php?t=2994
     
    • Thanks Thanks x 1
  13. xArktisFlamex

    xArktisFlamex L1: Registered

    Messages:
    17
    Positive Ratings:
    3
    This helped me understand cubemaps a little better. Thanks :D
     
  14. Oodily Doodily

    Oodily Doodily L1: Registered

    Messages:
    23
    Positive Ratings:
    0
    At last I fully understand cubemaps, cheers.
     
  15. Huckle

    Huckle L4: Comfortable Member

    Messages:
    150
    Positive Ratings:
    87
    I think your step #11 could also just be sv_cheats 1 and mat_reloadallmaterials. In theory, that should clear the cache, just like loading another map while being a bit faster than loading the entire other map.
     
  16. ArtistDude88

    ArtistDude88 L1: Registered

    Messages:
    5
    Positive Ratings:
    0
    Excellent guide! I definitely have this bookmarked!
     
  17. Werewolf

    aa Werewolf Probably not a real Werewolf

    Messages:
    791
    Positive Ratings:
    234
    Already thanked this post long ago, but bumping because I still direct people to this thread and it would benefit from the pictures being fixed.
     
    • Agree Agree x 1
  18. Pocket

    aa Pocket func_croc

    Messages:
    4,489
    Positive Ratings:
    2,219
    It should probably also be moved to the tutorials subforum, which I'm guessing hadn't even been made when this thread was new.
     
    • Agree Agree x 1
  19. Dog.vtf

    Dog.vtf L2: Junior Member

    Messages:
    50
    Positive Ratings:
    8
    I'm kind of getting negated outcomes???

    When I don't have cubemaps water has real reflections and cap points reflect the sky. But when I put cubemaps in, everything with a reflection is all Black and purple checkers.


    WUT?
     
  20. Pocket

    aa Pocket func_croc

    Messages:
    4,489
    Positive Ratings:
    2,219
    What you're seeing is the "default cubemap". If there are no cubemap entities in the map whatsoever, it uses that. Which means you can probably get away with not using any cubemaps during early test versions. Probably. The default cubemap was based on a daytime skybox, so in dimly-lit indoor rooms with shiny tiled floors it'll probably still look like butt.

    The checkerboards are the generic "missing texture" texture. You'll get that when there are cubemap entities, so the engine knows to look for cubemaps, but there are none in the map yet. They're generated when you actually build the cubemaps as per the instructions.