Patch Update - Skybox Shader wip - V9.3.2
This commit is contained in:
61
enginecustom/src/hlsl/skybox.ps
Normal file
61
enginecustom/src/hlsl/skybox.ps
Normal 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;
|
||||
}
|
67
enginecustom/src/hlsl/skybox.vs
Normal file
67
enginecustom/src/hlsl/skybox.vs
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user