예제 #1
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());
        }
예제 #2
0
            public void Init(bool enableDistortion, RenderTargetProperty renderTargetProperty
                             , StereoRendererUtil.StereoRenderingTypes stereoRenderingType = StereoRendererUtil.StereoRenderingTypes.None)
            {
                this.isDistortionEnabled        = enableDistortion;
                isDistortionMakeDisabledForcely = false;

                if (enableDistortion && renderTargetProperty != null && renderTargetProperty.colorTargetDescriptor.msaaSamples > 1)
                {
                    Debug.LogWarning("Distortion with MSAA is differnt from Editor on [Effekseer] Effekseer(*RP)");
                    Debug.LogWarning("If LWRP or URP, please check Opacue Texture is PipelineAsset");
                }

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

                if (stereoRenderingType == StereoRendererUtil.StereoRenderingTypes.SinglePass)
                {
                    // In SinglePass Stereo Rendering, draw eyes twice on the left and right with one CommandBuffer
                    this.isDistortionEnabled             = false;
                    this.isDistortionMakeDisabledForcely = true;
                }

                SetupBackgroundBuffer(this.isDistortionEnabled, renderTargetProperty);

                if (!isCommandBufferFromExternal)
                {
                    SetupEffekseerRenderCommandBuffer(commandBuffer, this.isDistortionEnabled, renderTargetProperty);
                }

                // register the command to a camera
                if (!isCommandBufferFromExternal)
                {
                    this.camera.AddCommandBuffer(this.cameraEvent, this.commandBuffer);
                }
            }
예제 #3
0
            public bool IsValid(RenderTargetProperty renderTargetProperty)
            {
                if (isDistortionMakeDisabledForcely)
                {
                }
                else
                {
                    if (this.isDistortionEnabled != EffekseerRendererUtils.IsDistortionEnabled)
                    {
                        return(false);
                    }
                }

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

                    return(targetSize.x == this.renderTexture.width &&
                           targetSize.y == this.renderTexture.height);
                }
                return(true);
            }
            public void Init(bool enableDistortion, bool enableDepth, RenderTargetProperty renderTargetProperty
                             , StereoRendererUtil.StereoRenderingTypes stereoRenderingType = StereoRendererUtil.StereoRenderingTypes.None)
            {
                this.isDistortionEnabled        = enableDistortion;
                isDepthEnabld                   = enableDepth;
                isDistortionMakeDisabledForcely = false;

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

                if (stereoRenderingType == StereoRendererUtil.StereoRenderingTypes.SinglePass)
                {
                    // In SinglePass Stereo Rendering, draw eyes twice on the left and right with one CommandBuffer
                    this.isDistortionEnabled             = false;
                    this.isDistortionMakeDisabledForcely = true;
                }

                SetupBackgroundBuffer(this.isDistortionEnabled, renderTargetProperty);

                RendererUtils.SetupDepthBuffer(ref depthTexture, isDistortionEnabled, camera, renderTargetProperty);

                if (!isCommandBufferFromExternal)
                {
                    SetupEffekseerRenderCommandBuffer(commandBuffer, this.isDistortionEnabled, renderTargetProperty);
                }

                // register the command to a camera
                if (!isCommandBufferFromExternal)
                {
                    this.camera.AddCommandBuffer(this.cameraEvent, this.commandBuffer);
                }
            }
예제 #5
0
        public BackgroundRenderTexture(int width, int height, int depth, RenderTextureFormat format, RenderTargetProperty renderTargetProperty)
        {
            if (renderTargetProperty != null)
            {
                width  = renderTargetProperty.colorTargetDescriptor.width;
                height = renderTargetProperty.colorTargetDescriptor.height;
            }

            if (renderTargetProperty != null)
            {
                renderTexture = new RenderTexture(renderTargetProperty.colorTargetDescriptor);
                renderTexture.antiAliasing = 1;
            }
            else
            {
                renderTexture = new RenderTexture(width, height, 0, format);
            }

            if (renderTexture != null)
            {
                renderTexture.name = "EffekseerBackground";
            }
        }
