forked from LukasBanana/LLGL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExample.hlsl
76 lines (56 loc) · 1.32 KB
/
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// HLSL model shader
// VERTEX SHADER
cbuffer Settings : register(b3)
{
float4x4 wvpMatrix;
int useTexture2DMS;
};
struct InputVS
{
float3 position : POSITION;
float2 texCoord : TEXCOORD;
};
struct OutputVS
{
float4 position : SV_Position;
float2 texCoord : TEXCOORD;
};
OutputVS VS(InputVS inp)
{
OutputVS outp;
outp.position = mul(wvpMatrix, float4(inp.position, 1));
outp.texCoord = inp.texCoord;
return outp;
}
// PIXEL SHADER
Texture2D colorMap : register(t2);
#ifdef ENABLE_TEXTURE2DMS
Texture2DMS<float4, 8> colorMapMS : register(t3);
#endif
SamplerState samplerState : register(s1);
float4 PS(OutputVS inp) : SV_Target
{
#ifdef ENABLE_TEXTURE2DMS
if (useTexture2DMS)
{
// Load texel from multi-sample texture
uint w, h, numSamples;
colorMapMS.GetDimensions(w, h, numSamples);
int2 tc = int2(
(int)(inp.texCoord.x * (float)w),
(int)(inp.texCoord.y * (float)h)
);
// Compute average of all samples
float4 c = (float4)0.0;
for (uint i = 0; i < numSamples; ++i)
c += colorMapMS.Load(tc, i);
c /= numSamples;
return c;
}
else
#endif
{
// Sample texel from standard texture
return colorMap.Sample(samplerState, inp.texCoord);
}
}