Hi,
I think that there is no way at this moment to pass the FragmentInput struct to the custom shader PolylineMaterialAppearance :: fragmentShaderSource.
Is that correct ?
If it’s true, I would like to be able pass custom attributes :
Custom attributes are also available, though they are renamed to use lowercase letters and underscores. For example, an attribute called _SURFACE_TEMPERATURE in the model would become fsInput.attributes.surface_temperature in the shader.
“cesium/Documentation/CustomShaderGuide/README.md at main · CesiumGS/cesium · GitHub”
With fragmentShaderText it’s possible to pass the FragmentInput struct, but not with fragmentShaderSource
why ?
fragmentShaderText: `void fragmentMain(
FragmentInput fsInput,
inout czm_modelMaterial material
) {
I’m interested to get the attributes in the call of the function czm_getMaterial()
I looked at the source of CesiumJS, and I found that :
function updateSetDynamicVaryingsFunction(shaderBuilder, attributeInfo) {
const { semantic, setIndex } = attributeInfo.attribute;
if (defined(semantic) && !defined(setIndex)) {
// positions, normals, and tangents are handled statically in
// GeometryStageVS
return;
}
// In the vertex shader, we want things like
// v_texCoord_1 = attributes.texCoord_1;
let functionId = GeometryPipelineStage.FUNCTION_ID_SET_DYNAMIC_VARYINGS_VS;
const variableName = attributeInfo.variableName;
let line = `v_${variableName} = attributes.${variableName};`;
shaderBuilder.addFunctionLines(functionId, [line]);
// In the fragment shader, we do the opposite:
// attributes.texCoord_1 = v_texCoord_1;
functionId = GeometryPipelineStage.FUNCTION_ID_SET_DYNAMIC_VARYINGS_FS;
line = `attributes.${variableName} = v_${variableName};`;
shaderBuilder.addFunctionLines(functionId, [line]);
}
so maybe I don’t need the FragmentInput struct
I tried to do in the js file :
new Cesium.PolylineMaterialAppearance({
....
translucent: false,
vertexShaderSource: myVertex,
fragmentShaderSource: myFragment,
...
new Cesium.GeometryInstance({
geometry: new Cesium.PolylineGeometry({
positions: Cesium.Cartesian3.fromDegreesArrayHeights(line.points),
width: 2,
vertexFormat: vertexFormat,
arcType: Cesium.ArcType.GEODESIC,
...
}),
attributes:
{
myCustomAttribute: 5
....
}
})
and in the vertex shader :
// get it in the vertex shader :
in int lineLength;
// give it to the fragment shader :
flat out int v_lineLength;
will it work ? Looks like not, when I’m using the debugger :
I looked at the variable attributeLocations in :
const attributeLocations = shader._attributeLocations;
if ((0,defined/* default */.A)(attributeLocations)) {
for (const attribute in attributeLocations) {
if (attributeLocations.hasOwnProperty(attribute)) {
gl.bindAttribLocation(
program,
attributeLocations[attribute],
attribute
);
}
}
}
but i didn’t find the attribute that I added …
I would like to know where in the source code, the attribute are passed to fragment shader ?
Thanks,