Пример #1
0
    void Initialize()
    {
        CreateMaterial();
        GameObject FogVolumeDataGO = GameObject.Find("Fog Volume Data");

        if (FogVolumeDataGO)
        {
            _FogVolumeData = FogVolumeDataGO.GetComponent <FogVolumeData>();
        }
        else
        {
            return;
        }

        _GameCamera = _FogVolumeData.GameCamera;

        GOShadowCamera = GameObject.Find("FogVolumeShadowCamera");
        if (!GOShadowCamera)
        {
            GOShadowCamera      = new GameObject();
            GOShadowCamera.name = "FogVolumeShadowCamera";
        }

        if (!GOShadowCamera)
        {
            print("Shadow camera is lost");
        }
        else
        {
            ShadowCamera = GOShadowCamera.GetComponent <Camera>();
        }

        if (!depthRT)
        {
            depthRT = new RenderTexture((int)Size, (int)Size, 16, RenderTextureFormat.RGFloat);
            depthRT.antiAliasing = (int)_Antialiasing;
            depthRT.filterMode   = FilterMode.Bilinear;
            depthRT.name         = "FogVolumeShadowMap";
            depthRT.wrapMode     = TextureWrapMode.Clamp;
        }

        if (!ShadowCamera)
        {
            ShadowCamera = GOShadowCamera.AddComponent <Camera>();
        }
        else
        {
            ShadowCamera = GOShadowCamera.GetComponent <Camera>();
        }

        ShadowCamera.clearFlags      = CameraClearFlags.Color;
        ShadowCamera.backgroundColor = Color.black;
        ShadowCamera.orthographic    = true;
        ShadowCamera.farClipPlane    = 10000.0f;
        ShadowCamera.enabled         = false;
        ShadowCamera.stereoTargetEye = StereoTargetEyeMask.None;
        ShadowCamera.targetTexture   = depthRT;
        ShadowCamera.cullingMask    &= ~(1 << LayerMask.NameToLayer("FogVolume"));
        ShadowCamera.cullingMask    &= ~(1 << LayerMask.NameToLayer("FogVolumeUniform"));
        ShadowCamera.cullingMask    &= ~(1 << LayerMask.NameToLayer("FogVolumeSurrogate"));
        ShadowCamera.cullingMask    &= ~(1 << LayerMask.NameToLayer("FogVolumeShadowCaster"));

        //make it child
        ShadowCamera.transform.parent = gameObject.transform;

        Quad = GameObject.Find("Depth map background");
        if (!Quad)
        {
            Quad = GameObject.CreatePrimitive(PrimitiveType.Quad);
        }
        Quad.name = "Depth map background";
        Quad.GetComponent <MeshRenderer>().sharedMaterial = QuadMaterial;
        Quad.transform.parent = ShadowCamera.transform;

        //remnove the collider
        DestroyImmediate(Quad.GetComponent <MeshCollider>());
        Quad.hideFlags = HideFlags.HideInHierarchy;
    }
Пример #2
0
 void OnEnable()
 {
     _target = (FogVolumeData)target;
 }
Пример #3
0
 // Use this for initialization
 void OnEnable()
 {
     thisFog        = GetComponent <FogVolume>();
     _FogVolumeData = thisFog._FogVolumeData;
 }
Пример #4
0
    void OnEnable()
    {
        nullTex = MakeTex(Color.black);
        if (SystemInfo.SupportsRenderTextureFormat(rt_DepthFormat))
        {
            rt_DepthFormat = RenderTextureFormat.RHalf;//not of the liking of small machines
        }
        else
        {
            rt_DepthFormat = RenderTextureFormat.Default;
        }

        // SceneCamera = Camera.main;
        _FogVolumeDataGO = GameObject.Find("Fog Volume Data");
        if (_FogVolumeDataGO)
        {
            _FogVolumeData = _FogVolumeDataGO.GetComponent <FogVolumeData>();
        }


        if (_FogVolumeData)
        {
            SceneCamera = _FogVolumeData.GetFogVolumeCamera;
        }

        if (SceneCamera == null)
        {
            Debug.Log("FogVolumeCamera.cs can't get a valid camera from 'Fog Volume Data'\n Assigning Camera.main");
            SceneCamera = Camera.main;
        }

        ShaderLoad();
        SetUpsampleMode(_upsampleMode);
        ShowBilateralEdge(_showBilateralEdge);
        _FogVolumeRenderer = SceneCamera.GetComponent <FogVolumeRenderer>();

        if (SceneCamera.gameObject.GetComponent <FogVolumeRenderer>() == null)
        {
            //    Combiner = SceneCamera.gameObject.GetComponent<FogVolumeRenderer>();
            //else
            SceneCamera.gameObject.AddComponent <FogVolumeRenderer>();
        }

        ThisCamera = GetComponent <Camera>();
        //ThisCamera.depthTextureMode = DepthTextureMode.Depth;
        ThisCamera.enabled = false;

        ThisCamera.clearFlags      = CameraClearFlags.SolidColor;
        ThisCamera.backgroundColor = new Color(0, 0, 0, 0);
        ThisCamera.farClipPlane    = SceneCamera.farClipPlane;

        _CameraRender = GetComponent <SPSRRT_helper>();

        if (_CameraRender == null)
        {
            _CameraRender = gameObject.AddComponent <SPSRRT_helper>();
        }

        _CameraRender.SceneCamera     = SceneCamera;
        _CameraRender.SecondaryCamera = ThisCamera;
    }
Пример #5
0
    void OnEnable()
    {
        nullTex = MakeTex(Color.black);
        if (SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.RFloat))
        {
            rt_DepthFormat = RenderTextureFormat.RFloat;
        }
        else
        {
            rt_DepthFormat = RenderTextureFormat.DefaultHDR;
        }

        // SceneCamera = Camera.main;
        _FogVolumeDataGO = GameObject.Find("Fog Volume Data");
        if (_FogVolumeDataGO)
        {
            _FogVolumeData = _FogVolumeDataGO.GetComponent <FogVolumeData>();
        }


        if (_FogVolumeData)
        {
            SceneCamera = _FogVolumeData.GetFogVolumeCamera;
        }

        if (SceneCamera == null)
        {
            Debug.Log("FogVolumeCamera.cs can't get a valid camera from 'Fog Volume Data'\n Assigning Camera.main");
            SceneCamera = Camera.main;
        }

        ShaderLoad();
        SetUpsampleMode(_upsampleMode);
        ShowBilateralEdge(_showBilateralEdge);
        _FogVolumeRenderer = SceneCamera.GetComponent <FogVolumeRenderer>();

        if (_FogVolumeRenderer == null)
        {
            //    Combiner = SceneCamera.gameObject.GetComponent<FogVolumeRenderer>();
            //else
            if (!_FogVolumeData.ForceNoRenderer)
            {
                var renderer = SceneCamera.gameObject.AddComponent <FogVolumeRenderer>();
                renderer.enabled = true;
            }
        }


        ThisCamera         = GetComponent <Camera>();
        ThisCamera.enabled = false;

        ThisCamera.clearFlags      = CameraClearFlags.SolidColor;
        ThisCamera.backgroundColor = new Color(0, 0, 0, 0);
        ThisCamera.farClipPlane    = SceneCamera.farClipPlane;

        _CameraRender = GetComponent <FogVolumeRenderManager>();

        if (_CameraRender == null)
        {
            _CameraRender = gameObject.AddComponent <FogVolumeRenderManager>();
        }

        _CameraRender.SceneCamera     = SceneCamera;
        _CameraRender.SecondaryCamera = ThisCamera;
    }