Hello,
I’m going to achieve something like seen below on the screenshot.
Is it correct way to use entity model and glTF?
Do you have some glTF model library where I can pick one similar to my case? Or at least just sphere without glow, there is only box example on official repo https://github.com/KhronosGroup/glTF/tree/master/sampleModels
Is there any way to use glsl to add custom shader with Entity API?
Please advice, thanks
hannah
July 5, 2016, 12:43pm
2
Hello,
Using a point would probably be the best solution.
To achieve the glow though, you’ll have to write a custom shader for the PointPrimitiveCollection
You can see the shaders we currently use here:
varying vec4 v_color;
varying vec4 v_outlineColor;
varying float v_innerPercent;
varying float v_pixelDistance;
varying vec4 v_pickColor;
void main()
{
// The distance in UV space from this fragment to the center of the point, at most 0.5.
float distanceToCenter = length(gl_PointCoord - vec2(0.5));
// The max distance stops one pixel shy of the edge to leave space for anti-aliasing.
float maxDistance = max(0.0, 0.5 - v_pixelDistance);
float wholeAlpha = 1.0 - smoothstep(maxDistance, 0.5, distanceToCenter);
float innerAlpha = 1.0 - smoothstep(maxDistance * v_innerPercent, 0.5 * v_innerPercent, distanceToCenter);
vec4 color = mix(v_outlineColor, v_color, innerAlpha);
color.a *= wholeAlpha;
// Fully transparent parts of the billboard are not pickable.
#if !defined(OPAQUE) && !defined(TRANSLUCENT)
This file has been truncated. show original
varying vec4 v_color;
varying vec4 v_outlineColor;
varying float v_innerPercent;
varying float v_pixelDistance;
varying vec4 v_pickColor;
void main()
{
// The distance in UV space from this fragment to the center of the point, at most 0.5.
float distanceToCenter = length(gl_PointCoord - vec2(0.5));
// The max distance stops one pixel shy of the edge to leave space for anti-aliasing.
float maxDistance = max(0.0, 0.5 - v_pixelDistance);
float wholeAlpha = 1.0 - smoothstep(maxDistance, 0.5, distanceToCenter);
float innerAlpha = 1.0 - smoothstep(maxDistance * v_innerPercent, 0.5 * v_innerPercent, distanceToCenter);
vec4 color = mix(v_outlineColor, v_color, innerAlpha);
color.a *= wholeAlpha;
// Fully transparent parts of the billboard are not pickable.
#if !defined(OPAQUE) && !defined(TRANSLUCENT)
This file has been truncated. show original
The shaders are added to the primitive in PointPrimitiveCollection.update:
And here is an example of how to add a point using a point primitive collection:
var pointPrimitives = scene.primitives.add(new Cesium.PointPrimitiveCollection());
pointPrimitives.add({
color : Cesium.Color.YELLOW,
position : Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883)
});
``
If you do decide to implement this, let us know! We would love the contribution back. I think this is something that would be helpful to a bunch of other people.
You can check out our build guide for instructions for getting and building the code: https://github.com/AnalyticalGraphicsInc/cesium/tree/master/Documentation/Contributors/BuildGuide
It’s a bit more work to connect this to the Entity API. Let me know if you get it working at the primitive level and I can give you the steps you need to hook it up at the entity level.
Best,
Hannah
thanks, I’ve played with the PointPrimitiveCollectionFS.glsl and as turns out if I set float maxDistance = 0.0 here https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Shaders/PointPrimitiveCollectionFS.glsl#L15 I got the effect I needed
the only issue with alpha, as you can see on the preview it is not transparent to other objects, but transparent to the terrain and space,
any ideas what it could be?
Try changing the line here: https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Scene/PointPrimitiveCollection.js#L863
from Pass.OPAQUE to Pass.TRANSLUCENT.
Points are going to have the same problems as billboards and labels. See this bug for more details: https://github.com/AnalyticalGraphicsInc/cesium/issues/2130
it works, thanks, here is a result