forked from LukasBanana/LLGL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.hlsl
More file actions
81 lines (60 loc) · 1.47 KB
/
Example.hlsl
File metadata and controls
81 lines (60 loc) · 1.47 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
// HLSL shader version 4.0 (for Direct3D 11/ 12)
cbuffer Settings : register(b2)
{
float4x4 vpMatrix;
float4 viewPos;
float3 fogColor;
float fogDensity;
float2 animVec;
};
struct InputVS
{
// Per-vertex attributes
float3 position : POSITION;
float2 texCoord : TEXCOORD;
// Per-instance attributes
float3 color : COLOR;
float4x4 wMatrix : WMATRIX;
float arrayLayer : ARRAYLAYER;
};
struct OutputVS
{
float4 position : SV_Position;
float4 worldPos : WORLDPOS;
float3 texCoord : TEXCOORD;
float3 color : COLOR;
};
// VERTEX SHADER
OutputVS VS(InputVS inp)
{
OutputVS outp;
float2 offset = animVec * inp.position.y;
float4 coord = float4(
inp.position.x + offset.x,
inp.position.y,
inp.position.z + offset.y,
1.0
);
outp.worldPos = mul(inp.wMatrix, coord);
outp.position = mul(vpMatrix, outp.worldPos);
outp.texCoord = float3(inp.texCoord, inp.arrayLayer);
outp.color = inp.color;
return outp;
}
// PIXEL SHADER
Texture2DArray tex : register(t3);
SamplerState texSampler : register(s4);
float4 PS(OutputVS inp) : SV_Target
{
// Sample albed texture
float4 color = tex.Sample(texSampler, inp.texCoord);
// Apply alpha clipping
clip(color.a - 0.5);
// Compute fog density
float viewDist = distance(viewPos, inp.worldPos);
float fog = viewDist*fogDensity;
fog = 1.0 - 1.0/exp(fog*fog);
// Interpolate between albedo and fog color
color.rgb = lerp(color.rgb * inp.color, fogColor, fog);
return color;
};