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

WebGL 2 and WebGL Extensions Roadmap #797

Closed pjcozzi closed 1 year ago

pjcozzi commented 11 years ago

Extensions in Canary

Draft WebGL Extensions

Proposed WebGL Extensions

OpenGL ES 3.0 Features

More on ES 3.0

More on WebGL 2.0

WebGL 2 Demos

Done

pjcozzi commented 10 years ago

Uniform buffer objects

The renderer could always expose UBOs and emulate them with traditional uniforms or uniform arrays if they are not supported. This will require some GLSL macros or shader patching for the uniform/uniform-buffer declarations.

Automatic uniforms can be grouped into uniform buffers based on update frequency: per frame and per object (model-matrix).

Each command can provide two uniform buffer: one for uniforms that don't change often and one for uniforms that do. This maps to technique (don't change) and material (do change) parameters. Or one uniform buffer might be fine since the command creator won't have to figure out how to organize them.

pjcozzi commented 9 years ago

Cesium Implementation Status (after #3094)

pjcozzi commented 9 years ago
pjcozzi commented 8 years ago
pjcozzi commented 8 years ago

WebGL 2 Samples

pjcozzi commented 7 years ago
pjcozzi commented 7 years ago

WebGL 2 articles on the RTR blog:

pjcozzi commented 7 years ago

Texture Array: we could use TEXTURE_2D_ARRAY in some cases where texture atlases are used. It will be simpler and great for dynamic updates when the size doesn't change, #2319

pjcozzi commented 7 years ago
pjcozzi commented 7 years ago
pjcozzi commented 7 years ago
pjcozzi commented 7 years ago
pjcozzi commented 7 years ago
pjcozzi commented 7 years ago

Hardware PCF for soft shadows

lilleyse commented 7 years ago
bagnell commented 7 years ago

For FXAA, use textureLod and textureLodOffset like the original shader. Consider using textureSize instead of a uniform.

pjcozzi commented 7 years ago
pjcozzi commented 7 years ago
pjcozzi commented 7 years ago
pjcozzi commented 7 years ago

Likely run our existing GLSL through modernizeShader, #5623, to generate GLSL ES 3.0, and then have a bit of a DSL (domain-specific language) with marcos/etc to handle differences like varying vs in/out. I'm sure it will not be that simple and some thing will have to be GLSL ES 3.0 specific, but we do not want to limit ourselves to only using GLSL ES 1.0 over the long haul, and I believe that engines like Unity do exactly this.

pjcozzi commented 7 years ago
pjcozzi commented 7 years ago
lilleyse commented 6 years ago

If running a webgl2 context bypass texture upscaling code in Model when generating mipmaps.

EDIT: forgot this was already added above.

lilleyse commented 5 years ago

See https://github.com/AnalyticalGraphicsInc/cesium/pull/6314 which enabled WebGL 2 by default but hasn't been tested enough yet and had gone stale.

lilleyse commented 5 years ago

Possible terrain loading bug in WebGL 2: https://github.com/AnalyticalGraphicsInc/cesium/issues/6756

OmarShehata commented 4 years ago

For anyone trying to use CesiumJS with WebGL 2, note this is not currently officially supported, but is on the roadmap. I'm consolidating open issues with running CesiumJS with WebGL 2 here.

For reference, you can activate WebGL 2 by initializing the viewer as follows:

var viewer = new Cesium.Viewer('cesiumContainer', {
    contextOptions: {
        requestWebgl2: true
    }
})

Known issues with WebGL 2

mramato commented 4 years ago

The original issue description is very out of date, if we're going to use this to track WebGL2 implementation, someone should update it with updated thoughts and plan of action.

lilleyse commented 4 years ago

@mramato 👍

That'll be on me an @YoussefV once we start the WebGL 2 / MSAA work.

lilleyse commented 4 years ago

In WebGL 2 the camera zooms towards the globe instead of towards the geometry that the mouse is hovering over. This seems like a bug in either ScreenSpaceCameraController or scene.pickPosition.

Sandcastle

WebGL 1 zoom-webgl1

WebGL 2 zoom-webgl2

dennisadams commented 4 years ago

@lilleyse When ScreenSpaceCameraController needs a pickPosition, it calls both scene.pickPositionWorldCoordinates and globe.pickWorldCoordinates and chooses the closer of the two, assuming both are defined.
In our case, scene.pickPositionWorldCoordinates returns undefined and so ScreenSpaceCameraController uses the globe pick instead. I played around a little and the problem seems to be that the depth texture is empty.
With the help of this error, I tried hard-coding a NEAREST filtering and it worked alright (even the error was gone). So I guess it's some problem with linear minification/magnification filtering.
I tried it with the changes from 8969, so that can also be a factor.

lilleyse commented 4 years ago

@dennisadams awesome, that fixes it for me as well. Just to confirm you added nearest filtering to the depth-stencil texture?

  globeDepth._depthStencilTexture = new Texture({
    context: context,
    width: width,
    height: height,
    pixelFormat: PixelFormat.DEPTH_STENCIL,
    pixelDatatype: PixelDatatype.UNSIGNED_INT_24_8,
    sampler: Sampler.NEAREST // Fixes the zoom
  });
baothientran commented 4 years ago

@dennisadams @lilleyse That also fixes the Silhouette post processing as well. Also I look it up, and in WebGL 2, it seems depth texture cannot have linear filtering. That may be a potential problem with other depth textures used by Cesium as well

dennisadams commented 4 years ago

Just to confirm you added nearest filtering to the depth-stencil texture?

I went on a safe bet - hard-coded the Texture constructor.

lilleyse commented 4 years ago

Labels look a bit different in WebGL 2. Click the images to see the difference.

WebGL 2 wegbl2

WebGL 1 wegbl2-off

Sandcastle

lilleyse commented 4 years ago

The AO post process has artifacts: Local sandcastle.

ao

lilleyse commented 4 years ago

Polyline arrows start to get squashed. Local sandcastle

arrow

lilleyse commented 4 years ago

Cesium Inspector is extremely show when "Show Frustums" is checked. Local sandcastle

cesium-inspector

lilleyse commented 4 years ago

Contour lines are much thinner in WebGL 2. Local sandcastle.

First thing I would look into is GL_OES_standard_derivatives which is another built-in define that's part of WebGL 1 but maybe not WebGL 2 (I haven't checked). GL_EXT_frag_depth is another one we should investigate.

