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

Geometry offset attribute #6607

Merged
merged 16 commits into from
Jun 8, 2018
Merged

Geometry offset attribute #6607

merged 16 commits into from
Jun 8, 2018

Conversation

hpinkos
Copy link
Contributor

@hpinkos hpinkos commented May 21, 2018

Part of #6434

  • Added a new offsetAttribute per vertex attribute to CorridorGeometry, EllipseGeometry, PolygonGeometry and RectangleGeometry. This is a boolean attribute used to specify which vertices the offset should be applied to.
  • Added OffsetGeometryInstanceAttribute which has a Cartesian3 value used to apply an offset to geometry vertices
  • Added Primitive._appendOffsetToShader which modifies the shader to add the offset vector to each vertex where applyOffset is true

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@cesium-concierge
Copy link

Signed CLA is on file.

@hpinkos, thanks for the pull request! Maintainers, we have a signed CLA from @hpinkos, so you can review this at any time.

⚠️ I noticed that CHANGES.md has not been updated. If this change updates the public API in any way, fixes a bug, or makes any non-trivial update, please add a bullet point to CHANGES.md and comment on this pull request so we know it was updated. For more info, see the Pull Request Guidelines.


I am a bot who helps you make Cesium awesome! Contributions to my configuration are welcome.

🌍 🌎 🌏

var wc = primitive._boundingSphereWC[i];

//TODO: associate BS with instance. Maybe be multiple BS for splitlongitude
var offset = primitive._batchTable.getBatchedAttribute(i, offsetIndex, new Cartesian3());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bagnell I could use some suggestions for what to do here. Sometimes there are two bounding spheres for one geometry instance when it's split across the IDL. Indexing into getBatchedAttribute with i doesn't work in this case.

@hpinkos
Copy link
Contributor Author

hpinkos commented Jun 6, 2018

@bagnell This is ready for review. I still need to update the specs, but I'll do that after you take a closer look at this

var origBS = BoundingSphere.clone(boundingSphere, offsetBoundingSphereScratch1);
var offsetBS = BoundingSphere.clone(boundingSphere, offsetBoundingSphereScratch2);
offsetBS.center = Cartesian3.add(offsetBS.center, offset, offsetBS.center);
boundingSphere = BoundingSphere.union(origBS, offsetBS, boundingSphere);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the original bounding sphere and have the primitive update them after creation. The union here could cause the bounding sphere to be huge and we could lose benefits from culling.

