Beispiel #1
0
            private void SetupEffekseerRenderCommandBuffer(
                CommandBuffer commandBuffer,
                bool enableDistortion,
                int?dstID,
                RenderTargetIdentifier?dstIdentifier)
            {
                // add a command to render effects.
                this.commandBuffer.IssuePluginEvent(Plugin.EffekseerGetRenderBackFunc(), this.renderId);

                if (enableDistortion)
                {
                    var width  = EffekseerRendererUtils.ScaledClamp(this.camera.scaledPixelWidth, EffekseerRendererUtils.DistortionBufferScale);
                    var height = EffekseerRendererUtils.ScaledClamp(this.camera.scaledPixelHeight, EffekseerRendererUtils.DistortionBufferScale);

#if UNITY_IOS || UNITY_ANDROID
                    RenderTextureFormat format = RenderTextureFormat.ARGB32;
#else
                    RenderTextureFormat format = (this.camera.allowHDR) ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.ARGB32;
#endif
                    this.renderTexture = new RenderTexture(width, height, 0, format);

                    // HACK for ZenPhone (cannot understand)
                    if (this.renderTexture == null || !this.renderTexture.Create())
                    {
                        this.renderTexture = null;
                        this.commandBuffer.IssuePluginEvent(Plugin.EffekseerGetRenderFrontFunc(), this.renderId);
                        this.camera.AddCommandBuffer(this.cameraEvent, this.commandBuffer);
                        return;
                    }

                    // Add a blit command that copy to the distortion texture
                    this.commandBuffer.Blit(BuiltinRenderTextureType.CameraTarget, this.renderTexture);
                    this.commandBuffer.SetRenderTarget(BuiltinRenderTextureType.CameraTarget);

                    if (dstID.HasValue)
                    {
                        this.commandBuffer.Blit(dstID.Value, this.renderTexture);
                        this.commandBuffer.SetRenderTarget(dstID.Value);
                    }
                    else if (dstIdentifier.HasValue)
                    {
                        this.commandBuffer.Blit(dstIdentifier.Value, this.renderTexture);
                        this.commandBuffer.SetRenderTarget(dstIdentifier.Value);
                    }
                    else
                    {
                        this.commandBuffer.Blit(BuiltinRenderTextureType.CameraTarget, this.renderTexture);
                        this.commandBuffer.SetRenderTarget(BuiltinRenderTextureType.CameraTarget);
                    }
                }

                this.commandBuffer.IssuePluginEvent(Plugin.EffekseerGetRenderFrontFunc(), this.renderId);
            }
Beispiel #2
0
            public bool IsValid()
            {
                if (this.isDistortionEnabled != EffekseerRendererUtils.IsDistortionEnabled)
                {
                    return(false);
                }

                if (this.renderTexture != null)
                {
                    var width  = EffekseerRendererUtils.ScaledClamp(this.camera.scaledPixelWidth, EffekseerRendererUtils.DistortionBufferScale);
                    var height = EffekseerRendererUtils.ScaledClamp(this.camera.scaledPixelHeight, EffekseerRendererUtils.DistortionBufferScale);

                    return(width == this.renderTexture.width &&
                           height == this.renderTexture.height);
                }
                return(true);
            }
Beispiel #3
0
        public static Vector2Int GetRequiredSize(Camera camera, RenderTargetProperty renderTargetProperty)
        {
            if (renderTargetProperty != null)
            {
                var width  = renderTargetProperty.colorTargetDescriptor.width;
                var height = renderTargetProperty.colorTargetDescriptor.height;
                return(new Vector2Int(width, height));
            }

            if (camera != null)
            {
                var width  = EffekseerRendererUtils.ScaledClamp(camera.scaledPixelWidth, EffekseerRendererUtils.DistortionBufferScale);
                var height = EffekseerRendererUtils.ScaledClamp(camera.scaledPixelHeight, EffekseerRendererUtils.DistortionBufferScale);
                return(new Vector2Int(width, height));
            }

            return(new Vector2Int());
        }
Beispiel #4
0
            public void Init(bool enableDistortion)
            {
                isDistortionEnabled = enableDistortion;

                // Create a command buffer that is effekseer renderer
                this.commandBuffer      = new CommandBuffer();
                this.commandBuffer.name = "Effekseer Rendering";

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

                // register the command to a camera
                this.camera.AddCommandBuffer(this.cameraEvent, this.commandBuffer);

                if (enableDistortion)
                {
                    var width  = EffekseerRendererUtils.ScaledClamp(this.camera.scaledPixelWidth, EffekseerRendererUtils.DistortionBufferScale);
                    var height = EffekseerRendererUtils.ScaledClamp(this.camera.scaledPixelHeight, EffekseerRendererUtils.DistortionBufferScale);

#if UNITY_IOS || UNITY_ANDROID
                    RenderTextureFormat format = RenderTextureFormat.ARGB32;
#else
                    RenderTextureFormat format = (this.camera.allowHDR) ? RenderTextureFormat.ARGBHalf : RenderTextureFormat.ARGB32;
#endif
                    this.renderTexture = new RenderTexture(width, height, 0, format);

                    // HACK for ZenPhone (cannot understand)
                    if (this.renderTexture == null || !this.renderTexture.Create())
                    {
                        this.renderTexture = null;
                    }
                }

                computeBufferFront = new ComputeBuffer(VertexMaxCount, VertexSize, ComputeBufferType.Default);
                computeBufferBack  = new ComputeBuffer(VertexMaxCount, VertexSize, ComputeBufferType.Default);
                computeBufferTemp  = new byte[VertexMaxCount * VertexSize];
            }