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

KHR_materials_pbrSpecularGlossiness support #74

Merged
merged 15 commits into from
Nov 6, 2017

Conversation

jm991
Copy link
Contributor

@jm991 jm991 commented Oct 7, 2017

There are quite a few areas where this could be improved, but it does load spec/gloss materials

Areas that still need work:

  • Add a test to GLTFSerialization project for the KHR_materials_pbrSpecularGlossiness test file I added (1501770225815.gltf)
  • Add toggle to GLTFComponent.cs that allows for optional addition of collision geometry and layer
  • Revert editor downgrade
  • Clean up test scene & reference approved spec gloss gltf file from GLTF samples
  • Double checked the full spec of KHR_materials_pbrSpecularGlossiness schema to make sure all properties are properly implemented in the Serialize/Deserialize methods
  • Removed PbrSpecularGlossiness GLTFProperty in favor of KHR_materials_pbrSpecularGlossiness Extension in GLTFSerialization project
  • in GLTFSerialization project Material.cs's case "extensions" might not be the best way to handle material extensions (is there a better way to iterate through the material extensions than the while loop I added?)

John McElmurray added 5 commits October 5, 2017 13:50
…BRSpecularGlossiness

Implement new class
GLTFSerialization/Schema/MaterialPBRSpecularGlossiness.cs (following
pattern set by MaterialPBRMetallicRoughness.cs)
Made sure the serialize/deserialize methods of PbrSpecularGlossiness can
read from the Remix3D extension "KHR_materials_pbrSpecularGlossiness"
declared in Remix3D gltf materials
…he existing PbrMetallicRoughness

Also added support in switch statement for the
"KHR_materials_pbrSpecularGlossiness" extension
* Update GLTFStandard.shader to support spec/gloss setup (create new
GLTFStandardSpecular.shader)
* Implement MaterialType.PbrSpecularGlossiness and
KHR_materials_pbrSpecularGlossines in GLTFSceneImporter.cs
** Add code to GLTFSceneImporter.cs@CreateMaterial(GLTF.Schema.Material
def, int materialIndex) to support the
KHR_materials_pbrSpecularGlossiness extension (follow pattern set by
def.PbrMetallicRoughness)
Test changes in GLTFComponent.cs to make sure Remix3D models' materials
load correctly:
@blgrossMS blgrossMS self-requested a review October 8, 2017 22:53
@blgrossMS blgrossMS self-assigned this Oct 8, 2017
Copy link

@blgrossMS blgrossMS left a comment

Choose a reason for hiding this comment

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

Thanks for adding this functionality! Your change looks pretty good. I left some comments.

Also make sure that the "areas that need work" listed above are completed before the PR is merged in.

