GithubHelp home page GithubHelp logo

skybox's Introduction

Skybox

Skybox is a technique used to fake a distant view with 2D textures. Generally, those textures are stored in a cube map. A cube map consists of 6 textures, and those textures together form a cube. The distant view (mostly the sky) is rendered to the interior of the cube. That's why it is called skybox.

To make a skybox realistic, the view must be distant enough so that even the viewer moves, it barely change. This is the same as our experience in the real world, when we walk toward a sky.

License

The MIT License (MIT)

Copyright (c) 2021, Jiang Ye

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note

According to OpenGL Wiki, the face orientation and the corresponding parameter is as following:

GL_TEXTURE_CUBE_MAP_POSITIVE_X (0) --> right
GL_TEXTURE_CUBE_MAP_NEGATIVE_X (1) --> left
GL_TEXTURE_CUBE_MAP_POSITIVE_Y (2) --> top
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y (3) --> bottom
GL_TEXTURE_CUBE_MAP_POSITIVE_Z (4) --> back (*)
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z (5) --> front (*)

(*) The coordinate system used in cube map has a reversed z axis, compared to the world space. That's why the back and front direction have been reversed.

Logically, images should be written into their corresponding spots. For example, right.png into GL_TEXTURE_CUBE_MAP_POSITIVE_X and top.png into GL_TEXTURE_CUBE_MAP_POSITIVE_Y. However, in my program, when I do that, I get a disordered skybox. So I have to reorder those images or the skybox vertices to get a correct result.

Finally, the code has become something like this:

"left.png" --> GL_TEXTURE_CUBE_MAP_POSITIVE_X
"right.png" --> GL_TEXTURE_CUBE_MAP_NEGATIVE_X
"bottom.png" --> GL_TEXTURE_CUBE_MAP_POSITIVE_Y
"top.png" --> GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
"front.png" --> GL_TEXTURE_CUBE_MAP_POSITIVE_Z
"back.png" --> GL_TEXTURE_CUBE_MAP_NEGATIVE_Z

and the skybox vertices is something like:

{rightFace, leftFace, topFace, bottomFace, frontFace, backFace}

I cannot figure out why, and since the result is fine, I've decided to ignore this problem for now.

Result

result

skybox's People

Contributors

iamyoukou avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.