コード例 #1
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="renderer"></param>
    /// <param name="viewProj"></param>
    private void VolumetricLightRenderer_PreRenderEvent(EnviroSkyRendering renderer, Matrix4x4 viewProj, Matrix4x4 viewProjSP)
    {
        if (EnviroSky.instance == null)
        {
            return;
        }

        // light was destroyed without deregistring, deregister now
        if (_light == null || _light.gameObject == null)
        {
            EnviroSkyRendering.PreRenderEvent -= VolumetricLightRenderer_PreRenderEvent;
            return;
        }

        if (!_light.gameObject.activeInHierarchy || _light.enabled == false)
        {
            return;
        }

        if (_material == null)
        {
            _material = new Material(volumeLightShader);
        }

        _material.SetVector("_CameraForward", Camera.current.transform.forward);
        _material.SetInt("_SampleCount", SampleCount);
        _material.SetVector("_NoiseVelocity", new Vector4(EnviroSky.instance.volumeLightSettings.noiseVelocity.x, EnviroSky.instance.volumeLightSettings.noiseVelocity.y) * EnviroSky.instance.volumeLightSettings.noiseScale);
        _material.SetVector("_NoiseData", new Vector4(EnviroSky.instance.volumeLightSettings.noiseScale, EnviroSky.instance.volumeLightSettings.noiseIntensity, EnviroSky.instance.volumeLightSettings.noiseIntensityOffset));
        _material.SetVector("_MieG", new Vector4(1 - (Anistropy * Anistropy), 1 + (Anistropy * Anistropy), 2 * Anistropy, 1.0f / (4.0f * Mathf.PI)));
        float scatter = ScatteringCoef;

        if (scaleWithTime)
        {
            scatter = ScatteringCoef * (1 - EnviroSky.instance.GameTime.solarTime);
        }
        _material.SetVector("_VolumetricLight", new Vector4(scatter, ExtinctionCoef, _light.range, 1.0f));// - SkyboxExtinctionCoef));
        _material.SetTexture("_CameraDepthTexture", renderer.GetVolumeLightDepthBuffer());
        _material.SetFloat("_ZTest", (int)UnityEngine.Rendering.CompareFunction.Always);

        if (_light.type == LightType.Point)
        {
            SetupPointLight(renderer, viewProj, viewProjSP);
        }
        else if (_light.type == LightType.Spot)
        {
            SetupSpotLight(renderer, viewProj, viewProjSP);
        }
    }
コード例 #2
0
    private void VolumetricLightRenderer_PreRenderEvent(
        EnviroSkyRendering renderer,
        Matrix4x4 viewProj,
        Matrix4x4 viewProjSP)
    {
        if (Object.op_Equality((Object)EnviroSky.instance, (Object)null))
        {
            return;
        }
        if (Object.op_Equality((Object)this._light, (Object)null) || Object.op_Equality((Object)((Component)this._light).get_gameObject(), (Object)null))
        {
            EnviroSkyRendering.PreRenderEvent -= new Action <EnviroSkyRendering, Matrix4x4, Matrix4x4>(this.VolumetricLightRenderer_PreRenderEvent);
        }
        if (!((Component)this._light).get_gameObject().get_activeInHierarchy() || !((Behaviour)this._light).get_enabled())
        {
            return;
        }
        this._material.SetVector("_CameraForward", Vector4.op_Implicit(((Component)Camera.get_current()).get_transform().get_forward()));
        this._material.SetInt("_SampleCount", this.SampleCount);
        this._material.SetVector("_NoiseVelocity", Vector4.op_Multiply(new Vector4((float)EnviroSky.instance.volumeLightSettings.noiseVelocity.x, (float)EnviroSky.instance.volumeLightSettings.noiseVelocity.y), EnviroSky.instance.volumeLightSettings.noiseScale));
        this._material.SetVector("_NoiseData", new Vector4(EnviroSky.instance.volumeLightSettings.noiseScale, EnviroSky.instance.volumeLightSettings.noiseIntensity, EnviroSky.instance.volumeLightSettings.noiseIntensityOffset));
        this._material.SetVector("_MieG", new Vector4((float)(1.0 - (double)this.Anistropy * (double)this.Anistropy), (float)(1.0 + (double)this.Anistropy * (double)this.Anistropy), 2f * this.Anistropy, 0.07957747f));
        float num = this.ScatteringCoef;

        if (this.scaleWithTime)
        {
            num = this.ScatteringCoef * (1f - EnviroSky.instance.GameTime.solarTime);
        }
        this._material.SetVector("_VolumetricLight", new Vector4(num, this.ExtinctionCoef, this._light.get_range(), 1f));
        this._material.SetTexture("_CameraDepthTexture", (Texture)renderer.GetVolumeLightDepthBuffer());
        this._material.SetFloat("_ZTest", 8f);
        if (this._light.get_type() == 2)
        {
            this.SetupPointLight(renderer, viewProj, viewProjSP);
        }
        else
        {
            if (this._light.get_type() != null)
            {
                return;
            }
            this.SetupSpotLight(renderer, viewProj, viewProjSP);
        }
    }