merge 3d diffuse lighting
This commit is contained in:
@@ -8,12 +8,11 @@
|
||||
/////////////
|
||||
Texture2D shaderTexture : register(t0);
|
||||
SamplerState SampleType : register(s0);
|
||||
|
||||
cbuffer LightBuffer
|
||||
{
|
||||
float4 diffuseColor;
|
||||
float3 lightDirection;
|
||||
float padding;
|
||||
float padding;
|
||||
};
|
||||
|
||||
|
||||
@@ -24,7 +23,7 @@ struct PixelInputType
|
||||
{
|
||||
float4 position : SV_POSITION;
|
||||
float2 tex : TEXCOORD0;
|
||||
float3 normal : NORMAL;
|
||||
float3 normal : NORMAL;
|
||||
};
|
||||
|
||||
|
||||
@@ -33,29 +32,26 @@ struct PixelInputType
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
float4 LightPixelShader(PixelInputType input) : SV_TARGET
|
||||
{
|
||||
float4 textureColor;
|
||||
float3 lightDir;
|
||||
float lightIntensity;
|
||||
float4 color;
|
||||
float4 textureColor;
|
||||
float3 lightDir;
|
||||
float lightIntensity;
|
||||
float4 color;
|
||||
|
||||
|
||||
// Sample the pixel color from the texture using the sampler at this texture coordinate location.
|
||||
textureColor = shaderTexture.Sample(SampleType, input.tex);
|
||||
// Sample the pixel color from the texture using the sampler at this texture coordinate location.
|
||||
textureColor = shaderTexture.Sample(SampleType, input.tex);
|
||||
|
||||
// Invert the light direction for calculations.
|
||||
// Invert the light direction for calculations.
|
||||
lightDir = -lightDirection;
|
||||
|
||||
// Calculate the amount of light on this pixel.
|
||||
lightIntensity = saturate(dot(input.normal, lightDir));
|
||||
|
||||
// Change the diffuse color to red (0, 1, 0)
|
||||
float3 greenDiffuseColor = float3(1, 0, 0);
|
||||
|
||||
// Determine the final amount of diffuse color based on the diffuse color combined with the light intensity.
|
||||
color = saturate(diffuseColor * lightIntensity);
|
||||
|
||||
// Multiply the texture pixel and the final diffuse color to get the final pixel color result.
|
||||
color = color * textureColor;
|
||||
color = color * textureColor;
|
||||
|
||||
return color;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
Reference in New Issue
Block a user