-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
@hpinkos, thanks for the pull request! Maintainers, we have a signed CLA from @hpinkos, so you can review this at any time.
I am a bot who helps you make Cesium awesome! Contributions to my configuration are welcome. 🌍 🌎 🌏 |
Source/Scene/Primitive.js
Outdated
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()); |
There was a problem hiding this comment.
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.
@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 |
Source/Core/GeometryPipeline.js
Outdated
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); |
There was a problem hiding this comment.
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.
Source/Core/GeometryPipeline.js
Outdated
@@ -1986,6 +2006,26 @@ define([ | |||
Cartesian3.pack(direction, currentAttributes.extrudeDirection.values, insertedIndex * 3); | |||
} | |||
|
|||
if (defined(applyOffsets)) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
.
There was a problem hiding this comment.
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
Source/Core/GeometryPipeline.js
Outdated
@@ -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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These aren't used.
Source/Core/GeometryPipeline.js
Outdated
@@ -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)) { |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
Source/Scene/Primitive.js
Outdated
return vertexShaderSource; | ||
} | ||
|
||
var attr = 'attribute float batchId;\nattribute float applyOffset;'; |
There was a problem hiding this comment.
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.
Source/Scene/Primitive.js
Outdated
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);'; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
Source/Scene/Primitive.js
Outdated
} | ||
|
||
if (result.length !== primitive._boundingSpheres.length) { | ||
throw new DeveloperError('whoops'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has this ever happened?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Source/Scene/Primitive.js
Outdated
var modelMatrix = primitive.modelMatrix; | ||
var offset = properties.offset; | ||
if (defined(offset)) { | ||
boundingSphere.center = Cartesian3.add(Cartesian3.fromArray(offset, 0, offsetScratch), boundingSphere.center, boundingSphere.center); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be the same as https://github.com/AnalyticalGraphicsInc/cesium/pull/6607/files#diff-74b9ecf8fb5af0a22b41c6d17e3a8aadR1892
Source/Scene/PrimitivePipeline.js
Outdated
@@ -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; |
There was a problem hiding this comment.
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.
I see 7 test failures with |
@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. |
Thanks for the feedback @bagnell! This is ready for a full review now |
Source/Scene/Primitive.js
Outdated
|
||
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); |
There was a problem hiding this comment.
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.
Source/Scene/PrimitivePipeline.js
Outdated
@@ -274,6 +276,8 @@ define([ | |||
var length = instances.length; | |||
var pickOffsets; | |||
|
|||
var offsetInstanceExtend;// = new Array(length); |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whitespace
@hpinkos Just those minor comments and this is ready to merge. |
Thanks @bagnell! Ready |
Part of #6434
offsetAttribute
per vertex attribute toCorridorGeometry
,EllipseGeometry
,PolygonGeometry
andRectangleGeometry
. This is a boolean attribute used to specify which vertices the offset should be applied to.OffsetGeometryInstanceAttribute
which has aCartesian3
value used to apply an offset to geometry verticesPrimitive._appendOffsetToShader
which modifies the shader to add the offset vector to each vertex whereapplyOffset
is true