Ejemplo n.º 1
0
    private void ResetRenderingTextures(MaskParameters iParameters)
    {
        // Prepare render textures.
        globalOcclusionMask = new RenderTexture(Screen.width, Screen.height, 0)
        {
            name = "Processed Occlusion Mask"
        };

        occlusionMaskExtended = new RenderTexture(iParameters.extendedTextureSize.x, iParameters.extendedTextureSize.y, 0)
        {
            name = "Processed Extended Occlusion Mask"
        };

        mixedLightMask = new RenderTexture(Screen.width, Screen.height, 0)
        {
            name = "Mixed Light Mask"
        };

        obstacleLightMask = new RenderTexture((int)(iParameters.lightTextureSize.x * iParameters.wallTextureRescale), (int)(iParameters.lightTextureSize.y * iParameters.wallTextureRescale), 0)
        {
            name = "Light Mask"
        };

        // Let members handle their own textures.
        // Possibly move to container?
        mOcclusionMaskRenderer.ResetRenderingTextures(iParameters);
        mLightMaskRenderer.ResetRenderingTextures(iParameters);
        mPostProcessingStack.ResetRenderingTextures(iParameters);
        mBackgroundRenderer.ResetRenderingTextures(iParameters);
    }
Ejemplo n.º 2
0
    private void OnDisable()
    {
        // Set global occlusion white, so occlusion dependent shaders will show appropriately while system is off.
        Shader.SetGlobalTexture("_FovMask", Texture2D.whiteTexture);

        // Default parameters to force parameters update on enable.
        mCurrentMaskParameters = default(MaskParameters);
    }
Ejemplo n.º 3
0
    private void Update()
    {
        // Drive render quality from light system inspector.
        renderSettings.quality = quality;

        // Monitor state to detect when we should trigger reinitialization of rendering textures.
        var _newParameters = new MaskParameters(mMainCamera, renderSettings);

        bool _shouldReinitializeTextures = _newParameters != mCurrentMaskParameters;

        if (_shouldReinitializeTextures)
        {
            mCurrentMaskParameters = _newParameters;

            ResetRenderingTextures(mCurrentMaskParameters);
        }
    }
    public void ResetRenderingTextures(MaskParameters iParameters)
    {
        // Prepare and assign RenderTexture.
        int _textureWidth  = iParameters.screenSize.x;
        int _textureHeight = iParameters.screenSize.y;

        var _newRenderTexture = new RenderTexture(_textureWidth, _textureHeight, 0, RenderTextureFormat.Default);

        _newRenderTexture.name             = "Background Mask";
        _newRenderTexture.autoGenerateMips = false;
        _newRenderTexture.useMipMap        = false;

        // Note: Assignment will release previous texture if exist.
        mask = _newRenderTexture;

        mMaskCamera.orthographicSize = iParameters.cameraOrthographicSize;
    }
Ejemplo n.º 5
0
    public void GenerateFovMask(
        RenderTexture iRawOcclusionMask,
        RenderTexture iGlobalOcclusionExtendedMask,
        RenderSettings iRenderSettings,
        Vector3 iFovCenterInViewSpace,
        float iFovDistance,
        MaskParameters iMaskParameters)
    {
        mMaterialContainer.fovMaterial.SetVector("_PositionOffset", iFovCenterInViewSpace);
        mMaterialContainer.fovMaterial.SetFloat("_OcclusionSpread", iRenderSettings.fovOcclusionSpread);

        // Adjust scale from Extended mask to Screen size mask.
        float   _yUVScale         = 1 / iMaskParameters.cameraAspect;
        Vector3 _adjustedDistance = iFovDistance * iMaskParameters.worldUnitInViewportSpace * (float)iMaskParameters.cameraOrthographicSize / iMaskParameters.extendedCameraSize;

        mMaterialContainer.fovMaterial.SetVector("_Distance", new Vector3(_adjustedDistance.x, _yUVScale, iRenderSettings.fovHorizonSmooth));

        Graphics.Blit(iRawOcclusionMask, iGlobalOcclusionExtendedMask, mMaterialContainer.fovMaterial);
    }
    public void ResetRenderingTextures(MaskParameters iParameters)
    {
        int _textureWidth  = iParameters.extendedTextureSize.x;
        int _textureHeight = iParameters.extendedTextureSize.y;

        var _newRenderTexture = new RenderTexture(_textureWidth, _textureHeight, 0, RenderTextureFormat.Default);

        _newRenderTexture.name             = "Raw Scaled Occlusion Mask";
        _newRenderTexture.autoGenerateMips = false;
        _newRenderTexture.useMipMap        = false;


        // Important to filter out matching pixels!
        _newRenderTexture.antiAliasing = iParameters.antiAliasing;
        _newRenderTexture.filterMode   = FilterMode.Bilinear;

        // Note: Assignment will release previous texture if exist.
        mask = _newRenderTexture;

        mMaskCamera.orthographicSize = iParameters.extendedCameraSize;
    }
