public override void Initialize() { AdapterConfig = new() { SwapChain = true, Debug = false, Bindless = true, //SingleQueue }; Adapter = new(AdapterConfig); Device = new(Adapter); SwapChain = new(Device, new() { Source = GetSwapchainSource(Adapter), ColorSrgb = false, Height = Window.Height, Width = Window.Width, VSync = false, DepthFormat = Adapter.DepthFormat is VkFormat.Undefined ? null : Adapter.DepthFormat }); Context = new(Device); Framebuffer = new(SwapChain); Camera.SetPosition(0, 0.34f, -18.5f); uniform = new(Camera.Projection, Camera.View); CreateBuffers(); CreatePipelineState(); }
public void Draw(ITransformation camera) { var cameraUniform = new TransformUniform(nameof(camera), camera); mrtSurface.Execute(() => { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); renderState.Set(new FaceCullingModeState(FaceCullingMode.BACK_SIDE)); renderState.Set(new DepthTest(true)); foreach (var vis in meshVisuals) { vis.SetUniform(cameraUniform); //TODO: only once per shader vis.Draw(); } renderState.Set(new DepthTest(false)); }); //TextureDebugger.Draw(mrtSurface.Textures.ElementAt(1)); return; GL.Clear(ClearBufferMask.ColorBufferBit); renderState.Set(BlendStates.Additive); renderState.Set(new FaceCullingModeState(FaceCullingMode.FRONT_SIDE)); // important to cull for light volume rendering, otherwise we would have lighting partly twice applied and to cull front face, otherwise near clipping artifacts lightsVisual.SetUniform(cameraUniform); lightsVisual.Draw(); renderState.Set(BlendStates.Opaque); }
public void Render(ITransformation camera, Vector3 cameraPosition) { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); var cameraUniform = new TransformUniform(nameof(camera), camera); var cameraPosUniform = new Vec3Uniform(nameof(cameraPosition), cameraPosition); foreach (var visual in visuals) { visual.SetUniform(cameraPosUniform); //TODO: only per shader needed visual.SetUniform(cameraUniform); visual.Draw(); } }
private void SetupTransformUniform(TransformUniform transform) { if (TransformUniformHandle == default(int)) { GL.GenBuffers(1, out TransformUniformHandle); GL.BindBuffer(BufferTarget.UniformBuffer, TransformUniformHandle); GL.BufferData(BufferTarget.UniformBuffer, GlobalUniform.Size, IntPtr.Zero, BufferUsageHint.DynamicDraw); } else { GL.BindBuffer(BufferTarget.UniformBuffer, TransformUniformHandle); } GL.BufferSubData(BufferTarget.UniformBuffer, IntPtr.Zero, TransformUniform.Size, ref transform); GL.BindBufferBase(BufferRangeTarget.UniformBuffer, UniformIndices.Transform, TransformUniformHandle); GL.BindBuffer(BufferTarget.UniformBuffer, 0); }
public override void Initialize() { AdapterConfig = new() { SwapChain = true, Debug = true, }; Adapter = new Adapter(AdapterConfig); Device = new Device(Adapter); SwapChain = new SwapChain(Device, new() { Source = GetSwapchainSource(Adapter), ColorSrgb = false, Height = Window.Height, Width = Window.Width, VSync = false, DepthFormat = Adapter.DepthFormat is VkFormat.Undefined ? null : Adapter.DepthFormat }); Context = new GraphicsContext(Device); Framebuffer = new Framebuffer(SwapChain); Camera = new(45f, 1f, 0.1f, 64f); Camera.SetPosition(0, 0, -3.0f); Camera.AspectRatio = (float)Window.Width / Window.Height; Camera.Update(); // Reset Model Model = Matrix4x4.Identity; Uniform = new(Camera.Projection, Model, Camera.View); CreateBuffers(); CreatePipelineState(); }
public override void Initialize() { AdapterConfig = new() { SwapChain = true, }; Camera.SetPosition(0, 0, -8.0f); Camera.Update(); Adapter = new(AdapterConfig); Device = new(Adapter); SwapChain = new(Device, new() { Source = GetSwapchainSource(Adapter), ColorSrgb = false, Height = Window.Height, Width = Window.Width, VSync = false, DepthFormat = Adapter.DepthFormat is VkFormat.Undefined ? null : Adapter.DepthFormat }); Context = new(Device); Framebuffer = new(SwapChain); uniform = new(Camera.Projection, Camera.View); light = new() { Ambient = new Vector4(0.5f, 0.5f, 0.5f, 1.0f), Diffuse = new Vector4(0.8f, 0.8f, 0.8f, 1.0f), Direction = new Vector3(1, 1, -1.05f), Specular = new(1, 1, 1), SpecularPower = 30, }; ConstBuffer = new(Device, new() { BufferFlags = BufferFlags.ConstantBuffer, Usage = ResourceUsage.CPU_To_GPU, SizeInBytes = Interop.SizeOf <TransformUniform>(), }); ConstBuffer2 = new(Device, new() { BufferFlags = BufferFlags.ConstantBuffer, Usage = ResourceUsage.CPU_To_GPU, SizeInBytes = Interop.SizeOf <Light>(), }); Sphere = new(Device, Vultaik.Toolkit.GeometricPrimitives.PrimitiveType.Sphere); Sphere.Position = new(-2.5f, 1.5f, 0.0f); Torus = new(Device, Vultaik.Toolkit.GeometricPrimitives.PrimitiveType.Torus); Torus.Position = new(2.5f, 1.5f, 0.0f); Pyramid = new(Device, Vultaik.Toolkit.GeometricPrimitives.PrimitiveType.Pyramid); Pyramid.Position = new(-2.5f, -1.5f, 0.0f); Cube = new(Device, Vultaik.Toolkit.GeometricPrimitives.PrimitiveType.Cube); Cube.Position = new(2.5f, -1.5f, 0.0f); Capsule = new(Device, Vultaik.Toolkit.GeometricPrimitives.PrimitiveType.Capsule); Capsule.Position = new(0, 0, 0.0f); Capsule.Size = new(0.4f, 0.4f, 0.4f); CreatePipelineState(); }