Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup three display and fix #3517 & #3503 #3522

Merged
merged 3 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion WGLMakie/src/Lines.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ function linesegments_vertex_shader(uniforms, attributes) {

${attribute_decl}
${uniform_decl}
uniform int is_segments_multi;

out vec2 f_uv;
out ${color} f_color;
flat out uint frag_instance_id;

vec2 get_resolution() {
// 2 * px_per_unit doesn't make any sense, but works
Expand Down Expand Up @@ -72,6 +74,7 @@ function linesegments_vertex_shader(uniforms, attributes) {
vec2 point = pointA + xBasis * position.x + yBasis * width * position.y;

gl_Position = vec4(point.xy / get_resolution(), position.x == 1.0 ? p_b.z : p_a.z, 1.0);
frag_instance_id = uint((gl_InstanceID * is_segments_multi) + int(position.x == 1.0));
}
`;
}
Expand All @@ -86,6 +89,7 @@ function lines_fragment_shader(uniforms, attributes) {
"nan_color",
"highclip",
"lowclip",
"picking",
]);
const uniform_decl = uniforms_to_type_declaration(color_uniforms);

Expand Down Expand Up @@ -147,24 +151,44 @@ function lines_fragment_shader(uniforms, attributes) {
return aastep(threshold1, dist) * aastep(threshold2, 1.0 - dist);
}

flat in uint frag_instance_id;
uniform uint object_id;

vec4 pack_int(uint id, uint index) {
vec4 unpack;
unpack.x = float((id & uint(0xff00)) >> 8) / 255.0;
unpack.y = float((id & uint(0x00ff)) >> 0) / 255.0;
unpack.z = float((index & uint(0xff00)) >> 8) / 255.0;
unpack.w = float((index & uint(0x00ff)) >> 0) / 255.0;
return unpack;
}
void main(){

float xalpha = aastep(0.0, 0.0, f_uv.x);
float yalpha = aastep(0.0, 0.0, f_uv.y);
vec4 color = get_color(f_color, colormap, colorrange);
if (picking) {
if (color.a > 0.1) {
fragment_color = pack_int(object_id, frag_instance_id);
}
return;
}
fragment_color = vec4(color.rgb, color.a);
}
`;
}

function create_line_material(uniforms, attributes) {
const uniforms_des = deserialize_uniforms(uniforms);
return new THREE.RawShaderMaterial({
const mat = new THREE.RawShaderMaterial({
uniforms: uniforms_des,
glslVersion: THREE.GLSL3,
vertexShader: linesegments_vertex_shader(uniforms_des, attributes),
fragmentShader: lines_fragment_shader(uniforms_des, attributes),
transparent: true,
});
mat.uniforms.object_id = { value: 1 };
return mat;
}

function attach_interleaved_line_buffer(attr_name, geometry, points, ndim, is_segments) {
Expand Down Expand Up @@ -268,6 +292,7 @@ export function _create_line(line_data, is_segments) {
geometry.attributes
);

material.uniforms.is_segments_multi = {value: is_segments ? 2 : 1};
const mesh = new THREE.Mesh(geometry, material);
const offset = is_segments ? 0 : 1;
const new_count = geometry.attributes.linepoint_start.count;
Expand Down
Loading
Loading