New skyboxrenderer + moved meshrenderer inside engine and out from main to clean that up

This commit is contained in:
2026-02-22 17:16:21 -05:00
parent a781facd48
commit 932c45d844
14 changed files with 399 additions and 7 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -13,8 +13,8 @@ Output main(uint vertexIndex : SV_VertexID)
// Retrieve the vertex buffer using SM6.6 bindless syntax
ByteAddressBuffer buffer = ResourceDescriptorHeap[BufferIndex];
// TextureIndex is used as vertex offset for consolidated buffer (depth-tested at 0, overlay at halfMax)
uint actualVertexIndex = vertexIndex + TextureIndex;
// VertexOffset is used as vertex offset for consolidated buffer (depth-tested at 0, overlay at halfMax)
uint actualVertexIndex = vertexIndex + VertexOffset;
// Vertex layout: float3 Position (12 bytes) + float4 Color (16 bytes) = 28 bytes stride
uint stride = 28;

View File

@@ -0,0 +1,26 @@
#include "RootConstants.hlsl"
float4 main(float3 ViewDir : TEXCOORD0) : SV_Target0
{
float3 dir = normalize(ViewDir);
// Simple Procedural Gradient Skybox Colors
float3 skyZenithColor = float3(0.05f, 0.15f, 0.45f); // Deep blue top
float3 skyHorizonColor = float3(0.4f, 0.6f, 0.9f); // Light blue horizon
float3 groundColor = float3(0.1f, 0.1f, 0.15f); // Dark ground
float t = dir.z; // -1 to 1 based on vertical alignment
float3 finalColor = groundColor;
if (t > 0.0f) {
// Blend from horizon to zenith
finalColor = lerp(skyHorizonColor, skyZenithColor, t);
} else {
// Ground - quick blend from horizon to ground
finalColor = lerp(skyHorizonColor, groundColor, saturate(-t * 2.0f));
}
// Combine with overall ambient lighting scale
return float4(finalColor, 1.0f);
}

View File

@@ -0,0 +1,74 @@
#include "RootConstants.hlsl"
struct Output
{
float3 ViewDir : TEXCOORD0;
float4 Position : SV_Position;
};
float4x4 Inverse(float4x4 m)
{
float n11 = m[0][0], n12 = m[1][0], n13 = m[2][0], n14 = m[3][0];
float n21 = m[0][1], n22 = m[1][1], n23 = m[2][1], n24 = m[3][1];
float n31 = m[0][2], n32 = m[1][2], n33 = m[2][2], n34 = m[3][2];
float n41 = m[0][3], n42 = m[1][3], n43 = m[2][3], n44 = m[3][3];
float t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
float t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
float t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
float t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
float det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
float idet = 1.0f / det;
float4x4 ret;
ret[0][0] = t11 * idet;
ret[0][1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * idet;
ret[0][2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * idet;
ret[0][3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * idet;
ret[1][0] = t12 * idet;
ret[1][1] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * idet;
ret[1][2] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * idet;
ret[1][3] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * idet;
ret[2][0] = t13 * idet;
ret[2][1] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * idet;
ret[2][2] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * idet;
ret[2][3] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * idet;
ret[3][0] = t14 * idet;
ret[3][1] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * idet;
ret[3][2] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * idet;
ret[3][3] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * idet;
return ret;
}
Output main(uint vertexID : SV_VertexID)
{
Output output;
// Fullscreen triangle properties
// vertexID 0 -> uv(0,0) -> pos(-1, 1)
// vertexID 1 -> uv(2,0) -> pos( 3, 1)
// vertexID 2 -> uv(0,2) -> pos(-1, -3)
float2 uv = float2((vertexID << 1) & 2, vertexID & 2);
// Map uv to clip space position.
// Z is set to 1.0 (far plane in reverse-Z or standard depth)
// Assuming standard Z projection ranges from 0 to 1, we use 1.0 for the far plane.
// Depending on reverse-z, this might need to be 0.0, but let's stick to standard 1.0
// depth for skyboxes.
float4 clipPos = float4(uv * 2.0 - 1.0, 1.0, 1.0);
clipPos.y = -clipPos.y; // Flip Y for D3D
output.Position = clipPos;
// Reconstruct view direction from clip space
float4x4 inverseVP = Inverse(ViewProjection);
float4 worldPos = mul(inverseVP, clipPos);
output.ViewDir = worldPos.xyz / worldPos.w;
return output;
}