예제 #6
0
        public void Render(Camera camera, RenderTargetProperty renderTargetProperty, CommandBuffer targetCommandBuffer)
        {
            var settings = EffekseerSettings.Instance;

#if UNITY_EDITOR
            if (camera.cameraType == CameraType.SceneView)
            {
                // check a camera in the scene view
                if (settings.drawInSceneView == false)
                {
                    return;
                }
            }
#endif

            // check a culling mask
            var mask = Effekseer.Plugin.EffekseerGetCameraCullingMaskToShowAllEffects();

            // don't need to update because doesn't exists and need not to render
            if ((camera.cullingMask & mask) == 0 && !renderPaths.ContainsKey(camera))
            {
                return;
            }

            // GC renderpaths
            bool hasDisposed = false;
            foreach (var path_ in renderPaths)
            {
                path_.Value.LifeTime--;
                if (path_.Value.LifeTime < 0)
                {
                    path_.Value.Dispose();
                    hasDisposed = true;
                }
            }

            // dispose renderpaths
            if (hasDisposed)
            {
                List <Camera> removed = new List <Camera>();
                foreach (var path_ in renderPaths)
                {
                    if (path_.Value.LifeTime >= 0)
                    {
                        continue;
                    }

                    removed.Add(path_.Key);
                    Plugin.EffekseerAddRemovingRenderPath(path_.Value.renderId);
                }

                foreach (var r in removed)
                {
                    renderPaths.Remove(r);
                }
            }

            RenderPath path;

            if (renderPaths.ContainsKey(camera))
            {
                path = renderPaths[camera];
            }
            else
            {
                // render path doesn't exists, create a render path
                while (true)
                {
                    bool found = false;
                    foreach (var kv in renderPaths)
                    {
                        if (kv.Value.renderId == nextRenderID)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (found)
                    {
                        nextRenderID++;
                    }
                    else
                    {
                        break;
                    }
                }

                path = new RenderPath(camera, cameraEvent, nextRenderID, targetCommandBuffer != null);
                var stereoRenderingType = (camera.stereoEnabled) ? StereoRendererUtil.GetStereoRenderingType() : StereoRendererUtil.StereoRenderingTypes.None;
                path.Init(EffekseerRendererUtils.IsDistortionEnabled, renderTargetProperty, stereoRenderingType);
                renderPaths.Add(camera, path);
                nextRenderID = (nextRenderID + 1) % EffekseerRendererUtils.RenderIDCount;
            }

            if (!path.IsValid(renderTargetProperty))
            {
                path.Dispose();
                var stereoRenderingType = (camera.stereoEnabled) ? StereoRendererUtil.GetStereoRenderingType() : StereoRendererUtil.StereoRenderingTypes.None;
                path.Init(EffekseerRendererUtils.IsDistortionEnabled, renderTargetProperty, stereoRenderingType);
            }

            path.LifeTime = 60;
            Plugin.EffekseerSetRenderingCameraCullingMask(path.renderId, camera.cullingMask);

            // effects shown don't exists
            if ((camera.cullingMask & mask) == 0)
            {
                // Because rendering thread is asynchronous
                SpecifyRenderingMatrix(camera, path);
                return;
            }

            if (path.isCommandBufferFromExternal)
            {
                path.AssignExternalCommandBuffer(targetCommandBuffer, renderTargetProperty);
            }

            // if LWRP
            if (renderTargetProperty != null)
            {
                // flip a rendertaget
                // Direct11 : OK (2019, LWRP 5.13)
                // Android(OpenGL) : OK (2019, LWRP 5.13)
                Plugin.EffekseerSetRenderSettings(path.renderId, true);
                Plugin.EffekseerSetIsBackgroundTextureFlipped(0);
            }
            else
            {
#if UNITY_SWITCH && !UNITY_EDITOR
                Plugin.EffekseerSetIsBackgroundTextureFlipped(1);
#else
                Plugin.EffekseerSetIsBackgroundTextureFlipped(0);
#endif
            }

            // assign a dinsotrion texture
            if (path.renderTexture != null)
            {
                Plugin.EffekseerSetBackGroundTexture(path.renderId, path.renderTexture.ptr);
            }

            SpecifyRenderingMatrix(camera, path);
        }
        public BackgroundRenderTexture(int width, int height, int depth, RenderTextureFormat format, RenderTargetProperty renderTargetProperty)
        {
            if (renderTargetProperty != null)
            {
                width  = renderTargetProperty.colorTargetDescriptor.width;
                height = renderTargetProperty.colorTargetDescriptor.height;
            }

#if UNITY_STANDALONE_WIN
            if (renderTargetProperty != null)
            {
                renderTexture = new RenderTexture(width, height, 0, format, RenderTextureReadWrite.Linear);
            }
            else
            {
                renderTexture = new RenderTexture(width, height, 0, format);
            }
#else
            renderTexture = new RenderTexture(width, height, 0, format);
#endif
            if (renderTexture != null)
            {
                renderTexture.name = "EffekseerBackground";
            }
        }
        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;
                }
            }
        }
            private void SetupEffekseerRenderCommandBuffer(
                CommandBuffer cmbBuf,
                bool enableDistortion,
                RenderTargetProperty renderTargetProperty)
            {
                // add a command to render effects.
                if (cmbBuf == null)
                {
                    return;
                }

                if (this.depthTexture != null)
                {
                    if (renderTargetProperty != null)
                    {
                        renderTargetProperty.ApplyToCommandBuffer(cmbBuf, this.depthTexture);

                        if (renderTargetProperty.Viewport.width > 0)
                        {
                            cmbBuf.SetViewport(renderTargetProperty.Viewport);
                        }
                    }
                    else
                    {
                        cmbBuf.Blit(BuiltinRenderTextureType.Depth, this.depthTexture.renderTexture);
                        cmbBuf.SetRenderTarget(BuiltinRenderTextureType.CameraTarget);

                        // to reset shader settings. SetRenderTarget is not applied until drawing
                        if (fakeMaterial != null)
                        {
                            cmbBuf.DrawProcedural(new Matrix4x4(), fakeMaterial, 0, MeshTopology.Triangles, 3);
                        }
                    }
                }

                cmbBuf.IssuePluginEvent(Plugin.EffekseerGetRenderBackFunc(), this.renderId);

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

                    if (renderTargetProperty != null)
                    {
                        if (renderTargetProperty.colorBufferID.HasValue)
                        {
                            cmbBuf.Blit(renderTargetProperty.colorBufferID.Value, this.renderTexture.renderTexture);
                            cmbBuf.SetRenderTarget(renderTargetProperty.colorBufferID.Value);

                            if (renderTargetProperty.Viewport.width > 0)
                            {
                                cmbBuf.SetViewport(renderTargetProperty.Viewport);
                            }
                        }
                        else
                        {
                            renderTargetProperty.ApplyToCommandBuffer(cmbBuf, this.renderTexture);

                            if (renderTargetProperty.Viewport.width > 0)
                            {
                                cmbBuf.SetViewport(renderTargetProperty.Viewport);
                            }
                        }
                    }
                    else
                    {
                        cmbBuf.Blit(BuiltinRenderTextureType.CameraTarget, this.renderTexture.renderTexture);
                        cmbBuf.SetRenderTarget(BuiltinRenderTextureType.CameraTarget);

                        // to reset shader settings. SetRenderTarget is not applied until drawing
                        if (fakeMaterial != null)
                        {
                            cmbBuf.DrawProcedural(new Matrix4x4(), fakeMaterial, 0, MeshTopology.Triangles, 3);
                        }
                    }
                }

                cmbBuf.IssuePluginEvent(Plugin.EffekseerGetRenderFrontFunc(), this.renderId);
            }