bug fix
This commit is contained in:
@@ -0,0 +1,272 @@
|
||||
using GLTF.Schema;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
namespace UnityGLTF
|
||||
{
|
||||
public abstract class BaseGraphMap : IUniformMap
|
||||
{
|
||||
public abstract IUniformMap Clone();
|
||||
|
||||
protected BaseGraphMap(Material mat)
|
||||
{
|
||||
_material = mat;
|
||||
}
|
||||
|
||||
protected BaseGraphMap(string shaderName, string fallbackGuid)
|
||||
{
|
||||
var s = Shader.Find(shaderName);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// workaround for first-import issues with Shader.Find and import order
|
||||
if (!s)
|
||||
s = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>(UnityEditor.AssetDatabase.GUIDToAssetPath(fallbackGuid));
|
||||
#endif
|
||||
|
||||
if (!s)
|
||||
throw new ShaderNotFoundException(shaderName + " not found. Did you forget to add it to the build?");
|
||||
|
||||
_material = new Material(s);
|
||||
}
|
||||
|
||||
public Material Material => _material;
|
||||
internal Material _material;
|
||||
|
||||
private AlphaMode _alphaMode;
|
||||
public virtual AlphaMode AlphaMode
|
||||
{
|
||||
get { return _alphaMode; }
|
||||
set
|
||||
{
|
||||
if (value == AlphaMode.MASK)
|
||||
{
|
||||
_material.SetOverrideTag("RenderType", "TransparentCutout");
|
||||
_material.SetFloat("_Mode", 1);
|
||||
_material.SetInt("_SrcBlend", (int)BlendMode.One);
|
||||
_material.SetInt("_DstBlend", (int)BlendMode.Zero);
|
||||
_material.SetInt("_BUILTIN_SrcBlend", (int)BlendMode.One);
|
||||
_material.SetInt("_BUILTIN_DstBlend", (int)BlendMode.Zero);
|
||||
_material.SetInt("_ZWrite", 1);
|
||||
_material.SetInt("_BUILTIN_ZWrite", 1);
|
||||
_material.SetInt("_AlphaClip", 1);
|
||||
_material.SetInt("_BUILTIN_AlphaClip", 1);
|
||||
_material.EnableKeyword("_ALPHATEST_ON");
|
||||
_material.EnableKeyword("_BUILTIN_ALPHATEST_ON");
|
||||
_material.DisableKeyword("_ALPHABLEND_ON");
|
||||
_material.DisableKeyword("_BUILTIN_ALPHABLEND_ON");
|
||||
_material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
|
||||
_material.DisableKeyword("_BUILTIN_ALPHAPREMULTIPLY_ON");
|
||||
_material.renderQueue = (int)RenderQueue.AlphaTest;
|
||||
if (_material.HasProperty("_Cutoff"))
|
||||
_material.SetFloat("_Cutoff", (float)AlphaCutoff);
|
||||
if (_material.HasProperty("alphaCutoff"))
|
||||
_material.SetFloat("alphaCutoff", (float)AlphaCutoff);
|
||||
|
||||
SetAlphaModeMask(_material, true);
|
||||
}
|
||||
else if (value == AlphaMode.BLEND)
|
||||
{
|
||||
_material.SetOverrideTag("RenderType", "Transparent");
|
||||
_material.SetFloat("_Mode", 2);
|
||||
_material.SetInt("_SrcBlend", (int)BlendMode.SrcAlpha);
|
||||
_material.SetInt("_DstBlend", (int)BlendMode.OneMinusSrcAlpha);
|
||||
_material.SetInt("_BUILTIN_SrcBlend", (int)BlendMode.SrcAlpha);
|
||||
_material.SetInt("_BUILTIN_DstBlend", (int)BlendMode.OneMinusSrcAlpha);
|
||||
_material.SetInt("_ZWrite", 0);
|
||||
_material.SetInt("_BUILTIN_ZWrite", 0);
|
||||
_material.SetInt("_AlphaClip", 0);
|
||||
_material.SetInt("_BUILTIN_AlphaClip", 0);
|
||||
_material.DisableKeyword("_ALPHATEST_ON");
|
||||
_material.DisableKeyword("_BUILTIN_ALPHATEST_ON");
|
||||
_material.EnableKeyword("_ALPHABLEND_ON");
|
||||
_material.EnableKeyword("_BUILTIN_ALPHABLEND_ON");
|
||||
_material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
|
||||
_material.DisableKeyword("_BUILTIN_ALPHAPREMULTIPLY_ON");
|
||||
_material.renderQueue = (int)RenderQueue.Transparent;
|
||||
_material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
|
||||
_material.EnableKeyword("_BUILTIN_SURFACE_TYPE_TRANSPARENT");
|
||||
|
||||
SetShaderModeBlend(_material);
|
||||
}
|
||||
else
|
||||
{
|
||||
_material.SetOverrideTag("RenderType", "Opaque");
|
||||
_material.SetFloat("_Mode", 0);
|
||||
_material.SetInt("_SrcBlend", (int)BlendMode.One);
|
||||
_material.SetInt("_DstBlend", (int)BlendMode.Zero);
|
||||
_material.SetInt("_BUILTIN_SrcBlend", (int)BlendMode.One);
|
||||
_material.SetInt("_BUILTIN_DstBlend", (int)BlendMode.Zero);
|
||||
_material.SetInt("_ZWrite", 1);
|
||||
_material.SetInt("_BUILTIN_ZWrite", 1);
|
||||
_material.SetInt("_AlphaClip", 0);
|
||||
_material.SetInt("_BUILTIN_AlphaClip", 0);
|
||||
_material.DisableKeyword("_ALPHATEST_ON");
|
||||
_material.DisableKeyword("_ALPHABLEND_ON");
|
||||
_material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
|
||||
_material.DisableKeyword("_BUILTIN_ALPHATEST_ON");
|
||||
_material.DisableKeyword("_BUILTIN_ALPHABLEND_ON");
|
||||
_material.DisableKeyword("_BUILTIN_ALPHAPREMULTIPLY_ON");
|
||||
_material.renderQueue = (int)RenderQueue.Geometry;
|
||||
}
|
||||
|
||||
_alphaMode = value;
|
||||
}
|
||||
}
|
||||
|
||||
protected void SetDoubleSided (Material material, bool doubleSided)
|
||||
{
|
||||
material.doubleSidedGI = doubleSided;
|
||||
var mode = doubleSided ? (int)CullMode.Off : (int)CullMode.Back;
|
||||
material.SetFloat(cullPropId, mode);
|
||||
material.SetFloat(cullModePropId, mode);
|
||||
material.SetFloat(cullModePropIdBuiltin, mode);
|
||||
}
|
||||
|
||||
public static readonly int cutoffPropId = Shader.PropertyToID("_Cutoff");
|
||||
|
||||
protected void SetAlphaModeMask(Material material, bool isMask) {
|
||||
material.SetFloat(cutoffPropId, isMask ? 1 : 0);
|
||||
// #if USING_HDRP_10_OR_NEWER || USING_URP_12_OR_NEWER
|
||||
material.EnableKeyword(KW_ALPHATEST_ON);
|
||||
material.EnableKeyword(KW_ALPHATEST_ON_BUILTIN);
|
||||
material.SetOverrideTag(TAG_RENDER_TYPE, TAG_RENDER_TYPE_CUTOUT);
|
||||
material.SetFloat(k_ZTestGBufferPropId, (int)CompareFunction.Equal); //3
|
||||
// #endif
|
||||
material.SetFloat(k_AlphaClip, 1);
|
||||
material.SetFloat(k_AlphaClipBuiltin, 1);
|
||||
if (isMask) material.EnableKeyword(KW_ALPHACLIP_ON_BUILTIN);
|
||||
else material.DisableKeyword(KW_ALPHACLIP_ON_BUILTIN);
|
||||
}
|
||||
|
||||
static readonly int cullPropId = Shader.PropertyToID("_Cull");
|
||||
static readonly int cullModePropId = Shader.PropertyToID("_CullMode");
|
||||
static readonly int cullModePropIdBuiltin = Shader.PropertyToID("_BUILTIN_CullMode");
|
||||
static readonly int k_AlphaClip = Shader.PropertyToID("_AlphaClip");
|
||||
static readonly int k_AlphaClipBuiltin = Shader.PropertyToID("_BUILTIN_AlphaClip");
|
||||
static readonly int k_Surface = Shader.PropertyToID("_Surface");
|
||||
static readonly int k_SurfaceBuiltin = Shader.PropertyToID("_BUILTIN_Surface");
|
||||
static readonly int k_AlphaDstBlendPropId = Shader.PropertyToID("_AlphaDstBlend");
|
||||
static readonly int k_ZTestGBufferPropId = Shader.PropertyToID("_ZTestGBuffer");
|
||||
static readonly int srcBlendPropId = Shader.PropertyToID("_SrcBlend");
|
||||
static readonly int dstBlendPropId = Shader.PropertyToID("_DstBlend");
|
||||
static readonly int zWritePropId = Shader.PropertyToID("_ZWrite");
|
||||
|
||||
const string TAG_RENDER_TYPE = "RenderType";
|
||||
const string TAG_RENDER_TYPE_CUTOUT = "TransparentCutout";
|
||||
const string TAG_RENDER_TYPE_OPAQUE = "Opaque";
|
||||
const string TAG_RENDER_TYPE_FADE = "Fade";
|
||||
const string TAG_RENDER_TYPE_TRANSPARENT = "Transparent";
|
||||
const string KW_ALPHATEST_ON = "_ALPHATEST_ON";
|
||||
const string KW_ALPHATEST_ON_BUILTIN = "_BUILTIN_ALPHATEST_ON";
|
||||
const string KW_ALPHACLIP_ON_BUILTIN = "_BUILTIN_AlphaClip";
|
||||
const string KW_DISABLE_SSR_TRANSPARENT = "_DISABLE_SSR_TRANSPARENT";
|
||||
const string KW_ENABLE_FOG_ON_TRANSPARENT = "_ENABLE_FOG_ON_TRANSPARENT";
|
||||
const string KW_SURFACE_TYPE_TRANSPARENT = "_SURFACE_TYPE_TRANSPARENT";
|
||||
const string KW_SURFACE_TYPE_TRANSPARENT_BUILTIN = "_BUILTIN_SURFACE_TYPE_TRANSPARENT";
|
||||
const string k_ShaderPassTransparentDepthPrepass = "TransparentDepthPrepass";
|
||||
const string k_ShaderPassTransparentDepthPostpass = "TransparentDepthPostpass";
|
||||
const string k_ShaderPassTransparentBackface = "TransparentBackface";
|
||||
const string k_ShaderPassRayTracingPrepass = "RayTracingPrepass";
|
||||
const string k_ShaderPassDepthOnlyPass = "DepthOnly";
|
||||
|
||||
protected void SetShaderModeBlend(Material material)
|
||||
{
|
||||
material.SetOverrideTag(TAG_RENDER_TYPE, TAG_RENDER_TYPE_TRANSPARENT);
|
||||
material.EnableKeyword(KW_SURFACE_TYPE_TRANSPARENT);
|
||||
material.EnableKeyword(KW_SURFACE_TYPE_TRANSPARENT_BUILTIN);
|
||||
material.EnableKeyword(KW_DISABLE_SSR_TRANSPARENT);
|
||||
material.EnableKeyword(KW_ENABLE_FOG_ON_TRANSPARENT);
|
||||
material.SetShaderPassEnabled(k_ShaderPassTransparentDepthPrepass, false);
|
||||
material.SetShaderPassEnabled(k_ShaderPassTransparentDepthPostpass, false);
|
||||
material.SetShaderPassEnabled(k_ShaderPassTransparentBackface, false);
|
||||
material.SetShaderPassEnabled(k_ShaderPassRayTracingPrepass, false);
|
||||
material.SetShaderPassEnabled(k_ShaderPassDepthOnlyPass, false);
|
||||
material.SetFloat(srcBlendPropId, (int) BlendMode.SrcAlpha);//5
|
||||
material.SetFloat(dstBlendPropId, (int)BlendMode.OneMinusSrcAlpha);//10
|
||||
material.SetFloat(k_ZTestGBufferPropId, (int)CompareFunction.Equal); //3
|
||||
material.SetFloat(k_AlphaDstBlendPropId, (int)BlendMode.OneMinusSrcAlpha);//10
|
||||
material.SetFloat(k_Surface, 1);
|
||||
material.SetFloat(k_SurfaceBuiltin, 1);
|
||||
material.SetFloat(zWritePropId, 0);
|
||||
}
|
||||
|
||||
public double AlphaCutoff
|
||||
{
|
||||
get => _material.GetFloat("alphaCutoff");
|
||||
set
|
||||
{
|
||||
_material.SetFloat("alphaCutoff", (float) value);
|
||||
#if !UNITY_2021_2_OR_NEWER
|
||||
// PBRGraph/UnlitGraph always have alphaCutoff on 2020.x, so we need to set it to 0 for non-masked modes
|
||||
if (_alphaMode != AlphaMode.MASK)
|
||||
_material.SetFloat("alphaCutoff", 0f);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool DoubleSided
|
||||
{
|
||||
get { return
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
!GraphicsSettings.currentRenderPipeline ?
|
||||
_material.GetInt(cullModePropIdBuiltin) == (int)CullMode.Off :
|
||||
#endif
|
||||
_material.GetInt(cullPropId) == (int)CullMode.Off; }
|
||||
set { SetDoubleSided(_material, value); }
|
||||
}
|
||||
|
||||
public virtual bool VertexColorsEnabled
|
||||
{
|
||||
get { return _material.IsKeywordEnabled("_VERTEX_COLORS_ON"); }
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
_material.EnableKeyword("_VERTEX_COLORS_ON");
|
||||
else
|
||||
_material.DisableKeyword("_VERTEX_COLORS_ON");
|
||||
}
|
||||
}
|
||||
|
||||
public Texture BaseColorTexture
|
||||
{
|
||||
get => _material.GetTexture("baseColorTexture");
|
||||
set => _material.SetTexture("baseColorTexture", value);
|
||||
}
|
||||
|
||||
public int BaseColorTexCoord
|
||||
{
|
||||
get => (int) _material.GetFloat("baseColorTextureTexCoord");
|
||||
set => _material.SetFloat("baseColorTextureTexCoord", Mathf.RoundToInt(value));
|
||||
}
|
||||
|
||||
public Vector2 BaseColorXOffset
|
||||
{
|
||||
get => _material.GetTextureOffset("baseColorTexture");
|
||||
set => _material.SetTextureOffset("baseColorTexture", value);
|
||||
}
|
||||
|
||||
public double BaseColorXRotation
|
||||
{
|
||||
get => _material.GetFloat("baseColorTextureRotation");
|
||||
set => _material.SetFloat("baseColorTextureRotation", (float) value);
|
||||
}
|
||||
|
||||
public Vector2 BaseColorXScale
|
||||
{
|
||||
get => _material.GetTextureScale("baseColorTexture");
|
||||
set => _material.SetTextureScale("baseColorTexture", value);
|
||||
}
|
||||
|
||||
public int BaseColorXTexCoord
|
||||
{
|
||||
get => (int) _material.GetFloat("baseColorTextureTexCoord");
|
||||
set => _material.SetFloat("baseColorTextureTexCoord", Mathf.RoundToInt(value));
|
||||
}
|
||||
|
||||
public Color BaseColorFactor
|
||||
{
|
||||
get => _material.GetColor("baseColorFactor");
|
||||
set => _material.SetColor("baseColorFactor", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3453f34a8c4d4d4b86685f873378869c
|
||||
timeCreated: 1657891795
|
||||
@@ -0,0 +1,123 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityGLTF
|
||||
{
|
||||
public class MetalRough2StandardMap : StandardMap, IMetalRoughUniformMap
|
||||
{
|
||||
private Vector2 baseColorOffset = new Vector2(0, 0);
|
||||
|
||||
public MetalRough2StandardMap(int MaxLOD = 1000) : base("Standard", null, MaxLOD) { }
|
||||
protected MetalRough2StandardMap(string shaderName, string shaderGuid, int MaxLOD = 1000) : base(shaderName, shaderGuid, MaxLOD) { }
|
||||
protected MetalRough2StandardMap(Material m, int MaxLOD = 1000) : base(m, MaxLOD) { }
|
||||
|
||||
public virtual Texture BaseColorTexture
|
||||
{
|
||||
get { return _material.GetTexture("_MainTex"); }
|
||||
set { _material.SetTexture("_MainTex", value); }
|
||||
}
|
||||
|
||||
// not implemented by the Standard shader
|
||||
public virtual int BaseColorTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual Vector2 BaseColorXOffset
|
||||
{
|
||||
get { return baseColorOffset; }
|
||||
set {
|
||||
baseColorOffset = value;
|
||||
_material.SetTextureOffset("_MainTex", value);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual double BaseColorXRotation
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual Vector2 BaseColorXScale
|
||||
{
|
||||
get { return _material.GetTextureScale("_MainTex"); }
|
||||
set {
|
||||
_material.SetTextureScale("_MainTex", value);
|
||||
BaseColorXOffset = baseColorOffset;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int BaseColorXTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual Color BaseColorFactor
|
||||
{
|
||||
get { return _material.GetColor("_Color"); }
|
||||
set { _material.SetColor("_Color", value); }
|
||||
}
|
||||
|
||||
public virtual Texture MetallicRoughnessTexture
|
||||
{
|
||||
get { return null; }
|
||||
set
|
||||
{
|
||||
// cap metalness at 0.5 to compensate for lack of texture
|
||||
MetallicFactor = Mathf.Min(0.5f, (float)MetallicFactor);
|
||||
}
|
||||
}
|
||||
|
||||
// not implemented by the Standard shader
|
||||
public virtual int MetallicRoughnessTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual Vector2 MetallicRoughnessXOffset
|
||||
{
|
||||
get { return new Vector2(0, 0); }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual double MetallicRoughnessXRotation
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual Vector2 MetallicRoughnessXScale
|
||||
{
|
||||
get { return new Vector2(1, 1); }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual int MetallicRoughnessXTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual double MetallicFactor
|
||||
{
|
||||
get { return _material.GetFloat("_Metallic"); }
|
||||
set { _material.SetFloat("_Metallic", (float)value); }
|
||||
}
|
||||
|
||||
// not supported by the Standard shader
|
||||
public virtual double RoughnessFactor
|
||||
{
|
||||
get { return 0.5; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public override IUniformMap Clone()
|
||||
{
|
||||
var copy = new MetalRough2StandardMap(new Material(_material));
|
||||
base.Copy(copy);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85ac6cc1932e01e4983730c9ffe91e06
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,98 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityGLTF
|
||||
{
|
||||
public class MetalRoughMap : MetalRough2StandardMap
|
||||
{
|
||||
private Vector2 metalRoughOffset = new Vector2(0, 0);
|
||||
|
||||
public MetalRoughMap(int MaxLOD = 1000) : base("GLTF/PbrMetallicRoughness", "9836e4430eb58204086d7d1440e16a4f", MaxLOD) { }
|
||||
public MetalRoughMap(string shaderName, int MaxLOD = 1000) : base(shaderName, "9836e4430eb58204086d7d1440e16a4f", MaxLOD) { }
|
||||
protected MetalRoughMap(Material m, int MaxLOD = 1000) : base(m, MaxLOD) { }
|
||||
|
||||
public override int NormalTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public override int OcclusionTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public override int EmissiveTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public override int BaseColorTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public override Texture MetallicRoughnessTexture
|
||||
{
|
||||
get { return _material.GetTexture("_MetallicGlossMap"); }
|
||||
set
|
||||
{
|
||||
_material.SetTexture("_MetallicGlossMap", value);
|
||||
_material.EnableKeyword("_METALLICGLOSSMAP");
|
||||
}
|
||||
}
|
||||
|
||||
public override int MetallicRoughnessTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public override Vector2 MetallicRoughnessXOffset
|
||||
{
|
||||
get { return metalRoughOffset; }
|
||||
set
|
||||
{
|
||||
metalRoughOffset = value;
|
||||
_material.SetTextureOffset("_MetallicGlossMap", value);
|
||||
}
|
||||
}
|
||||
|
||||
public override double MetallicRoughnessXRotation
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public override Vector2 MetallicRoughnessXScale
|
||||
{
|
||||
get { return _material.GetTextureScale("_MetallicGlossMap"); }
|
||||
set
|
||||
{
|
||||
_material.SetTextureScale("_MetallicGlossMap", value);
|
||||
MetallicRoughnessXOffset = metalRoughOffset;
|
||||
}
|
||||
}
|
||||
|
||||
public override int MetallicRoughnessXTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public override double RoughnessFactor
|
||||
{
|
||||
get { return _material.GetFloat("_Glossiness"); }
|
||||
set { _material.SetFloat("_Glossiness", (float)value); }
|
||||
}
|
||||
|
||||
public override IUniformMap Clone()
|
||||
{
|
||||
var copy = new MetalRoughMap(new Material(_material));
|
||||
base.Copy(copy);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eae97d9d46055684097402095ac8fcb6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,350 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityGLTF
|
||||
{
|
||||
public class PBRGraphMap : BaseGraphMap, IMetalRoughUniformMap, IVolumeMap, ITransmissionMap, IIORMap, IIridescenceMap, ISpecularMap, IClearcoatMap
|
||||
{
|
||||
private const string PBRGraphGuid = "478ce3626be7a5f4ea58d6b13f05a2e4";
|
||||
|
||||
public PBRGraphMap() : this("UnityGLTF/PBRGraph") {}
|
||||
|
||||
protected PBRGraphMap(string shaderName) : base(shaderName, PBRGraphGuid) { }
|
||||
|
||||
#if !UNITY_2021_1_OR_NEWER
|
||||
private const string PBRGraphTransparentGuid = "0a931320a74ca574b91d2d7d4557dcf1";
|
||||
private const string PBRGraphTransparentDoubleGuid = "54352a53405971b41a6587615f947085";
|
||||
private const string PBRGraphDoubleGuid = "8bc739b14fe811644abb82057b363ba8";
|
||||
|
||||
public PBRGraphMap(bool transparent, bool doubleSided) : base(
|
||||
"UnityGLTF/PBRGraph" + (transparent ? "-Transparent" : "") + (doubleSided ? "-Double" : ""),
|
||||
(transparent && doubleSided ? PBRGraphTransparentDoubleGuid : transparent ? PBRGraphTransparentGuid : doubleSided ? PBRGraphDoubleGuid : PBRGraphGuid)) { }
|
||||
#endif
|
||||
|
||||
public PBRGraphMap(Material mat) : base(mat) { }
|
||||
|
||||
public override IUniformMap Clone()
|
||||
{
|
||||
var clone = new PBRGraphMap(new Material(_material));
|
||||
clone.Material.shaderKeywords = _material.shaderKeywords;
|
||||
return clone;
|
||||
}
|
||||
|
||||
public Texture NormalTexture
|
||||
{
|
||||
get => _material.GetTexture("normalTexture");
|
||||
set => _material.SetTexture("normalTexture", value);
|
||||
}
|
||||
|
||||
public int NormalTexCoord
|
||||
{
|
||||
get => 0;
|
||||
set {}
|
||||
}
|
||||
|
||||
public double NormalTexScale
|
||||
{
|
||||
get => _material.GetFloat("normalScale");
|
||||
set => _material.SetFloat("normalScale", (float) value);
|
||||
}
|
||||
|
||||
public Vector2 NormalXOffset
|
||||
{
|
||||
get => _material.GetTextureOffset("normalTexture");
|
||||
set => _material.SetTextureOffset("normalTexture", value);
|
||||
}
|
||||
|
||||
public double NormalXRotation { get; set; }
|
||||
|
||||
public Vector2 NormalXScale
|
||||
{
|
||||
get => _material.GetTextureScale("normalTexture");
|
||||
set => _material.SetTextureScale("normalTexture", value);
|
||||
}
|
||||
|
||||
public int NormalXTexCoord
|
||||
{
|
||||
get => 0;
|
||||
set {}
|
||||
}
|
||||
|
||||
public Texture OcclusionTexture
|
||||
{
|
||||
get => _material.GetTexture("occlusionTexture");
|
||||
set => _material.SetTexture("occlusionTexture", value);
|
||||
}
|
||||
|
||||
public int OcclusionTexCoord
|
||||
{
|
||||
get => (int) _material.GetFloat("occlusionTextureTexCoord");
|
||||
set => _material.SetFloat("occlusionTextureTexCoord", Mathf.RoundToInt(value));
|
||||
}
|
||||
|
||||
public double OcclusionTexStrength
|
||||
{
|
||||
get => _material.GetFloat("occlusionStrength");
|
||||
set => _material.SetFloat("occlusionStrength", (float) value);
|
||||
}
|
||||
|
||||
public Vector2 OcclusionXOffset
|
||||
{
|
||||
get => _material.GetTextureOffset("occlusionTexture");
|
||||
set => _material.SetTextureOffset("occlusionTexture", value);
|
||||
}
|
||||
|
||||
public double OcclusionXRotation
|
||||
{
|
||||
get => _material.GetFloat("occlusionTextureRotation");
|
||||
set => _material.SetFloat("occlusionTextureRotation", (float) value);
|
||||
}
|
||||
|
||||
public Vector2 OcclusionXScale
|
||||
{
|
||||
get => _material.GetTextureScale("occlusionTexture");
|
||||
set => _material.SetTextureScale("occlusionTexture", value);
|
||||
}
|
||||
|
||||
public int OcclusionXTexCoord
|
||||
{
|
||||
get => (int) _material.GetFloat("occlusionTextureTexCoord");
|
||||
set => _material.SetFloat("occlusionTextureTexCoord", Mathf.RoundToInt(value));
|
||||
}
|
||||
|
||||
public Texture EmissiveTexture
|
||||
{
|
||||
get => _material.GetTexture("emissiveTexture");
|
||||
set => _material.SetTexture("emissiveTexture", value);
|
||||
}
|
||||
|
||||
public int EmissiveTexCoord
|
||||
{
|
||||
get => 0;
|
||||
set {}
|
||||
}
|
||||
|
||||
public Color EmissiveFactor
|
||||
{
|
||||
get => _material.GetColor("emissiveFactor");
|
||||
set => _material.SetColor("emissiveFactor", value);
|
||||
}
|
||||
|
||||
public Vector2 EmissiveXOffset
|
||||
{
|
||||
get => _material.GetTextureOffset("emissiveTexture");
|
||||
set => _material.SetTextureOffset("emissiveTexture", value);
|
||||
}
|
||||
|
||||
public double EmissiveXRotation { get; set; }
|
||||
|
||||
public Vector2 EmissiveXScale
|
||||
{
|
||||
get => _material.GetTextureScale("emissiveTexture");
|
||||
set => _material.SetTextureScale("emissiveTexture", value);
|
||||
}
|
||||
|
||||
public int EmissiveXTexCoord
|
||||
{
|
||||
get => 0;
|
||||
set {}
|
||||
}
|
||||
|
||||
public Texture MetallicRoughnessTexture
|
||||
{
|
||||
get => _material.GetTexture("metallicRoughnessTexture");
|
||||
set => _material.SetTexture("metallicRoughnessTexture", value);
|
||||
}
|
||||
|
||||
public int MetallicRoughnessTexCoord
|
||||
{
|
||||
get => 0;
|
||||
set {}
|
||||
}
|
||||
|
||||
public Vector2 MetallicRoughnessXOffset
|
||||
{
|
||||
get => _material.GetTextureOffset("metallicRoughnessTexture");
|
||||
set => _material.SetTextureOffset("metallicRoughnessTexture", value);
|
||||
}
|
||||
|
||||
public double MetallicRoughnessXRotation { get; set; }
|
||||
|
||||
public Vector2 MetallicRoughnessXScale
|
||||
{
|
||||
get => _material.GetTextureOffset("metallicRoughnessTexture");
|
||||
set => _material.SetTextureOffset("metallicRoughnessTexture", value);
|
||||
}
|
||||
|
||||
public int MetallicRoughnessXTexCoord
|
||||
{
|
||||
get => 0;
|
||||
set {}
|
||||
}
|
||||
|
||||
public double MetallicFactor
|
||||
{
|
||||
get => _material.GetFloat("metallicFactor");
|
||||
set => _material.SetFloat("metallicFactor", (float) value);
|
||||
}
|
||||
|
||||
public double RoughnessFactor
|
||||
{
|
||||
get => _material.GetFloat("roughnessFactor");
|
||||
set => _material.SetFloat("roughnessFactor", (float) value);
|
||||
}
|
||||
|
||||
public double ThicknessFactor
|
||||
{
|
||||
get => _material.GetFloat("thicknessFactor");
|
||||
set
|
||||
{
|
||||
_material.SetFloat("thicknessFactor", (float) value);
|
||||
}
|
||||
}
|
||||
|
||||
public Texture ThicknessTexture
|
||||
{
|
||||
get => _material.GetTexture("thicknessTexture");
|
||||
set
|
||||
{
|
||||
_material.SetTexture("thicknessTexture", value);
|
||||
}
|
||||
}
|
||||
|
||||
public double AttenuationDistance
|
||||
{
|
||||
get => _material.GetFloat("attenuationDistance");
|
||||
set => _material.SetFloat("attenuationDistance", (float) value);
|
||||
}
|
||||
|
||||
public Color AttenuationColor
|
||||
{
|
||||
get => _material.GetColor("attenuationColor");
|
||||
set => _material.SetColor("attenuationColor", value);
|
||||
}
|
||||
|
||||
public double TransmissionFactor
|
||||
{
|
||||
get => _material.GetFloat("transmissionFactor");
|
||||
set
|
||||
{
|
||||
_material.SetFloat("transmissionFactor", (float) value);
|
||||
}
|
||||
}
|
||||
|
||||
public Texture TransmissionTexture
|
||||
{
|
||||
get => _material.GetTexture("transmissionTexture");
|
||||
set
|
||||
{
|
||||
_material.SetTexture("transmissionTexture", value);
|
||||
}
|
||||
}
|
||||
|
||||
public double IOR
|
||||
{
|
||||
get => _material.GetFloat("ior");
|
||||
set => _material.SetFloat("ior", (float) value);
|
||||
}
|
||||
|
||||
public double IridescenceFactor
|
||||
{
|
||||
get => _material.GetFloat("iridescenceFactor");
|
||||
set => _material.SetFloat("iridescenceFactor", (float) value);
|
||||
}
|
||||
|
||||
public double IridescenceIor
|
||||
{
|
||||
get => _material.GetFloat("iridescenceIor");
|
||||
set => _material.SetFloat("iridescenceIor", (float) value);
|
||||
}
|
||||
|
||||
public double IridescenceThicknessMinimum
|
||||
{
|
||||
get => _material.GetFloat("iridescenceThicknessMinimum");
|
||||
set => _material.SetFloat("iridescenceThicknessMinimum", (float) value);
|
||||
}
|
||||
|
||||
public double IridescenceThicknessMaximum
|
||||
{
|
||||
get => _material.GetFloat("iridescenceThicknessMaximum");
|
||||
set => _material.SetFloat("iridescenceThicknessMaximum", (float) value);
|
||||
}
|
||||
|
||||
public Texture IridescenceTexture
|
||||
{
|
||||
get => _material.GetTexture("iridescenceTexture");
|
||||
set
|
||||
{
|
||||
_material.SetTexture("iridescenceTexture", value);
|
||||
}
|
||||
}
|
||||
|
||||
public Texture IridescenceThicknessTexture
|
||||
{
|
||||
get => _material.GetTexture("iridescenceThicknessTexture");
|
||||
set
|
||||
{
|
||||
_material.SetTexture("iridescenceThicknessTexture", value);
|
||||
}
|
||||
}
|
||||
|
||||
public double SpecularFactor
|
||||
{
|
||||
get => _material.GetFloat("specularFactor");
|
||||
set => _material.SetFloat("specularFactor", (float) value);
|
||||
}
|
||||
|
||||
public Texture SpecularTexture
|
||||
{
|
||||
get => _material.GetTexture("specularTexture");
|
||||
set
|
||||
{
|
||||
_material.SetTexture("specularTexture", value);
|
||||
}
|
||||
}
|
||||
|
||||
public Color SpecularColorFactor
|
||||
{
|
||||
get => _material.GetColor("specularColorFactor");
|
||||
set => _material.SetColor("specularColorFactor", value);
|
||||
}
|
||||
|
||||
public Texture SpecularColorTexture
|
||||
{
|
||||
get => _material.GetTexture("specularColorTexture");
|
||||
set
|
||||
{
|
||||
_material.SetTexture("specularColorTexture", value);
|
||||
}
|
||||
}
|
||||
|
||||
public double ClearcoatFactor
|
||||
{
|
||||
get => _material.GetFloat("clearcoatFactor");
|
||||
set => _material.SetFloat("clearcoatFactor", (float) value);
|
||||
}
|
||||
|
||||
public Texture ClearcoatTexture
|
||||
{
|
||||
get => _material.GetTexture("clearcoatTexture");
|
||||
set => _material.SetTexture("clearcoatTexture", value);
|
||||
}
|
||||
|
||||
public double ClearcoatRoughnessFactor
|
||||
{
|
||||
get => _material.GetFloat("clearcoatRoughnessFactor");
|
||||
set => _material.SetFloat("clearcoatRoughnessFactor", (float) value);
|
||||
}
|
||||
|
||||
public Texture ClearcoatRoughnessTexture
|
||||
{
|
||||
get => _material.GetTexture("clearcoatRoughnessTexture");
|
||||
set => _material.SetTexture("clearcoatRoughnessTexture", value);
|
||||
}
|
||||
|
||||
public Texture ClearcoatNormalTexture
|
||||
{
|
||||
get => _material.GetTexture("clearcoatNormalTexture");
|
||||
set => _material.SetTexture("clearcoatNormalTexture", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3702d621b762aa4081cbc83b8349d31
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,137 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityGLTF
|
||||
{
|
||||
public class SpecGloss2StandardMap : StandardMap, ISpecGlossUniformMap
|
||||
{
|
||||
private Vector2 diffuseOffset = new Vector2(0, 0);
|
||||
private Vector2 specGlossOffset = new Vector2(0, 0);
|
||||
|
||||
public SpecGloss2StandardMap(int MaxLOD = 1000) : base("Standard (Specular setup)", null, MaxLOD) { }
|
||||
protected SpecGloss2StandardMap(string shaderName, string shaderGuid, int MaxLOD = 1000) : base(shaderName, shaderGuid, MaxLOD) { }
|
||||
protected SpecGloss2StandardMap(Material m, int MaxLOD = 1000) : base(m, MaxLOD) { }
|
||||
|
||||
public virtual Texture DiffuseTexture
|
||||
{
|
||||
get { return _material.GetTexture("_MainTex"); }
|
||||
set { _material.SetTexture("_MainTex", value); }
|
||||
}
|
||||
|
||||
// not implemented by the Standard shader
|
||||
public virtual int DiffuseTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual Vector2 DiffuseXOffset
|
||||
{
|
||||
get { return diffuseOffset; }
|
||||
set
|
||||
{
|
||||
diffuseOffset = value;
|
||||
_material.SetTextureOffset("_MainTex", value);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual double DiffuseXRotation
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual Vector2 DiffuseXScale
|
||||
{
|
||||
get { return _material.GetTextureScale("_MainTex"); }
|
||||
set
|
||||
{
|
||||
_material.SetTextureScale("_MainTex", value);
|
||||
DiffuseXOffset = diffuseOffset;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int DiffuseXTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual Color DiffuseFactor
|
||||
{
|
||||
get { return _material.GetColor("_Color"); }
|
||||
set { _material.SetColor("_Color", value); }
|
||||
}
|
||||
|
||||
public virtual Texture SpecularGlossinessTexture
|
||||
{
|
||||
get { return _material.GetTexture("_SpecGlossMap"); }
|
||||
set
|
||||
{
|
||||
_material.SetTexture("_SpecGlossMap", value);
|
||||
_material.SetFloat("_SmoothnessTextureChannel", 0);
|
||||
_material.EnableKeyword("_SPECGLOSSMAP");
|
||||
}
|
||||
}
|
||||
|
||||
// not implemented by the Standard shader
|
||||
public virtual int SpecularGlossinessTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual Vector2 SpecularGlossinessXOffset
|
||||
{
|
||||
get { return specGlossOffset; }
|
||||
set
|
||||
{
|
||||
specGlossOffset = value;
|
||||
_material.SetTextureOffset("_SpecGlossMap", value);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual double SpecularGlossinessXRotation
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual Vector2 SpecularGlossinessXScale
|
||||
{
|
||||
get { return _material.GetTextureScale("_SpecGlossMap"); }
|
||||
set {
|
||||
_material.SetTextureScale("_SpecGlossMap", value);
|
||||
SpecularGlossinessXOffset = specGlossOffset;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int SpecularGlossinessXTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual Vector3 SpecularFactor
|
||||
{
|
||||
get { return _material.GetVector("_SpecColor"); }
|
||||
set { _material.SetVector("_SpecColor", value); }
|
||||
}
|
||||
|
||||
public virtual double GlossinessFactor
|
||||
{
|
||||
get { return _material.GetFloat("_GlossMapScale"); }
|
||||
set
|
||||
{
|
||||
_material.SetFloat("_GlossMapScale", (float)value);
|
||||
_material.SetFloat("_Glossiness", (float)value);
|
||||
}
|
||||
}
|
||||
|
||||
public override IUniformMap Clone()
|
||||
{
|
||||
var copy = new SpecGloss2StandardMap(new Material(_material));
|
||||
base.Copy(copy);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e4ff65c43d5c3774f90e67670d589cd0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityGLTF
|
||||
{
|
||||
public class SpecGlossMap : SpecGloss2StandardMap
|
||||
{
|
||||
public SpecGlossMap(int MaxLOD = 1000) : base("GLTF/PbrSpecularGlossiness", "0ffe2976cdefd434c8fcd886ffa69322", MaxLOD) { }
|
||||
public SpecGlossMap(string shaderName, int MaxLOD = 1000) : base(shaderName, "0ffe2976cdefd434c8fcd886ffa69322", MaxLOD) { }
|
||||
protected SpecGlossMap(Material m, int MaxLOD = 1000) : base(m, MaxLOD) { }
|
||||
|
||||
public override int NormalTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public override int OcclusionTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public override int EmissiveTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public override int DiffuseTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public override int SpecularGlossinessTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public override IUniformMap Clone()
|
||||
{
|
||||
var copy = new SpecGlossMap(new Material(_material));
|
||||
base.Copy(copy);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f096c5198ea17245803d827b00f12b8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,379 @@
|
||||
using GLTF.Schema;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using Material = UnityEngine.Material;
|
||||
using Texture = UnityEngine.Texture;
|
||||
|
||||
namespace UnityGLTF
|
||||
{
|
||||
public class StandardMap : ILitMap
|
||||
{
|
||||
protected Material _material;
|
||||
private AlphaMode _alphaMode = AlphaMode.OPAQUE;
|
||||
private double _alphaCutoff = 0.5;
|
||||
|
||||
private Vector2 normalOffset = new Vector2(0, 0);
|
||||
private Vector2 occlusionOffset = new Vector2(0, 0);
|
||||
private Vector2 emissiveOffset = new Vector2(0, 0);
|
||||
|
||||
protected StandardMap(string shaderName, string fallbackGuid, int MaxLOD = 1000)
|
||||
{
|
||||
var s = Shader.Find(shaderName);
|
||||
#if UNITY_EDITOR
|
||||
// workaround for first-import issues with Shader.Find and import order
|
||||
if (!s && fallbackGuid != null)
|
||||
s = UnityEditor.AssetDatabase.LoadAssetAtPath<Shader>(UnityEditor.AssetDatabase.GUIDToAssetPath(fallbackGuid));
|
||||
#endif
|
||||
if (s == null)
|
||||
{
|
||||
throw new ShaderNotFoundException(shaderName + " not found. Did you forget to add it to the build?");
|
||||
}
|
||||
|
||||
s.maximumLOD = MaxLOD;
|
||||
_material = new Material(s);
|
||||
}
|
||||
|
||||
protected StandardMap(Material mat, int MaxLOD = 1000)
|
||||
{
|
||||
mat.shader.maximumLOD = MaxLOD;
|
||||
_material = mat;
|
||||
|
||||
if (mat.HasProperty("_Cutoff"))
|
||||
{
|
||||
_alphaCutoff = mat.GetFloat("_Cutoff");
|
||||
}
|
||||
|
||||
switch (mat.renderQueue)
|
||||
{
|
||||
case (int)RenderQueue.AlphaTest:
|
||||
_alphaMode = AlphaMode.MASK;
|
||||
break;
|
||||
case (int)RenderQueue.Transparent:
|
||||
_alphaMode = AlphaMode.BLEND;
|
||||
break;
|
||||
case (int)RenderQueue.Geometry:
|
||||
default:
|
||||
_alphaMode = AlphaMode.OPAQUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public Material Material { get { return _material; } }
|
||||
|
||||
public virtual Texture NormalTexture
|
||||
{
|
||||
get { return _material.HasProperty("_BumpMap") ? _material.GetTexture("_BumpMap") : null; }
|
||||
set
|
||||
{
|
||||
if (_material.HasProperty("_BumpMap"))
|
||||
{
|
||||
_material.SetTexture("_BumpMap", value);
|
||||
_material.EnableKeyword("_NORMALMAP");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("Tried to set a normal map texture to a material that does not support it.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// not implemented by the Standard shader
|
||||
public virtual int NormalTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual Vector2 NormalXOffset
|
||||
{
|
||||
get { return normalOffset; }
|
||||
set
|
||||
{
|
||||
normalOffset = value;
|
||||
_material.SetTextureOffset("_BumpMap", value);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual double NormalXRotation
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual Vector2 NormalXScale
|
||||
{
|
||||
get { return _material.GetTextureScale("_BumpMap"); }
|
||||
set {
|
||||
_material.SetTextureScale("_BumpMap", value);
|
||||
NormalXOffset = normalOffset;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int NormalXTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual double NormalTexScale
|
||||
{
|
||||
get { return _material.HasProperty("_BumpScale") ? _material.GetFloat("_BumpScale") : 1; }
|
||||
set
|
||||
{
|
||||
if (_material.HasProperty("_BumpScale"))
|
||||
{
|
||||
_material.SetFloat("_BumpScale", (float)value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("Tried to set a normal map scale to a material that does not support it.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Texture OcclusionTexture
|
||||
{
|
||||
get { return _material.HasProperty("_OcclusionMap") ? _material.GetTexture("_OcclusionMap") : null; }
|
||||
set
|
||||
{
|
||||
if (_material.HasProperty("_OcclusionMap"))
|
||||
{
|
||||
_material.SetTexture("_OcclusionMap", value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("Tried to set an occlusion map to a material that does not support it.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// not implemented by the Standard shader
|
||||
public virtual int OcclusionTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual Vector2 OcclusionXOffset
|
||||
{
|
||||
get { return occlusionOffset; }
|
||||
set
|
||||
{
|
||||
occlusionOffset = value;
|
||||
_material.SetTextureOffset("_OcclusionMap", value);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual double OcclusionXRotation
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual Vector2 OcclusionXScale
|
||||
{
|
||||
get { return _material.GetTextureScale("_OcclusionMap"); }
|
||||
set {
|
||||
_material.SetTextureScale("_OcclusionMap", value);
|
||||
OcclusionXOffset = occlusionOffset;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int OcclusionXTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual double OcclusionTexStrength
|
||||
{
|
||||
get { return _material.HasProperty("_OcclusionStrength") ? _material.GetFloat("_OcclusionStrength") : 1; }
|
||||
set
|
||||
{
|
||||
if (_material.HasProperty("_OcclusionStrength"))
|
||||
{
|
||||
_material.SetFloat("_OcclusionStrength", (float)value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("Tried to set occlusion strength to a material that does not support it.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual Texture EmissiveTexture
|
||||
{
|
||||
get { return _material.HasProperty("_EmissionMap") ? _material.GetTexture("_EmissionMap") : null; }
|
||||
set
|
||||
{
|
||||
if (_material.HasProperty("_EmissionMap"))
|
||||
{
|
||||
_material.SetTexture("_EmissionMap", value);
|
||||
_material.EnableKeyword("_EMISSION");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("Tried to set an emission map to a material that does not support it.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// not implemented by the Standard shader
|
||||
public virtual int EmissiveTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual Vector2 EmissiveXOffset
|
||||
{
|
||||
get { return emissiveOffset; }
|
||||
set
|
||||
{
|
||||
emissiveOffset = value;
|
||||
_material.SetTextureOffset("_EmissionMap", value);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual double EmissiveXRotation
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual Vector2 EmissiveXScale
|
||||
{
|
||||
get { return _material.GetTextureScale("_EmissionMap"); }
|
||||
set {
|
||||
_material.SetTextureScale("_EmissionMap", value);
|
||||
EmissiveXOffset = emissiveOffset;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int EmissiveXTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual Color EmissiveFactor
|
||||
{
|
||||
get { return _material.HasProperty("_EmissionColor") ? _material.GetColor("_EmissionColor") : Color.white; }
|
||||
set
|
||||
{
|
||||
if (_material.HasProperty("_EmissionColor"))
|
||||
{
|
||||
_material.SetColor("_EmissionColor", value);
|
||||
_material.EnableKeyword("_EMISSION");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("Tried to set an emission factor to a material that does not support it.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual AlphaMode AlphaMode
|
||||
{
|
||||
get { return _alphaMode; }
|
||||
set
|
||||
{
|
||||
if (value == AlphaMode.MASK)
|
||||
{
|
||||
_material.SetOverrideTag("RenderType", "TransparentCutout");
|
||||
_material.SetFloat("_Mode", 1);
|
||||
_material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
|
||||
_material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
|
||||
_material.SetInt("_ZWrite", 1);
|
||||
_material.EnableKeyword("_ALPHATEST_ON");
|
||||
_material.DisableKeyword("_ALPHABLEND_ON");
|
||||
_material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
|
||||
_material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
|
||||
if (_material.HasProperty("_Cutoff"))
|
||||
{
|
||||
_material.SetFloat("_Cutoff", (float)_alphaCutoff);
|
||||
}
|
||||
}
|
||||
else if (value == AlphaMode.BLEND)
|
||||
{
|
||||
_material.SetOverrideTag("RenderType", "Transparent");
|
||||
_material.SetFloat("_Mode", 2);
|
||||
_material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
|
||||
_material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
|
||||
_material.SetInt("_ZWrite", 0);
|
||||
_material.DisableKeyword("_ALPHATEST_ON");
|
||||
_material.EnableKeyword("_ALPHABLEND_ON");
|
||||
_material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
|
||||
_material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
|
||||
}
|
||||
else
|
||||
{
|
||||
_material.SetOverrideTag("RenderType", "Opaque");
|
||||
_material.SetFloat("_Mode", 0);
|
||||
_material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
|
||||
_material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
|
||||
_material.SetInt("_ZWrite", 1);
|
||||
_material.DisableKeyword("_ALPHATEST_ON");
|
||||
_material.DisableKeyword("_ALPHABLEND_ON");
|
||||
_material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
|
||||
_material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Geometry;
|
||||
}
|
||||
|
||||
_alphaMode = value;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual double AlphaCutoff
|
||||
{
|
||||
get { return _alphaCutoff; }
|
||||
set
|
||||
{
|
||||
if ((_alphaMode == AlphaMode.MASK) && _material.HasProperty("_Cutoff"))
|
||||
{
|
||||
_material.SetFloat("_Cutoff", (float)value);
|
||||
}
|
||||
_alphaCutoff = value;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool DoubleSided
|
||||
{
|
||||
get { return _material.GetInt("_Cull") == (int)CullMode.Off; }
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
_material.SetInt("_Cull", (int)CullMode.Off);
|
||||
else
|
||||
_material.SetInt("_Cull", (int)CullMode.Back);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual bool VertexColorsEnabled
|
||||
{
|
||||
get { return _material.IsKeywordEnabled("VERTEX_COLOR_ON"); }
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
_material.EnableKeyword("VERTEX_COLOR_ON");
|
||||
else
|
||||
_material.DisableKeyword("VERTEX_COLOR_ON");
|
||||
}
|
||||
}
|
||||
|
||||
public virtual IUniformMap Clone()
|
||||
{
|
||||
var ret = new StandardMap(new Material(_material));
|
||||
ret._alphaMode = _alphaMode;
|
||||
ret._alphaCutoff = _alphaCutoff;
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected virtual void Copy(ILitMap o)
|
||||
{
|
||||
var other = (StandardMap)o;
|
||||
other._material = _material;
|
||||
other._alphaCutoff = _alphaCutoff;
|
||||
other._alphaMode = _alphaMode;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f9ec0afbd86788428f96c503a122ba6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,145 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityGLTF
|
||||
{
|
||||
public interface IUniformMap
|
||||
{
|
||||
Material Material { get; }
|
||||
|
||||
GLTF.Schema.AlphaMode AlphaMode { get; set; }
|
||||
double AlphaCutoff { get; set; }
|
||||
bool DoubleSided { get; set; }
|
||||
bool VertexColorsEnabled { get; set; }
|
||||
|
||||
IUniformMap Clone();
|
||||
}
|
||||
|
||||
public interface ILitMap : IUniformMap
|
||||
{
|
||||
Texture NormalTexture { get; set; }
|
||||
int NormalTexCoord { get; set; }
|
||||
double NormalTexScale { get; set; }
|
||||
Vector2 NormalXOffset { get; set; }
|
||||
double NormalXRotation { get; set; }
|
||||
Vector2 NormalXScale { get; set; }
|
||||
int NormalXTexCoord { get; set; }
|
||||
|
||||
Texture OcclusionTexture { get; set; }
|
||||
int OcclusionTexCoord { get; set; }
|
||||
double OcclusionTexStrength { get; set; }
|
||||
Vector2 OcclusionXOffset { get; set; }
|
||||
double OcclusionXRotation { get; set; }
|
||||
Vector2 OcclusionXScale { get; set; }
|
||||
int OcclusionXTexCoord { get; set; }
|
||||
|
||||
Texture EmissiveTexture { get; set; }
|
||||
int EmissiveTexCoord { get; set; }
|
||||
Color EmissiveFactor { get; set; }
|
||||
Vector2 EmissiveXOffset { get; set; }
|
||||
double EmissiveXRotation { get; set; }
|
||||
Vector2 EmissiveXScale { get; set; }
|
||||
int EmissiveXTexCoord { get; set; }
|
||||
}
|
||||
|
||||
public interface IMetalRoughUniformMap : ILitMap
|
||||
{
|
||||
Texture BaseColorTexture { get; set; }
|
||||
int BaseColorTexCoord { get; set; }
|
||||
Vector2 BaseColorXOffset { get; set; }
|
||||
double BaseColorXRotation { get; set; }
|
||||
Vector2 BaseColorXScale { get; set; }
|
||||
int BaseColorXTexCoord { get; set; }
|
||||
|
||||
Color BaseColorFactor { get; set; }
|
||||
|
||||
Texture MetallicRoughnessTexture { get; set; }
|
||||
int MetallicRoughnessTexCoord { get; set; }
|
||||
Vector2 MetallicRoughnessXOffset { get; set; }
|
||||
double MetallicRoughnessXRotation { get; set; }
|
||||
Vector2 MetallicRoughnessXScale { get; set; }
|
||||
int MetallicRoughnessXTexCoord { get; set; }
|
||||
|
||||
double MetallicFactor { get; set; }
|
||||
double RoughnessFactor { get; set; }
|
||||
}
|
||||
|
||||
public interface IVolumeMap : IMetalRoughUniformMap
|
||||
{
|
||||
double ThicknessFactor { get; set; }
|
||||
Texture ThicknessTexture { get; set; }
|
||||
double AttenuationDistance { get; set; }
|
||||
Color AttenuationColor { get; set; }
|
||||
}
|
||||
|
||||
public interface ITransmissionMap : IMetalRoughUniformMap
|
||||
{
|
||||
double TransmissionFactor { get; set; }
|
||||
Texture TransmissionTexture { get; set; }
|
||||
}
|
||||
|
||||
public interface IIORMap : IMetalRoughUniformMap
|
||||
{
|
||||
double IOR { get; set; }
|
||||
}
|
||||
|
||||
public interface ISpecularMap : IMetalRoughUniformMap
|
||||
{
|
||||
double SpecularFactor { get; set; }
|
||||
Texture SpecularTexture { get; set; }
|
||||
Color SpecularColorFactor { get; set; }
|
||||
Texture SpecularColorTexture { get; set; }
|
||||
}
|
||||
|
||||
public interface IIridescenceMap : IMetalRoughUniformMap
|
||||
{
|
||||
double IridescenceFactor { get; set; }
|
||||
double IridescenceIor { get; set; }
|
||||
double IridescenceThicknessMinimum { get; set; }
|
||||
double IridescenceThicknessMaximum { get; set; }
|
||||
Texture IridescenceTexture { get; set; }
|
||||
Texture IridescenceThicknessTexture { get; set; }
|
||||
}
|
||||
|
||||
public interface ISpecGlossUniformMap : ILitMap
|
||||
{
|
||||
Texture DiffuseTexture { get; set; }
|
||||
int DiffuseTexCoord { get; set; }
|
||||
Vector2 DiffuseXOffset { get; set; }
|
||||
double DiffuseXRotation { get; set; }
|
||||
Vector2 DiffuseXScale { get; set; }
|
||||
int DiffuseXTexCoord { get; set; }
|
||||
|
||||
Color DiffuseFactor { get; set; }
|
||||
|
||||
Texture SpecularGlossinessTexture { get; set; }
|
||||
int SpecularGlossinessTexCoord { get; set; }
|
||||
Vector2 SpecularGlossinessXOffset { get; set; }
|
||||
double SpecularGlossinessXRotation { get; set; }
|
||||
Vector2 SpecularGlossinessXScale { get; set; }
|
||||
int SpecularGlossinessXTexCoord { get; set; }
|
||||
|
||||
Vector3 SpecularFactor { get; set; }
|
||||
double GlossinessFactor { get; set; }
|
||||
}
|
||||
|
||||
public interface IClearcoatMap : IMetalRoughUniformMap
|
||||
{
|
||||
double ClearcoatFactor { get; set; }
|
||||
Texture ClearcoatTexture { get; set; }
|
||||
double ClearcoatRoughnessFactor { get; set; }
|
||||
Texture ClearcoatRoughnessTexture { get; set; }
|
||||
Texture ClearcoatNormalTexture { get; set; }
|
||||
}
|
||||
|
||||
public interface IUnlitUniformMap : IUniformMap
|
||||
{
|
||||
Texture BaseColorTexture { get; set; }
|
||||
int BaseColorTexCoord { get; set; }
|
||||
Vector2 BaseColorXOffset { get; set; }
|
||||
double BaseColorXRotation { get; set; }
|
||||
Vector2 BaseColorXScale { get; set; }
|
||||
int BaseColorXTexCoord { get; set; }
|
||||
|
||||
Color BaseColorFactor { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35a1bb8c3d231b0449dcb049debee71a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,31 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityGLTF
|
||||
{
|
||||
public class UnlitGraphMap : BaseGraphMap, IUnlitUniformMap
|
||||
{
|
||||
private const string UnlitGraphGuid = "59541e6caf586ca4f96ccf48a4813a51";
|
||||
public UnlitGraphMap() : this("UnityGLTF/UnlitGraph") {}
|
||||
|
||||
#if !UNITY_2021_1_OR_NEWER
|
||||
private const string UnlitGraphTransparentGuid = "83f2caca07949794fb997734c4b0520f";
|
||||
private const string UnlitGraphTransparentDoubleGuid = "8a8841b4fb2f63644896f4e2b36bc06d";
|
||||
private const string UnlitGraphDoubleGuid = "33ee70a7f505ddb4e80d235c3d70766d";
|
||||
|
||||
public UnlitGraphMap(bool transparent, bool doubleSided) : base(
|
||||
"UnityGLTF/UnlitGraph" + (transparent ? "-Transparent" : "") + (doubleSided ? "-Double" : ""),
|
||||
(transparent && doubleSided ? UnlitGraphTransparentDoubleGuid : transparent ? UnlitGraphTransparentGuid : doubleSided ? UnlitGraphDoubleGuid : UnlitGraphGuid)) { }
|
||||
#endif
|
||||
|
||||
protected UnlitGraphMap(string shaderName) : base(shaderName, UnlitGraphGuid) { }
|
||||
|
||||
public UnlitGraphMap(Material mat) : base(mat) { }
|
||||
|
||||
public override IUniformMap Clone()
|
||||
{
|
||||
var clone = new UnlitGraphMap(new Material(_material));
|
||||
clone.Material.shaderKeywords = _material.shaderKeywords;
|
||||
return clone;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3f20bde7da344549f9b68b6cf264b36
|
||||
timeCreated: 1657891307
|
||||
@@ -0,0 +1,63 @@
|
||||
using UnityEngine;
|
||||
using Material = UnityEngine.Material;
|
||||
using Texture = UnityEngine.Texture;
|
||||
|
||||
namespace UnityGLTF
|
||||
{
|
||||
public class UnlitMap : StandardMap, IUnlitUniformMap
|
||||
{
|
||||
private Vector2 baseColorOffset = new Vector2(0, 0);
|
||||
|
||||
public UnlitMap(int MaxLOD = 1000) : base("GLTF/Unlit", "4d20effaf200f604db8b73f8e6a2e386", MaxLOD) { }
|
||||
public UnlitMap(string shaderName, string shaderGuid, int MaxLOD = 1000) : base(shaderName, shaderGuid, MaxLOD) { }
|
||||
public UnlitMap(Material m, int MaxLOD = 1000) : base(m, MaxLOD) { }
|
||||
|
||||
public Texture BaseColorTexture
|
||||
{
|
||||
get { return _material.GetTexture("_MainTex"); }
|
||||
set { _material.SetTexture("_MainTex", value); }
|
||||
}
|
||||
|
||||
public virtual int BaseColorTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual Vector2 BaseColorXOffset
|
||||
{
|
||||
get { return baseColorOffset; }
|
||||
set {
|
||||
_material.SetTextureOffset("_MainTex", value);
|
||||
baseColorOffset = value;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual double BaseColorXRotation
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual Vector2 BaseColorXScale
|
||||
{
|
||||
get { return _material.GetTextureScale("_MainTex"); }
|
||||
set {
|
||||
_material.SetTextureScale("_MainTex", value);
|
||||
BaseColorXOffset = baseColorOffset;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual int BaseColorXTexCoord
|
||||
{
|
||||
get { return 0; }
|
||||
set { return; }
|
||||
}
|
||||
|
||||
public virtual Color BaseColorFactor
|
||||
{
|
||||
get { return _material.GetColor("_Color"); }
|
||||
set { _material.SetColor("_Color", value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ab9be6bfd7090247a61992f7b8f8adb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user