示例#1
0
        private void Start()
        {
            if (computeShader == null)
            {
                throw new System.InvalidOperationException("Compute shader not set!");
            }
            if (_instance != null)
            {
                throw new System.InvalidOperationException("AtmosphereScatteringLutManager already exists!");
            }
            _instance = this;
            AtmLutHelper.Init(computeShader);
            CameraVolumeHelper.Init(computeShader);
            for (int i = 0; i < pingPongUpdaters.Length; i++)
            {
                pingPongUpdaters[i]      = new ProgressiveLutUpdater(null, lutConfig, this);
                pingPongUpdaters[i].name = "Updater " + i;
            }

            //Quickly complete two set luts.
            for (int i = 1; i <= 2; i++)
            {
                pingPongUpdaters[i].atmConfigToUse = atmosphereConfig;
                var t = pingPongUpdaters[i].UpdateCoroutine();
                while (t.MoveNext())
                {
                    ;
                }
            }
            UpdateSkyboxMaterial(pingPongUpdaters[1], pingPongUpdaters[2]);

            KickOffUpdater(pingPongUpdaters[0]);
        }
示例#2
0
        //Generate camera volume texture.
        private void OnPreRender()
        {
            if (RenderSettings.sun == null)
            {
                return;
            }
            // get four corners of camera frustom in world space
            // bottom left
            _FrustumCorners[0] = camera.ViewportToWorldPoint(new Vector3(0, 0, camera.farClipPlane));
            // bottom right
            _FrustumCorners[1] = camera.ViewportToWorldPoint(new Vector3(1, 0, camera.farClipPlane));
            // top left
            _FrustumCorners[2] = camera.ViewportToWorldPoint(new Vector3(0, 1, camera.farClipPlane));
            // top right
            _FrustumCorners[3] = camera.ViewportToWorldPoint(new Vector3(1, 1, camera.farClipPlane));

            //Render camera volume texture.
            var projection_matrix = GL.GetGPUProjectionMatrix(camera.projectionMatrix, false);

            CameraVolumeHelper.CreateCameraAlignedVolumeTexture(ref transmittanceVolume, ref scatteringVolume, volumeTexSize);
            CameraVolumeHelper.UpdateCameraVolume(
                transmittanceVolume,
                scatteringVolume,
                volumeTexSize,
                transform.position,
                -RenderSettings.sun.transform.forward,
                _FrustumCorners,
                new Vector2(camera.nearClipPlane, camera.farClipPlane)
                );

            //Set it.
            Shader.SetGlobalTexture("_CameraVolumeTransmittance", transmittanceVolume);
            Shader.SetGlobalTexture("_CameraVolumeScattering", scatteringVolume);
            var vp_matrix = projection_matrix * camera.worldToCameraMatrix;

            Shader.SetGlobalMatrix("_Camera_VP", vp_matrix);
        }