i am a newbie at Cesium, Shader & GLSL. I would like to get dynamic variable names in fragmentShaderText . here is the sample code…
let point_length = 3;
const customShader = new Cesium.CustomShader({
uniforms: {
point_0: {
value: new Cesium.Cartesian2(0.0, 0.0),
type: Cesium.UniformType.VEC2
},
point_1: {
value: new Cesium.Cartesian2(1.0, 1.0),
type: Cesium.UniformType.VEC2
},
point_2: {
value: new Cesium.Cartesian2(2.0, 2.0),
type: Cesium.UniformType.VEC2
},
},
fragmentShaderText: `
void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {
for (int i = 0; i < ${point_length}; i++) {
----> vec2 currentPoint = point_ + i (How to use dynamic variable names???? point_0, point_1, point_2)
}
}
`
});
Hello, example declaration:
var uniforms = {
// hole: {
// value: new Cesium.Cartesian4(holeArray[0],holeArray[1],holeArray[2],holeArray[3]),//holeArray,
// type: Cesium.UniformType.VEC4
// },
hole1: {
value: new Cesium.Cartesian4(0.0,0.0,0.0,0.0),
type: Cesium.UniformType.VEC4
},
hole2: {
value: new Cesium.Cartesian4(0.0,0.0,0.0,0.0),
type: Cesium.UniformType.VEC4
},
hole3: {
value: new Cesium.Cartesian4(0.0,0.0,0.0,0.0),
type: Cesium.UniformType.VEC4
},
num_hole: {
value: arrHoleCartesian4.length,
type: Cesium.UniformType.INT
}
};
for(let i=0;i<arrHoleCartesian4.length;i++)
{
uniforms['hole'+(i+1)].value=arrHoleCartesian4[i];
}
exaple use in code:
if(num_hole>0)
{
if(num_hole>=1 && worldPositionM.x>hole1.z && worldPositionM.x<hole1.x &&
worldPositionM.y>hole1.y && worldPositionM.y<hole1.w)
{
v_mode1=1.0;
}
if(num_hole>=2 && worldPositionM.x>hole2.z && worldPositionM.x<hole2.x &&
worldPositionM.y>hole2.y && worldPositionM.y<hole2.w)
{
v_mode1=1.0;
}
if(num_hole>=3 && worldPositionM.x>hole3.z && worldPositionM.x<hole3.x &&
worldPositionM.y>hole3.y && worldPositionM.y<hole3.w)
{
v_mode1=1.0;
}
}
thanks for your suggestion