microsoft / DirectXTK

The DirectX Tool Kit (aka DirectXTK) is a collection of helper classes for writing DirectX 11.x code in C++
https://walbourn.github.io/directxtk/
MIT License
2.55k stars 506 forks source link

How to make a SkyBox/Cubemap with DirectXTK? #117

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hi, I am new to Directx11 and DirectXTK is great to help me build an app. I am looking for a method to make a SkyBox/Cubemap with DirectXTK but I cannot figure out it. Is there any way to make that with DirectXTK? Please tell me if exist or I have to use the original API. That is a pitty. :(

ghost commented 6 years ago

I tried to create a box with EnvironmentMapEffect but failed.

walbourn commented 6 years ago

Cubemaps are usually used to capture 'environments' surrounding a scene. The cubemap can be used to color in reflections, which is what the EnvironmentMapEffect achieves as seen in this tutorial.

To make the effect more convincing in outdoor scenes, you often want to make the 'skybox' surrounding a scene reflect the cubemaps used for reflections. For older Direct3D hardware feature levels, that's usually done with six individual 2D textures rendered inside of a 'box'. This has meant having two copies of the same 'cubemap': one as a cubemap and one as a set of six 2D textures (one for each face of the cubemap).

On Direct3D hardware feature level 10.0 or better, you can treat the same cubemap as an array of 2D textures for this. A DirectX 12 implementation can be see in this sample code but can be easily applied to DirectX 11 as well as long as you require Direct3D hardware feature level 10.0 or better.