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

Remove check for point length 0 in line material #24

Open
dmnsgn opened this issue Jan 31, 2025 · 1 comment
Open

Remove check for point length 0 in line material #24

dmnsgn opened this issue Jan 31, 2025 · 1 comment

Comments

@dmnsgn
Copy link
Member

dmnsgn commented Jan 31, 2025

What's the reason for this check:

if (length(aPointA) == 0.0 || length(aPointB) == 0.0) {
gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
} else {

If that's an optimisation for empty buffers, it should be an AND operation (length(aPointA) == 0.0 && length(aPointB) == 0.0), no?

Or is it something about discontinuous paths?

Currently this won't render in pex-renderer:

const linesEntity = createEntity({
  transform: components.transform(),
  geometry: components.geometry({
    positions: [
      [0, 0, 0],
      [1, 1, 1],
    ],
  }),
  material: components.material({
    type: "line",
    baseColor: [1, 1, 1, 1],
    lineWidth: 30,
  }),
});
@vorg
Copy link
Member

vorg commented Jan 31, 2025

Updated PathToSegments node

const nextCell = pathCells[j + 1] || pathCells[j]; // TODO: wrong
const nextValue = pathGeometry[attributeName].slice(
   nextCell * size,
   nextCell * size + size,
);

changed to

const nextVertexIndex = pathCell[j + 1] || -1; // TODO: wrong

//if value doesn't exist depend on pre-filled 0 to insert discontinuinty 0,0,0 between paths
if (nextVertexIndex != -1) {
  const nextValue = pathGeometry[attributeName].slice(
     nextVertexIndex * size,
    nextVertexIndex * size + size,
  );
  path[attributeName].set(nextValue, size * cellIndex + size);
}

gives you answer that it is indeed "Or is it something about discontinuous paths?" as we inser 0,0,0 for discontinuities.

because how we render lines with 4 floats offset

https://github.com/pex-gl/pex-renderer/blob/v4/systems/renderer/line.js

if (entity._geometry.attributes.aVertexColor) {
      attributes.aColorA = {
        buffer: entity._geometry.attributes.aVertexColor.buffer,
        divisor: 1,
        stride: Float32Array.BYTES_PER_ELEMENT * 8,
      };
      attributes.aColorB = {
        buffer: entity._geometry.attributes.aVertexColor.buffer,
        divisor: 1,
        stride: Float32Array.BYTES_PER_ELEMENT * 8,
        offset: Float32Array.BYTES_PER_ELEMENT * 4,
      };
    }

you end up with A B C D 0 E F and 0.0 checks are agains D 0 and 0 D. So there is never two 0 to check.

As 0,0,0 is such a common use case maybe we can use different number? Can we insert NaNs or infinity there? How others do it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants