-
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
Update technique render states and support for KHR_blend #387
Conversation
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.
Thanks @ggetz!
Maybe also check in on KhronosGroup/glTF#1302 and let everyone know that we plan on supporting the extension in gltf-pipeline and cesium, and whether more updates are expected.
README.md
Outdated
@@ -13,7 +13,7 @@ Content pipeline tools for optimizing [glTF](https://www.khronos.org/gltf) asset | |||
Supports common operations including: | |||
* Converting glTF to glb (and reverse) | |||
* Saving buffers/textures as embedded or separate files | |||
* Converting glTF 1.0 models to glTF 2.0 (using the [KHR_techniques_webgl](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_techniques_webgl) extension) | |||
* Converting glTF 1.0 models to glTF 2.0 (using the [KHR_techniques_webgl](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_techniques_webgl) and [EXT_blend](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/EXT_blend) extensions) |
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 EXT_blend
expected to be the final name, or will it be KHR_blend
? It seems like a bunch of extension proposals have that prefix but I'm not sure whether that's the actual prefix or just a placeholder.
lib/updateVersion.js
Outdated
@@ -841,6 +842,8 @@ function glTF10to20(gltf) { | |||
underscoreApplicationSpecificSemantics(gltf); | |||
// Clamp camera parameters | |||
clampCameraParameters(gltf); | |||
// Update material properties and add blending functions to EXT_blend extension, removing technique render states | |||
updateMaterialProperties(gltf); |
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.
The name of this helper could be more descriptive. Maybe moveTechniqueStatesToExtension
.
Technically some properties are being set to the material and not the extension, but I think that's ok.
lib/updateMaterialProperties.js
Outdated
module.exports = updateMaterialProperties; | ||
|
||
function isStateEnabled(renderStates, state) { | ||
return (renderStates.enable.indexOf(state) > -1); |
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.
Will need to check if enable
is defined first.
lib/updateMaterialProperties.js
Outdated
// If BLEND is enabled, the material should have alpha mode BLEND | ||
// and save the blend functions to the EXT_blend extension | ||
if (isStateEnabled(renderStates, WebGLConstants.BLEND) | ||
|| defined(renderStates.blendEquationSeparate) || defined(renderStates.blendFuncSeparate)) { |
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.
Should be renderStates.functions.blendEquationSeparate
and renderStates.functions.blendFuncSeparate
like it is below.
lib/updateMaterialProperties.js
Outdated
if (defined(renderStates.functions)) { | ||
blendingForTechnique[techniqueIndex] = { | ||
blendEquation: renderStates.functions.blendEquationSeparate, | ||
blendFactors: renderStates.functions.blendFuncSeparate |
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.
The draft extension doesn't say, but both blendEquation
and blendFactors
are probably required. Use default values if blendEquationSeparate
or blendFuncSeparate
are undefined. (the glTF 1.0 defaults are probably good).
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.
Actually they are required by the extension, so I should definitely provide defaults.
lib/updateMaterialProperties.js
Outdated
materialProperties.doubleSided = true; | ||
} | ||
|
||
delete techniqueLegacy.state; |
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.
Should be techniqueLegacy.states
(Though I don't think it actually matters since it won't be included in the final KHR_techniques_webgl
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.
I'm going to keep this here, if only because it allows this stage to run independently of later stages.
|
||
gltf = { | ||
programs: { | ||
program_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.
To make this more condensed clone the previous gltf and add the new state.
This can probably be done to make all the tests shorter. Have a single glTF above the tests that is cloned/edited by each test.
} | ||
], | ||
extensionsUsed: [], | ||
extensionsRequired: [] |
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 these two if they aren't used.
|
||
var material = gltfWithBlendExtension.materials[0]; | ||
expect(material.alphaMode).toBeUndefined(); | ||
expect(material.extensions).toBeDefined(); |
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.
At first I was confused why the extensions were defined, and then noticed KHR_techniques_webgl
. Maybe just remove that.
lib/updateMaterialProperties.js
Outdated
if (defined(renderStates.functions)) { | ||
blendingForTechnique[techniqueIndex] = { | ||
blendEquation: renderStates.functions.blendEquationSeparate, | ||
blendFactors: renderStates.functions.blendFuncSeparate |
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.
It looks like gltf 1 has more blend factors than the draft extension.
ZERO
ONE
SRC_COLOR
ONE_MINUS_SRC_COLOR
SRC_ALPHA
ONE_MINUS_SRC_ALPHA
DST_ALPHA
ONE_MINUS_DST_ALPHA
DST_COLOR
ONE_MINUS_DST_COLOR
CONSTANT_COLOR
ONE_MINUS_CONSTANT_COLOR
CONSTANT_ALPHA
ONE_MINUS_CONSTANT_ALPHA
SRC_ALPHA_SATURATE
vs
ZERO
ONE
SRC_COLOR
ONE_MINUS_SRC_COLOR
SRC_ALPHA
ONE_MINUS_SRC_ALPHA
DST_ALPHA
ONE_MINUS_DST_ALPHA
DST_COLOR
ONE_MINUS_DST_COLOR
If one of the old ones are encountered maybe just switch to the default value? Or not add the extension?
I think what you have here is good! |
Thanks @lilleyse, updated ! I bumped KhronosGroup/glTF#1302 to ask about the prefix and if there will be any more updates. |
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.
The updates look good, just some small comments on the tests.
|
||
describe('updateMaterialProperties', function() { | ||
it('sets material.doubleSided property if CULL_FACE is not enabled', function () { | ||
var gltfWithUpdatedMaterials = moveTechniqueRenderStates(gltf); |
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.
gltf
should be cloned first.
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 may also be causing intermittent failures when tests are run in random order, which I think jasmine does now?
var material = gltfWithUpdatedMaterials.materials[0]; | ||
expect(material.doubleSided).toBeUndefined(); | ||
|
||
var gltfDoubleSided = JSON.parse(JSON.stringify(gltf)); |
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.
Maybe use Cesium's clone
function instead. clone(gltf, 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.
I was having issues with the depth of the cloning when it came to arrays (even when using the deep clone argument). This was much more reliable.
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 that a Cesium bug? I don't think that should be happening...
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.
The documentation isn't partially clear on what the behavior should be: https://cesiumjs.org/Cesium/Build/Documentation/clone.html
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.
Alright, if this way works consistently then let's go with it.
] | ||
}; | ||
|
||
describe('updateMaterialProperties', function() { |
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.
Update the name to moveTechniqueToRenderStates
.
@lilleyse Alright, updated! And the tests are now consistently passing. |
Cool - will merge once we get word on the extension name. |
@lilleyse Extension name updated to |
Thanks @ggetz! |
Following #376, processes legacy technique render states, setting material
doubleSided
andalphaMode
properties where neccisary, and moving blending functions to theEXT_blend
extension.@lilleyse As far as this PR, is there anything else I have to do to address
material.alphaMode
(specifically forMASK
, andmaterial.alphaCutoff
)?Part of #330