hadronized / quaazar

Realtime 3D engine
BSD 3-Clause "New" or "Revised" License
6 stars 2 forks source link

Loadable cubemaps #73

Open hadronized opened 9 years ago

hadronized commented 9 years ago

Context

We can load textures (as Texture) but we lack a way to unify them into cubemaps. That is, we need a way to load a Cubemap that gathers six textures.

Cubemaps

First we need to introduce a new type into Core. Something like this:

data Cubemap = Cubemap {
    _cubePosX :: Texture
  , _cubeNegX :: Texture
  , _cubePosY :: Texture
  , _cubeNegY :: Texture
  , _cubePosZ :: Texture
  , _cubeNegZ :: Texture
  }

Some cubemaps use the old and pretty stupid way to make cubemaps by wasting a lot of space, like this one:

I guess artists are used to that, so we need to support it as well. Then, the JSON should be something like this:

{
  "unpacked": {
      "x+": "posXtexture.png"
    , "x-": "…"
    , "y+": "…"
    , "y-": "…"
    , "z+": "…"
    , "z-": "…"
    }
}

Or like this:

{
  "packed": "cubemap.png"
}

A packed cubemap will be a single giant image packing all faces within. The orientation is the same as the image above, that is, 3x4 (3 rows of 4 columns) grid. The leftmost image on middle row is the -X, the one in the middle is -Z, the right nearby is +X, the rightmost one is +Z, the one at top is +Y and the one at bottom is -Y.