implement skybox

This commit is contained in:
lightling 2022-04-03 18:18:42 -04:00
parent bedfe0d5f5
commit eeea33802a
Signed by: lightling
GPG key ID: 016F11E0AA296B67
13 changed files with 215 additions and 5 deletions

View file

@ -0,0 +1,60 @@
Welcome to AllSky Free!
This is a small sample edition of the full version of Allsky.
It contains a set of 10 skyboxes for use in your environments.
I hope you find them useful!
You can Buy the full version of AllSky here :
https://assetstore.unity.com/packages/2d/textures-materials/sky/allsky-200-sky-skybox-set-10109
The full version has 200 skies for Unity! Provided as 6 sided cubemaps sized from x1024 to x2048 per-side along with an equirectangular cubemap texture ranging from 4k to 16k in size. Each has an example lighting setup scene!
Various styles: Day, Night, Cartoon, Fantasy, Hazy, Epic, Space, Sunless and Moonless!
For lighting artists, environment artists and indie developers looking for a wide suite of skies to light their environments.
Lighting from day to night: Twilight, sunset, multiple times of day, multiple times of night, skyglow.
Many weather and cloud types: Clear, overcast, summery, stormy, autumnal, hazy, epic, foggy, cumulus.
TECHNICAL
Texture format: Each sky is a 6 sided cubemap. Source PNG texture resolution per-side ranges from x1024 to x2048. Equirectangular images vary in size up to 16k textures.
Skies are sorted by time of day or style in folders.
Each individual sky has a folder which contains the textures and a material with those textures assigned.
There is also a demo scene with example lighting and fog pass for reference.
Each sky has its own 6 sided skybox material which you can set to your scene's current skybox.
Please consult the Unity documentation if you are unsure how to do this.
http://docs.unity3d.com/Manual/HOWTO-UseSkybox.html
There is also an equirectangular material. Some users report that this is preferable in their use-case or build platform.
The materials are mostly set as /mobile/skyboxes shaders - which should be fastest - but you can change them to the other skybox shaders that ship with Unity and set the required textures. Some add tint, exposure and rotation controls.
The import resolution and type of compression used on the sky textures is entirely up to you. It should be set at a level which you feel utilises appropriate amounts of memory for your game amd platform, taking into account the amount of compression artifacts that you feel are acceptable.
DEMO SCENE
Each sky folder also has a demo scene. This shows a simple low-poly environment to demonstrate lighting and fog settings for that sky.
It was lit in the Forward Lighting Rendering Path with Linear lighting Color Space.
For intended demo scene lighting values and fog to be visible you will need a project with those settings.
(Under Edit->Project Settings->Player)
If you have to change these settings it may be necessary to re-import the sky textures.
The demo scene can benefit from increasing the Pixel light count in quality settings, and the Shadow Distance.
WHO
This asset pack is by Richard Whitelock.
A game developer, digital artist & photographer.
15+ years in the games industry working in a variety of senior art roles on 20+ titles.
Particularly experienced in environment art, lighting & special FX.
Currently working on various indie game & personal projects.
http://www.richardwhitelock.com

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 MiB

View file

@ -144,6 +144,7 @@
<ClCompile Include="Material.cpp" />
<ClCompile Include="Mesh.cpp" />
<ClCompile Include="SimpleShader.cpp" />
<ClCompile Include="Sky.cpp" />
<ClCompile Include="Transform.cpp" />
</ItemGroup>
<ItemGroup>
@ -156,6 +157,7 @@
<ClInclude Include="Material.h" />
<ClInclude Include="Mesh.h" />
<ClInclude Include="SimpleShader.h" />
<ClInclude Include="Sky.h" />
<ClInclude Include="Transform.h" />
<ClInclude Include="Vertex.h" />
</ItemGroup>
@ -826,6 +828,92 @@
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)/Assets/Textures/WithNormals</DestinationFolders>
</CopyFileToFolders>
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="Assets\Textures\Skies\planets\back.png">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
</CopyFileToFolders>
<CopyFileToFolders Include="Assets\Textures\Skies\planets\down.png">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
</CopyFileToFolders>
<CopyFileToFolders Include="Assets\Textures\Skies\planets\front.png">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
</CopyFileToFolders>
<CopyFileToFolders Include="Assets\Textures\Skies\planets\left.png">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
</CopyFileToFolders>
<CopyFileToFolders Include="Assets\Textures\Skies\planets\right.png">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
</CopyFileToFolders>
<CopyFileToFolders Include="Assets\Textures\Skies\planets\up.png">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</ExcludedFromBuild>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
<DestinationFolders Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)/Assets/Textures/Skies/planets</DestinationFolders>
</CopyFileToFolders>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
<Import Project="packages\Microsoft.XAudio2.Redist.1.2.8\build\native\Microsoft.XAudio2.Redist.targets" Condition="Exists('packages\Microsoft.XAudio2.Redist.1.2.8\build\native\Microsoft.XAudio2.Redist.targets')" />

View file

