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.03k stars 3.51k forks source link

Using fsInput.attributes.tangentEC in Custom Shader Leads to dimension mismatch exception #11352

Closed xtassin closed 1 year ago

xtassin commented 1 year ago

The simple mention of fsInput.attributes.tangentEC in my custom shader generates the following exception:

ERROR: 0:78: '=' : dimension mismatch
ERROR: 0:78: 'assign' : cannot convert from 'highp 3-component vector of float' to 'highp 4-component vector of float'

The attached GLTF model:

cube.zip

ggetz commented 1 year ago

Thanks for the report @xtassin.

@jjhembd Could you please triage this issue?

jjhembd commented 1 year ago

Hi @xtassin, it is correct for the glTF to have tangents of type VEC4. This is mentioned in the spec, where the description of the tangent reads:

XYZW vertex tangents where the XYZ portion is normalized, and the W component is a sign value (-1 or +1) indicating handedness of the tangent basis

However, within CesiumJS, we store the 'handedness' separately, and use it to compute a 'bitangent'. So in the shader, fsInput.attributes.tangentEC should always be a vec3.

If you access it as a vec3, does the error go away?

If there is still a problem, please share a Sandcastle link showing how you are using the tangent, so we can debug further.

xtassin commented 1 year ago

https://sandcastle.cesium.com/#c=jVRtT9swEP4rVr80lYqTjo5poaChrExILUyl8KkScpNLY82xI9spLaj/fRcnoREwafkS++655557SWIljSVbDs+gyQWR8EwiMLzM6aOzeate7O6RkpZxCXrVG5yv5EoKsCRXCQgMa0Lm1ZWmWuW/hE2915UkpNQiJP3M2sKEvp8wy+gG1ElqaKxyPy7XQDcI7g8rcFwaq/L7jCWgw66YqOOoeeunlDxVOjcheT0Mj+Yt03suN+/NldzwM8pKOF1Mf8+uounT/Go5XdxczTqBgm8yi4SuwDeGWddKH25nN8thG9HRAtrCrs6zhJ3FbmwVTxr7HHvqPbrjjSxKHIVx7yHhUuE1fsmfXJdrzF1pa1B9GGB9/Y7OVLNNDtJ+zNZ6XL7r5lJnTP+Rcc4saM4EyZsDZmuwlFmr+bq0YKhlcoNc0+j80K+VHAYreaiXpF4samKQQAvNc275FoNYknguSQ3DDuM2FcqgW8njQkUMizacyVO3VT9howGMdzL6ckqDb2dDMh7T4OuQjIJgcF433bHStgDNd0e2pWbSuHWhwIy9VdpmD8VSXfMdJNiTHLxWQivL90mEds0IN6iPy2rexEVW7qa82EFoKvZL1W5nAgaxrCIL/6+c8fhs9L0uaYw1jbGmZrRKc+yw4yK40sd5Z8CSSlBIgs4WFNzGGXnLim3IqFULhGL93slpQN+Yq0crISoGGjTja3xJqRv5AU6zN+xNjN0LuGwjf/C8wEZUX7hHqW8hLwRuivHXZfwHLI2NqdpYQSd+N3SS8C3hycUnvxYSC2YMetJSiHv+Aqve5cRH/IdQoVzpd/gZCbavYNnoclYbKaUTH6+fR1qlxJrpd8x/AQ

cube.zip