define skybox shaders

This commit is contained in:
lightling 2022-04-03 17:26:55 -04:00
parent d720c2072a
commit e54f629637
Signed by: lightling
GPG key ID: 016F11E0AA296B67
5 changed files with 76 additions and 0 deletions

View file

@ -186,6 +186,18 @@
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
</FxCompile>
<FxCompile Include="SkyboxPixelShader.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Pixel</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Pixel</ShaderType>
</FxCompile>
<FxCompile Include="SkyboxVertexShader.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Vertex</ShaderType>
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Vertex</ShaderType>
</FxCompile>
<FxCompile Include="VertexShader.hlsl">
<ShaderType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Vertex</ShaderType>
<ShaderModel Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">5.0</ShaderModel>
@ -309,6 +321,7 @@
<None Include="Defines.hlsli" />
<None Include="Lights.hlsli" />
<None Include="packages.config" />
<None Include="SkyboxDefines.hlsli" />
<None Include="ThirdPartyFunctions.hlsli" />
</ItemGroup>
<ItemGroup>

View file

@ -112,6 +112,12 @@
<FxCompile Include="SimplePixelShader.hlsl">
<Filter>Shaders</Filter>
</FxCompile>
<FxCompile Include="SkyboxPixelShader.hlsl">
<Filter>Shaders</Filter>
</FxCompile>
<FxCompile Include="SkyboxVertexShader.hlsl">
<Filter>Shaders</Filter>
</FxCompile>
</ItemGroup>
<ItemGroup>
<CopyFileToFolders Include="Assets\Models\cube.obj">
@ -255,5 +261,8 @@
<Filter>Shaders</Filter>
</None>
<None Include="packages.config" />
<None Include="SkyboxDefines.hlsli">
<Filter>Shaders</Filter>
</None>
</ItemGroup>
</Project>

20
SkyboxDefines.hlsli Normal file
View file

@ -0,0 +1,20 @@
#ifndef __SKYBOX_DEFINES__
#define __SKYBOX_DEFINES__
struct SkyboxVertexToPixel
{
float4 screenPosition : SV_POSITION;
float3 sampleDir : DIRECTION;
};
// Struct representing a single vertex worth of data
// - This should match Vertex.h
struct SkyboxVertexShaderInput
{
float3 localPosition : POSITION;
float3 normal : NORMAL;
float3 tangent : TANGENT;
float2 uv : TEXCOORD;
};
#endif

9
SkyboxPixelShader.hlsl Normal file
View file

@ -0,0 +1,9 @@
#include "SkyboxDefines.hlsli"
TextureCube SkyTexture : register(t0);
SamplerState Sampler : register(s0);
float4 main(SkyboxVertexToPixel input) : SV_TARGET
{
return SkyTexture.Sample(Sampler, input.sampleDir);
}

25
SkyboxVertexShader.hlsl Normal file
View file

@ -0,0 +1,25 @@
#include "SkyboxDefines.hlsli"
cbuffer ExternalData : register(b0)
{
matrix view;
matrix projection;
}
matrix RemoveTranslation(matrix m)
{
m._14 = 0;
m._24 = 0;
m._34 = 0;
return m;
}
SkyboxVertexToPixel main(SkyboxVertexShaderInput input)
{
SkyboxVertexToPixel output;
matrix worldViewProjection = mul(projection, RemoveTranslation(view));
output.screenPosition = mul(worldViewProjection, float4(input.localPosition, 1.0f));
output.screenPosition.z = output.screenPosition.w;
output.sampleDir = input.localPosition;
return output;
}