-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshader.fx
More file actions
92 lines (70 loc) · 2.41 KB
/
Copy pathshader.fx
File metadata and controls
92 lines (70 loc) · 2.41 KB
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
81
82
83
84
85
86
87
88
89
90
91
//--------------------------------------------------------------------------------------
// File: Tutorial05.fx
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------
// Constant Buffer Variables
//--------------------------------------------------------------------------------------
cbuffer ConstantBuffer : register( b0 )
{
matrix World;
matrix View;
matrix Projection;
}
Texture2D txDiffuse : register(t0);
SamplerState samLinear : register(s0);
//--------------------------------------------------------------------------------------
struct VS_INPUT
{
float4 Pos : POSITION;
float3 Norm : NORMAL;
float2 Tex : TEXCOORD0;
};
struct PS_INPUT
{
float4 Pos : SV_POSITION;
float4 worldPos : POSITION;
float3 Norm : NORMAL;
float2 Tex : TEXCOORD0;
};
struct LightingResult
{
float4 Diffuse;
float4 Specular;
};
LightingResult ComputeLighting(float4 vertexPos, float3 N)
{
LightingResult totalResult = { { 1, 1, 1, 1 },{ 0, 0, 0, 0 } };
totalResult.Diffuse = saturate(totalResult.Diffuse);
totalResult.Specular = saturate(totalResult.Specular);
return totalResult;
}
//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
PS_INPUT VS( VS_INPUT input )
{
PS_INPUT output = (PS_INPUT)0;
output.Pos = mul( input.Pos, World );
output.worldPos = output.Pos;
output.Pos = mul( output.Pos, View );
output.Pos = mul( output.Pos, Projection );
// multiply the normal by the world transform (to go from model space to world space)
output.Norm = mul(float4(input.Norm, 1), World).xyz;
output.Tex = input.Tex;
return output;
}
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 PS(PS_INPUT IN) : SV_TARGET
{
LightingResult lit = ComputeLighting(IN.worldPos, normalize(IN.Norm));
float4 ambient = float4(0.2, 0.2, 0.2, 1);
float4 diffuse = lit.Diffuse;
float4 specular = lit.Specular;
float4 texColor = txDiffuse.Sample(samLinear, IN.Tex);
float4 finalColor = (ambient + diffuse + specular) * texColor;
return finalColor;
}