CesiumGS / cesium

An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
https://cesium.com/cesiumjs/
Apache License 2.0
13.01k stars 3.51k forks source link

Cannot render a glTF point cloud with 3-component colors #9948

Closed javagl closed 2 years ago

javagl commented 2 years ago

When trying to render a glTF that contains a "point cloud" with colors that are declared as a VEC3 with GL_FLOAT components, it generates an error message:

Fragment shader compile log: ERROR: 0:142: 'assign' : cannot convert from 'highp 3-component vector of float' to 'highp 4-component vector of float'

The title and the quick summary here already contain many guesses. For example, I have to admit that I did not try out whether it can render a glTF with VEC4 colors, but ... based on the error message, I think that the VEC3 is the reason for the crash: The fragment shader code probably contains a hard-wired vec4 for the colors, and attempting to feed it with a vec3 does not work. If this is the case, the fragment shader code "template" has to fetch the information of whether it should use vec3 or vec4 from the glTF accessor.

The attached file contains

Cesium testColorVec3 2021-11-30.zip

ptrgags commented 2 years ago

Thanks @javagl, I tried out your tileset and I see the problem, this is a bug in code I had written. Everything is supposed to be declared as a vec4, that's clearly not happening

When I run he generated fragment shader it looks like this:

varying vec3 v_color_0; // should be a vec4
struct ProcessedAttributes
{
    vec3 positionWC;
    vec3 positionEC;
    vec3 positionMC;
    vec3 color_0; // should be a vec4
};
...
void setDynamicVaryings(inout ProcessedAttributes attributes)
{
    attributes.color_0 = v_color_0;
}

I'm not entirely sure, but I think it might have to do with these lines: https://github.com/CesiumGS/cesium/blob/aa0dfaf304600ffb94db5f01d976f81df2665069/Source/Scene/ModelExperimental/GeometryPipelineStage.js#L258-L261 -- I'm not taking into account that these attributes are color_N since you could potentially have multiple sets of vertex colors.