@ -31,6 +31,12 @@
<Filter Include="Assets\Textures\WithNormals">
<UniqueIdentifier>{7476640e-6b46-49e4-a478-c3ce10b2ddca}</UniqueIdentifier>
</Filter>
<Filter Include="Assets\Textures\Skies">
<UniqueIdentifier>{343d3538-c075-4c73-8ca8-f919b5ba231b}</UniqueIdentifier>
</Filter>
<Filter Include="Assets\Textures\Skies\planets">
<UniqueIdentifier>{f0ccea00-427b-47f7-8fce-7110b649b668}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="DXCore.cpp">
@ -63,6 +69,9 @@
<ClCompile Include="Material.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Sky.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Vertex.h">
@ -98,6 +107,9 @@
<ClInclude Include="Lights.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Sky.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<FxCompile Include="PixelShader.hlsl">
@ -246,6 +258,24 @@
<CopyFileToFolders Include="Assets\Textures\WithNormals\rock_specular.png">
<Filter>Assets\Textures\WithNormals</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="Assets\Textures\Skies\planets\up.png">
<Filter>Assets\Textures\Skies\planets</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="Assets\Textures\Skies\planets\back.png">
<Filter>Assets\Textures\Skies\planets</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="Assets\Textures\Skies\planets\down.png">
<Filter>Assets\Textures\Skies\planets</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="Assets\Textures\Skies\planets\front.png">
<Filter>Assets\Textures\Skies\planets</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="Assets\Textures\Skies\planets\left.png">
<Filter>Assets\Textures\Skies\planets</Filter>
</CopyFileToFolders>
<CopyFileToFolders Include="Assets\Textures\Skies\planets\right.png">
<Filter>Assets\Textures\Skies\planets</Filter>
</CopyFileToFolders>
</ItemGroup>
<ItemGroup>
<None Include="Helpers.hlsli">

View file

@ -90,8 +90,6 @@ void Game::LoadShadersAndMaterials()
// --------------------------------------------------------
void Game::LoadTextures()
{
Microsoft::WRL::ComPtr<ID3D11SamplerState> sampler;
D3D11_SAMPLER_DESC sampDesc = {};
sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
@ -186,6 +184,24 @@ void Game::CreateBasicGeometry()
entities[i]->GetTransform()->SetPosition((-(int)(entities.size() / 2) + i) * 5, 0, 0);
entities[i]->GetMaterial()->SetRoughness(0.60f);
}
skybox = std::make_shared<Sky>(
shapes[0],
std::make_shared<SimpleVertexShader>(device, context, GetFullPathTo_Wide(L"SkyboxVertexShader.cso").c_str()),
std::make_shared<SimplePixelShader>(device, context, GetFullPathTo_Wide(L"SkyboxPixelShader.cso").c_str()),
CreateCubemap(
device,
context,
L"Assets/Textures/Skies/planets/right.png",
L"Assets/Textures/Skies/planets/left.png",
L"Assets/Textures/Skies/planets/up.png",
L"Assets/Textures/Skies/planets/down.png",
L"Assets/Textures/Skies/planets/front.png",
L"Assets/Textures/Skies/planets/back.png"
),
sampler,
device
);
}
@ -241,6 +257,8 @@ void Game::Draw(float deltaTime, float totalTime)
entity->Draw(camera, ambient, lights);
}
skybox->Draw(context, camera);
// Present the back buffer to the user
// - Puts the final frame we're drawing into the window so the user can see it
// - Do this exactly ONCE PER FRAME (always at the very end of the frame)

4
Game.h
View file

@ -7,6 +7,7 @@
#include "SimpleShader.h"
#include "Material.h"
#include "Lights.h"
#include "Sky.h"
#include <DirectXMath.h>
#include <wrl/client.h> // Used for ComPtr - a smart pointer for COM objects
#include <memory>
@ -58,6 +59,9 @@ private:
// A7 Lights
std::vector<Light> lights;
DirectX::XMFLOAT3 ambient;
// A9 Normalmaps & Cubemaps
std::shared_ptr<Sky> skybox;
Microsoft::WRL::ComPtr<ID3D11SamplerState> sampler;
Microsoft::WRL::ComPtr<ID3D11Buffer> constantBufferVS;
};

12
Sky.cpp
View file

@ -1,10 +1,18 @@
#include "Sky.h"
Sky::Sky(std::shared_ptr<Mesh> _mesh, Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> _cubemap, Microsoft::WRL::ComPtr<ID3D11SamplerState> _sampler, Microsoft::WRL::ComPtr<ID3D11Device> _device)
Sky::Sky(
std::shared_ptr<Mesh> _mesh,
std::shared_ptr<SimpleVertexShader> _vertexShader,
std::shared_ptr<SimplePixelShader> _pixelShader,
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> _cubemap,
Microsoft::WRL::ComPtr<ID3D11SamplerState> _sampler,
Microsoft::WRL::ComPtr<ID3D11Device> _device)
{
mesh = _mesh;
cubemap = _cubemap;
sampler = _sampler;
vertexShader = _vertexShader;
pixelShader = _pixelShader;
D3D11_RASTERIZER_DESC rDesc = {};
rDesc.FillMode = D3D11_FILL_SOLID;
@ -21,7 +29,7 @@ Sky::~Sky()
{
}
void Sky::Draw(Microsoft::WRL::ComPtr<ID3D11DeviceContext> _context, Camera* _camera)
void Sky::Draw(Microsoft::WRL::ComPtr<ID3D11DeviceContext> _context, std::shared_ptr<Camera> _camera)
{
_context->RSSetState(rasterizerState.Get());
_context->OMSetDepthStencilState(depthState.Get(), 0);

4
Sky.h
View file

@ -12,6 +12,8 @@ class Sky
public:
Sky(
std::shared_ptr<Mesh> _mesh,
std::shared_ptr<SimpleVertexShader> _vertexShader,
std::shared_ptr<SimplePixelShader> _pixelShader,
Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> _cubemap,
Microsoft::WRL::ComPtr<ID3D11SamplerState> _sampler,
Microsoft::WRL::ComPtr<ID3D11Device> _device);
@ -19,7 +21,7 @@ public:
void Draw(
Microsoft::WRL::ComPtr<ID3D11DeviceContext> _context,
Camera* _camera);
std::shared_ptr<Camera> _camera);
private:
Microsoft::WRL::ComPtr<ID3D11SamplerState> sampler;