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

Add support for KHR_materials_unlit #6977

Merged
merged 9 commits into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Change Log
* Improved support for polygon entities using `perPositionHeight`, including supporting vertical polygons. This also improves KML compatibility. [#6791](https://github.com/AnalyticalGraphicsInc/cesium/pull/6791)
* Added `Cartesian3.midpoint` to compute the midpoint between two `Cartesian3` positions [#6836](https://github.com/AnalyticalGraphicsInc/cesium/pull/6836)
* Added `equalsEpsilon` methods to `OrthographicFrustum`, `PerspectiveFrustum`, `OrthographicOffCenterFrustum` and `PerspectiveOffCenterFrustum`.
* Added support for glTF extension [KHR_materials_unlit](https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit) [#6977](https://github.com/AnalyticalGraphicsInc/cesium/pull/6977).
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this isn't targeting master, as the changelog is 2 versions out of date as of today's release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'm merging into #6805 since that PR moves gltfPipeline from ThirdParty into Cesium core.

Copy link
Contributor

Choose a reason for hiding this comment

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

@OmarShehata Create a section for October's release and move your changes there. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see the problem now. I moved it into a new section for October. Thanks for pointing this out!


##### Deprecated :hourglass_flowing_sand:
* Support for 3D Tiles `content.url` is deprecated to reflect updates to the [3D Tiles spec](https://github.com/AnalyticalGraphicsInc/3d-tiles/pull/301). Use `content.uri instead`. Support for `content.url` will remain for backwards compatibility. [#6744](https://github.com/AnalyticalGraphicsInc/cesium/pull/6744)
Expand Down
3 changes: 2 additions & 1 deletion Source/Scene/ModelUtility.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ define([
'KHR_draco_mesh_compression' : true,
'KHR_materials_common' : true,
'KHR_techniques_webgl' : true,
'WEB3D_quantized_attributes' : true
'WEB3D_quantized_attributes' : true,
'KHR_materials_unlit' : true
};

ModelUtility.checkSupportedExtensions = function(extensionsRequired) {
Expand Down
34 changes: 23 additions & 11 deletions Source/Scene/processPbrMetallicRoughness.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ define([
var hasNormals = false;
var hasTangents = false;
var hasTexCoords = false;
var isUnlit = false;

if (defined(primitiveInfo)) {
skinningInfo = primitiveInfo.skinning;
Expand Down Expand Up @@ -181,6 +182,12 @@ define([
}
};

if (defined(material.extensions) && defined(material.extensions.KHR_materials_unlit)) {
isUnlit = true;
hasNormals = false;
hasTangents = false;
}

if (hasNormals) {
techniqueUniforms.u_normalMatrix = {
semantic : 'MODELVIEWINVERSETRANSPOSE',
Expand Down Expand Up @@ -628,19 +635,22 @@ define([
fragmentShader += ' vec3 color = baseColor;\n';
}

if (defined(generatedMaterialValues.u_occlusionTexture)) {
fragmentShader += ' color *= texture2D(u_occlusionTexture, ' + v_texcoord + ').r;\n';
}
if (defined(generatedMaterialValues.u_emissiveTexture)) {
fragmentShader += ' vec3 emissive = SRGBtoLINEAR3(texture2D(u_emissiveTexture, ' + v_texcoord + ').rgb);\n';
if (defined(generatedMaterialValues.u_emissiveFactor)) {
fragmentShader += ' emissive *= u_emissiveFactor;\n';
// Ignore occlusion and emissive when unlit
if (!isUnlit) {
if (defined(generatedMaterialValues.u_occlusionTexture)) {
fragmentShader += ' color *= texture2D(u_occlusionTexture, ' + v_texcoord + ').r;\n';
}
fragmentShader += ' color += emissive;\n';
}
else if (defined(generatedMaterialValues.u_emissiveFactor)) {
fragmentShader += ' color += u_emissiveFactor;\n';
if (defined(generatedMaterialValues.u_emissiveTexture)) {
fragmentShader += ' vec3 emissive = SRGBtoLINEAR3(texture2D(u_emissiveTexture, ' + v_texcoord + ').rgb);\n';
if (defined(generatedMaterialValues.u_emissiveFactor)) {
fragmentShader += ' emissive *= u_emissiveFactor;\n';
}
fragmentShader += ' color += emissive;\n';
}
else if (defined(generatedMaterialValues.u_emissiveFactor)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

else and else if blocks go on the same line as the previous brace } else if Refer to the https://github.com/AnalyticalGraphicsInc/cesium/tree/master/Documentation/Contributors/CodingGuide

fragmentShader += ' color += u_emissiveFactor;\n';
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please run the auto-formatter on your blocks of changed code so that the source file stays consistently formatted.

}

// Final color
fragmentShader += ' color = LINEARtoSRGB(color);\n';
Expand All @@ -660,6 +670,8 @@ define([
}
fragmentShader += '}\n';

console.log(fragmentShader);
Copy link
Contributor

Choose a reason for hiding this comment

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

Accidental debug code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, sorry. Thanks for catching that!


// Add shaders
var vertexShaderId = addToArray(shaders, {
type : WebGLConstants.VERTEX_SHADER,
Expand Down