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

Add property attribute point clouds sample #55

Merged
merged 12 commits into from
Aug 17, 2022

Conversation

javagl
Copy link
Contributor

@javagl javagl commented Aug 3, 2022

A DRAFT for an example showing point clouds with property attributes and statistics.

@javagl
Copy link
Contributor Author

javagl commented Aug 17, 2022

Updated the sample to add a README, screenshot and sandcastle.

Preview: https://github.com/javagl/3d-tiles-samples/tree/add-property-attribute-point-clouds/glTF/EXT_structural_metadata/PropertyAttributesPointCloud

The line

int classification = int(fsInput.metadata.classification + 0.5);

is still to be discussed: It should not be necessary to round up there.

@lilleyse
Copy link
Contributor

sRGB -> linear conversion needed here?

Selection_031

@lilleyse
Copy link
Contributor

The line

int classification = int(fsInput.metadata.classification + 0.5);

is still to be discussed: It should not be necessary to round up there.

It seems like the attributes are being interpolated even though the mode is gl.POINTS. My theory is that the GPU is treating each point as a quad, duplicating the attributes at each corner, and running interpolation math. I wonder if the flat qualifier in WebGL 2 would fix this.

I put together some custom shaders to help debug this.

Version 1: vertex shader only approach - works!

  CLASSIFICATION_SHADER: new Cesium.CustomShader({
    varyings: {
      v_color: Cesium.VaryingType.VEC3,
    },
    vertexShaderText: `
    void vertexMain(VertexInput vsInput, inout czm_modelVertexOutput vsOutput) {
        int classif = int(vsInput.attributes.classification);
        
        vec3 color = vec3(1);
        if (classif == 0) {
            color = vec3(0,0.5,0);
        }
        else if (classif == 1) {
            color = vec3(0.5,0.5,0.5);
        }

        v_color = color;
    }`,
    fragmentShaderText: `
    void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material)
    {
        material.diffuse = v_color;
    }
    `,
  }),

image

Version 2: fragment shader approach with custom varying - fails!

  CLASSIFICATION_SHADER: new Cesium.CustomShader({
    varyings: {
      v_classif: Cesium.VaryingType.FLOAT,
    },
    vertexShaderText: `
    void vertexMain(VertexInput vsInput, inout czm_modelVertexOutput vsOutput) {
        v_classif = vsInput.attributes.classification;
    }`,
    fragmentShaderText: `
    void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material)
    {
        vec3 color = vec3(1);
        int classification = int(v_classif);
        if (classification == 0) {
            color = vec3(0,0.5,0);
        }
        else if (classification == 1) {
            color = vec3(0.5,0.5,0.5);
        }
        material.diffuse = color;
    }
    `,
  }),

image

@javagl
Copy link
Contributor Author

javagl commented Aug 17, 2022

I have updated the colors with sRGB (not sure whether it's worth updating the screenshot as well), and applied the workaround that @lilleyse suggested. The issue of imprecise int values in the fragment shader is now tracked at CesiumGS/cesium#10699 (also linked in the sandcastle), so I think this is ready for review.

@javagl javagl marked this pull request as ready for review August 17, 2022 20:43
@javagl
Copy link
Contributor Author

javagl commented Aug 17, 2022

I actually had noticed that in the comment, but didn't update it when copying the shader from the comment to the sandcastle. Updated.

@lilleyse lilleyse merged commit f91e854 into CesiumGS:main Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants