Esempio n. 1
0
    private void init()
    {
        if (cam == null)
        {
            cam = GetComponent <Camera> ();
        }

        if (fog == null)
        {
            fog = GetComponent <UnderWaterFog> ();
        }

        if (cam.transform.position.y >= fog.height)
        {
            fog.fogColor.a = 0f;
        }
    }
Esempio n. 2
0
    private void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (!this.CheckResources())
        {
            Graphics.Blit(source, destination);
            return;
        }
        Camera    component     = base.GetComponent <Camera>();
        Transform transform     = component.transform;
        float     nearClipPlane = component.nearClipPlane;
        float     farClipPlane  = component.farClipPlane;
        float     fieldOfView   = component.fieldOfView;
        float     aspect        = component.aspect;
        Matrix4x4 identity      = Matrix4x4.identity;
        float     num           = fieldOfView * 0.5f;
        Vector3   b             = transform.right * nearClipPlane * Mathf.Tan(num * 0.017453292f) * aspect;
        Vector3   b2            = transform.up * nearClipPlane * Mathf.Tan(num * 0.017453292f);
        Vector3   vector        = transform.forward * nearClipPlane - b + b2;
        float     d             = vector.magnitude * farClipPlane / nearClipPlane;

        vector.Normalize();
        vector *= d;
        Vector3 vector2 = transform.forward * nearClipPlane + b + b2;

        vector2.Normalize();
        vector2 *= d;
        Vector3 vector3 = transform.forward * nearClipPlane + b - b2;

        vector3.Normalize();
        vector3 *= d;
        Vector3 vector4 = transform.forward * nearClipPlane - b - b2;

        vector4.Normalize();
        vector4 *= d;
        identity.SetRow(0, vector);
        identity.SetRow(1, vector2);
        identity.SetRow(2, vector3);
        identity.SetRow(3, vector4);
        Vector3 position = transform.position;
        float   num2     = position.y - this.height;
        float   z        = (num2 <= 0f) ? 1f : 0f;

        this.fogMaterial.SetColor("_Color", this.fogColor);
        this.fogMaterial.SetMatrix("_FrustumCornersWS", identity);
        this.fogMaterial.SetVector("_CameraWS", position);
        this.fogMaterial.SetVector("_HeightParams", new Vector4(this.height, num2, z, this.heightDensity * 0.5f));
        this.fogMaterial.SetVector("_DistanceParams", new Vector4(-Mathf.Max(this.startDistance, 0f), 1f, 0f, 0f));
        FogMode fogMode          = RenderSettings.fogMode;
        float   num3             = this.heightDensity;
        float   fogStartDistance = RenderSettings.fogStartDistance;
        float   fogEndDistance   = RenderSettings.fogEndDistance;
        bool    flag             = fogMode == FogMode.Linear;
        float   num4             = flag ? (fogEndDistance - fogStartDistance) : 0f;
        float   num5             = (Mathf.Abs(num4) > 0.0001f) ? (1f / num4) : 0f;
        Vector4 value;

        value.x = num3 * 1.2011224f;
        value.y = num3 * 1.442695f;
        value.z = (flag ? (-num5) : 0f);
        value.w = (flag ? (fogEndDistance * num5) : 0f);
        this.fogMaterial.SetVector("_SceneFogParams", value);
        this.fogMaterial.SetVector("_SceneFogMode", new Vector4((float)fogMode, 0f, 0f, 0f));
        UnderWaterFog.CustomGraphicsBlit(source, destination, this.fogMaterial, 0);
    }