CesiumGS / cesium

An open-source JavaScript library for world-class 3D globes and maps :earth_americas:
https://cesium.com/cesiumjs/
Apache License 2.0
12.74k stars 3.45k forks source link

Optimize setting uniforms #649

Open pjcozzi opened 11 years ago

pjcozzi commented 11 years ago

Setting uniforms can take up to 15% of our time in the profiler, which is pretty standard in a 3D engine. We can do better, by both optimizing setting them and using less of them (yes, that means packing things together).

CC #646

emackey commented 11 years ago

While developing the gridMaterial, I noticed the uniforms are exposed as-is in Materials.js. Would it be worthwhile for materials to have a bit of JS interface, for example publicly exposing 4 un-related floats, while privately bundling them into a vec4 uniform? In other words, allow a material to present more public variables, and hide the bundling from the user.

pjcozzi commented 11 years ago

@emackey we will do something like this for materials since we don't want end users to do deal with packing directly. However, materials are not much of a problem right now compared to, say, terrain tiles and, soon, models. Generally, there are a lot more draw commands for these than for primitives supporting materials, especially when we add better batching.

pjcozzi commented 11 years ago

Some improvements were made in #1144

For the Everest terrain view in Sandcastle, uniform1f still shows up on the profiler. We should pack floating-point array uniforms into vec4 array uniforms. We can also better isolate uniforms that don't change between draw commands.

pjcozzi commented 10 years ago

It should be low-hanging fruit to replace manualUniforms with an array.

image

pjcozzi commented 9 years ago

More improvements: #2357

Plans:

pjcozzi commented 9 years ago

Also see OpenGL Scene-Rendering Techniques.

pjcozzi commented 9 years ago

Section A.7 of the GLSL spec has some uniform packing tips.

pjcozzi commented 9 years ago

CC #2490 and #2493