Esempio n. 1
0
    override public char[] toChar()
    {
        string cameraString = "camera|";

        cameraString += clearFlags.ToString() + "|";
        cameraString += background.r + "|";
        cameraString += background.g + "|";
        cameraString += background.b + "|";
        cameraString += background.a + "|";
        cameraString += cullingMask.ToString() + "|";
        cameraString += near.ToString() + "|";
        cameraString += far.ToString() + "|";
        cameraString += viewportRect.x + "|";
        cameraString += viewportRect.y + "|";
        cameraString += viewportRect.width + "|";
        cameraString += viewportRect.height + "|";
        cameraString += renderingPath.ToString() + "|";
        cameraString += HDR.ToString() + "|";
        cameraString += MSAA.ToString() + "|";
        cameraString += occlusionCulling.ToString() + "|";
        cameraString += depth.ToString() + "|";
        cameraString += fov.ToString() + "|";
        cameraString += targetDisplay.ToString() + "|";
        return(cameraString.ToCharArray());
    }
Esempio n. 2
0
        int GetMsaa(MSAA m, int srcMsaa)
        {
            int msaa = srcMsaa;

            switch (m)
            {
            case MSAA.AUTO:
                break;

            case MSAA.OFF:
                msaa = 1;
                break;

            case MSAA.X2:
                msaa = 2;
                break;

            case MSAA.X4:
                msaa = 4;
                break;

            case MSAA.X8:
                msaa = 8;
                break;
            }
            return(msaa);
        }
Esempio n. 3
0
        public RenderTarget(Renderer renderer, Window window, MSAA msaa)
        {
            Renderer = renderer;
            Window   = window;
            Window.Swapchain.Renderer = renderer;

            // Do initial build
            var maxAtt = (renderer?.MSAALayout ?? renderer !.Layout).Attachments.Length;

            _images       = new VkImage[maxAtt];
            _memorys      = new MemoryAllocation[maxAtt];
            Views         = new VkImageView[maxAtt];
            _framebuffers = new VkFramebuffer[Swapchain.MAX_IMAGE_COUNT];
            Rebuild(msaa);
        }
Esempio n. 4
0
 /// <summary>
 /// Checks if the given MSAA is supported by the current platform. <see cref="Core.Instance"/> must be
 /// populated.
 /// </summary>
 /// <param name="msaa">The MSAA level to check.</param>
 public static bool IsSupported(this MSAA msaa) => Core.Instance?.Graphics.Limits.IsMSAASupported(msaa) ?? false;