@@ -0,0 +1,194 @@
{

Choose a reason for hiding this comment

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

File name should be more descriptive

{
readonly string GLTF_PATH = Directory.GetCurrentDirectory() + "/../../../../External/glTF/BoomBox.gltf";
{
readonly string GLTF_PATH = Directory.GetCurrentDirectory() + "/../../../../External/glTF/1501770225815.gltf";

Choose a reason for hiding this comment

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

undo or add another test


if (CommonConstant != null)
if (CommonConstant != null)

Choose a reason for hiding this comment

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

nit- make spaces tabs

case "pbrSpecularGlossiness":
material.PbrSpecularGlossiness = PbrSpecularGlossiness.Deserialize(root, reader);
break;
case "extensions":

Choose a reason for hiding this comment

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

extensions are handled by the default case. You should let that process the extensions and hook up an extension handler via extension factory API.

Choose a reason for hiding this comment

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

Also why are there two ways of processing KHR_materials_pbrSpecularGlossiness

@sbtron sbtron added the 0.5 label Oct 18, 2017
John McElmurray added 6 commits October 24, 2017 14:28
…sion KHR_materials_pbrSpecularGlossinessExtension.cs
…l/74/files

* Moved KHR_materials_pbrSpecularGlossinessExtension files from Schema
to Extensions folder
* Added logic to GLTFProperty to deserialize using the
KHR_materials_pbrSpecularGlossinessExtensionFactory if the extension
name is found in the file
* Removed specular gloss code from Material.cs since the spec-gloss
material is now an extension
* Removed MaterialPBRSpecularGlossiness.cs since it's now an extension
instead of a GLTFProperty
* Removed GLTFSceneImporter.MaterialType.PbrSpecularGloss in favor of
GLTFSceneImporter.MaterialType.KHR_materials_pbrSpecularGlossiness
* GLTFSceneImporter now accesses the KHR spec gloss extension properly
* Updated GLTFSerialization.dll in Unity project
* Renamed 1501770225815.gltf to a more descriptive filename
* Cleaned up edits I had made to GLTFLoaderTest.cs
Copy link
Contributor Author

@jm991 jm991 left a comment

Choose a reason for hiding this comment

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

http://answers.unity3d.com/questions/970290/emission-at-run-time-works-in-editor-but-not-in-bu.html

We ran into this when using UnityGLTF in our project. The fix to make Unity compile all the variants of the Standard shader was to include a Material in the Resources folder that had a texture in all the material slots. I can add this too so that others won't be tripped up by this.

@@ -0,0 +1,194 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a test file from remix3d.com that uses KHR_materials_pbrSpecularGlossiness. I plan to add a few more complex scenes to further test the implementation before checking in

case "pbrSpecularGlossiness":
material.PbrSpecularGlossiness = PbrSpecularGlossiness.Deserialize(root, reader);
break;
case "extensions":
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this the correct way to parse the material extension JSON? I wasn't sure if the second while (reader.Read() && reader.TokenType == JsonToken.PropertyName) was the best way to iterate thru the material extensions to find KHR_materials_pbrSpecularGlossiness

@@ -15,6 +15,12 @@ public class Material : GLTFChildOfRootProperty
/// </summary>
public PbrMetallicRoughness PbrMetallicRoughness;

/// <summary>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I rename MaterialPBRSpecularGlossiness.cs to KHRMaterialPBRSpecularGlossiness.cs, this will be updated to reflect that change.

I noticed UnityGLTF/Assets/UnityGLTF/Scripts/GLTFSceneImporter.cs.MaterialType included PbrSpecularGlossiness, so I wasn't sure whether to add public PbrSpecularGlossiness as a new Material or public KHR_materials_pbrSpecularGlossiness

/// <summary>
/// The color of the material's specular highlights.
/// </summary>
public Vector3 SpecularFactor = Vector3.One;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

k fixed this

{
readonly string GLTF_PATH = Directory.GetCurrentDirectory() + "/../../../../External/glTF/BoomBox.gltf";
{
readonly string GLTF_PATH = Directory.GetCurrentDirectory() + "/../../../../External/glTF/1501770225815.gltf";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

rename this to be more clear that it's a test for KHR_materials_pbrSpecularGlossiness & run it as a separate test instead of commenting it out in this test

@@ -1 +1 @@
m_EditorVersion: 5.6.1f1
m_EditorVersion: 5.6.0f3
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 won't check in this editor downgrade - we are using this version of Unity on my team

loader.SetShaderForMaterialType(GLTFSceneImporter.MaterialType.PbrMetallicRoughness, GLTFStandard);
loader.SetShaderForMaterialType(GLTFSceneImporter.MaterialType.CommonConstant, GLTFConstant);
loader.SetShaderForMaterialType(GLTFSceneImporter.MaterialType.PbrMetallicRoughness, GLTFStandard);
loader.SetShaderForMaterialType(GLTFSceneImporter.MaterialType.PbrSpecularGlossiness, GLTFStandardSpecular);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove this

@@ -64,6 +66,51 @@ public static List<T> ReadList<T>(this JsonReader reader, Func<T> deserializerFu
return list;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MSblgross I added a bunch of new utility methods to this class that will help Extensions deserialize JTokens.
E.g., we already had JsonReader methods, like:
Color ReadAsRGBAColor(this JsonReader reader)
So I added JToken methods, such as:
DeserializeAsColor(this JToken token)

@@ -64,6 +66,51 @@ public static List<T> ReadList<T>(this JsonReader reader, Func<T> deserializerFu
return list;
}

// TODO: (CR) is it ok to pass the GLTFRoot here and inclue using GLTF.Schema?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MSblgross is it ok to pass the GLTFRoot to DeserializeAsTexture and include reference to using GLTF.Schema?

@@ -27,13 +29,13 @@ public static new NormalTextureInfo Deserialize(GLTFRoot root, JsonReader reader

switch (curProp)
{
case "index":
case INDEX:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MSblgross I tried to go through the code and remove any hardcoded strings that appeared in a lot of places, such as "index" or "texCoord", hopefully that's ok to do

John McElmurray added 2 commits October 26, 2017 10:25
* Added spec gloss Unity test scene (uses existing spec gloss Lantern
GLTF test files)
* Added UWP test for spec gloss
* Modifed test for spec gloss to use Lantern and deleted my test file (a
file I had downloaded off Remix 3D)
* Added spec gloss Lantern GLTF test files to GLTFSerialization project
* Added nullref checks to spec gloss extension deserialization for
assets that don't have all spec gloss properties defined (threw
exception previously)
* Added correct default values for spec gloss extension
* Added README for compiling shader variants in Standalone Unity player,
as well as a sample material and shader variant file to force shader
variant compilation
* Updated GLTFSerialization DLLs in Unity
* Added optional mesh collider flag when creating GameObjects from GLTF
files
* Deleted GLTFSceneImporter.cs.orig (looks like someone checked in a
partial merge)
@jm991 jm991 changed the title KHR_materials_pbrSpecularGlossiness and PbrSpecularGlossiness support KHR_materials_pbrSpecularGlossiness support Oct 26, 2017
@blgrossMS blgrossMS merged commit 516134c into KhronosGroup:master Nov 6, 2017
github-actions bot pushed a commit to Rhinox-Training/UnityGLTF that referenced this pull request Nov 9, 2022
KHR_materials_pbrSpecularGlossiness support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants