Esempio n. 1
0
        public void Init(PostProcessChain parent, string shader_name)
        {
            if (_inited)
            {
                return;
            }

            _parent = parent;

            _shader = PostProcessChain.GetShader(shader_name);

            if (_shader != null)
            {
                _material = new Material(_shader);
            }

            if (_material == null)
            {
                Common.HobaDebuger.LogErrorFormat("PostProcessItem Init Failed: {0}", shader_name);
            }

            OnInit();

            //enabled = false;

            _inited = true;
        }
Esempio n. 2
0
    //void OnWaterLoaded(UnityEngine.Object obj)
    //{
    //    OnPBLoaded(obj, ref pbWater, ref _GroundWater, GROUND_TYPE.Water);
    //}

    //void OnShadowLoaded(UnityEngine.Object obj)
    //{
    //    OnPBLoaded(obj, ref pbShadow, ref _GroundShadow, GROUND_TYPE.Shadow);
    //}

    #region PostEffect

    private void SetupPP()
    {
        if (!UsePostEffect)
        {
            return;
        }

        if (_PPChainRef == null)
        {
            Camera main_camera = Main.Main3DCamera;
            if (main_camera != null)
            {
                _PPChainRef = main_camera.GetComponent <PostProcessChain>();
            }
        }

        if (_PPChainRef != null)
        {
            if (_PPChain == null && _UICamera != null)
            {
                _PPChain = _UICamera.GetComponent <PostProcessChain>();
            }
            if (_PPChain == null && _UICamera != null)
            {
                _PPChain = _UICamera.gameObject.AddComponent <PostProcessChain>();
            }
        }

        //_IsPPRunning = true;
    }
Esempio n. 3
0
    private void CleanPP()
    {
        //_IsPPRunning = false;

        if (_PPChain != null)
        {
            _PPChain.EnableHsvAdjust = false;
            _PPChain.enabled         = false;
            _PPChain = null;
        }

        _PPChainRef = null;
    }
Esempio n. 4
0
        protected override void OnRenderImage(RenderTexture src, RenderTexture dest)
        {
            accumulation = PostProcessChain.CreateRenderTexture(src.width >> _Divide, src.height >> _Divide, 0, RenderTextureFormat.Default, accumulation);

            if (rebuildacc)
            {
                Graphics.Blit(src, accumulation);

                Graphics.Blit(src, dest);
                rebuildacc = false;
            }
            else
            {
                float f = _parent.MotionBlurParamter.x;

                if (Duration > 0 && Elapse < Duration)
                {
                    float t = Elapse / Duration;
                    if (t < Fade_in_timing)
                    {
                        f *= Mathf.Clamp01(t / Fade_in_timing);
                    }
                    else if (t > Fade_out_timing)
                    {
                        f *= Mathf.Clamp01(((1 - t) / (1 - Fade_out_timing)));
                    }

                    _material.SetFloat(_BlendFactorId, f);
                    Graphics.Blit(src, accumulation, _material);

                    Graphics.Blit(accumulation, dest);

                    Elapse += Time.deltaTime;
                }
                else
                {
                    Graphics.Blit(src, dest);
                    _parent.EnableMotionBlur = false;
                }
            }
        }
Esempio n. 5
0
 private void Awake()
 {
     _MainCamera  = Main.Main3DCamera;
     _PostProcess = Main.MainPostProcessChain;
 }