Esempio n. 5
0
        void UpdateRenderTextures(int srcX, int srcY, int srcMsaa)
        {
            bool changeRes = (srcX != _rtX || srcY != _rtY || srcMsaa != _rtA);
            bool updated   = false;

            // Update background RT
            if (
                _usingCageRt &&
                (changeRes || _cageRt == null || _lastCageDownsample != cageDownsample || _lastCageMsaa != cageAntiAliasing)
                )
            {
                if (_cageRt != null)
                {
                    _cageRt.Release();
                }

                int x = srcX / (cageDownsample + 1);
                int y = srcY / (cageDownsample + 1);
                                #if UNITY_2017_2_OR_NEWER
                RenderTextureDescriptor cageRtd = new RenderTextureDescriptor(x, y, RenderTextureFormat.Default, 24);
                cageRtd.vrUsage = UnityEngine.XR.XRSettings.eyeTextureDesc.vrUsage;
                _cageRt         = new RenderTexture(cageRtd);
                                #else
                _cageRt = new RenderTexture(x, y, 24);
                                #endif
                _cageRt.antiAliasing = GetMsaa(cageAntiAliasing, srcMsaa);
                _cageRt.name         = "VTP Background";
                _cageRt.Create();

                _lastCageDownsample = cageDownsample;
                _lastCageMsaa       = cageAntiAliasing;
                updated             = true;
            }

            // Update mask RT
            if (usingMask && (changeRes || _maskRt == null /*|| _lastMaskMsaa != maskAntiAliasing*/))
            {
                if (_maskRt != null)
                {
                    _maskRt.Release();
                }

                _maskRt = new RenderTexture(srcX, srcY, 16, RenderTextureFormat.R8);
                _maskRt.antiAliasing = srcMsaa;                 //GetMsaa(maskAntiAliasing, srcMsaa);
                _maskRt.name         = "VTP Mask";
                _maskRt.Create();

                ResetMaskCommandBuffer();

                //_lastMaskMsaa = maskAntiAliasing;
                updated = true;
            }

            // Update blur RTs
            if (
                backgroundMode == BackgroundMode.BLUR &&
                (changeRes || _blurRt0 == null || _blurRt1 == null || _lastBlurDownsample != blurDownsample)
                )
            {
                if (_blurRt0 != null)
                {
                    _blurRt0.Release();
                }
                if (_blurRt1 != null)
                {
                    _blurRt1.Release();
                }

                int x = srcX / (blurDownsample + 1);
                int y = srcY / (blurDownsample + 1);
                                #if UNITY_2017_2_OR_NEWER
                RenderTextureDescriptor blurRtd = new RenderTextureDescriptor(x, y, RenderTextureFormat.Default, 0);
                blurRtd.vrUsage = UnityEngine.XR.XRSettings.eyeTextureDesc.vrUsage;
                _blurRt0        = new RenderTexture(blurRtd);
                _blurRt1        = new RenderTexture(blurRtd);
                                #else
                _blurRt0 = new RenderTexture(x, y, 0);
                _blurRt1 = new RenderTexture(x, y, 0);
                                #endif
                _blurRt0.name = "VTP Blur 0";
                _blurRt1.name = "VTP Blur 1";
                _blurRt0.Create();
                _blurRt1.Create();
                UpdateBlurKernel();
                _lastBlurDownsample = blurDownsample;
                updated             = true;
            }

            if (updated)
            {
                _rtX = srcX;
                _rtY = srcY;
                _rtA = srcMsaa;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Override some or all settings using a TunnellingPreset asset.
        /// </summary>
        public void ApplyPreset(TunnellingPreset p)
        {
            ApplyPresetBase(p);

            if (p.overrideEffectOverlay)
            {
                effectOverlay = p.effectOverlay;
            }
            if (p.overrideBackgroundMode)
            {
                backgroundMode = p.backgroundMode;
            }

            if (p.overrideCageDownsample)
            {
                cageDownsample = p.cageDownsample;
            }
            if (p.overrideCageAntiAliasing)
            {
                cageAntiAliasing = p.cageAntiAliasing;
            }
            if (p.overrideCageUpdateEveryFrame)
            {
                cageUpdateEveryFrame = p.cageUpdateEveryFrame;
            }

            if (p.overrideCageFogDensity)
            {
                cageFogDensity = p.cageFogDensity;
            }
            if (p.overrideCageFogPower)
            {
                cageFogPower = p.cageFogPower;
            }
            if (p.overrideCageFogBlend)
            {
                cageFogBlend = p.cageFogBlend;
            }

            if (p.overrideMaskMode)
            {
                maskMode = p.maskMode;
            }
            if (p.overrideBlurDownsample)
            {
                blurDownsample = p.blurDownsample;
            }
            if (p.overrideBlurDistance)
            {
                blurDistance = p.blurDistance;
            }
            if (p.overrideBlurPasses)
            {
                blurPasses = p.blurPasses;
            }
            if (p.overrideBlurSamples)
            {
                blurSamples = p.blurSamples;
            }

            if (p.overrideCounterVelocityMode)
            {
                counterVelocityMode = p.counterVelocityMode;
            }
            if (p.overrideCounterVelocityResetDistance)
            {
                counterVelocityResetDistance = p.counterVelocityResetDistance;
            }
            if (p.overrideCounterVelocityResetTime)
            {
                counterVelocityResetTime = p.counterVelocityResetTime;
            }
            if (p.overrideCounterVelocityStrength)
            {
                counterVelocityStrength = p.counterVelocityStrength;
            }
            if (p.overrideCounterVelocityPerAxis)
            {
                counterVelocityPerAxis = p.counterVelocityPerAxis;
            }

            if (p.overrideIrisZRejection)
            {
                irisZRejection = p.irisZRejection;
            }
        }
Esempio n. 7
0
        void DrawMSAA(Surface screen, Surface debugScreen)
        {
            if (MSAA > 64)
            {
                return;
            }
            Vector3 subScreenPoint;
            Vector3 finalColor = new Vector3(0);
            Ray     ray        = new Ray(Vector3.UnitX, Vector3.Zero);
            Vector3 screenPoint;
            Vector3 dir;
            Vector3 screenHorz = camera.TopRight - camera.TopLeft;   //Horizontal vector of the screen
            Vector3 screenVert = camera.BottomLeft - camera.TopLeft; //Vertical vector of the screen
            float   horzStep   = 1f / screen.width;
            float   vertStep   = 1f / screen.height;
            float   msX        = 0;
            float   msY        = 0;

            for (int y = yoffset; y < (yoffset + yjump); ++y, u = 0, v += vertStep, offset += screen.width)
            {
                for (int x = 0; x < screen.width; ++x, u += horzStep)
                {
                    screenPoint = camera.TopLeft + u * screenHorz + v * screenVert; //Top left + u * horz + v * vert => screen point
                    dir         = screenPoint - camera.Position;
                    finalColor  = new Vector3(0);
                    msX         = 0;
                    msY         = 0;
                    for (int subY = 0; subY < msaaValue; subY++, msX = 0, msY += axisoffsetY)
                    {
                        for (int subX = 0; subX < msaaValue; subX++, msX += axisoffsetX)
                        {
                            subScreenPoint = new Vector3(screenPoint.X + msX, screenPoint.Y + msY, screenPoint.Z);
                            //subScreenPoint = screenPoint;
                            dir = subScreenPoint - camera.Position;           //A vector from the camera to that screen point
                            ray = new Ray(dir.Normalized(), camera.Position); //Create a primary ray from there

                            //foreach (Primitive p in scene.Primitives)
                            //   p.Intersect(ray);  //Calculate the intersection with all the primitives

                            //byte i = (byte)(1024 / (ray.Intsect.Distance * ray.Intsect.Distance));

                            finalColor += ray.GetColor(scene);
                            //Console.WriteLine("InLoop: " +subScreenPoint + " : " + subColor + " : " + finalColor);

                            //Draw some rays on the debug screen
                        }
                    }

                    screen.pixels[x + offset] = CreateColor(finalColor * msaaFactor);
                }
            }
            screen.Line(0, yoffset + yjump, screen.width, yoffset + yjump, 0xff00ff);
            if (screen.height - yoffset > 64)
            {
                screen.Print("MSAAx" + MSAA.ToString(), screen.width / 2 - 20, yoffset + yjump + 2, 0xffffff);
            }

            if (yoffset < screen.height - yjump)
            {
                yoffset += yjump;
            }
            else
            {
                yoffset = 0;
                u       = 0;
                v       = 0;
                offset  = 0;
                if (MSAA < 64)
                {
                    MSAA = MSAA * 4;
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Override some or all settings using a TunnellingPreset asset.
        /// </summary>
        public void ApplyPreset(TunnellingPreset p)
        {
            ApplyPresetBase(p);

            if (p.overrideBackgroundMode)
            {
                backgroundMode = p.backgroundMode;
            }

            if (p.overrideCageDownsample)
            {
                cageDownsample = p.cageDownsample;
            }
            if (p.overrideCageAntiAliasing)
            {
                cageAntiAliasing = p.cageAntiAliasing;
            }
            if (p.overrideCageUpdateEveryFrame)
            {
                cageUpdateEveryFrame = p.cageUpdateEveryFrame;
            }

            if (p.overrideCageFogDensity)
            {
                cageFogDensity = p.cageFogDensity;
            }
            if (p.overrideCageFogPower)
            {
                cageFogPower = p.cageFogPower;
            }
            if (p.overrideCageFogBlend)
            {
                cageFogBlend = p.cageFogBlend;
            }

            if (p.overrideMaskMode)
            {
                maskMode = p.maskMode;
            }
            if (p.overrideBlurDownsample)
            {
                blurDownsample = p.blurDownsample;
            }
            if (p.overrideBlurDistance)
            {
                blurDistance = p.blurDistance;
            }
            if (p.overrideBlurPasses)
            {
                blurPasses = p.blurPasses;
            }
            if (p.overrideBlurSamples)
            {
                blurSamples = p.blurSamples;
            }

            if (p.overrideIrisZRejection)
            {
                irisZRejection = p.irisZRejection;
            }
        }
Esempio n. 9
0
        // Rebuilds the additional images and framebuffers
        public void Rebuild(MSAA msaa)
        {
            // Destroy old framebuffers
            foreach (var fb in _framebuffers)
            {
                fb?.DestroyFramebuffer(null);
            }
            Array.Clear(_framebuffers, 0, _framebuffers.Length);

            // Destroy old images
            foreach (var view in Views)
            {
                view?.DestroyImageView(null);
            }
            Array.Clear(Views, 0, Views.Length);
            foreach (var image in _images)
            {
                image?.DestroyImage(null);
            }
            Array.Clear(_images, 0, _images.Length);
            foreach (var mem in _memorys)
            {
                mem?.Free();
            }
            Array.Clear(_memorys, 0, _memorys.Length);

            // Create new images
            var  layout    = (msaa != MSAA.X1) ? Renderer.MSAALayout ! : Renderer.Layout;
            var  windowIdx = (layout.HasMSAA ? layout.NonResolveCount : 0);
            uint idx       = 0;

            foreach (var att in layout.Attachments)
            {
                if (idx != windowIdx)                   // Skip attachment for window
                {
                    CreateImage(Renderer.Graphics, att, msaa, Size, out _images[idx], out _memorys[idx], out Views[idx]);
                }
                idx++;
            }

            // Create a new framebuffer for each swapchain iamge
            var viewHandles = stackalloc VulkanHandle <VkImageView> [Views.Length];
            int vidx        = 0;

            foreach (var view in Views)
            {
                viewHandles[vidx++] = view?.Handle ?? VulkanHandle <VkImageView> .Null;
            }
            VkFramebufferCreateInfo fbci = new(
                flags : VkFramebufferCreateFlags.NoFlags,
                renderPass : Renderer.RenderPass,
                attachmentCount : (uint)layout.Attachments.Length,
                attachments : viewHandles,
                width : Size.Width,
                height : Size.Height,
                layers : 1
                );
            int fbidx = 0;

            foreach (var view in Swapchain.ImageViews)
            {
                viewHandles[windowIdx] = view.Handle;
                VulkanHandle <VkFramebuffer> fbhandle;
                Renderer.Graphics.VkDevice.CreateFramebuffer(&fbci, null, &fbhandle)
                .Throw("Failed to create framebuffer");
                _framebuffers[fbidx++] = new(fbhandle, Renderer.Graphics.VkDevice);
            }

            // Update values
            MSAA = msaa;
        }