Ejemplo n.º 7
0
    public void ResetRenderingTextures(MaskParameters iParameters)
    {
        // Prepare and assign RenderTexture.
        int _textureWidth  = iParameters.lightTextureSize.x;
        int _textureHeight = iParameters.lightTextureSize.y;

        var _newRenderTexture = new RenderTexture(_textureWidth, _textureHeight, 0, RenderTextureFormat.Default);

        _newRenderTexture.name             = "Raw Light Mask";
        _newRenderTexture.autoGenerateMips = false;
        _newRenderTexture.useMipMap        = false;
        _newRenderTexture.filterMode       = FilterMode.Bilinear;
        _newRenderTexture.antiAliasing     = iParameters.antiAliasing;

        // Note: Assignment will release previous texture if exist.
        mask = _newRenderTexture;

        mMaskCamera.orthographicSize = iParameters.cameraOrthographicSize;

        Vector2 _scale = new Vector2((float)iParameters.cameraOrthographicSize / iParameters.extendedCameraSize, (float)iParameters.cameraOrthographicSize / iParameters.extendedCameraSize);

        Shader.SetGlobalVector("_ExtendedToSmallTextureScale", _scale);
    }
Ejemplo n.º 8
0
    public void ResetRenderingTextures(MaskParameters iParameters)
    {
        // Prepare and assign RenderTexture.
        int _textureWidth  = iParameters.screenSize.x;
        int _textureHeight = iParameters.screenSize.y;

        {
            var _newRenderTexture = new RenderTexture(_textureWidth, _textureHeight, 0, RenderTextureFormat.Default);
            _newRenderTexture.name             = "Blur Render Texture";
            _newRenderTexture.autoGenerateMips = false;
            _newRenderTexture.useMipMap        = false;

            // Note: Assignment will release previous texture if exist.
            blurRenderTexture = _newRenderTexture;
        }

        {
            var _newRenderTexture = new RenderTexture(iParameters.lightTextureSize.x, iParameters.lightTextureSize.y, 0, RenderTextureFormat.Default);
            _newRenderTexture.name             = "Blur Render Texture";
            _newRenderTexture.autoGenerateMips = false;
            _newRenderTexture.useMipMap        = false;

            // Note: Assignment will release previous texture if exist.
            blurRenderTextureLight = _newRenderTexture;
        }

        {
            var _newRenderTexture = new RenderTexture(iParameters.lightTextureSize.x, iParameters.lightTextureSize.y, 0, RenderTextureFormat.Default);
            _newRenderTexture.name             = "Blur Render Texture";
            _newRenderTexture.autoGenerateMips = false;
            _newRenderTexture.useMipMap        = false;

            // Note: Assignment will release previous texture if exist.
            blurRenderTextureWallLight = _newRenderTexture;
        }
    }
Ejemplo n.º 9
0
    public void FitExtendedOcclusionMask(RenderTexture iSource, RenderTexture iDestination, MaskParameters iMaskParameters)
    {
        Vector2 _scale = new Vector2((float)iMaskParameters.cameraOrthographicSize / iMaskParameters.extendedCameraSize, (float)iMaskParameters.cameraOrthographicSize / iMaskParameters.extendedCameraSize);

        Graphics.Blit(iSource, iDestination, _scale, (Vector2.one - _scale) * 0.5f);
    }