forked from baldurk/renderdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebugdisplay.hlsl
More file actions
329 lines (275 loc) · 7.91 KB
/
debugdisplay.hlsl
File metadata and controls
329 lines (275 loc) · 7.91 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2014 Crytek
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
v2f RENDERDOC_DebugVS(a2v IN)
{
v2f OUT = (v2f)0;
OUT.pos = float4(Position.xy + (float2(IN.pos.z,0) + IN.pos.xy*TextureResolution.xy)*Scale*ScreenAspect.xy, 0, 1)-float4(1.0,-1.0,0,0);
OUT.tex.xy = float2(IN.pos.x, -IN.pos.y);
return OUT;
}
// main texture display shader, used for the texture viewer. It samples the right resource
// for the type and applies things like the range check and channel masking.
// It also does a couple of overlays that we can get 'free' like NaN/inf checks
// or range clipping
float4 RENDERDOC_TexDisplayPS(v2f IN) : SV_Target0
{
bool uintTex = OutputDisplayFormat & TEXDISPLAY_UINT_TEX;
bool sintTex = OutputDisplayFormat & TEXDISPLAY_SINT_TEX;
float4 col = 0;
uint4 ucol = 0;
int4 scol = 0;
if(uintTex)
{
ucol = SampleTextureUInt4(OutputDisplayFormat & TEXDISPLAY_TYPEMASK,
IN.tex.xy, Slice, MipLevel, TextureResolutionPS);
}
else if(sintTex)
{
scol = SampleTextureInt4 (OutputDisplayFormat & TEXDISPLAY_TYPEMASK,
IN.tex.xy, Slice, MipLevel, TextureResolutionPS);
}
else
{
col = SampleTextureFloat4(OutputDisplayFormat & TEXDISPLAY_TYPEMASK, (ScalePS < 1 && MipLevel == 0),
IN.tex.xy, Slice, MipLevel, TextureResolutionPS);
}
if(RawOutput)
{
if(uintTex)
return asfloat(ucol);
else if(sintTex)
return asfloat(scol);
else
return col;
}
// RGBM encoding
if(WireframeColour.x > 0.0f)
{
if(uintTex)
ucol = float4(ucol.rgb * ucol.a * (uint)(WireframeColour.x), 1.0f);
else if(sintTex)
scol = float4(scol.rgb * scol.a * (int)(WireframeColour.x), 1.0f);
else
col = float4(col.rgb * col.a * WireframeColour.x, 1.0f);
}
if(uintTex)
col = (float4)(ucol);
else if(sintTex)
col = (float4)(scol);
col = ((col - RangeMinimum)*InverseRangeSize);
col = lerp(float4(0,0,0,1), col, Channels);
// show nans, infs and negatives
if(OutputDisplayFormat & TEXDISPLAY_NANS)
{
if(isnan(col.r) || isnan(col.g) || isnan(col.b) || isnan(col.a))
return float4(1, 0, 0, 1);
if(isinf(col.r) || isinf(col.g) || isinf(col.b) || isinf(col.a))
return float4(0, 1, 0, 1);
if(col.r < 0 || col.g < 0 || col.b < 0 || col.a < 0)
return float4(0, 0, 1, 1);
col = float4(dot(col.xyz, float3(0.2126, 0.7152, 0.0722)).xxx, 1);
}
else if(OutputDisplayFormat & TEXDISPLAY_CLIPPING)
{
if(col.r < 0 || col.g < 0 || col.b < 0 || col.a < 0)
return float4(1, 0, 0, 1);
if(col.r > 1 || col.g > 1 || col.b > 1 || col.a > 1)
return float4(0, 1, 0, 1);
col = float4(dot(col.xyz, float3(0.2126, 0.7152, 0.0722)).xxx, 1);
}
else
{
// if only one channel is selected
if(dot(Channels, 1) == 1)
{
// if it's alpha, just move it into rgb
// otherwise, select the channel that's on and replicate it across all channels
if(Channels.a == 1)
col = float4(col.aaa, 1);
else
col = float4(dot(col.rgb, 1).xxx, 1);
}
}
if(OutputDisplayFormat & TEXDISPLAY_GAMMA_CURVE)
{
col.rgb = pow(saturate(col.rgb), 2.2f);
}
return col;
}
struct MultipleOutput
{
float4 col0 : SV_Target0;
float4 col1 : SV_Target1;
float4 col2 : SV_Target2;
float4 col3 : SV_Target3;
float4 col4 : SV_Target4;
float4 col5 : SV_Target5;
float4 col6 : SV_Target6;
float4 col7 : SV_Target7;
};
struct wireframeV2F
{
float4 pos : SV_Position;
float3 norm : Normal;
float3 color : COLOR;
float2 tex : TEXCOORD0;
};
wireframeV2F RENDERDOC_WireframeHomogVS(float4 pos : POSITION, uint vid : SV_VertexID)
{
wireframeV2F OUT = (wireframeV2F)0;
OUT.pos = mul(pos, ModelViewProj);
float2 psprite[4] =
{
float2(-1.0f, -1.0f),
float2(-1.0f, 1.0f),
float2( 1.0f, -1.0f),
float2( 1.0f, 1.0f)
};
OUT.pos.xy += SpriteSize.xy*0.01f*psprite[vid%4]*OUT.pos.w;
return OUT;
}
struct meshA2V
{
float3 pos : pos;
float2 tex : tex;
float3 color : col;
};
wireframeV2F RENDERDOC_MeshVS(meshA2V IN, uint vid : SV_VertexID)
{
wireframeV2F OUT = (wireframeV2F)0;
OUT.pos = mul(float4(IN.pos, 1), ModelViewProj);
OUT.norm = float3(0, 0, 1);
OUT.color = IN.color;
OUT.tex = IN.tex;
return OUT;
}
[maxvertexcount(3)]
void RENDERDOC_MeshGS(triangle wireframeV2F input[3], inout TriangleStream<wireframeV2F> TriStream)
{
wireframeV2F output;
float4 faceEdgeA = mul(input[1].pos, InvProj) - mul(input[0].pos, InvProj);
float4 faceEdgeB = mul(input[2].pos, InvProj) - mul(input[0].pos, InvProj);
float3 faceNormal = normalize( cross(faceEdgeA.xyz, faceEdgeB.xyz) );
for(int i=0; i<3; i++)
{
output.pos = input[i].pos;
output.norm = faceNormal;
output.color = input[i].color;
output.tex = input[i].tex;
TriStream.Append(output);
}
TriStream.RestartStrip();
}
float4 RENDERDOC_MeshPS(wireframeV2F IN) : SV_Target0
{
uint type = OutputDisplayFormat;
if(type == MESHDISPLAY_TEXCOORD)
return float4(IN.tex.xy, 0, 1);
else if(type == MESHDISPLAY_COLOR)
return float4(IN.color.xyz, 1);
else if(type == MESHDISPLAY_FACELIT)
{
float3 lightDir = normalize(float3(0, -0.3f, -1));
return float4(WireframeColour.xyz*saturate(dot(lightDir, IN.norm)), 1);
}
else //if(type == MESHDISPLAY_SOLID)
return float4(WireframeColour.xyz, 1);
}
wireframeV2F RENDERDOC_WireframeVS(float3 pos : POSITION, uint vid : SV_VertexID)
{
wireframeV2F OUT = (wireframeV2F)0;
OUT.pos = mul(float4(pos, 1), ModelViewProj);
float2 psprite[4] =
{
float2(-1.0f, -1.0f),
float2(-1.0f, 1.0f),
float2( 1.0f, -1.0f),
float2( 1.0f, 1.0f)
};
OUT.pos.xy += SpriteSize.xy*0.01f*psprite[vid%4]*OUT.pos.w;
return OUT;
}
wireframeV2F RENDERDOC_FullscreenVS(uint id : SV_VertexID)
{
wireframeV2F OUT = (wireframeV2F)0;
float4 pos[] = {
float4( -1.0f, 1.0f, 0.0f, 1.0f),
float4( 3.0f, 1.0f, 0.0f, 1.0f),
float4( -1.0f, -3.0f, 0.0f, 1.0f)
};
float2 uv[] = {
float2(0.0f, 0.0f),
float2(2.0f, 0.0f),
float2(0.0f, 2.0f)
};
OUT.pos = pos[id];
OUT.tex = uv[id];
OUT.norm = float3(0, 0, 1);
OUT.color = float3(1, 1, 1);
return OUT;
}
MultipleOutput RENDERDOC_WireframePS(wireframeV2F IN)
{
MultipleOutput OUT = (MultipleOutput)0;
OUT.col0 =
OUT.col1 =
OUT.col2 =
OUT.col3 =
OUT.col4 =
OUT.col5 =
OUT.col6 =
OUT.col7 =
float4(WireframeColour.xyz, 1);
return OUT;
}
cbuffer overlayconsts : register(b1)
{
float4 overlaycol;
};
MultipleOutput RENDERDOC_OverlayPS(float4 IN : SV_Position)
{
MultipleOutput OUT = (MultipleOutput)0;
OUT.col0 =
OUT.col1 =
OUT.col2 =
OUT.col3 =
OUT.col4 =
OUT.col5 =
OUT.col6 =
OUT.col7 =
overlaycol;
return OUT;
}
float4 RENDERDOC_CheckerboardPS(float4 IN : SV_Position) : SV_Target0
{
float2 ab = fmod(IN.xy, 128.0.xx);
if(
(ab.x < 64 && ab.y < 64) ||
(ab.x > 64 && ab.y > 64)
)
{
return float4(sqrt(WireframeColour.rgb), 1);
}
return float4(sqrt(Channels.rgb), 1);
}