Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MSAA option for Webgl2 #10052

Merged
merged 37 commits into from Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
fbbe3f3
SceneFramebuffer MSAA
ebogo1 Jan 6, 2022
f86c95b
Invert classification
ebogo1 Jan 19, 2022
59d7d2b
Invert classification with changing numSamples, cleanup
ebogo1 Jan 21, 2022
b9ac432
Cleanup for shared attachments
ebogo1 Jan 21, 2022
bd876c5
blit globeDepth before OIT translucent commands
ebogo1 Jan 26, 2022
5532131
Fix OIT debug framebufer
ebogo1 Jan 26, 2022
f56f3e4
Fix translucent tile classification spec
ebogo1 Jan 26, 2022
4aa7b2e
Merge tag 'pre-let-const' into msaa-es6-merge
ebogo1 Jan 27, 2022
818e24e
Merge tag 'post-let-const' into msaa-es6-merge
ebogo1 Jan 27, 2022
d8977d6
Merge remote-tracking branch 'origin/main' into msaa-es6-merge
ebogo1 Jan 27, 2022
183782f
Add let-const in changed files
ebogo1 Jan 27, 2022
9209c99
MultisampleFramebuffer specs, doc cleanup
ebogo1 Jan 27, 2022
614c88c
Clean up renderTranslucentDepthForPick logic in Scene.js
ebogo1 Jan 27, 2022
d22ee26
Prettier, fix Webgl2 specs
ebogo1 Jan 28, 2022
cbd8c45
Disable multisampling during pick frames
ebogo1 Jan 28, 2022
a3ad889
Disable webgl2 in failing FramebufferManager test
ebogo1 Jan 28, 2022
b443feb
Remove extra createGuid() calls
ebogo1 Jan 28, 2022
8c26a13
Remove PassThrough stage from PostProcessStageCollection
ebogo1 Jan 28, 2022
dd0a7f8
Remove passThrough check in Scene.js
ebogo1 Jan 28, 2022
1301ddd
Check for dirty OIT frames
ebogo1 Jan 28, 2022
dd29f44
Check view.oit is defined
ebogo1 Jan 28, 2022
cd2b741
Scene.js prettier
ebogo1 Jan 31, 2022
1bfb1f1
Store a picking-only Framebuffer in GlobeDepth for pick frames
ebogo1 Feb 1, 2022
87997e2
Rename numberSamples to msaaSamples, fix TranslucentTileClassification
ebogo1 Feb 2, 2022
895c641
Fix HDR, add float and half float RenderbufferFormats
ebogo1 Feb 3, 2022
0fa4811
Add msaaSamples to constructor options, clamp value to GL_MAX_SAMPLES
ebogo1 Feb 3, 2022
c017f5a
Merge branch 'main' into manager-msaa
ebogo1 Feb 3, 2022
67cdee4
Prettier, update getWebGLStub for GL_MAX_SAMPLES
ebogo1 Feb 3, 2022
b982262
Merge branch 'manager-msaa' of github.com:CesiumGS/cesium into manage…
ebogo1 Feb 3, 2022
fd84fd9
Update CHANGES.md and add Sandcastle example
ebogo1 Feb 3, 2022
4c2d6f6
Sandcastle prettier
ebogo1 Feb 3, 2022
496b1c1
Remove blit before pickDepth update
ebogo1 Feb 4, 2022
a2fa0e4
Move MSAA Sandcastle to Showcases, change balloon view, fix MSAA gett…
ebogo1 Feb 17, 2022
06190d3
Do not set stencil buffer bit before blit
ebogo1 Feb 17, 2022
2a04209
Fix TranslucentTileClassificationSpec
ebogo1 Feb 17, 2022
fbf3de9
Pass undefined instead of GlobeDepth texture for failing unit test
ebogo1 Feb 17, 2022
ca82c10
Fix doc [skip ci]
lilleyse Feb 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
177 changes: 177 additions & 0 deletions Apps/Sandcastle/gallery/MSAA.html
@@ -0,0 +1,177 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"
/>
<meta name="description" content="Add MSAA to the scene." />
<meta name="cesium-sandcastle-labels" content="Post Processing" />
ebogo1 marked this conversation as resolved.
Show resolved Hide resolved
<title>Cesium Demo</title>
<script type="text/javascript" src="../Sandcastle-header.js"></script>
<script
type="text/javascript"
src="../../../Build/CesiumUnminified/Cesium.js"
nomodule
></script>
<script type="module" src="../load-cesium-es6.js"></script>
</head>
<body
class="sandcastle-loading"
data-sandcastle-bucket="bucket-requirejs.html"
>
<style>
@import url(../templates/bucket.css);
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar"></div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
"use strict";
//Sandcastle_Begin
const viewer = new Cesium.Viewer("cesiumContainer", {
terrainProvider: Cesium.createWorldTerrain(),
contextOptions: {
requestWebgl2: true,
},
});

