-
Notifications
You must be signed in to change notification settings - Fork 476
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from jm991/master
KHR_materials_pbrSpecularGlossiness support
- Loading branch information
Showing
38 changed files
with
2,104 additions
and
788 deletions.
There are no files selected for viewing
Binary file not shown.
525 changes: 525 additions & 0 deletions
525
GLTFSerialization/External/glTF-pbrSpecularGlossiness/Lantern.gltf
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file added
BIN
+4.25 MB
GLTFSerialization/External/glTF-pbrSpecularGlossiness/Lantern_baseColor.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.84 MB
GLTFSerialization/External/glTF-pbrSpecularGlossiness/Lantern_diffuse.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+165 KB
GLTFSerialization/External/glTF-pbrSpecularGlossiness/Lantern_emissive.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.79 MB
GLTFSerialization/External/glTF-pbrSpecularGlossiness/Lantern_normal.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2 MB
...Serialization/External/glTF-pbrSpecularGlossiness/Lantern_roughnessMetallic.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.55 MB
...erialization/External/glTF-pbrSpecularGlossiness/Lantern_specularGlossiness.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
...erialization/GLTFSerialization/Extensions/KHR_materials_pbrSpecularGlossinessExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using GLTF.Math; | ||
using GLTF.Schema; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace GLTF.Schema | ||
{ | ||
/// <summary> | ||
/// glTF extension that defines the specular-glossiness | ||
/// material model from Physically-Based Rendering (PBR) methodology. | ||
/// | ||
/// Spec can be found here: | ||
/// https://github.com/KhronosGroup/glTF/tree/master/extensions/Khronos/KHR_materials_pbrSpecularGlossiness | ||
/// </summary> | ||
public class KHR_materials_pbrSpecularGlossinessExtension : Extension | ||
{ | ||
public static readonly Vector3 SPEC_FACTOR_DEFAULT = new Vector3(0.2f, 0.2f, 0.2f); | ||
public static readonly double GLOSS_FACTOR_DEFAULT = 0.5d; | ||
|
||
/// <summary> | ||
/// The RGBA components of the reflected diffuse color of the material. | ||
/// Metals have a diffuse value of [0.0, 0.0, 0.0]. | ||
/// The fourth component (A) is the alpha coverage of the material. | ||
/// The <see cref="Material.AlphaMode"/> property specifies how alpha is interpreted. | ||
/// The values are linear. | ||
/// </summary> | ||
public Color DiffuseFactor = Color.White; | ||
|
||
/// <summary> | ||
/// The diffuse texture. | ||
/// This texture contains RGB(A) components of the reflected diffuse color of the material in sRGB color space. | ||
/// If the fourth component (A) is present, it represents the alpha coverage of the | ||
/// material. Otherwise, an alpha of 1.0 is assumed. | ||
/// The <see cref="Material.AlphaMode"/> property specifies how alpha is interpreted. | ||
/// The stored texels must not be premultiplied. | ||
/// </summary> | ||
public TextureInfo DiffuseTexture; | ||
|
||
/// <summary> | ||
/// The specular RGB color of the material. This value is linear | ||
/// </summary> | ||
public Vector3 SpecularFactor = SPEC_FACTOR_DEFAULT; | ||
|
||
/// <summary> | ||
/// The glossiness or smoothness of the material. | ||
/// A value of 1.0 means the material has full glossiness or is perfectly smooth. | ||
/// A value of 0.0 means the material has no glossiness or is completely rough. | ||
/// This value is linear. | ||
/// </summary> | ||
public double GlossinessFactor = GLOSS_FACTOR_DEFAULT; | ||
|
||
/// <summary> | ||
/// The specular-glossiness texture is RGBA texture, containing the specular color of the material (RGB components) and its glossiness (A component). | ||
/// The values are in sRGB space. | ||
/// </summary> | ||
public TextureInfo SpecularGlossinessTexture; | ||
|
||
public KHR_materials_pbrSpecularGlossinessExtension(Color diffuseFactor, TextureInfo diffuseTexture, Vector3 specularFactor, double glossinessFactor, TextureInfo specularGlossinessTexture) | ||
{ | ||
DiffuseFactor = diffuseFactor; | ||
DiffuseTexture = diffuseTexture; | ||
SpecularFactor = specularFactor; | ||
GlossinessFactor = glossinessFactor; | ||
SpecularGlossinessTexture = specularGlossinessTexture; | ||
} | ||
|
||
public JProperty Serialize() | ||
{ | ||
JProperty jProperty = | ||
new JProperty(KHR_materials_pbrSpecularGlossinessExtensionFactory.EXTENSION_NAME, | ||
new JObject( | ||
new JProperty(KHR_materials_pbrSpecularGlossinessExtensionFactory.DIFFUSE_FACTOR, DiffuseFactor), | ||
new JProperty(KHR_materials_pbrSpecularGlossinessExtensionFactory.DIFFUSE_TEXTURE, | ||
new JObject( | ||
new JProperty(TextureInfo.INDEX, DiffuseTexture.Index.Id) | ||
) | ||
), | ||
new JProperty(KHR_materials_pbrSpecularGlossinessExtensionFactory.SPECULAR_FACTOR, SpecularFactor), | ||
new JProperty(KHR_materials_pbrSpecularGlossinessExtensionFactory.GLOSSINESS_FACTOR, GlossinessFactor), | ||
new JProperty(KHR_materials_pbrSpecularGlossinessExtensionFactory.SPECULAR_GLOSSINESS_TEXTURE, | ||
new JObject( | ||
new JProperty(TextureInfo.INDEX, SpecularGlossinessTexture.Index.Id) | ||
) | ||
) | ||
) | ||
); | ||
|
||
return jProperty; | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...ation/GLTFSerialization/Extensions/KHR_materials_pbrSpecularGlossinessExtensionFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System; | ||
using Newtonsoft.Json.Linq; | ||
using GLTF.Math; | ||
using Newtonsoft.Json; | ||
using GLTF.Extensions; | ||
|
||
namespace GLTF.Schema | ||
{ | ||
public class KHR_materials_pbrSpecularGlossinessExtensionFactory : ExtensionFactory | ||
{ | ||
public const string EXTENSION_NAME = "KHR_materials_pbrSpecularGlossiness"; | ||
public const string DIFFUSE_FACTOR = "diffuseFactor"; | ||
public const string DIFFUSE_TEXTURE = "diffuseTexture"; | ||
public const string SPECULAR_FACTOR = "specularFactor"; | ||
public const string GLOSSINESS_FACTOR = "glossinessFactor"; | ||
public const string SPECULAR_GLOSSINESS_TEXTURE = "specularGlossinessTexture"; | ||
|
||
public KHR_materials_pbrSpecularGlossinessExtensionFactory() | ||
{ | ||
ExtensionName = EXTENSION_NAME; | ||
} | ||
|
||
public override Extension Deserialize(GLTFRoot root, JProperty extensionToken) | ||
{ | ||
Color diffuseFactor = Color.White; | ||
TextureInfo diffuseTextureInfo = new TextureInfo(); | ||
Vector3 specularFactor = KHR_materials_pbrSpecularGlossinessExtension.SPEC_FACTOR_DEFAULT; | ||
double glossinessFactor = KHR_materials_pbrSpecularGlossinessExtension.GLOSS_FACTOR_DEFAULT; | ||
TextureInfo specularGlossinessTextureInfo = new TextureInfo(); | ||
|
||
if (extensionToken != null) | ||
{ | ||
System.Diagnostics.Debug.WriteLine(extensionToken.Value.ToString()); | ||
System.Diagnostics.Debug.WriteLine(extensionToken.Value.Type); | ||
|
||
JToken diffuseFactorToken = extensionToken.Value[DIFFUSE_FACTOR]; | ||
diffuseFactor = diffuseFactorToken != null ? diffuseFactorToken.DeserializeAsColor() : diffuseFactor; | ||
diffuseTextureInfo = extensionToken.Value[DIFFUSE_TEXTURE].DeserializeAsTexture(root); | ||
JToken specularFactorToken = extensionToken.Value[SPECULAR_FACTOR]; | ||
specularFactor = specularFactorToken != null ? specularFactorToken.DeserializeAsVector3() : specularFactor; | ||
JToken glossinessFactorToken = extensionToken.Value[GLOSSINESS_FACTOR]; | ||
glossinessFactor = glossinessFactorToken != null ? glossinessFactorToken.DeserializeAsDouble() : glossinessFactor; | ||
specularGlossinessTextureInfo = extensionToken.Value[SPECULAR_GLOSSINESS_TEXTURE].DeserializeAsTexture(root); | ||
} | ||
|
||
return new KHR_materials_pbrSpecularGlossinessExtension(diffuseFactor, diffuseTextureInfo, specularFactor, glossinessFactor, specularGlossinessTextureInfo); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.