2 % The ternary operator works differently in sm6. See sm6-ternary.shader_test.
9 float4 main() : sv_target
11 return x.x ? x : x - 1;
15 uniform 0 float4 2.0 3.0 4.0 5.0
17 probe (0, 0) rgba (2.0, 3.0, 4.0, 5.0)
18 uniform 0 float4 0.0 10.0 11.0 12.0
20 probe (0, 0) rgba (-1.0, 9.0, 10.0, 11.0)
26 float4 main() : sv_target
30 ret.x = x.x ? x.x : 1;
31 ret.y = x.y ? 2 : x.y;
37 uniform 0 float4 1.1 3.0 4.0 5.0
39 probe (0, 0) rgba (1.1, 2.0, 0.0, 0.0)
45 float4 main() : sv_target
47 float f1 = 0.1, f2 = 0.2, f3;
48 f3 = f.x ? (f1 = 0.5) + 0.2 : (f2 = 0.6);
49 return float4(f1, f2, f3, 0.0);
53 uniform 0 float4 1.0 0.0 0.0 0.0
55 probe (0, 0) rgba (0.5, 0.6, 0.7, 0.0)
61 float4 main() : sv_target
67 uniform 0 float4 0.0 1.0 0.0 -3.0
68 uniform 4 float4 1.0 2.0 3.0 4.0
69 uniform 8 float4 5.0 6.0 7.0 8.0
71 probe (0, 0) rgba (5.0, 2.0, 7.0, 4.0)
74 % The usual type conversion is applied to the first and second expression, as
75 % long as they are numeric.
82 float4 main() : sv_target
91 static float3x3 a = {0, 1, 2, 3, 4, 5, 6, 7, 8};
92 static float2x2 b = {.1, .2, .3, .4};
94 float4 main() : sv_target
96 return float4(1 ? a : b);
101 probe (0, 0) rgba (0.0, 1.0, 3.0, 4.0)
106 static float3 a = {0, 1, 2};
107 static float4 b = {5, 6, 7, 8};
109 float4 main() : sv_target
111 return float4(0 ? a : b, 1.0);
116 probe (0, 0) rgba (5.0, 6.0, 7.0, 1.0)
119 % More restrictions are placed on the type of the first (condition) operand,
120 % relative to the common type computed from the other two (result). Either:
121 % * the class and dimensions must match exactly;
122 % * the condition operand is scalar;
123 % * the result operands are scalar;
124 % * one is a typeN and the other is a type1xN
129 uniform float2x2 a, b;
131 float4 main() : sv_target
133 return float4(cond ? a : b);
139 uniform float2x2 cond;
142 float4 main() : sv_target
144 return float4(cond ? a : b);
150 static float2x2 cond = {1, 0, 0, 1};
151 static float2x2 a = {1, 2, 3, 4};
152 static float2x2 b = {5, 6, 7, 8};
154 float4 main() : sv_target
156 return float4(cond ? a : b);
161 probe (0, 0) rgba (1.0, 6.0, 7.0, 4.0)
169 float4 main() : sv_target
179 uniform float4x1 a, b;
181 float4 main() : sv_target
188 % As may be expected, this yields the type of the arguments, not the conditional.
192 static float4 cond = {1, 0, 0, 1};
193 static float1x4 a = {1, 2, 3, 4};
194 static float1x4 b = {5, 6, 7, 8};
196 float4 main() : sv_target
198 return (cond ? a : b)[0];
203 probe (0, 0) rgba (1.0, 6.0, 7.0, 4.0)
208 static float1x4 cond = {1, 0, 0, 1};
209 static float4 a = {1, 2, 3, 4};
210 static float4 b = {5, 6, 7, 8};
212 float4 main() : sv_target
214 return (cond ? a : b)[0];
219 probe (0, 0) rgba (1.0, 1.0, 1.0, 1.0)
224 uniform float1x4 cond;
227 float4 main() : sv_target
229 return (cond ? a : b)[0][0];
235 static float1 cond = {0};
236 static float1x1 a = {2};
237 static float1x1 b = {3};
239 float4 main() : sv_target
241 return (cond ? a : b)[0][0];
246 probe (0, 0) rgba (3.0, 3.0, 3.0, 3.0)
251 static float1x1 cond = {1};
252 static float1 a = {2};
253 static float1 b = {3};
255 float4 main() : sv_target
257 return (cond ? a : b)[0];
262 probe (0, 0) rgba (2.0, 2.0, 2.0, 2.0)
267 static float1x1 cond = {1};
268 static float1 a = {2};
269 static float1 b = {3};
271 float4 main() : sv_target
273 return (cond ? a : b)[0][0];
282 float4 main() : sv_target
284 return float4(cond ? a : b);
288 uniform 0 float4 1.0 0.0 0.0 0.0
289 uniform 4 float4 1.0 2.0 3.0 4.0
290 uniform 8 float4 5.0 6.0 7.0 8.0
292 probe (0, 0) rgba (1.0, 2.0, 3.0, 4.0)
297 // "scalar" can mean any 1-component numeric type.
298 static float1x1 cond = {0};
299 static float4 a = {1, 2, 3, 4};
300 static float4 b = {5, 6, 7, 8};
302 float4 main() : sv_target
304 return float4(cond ? a : b);
309 probe (0, 0) rgba (5.0, 6.0, 7.0, 8.0)
317 float4 main() : sv_target
319 return float4(cond ? a.x : b.x);
323 uniform 0 float4 1.0 0.0 1.0 0.0
324 uniform 4 float4 1.0 2.0 3.0 4.0
325 uniform 8 float4 5.0 6.0 7.0 8.0
327 probe (0, 0) rgba (1.0, 5.0, 1.0, 5.0)
332 // "scalar" can mean any 1-component numeric type.
333 static float4 cond = {1, 0, 0, 1};
334 static float1x1 a = {2};
335 static float1x1 b = {3};
337 float4 main() : sv_target
339 return float4(cond ? a : b);
344 probe (0, 0) rgba (2.0, 3.0, 3.0, 2.0)
347 % Objects can be used, but their types have to be identical.
352 float4 main() : sv_target
354 Texture2D tmp = 0 ? t : t;
359 [pixel shader fail todo]
363 float4 main() : sv_target
374 float4 main() : sv_target
381 % Of course objects cannot be used as the condition.
386 float4 main() : sv_target