Example #1
0
    /// <summary>
    ///
    /// </summary>
    void Awake()
    {
        _camera = GetComponent <Camera>();
        if (_camera.actualRenderingPath == RenderingPath.Forward)
        {
            _camera.depthTextureMode = DepthTextureMode.Depth;
        }

        _currentResolution = Resolution;

        Shader shader = Shader.Find("Hidden/BlitAdd");

        if (shader == null)
        {
            throw new Exception("Critical Error: \"Hidden/BlitAdd\" shader is missing. Make sure it is included in \"Always Included Shaders\" in ProjectSettings/Graphics.");
        }
        _blitAddMaterial = new Material(shader);

        shader = Shader.Find("Hidden/BilateralBlur");
        if (shader == null)
        {
            throw new Exception("Critical Error: \"Hidden/BilateralBlur\" shader is missing. Make sure it is included in \"Always Included Shaders\" in ProjectSettings/Graphics.");
        }
        _bilateralBlurMaterial = new Material(shader);

        _preLightPass      = new CommandBuffer();
        _preLightPass.name = "PreLight";

        ChangeResolution();

        if (_pointLightMesh == null)
        {
            GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            _pointLightMesh = go.GetComponent <MeshFilter>().sharedMesh;
            Destroy(go);
        }

        if (_spotLightMesh == null)
        {
            _spotLightMesh = CreateSpotLightMesh();
        }

        if (_lightMaterial == null)
        {
            shader = Shader.Find("Sandbox/VolumetricLight");
            if (shader == null)
            {
                throw new Exception("Critical Error: \"Sandbox/VolumetricLight\" shader is missing. Make sure it is included in \"Always Included Shaders\" in ProjectSettings/Graphics.");
            }
            _lightMaterial = new Material(shader);
        }

        if (_defaultSpotCookie == null)
        {
            _defaultSpotCookie = DefaultSpotCookie;
        }

        LoadNoise3dTexture();
        GenerateDitherTexture();
    }
Example #2
0
 void Update()
 {
     if (Resolution != curResolution)
     {
         ChangeResolution();
         curResolution = Resolution;
     }
     _defaultSpotCookie = DefaultSpotCookie;
 }
Example #3
0
    /// <summary>
    ///
    /// </summary>
    void Awake()
    {
        //Application.targetFrameRate = 1000;
        _camera = GetComponent <Camera>();

        _currentResolution = Resolution;

        _blitAddMaterial       = new Material(Shader.Find("Hidden/BlitAdd"));
        _bilateralBlurMaterial = new Material(Shader.Find("Hidden/BilateralBlur"));

        _preLightPass      = new CommandBuffer();
        _preLightPass.name = "PreLight";

        _postLightPass      = new CommandBuffer();
        _postLightPass.name = "PostLight";

        _preFinalPass      = new CommandBuffer();
        _preFinalPass.name = "PreFinal";

        ChangeResolution();

        if (_pointLightMesh == null)
        {
            GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            _pointLightMesh = go.GetComponent <MeshFilter>().sharedMesh;
            Destroy(go);
        }

        if (_spotLightMesh == null)
        {
            _spotLightMesh = CreateSpotLightMesh();
        }

        if (_dirLightMesh == null)
        {
            _dirLightMesh = CreateDirLightMesh();
        }

        if (_lightMaterial == null)
        {
            _lightMaterial = new Material(Shader.Find("Sandbox/VolumetricLight"));
        }

        if (_defaultSpotCookie == null)
        {
            _defaultSpotCookie = DefaultSpotCookie;
        }

        LoadNoise3dTexture();
        GenerateDitherTexture();
    }
