Example #1
0
            private void SetupBackgroundBuffer(bool enableDistortion, RenderTargetProperty renderTargetProperty)
            {
                if (this.renderTexture != null)
                {
                    this.renderTexture.Release();
                    this.renderTexture = null;
                }

                if (enableDistortion)
                {
                    var targetSize = BackgroundRenderTexture.GetRequiredSize(this.camera, renderTargetProperty);

#if UNITY_IOS || UNITY_ANDROID
                    RenderTextureFormat format = RenderTextureFormat.ARGB32;
#else
                    RenderTextureFormat format = (this.camera.allowHDR) ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.ARGB32;
#endif
                    this.renderTexture = new BackgroundRenderTexture(targetSize.x, targetSize.y, 0, format, renderTargetProperty);

                    // HACK for ZenPhone
                    if (this.renderTexture == null || !this.renderTexture.Create())
                    {
                        this.renderTexture = null;
                    }
                }
            }
        public static void SetupDepthBuffer(ref DepthRenderTexture depthRenderTexure, bool enabled, Camera camera, RenderTargetProperty renderTargetProperty)
        {
            if (depthRenderTexure != null)
            {
                depthRenderTexure.Release();
                depthRenderTexure = null;
            }

            if (enabled)
            {
                var targetSize = BackgroundRenderTexture.GetRequiredSize(camera, renderTargetProperty);

#if UNITY_IOS || UNITY_ANDROID
                RenderTextureFormat format = RenderTextureFormat.ARGB32;
#else
                RenderTextureFormat format = (camera.allowHDR) ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.ARGB32;
#endif
                depthRenderTexure = new DepthRenderTexture(targetSize.x, targetSize.y, renderTargetProperty);

                // HACK for some smart phone
                if (depthRenderTexure == null || !depthRenderTexure.Create())
                {
                    depthRenderTexure = null;
                }
            }
        }
            public bool IsValid(RenderTargetProperty renderTargetProperty)
            {
                if (isDistortionMakeDisabledForcely)
                {
                }
                else
                {
                    if (this.isDistortionEnabled != EffekseerRendererUtils.IsDistortionEnabled)
                    {
                        return(false);
                    }
                }

                if (this.isDepthEnabld != EffekseerRendererUtils.IsDepthEnabled)
                {
                    var targetSize = BackgroundRenderTexture.GetRequiredSize(this.camera, renderTargetProperty);

                    return(targetSize.x == this.depthTexture.width &&
                           targetSize.y == this.depthTexture.height);
                }

                if (this.renderTexture != null)
                {
                    var targetSize = BackgroundRenderTexture.GetRequiredSize(this.camera, renderTargetProperty);

                    return(targetSize.x == this.renderTexture.width &&
                           targetSize.y == this.renderTexture.height);
                }
                return(true);
            }
        internal void ApplyToCommandBuffer(CommandBuffer cb, BackgroundRenderTexture backgroundRenderTexture)
        {
            if (isRequiredToChangeViewport)
            {
                if (colorTargetRenderTexture.dimension == TextureDimension.Tex2DArray)
                {
                    var m = AllocateBlitArrayMaterial();
                    m.SetTexture("_BackgroundTex", colorTargetRenderTexture);
                    m.SetVector("textureArea", new Vector4(
                                    Viewport.width / colorTargetRenderTexture.width,
                                    Viewport.height / colorTargetRenderTexture.height,
                                    Viewport.x / colorTargetRenderTexture.width,
                                    Viewport.y / colorTargetRenderTexture.height));
                    cb.SetRenderTarget(backgroundRenderTexture.renderTexture);
                    cb.ClearRenderTarget(true, true, new Color(0, 0, 0));
                    cb.Blit(colorTargetIdentifier, backgroundRenderTexture.renderTexture, m);
                }
                else
                {
                    var m = AllocateBlitMaterial();
                    m.SetTexture("_BackgroundTex", colorTargetRenderTexture);
                    m.SetVector("textureArea", new Vector4(
                                    Viewport.width / colorTargetRenderTexture.width,
                                    Viewport.height / colorTargetRenderTexture.height,
                                    Viewport.x / colorTargetRenderTexture.width,
                                    Viewport.y / colorTargetRenderTexture.height));
                    cb.SetRenderTarget(backgroundRenderTexture.renderTexture);
                    cb.ClearRenderTarget(true, true, new Color(0, 0, 0));
                    cb.Blit(colorTargetIdentifier, backgroundRenderTexture.renderTexture, m);
                }
            }
            else if (isRequiredToCopyBackground)
            {
                cb.CopyTexture(colorTargetIdentifier, new RenderTargetIdentifier(backgroundRenderTexture.renderTexture));
            }
            else
            {
                cb.Blit(colorTargetIdentifier, backgroundRenderTexture.renderTexture);
            }

            if (!isRequiredToCopyBackground)
            {
                if (depthTargetIdentifier.HasValue)
                {
                    cb.SetRenderTarget(colorTargetIdentifier, depthTargetIdentifier.Value);
                }
                else
                {
                    cb.SetRenderTarget(colorTargetIdentifier);
                }
            }
        }
Example #5
0
            public void Dispose()
            {
                if (this.commandBuffer != null && !isCommandBufferFromExternal)
                {
                    if (this.camera != null)
                    {
                        this.camera.RemoveCommandBuffer(this.cameraEvent, this.commandBuffer);
                    }
                    this.commandBuffer.Dispose();
                    this.commandBuffer = null;
                }

                if (this.renderTexture != null)
                {
                    this.renderTexture.Release();
                    this.renderTexture = null;
                }
            }