This repository has been archived by the owner on Dec 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 225
/
SimpleLighting.hlsli
80 lines (67 loc) · 2.38 KB
/
SimpleLighting.hlsli
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//--------------------------------------------------------------------------------------
// SimpleLighting.hlsl
//
// Shader demonstrating Lambertian lighting from multiple sources
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
// Constant Buffer Variables
//--------------------------------------------------------------------------------------
cbuffer Constants : register( b0 )
{
float4x4 mWorld;
float4x4 mView;
float4x4 mProjection;
float4 lightDir[ 2 ];
float4 lightColor[ 2 ];
float4 outputColor;
}
//--------------------------------------------------------------------------------------
struct VS_INPUT
{
float4 Pos : POSITION;
float3 Normal : NORMAL;
};
struct PS_INPUT
{
float4 Pos : SV_POSITION;
float3 Normal : TEXCOORD0;
};
//--------------------------------------------------------------------------------------
// Name: TriangleVS
// Desc: Vertex shader
//--------------------------------------------------------------------------------------
PS_INPUT TriangleVS( VS_INPUT input )
{
PS_INPUT output = ( PS_INPUT )0;
output.Pos = mul( input.Pos, mWorld );
output.Pos = mul( output.Pos, mView );
output.Pos = mul( output.Pos, mProjection );
output.Normal = mul( input.Normal, ( ( float3x3 ) mWorld ) );
return output;
}
//--------------------------------------------------------------------------------------
// Name: TrianglePS
// Desc: Pixel shader applying Lambertian lighting from two lights
//--------------------------------------------------------------------------------------
float4 LambertPS( PS_INPUT input ) : SV_Target
{
float4 finalColor = 0;
//do NdotL lighting for 2 lights
for( int i=0; i< 2; i++ )
{
finalColor += saturate( dot( ( float3 ) lightDir[ i ], input.Normal ) * lightColor[ i ] );
}
finalColor.a = 1;
return finalColor;
}
//--------------------------------------------------------------------------------------
// Name: TriangleSolidColorPS
// Desc: Pixel shader applying solid color
//--------------------------------------------------------------------------------------
float4 SolidColorPS( PS_INPUT input ) : SV_Target
{
return outputColor;
}