forked from LukasBanana/LLGL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample.hlsl
56 lines (40 loc) · 986 Bytes
/
Example.hlsl
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
// HLSL model shader
cbuffer Settings : register(b1)
{
float4x4 wMatrix;
float4x4 vpMatrix;
float4 lightDir;
float4 diffuse;
};
// VERTEX SHADER STENCIL-BUFFER
float4 VStencil(float3 position : POSITION) : SV_Position
{
return mul(vpMatrix, mul(wMatrix, float4(position, 1)));
}
// VERTEX SHADER SCENE
struct InputVScene
{
float3 position : POSITION;
float3 normal : NORMAL;
};
struct OutputVScene
{
float4 position : SV_Position;
float4 normal : NORMAL;
};
OutputVScene VScene(InputVScene inp)
{
OutputVScene outp;
outp.position = mul(vpMatrix, mul(wMatrix, float4(inp.position, 1)));
outp.normal = mul(wMatrix, float4(inp.normal, 0));
return outp;
}
// PIXEL SHADER SCENE
float4 PScene(OutputVScene inp) : SV_Target
{
// Compute lighting
float3 normal = normalize(inp.normal.xyz);
float NdotL = max(0.2, dot(normal, -lightDir.xyz));
// Set final output color
return float4(diffuse.rgb * NdotL, 1.0);
}