-
Notifications
You must be signed in to change notification settings - Fork 0
/
light.ps
49 lines (37 loc) · 1.16 KB
/
light.ps
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Texture2D shaderTexture;
SamplerState SampleType;
cbuffer LightBuffer
{
float4 diffuseColor;
float3 lightDirection;
};
//////////////
// TYPEDEFS //
//////////////
struct PixelInputType
{
float4 position : SV_POSITION;
float2 tex : TEXCOORD0;
float3 normal : NORMAL;
};
////////////////////////////////////////////////////////////////////////////////
// Pixel Shader
////////////////////////////////////////////////////////////////////////////////
float4 LightPixelShader(PixelInputType input) : SV_TARGET
{
float4 textureColor;
float3 lightDir;
float lightIntensity;
float4 color;
// 이 텍스처 좌표 위치에서 샘플러를 사용하여 텍스처에서 픽셀 색상을 샘플링합니다.
textureColor = shaderTexture.Sample(SampleType, input.tex);
// 계산을 위해 빛 방향을 반전시킵니다.
lightDir = -lightDirection;
// 이 픽셀의 빛의 양을 계산합니다.
lightIntensity = saturate(dot(input.normal, lightDir));
// Determine the final diffuse color based on the diffuse color and the amount of light intensity.
color = saturate(diffuseColor * lightIntensity);
// Multiply the texture pixel and the input color to get the final result.
color = color * textureColor;
return color;
}