Beispiel #1
0
        Entity CreateFrontBufferRenderNode(int w, int h)
        {
            Entity eNode = EntityManager.CreateEntity();

            EntityManager.AddComponentData(eNode, new RenderNode {
            });
            EntityManager.AddComponentData(eNode, new RenderNodePrimarySurface {
            });

            var passRect = new RenderPassRect {
                x = 0, y = 0, w = (ushort)w, h = (ushort)h
            };
            Entity ePassBlit = EntityManager.CreateEntity();

            EntityManager.AddComponentData(ePassBlit, new RenderPass {
                inNode              = eNode,
                sorting             = RenderPassSort.Unsorted,
                projectionTransform = float4x4.identity,
                viewTransform       = float4x4.identity,
                passType            = RenderPassType.FullscreenQuad,
                viewId              = 0xffff,
                scissor             = new RenderPassRect(),
                viewport            = passRect,
                targetRect          = passRect,
                clearFlags          = RenderPassClear.Color,
                clearDepth          = 1.0f,
                clearStencil        = 0,
                clearRGBA           = 0xff,
                shadowMask          = ulong.MaxValue,
                cameraMask          = ulong.MaxValue
            });
            EntityManager.AddComponent <RenderPassAutoSizeToNode>(ePassBlit);
            EntityManager.AddComponent <RenderPassClearColorFromBorder>(ePassBlit);

            Entity ePassDebug = EntityManager.CreateEntity();

            EntityManager.AddComponentData(ePassDebug, new RenderPass {
                inNode              = eNode,
                sorting             = RenderPassSort.Sorted,
                projectionTransform = float4x4.identity,
                viewTransform       = float4x4.identity,
                passType            = RenderPassType.DebugOverlay,
                viewId              = 0xffff,
                scissor             = new RenderPassRect(),
                viewport            = passRect,
                targetRect          = passRect,
                clearFlags          = 0,
                clearDepth          = 1.0f,
                clearStencil        = 0,
                shadowMask          = ulong.MaxValue,
                cameraMask          = ulong.MaxValue
            });
            EntityManager.AddComponent <RenderPassAutoSizeToNode>(ePassDebug);

            DynamicBuffer <RenderNodeRef> nodeRefs = EntityManager.AddBuffer <RenderNodeRef>(eNode);
            DynamicBuffer <RenderPassRef> passRefs = EntityManager.AddBuffer <RenderPassRef>(eNode);

            passRefs.Add(new RenderPassRef {
                e = ePassBlit
            });
            passRefs.Add(new RenderPassRef {
                e = ePassDebug
            });

            return(eNode);
        }
