Пример #1
0
        /// <summary>
        /// Create a Particle definition.
        /// </summary>
        /// <param name="vgoParticle"></param>
        /// <returns></returns>
        protected virtual ParticleDefinition CreateParticleDefinition(VGO_materials_particle vgoParticle)
        {
            ParticleDefinition particleDefinition = new ParticleDefinition()
            {
                RenderMode               = (UniStandardParticle.BlendMode)vgoParticle.renderMode,
                ColorMode                = (UniStandardParticle.ColorMode)vgoParticle.colorMode,
                FlipBookMode             = (UniStandardParticle.FlipBookMode)vgoParticle.flipBookMode,
                CullMode                 = vgoParticle.cullMode,
                SoftParticlesEnabled     = vgoParticle.softParticlesEnabled,
                SoftParticleFadeParams   = ArrayConverter.ToVector4(vgoParticle.softParticleFadeParams),
                CameraFadingEnabled      = vgoParticle.cameraFadingEnabled,
                CameraFadeParams         = ArrayConverter.ToVector4(vgoParticle.cameraFadeParams),
                DistortionEnabled        = vgoParticle.distortionEnabled,
                GrabTexture              = GetTexture(UniStandardParticle.Utils.PropGrabTexture, vgoParticle.grabTextureIndex),
                DistortionStrengthScaled = vgoParticle.distortionStrengthScaled,
                DistortionBlend          = vgoParticle.distortionBlend,
                ColorAddSubDiff          = ArrayConverter.ToColor(vgoParticle.colorAddSubDiff, gamma: true),
                MainTex          = GetTexture(UniStandardParticle.Utils.PropMainTex, vgoParticle.mainTexIndex),
                MainTexSt        = ArrayConverter.ToVector4(vgoParticle.mainTexSt),
                Color            = ArrayConverter.ToColor(vgoParticle.color, gamma: true),
                Cutoff           = vgoParticle.cutoff,
                MetallicGlossMap = GetTexture(UniStandardParticle.Utils.PropMetallicGlossMap, vgoParticle.metallicGlossMapIndex),
                Metallic         = vgoParticle.metallic,
                Glossiness       = vgoParticle.glossiness,
                BumpMap          = GetTexture(UniStandardParticle.Utils.PropBumpMap, vgoParticle.bumpMapIndex),
                BumpScale        = vgoParticle.bumpScale,
                LightingEnabled  = vgoParticle.lightingEnabled,
                EmissionEnabled  = vgoParticle.emissionEnabled,
                EmissionColor    = ArrayConverter.ToColor(vgoParticle.emissionColor, gamma: true),
                EmissionMap      = GetTexture(UniStandardParticle.Utils.PropEmissionMap, vgoParticle.emissionMapIndex),
            };

            return(particleDefinition);
        }