Esempio n. 6
0
    public void OnDebugCmd(string cmd)
    {
        if (cmd.Contains("navmesh "))
        {
            NavMeshRenderer.Instance.OnDebugCmd(cmd);
        }
        else if (cmd.Contains("lightregion ") || cmd.Contains("regionset ") || cmd.Contains("obstacleset "))
        {
            MapRegionRenderer.Instance.OnDebugCmd(cmd);
        }
        else if (cmd.Contains("dn "))
        {
            ScenesManager.Instance.OnDebugCmd(cmd);
        }
        else if (cmd == "count")
        {
            U3DFuncWrap.Instance().OnDebugCmd(cmd);
        }
        else if (cmd == "abcount")
        {
        }
        else if (cmd.Contains("logtimer"))
        {
            HobaDebuger.LogWarningFormat("Timer Count: {0}", _TimerList.GetTimerCount());
            for (int i = 0; i < _TimerList.GetTimerCount(); ++i)
            {
                var tm = _TimerList.GetTimer(i);
                HobaDebuger.LogWarningFormat("Id:{0}, ttl:{1}, once:{2}, debug:{3}", tm.Id, tm.TTL, tm.IsOnce, tm.DebugInfo);
            }

            HobaDebuger.LogWarningFormat("Late Timer Count: {0}", _LateTimerList.GetTimerCount());
            for (int i = 0; i < _LateTimerList.GetTimerCount(); ++i)
            {
                var tm = _LateTimerList.GetTimer(i);
                HobaDebuger.LogWarningFormat("Id:{0}, ttl:{1}, once:{2}, debug:{3}", tm.Id, tm.TTL, tm.IsOnce, tm.DebugInfo);
            }
        }
        else if (cmd.Contains("showui "))
        {
            string[] result = cmd.Split(' ');
            if (result == null || result.GetLength(0) < 2)
            {
                return;
            }

            if (result[0].Equals("showui"))
            {
                if (_CmdTransform == null)
                {
                    _CmdTransform = Main.PanelRoot.Find("UI_Debug(Clone)") as RectTransform;
                }
                //if (cmdTransform == null)
                //    cmdTransform = Main.TopPateCanvas.Find("UI_Debug(Clone)") as RectTransform;

                if (_LogTransform == null)
                {
                    _LogTransform = Main.PanelRoot.Find("UI_Log(Clone)") as RectTransform;
                }
                //if (logTransform == null)
                //    logTransform = Main.TopPateCanvas.Find("UI_Log(Clone)") as RectTransform;

                if (_SkillSlotTransform == null)
                {
                    _SkillSlotTransform = Main.PanelRoot.Find("Panel_Main_SkillNew(Clone)") as RectTransform;
                }
                if (_UIHeadTransform == null)
                {
                    _UIHeadTransform = Main.PanelRoot.Find("UI_Head(Clone)") as RectTransform;
                }
                if (result[1].Equals("0"))
                {
                    if (_CmdTransform != null)
                    {
                        _CmdTransform.SetParent(Main.UIRootCanvas);
                    }
                    if (_LogTransform != null)
                    {
                        _LogTransform.SetParent(Main.UIRootCanvas);
                    }

                    if (_SkillSlotTransform != null)
                    {
                        _SkillSlotTransform.gameObject.SetActive(false);
                    }

                    if (_UIHeadTransform != null)
                    {
                        _UIHeadTransform.gameObject.SetActive(false);
                    }

                    Main.PanelRoot.gameObject.transform.localScale = Vector3.zero;
                    Main.PanelHUD.gameObject.SetActive(false);
                    Main.TopPateCanvas.gameObject.SetActive(false);
                }
                else
                {
                    Main.PanelRoot.gameObject.transform.localScale = Vector3.one;
                    Main.PanelHUD.gameObject.SetActive(true);
                    Main.TopPateCanvas.gameObject.SetActive(true);

                    if (_CmdTransform != null)
                    {
                        _CmdTransform.SetParent(Main.PanelRoot);
                    }
                    if (_LogTransform != null)
                    {
                        _LogTransform.SetParent(Main.PanelRoot);
                    }
                    if (_SkillSlotTransform != null)
                    {
                        _SkillSlotTransform.gameObject.SetActive(true);
                    }
                    if (_UIHeadTransform != null)
                    {
                        _UIHeadTransform.gameObject.SetActive(true);
                    }
                }
            }
        }
        else if (cmd.Contains("perfs "))
        {
            string[] result = cmd.Split(' ');
            if (result == null || result.GetLength(0) < 3)
            {
                return;
            }

            if (result[0].Equals("perfs"))
            {
                int opt;
                if (int.TryParse(result[1], out opt))
                {
                    bool enable = !result[2].Equals("0");
                    switch (opt)
                    {
                    case 1:
                        DebugOptionShowTerrain = enable;
                        ShowTerrain();
                        break;

                    case 2:
                        DebugOptionShowBlocks = enable;
                        ShowBlocks(); break;

                    case 3:
                        DebugOptionShowFx = enable;
                        ShowFx(); break;

                    case 4:
                        DebugOptionShowProjector = enable;
                        break;

                    default: break;
                    }
                }
            }
        }
        else if (cmd.Contains("postprocess "))
        {
            string[] result = cmd.Split(' ');
            if (result == null || result.GetLength(0) < 2)
            {
                return;
            }

            if (result[0].Equals("postprocess"))
            {
                if (result[1].Equals("0"))
                {
                    Camera           cam   = Main.Main3DCamera;
                    PostProcessChain chain = null;
                    if (cam != null)
                    {
                        chain = cam.GetComponent <PostProcessChain>();
                    }
                    if (chain != null)
                    {
                        chain.enabled = false;
                    }
                }
                else
                {
                    Camera           cam   = Main.Main3DCamera;
                    PostProcessChain chain = null;
                    if (cam != null)
                    {
                        chain = cam.GetComponent <PostProcessChain>();
                    }
                    if (chain != null)
                    {
                        chain.enabled = true;
                    }
                }
            }
        }
        else if (cmd.Contains("errormessage "))
        {
            string[] result = cmd.Split(' ');
            if (result == null || result.GetLength(0) < 2)
            {
                return;
            }

            if (result[0].Equals("errormessage"))
            {
                int id = 0;
                if (int.TryParse(result[1], out id))
                {
                    StartCoroutine(ShowErrorMessage(id));
                }
            }
        }
    }