const scene = viewer.scene;
if (!scene.msaaSupported) {
window.alert("This browser does not support MSAA.");
}

function createModel(url, height) {
const position = Cesium.Cartesian3.fromDegrees(
-123.0744619,
44.0503706,
height
);
const heading = Cesium.Math.toRadians(135);
const pitch = 0;
const roll = 0;
const hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);
const orientation = Cesium.Transforms.headingPitchRollQuaternion(
position,
hpr
);

const entity = viewer.entities.add({
name: url,
position: position,
orientation: orientation,
model: {
uri: url,
minimumPixelSize: 128,
maximumScale: 20000,
},
});
viewer.trackedEntity = entity;
}

const options = [
{
text: "Statue of Liberty",
onselect: function () {
viewer.entities.removeAll();
scene.primitives.removeAll();
scene.camera.setView({
destination: new Cesium.Cartesian3(
1331419.302230775,
-4656681.5022043325,
4136232.6465900405
),
orientation: new Cesium.HeadingPitchRoll(
6.032455545102689,
-0.056832496140112765,
6.282360923090216
),
endTransform: Cesium.Matrix4.IDENTITY,
});

scene.primitives.add(
new Cesium.Cesium3DTileset({
url: Cesium.IonResource.fromAssetId(75343),
})
);
},
},
{
text: "3D Tiles BIM",
onselect: function () {
viewer.entities.removeAll();
scene.primitives.removeAll();
const tileset = scene.primitives.add(
new Cesium.Cesium3DTileset({
url: Cesium.IonResource.fromAssetId(8564),
})
);
viewer.camera.setView({
destination: new Cesium.Cartesian3(
1234138.7804841248,
-5086063.633843134,
3633284.606361642
),
orientation: {
heading: 0.4304630387656614,
pitch: -0.16969316864215878,
roll: 6.283184816241989,
},
});
},
},
{
text: "Hot Air Balloon",
ebogo1 marked this conversation as resolved.
Show resolved Hide resolved
onselect: function () {
viewer.entities.removeAll();
scene.primitives.removeAll();
createModel(
"../../SampleData/models/CesiumBalloon/CesiumBalloon.glb",
1000.0
);
},
},
];

const samplingOptions = [
{
text: "MSAA off",
onselect: function () {
scene.msaaSamples = 1;
},
},
{
text: "MSAA 2x",
onselect: function () {
scene.msaaSamples = 2;
},
},
{
text: "MSAA 4x",
onselect: function () {
scene.msaaSamples = 4;
},
},
{
text: "MSAA 8x",
onselect: function () {
scene.msaaSamples = 8;
},
},
];

Sandcastle.addToolbarMenu(options);
Sandcastle.addToolbarMenu(samplingOptions);
//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
window.startupCalled = true;
startup(Cesium);
}
</script>
</body>
</html>
Binary file added Apps/Sandcastle/gallery/MSAA.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -4,6 +4,7 @@

##### Additions :tada:

