Patch Update - Skybox Shader wip - V9.3.2

This commit is contained in:
2025-05-01 18:41:32 +02:00
parent f1c13a3c8c
commit 96b0d0e72d
12 changed files with 739 additions and 236 deletions

View File

@@ -0,0 +1,61 @@
/////////////
// GLOBALS //
/////////////
Texture2D shaderTexture : register(t0);
SamplerState SampleType : register(s0);
cbuffer SunLightBuffer
{
float4 ambientColor;
float4 diffuseColor;
float3 lightDirection;
float intensity;
};
cbuffer SunLightColorBuffer
{
float4 sunColor;
};
//////////////
// TYPEDEFS //
//////////////
struct PixelInputType
{
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
};
////////////////////////////////////////////////////////////////////////////////
// Pixel Shader
////////////////////////////////////////////////////////////////////////////////
float4 SunLightPixelShader(PixelInputType input) : SV_TARGET
{
float4 textureColor;
float4 color;
float lightIntensity;
float4 colorArray;
float4 colorSum;
// Sample the pixel color from the texture using the sampler at this texture coordinate location.
textureColor = shaderTexture.Sample(SampleType, input.tex);
// Calculate the different amounts of light on this pixel based on the direction of the light.
lightIntensity = saturate(dot(input.normal, -lightDirection));
// Determine the diffuse color amount of the light.
colorArray = (diffuseColor * lightIntensity) * intensity;
// Initialize the sum of colors.
colorSum = float4(0.0f, 0.0f, 0.0f, 1.0f);
// Add the light color.
colorSum.r += colorArray.r;
colorSum.g += colorArray.g;
colorSum.b += colorArray.b;
// Multiply the texture pixel by the light color to get the final result.
color = saturate(colorSum) * textureColor;
return color;
}

View File

@@ -0,0 +1,67 @@
/////////////
// GLOBALS //
/////////////
cbuffer MatrixBuffer
{
matrix worldMatrix;
matrix viewMatrix;
matrix projectionMatrix;
};
cbuffer CameraBuffer
{
float3 cameraPosition;
float padding;
};
cbuffer SunLightBuffer
{
float4 ambientColor;
float4 diffuseColor;
float3 lightDirection;
float intensity;
};
//////////////
// TYPEDEFS //
//////////////
struct VertexInputType
{
float4 position : POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
};
struct PixelInputType
{
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
};
////////////////////////////////////////////////////////////////////////////////
// Vertex Shader
////////////////////////////////////////////////////////////////////////////////
PixelInputType SunLightVertexShader(VertexInputType input)
{
PixelInputType output;
// Change the position vector to be 4 units for proper matrix calculations.
input.position.w = 1.0f;
// Calculate the position of the vertex against the world, view, and projection matrices.
output.position = mul(input.position, worldMatrix);
output.position = mul(output.position, viewMatrix);
output.position = mul(output.position, projectionMatrix);
// Store the texture coordinates for the pixel shader.
output.tex = input.tex;
// Calculate the normal vector against the world matrix only.
output.normal = mul(input.normal, (float3x3) worldMatrix);
// Normalize the normal vector.
output.normal = normalize(output.normal);
return output;
}