-
Notifications
You must be signed in to change notification settings - Fork 0
/
LightBufferFx.fx
66 lines (55 loc) · 1.53 KB
/
LightBufferFx.fx
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
float3 g_vLightColor : LightColor = float3( 1.0f, 1.0f, 1.0f ); // Light color
float3 g_vLightDirection : LightDirection = float3( 0.0f, 1.0f, 0.0f ); // Light direction
float3 g_vCameraPosition : CameraPosition;
texture g_normalTex : NormalTex;
texture g_worldPosTex:WorldPosTex;
sampler g_normalTexSampler = sampler_state
{
Texture = <g_normalTex>;
Filter = MIN_MAG_MIP_POINT;
AddressU = CLAMP;
AddressV = CLAMP;
};
sampler g_worldPosTexSampler = sampler_state
{
Texture = <g_worldPosTex>;
Filter = MIN_MAG_MIP_POINT;
AddressU = CLAMP;
AddressV = CLAMP;
};
struct VsInput
{
float4 position: POSITION;
float2 texCoord: TEXCOORD0;
};
struct PsInput
{
float2 texCoord: TEXCOORD0;
};
struct PsOutput
{
float4 diffuseAndSpecular: COLOR0;
};
VsInput mainVS(VsInput input)
{
return input;
}
void mainPS(in PsInput input, out PsOutput output)
{
float4 norDepth = tex2D(g_normalTexSampler, input.texCoord);
float4 worldPos = tex2D(g_worldPosTexSampler, input.texCoord);
float3 viewDir = normalize(g_vCameraPosition - worldPos.xyz);
float3 normal = normalize(norDepth.xyz);
float3 lightDir = normalize(g_vLightDirection.xyz);
float3 reflDir = reflect(lightDir, normal);
float diffuseFactor = saturate(dot(lightDir, normal));
float specularFactor= saturate(dot(-reflDir, viewDir));
output.diffuseAndSpecular = float4(diffuseFactor, specularFactor, 0,0);
}
technique technique0 {
pass p0 {
CullMode = None;
VertexShader = compile vs_2_0 mainVS();
PixelShader = compile ps_2_0 mainPS();
}
}