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

Update technique render states and support for KHR_blend #387

Merged
merged 12 commits into from
Jul 11, 2018
Merged

Conversation

ggetz
Copy link
Contributor

@ggetz ggetz commented Jun 27, 2018

Following #376, processes legacy technique render states, setting material doubleSided and alphaMode properties where neccisary, and moving blending functions to the EXT_blend extension.

@lilleyse As far as this PR, is there anything else I have to do to address material.alphaMode (specifically for MASK, and material.alphaCutoff)?

Part of #330

@ggetz ggetz requested a review from lilleyse June 27, 2018 17:59
Copy link
Contributor

@lilleyse lilleyse left a 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)
Copy link
Contributor

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.

@@ -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);
Copy link
Contributor

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.

module.exports = updateMaterialProperties;

function isStateEnabled(renderStates, state) {
return (renderStates.enable.indexOf(state) > -1);
Copy link
Contributor

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.

// 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)) {
Copy link
Contributor

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.

if (defined(renderStates.functions)) {
blendingForTechnique[techniqueIndex] = {
blendEquation: renderStates.functions.blendEquationSeparate,
blendFactors: renderStates.functions.blendFuncSeparate
Copy link
Contributor

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).

Copy link
Contributor Author

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.

materialProperties.doubleSided = true;
}

delete techniqueLegacy.state;
Copy link
Contributor

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)

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'm going to keep this here, if only because it allows this stage to run independently of later stages.


gltf = {
programs: {
program_0: {
Copy link
Contributor

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: []
Copy link
Contributor

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();
Copy link
Contributor

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.

if (defined(renderStates.functions)) {
blendingForTechnique[techniqueIndex] = {
blendEquation: renderStates.functions.blendEquationSeparate,
blendFactors: renderStates.functions.blendFuncSeparate
Copy link
Contributor

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?

@lilleyse
Copy link
Contributor

@lilleyse As far as this PR, is there anything else I have to do to address material.alphaMode (specifically for MASK, and material.alphaCutoff)?

I think what you have here is good!

@ggetz ggetz mentioned this pull request Jun 28, 2018
4 tasks
@ggetz
Copy link
Contributor Author

ggetz commented Jun 28, 2018

Thanks @lilleyse, updated !

I bumped KhronosGroup/glTF#1302 to ask about the prefix and if there will be any more updates.

Copy link
Contributor

@lilleyse lilleyse left a 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);
Copy link
Contributor

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.

Copy link
Contributor

@lilleyse lilleyse Jun 29, 2018

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));
Copy link
Contributor

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).

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 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.

Copy link
Contributor

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...

Copy link
Contributor Author

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

Copy link
Contributor

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() {
Copy link
Contributor

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.

@ggetz
Copy link
Contributor Author

ggetz commented Jun 29, 2018

@lilleyse Alright, updated! And the tests are now consistently passing.

@lilleyse
Copy link
Contributor

Cool - will merge once we get word on the extension name.

@ggetz ggetz changed the title Update technique render states and support for EXT_blend Update technique render states and support for KHR_blend Jul 11, 2018
@ggetz
Copy link
Contributor Author

ggetz commented Jul 11, 2018

@lilleyse Extension name updated to KHR_blend and updated this PR accordingly.

@lilleyse
Copy link
Contributor

Thanks @ggetz!

@lilleyse lilleyse merged commit 0e9e3f0 into 2.0 Jul 11, 2018
@lilleyse lilleyse deleted the ext-blend branch July 11, 2018 14:57
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.

2 participants