Questions for a particle renderer

I'm making a particle renderer, which I have initially working mostly fine, using a very hacked together primitive class with Appearance and Geometry that attached to an entity.
But I still have critical problems preventing quality results.
I'll ask questions in descending order of importance

-How do I pass an image as a sampler to vertex shader, when I have both a vertex and fragment shader?

-What is the proper way to feed the position of an entity to a primitive for use in uniforms?

-How do I assign uniforms per primitive? I've been doing a horrible hack where I recreate an appearance for every primitive, and setting onPreRender.
I can't find any sort of function such as primitive.onRender(); or uniforms[i](primitive);.
The way I figured out how to use appearance.uniforms was by grepping czm's source and setting breakpoints then going up the stack. Appearance's documentation and even source make no mention of "uniform".

-Terrain's depth function appears to be variable per tile. czm_modelViewProjection works perfectly for everything else, but particles inside the ground will show when at high zoom levels and certain camera angles. I'm guessing each terrain tile is rendered with its own near/far? I don't know how to compensate for this.

-How to properly put a shader as a file instead of hardcoding it?

My experience with czm is that it does the things it expects you to do with it very well, but any expansion outside of that is awful.
After having to dig through stuff for about a week to learn how to make a basic renderer, I'm thinking It would've been easier to hack my own pipeline onPostRender.


Sounds cool! Any reason you are not building this on the BillboardCollection or a modified version of it?


If billboard collection can have custom shaders I'm not sure how.

My position is entirely determined by in vertex shader by f(randSeed, time%loop).


There is not a public API to change the billboard shaders, but it still may be easier to start with the billboard collection. For the shaders, see:


I already have an internally very nice particle system, in an externally jury rigged way, such that I can 'attach' emitters to entities.

I've since found I don't need a sampler in my vertex shader because I scrapped that effect design.
Biggest need right now is figuring out uniforms.

I've been looking at drawCommands and I believe they would provide what i need with a uniformMap, but it appears you can't simply add a draw command without forking or some appalling runtime modding.
Why doesn't Appearance provide a similar interface for uniforms?

Documentation explaining the whole thing with manual/automatic and in general how uniforms work in czm would be extremely helpful

I would like to see uniforms working as
engine: setUniform( uniforms[name](primitive) )
use: function(prim){ return; }
Where passing the primitive as an arg allows the uniform getters to access arbitrary decoration on the primitive.

The current system where uniforms can only be set per appearance doesn't make sense, as that is equivalent to defines. Whereas drawCommand implements this sensibly.

(could you turn on own-post editing for this group?)
I don't need billboards not only because I already have my own system, but additionally because billboards are positioned on cpu, and refresh the entire buffer per change. Where my use-case is for fx with 1.e[5-6] points


I don’t really understand how you made a particle system. Did you create a primitive with point geometries and a custom appearance? Instead, you might want to start out creating a custom primitive. See for a simple example of the structure. After you add your custom primitive to the scene’s primitive collection, any commands you created will be queued for rendering


Ah I think this is exactly what I need.

Got everything working with my custom primitive, uniforms actually act like uniforms, and i converted my sliders into shader includes, which oddly cause lag when refreshing the program, but theyre for dev only so thats not an issue.

I still have an issue with particles not depthtesting the ground correctly. My vertices are normalized [-1,1] before multiplying by czm_modelViewProjection. I'm guessing its a precision issue, because this happens when viewing with a large modelmatrix scale and distant zoom. However if it is precision then there is a very large lack of it, because the entire lower half of the model will end up showing through the ground.

The depth buffer is cleared after rendering terrain and after each frustum of the multifrustum. We do this for when primitives (not ground primitives) are rendered on the surface to avoid z-fighting or having to triangulate the mesh exactly as we do for the ellipsoid surface. There is a depthTestAgainstTerrain option on the globe that you can set to true to have everything depth tested (that have it enabled in the render state) or you can set your draw command’s pass property to Pass.GROUND to have it rendered after the terrain but before the depth is cleared. Note that the later will cause the depths of your particles to be cleared.

Can you share a link to a demo with a particle system?

There is a depthTestAgainstTerrain option on the globe that you can set to true to have everything depth tested

Works perfectly. I'm not noticing any fighting, although i don't have any near-ground primitives.

Can you share a link to a demo with a particle system?

Sadly no because its for work.

My design is to have a single primitive class which:
function Emitter(entity, unis, modelmatGetter, emitterAppearance)
emitterAppearances contain the shaders, and shader includes, which remake the program upon change.
Unis are standard uniformMap.
"subclasses" of emitter take a single param for entity, or multiple entities if needed, and factory an Emitter with the appropriate params. Scope is used to pass the entities to the uniformMap and modelmatGetter

For the particles all I'm doing is using a vertex shader where
uniform float time;
attribute float randSeed;
pos= f(time,randSeed);
Its very fast and is limited mostly by fragment depthtest and blending