@@ -1986,6 +2006,26 @@ define([
Cartesian3.pack(direction, currentAttributes.extrudeDirection.values, insertedIndex * 3);
}

if (defined(applyOffsets)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't #6644 handle this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, since it's a boolean property we don't want to interpolate it. The value should always be 1.0 or 0.0. It took me forever to figure out the correct values here, I really don't think it can be generalized.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't you interpolate it? If all vertices have a 0.0, the interpolation will be 0.0. If all vertices have 1.0, the interpolation will be 1.0, If the interpolation is between 0.0 and 1.0, it should be 1.0 so set it to Math.ceil(interpolatedValue).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I figured it out. It was just an epsilon problem that was causing the barycentric interpolation to go wrong

@@ -1949,7 +1965,11 @@ define([
var p1Scratch = new Cartesian3();
var p2Scratch = new Cartesian3();
var barycentricScratch = new Cartesian3();
function computeTriangleAttributes(i0, i1, i2, point, positions, normals, tangents, bitangents, texCoords, extrudeDirections, currentAttributes, customAttributeNames, customAttributesLength, allAttributes, insertedIndex) {
var s0Scratch = new Cartesian2();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't used.

@@ -2233,13 +2277,31 @@ define([
}

var offsetPoint = Cartesian3.add(intersection, offset, offsetPointScratch);
insertSplitPoint(p0Attributes, p0Indices, p0IndexMap, indices, i, p0);
insertSplitPoint(p0Attributes, p0Indices, p0IndexMap, indices, -1, offsetPoint);
if (defined(applyOffset)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make something similar to computeTriangleAttributes or make it more general?

@@ -0,0 +1,151 @@
define([
'./Check',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace.

'use strict';

/**
* Value and type information for per-instance geometry attribute that determines if the geometry instance has a distance display condition.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be private since GeometryOffsetAttribute is.

return vertexShaderSource;
}

var attr = 'attribute float batchId;\nattribute float applyOffset;';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After a new line in a string, continue it on the next line. Same below.

var attr = 'attribute float batchId;\nattribute float applyOffset;';
var modifiedShader = vertexShaderSource.replace(/attribute\s+float\s+batchId;/g, attr);

var str = 'vec4 p = czm_computePosition();\n p = p + vec4(czm_batchTable_offset(batchId) * applyOffset, 0.0);';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is p always defined here? I would capture the variable name just to be safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's always defined? At least we don't check if it's defined in any of the other shaders that use czm_computePosition

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I used the wrong term. The value returned by czm_computePosition is always defined (it must be since it's GLSL). I meant you should use regex captures to get the name of the variable, in this case p.

}

if (result.length !== primitive._boundingSpheres.length) {
throw new DeveloperError('whoops');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this ever happened?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet. I put this in here as I was debugging just to check, but I'll remove it before merging this into master

var origBS = BoundingSphere.clone(boundingSphere, offsetBoundingSphereScratch1);
var offsetBS = BoundingSphere.clone(boundingSphere, offsetBoundingSphereScratch2);
offsetBS.center = Cartesian3.add(offsetBS.center, offset, offsetBS.center);
boundingSphere = BoundingSphere.union(origBS, offsetBS, boundingSphere);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should take into account what the offset type is. If it's ALL, then the whole bounding sphere moves. If it's TOP, then it would be the union like you have here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what the extend param to the function does

var modelMatrix = primitive.modelMatrix;
var offset = properties.offset;
if (defined(offset)) {
boundingSphere.center = Cartesian3.add(Cartesian3.fromArray(offset, 0, offsetScratch), boundingSphere.center, boundingSphere.center);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -45,6 +47,11 @@ define([
var modelMatrix = instances[0].modelMatrix;

for (i = 1; i < length; ++i) {
var offset = instances[i].attributes.offset;
if (defined(offset)) {
toWorld = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break things that depend of changing the model matrix, like boxes and ellipsoids.

@bagnell
Copy link
Contributor

bagnell commented Jun 6, 2018

I see 7 test failures with ClassificationPrimitive, GroundPrimitive and Primitive.

@bagnell bagnell closed this Jun 6, 2018
@bagnell bagnell reopened this Jun 6, 2018
@bagnell
Copy link
Contributor

bagnell commented Jun 6, 2018

@hpinkos That's all I have for now. I didn't run through and test all of the geometry. Let me know when this is ready again and I will.

@hpinkos
Copy link
Contributor Author

hpinkos commented Jun 7, 2018

Thanks for the feedback @bagnell! This is ready for a full review now


var str = 'vec4 $1 = czm_computePosition();\n';
str += ' $1 = $1 + vec4(czm_batchTable_offset(batchId) * applyOffset, 0.0);';
modifiedShader = modifiedShader.replace(/vec4\s+([A-Za-z]+)\s+=\s+czm_computePosition\(\);/g, str);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add 0-9 and _ to the variable regex.

@@ -274,6 +276,8 @@ define([
var length = instances.length;
var pickOffsets;

var offsetInstanceExtend;// = new Array(length);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment.

@@ -0,0 +1,18 @@
define([
'../Core/freezeObject'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace

@bagnell
Copy link
Contributor

bagnell commented Jun 8, 2018

@hpinkos Just those minor comments and this is ready to merge.

@hpinkos
Copy link
Contributor Author

hpinkos commented Jun 8, 2018

Thanks @bagnell! Ready

@bagnell bagnell merged commit f73a9f6 into master Jun 8, 2018
@bagnell bagnell deleted the offset-attribute branch June 8, 2018 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants