public void CanCalculateFrustum() { // Arrange. var light = new GlobalShaderResources.Light { Direction = Vector3.Normalize(new Vector3(-1, -1, -1)) }; var camera = new Camera(() => new Veldrid.Viewport { Width = 800, Height = 600 }); camera.SetLookAt(new Vector3(5, 3, 10), Vector3.Zero, Vector3.UnitZ); var window = new Veldrid.Sdl2.Sdl2Window("Test", 0, 0, 100, 100, 0, false); using (var graphicsDevice = VeldridStartup.CreateGraphicsDevice(window)) { var shadowData = new ShadowData(4, 5, 1000, 512, graphicsDevice); var settings = new ShadowSettings(); var lightFrustumCalculator = new ShadowFrustumCalculator(); // Act. lightFrustumCalculator.CalculateShadowData(light, camera, shadowData, settings); // Assert. Assert.Equal(-0.02f, shadowData.ShadowCameraViewProjections[0].M11, 2); Assert.Equal(0.37f, shadowData.ShadowCameraViewProjections[0].M43, 2); } }
static void Main(string[] args) { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { SetProcessDPIAware(); // no DPI scaling -> no blurry fonts } Veldrid.Sdl2.Sdl2Window window = VeldridStartup.CreateWindow(new WindowCreateInfo(200, 60, 1024, 1024, WindowState.Normal, nameof(ShaderPlayer))); IoC.RegisterInstance(window); var mainViewModel = new MainViewModel(); var tracker = Persist.CreateTracker(window, mainViewModel); var options = new GraphicsDeviceOptions() { PreferStandardClipSpaceYDirection = true, SyncToVerticalBlank = true }; var graphicsDevice = VeldridStartup.CreateDefaultOpenGLGraphicsDevice(options, window, GraphicsBackend.OpenGL); //var graphicsDevice = VeldridStartup.CreateGraphicsDevice(window, options, GraphicsBackend.OpenGL); //var graphicsDevice = VeldridStartup.CreateGraphicsDevice(window, options); //var graphicsDevice = VeldridStartup.CreateVulkanGraphicsDevice(options, window); window.Resized += () => graphicsDevice.ResizeMainWindow((uint)window.Width, (uint)window.Height); IoC.RegisterInstance(graphicsDevice); var inputTracker = new InputTracker(); var myGui = new MyGui(mainViewModel); var viewModel = new ShaderViewModel(); window.Resized += () => viewModel.Resize((uint)window.Width, (uint)window.Height); var taskService = new TaskService(); IoC.RegisterInstance(taskService); IDisposable fileChangeSubscription = null; void LoadShader(string shaderFileName) { fileChangeSubscription?.Dispose(); fileChangeSubscription = TrackedFile.DelayedLoad(shaderFileName).Subscribe( fileName => { taskService.AddTask(() => mainViewModel.ErrorMessage = viewModel.Load(fileName)); //myGui.ShowErrorInfo(viewModel.Load(fileName)); window.Title = fileName; }); } window.DragDrop += (dropEvent) => LoadShader(dropEvent.File); //LoadShader(@"D:\Daten\git\SHADER\2D\PatternCircle.glsl"); var guiVisual = new GuiVisual(); var commandList = graphicsDevice.ResourceFactory.CreateCommandList(); //IoC.RegisterInstance(commandList); var time = new Time(); while (window.Exists) { time.Update(); var inputSnapShot = window.PumpEvents(); inputTracker.UpdateFrameInput(inputSnapShot, window); myGui.CommandBindings.Execute(inputTracker); var viewport = myGui.Viewport; var mousePos = inputSnapShot.MousePosition; mousePos.Y = viewport.Height - mousePos.Y - 1; commandList.Begin(); viewModel.Draw(commandList, mousePos, time.Total); guiVisual.BeginDraw(time.FrameDelta, inputSnapShot); myGui.Submit(); guiVisual.EndDraw(commandList); commandList.End(); graphicsDevice.SubmitCommands(commandList); graphicsDevice.SwapBuffers(); taskService.ProcessNextTask(); } guiVisual.Dispose(); fileChangeSubscription?.Dispose(); graphicsDevice.WaitForIdle(); viewModel.Dispose(); commandList.Dispose(); graphicsDevice.Dispose(); }