-
Notifications
You must be signed in to change notification settings - Fork 112
/
shader_builtin_ui_quadrant.hlsl
48 lines (43 loc) · 1.44 KB
/
shader_builtin_ui_quadrant.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
#include "stereokit.hlsli"
struct vsIn {
float4 pos : SV_Position;
float3 norm : NORMAL0;
float2 quadrant : TEXCOORD0;
float4 color : COLOR0;
};
struct psIn {
float4 pos : SV_Position;
float3 world : TEXCOORD1;
half4 color : COLOR0;
uint view_id : SV_RenderTargetArrayIndex;
};
psIn vs(vsIn input, uint id : SV_InstanceID) {
psIn o;
o.view_id = id % sk_view_count;
id = id / sk_view_count;
// Extract scale from the matrix
float4x4 world_mat = sk_inst[id].world;
float2 scale = float2(
length(float3(world_mat._11,world_mat._12,world_mat._13)),
length(float3(world_mat._21,world_mat._22,world_mat._23))
);
// Restore scale to 1
world_mat[0] = world_mat[0] / scale.x;
world_mat[1] = world_mat[1] / scale.y;
// Translate the position using the quadrant (TEXCOORD0) information and
// the extracted scale.
float4 sized_pos;
sized_pos.xy = input.pos.xy + input.quadrant * scale * 0.5;
sized_pos.zw = input.pos.zw;
float3 normal = normalize(mul(input.norm, (float3x3)world_mat));
float4 world = mul(sized_pos, world_mat);
o.pos = mul(world, sk_viewproj[o.view_id]);
o.world = world.xyz;
o.color.rgb = input.color.rgb * sk_inst[id].color.rgb * sk_lighting(normal);
o.color.a = input.color.a;
return o;
}
float4 ps(psIn input) : SV_TARGET {
float glow = pow(1-saturate(sk_finger_distance(input.world) / 0.12), 10);
return float4(lerp(input.color.rgb, half3(1, 1, 1), glow), input.color.a);
}