Exemplo n.º 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Set ParticleSystem rotationBySpeed field value.
        /// </summary>
        /// <param name="particleSystem"></param>
        /// <param name="vgoModule"></param>
        protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_RotationBySpeedModule vgoModule)
        {
            if (vgoModule == null)
            {
                return;
            }

            RotationBySpeedModule module = particleSystem.rotationBySpeed;

            module.enabled      = vgoModule.enabled;
            module.separateAxes = vgoModule.separateAxes;

            if (vgoModule.separateAxes)
            {
                module.x           = VgoParticleSystemMinMaxCurveConverter.CreateMinMaxCurve(vgoModule.x);
                module.y           = VgoParticleSystemMinMaxCurveConverter.CreateMinMaxCurve(vgoModule.y);
                module.z           = VgoParticleSystemMinMaxCurveConverter.CreateMinMaxCurve(vgoModule.z);
                module.xMultiplier = vgoModule.xMultiplier;
                module.yMultiplier = vgoModule.yMultiplier;
                module.zMultiplier = vgoModule.zMultiplier;
            }
            else
            {
                module.x           = VgoParticleSystemMinMaxCurveConverter.CreateMinMaxCurve(vgoModule.x);
                module.xMultiplier = vgoModule.xMultiplier;
            }

            module.range = ArrayConverter.ToVector2(vgoModule.range);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Set ParticleSystem shape field value.
        /// </summary>
        /// <param name="particleSystem"></param>
        /// <param name="vgoModule"></param>
        /// <param name="textureItemList"></param>
        protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_ShapeModule vgoModule, IList <TextureItem> textureItemList)
        {
            if (vgoModule == null)
            {
                return;
            }

            ShapeModule module = particleSystem.shape;

            module.enabled               = vgoModule.enabled;
            module.shapeType             = vgoModule.shapeType;
            module.angle                 = vgoModule.angle;
            module.radius                = vgoModule.radius;
            module.donutRadius           = vgoModule.donutRadius;
            module.radiusMode            = vgoModule.radiusMode;
            module.radiusSpread          = vgoModule.radiusSpread;
            module.radiusSpeed           = VgoParticleSystemMinMaxCurveConverter.CreateMinMaxCurve(vgoModule.radiusSpeed);
            module.radiusSpeedMultiplier = vgoModule.radiusSpeedMultiplier;
            module.radiusThickness       = vgoModule.radiusThickness;
            module.boxThickness          = ArrayConverter.ToVector3(vgoModule.boxThickness, reverseZ: true);
            module.arc                      = vgoModule.arc;
            module.arcMode                  = vgoModule.arcMode;
            module.arcSpread                = vgoModule.arcSpread;
            module.arcSpeed                 = VgoParticleSystemMinMaxCurveConverter.CreateMinMaxCurve(vgoModule.arcSpeed);
            module.arcSpeedMultiplier       = vgoModule.arcSpeedMultiplier;
            module.length                   = vgoModule.length;
            module.meshShapeType            = vgoModule.meshShapeType;
            module.meshSpawnMode            = vgoModule.meshSpawnMode;
            module.meshSpawnSpread          = vgoModule.meshSpawnSpread;
            module.meshSpawnSpeed           = VgoParticleSystemMinMaxCurveConverter.CreateMinMaxCurve(vgoModule.meshSpawnSpeed);
            module.meshSpawnSpeedMultiplier = vgoModule.meshSpawnSpeedMultiplier;
            //module.mesh;
            //module.meshRenderer;
            //module.skinnedMeshRenderer;
            module.useMeshMaterialIndex = vgoModule.useMeshMaterialIndex;
            module.meshMaterialIndex    = vgoModule.meshMaterialIndex;
            module.useMeshColors        = vgoModule.useMeshColors;
            //module.sprite;
            //module.spriteRenderer;
            module.normalOffset = vgoModule.normalOffset;
            if ((textureItemList != null) && (-1 < vgoModule.textureIndex) && (vgoModule.textureIndex < textureItemList.Count))
            {
                module.texture = textureItemList[vgoModule.textureIndex].Texture;
            }
            module.textureClipChannel           = vgoModule.textureClipChannel;
            module.textureClipThreshold         = vgoModule.textureClipThreshold;
            module.textureColorAffectsParticles = vgoModule.textureColorAffectsParticles;
            module.textureAlphaAffectsParticles = vgoModule.textureAlphaAffectsParticles;
            module.textureBilinearFiltering     = vgoModule.textureBilinearFiltering;
            module.textureUVChannel             = vgoModule.textureUVChannel;
            module.position                 = ArrayConverter.ToVector3(vgoModule.position, reverseZ: true);
            module.rotation                 = ArrayConverter.ToVector3(vgoModule.rotation, reverseZ: true);
            module.scale                    = ArrayConverter.ToVector3(vgoModule.scale);
            module.alignToDirection         = vgoModule.alignToDirection;
            module.randomPositionAmount     = vgoModule.randomPositionAmount;
            module.sphericalDirectionAmount = vgoModule.sphericalDirectionAmount;
            module.randomDirectionAmount    = vgoModule.randomDirectionAmount;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Set Collider field value.
        /// </summary>
        /// <param name="collider"></param>
        /// <param name="vgoCollider"></param>
        public static void SetComponentValue(Collider collider, VGO_Collider vgoCollider)
        {
            if (collider == null)
            {
                return;
            }

            if (vgoCollider == null)
            {
                return;
            }

            Type type = collider.GetType();

            if (type == typeof(BoxCollider))
            {
                var boxCollider = collider as BoxCollider;

                if (vgoCollider.type == ColliderType.Box)
                {
                    boxCollider.enabled        = vgoCollider.enabled;
                    boxCollider.isTrigger      = vgoCollider.isTrigger;
                    boxCollider.center         = ArrayConverter.ToVector3(vgoCollider.center, reverseZ: true);
                    boxCollider.size           = ArrayConverter.ToVector3(vgoCollider.size);
                    boxCollider.sharedMaterial = VgoPhysicMaterialConverter.ToPhysicMaterial(vgoCollider.physicMaterial);
                }
            }
            else if (type == typeof(CapsuleCollider))
            {
                var capsuleCollider = collider as CapsuleCollider;

                if (vgoCollider.type == ColliderType.Capsule)
                {
                    capsuleCollider.enabled        = vgoCollider.enabled;
                    capsuleCollider.isTrigger      = vgoCollider.isTrigger;
                    capsuleCollider.center         = ArrayConverter.ToVector3(vgoCollider.center, reverseZ: true);
                    capsuleCollider.radius         = vgoCollider.radius;
                    capsuleCollider.height         = vgoCollider.height;
                    capsuleCollider.direction      = vgoCollider.direction;
                    capsuleCollider.sharedMaterial = VgoPhysicMaterialConverter.ToPhysicMaterial(vgoCollider.physicMaterial);
                }
            }
            else if (type == typeof(SphereCollider))
            {
                var sphereCollider = collider as SphereCollider;

                if (vgoCollider.type == ColliderType.Sphere)
                {
                    sphereCollider.enabled        = vgoCollider.enabled;
                    sphereCollider.isTrigger      = vgoCollider.isTrigger;
                    sphereCollider.center         = ArrayConverter.ToVector3(vgoCollider.center, reverseZ: true);
                    sphereCollider.radius         = vgoCollider.radius;
                    sphereCollider.sharedMaterial = VgoPhysicMaterialConverter.ToPhysicMaterial(vgoCollider.physicMaterial);
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Set ParticleSystem colorOverLifetime field value.
        /// </summary>
        /// <param name="particleSystem"></param>
        /// <param name="vgoModule"></param>
        protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_ColorBySpeedModule vgoModule)
        {
            if (vgoModule == null)
            {
                return;
            }

            ColorBySpeedModule module = particleSystem.colorBySpeed;

            module.enabled = vgoModule.enabled;
            module.color   = VgoParticleSystemMinMaxGradientConverter.CreateMinMaxGradient(vgoModule.color);
            module.range   = ArrayConverter.ToVector2(vgoModule.range);
        }
Exemplo n.º 6
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;
                }
            }
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Set ParticleSystem main field value.
        /// </summary>
        /// <param name="particleSystem"></param>
        /// <param name="vgoModule"></param>
        protected virtual void SetModuleValue(ParticleSystem particleSystem, VGO_PS_MainModule vgoModule)
        {
            if (vgoModule == null)
            {
                return;
            }

            MainModule module = particleSystem.main;

            // @notice
            if (Application.isPlaying == false)
            {
                module.duration = vgoModule.duration;
            }

            module.loop                    = vgoModule.loop;
            module.prewarm                 = vgoModule.prewarm;
            module.startDelay              = VgoParticleSystemMinMaxCurveConverter.CreateMinMaxCurve(vgoModule.startDelay);
            module.startDelayMultiplier    = vgoModule.startDelayMultiplier;
            module.startLifetime           = VgoParticleSystemMinMaxCurveConverter.CreateMinMaxCurve(vgoModule.startLifetime);
            module.startLifetimeMultiplier = vgoModule.startLifetimeMultiplier;
            module.startSpeed              = VgoParticleSystemMinMaxCurveConverter.CreateMinMaxCurve(vgoModule.startSpeed);
            module.startSpeedMultiplier    = vgoModule.startSpeedMultiplier;

            module.startSize3D = vgoModule.startSize3D;

            if (vgoModule.startSize3D)
            {
                module.startSizeX           = VgoParticleSystemMinMaxCurveConverter.CreateMinMaxCurve(vgoModule.startSizeX);
                module.startSizeY           = VgoParticleSystemMinMaxCurveConverter.CreateMinMaxCurve(vgoModule.startSizeY);
                module.startSizeZ           = VgoParticleSystemMinMaxCurveConverter.CreateMinMaxCurve(vgoModule.startSizeZ);
                module.startSizeXMultiplier = vgoModule.startSizeXMultiplier;
                module.startSizeYMultiplier = vgoModule.startSizeYMultiplier;
                module.startSizeZMultiplier = vgoModule.startSizeZMultiplier;
            }
            else
            {
                module.startSize           = VgoParticleSystemMinMaxCurveConverter.CreateMinMaxCurve(vgoModule.startSize);
                module.startSizeMultiplier = vgoModule.startSizeMultiplier;
            }

            module.startRotation3D = vgoModule.startRotation3D;

            if (vgoModule.startRotation3D)
            {
                module.startRotationX           = VgoParticleSystemMinMaxCurveConverter.CreateMinMaxCurve(vgoModule.startRotationX);
                module.startRotationY           = VgoParticleSystemMinMaxCurveConverter.CreateMinMaxCurve(vgoModule.startRotationY);
                module.startRotationZ           = VgoParticleSystemMinMaxCurveConverter.CreateMinMaxCurve(vgoModule.startRotationZ);
                module.startRotationXMultiplier = vgoModule.StartRotationXMultiplier;
                module.startRotationYMultiplier = vgoModule.StartRotationYMultiplier;
                module.startRotationZMultiplier = vgoModule.StartRotationZMultiplier;
            }
            else
            {
                module.startRotation           = VgoParticleSystemMinMaxCurveConverter.CreateMinMaxCurve(vgoModule.startRotation);
                module.startRotationMultiplier = vgoModule.StartRotationMultiplier;
            }

            module.flipRotation              = vgoModule.flipRotation;
            module.startColor                = VgoParticleSystemMinMaxGradientConverter.CreateMinMaxGradient(vgoModule.startColor);
            module.gravityModifier           = VgoParticleSystemMinMaxCurveConverter.CreateMinMaxCurve(vgoModule.gravityModifier);
            module.gravityModifierMultiplier = vgoModule.gravityModifierMultiplier;

            module.simulationSpace = vgoModule.simulationSpace;
            module.simulationSpeed = vgoModule.simulationSpeed;
            VgoTransformConverter.SetComponentValue(module.customSimulationSpace, vgoModule.customSimulationSpace);

            module.useUnscaledTime     = vgoModule.useUnscaledTime;
            module.scalingMode         = vgoModule.scalingMode;
            module.playOnAwake         = vgoModule.playOnAwake;
            module.emitterVelocityMode = vgoModule.emitterVelocityMode;
            module.maxParticles        = vgoModule.maxParticles;
            module.stopAction          = vgoModule.stopAction;
            module.cullingMode         = vgoModule.cullingMode;
            module.ringBufferMode      = vgoModule.ringBufferMode;

            if (vgoModule.ringBufferMode == ParticleSystemRingBufferMode.LoopUntilReplaced)
            {
                module.ringBufferLoopRange = ArrayConverter.ToVector2(vgoModule.ringBufferLoopRange);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Set particleSystemRenderer field value.
        /// </summary>
        /// <param name="particleSystemRenderer"></param>
        /// <param name="vgoRenderer"></param>
        /// <param name="materialList"></param>
        public virtual void SetComponentValue(ParticleSystemRenderer particleSystemRenderer, VGO_PS_Renderer vgoRenderer, IList <Material> materialList)
        {
            if (vgoRenderer == null)
            {
                return;
            }

            particleSystemRenderer.enabled    = vgoRenderer.enabled;
            particleSystemRenderer.renderMode = vgoRenderer.renderMode;

            // Billboard
            particleSystemRenderer.cameraVelocityScale = vgoRenderer.cameraVelocityScale;
            particleSystemRenderer.velocityScale       = vgoRenderer.velocityScale;
            particleSystemRenderer.lengthScale         = vgoRenderer.lengthScale;
            particleSystemRenderer.normalDirection     = vgoRenderer.normalDirection;

            // Material
            if ((materialList != null) && (-1 < vgoRenderer.sharedMaterial) && (vgoRenderer.sharedMaterial < materialList.Count))
            {
                particleSystemRenderer.sharedMaterial = materialList[vgoRenderer.sharedMaterial];
            }

            if ((materialList != null) && (-1 < vgoRenderer.trailMaterialIndex) && (vgoRenderer.trailMaterialIndex < materialList.Count))
            {
                particleSystemRenderer.trailMaterial = materialList[vgoRenderer.trailMaterialIndex];
            }

            particleSystemRenderer.sortMode        = vgoRenderer.sortMode;
            particleSystemRenderer.sortingFudge    = vgoRenderer.sortingFudge;
            particleSystemRenderer.minParticleSize = vgoRenderer.minParticleSize;
            particleSystemRenderer.maxParticleSize = vgoRenderer.maxParticleSize;
            particleSystemRenderer.alignment       = vgoRenderer.alignment;
            particleSystemRenderer.flip            = ArrayConverter.ToVector3(vgoRenderer.flip, reverseZ: true);
            particleSystemRenderer.allowRoll       = vgoRenderer.allowRoll;
            particleSystemRenderer.pivot           = ArrayConverter.ToVector3(vgoRenderer.pivot, reverseZ: true);

            particleSystemRenderer.maskInteraction     = vgoRenderer.maskInteraction;
            particleSystemRenderer.enableGPUInstancing = vgoRenderer.enableGPUInstancing;

            // Shadow
            particleSystemRenderer.shadowCastingMode = vgoRenderer.shadowCastingMode;
            particleSystemRenderer.receiveShadows    = vgoRenderer.receiveShadows;
            particleSystemRenderer.shadowBias        = vgoRenderer.shadowBias;

            particleSystemRenderer.motionVectorGenerationMode = vgoRenderer.motionVectorGenerationMode;
            particleSystemRenderer.forceRenderingOff          = vgoRenderer.forceRenderingOff;
            particleSystemRenderer.rendererPriority           = vgoRenderer.rendererPriority;
            particleSystemRenderer.renderingLayerMask         = vgoRenderer.renderingLayerMask;
            particleSystemRenderer.sortingLayerID             = vgoRenderer.sortingLayerID;
            particleSystemRenderer.sortingOrder         = vgoRenderer.sortingOrder;
            particleSystemRenderer.lightProbeUsage      = vgoRenderer.lightProbeUsage;
            particleSystemRenderer.reflectionProbeUsage = vgoRenderer.reflectionProbeUsage;

            // @notice
            VgoTransformConverter.SetComponentValue(particleSystemRenderer.probeAnchor, vgoRenderer.probeAnchor);

            if (particleSystemRenderer.sharedMaterial != null)
            {
                //SetVertexStream(particleSystemRenderer, particleSystemRenderer.sharedMaterial);
            }
        }