Files
Seele/res/shaders/Skybox.slang
T

105 lines
2.7 KiB
Plaintext
Raw Normal View History

2023-01-29 18:58:59 +01:00
import Common;
struct VertexShaderOutput
{
float4 clipPos : SV_Position;
float3 texCoords;
};
2023-11-05 10:36:01 +01:00
struct SkyboxData
{
float4x4 transformMatrix;
float4 fogBlend;
};
2023-11-08 23:27:21 +01:00
ParameterBlock<SkyboxData> pSkyboxData;
2023-01-29 18:58:59 +01:00
[shader("vertex")]
2023-02-01 22:13:04 +01:00
VertexShaderOutput vertexMain(
2023-11-15 17:42:57 +01:00
uint vertexIndex : SV_VertexId)
2023-01-29 18:58:59 +01:00
{
2023-11-16 22:58:47 +01:00
const float3 vertices[] = {
// Back
float3(-512, -512, 512),
float3(-512, 512, 512),
float3( 512, -512, 512),
float3( 512, -512, 512),
float3(-512, 512, 512),
float3( 512, 512, 512),
// Front
float3( 512, -512, -512),
float3( 512, 512, -512),
float3(-512, -512, -512),
float3(-512, -512, -512),
float3( 512, 512, -512),
float3(-512, 512, -512),
// Top
float3(-512, -512, -512),
float3(-512, -512, 512),
float3( 512, -512, -512),
float3( 512, -512, -512),
float3(-512, -512, 512),
float3( 512, -512, 512),
// Bottom
float3(-512, 512, 512),
float3(-512, 512, -512),
float3( 512, 512, 512),
float3( 512, 512, 512),
float3(-512, 512, -512),
float3( 512, 512, -512),
// Left
float3(-512, -512, -512),
float3(-512, 512, -512),
float3(-512, -512, 512),
float3(-512, -512, 512),
float3(-512, 512, -512),
float3(-512, 512, 512),
// Right
float3( 512, -512, 512),
float3( 512, 512, 512),
float3( 512, -512, -512),
float3( 512, -512, -512),
float3( 512, 512, 512),
float3( 512, 512, -512),
};
2023-02-01 22:13:04 +01:00
VertexShaderOutput output;
2024-10-01 16:56:04 +02:00
float3x3 cameraRotation = float3x3(pViewParams.viewMatrix);
2023-11-15 17:42:57 +01:00
float4 worldPos = float4(mul(cameraRotation, vertices[vertexIndex]), 1.0f);
2023-02-01 22:13:04 +01:00
//clip(dot(worldPos, clipPlane));
2024-10-01 16:56:04 +02:00
output.clipPos = mul(pViewParams.projectionMatrix, worldPos);
2023-11-16 22:58:47 +01:00
output.texCoords = normalize(vertices[vertexIndex]);
2023-01-29 18:58:59 +01:00
return output;
}
2023-11-05 10:36:01 +01:00
struct TextureData
{
TextureCube cubeMap;
TextureCube cubeMap2;
SamplerState sampler;
};
2024-06-15 21:47:20 +02:00
ParameterBlock<TextureData> pSkyboxTextures;
2023-02-01 22:13:04 +01:00
static const float lowerLimit = 0.0;
static const float upperLimit = 0.1;
2023-01-29 18:58:59 +01:00
2023-02-01 22:13:04 +01:00
[shader("fragment")]
float4 fragmentMain(
VertexShaderOutput output) : SV_Target
2023-01-29 18:58:59 +01:00
{
2024-06-15 21:47:20 +02:00
float4 texture1 = pSkyboxTextures.cubeMap.Sample(pSkyboxTextures.sampler, output.texCoords);
float4 texture2 = pSkyboxTextures.cubeMap2.Sample(pSkyboxTextures.sampler, output.texCoords);
2023-11-08 23:27:21 +01:00
float4 finalColor = lerp(texture1, texture2, pSkyboxData.fogBlend.w);
2023-01-29 18:58:59 +01:00
2023-02-01 22:13:04 +01:00
float factor = (output.texCoords.y - lowerLimit) / (upperLimit - lowerLimit);
2023-01-29 18:58:59 +01:00
factor = clamp(factor, 0.0, 1.0);
2025-03-31 11:39:17 +02:00
return lerp(float4(pSkyboxData.fogBlend.xyz, 1), finalColor, factor);
2023-01-29 18:58:59 +01:00
}