Пример #2
0
        /// <summary>
        /// Set Light parameter.
        /// </summary>
        /// <param name="light"></param>
        /// <param name="vgoLight"></param>
        public static void SetComponentValue(Light light, VGO_Light vgoLight)
        {
            if (light == null)
            {
                return;
            }

            if (vgoLight == null)
            {
                return;
            }

            switch (vgoLight.type)
            {
            case LightType.Spot:
            case LightType.Directional:
            case LightType.Point:
            case LightType.Rectangle:
            case LightType.Disc:
                break;

            default:
                return;
            }

            light.enabled         = vgoLight.enabled;
            light.type            = vgoLight.type;
            light.color           = ArrayConverter.ToColor(vgoLight.color, gamma: true);
            light.intensity       = vgoLight.intensity;
            light.bounceIntensity = vgoLight.bounceIntensity;
            light.renderMode      = vgoLight.renderMode;
            light.cullingMask     = vgoLight.cullingMask;

#if UNITY_EDITOR
            light.lightmapBakeType = vgoLight.lightmapBakeType;
#endif

            switch (vgoLight.type)
            {
            case LightType.Spot:
                light.shape     = vgoLight.shape;
                light.range     = vgoLight.range;
                light.spotAngle = vgoLight.spotAngle;
                break;

            case LightType.Point:
                light.range = vgoLight.range;
                break;

#if UNITY_EDITOR
            case LightType.Rectangle:
                light.areaSize = ArrayConverter.ToVector2(vgoLight.areaSize);
                break;

            case LightType.Disc:
                light.areaSize = new Vector2(vgoLight.areaRadius, 1.0f);
                break;
#endif
            default:
                break;
            }

            light.shadows = vgoLight.shadows;

#if UNITY_EDITOR
            // Baked Shadows
            if ((vgoLight.lightmapBakeType == LightmapBakeType.Baked) ||
                (vgoLight.lightmapBakeType == LightmapBakeType.Mixed))
            {
                if (vgoLight.shadows == LightShadows.Soft)
                {
                    switch (vgoLight.type)
                    {
                    case LightType.Spot:
                    case LightType.Point:
                        light.shadowRadius = vgoLight.shadowRadius;
                        break;

                    case LightType.Directional:
                        light.shadowAngle = vgoLight.shadowAngle;
                        break;

                    default:
                        break;
                    }
                }
            }
#endif
            // Realtime Shadows
            if ((vgoLight.lightmapBakeType == LightmapBakeType.Realtime) ||
                (vgoLight.lightmapBakeType == LightmapBakeType.Mixed))
            {
                if ((vgoLight.type == LightType.Directional) ||
                    (vgoLight.type == LightType.Point))
                {
                    light.shadowStrength   = vgoLight.shadowStrength;
                    light.shadowResolution = vgoLight.shadowResolution;
                    light.shadowBias       = vgoLight.shadowBias;
                    light.shadowNormalBias = vgoLight.shadowNormalBias;
                    light.shadowNearPlane  = vgoLight.shadowNearPlane;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Create a Unlit material.
        /// </summary>
        /// <param name="i"></param>
        /// <param name="src"></param>
        /// <param name="hasVertexColor"></param>
        /// <returns></returns>
        protected virtual Material CreateUnlitMaterial(int i, glTFMaterial src, bool hasVertexColor)
        {
            var shader = m_shaderStore.GetShader(src);

            var material = new Material(shader);

            material.name = CreateMaterialName(i, src);

#if UNITY_EDITOR
            material.hideFlags = HideFlags.DontUnloadUnusedAsset;
#endif
            // renderMode
            switch (src.alphaMode)
            {
            case MaterialAlphaMode.OPAQUE:
                UniGLTF.UniUnlit.Utils.SetRenderMode(material, UniGLTF.UniUnlit.UniUnlitRenderMode.Opaque);
                break;

            case MaterialAlphaMode.BLEND:
                UniGLTF.UniUnlit.Utils.SetRenderMode(material, UniGLTF.UniUnlit.UniUnlitRenderMode.Transparent);
                break;

            case MaterialAlphaMode.MASK:
                UniGLTF.UniUnlit.Utils.SetRenderMode(material, UniGLTF.UniUnlit.UniUnlitRenderMode.Cutout);
                break;

            default:
                UniGLTF.UniUnlit.Utils.SetRenderMode(material, UniGLTF.UniUnlit.UniUnlitRenderMode.Opaque);
                break;
            }

            // culling
            if (src.doubleSided)
            {
                UniGLTF.UniUnlit.Utils.SetCullMode(material, UniGLTF.UniUnlit.UniUnlitCullMode.Off);
            }
            else
            {
                UniGLTF.UniUnlit.Utils.SetCullMode(material, UniGLTF.UniUnlit.UniUnlitCullMode.Back);
            }

            // VColor
            if (hasVertexColor)
            {
                UniGLTF.UniUnlit.Utils.SetVColBlendMode(material, UniGLTF.UniUnlit.UniUnlitVertexColorBlendOp.Multiply);
            }
            else
            {
                UniGLTF.UniUnlit.Utils.SetVColBlendMode(material, UniGLTF.UniUnlit.UniUnlitVertexColorBlendOp.None);
            }

            if (src.pbrMetallicRoughness != null)
            {
                // color
                if (src.pbrMetallicRoughness.baseColorFactor != null)
                {
                    material.color = ArrayConverter.ToColor(src.pbrMetallicRoughness.baseColorFactor, gamma: true);
                }

                // texture
                if (src.pbrMetallicRoughness.baseColorTexture != null)
                {
                    var texture = Context.GetTexture(src.pbrMetallicRoughness.baseColorTexture.index);

                    if (texture != null)
                    {
                        material.mainTexture = texture.Texture;
                    }
                }
            }

            if (material.shader.name == ShaderName.UniGLTF_UniUnlit)
            {
                UniGLTF.UniUnlit.Utils.ValidateProperties(material, true);

                return(material);
            }

            switch (src.alphaMode)
            {
            case MaterialAlphaMode.BLEND:
                material.SetInt(UniGLTF.UniUnlit.Utils.PropNameBlendMode, (int)BlendMode.Fade);
                material.SetInt(UniGLTF.UniUnlit.Utils.PropNameSrcBlend, (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
                material.SetInt(UniGLTF.UniUnlit.Utils.PropNameDstBlend, (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                material.SetInt(UniGLTF.UniUnlit.Utils.PropNameZWrite, 0);
                material.DisableKeyword(UniGLTF.UniUnlit.Utils.KeywordAlphaTestOn);
                material.EnableKeyword(UniGLTF.UniUnlit.Utils.KeywordAlphaBlendOn);
                material.renderQueue = (int)RenderQueue.Transparent;
                break;

            case MaterialAlphaMode.MASK:
                material.SetFloat(UniGLTF.UniUnlit.Utils.PropNameCutoff, src.alphaCutoff);
                material.SetInt(UniGLTF.UniUnlit.Utils.PropNameBlendMode, (int)BlendMode.Cutout);
                material.SetInt(UniGLTF.UniUnlit.Utils.PropNameSrcBlend, (int)UnityEngine.Rendering.BlendMode.One);
                material.SetInt(UniGLTF.UniUnlit.Utils.PropNameDstBlend, (int)UnityEngine.Rendering.BlendMode.Zero);
                material.SetInt(UniGLTF.UniUnlit.Utils.PropNameZWrite, 1);
                material.EnableKeyword(UniGLTF.UniUnlit.Utils.KeywordAlphaTestOn);
                material.DisableKeyword(UniGLTF.UniUnlit.Utils.KeywordAlphaBlendOn);
                material.renderQueue = (int)RenderQueue.AlphaTest;
                break;

            case MaterialAlphaMode.OPAQUE:
            default:
                material.SetInt(UniGLTF.UniUnlit.Utils.PropNameBlendMode, (int)BlendMode.Opaque);
                material.SetInt(UniGLTF.UniUnlit.Utils.PropNameSrcBlend, (int)UnityEngine.Rendering.BlendMode.One);
                material.SetInt(UniGLTF.UniUnlit.Utils.PropNameDstBlend, (int)UnityEngine.Rendering.BlendMode.Zero);
                material.SetInt(UniGLTF.UniUnlit.Utils.PropNameZWrite, 1);
                material.DisableKeyword(UniGLTF.UniUnlit.Utils.KeywordAlphaTestOn);
                material.DisableKeyword(UniGLTF.UniUnlit.Utils.KeywordAlphaBlendOn);
                material.renderQueue = -1;
                break;
            }

            return(material);
        }
Пример #4
0
        /// <summary>
        /// Create a MToon definition.
        /// </summary>
        /// <param name="mtoon"></param>
        /// <returns></returns>
        protected virtual MToonDefinition CreateMtoonDefinition(VRMC_materials_mtoon mtoon)
        {
            MToonDefinition mtoonDefinition = new MToonDefinition();

            // Meta
            mtoonDefinition.Meta = new MetaDefinition()
            {
                VersionNumber  = MToon.Utils.VersionNumber,
                Implementation = MToon.Utils.Implementation,
            };

            // Rendering
            mtoonDefinition.Rendering = new RenderingDefinition()
            {
                RenderMode = (MToon.RenderMode)mtoon.renderMode,
                CullMode   = (MToon.CullMode)mtoon.cullMode,
                RenderQueueOffsetNumber = mtoon.renderQueueOffsetNumber,
            };

            // Color
            mtoonDefinition.Color = new ColorDefinition()
            {
                LitColor             = ArrayConverter.ToColor(mtoon.litFactor, gamma: true),
                LitMultiplyTexture   = GetTexture(MToon.Utils.PropMainTex, mtoon.litMultiplyTexture),
                ShadeColor           = ArrayConverter.ToColor(mtoon.shadeFactor, gamma: true),
                ShadeMultiplyTexture = GetTexture(MToon.Utils.PropShadeTexture, mtoon.shadeMultiplyTexture),
                CutoutThresholdValue = mtoon.cutoutThresholdFactor,
            };

            // Lighting
            mtoonDefinition.Lighting = new LightingDefinition();
            mtoonDefinition.Lighting.LitAndShadeMixing = new LitAndShadeMixingDefinition()
            {
                ShadingShiftValue                          = mtoon.shadingShiftFactor,
                ShadingToonyValue                          = mtoon.shadingToonyFactor,
                ShadowReceiveMultiplierValue               = mtoon.shadowReceiveMultiplierFactor,
                ShadowReceiveMultiplierMultiplyTexture     = GetTexture(MToon.Utils.PropReceiveShadowTexture, mtoon.shadowReceiveMultiplierMultiplyTexture),
                LitAndShadeMixingMultiplierValue           = mtoon.litAndShadeMixingMultiplierFactor,
                LitAndShadeMixingMultiplierMultiplyTexture = GetTexture(MToon.Utils.PropShadingGradeTexture, mtoon.litAndShadeMixingMultiplierMultiplyTexture),
            };
            mtoonDefinition.Lighting.LightingInfluence = new LightingInfluenceDefinition()
            {
                LightColorAttenuationValue = mtoon.lightColorAttenuationFactor,
                GiIntensityValue           = mtoon.giIntensityFactor,
            };
            mtoonDefinition.Lighting.Normal = new NormalDefinition()
            {
                NormalTexture    = GetTexture(MToon.Utils.PropBumpMap, mtoon.normalTexture),
                NormalScaleValue = mtoon.normalScaleFactor,
            };

            // Emission
            mtoonDefinition.Emission = new EmissionDefinition()
            {
                EmissionColor           = ArrayConverter.ToColor(mtoon.emissionFactor, gamma: true),
                EmissionMultiplyTexture = GetTexture(MToon.Utils.PropEmissionMap, mtoon.emissionMultiplyTexture),
            };

            // MatCap
            mtoonDefinition.MatCap = new MatCapDefinition()
            {
                AdditiveTexture = GetTexture(MToon.Utils.PropSphereAdd, mtoon.additiveTexture),
            };

            // Rim
            mtoonDefinition.Rim = new RimDefinition()
            {
                RimColor             = ArrayConverter.ToColor(mtoon.rimFactor, gamma: true),
                RimMultiplyTexture   = GetTexture(MToon.Utils.PropRimTexture, mtoon.rimMultiplyTexture),
                RimLightingMixValue  = mtoon.rimLightingMixFactor,
                RimFresnelPowerValue = mtoon.rimFresnelPowerFactor,
                RimLiftValue         = mtoon.rimLiftFactor,
            };

            // Outline
            mtoonDefinition.Outline = new OutlineDefinition()
            {
                OutlineWidthMode              = (MToon.OutlineWidthMode)mtoon.outlineWidthMode,
                OutlineWidthValue             = mtoon.outlineWidthFactor,
                OutlineWidthMultiplyTexture   = GetTexture(MToon.Utils.PropOutlineWidthTexture, mtoon.outlineWidthMultiplyTexture),
                OutlineScaledMaxDistanceValue = mtoon.outlineScaledMaxDistanceFactor,
                OutlineColorMode              = (MToon.OutlineColorMode)mtoon.outlineColorMode,
                OutlineColor            = ArrayConverter.ToColor(mtoon.outlineFactor, gamma: true),
                OutlineLightingMixValue = mtoon.outlineLightingMixFactor,
            };

            // Texture Option
            mtoonDefinition.TextureOption = new TextureUvCoordsDefinition()
            {
                MainTextureLeftBottomOriginScale  = ArrayConverter.ToVector2(mtoon.mainTextureLeftBottomOriginScale),
                MainTextureLeftBottomOriginOffset = ArrayConverter.ToVector2(mtoon.mainTextureLeftBottomOriginOffset),
                UvAnimationMaskTexture            = GetTexture(MToon.Utils.PropUvAnimMaskTexture, mtoon.uvAnimationMaskTexture),
                UvAnimationScrollXSpeedValue      = mtoon.uvAnimationScrollXSpeedFactor,
                UvAnimationScrollYSpeedValue      = mtoon.uvAnimationScrollYSpeedFactor,
                UvAnimationRotationSpeedValue     = mtoon.uvAnimationRotationSpeedFactor,
            };

            return(mtoonDefinition);
        }
Пример #5
0
        /// <summary>
        /// Create a Skybox material.
        /// </summary>
        /// <param name="i"></param>
        /// <param name="src"></param>
        /// <returns></returns>
        protected virtual Material CreateSkyboxMaterial(int i, glTFMaterial src)
        {
            var shader = m_shaderStore.GetShader(src);

            Material material = new Material(shader);

            material.name = CreateMaterialName(i, src);

#if UNITY_EDITOR
            material.hideFlags = HideFlags.DontUnloadUnusedAsset;
#endif

            VGO_materials_skybox vgoSkybox = src.extensions.VGO_materials_skybox;

            switch (shader.name)
            {
            case ShaderName.Skybox_6_Sided:
                UniSkybox.Utils.SetParametersToMaterial(material, new Skybox6SidedDefinition()
                {
                    Tint     = ArrayConverter.ToColor(vgoSkybox.tint, gamma: true),
                    Exposure = vgoSkybox.exposure,
                    Rotation = vgoSkybox.rotation,
                    FrontTex = GetTexture(UniSkybox.Utils.PropFrontTex, vgoSkybox.frontTexIndex),
                    BackTex  = GetTexture(UniSkybox.Utils.PropBackTex, vgoSkybox.backTexIndex),
                    LeftTex  = GetTexture(UniSkybox.Utils.PropLeftTex, vgoSkybox.leftTexIndex),
                    RightTex = GetTexture(UniSkybox.Utils.PropRightTex, vgoSkybox.rightTexIndex),
                    UpTex    = GetTexture(UniSkybox.Utils.PropUpTex, vgoSkybox.upTexIndex),
                    DownTex  = GetTexture(UniSkybox.Utils.PropDownTex, vgoSkybox.downTexIndex),
                });
                break;

            case ShaderName.Skybox_Cubemap:      // @todo Tex (Cubemap)
                UniSkybox.Utils.SetParametersToMaterial(material, new SkyboxCubemapDefinition()
                {
                    Tint     = ArrayConverter.ToColor(vgoSkybox.tint, gamma: true),
                    Exposure = vgoSkybox.exposure,
                    Rotation = vgoSkybox.rotation,
                    Tex      = GetCubemap(UniSkybox.Utils.PropTex, vgoSkybox.texIndex),
                });
                break;

            case ShaderName.Skybox_Panoramic:
                UniSkybox.Utils.SetParametersToMaterial(material, new SkyboxPanoramicDefinition()
                {
                    Tint         = ArrayConverter.ToColor(vgoSkybox.tint, gamma: true),
                    Exposure     = vgoSkybox.exposure,
                    Rotation     = vgoSkybox.rotation,
                    MainTex      = GetTexture(UniSkybox.Utils.PropMainTex, vgoSkybox.mainTexIndex),
                    Mapping      = (Mapping)vgoSkybox.mapping,
                    ImageType    = (ImageType)vgoSkybox.imageType,
                    MirrorOnBack = vgoSkybox.mirrorOnBack,
                    Layout       = (Layout)vgoSkybox.layout,
                });
                break;

            case ShaderName.Skybox_Procedural:
                UniSkybox.Utils.SetParametersToMaterial(material, new SkyboxProceduralDefinition()
                {
                    SunDisk             = (SunDisk)vgoSkybox.sunDisk,
                    SunSize             = vgoSkybox.sunSize,
                    SunSizeConvergence  = vgoSkybox.sunSizeConvergence,
                    AtmosphereThickness = vgoSkybox.atmosphereThickness,
                    SkyTint             = ArrayConverter.ToColor(vgoSkybox.skyTint, gamma: true),
                    GroundColor         = ArrayConverter.ToColor(vgoSkybox.groundColor, gamma: true),
                    Exposure            = vgoSkybox.exposure,
                });
                break;

            default:
                break;
            }

            return(material);
        }