-
Notifications
You must be signed in to change notification settings - Fork 476
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
Conversation
…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:
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 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 @@ | |||
{ |
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.
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"; |
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.
undo or add another test
|
||
if (CommonConstant != null) | ||
if (CommonConstant != null) |
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.
nit- make spaces tabs
case "pbrSpecularGlossiness": | ||
material.PbrSpecularGlossiness = PbrSpecularGlossiness.Deserialize(root, reader); | ||
break; | ||
case "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.
extensions are handled by the default case. You should let that process the extensions and hook up an extension handler via extension factory API.
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.
Also why are there two ways of processing KHR_materials_pbrSpecularGlossiness
…rials_pbrSpecularGlossiness schema Addressing PR feedback: https://github.com/KhronosGroup/UnityGLTF/pull/74/files Comment on this should be updated to reflect official schema comments from here: https://github.com/KhronosGroup/glTF/blob/master/extensions/Khronos/KHR_materials_pbrSpecularGlossiness/schema/glTF.KHR_materials_pbrSpecularGlossiness.schema.json
…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
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.
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 @@ | |||
{ |
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 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": |
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 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> |
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 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; |
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.
Comment on this should be updated to reflect official schema comments from here:
https://github.com/KhronosGroup/glTF/blob/master/extensions/Khronos/KHR_materials_pbrSpecularGlossiness/schema/glTF.KHR_materials_pbrSpecularGlossiness.schema.json
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.
k fixed this
{ | ||
readonly string GLTF_PATH = Directory.GetCurrentDirectory() + "/../../../../External/glTF/BoomBox.gltf"; | ||
{ | ||
readonly string GLTF_PATH = Directory.GetCurrentDirectory() + "/../../../../External/glTF/1501770225815.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.
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 |
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 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); |
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
@@ -64,6 +66,51 @@ public static List<T> ReadList<T>(this JsonReader reader, Func<T> deserializerFu | |||
return list; | |||
} | |||
|
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.
@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? |
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.
@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: |
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.
@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
* 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)
KHR_materials_pbrSpecularGlossiness support
There are quite a few areas where this could be improved, but it does load spec/gloss materials
Areas that still need work: