internal SpeedTreeUpgrader(string oldShaderName)
 {
     RenameShader(oldShaderName, ShaderUtils.GetShaderPath(ShaderPathID.SpeedTree7));
 }
        public void OnPreprocessMaterialDescription(MaterialDescription description, Material material, AnimationClip[] clips)
        {
            var pipelineAsset = GraphicsSettings.currentRenderPipeline;

            if (!pipelineAsset || pipelineAsset.GetType() != typeof(UniversalRenderPipelineAsset))
            {
                return;
            }

            var lowerCasePath = Path.GetExtension(assetPath).ToLower();

            if (lowerCasePath != ".skp")
            {
                return;
            }

            string path   = AssetDatabase.GUIDToAssetPath(ShaderUtils.GetShaderGUID(ShaderPathID.Lit));
            var    shader = AssetDatabase.LoadAssetAtPath <Shader>(path);

            if (shader == null)
            {
                return;
            }
            material.shader = shader;

            float   floatProperty;
            Vector4 vectorProperty;
            TexturePropertyDescription textureProperty;

            if (description.TryGetProperty("DiffuseMap", out textureProperty) && textureProperty.texture != null)
            {
                SetMaterialTextureProperty("_BaseMap", material, textureProperty);
                SetMaterialTextureProperty("_MainTex", material, textureProperty);
                var color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
                material.SetColor("_BaseColor", color);
                material.SetColor("_Color", color);
            }
            else if (description.TryGetProperty("DiffuseColor", out vectorProperty))
            {
                Color diffuseColor = vectorProperty;
                diffuseColor = PlayerSettings.colorSpace == ColorSpace.Linear ? diffuseColor.gamma : diffuseColor;
                material.SetColor("_BaseColor", diffuseColor);
                material.SetColor("_Color", diffuseColor);
            }

            if (description.TryGetProperty("IsTransparent", out floatProperty) && floatProperty == 1.0f)
            {
                material.SetFloat("_Mode", 3.0f); // From C# enum BlendMode
                material.SetOverrideTag("RenderType", "Transparent");
                material.SetFloat("_SrcBlend", (float)UnityEngine.Rendering.BlendMode.One);
                material.SetFloat("_DstBlend", (float)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                material.SetFloat("_ZWrite", 0.0f);
                material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
                material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
                material.SetFloat("_Surface", 1.0f);
                material.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
            }
            else
            {
                material.SetFloat("_Mode", 0.0f); // From C# enum BlendMode
                material.SetOverrideTag("RenderType", "");
                material.SetFloat("_SrcBlend", (float)UnityEngine.Rendering.BlendMode.One);
                material.SetFloat("_DstBlend", (float)UnityEngine.Rendering.BlendMode.Zero);
                material.SetFloat("_ZWrite", 1.0f);
                material.DisableKeyword("_ALPHATEST_ON");
                material.DisableKeyword("_ALPHABLEND_ON");
                material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                material.renderQueue = -1;
                material.SetFloat("_Surface", 0.0f);
                material.DisableKeyword("_SURFACE_TYPE_TRANSPARENT");
            }
        }
 public TerrainUpgrader(string oldShaderName)
 {
     RenameShader(oldShaderName, ShaderUtils.GetShaderPath(ShaderPathID.TerrainLit));
 }
    protected void Start()
    {
        CheatMgr mgr = CheatMgr.Get();

        if (mgr != null)
        {
            mgr.RegisterCheatHandler("wireframe", new CheatMgr.ProcessCheatCallback(this.OnProcessCheat_RenderWireframe), null, null, null);
        }
        base.gameObject.GetComponent <Camera>().clearFlags = CameraClearFlags.Color;
        if (!SystemInfo.supportsImageEffects)
        {
            Debug.LogError("Fullscreen Effects not supported");
            base.enabled = false;
        }
        else
        {
            if (this.m_BlurShader == null)
            {
                this.m_BlurShader = ShaderUtils.FindShader("Custom/FullScreen/Blur");
            }
            if (this.m_BlurShader == null)
            {
                Debug.LogError("Fullscreen Effect Failed to load Shader: Custom/FullScreen/Blur");
                base.enabled = false;
            }
            if ((this.m_BlurShader == null) || !this.blurMaterial.shader.isSupported)
            {
                Debug.LogError("Fullscreen Effect Shader not supported: Custom/FullScreen/Blur");
                base.enabled = false;
            }
            else
            {
                if (this.m_BlurVignettingShader == null)
                {
                    this.m_BlurVignettingShader = ShaderUtils.FindShader("Custom/FullScreen/BlurVignetting");
                }
                if (this.m_BlurVignettingShader == null)
                {
                    Debug.LogError("Fullscreen Effect Failed to load Shader: Custom/FullScreen/BlurVignetting");
                    base.enabled = false;
                }
                if (this.m_BlurDesaturationShader == null)
                {
                    this.m_BlurDesaturationShader = ShaderUtils.FindShader("Custom/FullScreen/DesaturationBlur");
                }
                if (this.m_BlurDesaturationShader == null)
                {
                    Debug.LogError("Fullscreen Effect Failed to load Shader: Custom/FullScreen/DesaturationBlur");
                    base.enabled = false;
                }
                if (this.m_BlendShader == null)
                {
                    this.m_BlendShader = ShaderUtils.FindShader("Custom/FullScreen/Blend");
                }
                if (this.m_BlendShader == null)
                {
                    Debug.LogError("Fullscreen Effect Failed to load Shader: Custom/FullScreen/Blend");
                    base.enabled = false;
                }
                if (this.m_VignettingShader == null)
                {
                    this.m_VignettingShader = ShaderUtils.FindShader("Custom/FullScreen/Vignetting");
                }
                if (this.m_VignettingShader == null)
                {
                    Debug.LogError("Fullscreen Effect Failed to load Shader: Custom/FullScreen/Vignetting");
                    base.enabled = false;
                }
                if (this.m_BlendToColorShader == null)
                {
                    this.m_BlendToColorShader = ShaderUtils.FindShader("Custom/FullScreen/BlendToColor");
                }
                if (this.m_BlendToColorShader == null)
                {
                    Debug.LogError("Fullscreen Effect Failed to load Shader: Custom/FullScreen/BlendToColor");
                    base.enabled = false;
                }
                if (this.m_DesaturationShader == null)
                {
                    this.m_DesaturationShader = ShaderUtils.FindShader("Custom/FullScreen/Desaturation");
                }
                if (this.m_DesaturationShader == null)
                {
                    Debug.LogError("Fullscreen Effect Failed to load Shader: Custom/FullScreen/Desaturation");
                    base.enabled = false;
                }
                if (this.m_DesaturationVignettingShader == null)
                {
                    this.m_DesaturationVignettingShader = ShaderUtils.FindShader("Custom/FullScreen/DesaturationVignetting");
                }
                if (this.m_DesaturationVignettingShader == null)
                {
                    Debug.LogError("Fullscreen Effect Failed to load Shader: Custom/FullScreen/DesaturationVignetting");
                    base.enabled = false;
                }
                if (this.m_BlurDesaturationVignettingShader == null)
                {
                    this.m_BlurDesaturationVignettingShader = ShaderUtils.FindShader("Custom/FullScreen/BlurDesaturationVignetting");
                }
                if (this.m_BlurDesaturationVignettingShader == null)
                {
                    Debug.LogError("Fullscreen Effect Failed to load Shader: Custom/FullScreen/BlurDesaturationVignetting");
                    base.enabled = false;
                }
            }
        }
    }
 public TerrainUpgrader(string oldShaderName)
 {
     RenameShader(oldShaderName, ShaderUtils.GetShaderPath(ShaderPathID.TerrainPhysicallyBased));
 }
Beispiel #6
0
        /// <summary>
        /// Load content for the screen.
        /// </summary>
        /// <param name="GraphicInfo"></param>
        /// <param name="factory"></param>
        /// <param name="contentManager"></param>
        protected override void LoadContent(PloobsEngine.Engine.GraphicInfo GraphicInfo, PloobsEngine.Engine.GraphicFactory factory, IContentManager contentManager)
        {
            ///must be called before all
            base.LoadContent(GraphicInfo, factory, contentManager);

            {
                ///Create a simple object
                ///Geomtric Info and textures (this model automaticaly loads the texture)
                SimpleModel simpleModel = new SimpleModel(factory, "model/dude");
                //simpleModel.SetTexture(factory.CreateTexture2DColor(1,1,Color.Red), TextureType.DIFFUSE);
                ///Physic info (position, rotation and scale are set here)
                GhostObject pi = new GhostObject(new Vector3(200, 10, 0), Matrix.Identity, new Vector3(4));
                ///Shader info (must be a deferred type)
                DeferredNormalShader shader = new DeferredNormalShader();
                shader.ShaderId = ShaderUtils.CreateBitField(false, false, false, false, true);
                ///Material info (must be a deferred type also)
                DeferredMaterial fmaterial = new DeferredMaterial(shader);
                fmaterial.IsVisible = false;
                ///The object itself
                IObject obj = new IObject(fmaterial, simpleModel, pi);
                ///Add to the world
                this.World.AddObject(obj);
                StealthPostEffect StealthPostEffect = new StealthPostEffect();
                StealthPostEffect.objs.Add(obj);
                this.RenderTechnic.AddPostEffect(StealthPostEffect);
            }



            {
                ///Create a simple object
                ///Geomtric Info and textures (this model automaticaly loads the texture)
                SimpleModel simpleModel = new SimpleModel(factory, "model/cenario");
                ///Physic info (position, rotation and scale are set here)
                TriangleMeshObject tmesh = new TriangleMeshObject(simpleModel, Vector3.Zero, Matrix.Identity, Vector3.One, MaterialDescription.DefaultBepuMaterial());
                ///Shader info (must be a deferred type)
                DeferredNormalShader shader = new DeferredNormalShader();
                ///Material info (must be a deferred type also)
                DeferredMaterial fmaterial = new DeferredMaterial(shader);
                ///The object itself
                IObject obj = new IObject(fmaterial, simpleModel, tmesh);
                ///Add to the world
                this.World.AddObject(obj);
            }
            ///Add some directional lights to completely iluminate the world
            #region Lights
            DirectionalLightPE ld1 = new DirectionalLightPE(Vector3.Left, Color.White);
            DirectionalLightPE ld2 = new DirectionalLightPE(Vector3.Right, Color.White);
            DirectionalLightPE ld3 = new DirectionalLightPE(Vector3.Backward, Color.White);
            DirectionalLightPE ld4 = new DirectionalLightPE(Vector3.Forward, Color.White);
            DirectionalLightPE ld5 = new DirectionalLightPE(Vector3.Down, Color.White);
            float li = 0.4f;
            ld1.LightIntensity = li;
            ld2.LightIntensity = li;
            ld3.LightIntensity = li;
            ld4.LightIntensity = li;
            ld5.LightIntensity = li;
            this.World.AddLight(ld1);
            this.World.AddLight(ld2);
            this.World.AddLight(ld3);
            this.World.AddLight(ld4);
            this.World.AddLight(ld5);
            #endregion

            ///Add a AA post effect
            //this.RenderTechnic.AddPostEffect(new AntiAliasingPostEffect());

            ///add a camera
            this.World.CameraManager.AddCamera(new CameraFirstPerson(GraphicInfo));

            SkyBoxSetTextureCube stc = new SkyBoxSetTextureCube("Textures//cubemap");
            CommandProcessor.getCommandProcessor().SendCommandAssyncronous(stc);
        }
        public void OnPreprocessMaterialDescription(MaterialDescription description, Material material, AnimationClip[] clips)
        {
            var pipelineAsset = GraphicsSettings.currentRenderPipeline;

            if (!pipelineAsset || pipelineAsset.GetType() != typeof(UniversalRenderPipelineAsset))
            {
                return;
            }

            var lowerCasePath = Path.GetExtension(assetPath).ToLower();

            if (lowerCasePath != ".3ds")
            {
                return;
            }

            string path   = AssetDatabase.GUIDToAssetPath(ShaderUtils.GetShaderGUID(ShaderPathID.Lit));
            var    shader = AssetDatabase.LoadAssetAtPath <Shader>(path);

            if (shader == null)
            {
                return;
            }
            material.shader = shader;

            TexturePropertyDescription textureProperty;
            float   floatProperty;
            Vector4 vectorProperty;

            description.TryGetProperty("diffuse", out vectorProperty);
            vectorProperty.x /= 255.0f;
            vectorProperty.y /= 255.0f;
            vectorProperty.z /= 255.0f;
            vectorProperty.w /= 255.0f;
            description.TryGetProperty("transparency", out floatProperty);

            bool isTransparent = vectorProperty.w <= 0.99f || floatProperty > .0f;

            if (isTransparent)
            {
                material.SetFloat("_Mode", (float)3.0); // From C# enum BlendMode
                material.SetOverrideTag("RenderType", "Transparent");
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                material.SetInt("_ZWrite", 0);
                material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
                material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
                material.SetInt("_Surface", 1);
            }
            else
            {
                material.SetFloat("_Mode", (float)0.0); // From C# enum BlendMode
                material.SetOverrideTag("RenderType", "");
                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 = -1;
                material.SetInt("_Surface", 0);
            }

            if (floatProperty > .0f)
            {
                vectorProperty.w = 1.0f - floatProperty;
            }

            Color diffuseColor = vectorProperty;

            material.SetColor("_Color", PlayerSettings.colorSpace == ColorSpace.Linear ? diffuseColor.gamma : diffuseColor);
            material.SetColor("_BaseColor", PlayerSettings.colorSpace == ColorSpace.Linear ? diffuseColor.gamma : diffuseColor);

            if (description.TryGetProperty("EmissiveColor", out vectorProperty))
            {
                material.SetColor("_EmissionColor", vectorProperty);
                material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.RealtimeEmissive;
                material.EnableKeyword("_EMISSION");
            }

            if (description.TryGetProperty("texturemap1", out textureProperty))
            {
                SetMaterialTextureProperty("_BaseMap", material, textureProperty);
            }

            if (description.TryGetProperty("bumpmap", out textureProperty))
            {
                if (material.HasProperty("_BumpMap"))
                {
                    SetMaterialTextureProperty("_BumpMap", material, textureProperty);
                    material.EnableKeyword("_NORMALMAP");
                }
            }
        }
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            var upgradeLog   = "LWRP Material log:";
            var upgradeCount = 0;

            foreach (var asset in importedAssets)
            {
                if (!asset.ToLowerInvariant().EndsWith(".mat"))
                {
                    continue;
                }

                var material = (Material)AssetDatabase.LoadAssetAtPath(asset, typeof(Material));
                if (!ShaderUtils.IsLWShader(material.shader))
                {
                    continue;
                }

                ShaderPathID id            = ShaderUtils.GetEnumFromPath(material.shader.name);
                var          wasUpgraded   = false;
                var          assetVersions = AssetDatabase.LoadAllAssetsAtPath(asset);
                AssetVersion assetVersion  = null;
                foreach (var subAsset in assetVersions)
                {
                    if (subAsset.GetType() == typeof(AssetVersion))
                    {
                        assetVersion = subAsset as AssetVersion;
                    }
                }
                var debug = "\n" + material.name;

                if (!assetVersion)
                {
                    wasUpgraded  = true;
                    assetVersion = ScriptableObject.CreateInstance <AssetVersion>();
                    if (s_CreatedAssets.Contains(asset))
                    {
                        assetVersion.version = k_Upgraders.Length;
                        s_CreatedAssets.Remove(asset);
                        InitializeLatest(material, id);
                    }
                    else
                    {
                        assetVersion.version = 0;
                    }

                    assetVersion.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector | HideFlags.NotEditable;
                    AssetDatabase.AddObjectToAsset(assetVersion, asset);
                    debug += " initialized.";
                }

                while (assetVersion.version < k_Upgraders.Length)
                {
                    k_Upgraders[assetVersion.version](material, id);
                    debug += $" upgrading:v{assetVersion.version} to v{assetVersion.version + 1}";
                    assetVersion.version++;
                    wasUpgraded = true;
                }

                if (wasUpgraded)
                {
                    upgradeLog += debug;
                    upgradeCount++;
                    EditorUtility.SetDirty(assetVersion);
                }
            }
            if (upgradeCount > 0)
            {
                Debug.Log(upgradeLog);
            }
        }
        public void OnPreprocessMaterialDescription(MaterialDescription description, Material material, AnimationClip[] clips)
        {
            var lowerCaseExtension = Path.GetExtension(assetPath).ToLower();

            if (lowerCaseExtension != ".fbx" && lowerCaseExtension != ".obj" && lowerCaseExtension != ".blend" && lowerCaseExtension != ".mb" && lowerCaseExtension != ".ma" && lowerCaseExtension != ".max")
            {
                return;
            }

            string path   = AssetDatabase.GUIDToAssetPath(ShaderUtils.GetShaderGUID(ShaderPathID.Lit));
            var    shader = AssetDatabase.LoadAssetAtPath <Shader>(path);

            if (shader == null)
            {
                return;
            }


            material.shader = shader;

            Vector4 vectorProperty;
            float   floatProperty;
            TexturePropertyDescription textureProperty;

            bool isTransparent = false;

            float opacity;
            float transparencyFactor;

            if (!description.TryGetProperty("Opacity", out opacity))
            {
                if (description.TryGetProperty("TransparencyFactor", out transparencyFactor))
                {
                    opacity = transparencyFactor == 1.0f ? 1.0f : 1.0f - transparencyFactor;
                }
                if (opacity == 1.0f && description.TryGetProperty("TransparentColor", out vectorProperty))
                {
                    opacity = vectorProperty.x == 1.0f ? 1.0f : 1.0f - vectorProperty.x;
                }
            }
            if (opacity < 1.0f || (opacity == 1.0f && description.TryGetProperty("TransparentColor", out textureProperty)))
            {
                isTransparent = true;
            }
            else if (description.HasAnimationCurve("TransparencyFactor") || description.HasAnimationCurve("TransparentColor"))
            {
                isTransparent = true;
            }

            if (isTransparent)
            {
                material.SetInt("_Mode", 3);
                material.SetOverrideTag("RenderType", "Transparent");
                material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                material.SetInt("_ZWrite", 0);
                material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
                material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
                material.SetInt("_Surface", 1);
            }
            else
            {
                material.SetInt("_Mode", 0);
                material.SetOverrideTag("RenderType", "");
                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 = -1;
                material.SetInt("_Surface", 0);
            }

            if (description.TryGetProperty("DiffuseColor", out textureProperty) && textureProperty.texture != null)
            {
                Color diffuseColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
                if (description.TryGetProperty("DiffuseFactor", out floatProperty))
                {
                    diffuseColor *= floatProperty;
                }
                diffuseColor.a = opacity;

                SetMaterialTextureProperty("_BaseMap", material, textureProperty);
                material.SetColor("_BaseColor", diffuseColor);
            }
            else if (description.TryGetProperty("DiffuseColor", out vectorProperty))
            {
                Color diffuseColor = vectorProperty;
                diffuseColor.a = opacity;
                material.SetColor("_BaseColor", PlayerSettings.colorSpace == ColorSpace.Linear ? diffuseColor.gamma : diffuseColor);
            }

            if (description.TryGetProperty("Bump", out textureProperty))
            {
                SetMaterialTextureProperty("_BumpMap", material, textureProperty);
                material.EnableKeyword("_NORMALMAP");

                if (description.TryGetProperty("BumpFactor", out floatProperty))
                {
                    material.SetFloat("_BumpScale", floatProperty);
                }
            }
            else if (description.TryGetProperty("NormalMap", out textureProperty))
            {
                SetMaterialTextureProperty("_BumpMap", material, textureProperty);
                material.EnableKeyword("_NORMALMAP");

                if (description.TryGetProperty("BumpFactor", out floatProperty))
                {
                    material.SetFloat("_BumpScale", floatProperty);
                }
            }

            if (description.TryGetProperty("EmissiveColor", out textureProperty))
            {
                Color emissiveColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);

                material.SetColor("_EmissionColor", emissiveColor);
                SetMaterialTextureProperty("_EmissionMap", material, textureProperty);

                if (description.TryGetProperty("EmissiveFactor", out floatProperty) && floatProperty > 0.0f)
                {
                    material.EnableKeyword("_EMISSION");
                    material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.RealtimeEmissive;
                }
            }
            else if (
                description.TryGetProperty("EmissiveColor", out vectorProperty) && vectorProperty.magnitude > vectorProperty.w ||
                description.HasAnimationCurve("EmissiveColor.x"))
            {
                if (description.TryGetProperty("EmissiveFactor", out floatProperty))
                {
                    vectorProperty *= floatProperty;
                }

                material.SetColor("_EmissionColor", vectorProperty);
                if (floatProperty > 0.0f)
                {
                    material.EnableKeyword("_EMISSION");
                    material.globalIlluminationFlags |= MaterialGlobalIlluminationFlags.RealtimeEmissive;
                }
            }

            material.SetFloat("_Glossiness", 0.0f);

            if (PlayerSettings.colorSpace == ColorSpace.Linear)
            {
                RemapAndTransformColorCurves(description, clips, "DiffuseColor", "_BaseColor", ConvertFloatLinearToGamma);
            }
            else
            {
                RemapColorCurves(description, clips, "DiffuseColor", "_BaseColor");
            }

            RemapTransparencyCurves(description, clips);

            RemapColorCurves(description, clips, "EmissiveColor", "_EmissionColor");
        }
Beispiel #10
0
 protected void Initialize()
 {
     if (!this.m_Initialized)
     {
         this.m_Initialized = true;
         if (this.m_HighlightShader == null)
         {
             this.m_HighlightShader = ShaderUtils.FindShader(this.HIGHLIGHT_SHADER_NAME);
         }
         if (this.m_HighlightShader == null)
         {
             Debug.LogError("Failed to load Highlight Shader: " + this.HIGHLIGHT_SHADER_NAME);
             base.enabled = false;
         }
         base.GetComponent <Renderer>().material.shader = this.m_HighlightShader;
         if (this.m_MultiSampleShader == null)
         {
             this.m_MultiSampleShader = ShaderUtils.FindShader(this.MULTISAMPLE_SHADER_NAME);
         }
         if (this.m_MultiSampleShader == null)
         {
             Debug.LogError("Failed to load Highlight Shader: " + this.MULTISAMPLE_SHADER_NAME);
             base.enabled = false;
         }
         if (this.m_MultiSampleBlendShader == null)
         {
             this.m_MultiSampleBlendShader = ShaderUtils.FindShader(this.MULTISAMPLE_BLEND_SHADER_NAME);
         }
         if (this.m_MultiSampleBlendShader == null)
         {
             Debug.LogError("Failed to load Highlight Shader: " + this.MULTISAMPLE_BLEND_SHADER_NAME);
             base.enabled = false;
         }
         if (this.m_BlendShader == null)
         {
             this.m_BlendShader = ShaderUtils.FindShader(this.BLEND_SHADER_NAME);
         }
         if (this.m_BlendShader == null)
         {
             Debug.LogError("Failed to load Highlight Shader: " + this.BLEND_SHADER_NAME);
             base.enabled = false;
         }
         if (this.m_RootTransform == null)
         {
             Transform parent = base.transform.parent.parent;
             if (parent.GetComponent <ActorStateMgr>() != null)
             {
                 this.m_RootTransform = parent.parent;
             }
             else
             {
                 this.m_RootTransform = parent;
             }
             if (this.m_RootTransform == null)
             {
                 Debug.LogError("m_RootTransform is null. Highlighting disabled!");
                 base.enabled = false;
             }
         }
         this.m_VisibilityStates = new Map <Renderer, bool>();
         HighlightSilhouetteInclude[] componentsInChildren = this.m_RootTransform.GetComponentsInChildren <HighlightSilhouetteInclude>();
         if (componentsInChildren != null)
         {
             foreach (HighlightSilhouetteInclude include in componentsInChildren)
             {
                 Renderer component = include.gameObject.GetComponent <Renderer>();
                 if (component != null)
                 {
                     this.m_VisibilityStates.Add(component, false);
                 }
             }
         }
         this.m_UnlitColorShader = ShaderUtils.FindShader(this.UNLIT_COLOR_SHADER_NAME);
         if (this.m_UnlitColorShader == null)
         {
             Debug.LogError("Failed to load Highlight Rendering Shader: " + this.UNLIT_COLOR_SHADER_NAME);
         }
         this.m_UnlitGreyShader = ShaderUtils.FindShader(this.UNLIT_GREY_SHADER_NAME);
         if (this.m_UnlitGreyShader == null)
         {
             Debug.LogError("Failed to load Highlight Rendering Shader: " + this.UNLIT_GREY_SHADER_NAME);
         }
         this.m_UnlitLightGreyShader = ShaderUtils.FindShader(this.UNLIT_LIGHTGREY_SHADER_NAME);
         if (this.m_UnlitLightGreyShader == null)
         {
             Debug.LogError("Failed to load Highlight Rendering Shader: " + this.UNLIT_LIGHTGREY_SHADER_NAME);
         }
         this.m_UnlitDarkGreyShader = ShaderUtils.FindShader(this.UNLIT_DARKGREY_SHADER_NAME);
         if (this.m_UnlitDarkGreyShader == null)
         {
             Debug.LogError("Failed to load Highlight Rendering Shader: " + this.UNLIT_DARKGREY_SHADER_NAME);
         }
         this.m_UnlitBlackShader = ShaderUtils.FindShader(this.UNLIT_BLACK_SHADER_NAME);
         if (this.m_UnlitBlackShader == null)
         {
             Debug.LogError("Failed to load Highlight Rendering Shader: " + this.UNLIT_BLACK_SHADER_NAME);
         }
         this.m_UnlitWhiteShader = ShaderUtils.FindShader(this.UNLIT_WHITE_SHADER_NAME);
         if (this.m_UnlitWhiteShader == null)
         {
             Debug.LogError("Failed to load Highlight Rendering Shader: " + this.UNLIT_WHITE_SHADER_NAME);
         }
     }
 }
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            var upgradeLog   = "UniversalRP Material log:";
            var upgradeCount = 0;

            foreach (var asset in importedAssets)
            {
                if (!asset.EndsWith(".mat", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }

                var material = (Material)AssetDatabase.LoadAssetAtPath(asset, typeof(Material));
                if (!ShaderUtils.IsLWShader(material.shader))
                {
                    continue;
                }

                ShaderPathID id          = ShaderUtils.GetEnumFromPath(material.shader.name);
                var          wasUpgraded = false;

                var debug = "\n" + material.name;

                AssetVersion assetVersion = null;
                var          allAssets    = AssetDatabase.LoadAllAssetsAtPath(asset);
                foreach (var subAsset in allAssets)
                {
                    if (subAsset is AssetVersion sub)
                    {
                        assetVersion = sub;
                    }
                }

                if (!assetVersion)
                {
                    wasUpgraded  = true;
                    assetVersion = ScriptableObject.CreateInstance <AssetVersion>();
                    if (s_CreatedAssets.Contains(asset))
                    {
                        assetVersion.version = k_Upgraders.Length;
                        s_CreatedAssets.Remove(asset);
                        InitializeLatest(material, id);
                        debug += " initialized.";
                    }
                    else
                    {
                        assetVersion.version = UniversalProjectSettings.materialVersionForUpgrade;
                        debug += $" assumed to be version {UniversalProjectSettings.materialVersionForUpgrade} due to missing version.";
                    }

                    assetVersion.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector | HideFlags.NotEditable;
                    AssetDatabase.AddObjectToAsset(assetVersion, asset);
                }

                while (assetVersion.version < k_Upgraders.Length)
                {
                    k_Upgraders[assetVersion.version](material, id);
                    debug += $" upgrading:v{assetVersion.version} to v{assetVersion.version + 1}";
                    assetVersion.version++;
                    wasUpgraded = true;
                }

                if (wasUpgraded)
                {
                    upgradeLog += debug;
                    upgradeCount++;
                    EditorUtility.SetDirty(assetVersion);
                    s_ImportedAssetThatNeedSaving.Add(asset);
                    s_NeedsSavingAssets = true;
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// Load content for the screen.
        /// </summary>
        /// <param name="GraphicInfo"></param>
        /// <param name="factory"></param>
        /// <param name="contentManager"></param>
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo, factory, contentManager);

            #region Models

            {
                ///Need to load the height, the normal texture and the difuse texture
                SimpleModel sm = new SimpleModel(factory, "..\\Content\\Model\\block", "..\\Content\\Textures\\color_map");
                sm.SetTexture("Textures\\normal_map", TextureType.BUMP);
                sm.SetCubeTexture(factory.GetTextureCube("Textures//cubemap"), TextureType.ENVIRONMENT);

                BoxObject pi = new BoxObject(new Vector3(200, 110, 0), 1, 1, 1, 5, new Vector3(100, 100, 100), Matrix.Identity, MaterialDescription.DefaultBepuMaterial());
                DeferredEnvironmentCustomShader = new DeferredEnvironmentCustomShader(false, true, false);
                DeferredEnvironmentCustomShader.SpecularIntensity = 0.2f;
                DeferredEnvironmentCustomShader.SpecularPower     = 30;
                DeferredEnvironmentCustomShader.ReflectionIndex   = 0.5f;

                ///Setting Shader iD
                ///This make the object be not affect by the light
                DeferredEnvironmentCustomShader.ShaderId = ShaderUtils.CreateSpecificBitField(true);
                IMaterial mat  = new DeferredMaterial(DeferredEnvironmentCustomShader);
                IObject   obj3 = new IObject(mat, sm, pi);
                this.World.AddObject(obj3);

                {
                    SimpleConcreteKeyboardInputPlayable ik = new SimpleConcreteKeyboardInputPlayable(StateKey.PRESS, Keys.Space,
                                                                                                     (a) =>
                    {
                        if (DeferredEnvironmentCustomShader.ShaderId == ShaderUtils.CreateSpecificBitField(true))
                        {
                            DeferredEnvironmentCustomShader.ShaderId = ShaderUtils.CreateSpecificBitField(false);
                        }
                        else
                        {
                            DeferredEnvironmentCustomShader.ShaderId = ShaderUtils.CreateSpecificBitField(true);
                        }
                    }
                                                                                                     );
                    this.BindInput(ik);
                }
            }

            {
                SimpleModel          simpleModel = new SimpleModel(factory, "Model//cenario");
                TriangleMeshObject   tmesh       = new TriangleMeshObject(simpleModel, Vector3.Zero, Matrix.Identity, Vector3.One, MaterialDescription.DefaultBepuMaterial());
                DeferredCustomShader shader      = new DeferredCustomShader(false, false, false, false);
                DeferredMaterial     fmaterial   = new DeferredMaterial(shader);
                IObject obj = new IObject(fmaterial, simpleModel, tmesh);
                this.World.AddObject(obj);
            }

            #endregion

            #region NormalLight
            DirectionalLightPE ld1 = new DirectionalLightPE(Vector3.Left, Color.White);
            DirectionalLightPE ld2 = new DirectionalLightPE(Vector3.Right, Color.White);
            DirectionalLightPE ld3 = new DirectionalLightPE(Vector3.Backward, Color.White);
            DirectionalLightPE ld4 = new DirectionalLightPE(Vector3.Forward, Color.White);
            DirectionalLightPE ld5 = new DirectionalLightPE(Vector3.Down, Color.White);
            float li = 0.5f;
            ld1.LightIntensity = li;
            ld2.LightIntensity = li;
            ld3.LightIntensity = li;
            ld4.LightIntensity = li;
            ld5.LightIntensity = li;
            this.World.AddLight(ld1);
            this.World.AddLight(ld2);
            this.World.AddLight(ld3);
            this.World.AddLight(ld4);
            this.World.AddLight(ld5);
            #endregion

            CameraFirstPerson cam = new CameraFirstPerson(MathHelper.ToRadians(10), MathHelper.ToRadians(-10), new Vector3(200, 150, 250), GraphicInfo);
            this.World.CameraManager.AddCamera(cam);

            LightThrowBepu = new LightThrowBepu(this.World, GraphicFactory);

            SkyBoxSetTextureCube stc = new SkyBoxSetTextureCube("Textures//cubemap");
            CommandProcessor.getCommandProcessor().SendCommandAssyncronous(stc);
        }
Beispiel #13
0
        protected override void Draw(GameTime gameTime, RenderHelper render)
        {
            ///must be called before
            base.Draw(gameTime, render);

            ///Draw some text to the screen
            render.RenderTextComplete("Shader ID. The Big Box Object is not affected by the Light", new Vector2(20, 15), Color.White, Matrix.Identity);
            render.RenderTextComplete("This can be used to create lots of cool effects, like custom lightining", new Vector2(20, 35), Color.White, Matrix.Identity);
            render.RenderTextComplete("Press Space to toggle, left mouse buttom to throw a ball with a light", new Vector2(20, 55), Color.White, Matrix.Identity);
            render.RenderTextComplete("Box is Affected By Light: " + (DeferredEnvironmentCustomShader.ShaderId != ShaderUtils.CreateSpecificBitField(true)), new Vector2(20, 75), Color.White, Matrix.Identity);
        }
Beispiel #14
0
        }                                                               // null by now but use VFXURPSubOutput when there is a need to store URP specific data

        public override void SetupMaterial(Material material, bool hasMotionVector = false, bool hasShadowCasting = false, ShaderGraphVfxAsset shaderGraph = null)
        {
            ShaderUtils.UpdateMaterial(material, ShaderUtils.MaterialUpdateType.ModifiedShader);
            material.SetShaderPassEnabled("MotionVectors", hasMotionVector);
            material.SetShaderPassEnabled("ShadowCaster", hasShadowCasting);
        }