Esempio n. 7
0
        void Render(RenderTexture src, RenderTexture dest)
        {
            if (_material == null)
            {
                Shader shader = PostProcessChain.GetShader("Hidden/PostProcessing/BloomHD");
                if (shader == null)
                {
                    Graphics.Blit(src, dest);
                    return;
                }
                _material = new Material(shader);
            }

            var threshold = Mathf.GammaToLinearSpace(Threshold);

            _material.SetFloat(_ThresholdId, threshold);

            float SoftKnee = SoftKneeA;
            var   knee     = threshold * SoftKnee + 1e-5f;
            var   curve    = new Vector3(threshold - knee, knee * 2, 0.25f / knee);

            _material.SetVector(_CurveId, curve);

            float sampleRadius = Radius;

            _material.SetFloat(_UpSampleScaleId, sampleRadius);

            _material.SetFloat(_IntensityId, Intensity);

            RenderTextureFormat rtFormat = RenderTextureFormat.DefaultHDR;

            int filterTexWidth  = Screen.width >> _Level;
            int filterTexHeight = Screen.height >> _Level;

            RenderTexture filter_texture = RenderTexture.GetTemporary(filterTexWidth, filterTexHeight, 0, rtFormat);

            filter_texture.name = "filter_texture";
            RenderTexture blend_texture = RenderTexture.GetTemporary(filterTexWidth, filterTexHeight, 0, rtFormat);

            blend_texture.name = "blend_texture";

            // 注意:WithFlicker 字面意思与实际作用正好相反
            Graphics.Blit(src, filter_texture, _material, WithFlicker ? (int)BloomHDPass.Bright : (int)BloomHDPass.BrightWithFlicker);

            int levelWidth  = filterTexWidth >> 1;
            int levelHeight = filterTexHeight >> 1;

            for (int i = 0; i < 16; ++i)
            {
                rtCache[i]  = null;
                rtCache1[i] = null;
            }

            RenderTexture last = filter_texture;

            // down sample
            int it = 0;

            for (; it < _Iteration && levelWidth >= 4 && levelHeight >= 4; ++it)
            {
                rtCache[it]      = RenderTexture.GetTemporary(levelWidth, levelHeight, 0, rtFormat);
                rtCache[it].name = "rtCache";

                // 注意:WithFlicker 字面意思与实际作用正好相反
                Graphics.Blit(last, rtCache[it], _material, WithFlicker ? (int)BloomHDPass.Downsample : (int)BloomHDPass.DownsampleWithFlicker);

                levelWidth  = levelWidth >> 1;
                levelHeight = levelHeight >> 1;

                last = rtCache[it];
            }

            // up sampler
            for (int i = it - 2; i >= 0; i--)
            {
                rtCache1[i]      = RenderTexture.GetTemporary(rtCache[i].width, rtCache[i].height, 0, rtFormat);
                rtCache1[i].name = "rtCache1";

                _material.SetTexture(_BloomTexId, rtCache[i]);

                Graphics.Blit(last, rtCache1[i], _material, (int)BloomHDPass.Upsample);

                last = rtCache1[i];
            }
            _material.SetTexture(_BloomTexId, filter_texture);

            // blend
            RenderTexture rt = rtCache1[0] == null ? last : rtCache1[0];

            Graphics.Blit(rt, blend_texture, _material, (int)BloomHDPass.Blend);

            //_material.
            _material.SetTexture(_BloomTexId, blend_texture);

            Graphics.Blit(src, dest, _material, (int)BloomHDPass.Final);

            RenderTexture.ReleaseTemporary(blend_texture);
            RenderTexture.ReleaseTemporary(filter_texture);

            for (int i = 0; i < 16; ++i)
            {
                if (rtCache[i] != null)
                {
                    RenderTexture.ReleaseTemporary(rtCache[i]);
                }
                if (rtCache1[i] != null)
                {
                    RenderTexture.ReleaseTemporary(rtCache1[i]);
                }
            }
        }