- Added MSAA support for WebGL2. Enabled on viewer creation with the multisampling rate as the `msaaSamples` option and can be controlled through `Scene.msaaSamples`.
- glTF contents now use `ModelExperimental` by default. [#10055](https://github.com/CesiumGS/cesium/pull/10055)
- Added the ability to toggle back-face culling in `ModelExperimental`. [#10070](https://github.com/CesiumGS/cesium/pull/10070)
- Added `depthPlaneEllipsoidOffset` to Viewer and Scene constructors to address rendering artefacts below ellipsoid zero elevation. [#9200](https://github.com/CesiumGS/cesium/pull/9200)
Expand Down
14 changes: 14 additions & 0 deletions Source/Renderer/Context.js
Expand Up @@ -256,6 +256,8 @@ function Context(canvas, options) {
gl.MAX_VERTEX_UNIFORM_VECTORS
); // min: 128

ContextLimits._maximumSamples = gl.getParameter(gl.MAX_SAMPLES);

const aliasedLineWidthRange = gl.getParameter(gl.ALIASED_LINE_WIDTH_RANGE); // must include 1
ContextLimits._minimumAliasedLineWidth = aliasedLineWidthRange[0];
ContextLimits._maximumAliasedLineWidth = aliasedLineWidthRange[1];
Expand Down Expand Up @@ -598,6 +600,18 @@ Object.defineProperties(Context.prototype, {
},
},

/**
* <code>true</code> if the WebGL context supports multisample antialiasing. Requires
* WebGL2.
* @memberof Context.prototype
* @type {Boolean}
*/
msaa: {
get: function () {
return this._webgl2;
},
},

/**
* <code>true</code> if the OES_standard_derivatives extension is supported. This
* extension provides access to <code>dFdx</code>, <code>dFdy</code>, and <code>fwidth</code>
Expand Down
12 changes: 12 additions & 0 deletions Source/Renderer/ContextLimits.js
Expand Up @@ -21,6 +21,7 @@ const ContextLimits = {
_maximumTextureFilterAnisotropy: 0,
_maximumDrawBuffers: 0,
_maximumColorAttachments: 0,
_maximumSamples: 0,
_highpFloatSupported: false,
_highpIntSupported: false,
};
Expand Down Expand Up @@ -260,6 +261,17 @@ Object.defineProperties(ContextLimits, {
},
},

/**
* The maximum number of samples supported for multisampling.
* @memberof ContextLimits
* @type {Number}
*/
maximumSamples: {
get: function () {
return ContextLimits._maximumSamples;
},
},

/**
* High precision float supported (<code>highp</code>) in fragment shaders.
* @memberof ContextLimits
Expand Down
12 changes: 11 additions & 1 deletion Source/Renderer/Framebuffer.js
Expand Up @@ -33,7 +33,7 @@ function attachRenderbuffer(framebuffer, attachment, renderbuffer) {
* Framebuffers are used for render-to-texture effects; they allow us to render to
* textures in one pass, and read from it in a later pass.
*
* @param {Object} options The initial framebuffer attachments as shown in the example below. <code>context</code> is required. The possible properties are <code>colorTextures</code>, <code>colorRenderbuffers</code>, <code>depthTexture</code>, <code>depthRenderbuffer</code>, <code>stencilRenderbuffer</code>, <code>depthStencilTexture</code>, and <code>depthStencilRenderbuffer</code>.
* @param {Object} options The initial framebuffer attachments as shown in the example below. <code>context</code> is required. The possible properties are <code>colorTextures</code>, <code>colorRenderbuffers</code>, <code>depthTexture</code>, <code>depthRenderbuffer</code>, <code>stencilRenderbuffer</code>, <code>depthStencilTexture</code>, <code>depthStencilRenderbuffer</code>, and <code>destroyAttachments</code>.
*
* @exception {DeveloperError} Cannot have both color texture and color renderbuffer attachments.
* @exception {DeveloperError} Cannot have both a depth texture and depth renderbuffer attachment.
Expand Down Expand Up @@ -362,6 +362,16 @@ Framebuffer.prototype._unBind = function () {
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
};

Framebuffer.prototype.bindDraw = function () {
const gl = this._gl;
gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, this._framebuffer);
};

Framebuffer.prototype.bindRead = function () {
const gl = this._gl;
gl.bindFramebuffer(gl.READ_FRAMEBUFFER, this._framebuffer);
};

Framebuffer.prototype._getActiveColorAttachments = function () {
return this._activeColorAttachments;
};
Expand Down