private void UpdateShaderViewport()
        {
            if (ViewportHost != null)
            {
                if (SelectedShaderGroup != null && SelectedShaderGroup.IsBuilded)
                {
                    string[] shaderLocations = new string[5];
                    foreach (Shader s in SelectedShaderGroup.Shaders)
                    {
                        if (s.ShaderType != ShaderType.Header)
                        {
                            shaderLocations[(int)s.ShaderType] = $"{MainWindowPageViewModel.ShaderBoxResourcesFolderLocation}{SelectedShaderGroup.UniqueName}/.cso/{s.GetShaderTarget().Substring(0, 2)}.cso";
                        }
                    }
                    bool isStandard = SelectedShaderGroup.ShaderGroupType == ShaderGroupType.Standard;
                    if (isStandard)
                    {
                        ViewportHost.SetShaders(shaderLocations[0] ?? "", shaderLocations[1] ?? "", shaderLocations[2] ?? "", shaderLocations[3] ?? "", shaderLocations[4] ?? "");
                        ViewportHost.SetTopology((int)SelectedShaderGroup.Topology);
                        ViewportHost.SetRasterizerState((int)SelectedShaderGroup.CullMode, (int)SelectedShaderGroup.FillMode);
                    }
                    else
                    {
                        ViewportHost.SetPPShader(shaderLocations[4] ?? "");
                    }
                    _settedGroup = SelectedShaderGroup;

                    foreach (AnnotationShaderGroup annotationShaderGroup in SelectedShaderGroup.AnnotationShaderGroups)
                    {
                        foreach (AnnotationGroup annotationGroup in annotationShaderGroup.Buffers)
                        {
                            foreach (AnnotationVariable annotationVariable in annotationGroup.AnnotationVariables)
                            {
                                annotationVariable.UpdateBuffer(false);
                            }
                            annotationGroup.MarshalBuffer(ViewportHost, isStandard);
                        }
                    }
                }

                ViewportHost.SetModel(SelectedModel?.Path ?? Workspace.Models[0].Path);
                ViewportHost.SetCameraOffset(CameraOffset);

                RaisePropertyChanged("SelectedModel");
            }
        }
        private void RaiseBuildShaderGroup()
        {
            Shader shader = ShaderGroupsView.CurrentItem as Shader;

            if (shader.Group.ShaderGroupType != ShaderGroupType.SharedHeaders)
            {
                shader.Group.AnnotationShaderGroups.Clear();

                bool     hasErrors       = false;
                string[] shaderLocations = new string[5];
                foreach (Shader s in shader.Group.Shaders)
                {
                    if (s.ShaderType != ShaderType.Header)
                    {
                        hasErrors |= CompileShader(s, true);
                        shaderLocations[(int)s.ShaderType] = $"{MainWindowPageViewModel.ShaderBoxResourcesFolderLocation}{shader.Group.UniqueName}/.cso/{s.GetShaderTarget().Substring(0, 2)}.cso";
                        if (hasErrors)
                        {
                            shader.Group.IsBuilded = false;
                            if (Directory.Exists(Path.GetDirectoryName(Path.GetFullPath(s.FileLocation)) + "/.cso"))
                            {
                                Directory.Delete(Path.GetDirectoryName(Path.GetFullPath(s.FileLocation)) + "/.cso", true);
                            }
                            break;
                        }
                    }
                }

                // Only refresh shader variables if compilation of all shaders succesfull

                if (!hasErrors)
                {
                    SelectedShaderGroup.IsBuilded = true;

                    if (SelectedShaderGroup.ShaderGroupType == ShaderGroupType.Standard)
                    {
                        if (SelectedShaderGroup == _settedGroup)
                        {
                            ViewportHost.UpdateShaders(
                                shaderLocations[0] ?? "", shaderLocations[1] ?? "", shaderLocations[2] ?? "", shaderLocations[3] ?? "", shaderLocations[4] ?? "");
                        }
                        else
                        {
                            // Workaround so we don't update the wrong shader, if shaders wasn't in cache we load everything double, not good
                            ViewportHost.SetShaders(
                                shaderLocations[0] ?? "", shaderLocations[1] ?? "", shaderLocations[2] ?? "", shaderLocations[3] ?? "", shaderLocations[4] ?? "");
                            ViewportHost.UpdateShaders(
                                shaderLocations[0] ?? "", shaderLocations[1] ?? "", shaderLocations[2] ?? "", shaderLocations[3] ?? "", shaderLocations[4] ?? "");
                            ViewportHost.SetTopology((int)SelectedShaderGroup.Topology);
                            ViewportHost.SetRasterizerState((int)SelectedShaderGroup.CullMode, (int)SelectedShaderGroup.FillMode);
                        }
                    }
                    else
                    {
                        if (SelectedShaderGroup == _settedGroup)
                        {
                            ViewportHost.UpdatePPShader(shaderLocations[4] ?? "");
                        }
                        else
                        {
                            ViewportHost.SetPPShader(shaderLocations[4] ?? "");
                            ViewportHost.UpdatePPShader(shaderLocations[4] ?? "");
                        }
                    }
                    try
                    {
                        foreach (Shader s in SelectedShaderGroup.Shaders)
                        {
                            SyntaxTree            syntaxTree = SyntaxFactory.ParseSyntaxTree(SourceText.From(s.Document.Text), null, null);
                            AnnotationShaderGroup options    = UpdateVariables(syntaxTree, s.ShaderType);
                            if (options == null)
                            {
                                break;
                            }
                            if (options.Buffers.Count > 0)
                            {
                                SelectedShaderGroup.AnnotationShaderGroups.Add(options);
                            }
                        }

                        ViewportHost.RenderThumbnail(Path.GetFullPath($"{MainWindowPageViewModel.ShaderBoxResourcesFolderLocation}{SelectedShaderGroup.UniqueName}/preview.png"),
                                                     async() =>
                        {
                            await Application.Current.Dispatcher.InvokeAsync(() =>
                            {
                                _selectedShaderGroup.Image = null;
                                ViewportHost.PopCallbackRenderThumbnail();
                            });
                        });
                    }
                    catch (Exception)
                    {
                        SelectedShaderGroup.AnnotationShaderGroups.Clear();
                    }
                }
                SelectedShaderGroup.Save(Workspace);
            }
        }