Files
armorpaint/base/shaders/cursor.vert.glsl
T

71 lines
1.8 KiB
GLSL
Raw Normal View History

2023-02-15 17:16:58 +01:00
#version 450
2023-02-08 14:40:15 +01:00
uniform mat4 VP;
uniform mat4 invVP;
uniform vec2 mouse;
2024-08-15 20:29:14 +02:00
uniform vec2 tex_step;
2023-02-08 14:40:15 +01:00
uniform float radius;
2024-08-15 20:29:14 +02:00
uniform vec3 camera_right;
2023-02-08 14:40:15 +01:00
uniform sampler2D gbufferD;
#ifdef HLSL
2024-10-02 23:17:50 +02:00
// direct3d12 unit align
uniform sampler2D texa;
2023-02-08 14:40:15 +01:00
#endif
2023-02-15 17:16:58 +01:00
2024-10-15 23:24:15 +02:00
#ifdef HLSL
2023-02-08 14:40:15 +01:00
in vec4 pos;
in vec2 nor;
2024-10-15 23:24:15 +02:00
#endif
2023-02-08 14:40:15 +01:00
in vec2 tex;
2024-08-15 20:29:14 +02:00
out vec2 tex_coord;
2023-02-08 14:40:15 +01:00
2024-08-15 20:29:14 +02:00
vec3 get_pos(vec2 uv) {
2024-10-15 23:24:15 +02:00
#ifdef HLSL
2023-02-08 14:40:15 +01:00
float keep = textureLod(texa, vec2(0.0, 0.0), 0.0).r; // direct3d12 unit align
float keep2 = pos.x + nor.x;
2024-10-15 23:24:15 +02:00
#endif
#ifdef GLSL
2023-02-08 14:40:15 +01:00
float depth = textureLod(gbufferD, uv, 0.0).r;
2024-10-15 23:24:15 +02:00
#else
float depth = textureLod(gbufferD, vec2(uv.x, 1.0 - uv.y), 0.0).r;
#endif
2023-02-08 14:40:15 +01:00
vec4 wpos = vec4(uv * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0);
2024-10-02 23:17:50 +02:00
wpos = mul(wpos, invVP);
2023-02-08 14:40:15 +01:00
return wpos.xyz / wpos.w;
}
2023-02-15 17:16:58 +01:00
2024-08-15 20:29:14 +02:00
vec3 get_normal(vec3 p0, vec2 uv) {
vec3 p1 = get_pos(uv + vec2(tex_step.x * 4, 0));
vec3 p2 = get_pos(uv + vec2(0, tex_step.y * 4));
2023-02-08 14:40:15 +01:00
return normalize(cross(p2 - p0, p1 - p0));
}
2023-02-15 17:16:58 +01:00
2024-10-15 23:24:15 +02:00
void create_basis(vec3 normal, OUT(vec3, tangent), OUT(vec3, binormal)) {
2024-08-15 20:29:14 +02:00
tangent = normalize(camera_right - normal * dot(camera_right, normal));
2023-02-08 14:40:15 +01:00
binormal = cross(tangent, normal);
}
2023-02-15 17:16:58 +01:00
2023-02-08 14:40:15 +01:00
void main() {
2024-08-15 20:29:14 +02:00
tex_coord = tex;
vec3 wpos = get_pos(mouse);
vec2 uv1 = mouse + tex_step * 4;
vec2 uv2 = mouse - tex_step * 4;
vec3 wpos1 = get_pos(uv1);
vec3 wpos2 = get_pos(uv2);
2023-02-08 14:40:15 +01:00
vec3 n = normalize(
2024-08-15 20:29:14 +02:00
get_normal(wpos, mouse) +
get_normal(wpos1, uv1) +
get_normal(wpos2, uv2)
2023-02-08 14:40:15 +01:00
);
vec3 n_tan;
vec3 n_bin;
2024-08-15 20:29:14 +02:00
create_basis(n, n_tan, n_bin);
2023-02-08 14:40:15 +01:00
if (gl_VertexID == 0) wpos += normalize(-n_tan - n_bin) * 0.7 * radius;
else if (gl_VertexID == 1) wpos += normalize( n_tan - n_bin) * 0.7 * radius;
else if (gl_VertexID == 2) wpos += normalize( n_tan + n_bin) * 0.7 * radius;
else if (gl_VertexID == 3) wpos += normalize(-n_tan + n_bin) * 0.7 * radius;
2024-10-02 23:17:50 +02:00
gl_Position = mul(vec4(wpos, 1.0), VP);
2023-02-08 14:40:15 +01:00
}