Esempio n. 1
0
    private void UpdateCameraModes()
    {
        if (!shadowCamera)
        {
            return;
        }
        Bounds bb = GetBoundingBoxofSelectedObjects();
        //Debug.Log (bb);
        float maxlength = bb.extents.magnitude;

        //maxlength = Mathf.Max (Mathf.Max (bb.extents.x, bb.extents.y), bb.extents.z);
        if (maxlength == 0)
        {
            return;
        }
        float   distance = maxlength + 150;
        Vector3 center   = bb.center;

        shadowCamera.orthographic = IsOrthographic;
        if (IsOrthographic)
        {
            shadowCamera.orthographicSize = maxlength;
        }
        else
        {
            shadowCamera.fieldOfView = 50;
        }
        shadowCamera.transform.position = center - transform.forward * distance;
        shadowCamera.transform.rotation = transform.rotation;
        //transform.position=center - shadowCamera.transform.forward * distance;
        shadowCamera.farClipPlane  = distance + maxlength;
        shadowCamera.nearClipPlane = 150;
        shadowCamera.targetTexture = shadowMap;
        _fx = shadowCamera.GetComponent(typeof(blurImageEffect)) as blurImageEffect;
        if (SystemInfo.supportsImageEffects && UseBlurShadowMap)
        {
            if (!_fx)
            {
                _fx = shadowCamera.gameObject.AddComponent(typeof(blurImageEffect)) as blurImageEffect;
                _fx.BlurIterations = BlurIterations;
                _fx.BlurSpreadSize = BlurSpreadSize;
            }
            else
            {
                _fx.enabled = true;
            }
        }
        else
        {
            if (_fx)
            {
                _fx.enabled = false;
            }
        }
    }
Esempio n. 2
0
    public void UpdateCamera(Vector3 lookat, float distance, Vector3 target, float size, float depth)
    {
        if (!shadowCamera)
        {
            return;
        }
        Vector3 center = target;

        shadowCamera.orthographic       = true;
        shadowCamera.orthographicSize   = size;
        shadowCamera.transform.position = center - lookat * distance;
        shadowCamera.transform.rotation = Quaternion.LookRotation(lookat);
        shadowCamera.farClipPlane       = distance + depth;
        shadowCamera.nearClipPlane      = distance - depth;
        shadowCamera.targetTexture      = shadowMap;
        _fx = shadowCamera.GetComponent(typeof(blurImageEffect)) as blurImageEffect;
        if (SystemInfo.supportsImageEffects && UseBlurShadowMap)
        {
            if (!_fx)
            {
                _fx = shadowCamera.gameObject.AddComponent(typeof(blurImageEffect)) as blurImageEffect;
                _fx.BlurIterations = BlurIterations;
                _fx.BlurSpreadSize = BlurSpreadSize;
            }
            else
            {
                _fx.enabled = true;
            }
        }
        else
        {
            if (_fx)
            {
                _fx.enabled = false;
            }
        }
    }
Esempio n. 3
0
    public void InitializeRenderer()
    {
        if (!shadowMap)
        {
            shadowMap              = RenderTexture.GetTemporary(m_TextureSize, m_TextureSize, 16);
            shadowMap.name         = "__ShadowMap";
            shadowMap.isPowerOfTwo = true;
            shadowMap.hideFlags    = HideFlags.DontSave;

            if (SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGB32))
            {
                shadowMap.format = RenderTextureFormat.ARGB32;
            }
            shadowMap.filterMode = FilterMode.Bilinear;
            //shadowMap.useMipMap = true;
        }

        if (!shadowCamera)
        {
            GameObject go = new GameObject("__ShadowMap Camera", typeof(Camera));
            shadowCamera         = go.GetComponent <Camera> ();
            shadowCamera.enabled = false;
            shadowCamera.gameObject.AddComponent <FlareLayer> ();
            shadowCamera.cullingMask     = ~(1 << 4) & m_ShadowLayers.value;
            shadowCamera.clearFlags      = CameraClearFlags.SolidColor;
            shadowCamera.backgroundColor = Color.white;
            shadowCamera.targetTexture   = shadowMap;
            if (SystemInfo.supportsImageEffects && UseBlurShadowMap)
            {
                _fx = shadowCamera.gameObject.AddComponent(typeof(blurImageEffect)) as blurImageEffect;
                _fx.BlurIterations = BlurIterations;
                _fx.BlurSpreadSize = BlurSpreadSize;
            }
            go.hideFlags = HideFlags.HideAndDontSave;
        }
    }
