Ejemplo n.º 1
0
 private static void SpecifyRenderingMatrix(Camera camera, RenderPath path)
 {
     // specify matrixes for stereo rendering
     if (camera.stereoEnabled)
     {
         var stereoRenderType = StereoRendererUtil.GetStereoRenderingType();
         if (stereoRenderType != StereoRendererUtil.StereoRenderingTypes.None)
         {
             float[] camCenterMat = Utility.Matrix2Array(camera.worldToCameraMatrix);
             float[] projMatL     = Utility.Matrix2Array(GL.GetGPUProjectionMatrix(camera.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left), false));
             float[] projMatR     = Utility.Matrix2Array(GL.GetGPUProjectionMatrix(camera.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right), false));
             float[] camMatL      = Utility.Matrix2Array(camera.GetStereoViewMatrix(Camera.StereoscopicEye.Left));
             float[] camMatR      = Utility.Matrix2Array(camera.GetStereoViewMatrix(Camera.StereoscopicEye.Right));
             Plugin.EffekseerSetStereoRenderingMatrix(path.renderId, (int)stereoRenderType, camCenterMat, projMatL, projMatR, camMatL, camMatR);
         }
     }
     else
     {
         // update view matrixes
         Plugin.EffekseerSetProjectionMatrix(path.renderId, Utility.Matrix2Array(
                                                 GL.GetGPUProjectionMatrix(camera.projectionMatrix, false)));
         Plugin.EffekseerSetCameraMatrix(path.renderId, Utility.Matrix2Array(
                                             camera.worldToCameraMatrix));
     }
 }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public void Render(Camera camera, int?dstID, RenderTargetIdentifier?dstIdentifier)
        {
            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();

            if ((camera.cullingMask & mask) == 0)
            {
                if (renderPaths.ContainsKey(camera))
                {
                    var path_ = renderPaths[camera];
                    path_.Dispose();
                    renderPaths.Remove(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);
                }

                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
                path = new RenderPath(camera, cameraEvent, renderPaths.Count);
                var stereoRenderingType = (camera.stereoEnabled)? StereoRendererUtil.GetStereoRenderingType() : StereoRendererUtil.StereoRenderingTypes.None;
                path.Init(EffekseerRendererUtils.IsDistortionEnabled, dstID, dstIdentifier, stereoRenderingType);
                renderPaths.Add(camera, path);
            }

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

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

            // if LWRP
            if (dstID.HasValue || dstIdentifier.HasValue)
            {
                // 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
            {
                Plugin.EffekseerSetIsBackgroundTextureFlipped(0);
            }

            // assign a dinsotrion texture
            if (path.renderTexture)
            {
                Plugin.EffekseerSetBackGroundTexture(path.renderId, path.renderTexture.GetNativeTexturePtr());
            }

            // specify matrixes for stereo rendering
            if (camera.stereoEnabled)
            {
                var stereoRenderType = StereoRendererUtil.GetStereoRenderingType();
                if (stereoRenderType != StereoRendererUtil.StereoRenderingTypes.None)
                {
                    float[] camCenterMat = Utility.Matrix2Array(camera.worldToCameraMatrix);
                    float[] projMatL     = Utility.Matrix2Array(GL.GetGPUProjectionMatrix(camera.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left), false));
                    float[] projMatR     = Utility.Matrix2Array(GL.GetGPUProjectionMatrix(camera.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right), false));
                    float[] camMatL      = Utility.Matrix2Array(camera.GetStereoViewMatrix(Camera.StereoscopicEye.Left));
                    float[] camMatR      = Utility.Matrix2Array(camera.GetStereoViewMatrix(Camera.StereoscopicEye.Right));
                    Plugin.EffekseerSetStereoRenderingMatrix(path.renderId, (int)stereoRenderType, camCenterMat, projMatL, projMatR, camMatL, camMatR);
                }
            }
            else
            {
                // update view matrixes
                Plugin.EffekseerSetProjectionMatrix(path.renderId, Utility.Matrix2Array(
                                                        GL.GetGPUProjectionMatrix(camera.projectionMatrix, false)));
                Plugin.EffekseerSetCameraMatrix(path.renderId, Utility.Matrix2Array(
                                                    camera.worldToCameraMatrix));
            }
        }