-
Notifications
You must be signed in to change notification settings - Fork 250
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
Preserve the existence of non-default shader attributes #175
Conversation
@lilleyse Can we get this reviewed? It would be helpful to get this into |
I made some small fixes. Talked with @tfili offline. We aren't sure if these b3dm steps belong in the gltf-pipeline. The main tangle point is when normals are generated a new shader is built, and the |
@pjcozzi what do you think about keeping this in here vs. 3d-tiles-tools or some other repo? |
I've been thinking about this a bit, and it may be a better solution to just make sure that BATCHID never gets removed in the first place. In a more general sense, I think if we generate a new shader from modelMaterialsCommon, it should declare all of the semantics from the primitive, even if it doesn't use them in the shader. |
@lasalvavida Also one thing I noticed, the way the b3dm handling is currently done I can't call it from another node script. It would be nice if I could call a function in the pipeline like processJSONWithExtras, but all the removing of b3dm headers are in the |
…pipeline into support-b3dm
Please enter the commit message for your changes. Lines starting
I've finished the first part of this. In modelMaterialsCommon, we now preserve the existence of primitive semantics that don't exist by default in the generated shader. I think this is the correct approach and is not a 3d-tiles specific feature, since anyone doing dynamic shader modification using some non-default shader attribute would need this as well. I'm still looking at the integration of reading and writing b3dms. |
However, I think I'm going to revert the b3dm changes in this PR for now so we can get it and face normals merged sooner. After this change it would be pretty straightforward to go either path: gltf-pipeline supporting more file types or a 3d-tiles-tool that uses gltf-pipeline. |
Okay, this should be ready for a look. |
@@ -727,6 +729,85 @@ function lightDefaults(gltf) { | |||
} | |||
} | |||
|
|||
function getShaderVariable(accessor) { |
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 update the spacing in this file to be consistent with the rest of the codebase?
Is this already tested by other unit tests? |
Doesn't look like it, I'll add a test. |
if (defined(program)) { | ||
vertexShaderId = program.vertexShader; | ||
vertexShader = shaders[vertexShaderId]; | ||
} |
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.
Won't a lot of these checks always be true since it has gone through the modelMaterialsCommon? It should always have a material/technique/program. This also lets you simplify the loop.
var accessorId = attributes[semantic]; | ||
var accessor = accessors[accessorId]; | ||
var lowerCase = semantic.toLowerCase(); | ||
var attributeName = 'a_' + lowerCase; |
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.
For the a_batchId
case this will produce a_batchid
instead.
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.
So I don't think this matters. We replace the program.attribute
, technique.attribute
, technique.parameter
and in the shader with the same case, so Cesium should handle it correctly because of the semantic.
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.
In Cesium we build the shader with the assumption that it's called a_batchId
: https://github.com/AnalyticalGraphicsInc/cesium/blob/3d-tiles/Source/Scene/Cesium3DTileBatchTable.js#L498. Maybe this isn't a good assumption though - instead should we use whatever parameter has the BATCHID
semantic?
var pipelineExtras = vertexShader.extras._pipeline; | ||
var shaderText = pipelineExtras.source.toString(); | ||
shaderText = 'attribute ' + getShaderVariable(accessor) + ' ' + attributeName + ';\n' + shaderText; | ||
pipelineExtras.source = shaderText.toString(); |
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.
Already a string.
} | ||
} | ||
} | ||
} |
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.
If the function above be can be shortened enough, I wouldn't see a problem combining the two functions.
/* | ||
* If any primitives have semantics that aren't declared in the generated | ||
* shaders, we want to preserve them. | ||
*/ |
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.
Use //
here.
The |
@lilleyse The test has been added and I believe all the PR comments have been addressed. |
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.
@tfili just needs some small fixes.
for (var semantic in attributes) { | ||
if (attributes.hasOwnProperty(semantic)) { | ||
if (!defined(techniqueParameterForSemantic(technique, semantic))) { | ||
if (defined(technique)) { |
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.
Check isn't needed.
type: accessor.componentType | ||
}; | ||
technique.attributes[attributeName] = lowerCase; | ||
if (defined(program)) { |
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.
Same comment.
technique.attributes[attributeName] = lowerCase; | ||
if (defined(program)) { | ||
program.attributes.push(attributeName); | ||
if (defined(vertexShader)) { |
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.
Same comment.
var gltfClone = clone(gltf); | ||
addDefaults(gltfClone); | ||
|
||
// Uses the Cesium sun as its default light source |
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 this comment.
@lilleyse I think that should be everything. |
Edit: The scope of this pull request has changed and the title has been updated to reflect that. I've kept the old text here as a record.
Single b3dm files can be processed via the glTF pipeline with these changes. This is based on the hard-normals branch, so that is what it is diffed against currently.I am open to suggestions, but I think this is the best way to integrate b3dm support with gltf-pipeline given the current state of the public API, since it requires access to some of the internal machinery of gltf-pipeline.This makes it easy to write a script to process tilesets concurrently using gltf-pipeline.