Esempio n. 4
0
    private void InitializeCamera()
    {
        Light l = GetComponent <Light> ();

        if (!l)
        {
            return;
        }
        if (l.type != LightType.Directional)
        {
            return;
        }

        oldrotation = transform.rotation;

        if (!shadowMap)
        {
            shadowMap              = RenderTexture.GetTemporary(m_TextureSize, m_TextureSize, 16);
            shadowMap.name         = "__ShadowMap" + GetInstanceID();
            shadowMap.isPowerOfTwo = true;
            shadowMap.hideFlags    = HideFlags.DontSave;

            if (SystemInfo.SupportsRenderTextureFormat(RenderTextureFormat.ARGB32))
            {
                shadowMap.format = RenderTextureFormat.ARGB32;
            }
            shadowMap.filterMode = FilterMode.Bilinear;
            //shadowMap.useMipMap = true;
        }



        if (!shadowCamera)
        {
            GameObject go = new GameObject("ShadowMap Camera id" + GetInstanceID() + " for " + l.GetInstanceID(), typeof(Camera));
            shadowCamera                    = go.GetComponent <Camera>();
            shadowCamera.enabled            = false;
            shadowCamera.transform.position = transform.position;
            shadowCamera.transform.rotation = transform.rotation;
            shadowCamera.gameObject.AddComponent <FlareLayer>();

            shadowCamera.clearFlags      = CameraClearFlags.SolidColor;
            shadowCamera.backgroundColor = Color.white;
            shadowCamera.targetTexture   = shadowMap;
            if (SystemInfo.supportsImageEffects && UseBlurShadowMap)
            {
                _fx = shadowCamera.gameObject.AddComponent(typeof(blurImageEffect)) as blurImageEffect;
                _fx.BlurIterations = BlurIterations;
                _fx.BlurSpreadSize = BlurSpreadSize;
            }
            go.hideFlags = HideFlags.HideAndDontSave;
        }

        UpdateCameraModes();
        RenderShadow();
        MeshRenderer[] renderers = FindObjectsOfType(typeof(MeshRenderer)) as MeshRenderer[];
        for (int i = 0; i < renderers.Length; ++i)
        {
            if (m_ShadowLayers == (m_ShadowLayers | 1 << renderers[i].gameObject.layer))
            {
                Material[] materials = renderers[i].sharedMaterials;
                foreach (Material mat in materials)
                {
                    if (mat.HasProperty("_ShadowMap"))
                    {
                        //Debug.Log(mrenderer.ReflectionTexture);
                        mat.SetTexture("_ShadowMap", shadowMap);
                    }
                    Matrix4x4 shadowMatrix = shadowCamera.projectionMatrix;

                    if (SystemInfo.usesReversedZBuffer)
                    {
                        shadowMatrix [2, 0] = -shadowMatrix [2, 0];
                        shadowMatrix [2, 1] = -shadowMatrix [2, 1];
                        shadowMatrix [2, 2] = -shadowMatrix [2, 2];
                        shadowMatrix [2, 3] = -shadowMatrix [2, 3];
                    }
                    shadowMatrix *= shadowCamera.worldToCameraMatrix;
                    mat.SetMatrix("_shadowMatrix", shadowMatrix);
                }
            }
        }
    }