Beispiel #2
0
        void CreateAllCameraPasses(int w, int h, Entity eCam, Entity eNode)
        {
            Camera cam = EntityManager.GetComponentData <Camera>(eCam);
            ulong  cameraMask;

            if (EntityManager.HasComponent <CameraMask>(eCam))
            {
                cameraMask = EntityManager.GetComponentData <CameraMask>(eCam).mask;
            }
            else
            {
                cameraMask = ulong.MaxValue;
            }

            RenderPassRect passRect = new RenderPassRect {
                x = (ushort)(cam.viewportRect.x * w),
                y = (ushort)(cam.viewportRect.y * h),
                w = (ushort)(cam.viewportRect.width * w),
                h = (ushort)(cam.viewportRect.height * h)
            };
            Entity ePassClear = EntityManager.CreateEntity();

            EntityManager.AddComponentData(ePassClear, new RenderPass {
                inNode              = eNode,
                sorting             = RenderPassSort.Unsorted,
                projectionTransform = float4x4.identity,
                viewTransform       = float4x4.identity,
                passType            = RenderPassType.Clear,
                viewId              = 0xffff,
                scissor             = new RenderPassRect(),
                viewport            = passRect,
                targetRect          = passRect,
                clearFlags          = RenderPassClear.Depth | RenderPassClear.Color, // copied from camera
                clearRGBA           = 0xff00ffff,
                clearDepth          = 1.0f,
                clearStencil        = 0,
                shadowMask          = ulong.MaxValue,
                cameraMask          = cameraMask
            });
            SetPassComponents(ePassClear, eCam, true);

            Entity ePassOpaque = EntityManager.CreateEntity();

            EntityManager.AddComponentData(ePassOpaque, new RenderPass {
                inNode              = eNode,
                sorting             = RenderPassSort.Unsorted,
                projectionTransform = float4x4.identity,
                viewTransform       = float4x4.identity,
                passType            = RenderPassType.Opaque,
                viewId              = 0xffff,
                scissor             = new RenderPassRect(),
                viewport            = passRect,
                targetRect          = passRect,
                clearFlags          = 0,
                clearDepth          = 1.0f,
                clearStencil        = 0,
                shadowMask          = ulong.MaxValue,
                cameraMask          = cameraMask
            });
            SetPassComponents(ePassOpaque, eCam);

            Entity ePassSprites = EntityManager.CreateEntity();

            EntityManager.AddComponentData(ePassSprites, new RenderPass {
                inNode              = eNode,
                sorting             = RenderPassSort.SortZGreater,
                projectionTransform = float4x4.identity,
                viewTransform       = float4x4.identity,
                passType            = RenderPassType.Sprites,
                viewId              = 0xffff,
                scissor             = new RenderPassRect(),
                viewport            = passRect,
                targetRect          = passRect,
                clearFlags          = 0,
                clearDepth          = 1.0f,
                clearStencil        = 0,
                shadowMask          = ulong.MaxValue,
                cameraMask          = cameraMask
            });
            SetPassComponents(ePassSprites, eCam);
            EntityManager.AddBuffer <SortSpritesEntry>(ePassSprites);

            Entity ePassUI = EntityManager.CreateEntity();

            EntityManager.AddComponentData(ePassUI, new RenderPass {
                inNode              = eNode,
                sorting             = RenderPassSort.Sorted,
                projectionTransform = float4x4.identity,
                viewTransform       = float4x4.identity,
                passType            = RenderPassType.UI,
                viewId              = 0xffff,
                scissor             = new RenderPassRect(),
                viewport            = new RenderPassRect {
                    x = 0, y = 0, w = (ushort)w, h = (ushort)h
                },
                targetRect   = passRect,
                clearFlags   = 0,
                clearDepth   = 1.0f,
                clearStencil = 0,
                shadowMask   = ulong.MaxValue,
                cameraMask   = cameraMask
            });
            SetPassComponents(ePassUI, eCam);

            Entity ePassTransparent = EntityManager.CreateEntity();

            EntityManager.AddComponentData(ePassTransparent, new RenderPass {
                inNode              = eNode,
                sorting             = RenderPassSort.SortZLess,
                projectionTransform = float4x4.identity,
                viewTransform       = float4x4.identity,
                passType            = RenderPassType.Transparent,
                viewId              = 0xffff,
                scissor             = new RenderPassRect(),
                viewport            = passRect,
                targetRect          = passRect,
                clearFlags          = 0,
                clearDepth          = 1.0f,
                clearStencil        = 0,
                shadowMask          = ulong.MaxValue,
                cameraMask          = cameraMask
            });
            SetPassComponents(ePassTransparent, eCam);

            // add passes to node, in order
            DynamicBuffer <RenderPassRef> passRefs = EntityManager.GetBuffer <RenderPassRef>(eNode);

            passRefs.Add(new RenderPassRef {
                e = ePassClear
            });
            passRefs.Add(new RenderPassRef {
                e = ePassOpaque
            });
            passRefs.Add(new RenderPassRef {
                e = ePassSprites
            });
            passRefs.Add(new RenderPassRef {
                e = ePassUI
            });
            passRefs.Add(new RenderPassRef {
                e = ePassTransparent
            });
        }