contour1 contour2

lilleyse commented 4 years ago

Alright that's all I've uncovered so far by going through each sandcastle example with WebGL2 enabled. @baothientran I recomend starting with https://github.com/CesiumGS/cesium/issues/797#issuecomment-646920630 and seeing what other bugs are fixed in the process.

lilleyse commented 4 years ago

@baothientran since the number of bugs fixes was starting to grow too much I consolidated them into a single CHANGES.md entry: https://github.com/CesiumGS/cesium/commit/65757f8b7dce74d1ffbf9d61ea10d6e4508b86f2

lilleyse commented 4 years ago

Also I updated the checklist above: https://github.com/CesiumGS/cesium/issues/797#issuecomment-617189407

lilleyse commented 4 years ago
ebogo1 commented 3 years ago

Suggestions to improve modernizeShader from @genosage in #9743:

A better way [than using replaceInSourceString/Regex] may be assigning an identifier and use it as the keyword to avoid calling replace functions each draw call.

// ShaderCache.js
  var vertexShaderText = vertexShaderSource.createCombinedVertexShader(
    this._context
  );
  var fragmentShaderText = fragmentShaderSource.createCombinedFragmentShader(
    this._context
  );

  var keyword =
    vertexShaderText + fragmentShaderText + JSON.stringify(attributeLocations);
ptrgags commented 2 years ago

When implementing EXT_mesh_features in CesiumJS, one WebGL 1 hurdle that impacts performance is the lack of gl_VertexID.

Implicit feature ID attributes can be computed by offset + floor(gl_VertexID / repeat). However, in WebGL 1, we have no choice but to do this computation on the CPU and then upload an extra attribute

ptrgags commented 2 years ago

Another WebGL 1 limitation that limits our implementation of EXT_mesh_features: In this table in the MDN docs, it seems that even a highp int is only required to have 17 bits. So for feature IDs, I'll have to use a highp float to squeeze out a couple more bits. Also there's no uint type. In a shader,uint32 would be more ideal, but only guaranteed in WebGL 2

lilleyse commented 2 years ago

CloudCollection and voxels would benefit from 3D textures

lilleyse commented 2 years ago

Point cloud properties (e.g. classification) may have precision artifacts in WebGL 1 if accessed in the frag shader. WebGL 2 may fix this with the flat qualifier. See https://github.com/CesiumGS/3d-tiles-samples/pull/55#issuecomment-1218332158 for more details.

ggetz commented 1 year ago

Given the work done in https://github.com/CesiumGS/cesium/pull/10894, that should cover most of the actionable items in this issue. I'm going to close this and any specific items should be listed in their won issue, such as https://github.com/CesiumGS/cesium/issues/649 and https://github.com/CesiumGS/cesium/issues/630.