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

add param computeLength and append v_distanceCamera when needed #12343

Open mickae1 opened 4 days ago

mickae1 commented 4 days ago

I'm working on custom shader, and I've some change needed to be done, on the core of cesium that I think will help others also.

By example, the dash material for polyline will be improved later ( the dash pattern depend of the position of the camera, which make the dash pattern move when the camera move which is not nice )

To help that, I need to know the distance of the fragment shader from the first point of the polyline. That why, I added an attribute in the class PolylineGeometry. By default it's desactived, and it can be activated with the option computeLength.

In my custom shader, I need also to know the distance of the camera, which is already done here :

https://github.com/CesiumGS/cesium/blob/c403b50282030c17739ea65d6c7b9a835792f4c2/packages/engine/Source/Scene/Primitive.js#L1004

so I just prepend in the vertexshader : "out float v_distanceCamera; \n" +

when the function _appendDistanceDisplayConditionToShader is called.

which help me to show/hide, change object property in the custom shader depending of the distance of the camera from the object.

I think this will help also other.

Michael,

github-actions[bot] commented 4 days ago

Thank you for the pull request, @mickae1!

:white_check_mark: We can confirm we have a CLA on file for you.