Пример #1
0
    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (!EffectMaterial)
        {
            Graphics.Blit(source, destination); // do nothing
            return;
        }
        //if (!RenderMaterial)
        //{
        //    Graphics.Blit(source, destination); // do nothing
        //    return;
        //}

        // pass frustum rays to shader
        EffectMaterial.SetMatrix("_FrustumCornersES", GetFrustumCorners(CurrentCamera));
        EffectMaterial.SetMatrix("_CameraInvViewMatrix", CurrentCamera.cameraToWorldMatrix);
        EffectMaterial.SetVector("_cameraWS", CurrentCamera.transform.position);
        EffectMaterial.SetTexture("_cloudNoise3D", CloudTex3D);
        EffectMaterial.SetFloat("_cutoff", CutOff);
        EffectMaterial.SetFloat("_cloudScale", CloudScale);
        EffectMaterial.SetTexture("_heightTex", HeightTex);
        EffectMaterial.SetFloat("_cloudBase", CloudBase);
        EffectMaterial.SetFloat("_layerHeight", LayerHeight);
        EffectMaterial.SetTexture("_randomNoiseTex", BlueNoise);
        //EffectMaterial.SetVector("_lightDir", SkyLight.transform.forward);
        EffectMaterial.SetTexture("_detailTex", DetailTex);
        EffectMaterial.SetFloat("_edgeScale", EdgeScale);
        EffectMaterial.SetFloat("_erodeDepth", ErodeDepth);
        EffectMaterial.SetFloat("_coverage", Coverage);
        EffectMaterial.SetFloat("_BeerLaw", BeerLaw);
        EffectMaterial.SetFloat("_SilverIntensity", SilverIntensity);
        EffectMaterial.SetFloat("_SilverSpread", SilverSpread);
        EffectMaterial.SetTexture("_CurlNoise", CurlNoise);
        EffectMaterial.SetFloat("_CurlTile", CurlTile);
        EffectMaterial.SetFloat("_CurlStrength", CurlStrength);
        EffectMaterial.SetFloat("_CloudTopOffset", TopOffset);
        EffectMaterial.SetFloat("_MaxDistance", MaxDistance);

        EffectMaterial.SetTexture("_WeatherTex", WeatherTex);
        EffectMaterial.SetFloat("_WeatherTexSize", WeatherTexSize);
        EffectMaterial.SetFloat("_nearestRenderDistance", nearestRenderDistance);
        Matrix4x4 projectionMatrix = GL.GetGPUProjectionMatrix(_CurrentCamera.projectionMatrix, false);

        projectionMatrix = GL.GetGPUProjectionMatrix(_ShadowCamera.projectionMatrix, false);
        EffectMaterial.SetMatrix("_inverseVP", Matrix4x4.Inverse(projectionMatrix * _CurrentCamera.worldToCameraMatrix));
        EffectMaterial.SetMatrix("_WorldToShadow", projectionMatrix * _ShadowCamera.worldToCameraMatrix);
        EffectMaterial.SetFloat("_WindSpeed", WindSpeed);
        EffectMaterial.SetFloat("_cloudDensity", CloudDensity);


        CustomGraphicsBlit(null, cloud, EffectMaterial, 0);
        RenderMaterial.SetTexture("cloudTexture", cloud);
        Graphics.Blit(source, destination, RenderMaterial);
    }
Пример #2
0
    void RecreateViewTexture(int width, int height)
    {
        RenderTextureReadWrite textureReadWrite =
            RenderTextureReadWrite.Default;

        if (GTRenderTextureFormat == ColorSpace.Gamma)
        {
            textureReadWrite = RenderTextureReadWrite.sRGB;
        }
        else if (GTRenderTextureFormat == ColorSpace.Linear)
        {
            textureReadWrite = RenderTextureReadWrite.Linear;
        }

        var rt = new RenderTexture(
            width, height, 0,
            RenderTextureFormat.ARGB32,
            textureReadWrite);

        rt.name = "CoherentRenderingRTT" + View.GetId();
        rt.Create();

                #if !UNITY_EDITOR_WIN && !UNITY_STANDALONE_WIN
        RenderTexture current = RenderTexture.active;
        RenderTexture.active = rt;
        GL.Clear(true, true, Color.clear);
        RenderTexture.active = current;
                #endif
        ViewTexture = rt;

        var dt = new RenderTexture(
            width, height, 24,
            RenderTextureFormat.Depth,
            textureReadWrite);
        dt.name = "CoherentRenderingRTD" + View.GetId();
        dt.Create();
        DepthTexture = dt;

        if (RenderMaterial != null)
        {
            RenderMaterial.SetTexture("_MainTex", ViewTexture);
        }
    }