Example #4
0
    /// <summary>
    ///
    /// </summary>
    void Update()
    {
        //#if UNITY_EDITOR
        if (_currentResolution != Resolution)
        {
            _currentResolution = Resolution;
            ChangeResolution();
        }

        if ((_volumeLightTexture.width != _camera.pixelWidth || _volumeLightTexture.height != _camera.pixelHeight))
        {
            ChangeResolution();
        }
        //#endif
    }
    /// <summary>
    ///
    /// </summary>
    void Update()
    {
        Shader.SetGlobalTexture("_DitherTexture", _ditheringTexture);
        Shader.SetGlobalTexture("_NoiseTexture", _noiseTexture);

        //#if UNITY_EDITOR
        if (_currentResolution != Resolution)
        {
            _currentResolution = Resolution;
            ChangeResolution();
        }

        if ((_volumeLightTexture.width != _camera.pixelWidth || _volumeLightTexture.height != _camera.pixelHeight))
        {
            ChangeResolution();
        }
        //#endif
    }
    /// <summary>
    ///
    /// </summary>
    void Awake()
    {
        if (!inited)
        {
            InitVariable();
            inited = true;
        }
        _currentResolution = resolution;
        _camera            = GetComponent <Camera>();
        if (_camera.actualRenderingPath == RenderingPath.Forward)
        {
            _camera.depthTextureMode = DepthTextureMode.Depth;
        }

        Shader shader = Shader.Find("Hidden/BlitAdd");

        if (shader == null)
        {
            throw new Exception("Critical Error: \"Hidden/BlitAdd\" shader is missing. Make sure it is included in \"Always Included Shaders\" in ProjectSettings/Graphics.");
        }
        _blitAddMaterial = new Material(shader);

        shader = Shader.Find("Hidden/BilateralBlur");
        if (shader == null)
        {
            throw new Exception("Critical Error: \"Hidden/BilateralBlur\" shader is missing. Make sure it is included in \"Always Included Shaders\" in ProjectSettings/Graphics.");
        }
        _bilateralBlurMaterial = new Material(shader);

        _preLightPass      = new CommandBuffer();
        _preLightPass.name = "PreLight";

        ChangeResolution();
        volumeLightTexture = GetVolumeLightBuffer();
        volumeDepthTexture = GetVolumeLightDepthBuffer();
        if (_pointLightMesh == null)
        {
            GameObject go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            _pointLightMesh = go.GetComponent <MeshFilter>().sharedMesh;
            Destroy(go);
        }

        if (_spotLightMesh == null)
        {
            _spotLightMesh = CreateSpotLightMesh();
        }

        if (_lightMaterial == null)
        {
            shader = Shader.Find("Sandbox/VolumetricLight");
            if (shader == null)
            {
                throw new Exception("Critical Error: \"Sandbox/VolumetricLight\" shader is missing. Make sure it is included in \"Always Included Shaders\" in ProjectSettings/Graphics.");
            }
            _lightMaterial = new Material(shader);
        }

        if (_defaultSpotCookie == null)
        {
            _defaultSpotCookie = DefaultSpotCookie;
        }

        LoadNoise3dTexture();
        GenerateDitherTexture();
        bool dx11 = SystemInfo.graphicsShaderLevel > 40;

        halfPass     = dx11 ? 4 : 10;
        fullPass     = dx11 ? 6 : 11;
        screenWidth  = _camera.pixelWidth;
        screenHeight = _camera.pixelHeight;
        if (_currentResolution == VolumtericResolution.Half)
        {
            onPreRenderAction = () => {
                Texture nullTexture = null;
                // down sample depth to half res
                _preLightPass.Blit(nullTexture, _halfDepthBuffer, _bilateralBlurMaterial, halfPass);

                _preLightPass.SetRenderTarget(_halfVolumeLightTexture);
            };
            onRenderImageAction = () => {
                RenderTexture temp = RenderTexture.GetTemporary(_halfVolumeLightTexture.width, _halfVolumeLightTexture.height, 0, RenderTextureFormat.ARGBFloat);
                temp.filterMode = FilterMode.Bilinear;

                // horizontal bilateral blur at half res
                Graphics.Blit(_halfVolumeLightTexture, temp, _bilateralBlurMaterial, 2);

                // vertical bilateral blur at half res
                Graphics.Blit(temp, _halfVolumeLightTexture, _bilateralBlurMaterial, 3);

                // upscale to full res
                Graphics.Blit(_halfVolumeLightTexture, _volumeLightTexture, _bilateralBlurMaterial, 5);
                RenderTexture.ReleaseTemporary(temp);
            };
        }
        else
        {
            onPreRenderAction   = () => _preLightPass.SetRenderTarget(_volumeLightTexture);
            onRenderImageAction = () => {
                RenderTexture temp = RenderTexture.GetTemporary(_volumeLightTexture.width, _volumeLightTexture.height, 0, RenderTextureFormat.ARGBFloat);
                temp.filterMode = FilterMode.Bilinear;

                // horizontal bilateral blur at full res
                Graphics.Blit(_volumeLightTexture, temp, _bilateralBlurMaterial, 0);
                // vertical bilateral blur at full res
                Graphics.Blit(temp, _volumeLightTexture, _bilateralBlurMaterial, 1);
                RenderTexture.ReleaseTemporary(temp);
            };
        }
    }