Esempio n. 8
0
    public override void OnInspectorGUI()
    {
        //base.OnInspectorGUI();
        PostProcessChain sv = target as PostProcessChain;
        // brightness & contrast
        //if (sv.Brightness_Contrast != null)
        {
            DrawItem(
                () =>
            {
                EditorGUILayout.LabelField("# Motion Blur");
                sv.EnableMotionBlur = EditorGUILayout.Toggle(" ", sv.EnableMotionBlur);
                return(sv.EnableMotionBlur);
            },
                () =>
            {
                EditorGUI.BeginDisabledGroup(true);
                sv.MotionBlurParamter = EditorGUILayout.Vector4Field("Mix", sv.MotionBlurParamter);
                EditorGUI.EndDisabledGroup();
            });
        }
        {
            DrawItem(
                () =>
            {
                EditorGUILayout.LabelField("# Fog");
                sv.EnableFog = EditorGUILayout.Toggle(" ", sv.EnableFog);
                return(sv.EnableFog);
            },
                () =>
            {
                sv.fog_color      = EditorGUILayout.ColorField("Fog Color", sv.fog_color);
                sv.fog_paramter.x = EditorGUILayout.FloatField("Distance Fog Begin", sv.fog_paramter.x);
                sv.fog_paramter.y = EditorGUILayout.FloatField("Distance Fog Length", sv.fog_paramter.y);
                sv.fog_paramter.z = EditorGUILayout.FloatField("Height Fog Begin", sv.fog_paramter.z);
                sv.fog_paramter.w = EditorGUILayout.FloatField("Height Fog Length", sv.fog_paramter.w);
            });
        }
        {
            DrawItem(
                () =>
            {
                EditorGUILayout.LabelField("# Depth Of Field");
                sv.EnableDepthOfField = EditorGUILayout.Toggle(" ", sv.EnableDepthOfField);
                return(sv.EnableDepthOfField);
            },
                () =>
            {
                sv.depthoffield_paramter.x = EditorGUILayout.FloatField("Distance", sv.depthoffield_paramter.x);
                sv.depthoffield_paramter.y = EditorGUILayout.FloatField("Range", sv.depthoffield_paramter.y);
                sv.depthoffield_paramter.z = EditorGUILayout.FloatField("Bokeh", sv.depthoffield_paramter.z);
            });
        }
        {
            DrawItem(
                () =>
            {
                EditorGUILayout.LabelField("# HSV");
                sv.EnableHsvAdjust = EditorGUILayout.Toggle(" ", sv.EnableHsvAdjust);
                return(sv.EnableHsvAdjust);
            },
                () =>
            {
                sv._hsv_adjust_paramters.x = EditorGUILayout.FloatField("Hue [0, 360]", sv._hsv_adjust_paramters.x);
                sv._hsv_adjust_paramters.y = EditorGUILayout.FloatField("Saturation [0, 1]", sv._hsv_adjust_paramters.y);
                sv._hsv_adjust_paramters.z = EditorGUILayout.FloatField("Value [0, 1]", sv._hsv_adjust_paramters.z);
            });
        }
        {
            DrawItem(
                () =>
            {
                EditorGUI.BeginDisabledGroup(true);
                EditorGUILayout.LabelField("# Brightness & Contrast");
                EditorGUI.EndDisabledGroup();

                return(sv.EnableHsvAdjust);
            },
                () =>
            {
                //EditorGUI.BeginDisabledGroup(true);

                sv.brightness_contrast_paramters.x = EditorGUILayout.FloatField("Brightness Factor [0, 2]", sv.brightness_contrast_paramters.x);

                //EditorGUI.EndDisabledGroup();

                sv.brightness_contrast_paramters.y = EditorGUILayout.FloatField("Contrast Factor [0, 2]", sv.brightness_contrast_paramters.y);
                sv.brightness_contrast_paramters.z = EditorGUILayout.FloatField("Average Brightness [0, 1]", sv.brightness_contrast_paramters.z);
            });
        }
        // bloom
        //if (sv.Bloom != null)
        {
            DrawItem(
                () =>
            {
                EditorGUILayout.LabelField("# BloomHD");
                EditorGUI.BeginDisabledGroup(true);
                sv.EnableBloomHD = EditorGUILayout.Toggle(" ", sv.EnableBloomHD);
                EditorGUI.EndDisabledGroup();
                return(sv.EnableBloomHD);
            },
                () =>
            {
                //sv.bloom_paramters.x = EditorGUILayout.FloatField("Brightness Threshold [0, 1]", sv.bloom_paramters.x);
                //sv.bloom_paramters.y = EditorGUILayout.FloatField("Bloom Blend Factor [0, 1]", sv.bloom_paramters.y);
            });
        }
        {
            DrawItem(
                () =>
            {
                EditorGUILayout.LabelField("# Simple Radial Blur");
                sv.EnableRadialBlur = EditorGUILayout.Toggle(" ", sv.EnableRadialBlur);
                return(sv.EnableRadialBlur);
            },
                () =>
            {
                sv.radial_blur_pos         = EditorGUILayout.Vector2Field("Pos", sv.radial_blur_pos);
                sv.radial_blur_paramters.x = EditorGUILayout.FloatField("P1", sv.radial_blur_paramters.x);
                sv.radial_blur_paramters.y = EditorGUILayout.FloatField("P2", sv.radial_blur_paramters.y);
            });
        }
        // special vision
        //if (sv.SpecialVision != null)
        {
            DrawItem(
                () =>
            {
                EditorGUILayout.LabelField("# Special Vision");
                sv.EnableSpecialVision = EditorGUILayout.Toggle(" ", sv.EnableSpecialVision);
                return(sv.EnableSpecialVision);
            },
                () =>
            {
                sv.vision_color = EditorGUILayout.ColorField("Special Vision Color (RGB)", sv.vision_color);
                sv.special_vision_paramters.x = EditorGUILayout.FloatField("Fuzzy Factor", sv.special_vision_paramters.x);
                sv.special_vision_paramters.y = EditorGUILayout.FloatField("Brightness Factor [0, 2]", sv.special_vision_paramters.y);
            });
        }
    }