├── .gitattributes ├── .gitignore ├── Assets ├── colored_cube.obj ├── cube.obj ├── flat_vase.obj ├── quad.obj └── smooth_vase.obj ├── Docs ├── screenshot1.png ├── screenshot2.png └── screenshot3.png ├── LICENSE.md ├── README.md └── Source ├── Chapter01Window ├── Chapter01Window.csproj ├── FirstApp.cs ├── LveWindow.cs └── Program01.cs ├── Chapter02Shaders ├── Chapter02Shaders.csproj ├── FirstApp.cs ├── LvePipeline.cs ├── LveWindow.cs ├── Program02.cs └── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv ├── Chapter03PipelineSetup ├── Chapter03PipelineSetup.csproj ├── FirstApp.cs ├── Globals.cs ├── LogUtil.cs ├── LveDevice.cs ├── LvePipeline.cs ├── LveWindow.cs ├── Program03.cs └── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv ├── Chapter04PipelineStages ├── Chapter04PipelineStages.csproj ├── FirstApp.cs ├── Globals.cs ├── LogUtil.cs ├── LveDevice.cs ├── LvePipeline.cs ├── LveWindow.cs ├── Program04.cs └── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv ├── Chapter05SwapChain ├── Chapter05PipelineStages.csproj ├── FirstApp.cs ├── Globals.cs ├── LogUtil.cs ├── LveDevice.cs ├── LvePipeline.cs ├── LveSwapChain.cs ├── LveWindow.cs ├── Program05.cs └── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv ├── Chapter06VertexBuffers ├── Chapter06VertextBuffers.csproj ├── FirstApp.cs ├── Globals.cs ├── LogUtil.cs ├── LveDevice.cs ├── LveModel.cs ├── LvePipeline.cs ├── LveSwapChain.cs ├── LveWindow.cs ├── Program06.cs └── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv ├── Chapter07FragmentInterpolation ├── Chapter07FragmentInterpolation.csproj ├── FirstApp.cs ├── Globals.cs ├── LogUtil.cs ├── LveDevice.cs ├── LveModel.cs ├── LvePipeline.cs ├── LveSwapChain.cs ├── LveWindow.cs ├── Program07.cs └── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv ├── Chapter08DynamicViewports ├── Chapter08DynamicViewports.csproj ├── FirstApp.cs ├── Globals.cs ├── LogUtil.cs ├── LveDevice.cs ├── LveModel.cs ├── LvePipeline.cs ├── LveSwapChain.cs ├── Program08.cs └── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv ├── Chapter09PushConstants ├── Chapter09PushConstants.csproj ├── FirstApp.cs ├── Globals.cs ├── LogUtil.cs ├── LveDevice.cs ├── LveModel.cs ├── LvePipeline.cs ├── LveSwapChain.cs ├── Program09.cs └── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv ├── Chapter10TwoDTransformations ├── Chapter10TwoDTransformations.csproj ├── FirstApp.cs ├── Globals.cs ├── LogUtil.cs ├── LveDevice.cs ├── LveGameObject.cs ├── LveModel.cs ├── LvePipeline.cs ├── LveSwapChain.cs ├── Program10.cs └── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv ├── Chapter11RendererSystems ├── Chapter11RendererSystems.csproj ├── FirstApp.cs ├── Globals.cs ├── LogUtil.cs ├── LveDevice.cs ├── LveGameObject.cs ├── LveModel.cs ├── LvePipeline.cs ├── LveRenderer.cs ├── LveSwapChain.cs ├── Program11.cs ├── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv └── SimpleRenderSystem.cs ├── Chapter12EulerHomogeneousCoords ├── Chapter12EulerHomogeneousCoords.csproj ├── FirstApp.cs ├── Globals.cs ├── LogUtil.cs ├── LveDevice.cs ├── LveGameObject.cs ├── LveModel.cs ├── LvePipeline.cs ├── LveRenderer.cs ├── LveSwapChain.cs ├── Program12.cs ├── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv └── SimpleRenderSystem.cs ├── Chapter13ProjectionMatrices ├── Chapter13ProjectionMatrices.csproj ├── FirstApp.cs ├── Globals.cs ├── LogUtil.cs ├── LveCamera.cs ├── LveDevice.cs ├── LveGameObject.cs ├── LveModel.cs ├── LvePipeline.cs ├── LveRenderer.cs ├── LveSwapChain.cs ├── Program13.cs ├── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv └── SimpleRenderSystem.cs ├── Chapter14CameraViewTransform ├── Chapter14CameraViewTransform.csproj ├── FirstApp.cs ├── Globals.cs ├── LogUtil.cs ├── LveCamera.cs ├── LveDevice.cs ├── LveGameObject.cs ├── LveModel.cs ├── LvePipeline.cs ├── LveRenderer.cs ├── LveSwapChain.cs ├── Program14.cs ├── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv └── SimpleRenderSystem.cs ├── Chapter15GameLoopUserInput ├── Chapter15GameLoopUserInput.csproj ├── FirstApp.cs ├── Globals.cs ├── KeyboardMovementController.cs ├── LogUtil.cs ├── LveCamera.cs ├── LveDevice.cs ├── LveGameObject.cs ├── LveModel.cs ├── LvePipeline.cs ├── LveRenderer.cs ├── LveSwapChain.cs ├── Program15.cs ├── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv └── SimpleRenderSystem.cs ├── Chapter16IndexStagingBuffers ├── Chapter16IndexStagingBuffers.csproj ├── FirstApp.cs ├── Globals.cs ├── KeyboardMovementController.cs ├── LogUtil.cs ├── LveCamera.cs ├── LveDevice.cs ├── LveGameObject.cs ├── LvePipeline.cs ├── LveRenderer.cs ├── LveSwapChain.cs ├── Model │ ├── Builder.cs │ ├── LveModel.cs │ └── Vertex.cs ├── Program16.cs ├── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv └── SimpleRenderSystem.cs ├── Chapter17Loading3DModels ├── CameraController.cs ├── Chapter17Loading3DModels.csproj ├── FirstApp.cs ├── Globals.cs ├── KeyboardController.cs ├── LogUtil.cs ├── LveCamera.cs ├── LveDevice.cs ├── LveGameObject.cs ├── LvePipeline.cs ├── LveRenderer.cs ├── LveSwapChain.cs ├── Model │ ├── Builder.cs │ ├── ColorHelper.cs │ ├── LveModel.cs │ ├── MatrixUtil.cs │ ├── ModelUtils.cs │ └── Vertex.cs ├── OrthographicCamera.cs ├── Program17.cs ├── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv └── SimpleRenderSystem.cs ├── Chapter18DiffuseShading ├── CameraController.cs ├── Chapter18DiffuseShading.csproj ├── FirstApp.cs ├── Globals.cs ├── KeyboardController.cs ├── LogUtil.cs ├── LveCamera.cs ├── LveDevice.cs ├── LveGameObject.cs ├── LvePipeline.cs ├── LveRenderer.cs ├── LveSwapChain.cs ├── Model │ ├── Builder.cs │ ├── ColorHelper.cs │ ├── LveModel.cs │ ├── MatrixUtil.cs │ ├── ModelUtils.cs │ └── Vertex.cs ├── OrthographicCamera.cs ├── Program18.cs ├── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv └── SimpleRenderSystem.cs ├── Chapter19UniformBuffers ├── CameraController.cs ├── Chapter19UniformBuffers.csproj ├── FirstApp.cs ├── FrameInfo.cs ├── Globals.cs ├── KeyboardController.cs ├── LogUtil.cs ├── LveBuffer.cs ├── LveCamera.cs ├── LveDevice.cs ├── LveGameObject.cs ├── LvePipeline.cs ├── LveRenderer.cs ├── LveSwapChain.cs ├── Model │ ├── Builder.cs │ ├── ColorHelper.cs │ ├── GlobalUbo.cs │ ├── LveModel.cs │ ├── MatrixUtil.cs │ ├── ModelUtils.cs │ └── Vertex.cs ├── OrthographicCamera.cs ├── Program19.cs ├── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv └── SimpleRenderSystem.cs ├── Chapter19zNoCoherentAomSizeFix ├── CameraController.cs ├── Chapter19zNoCoherentAomSizeFix.csproj ├── FirstApp.cs ├── FrameInfo.cs ├── Globals.cs ├── KeyboardController.cs ├── LogUtil.cs ├── LveBuffer.cs ├── LveCamera.cs ├── LveDevice.cs ├── LveGameObject.cs ├── LvePipeline.cs ├── LveRenderer.cs ├── LveSwapChain.cs ├── Model │ ├── Builder.cs │ ├── ColorHelper.cs │ ├── GlobalUbo.cs │ ├── LveModel.cs │ ├── MatrixUtil.cs │ ├── ModelUtils.cs │ └── Vertex.cs ├── OrthographicCamera.cs ├── Program19z.cs ├── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv └── SimpleRenderSystem.cs ├── Chapter20DescriptorSets ├── CameraController.cs ├── Chapter20DescriptorSets.csproj ├── Descriptor │ ├── LveDescriptorPool.cs │ ├── LveDescriptorSetLayout.cs │ └── LveDescriptorSetWriter.cs ├── FirstApp.cs ├── FrameInfo.cs ├── Globals.cs ├── KeyboardController.cs ├── LogUtil.cs ├── LveBuffer.cs ├── LveCamera.cs ├── LveDevice.cs ├── LveGameObject.cs ├── LvePipeline.cs ├── LveRenderer.cs ├── LveSwapChain.cs ├── Model │ ├── Builder.cs │ ├── ColorHelper.cs │ ├── GlobalUbo.cs │ ├── LveModel.cs │ ├── MatrixUtil.cs │ ├── ModelUtils.cs │ └── Vertex.cs ├── OrthographicCamera.cs ├── Program20.cs ├── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv └── SimpleRenderSystem.cs ├── Chapter20aDescriptorSetsNoBuilder ├── CameraController.cs ├── Chapter20aDescriptorSetsNoBuilder.csproj ├── Descriptor │ ├── LveDescriptorPool.cs │ ├── LveDescriptorSetLayout.cs │ └── LveDescriptorSetWriter.cs ├── FirstApp.cs ├── FrameInfo.cs ├── Globals.cs ├── KeyboardController.cs ├── LogUtil.cs ├── LveBuffer.cs ├── LveCamera.cs ├── LveDevice.cs ├── LveGameObject.cs ├── LvePipeline.cs ├── LveRenderer.cs ├── LveSwapChain.cs ├── Model │ ├── Builder.cs │ ├── ColorHelper.cs │ ├── GlobalUbo.cs │ ├── LveModel.cs │ ├── MatrixUtil.cs │ ├── ModelUtils.cs │ └── Vertex.cs ├── OrthographicCamera.cs ├── Program20alt.cs ├── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv └── SimpleRenderSystem.cs ├── Chapter21PointLights ├── CameraController.cs ├── Chapter21PointLights.csproj ├── Descriptor │ ├── LveDescriptorPool.cs │ ├── LveDescriptorSetLayout.cs │ └── LveDescriptorSetWriter.cs ├── FirstApp.cs ├── FrameInfo.cs ├── Globals.cs ├── KeyboardController.cs ├── LogUtil.cs ├── LveBuffer.cs ├── LveCamera.cs ├── LveDevice.cs ├── LveGameObject.cs ├── LvePipeline.cs ├── LveRenderer.cs ├── LveSwapChain.cs ├── Model │ ├── Builder.cs │ ├── ColorHelper.cs │ ├── GlobalUbo.cs │ ├── LveModel.cs │ ├── MatrixUtil.cs │ ├── ModelUtils.cs │ └── Vertex.cs ├── OrthographicCamera.cs ├── Program21.cs ├── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv └── SimpleRenderSystem.cs ├── Chapter22FragmentLighting ├── CameraController.cs ├── Chapter22FragmentLighting.csproj ├── Descriptor │ ├── LveDescriptorPool.cs │ ├── LveDescriptorSetLayout.cs │ └── LveDescriptorSetWriter.cs ├── FirstApp.cs ├── FrameInfo.cs ├── Globals.cs ├── KeyboardController.cs ├── LogUtil.cs ├── LveBuffer.cs ├── LveCamera.cs ├── LveDevice.cs ├── LveGameObject.cs ├── LvePipeline.cs ├── LveRenderer.cs ├── LveSwapChain.cs ├── Model │ ├── Builder.cs │ ├── ColorHelper.cs │ ├── GlobalUbo.cs │ ├── LveModel.cs │ ├── MatrixUtil.cs │ ├── ModelUtils.cs │ └── Vertex.cs ├── OrthographicCamera.cs ├── Program22.cs ├── Shaders │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv └── SimpleRenderSystem.cs ├── Chapter24Billboards ├── CameraController.cs ├── Chapter24Billboards.csproj ├── Descriptor │ ├── LveDescriptorPool.cs │ ├── LveDescriptorSetLayout.cs │ └── LveDescriptorSetWriter.cs ├── FirstApp.cs ├── FrameInfo.cs ├── Globals.cs ├── KeyboardController.cs ├── LogUtil.cs ├── LveBuffer.cs ├── LveCamera.cs ├── LveDevice.cs ├── LveGameObject.cs ├── LvePipeline.cs ├── LveRenderer.cs ├── LveSwapChain.cs ├── Model │ ├── Builder.cs │ ├── ColorHelper.cs │ ├── GlobalUbo.cs │ ├── LveModel.cs │ ├── MatrixUtil.cs │ ├── ModelUtils.cs │ └── Vertex.cs ├── OrthographicCamera.cs ├── Program24.cs ├── Shaders │ ├── pointLight.frag │ ├── pointLight.frag.spv │ ├── pointLight.vert │ ├── pointLight.vert.spv │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv └── Systems │ ├── PointLightRenderSystem.cs │ └── SimpleRenderSystem.cs ├── Chapter25MultiplePointLights ├── CameraController.cs ├── Chapter25MultiplePointLights.csproj ├── Descriptor │ ├── LveDescriptorPool.cs │ ├── LveDescriptorSetLayout.cs │ └── LveDescriptorSetWriter.cs ├── FirstApp.cs ├── FrameInfo.cs ├── GlobalUbo.cs ├── Globals.cs ├── KeyboardController.cs ├── LogUtil.cs ├── LveBuffer.cs ├── LveCamera.cs ├── LveDevice.cs ├── LveGameObject.cs ├── LvePipeline.cs ├── LveRenderer.cs ├── LveSwapChain.cs ├── Model │ ├── Builder.cs │ ├── ColorHelper.cs │ ├── LveModel.cs │ ├── MatrixUtil.cs │ ├── ModelUtils.cs │ ├── PointLightComponent.cs │ └── Vertex.cs ├── OrthographicCamera.cs ├── Program25.cs ├── Shaders │ ├── pointLight.frag │ ├── pointLight.frag.spv │ ├── pointLight.vert │ ├── pointLight.vert.spv │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv └── Systems │ ├── PointLightRenderSystem.cs │ └── SimpleRenderSystem.cs ├── Chapter26SpecularLighting ├── CameraController.cs ├── Chapter26SpecularLighting.csproj ├── Descriptor │ ├── LveDescriptorPool.cs │ ├── LveDescriptorSetLayout.cs │ └── LveDescriptorSetWriter.cs ├── FirstApp.cs ├── FrameInfo.cs ├── GlobalUbo.cs ├── Globals.cs ├── ICamera.cs ├── KeyboardController.cs ├── LogUtil.cs ├── LveBuffer.cs ├── LveCamera.cs ├── LveDevice.cs ├── LveGameObject.cs ├── LvePipeline.cs ├── LveRenderer.cs ├── LveSwapChain.cs ├── Model │ ├── Builder.cs │ ├── ColorHelper.cs │ ├── LveModel.cs │ ├── MatrixUtil.cs │ ├── ModelUtils.cs │ ├── PointLightComponent.cs │ └── Vertex.cs ├── OrthographicCamera.cs ├── PerspectiveCamera.cs ├── Program26.cs ├── Shaders │ ├── pointLight.frag │ ├── pointLight.frag.spv │ ├── pointLight.vert │ ├── pointLight.vert.spv │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv └── Systems │ ├── PointLightRenderSystem.cs │ └── SimpleRenderSystem.cs ├── Chapter27AlphaBlending ├── BlittableHelper.cs ├── CameraController.cs ├── Chapter27AlphaBlending.csproj ├── Descriptor │ ├── LveDescriptorPool.cs │ ├── LveDescriptorSetLayout.cs │ └── LveDescriptorSetWriter.cs ├── FirstApp.cs ├── FrameInfo.cs ├── GlobalUbo.cs ├── Globals.cs ├── ICamera.cs ├── KeyboardController.cs ├── LogUtil.cs ├── LveBuffer.cs ├── LveCamera.cs ├── LveDevice.cs ├── LveGameObject.cs ├── LvePipeline.cs ├── LveRenderer.cs ├── LveSwapChain.cs ├── Model │ ├── Builder.cs │ ├── ColorHelper.cs │ ├── LveModel.cs │ ├── MatrixUtil.cs │ ├── ModelUtils.cs │ ├── PointLightComponent.cs │ └── Vertex.cs ├── OrthographicCamera.cs ├── PerspectiveCamera.cs ├── Program27.cs ├── Shaders │ ├── pointLight.frag │ ├── pointLight.frag.spv │ ├── pointLight.vert │ ├── pointLight.vert.spv │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv └── Systems │ ├── PointLightRenderSystem.cs │ └── SimpleRenderSystem.cs ├── Sandbox01MultiSampling ├── BlittableHelper.cs ├── CameraController.cs ├── Descriptor │ ├── LveDescriptorPool.cs │ ├── LveDescriptorSetLayout.cs │ └── LveDescriptorSetWriter.cs ├── FirstApp.cs ├── FrameInfo.cs ├── GlobalUbo.cs ├── Globals.cs ├── ICamera.cs ├── KeyboardController.cs ├── LogUtil.cs ├── LveBuffer.cs ├── LveCamera.cs ├── LveDevice.cs ├── LveGameObject.cs ├── LvePipeline.cs ├── LveRenderer.cs ├── LveSwapChain.cs ├── Model │ ├── Builder.cs │ ├── ColorHelper.cs │ ├── LveModel.cs │ ├── MatrixUtil.cs │ ├── ModelUtils.cs │ ├── PointLightComponent.cs │ └── Vertex.cs ├── OrthographicCamera.cs ├── PerspectiveCamera.cs ├── Program.cs ├── Sandbox01MultiSampling.csproj ├── Shaders │ ├── pointLight.frag │ ├── pointLight.frag.spv │ ├── pointLight.vert │ ├── pointLight.vert.spv │ ├── simpleShader.frag │ ├── simpleShader.frag.spv │ ├── simpleShader.vert │ └── simpleShader.vert.spv └── Systems │ ├── PointLightRenderSystem.cs │ └── SimpleRenderSystem.cs ├── Sandbox02ImGui ├── Camera │ ├── ICamera.cs │ ├── LveCamera.cs │ ├── OrthographicCamera.cs │ └── PerspectiveCamera.cs ├── Controls │ ├── CameraController.cs │ └── KeyboardController.cs ├── Engine │ ├── FrameInfo.cs │ ├── GlobalUbo.cs │ ├── LveBuffer.cs │ ├── LveDescriptorPool.cs │ ├── LveDescriptorSetLayout.cs │ ├── LveDescriptorSetWriter.cs │ ├── LveDevice.cs │ ├── LveGameObject.cs │ ├── LveModel.cs │ ├── LvePipeline.cs │ ├── LveRenderer.cs │ └── LveSwapChain.cs ├── FirstApp.cs ├── FirstApp_gui.cs ├── Globals.cs ├── Program.cs ├── Sandbox02ImGui.csproj ├── Systems │ ├── ImGui │ │ ├── ImGuiController.cs │ │ ├── ImGuiFontConfig.cs │ │ └── Shaders.cs │ ├── PointLight │ │ ├── PointLightComponent.cs │ │ ├── PointLightRenderSystem.cs │ │ ├── pointLight.frag │ │ ├── pointLight.frag.spv │ │ ├── pointLight.vert │ │ └── pointLight.vert.spv │ └── Simple │ │ ├── SimpleRenderSystem.cs │ │ ├── Vertex.cs │ │ ├── simpleShader.frag │ │ ├── simpleShader.frag.spv │ │ ├── simpleShader.vert │ │ └── simpleShader.vert.spv └── Utils │ ├── BlittableHelper.cs │ ├── ColorHelper.cs │ ├── LogUtil.cs │ ├── MatrixUtil.cs │ └── ModelUtils.cs ├── Sandbox03MeshShaders ├── Camera │ ├── ICamera.cs │ ├── LveCamera.cs │ ├── OrthographicCamera.cs │ └── PerspectiveCamera.cs ├── Controls │ ├── CameraController.cs │ └── KeyboardController.cs ├── Engine │ ├── FrameInfo.cs │ ├── GlobalUbo.cs │ ├── LveBuffer.cs │ ├── LveDescriptorPool.cs │ ├── LveDescriptorSetLayout.cs │ ├── LveDescriptorSetWriter.cs │ ├── LveDevice.cs │ ├── LveGameObject.cs │ ├── LveMeshObject.cs │ ├── LveMeshPipeline.cs │ ├── LveModel.cs │ ├── LveRenderer.cs │ ├── LveStdPipeline.cs │ └── LveSwapChain.cs ├── FirstApp.cs ├── FirstApp_gui.cs ├── Globals.cs ├── Program.cs ├── Sandbox03MeshShaders.csproj ├── Systems │ ├── ImGui │ │ ├── ImGuiController.cs │ │ ├── ImGuiFontConfig.cs │ │ └── Shaders.cs │ ├── MeshTest │ │ ├── Mesh2Renderer.cs │ │ ├── SboMeshTest.cs │ │ ├── testMesh.frag │ │ ├── testMesh.mesh │ │ └── testMesh.task │ ├── PointLight │ │ ├── PointLightComponent.cs │ │ ├── PointLightRenderSystem.cs │ │ ├── pointLight.frag │ │ └── pointLight.vert │ ├── SPIRV │ │ ├── pointLight.frag.spv │ │ ├── pointLight.vert.spv │ │ ├── simpleShader.frag.spv │ │ ├── simpleShader.vert.spv │ │ ├── testMesh.frag.spv │ │ ├── testMesh.mesh.spv │ │ └── testMesh.task.spv │ └── Simple │ │ ├── SimpleRenderSystem.cs │ │ ├── Vertex.cs │ │ ├── simpleShader.frag │ │ └── simpleShader.vert └── Utils │ ├── BlittableHelper.cs │ ├── ColorHelper.cs │ ├── FileUtil.cs │ ├── LogUtil.cs │ ├── MatrixUtil.cs │ └── ModelUtils.cs └── SilkVulkanBrendanGaleaTutorial.sln /Assets/colored_cube.obj: -------------------------------------------------------------------------------- 1 | # Blender v2.90.1 OBJ File: '' 2 | # www.blender.org 3 | mtllib untitled.mtl 4 | o Cube 5 | v 1.000000 -1.000000 1.000000 1.0 0.0 0.0 6 | v 1.000000 1.000000 1.000000 0.0 0.0 1.0 7 | v 1.000000 -1.000000 -1.000000 0.0 1.0 0.0 8 | v 1.000000 1.000000 -1.000000 1.0 0.5 0.0 9 | v -1.000000 -1.000000 1.000000 1.0 0.0 0.0 10 | v -1.000000 1.000000 1.000000 1.0 0.0 1.0 11 | v -1.000000 -1.000000 -1.000000 0.0 1.0 0.0 12 | v -1.000000 1.000000 -1.000000 1.0 0.5 0.0 13 | vt 0.875000 0.500000 14 | vt 0.625000 0.750000 15 | vt 0.625000 0.500000 16 | vt 0.375000 1.000000 17 | vt 0.375000 0.750000 18 | vt 0.625000 0.000000 19 | vt 0.375000 0.250000 20 | vt 0.375000 0.000000 21 | vt 0.375000 0.500000 22 | vt 0.125000 0.750000 23 | vt 0.125000 0.500000 24 | vt 0.625000 0.250000 25 | vt 0.875000 0.750000 26 | vt 0.625000 1.000000 27 | vn 0.0000 -1.0000 0.0000 28 | vn 0.0000 0.0000 -1.0000 29 | vn -1.0000 0.0000 0.0000 30 | vn 0.0000 1.0000 0.0000 31 | vn 1.0000 0.0000 0.0000 32 | vn 0.0000 0.0000 1.0000 33 | usemtl Material 34 | s off 35 | f 5/1/1 3/2/1 1/3/1 36 | f 3/2/2 8/4/2 4/5/2 37 | f 7/6/3 6/7/3 8/8/3 38 | f 2/9/4 8/10/4 6/11/4 39 | f 1/3/5 4/5/5 2/9/5 40 | f 5/12/6 2/9/6 6/7/6 41 | f 5/1/1 7/13/1 3/2/1 42 | f 3/2/2 7/14/2 8/4/2 43 | f 7/6/3 5/12/3 6/7/3 44 | f 2/9/4 4/5/4 8/10/4 45 | f 1/3/5 3/2/5 4/5/5 46 | f 5/12/6 1/3/6 2/9/6 47 | -------------------------------------------------------------------------------- /Assets/cube.obj: -------------------------------------------------------------------------------- 1 | # Blender v2.90.1 OBJ File: '' 2 | # www.blender.org 3 | mtllib untitled.mtl 4 | o Cube 5 | v 1.000000 -1.000000 1.000000 6 | v 1.000000 1.000000 1.000000 7 | v 1.000000 -1.000000 -1.000000 8 | v 1.000000 1.000000 -1.000000 9 | v -1.000000 -1.000000 1.000000 10 | v -1.000000 1.000000 1.000000 11 | v -1.000000 -1.000000 -1.000000 12 | v -1.000000 1.000000 -1.000000 13 | vt 0.875000 0.500000 14 | vt 0.625000 0.750000 15 | vt 0.625000 0.500000 16 | vt 0.375000 1.000000 17 | vt 0.375000 0.750000 18 | vt 0.625000 0.000000 19 | vt 0.375000 0.250000 20 | vt 0.375000 0.000000 21 | vt 0.375000 0.500000 22 | vt 0.125000 0.750000 23 | vt 0.125000 0.500000 24 | vt 0.625000 0.250000 25 | vt 0.875000 0.750000 26 | vt 0.625000 1.000000 27 | vn 0.0000 -1.0000 0.0000 28 | vn 0.0000 0.0000 -1.0000 29 | vn -1.0000 0.0000 0.0000 30 | vn 0.0000 1.0000 0.0000 31 | vn 1.0000 0.0000 0.0000 32 | vn 0.0000 0.0000 1.0000 33 | usemtl Material 34 | s off 35 | f 5/1/1 3/2/1 1/3/1 36 | f 3/2/2 8/4/2 4/5/2 37 | f 7/6/3 6/7/3 8/8/3 38 | f 2/9/4 8/10/4 6/11/4 39 | f 1/3/5 4/5/5 2/9/5 40 | f 5/12/6 2/9/6 6/7/6 41 | f 5/1/1 7/13/1 3/2/1 42 | f 3/2/2 7/14/2 8/4/2 43 | f 7/6/3 5/12/3 6/7/3 44 | f 2/9/4 4/5/4 8/10/4 45 | f 1/3/5 3/2/5 4/5/5 46 | f 5/12/6 1/3/6 2/9/6 47 | -------------------------------------------------------------------------------- /Assets/quad.obj: -------------------------------------------------------------------------------- 1 | o Quad 2 | v -1.0 0.0 -1.0 3 | v -1.0 0.0 1.0 4 | v 1.0 0.0 1.0 5 | v 1.0 0.0 -1.0 6 | vt 0.0 0.0 7 | vt 1.0 0.0 8 | vt 1.0 1.0 9 | vt 0.0 1.0 10 | vn 0.0000 -1.0000 0.0000 11 | f 1/1/1 3/3/1 2/2/1 12 | f 3/3/1 1/1/1 4/4/1 -------------------------------------------------------------------------------- /Docs/screenshot1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Docs/screenshot1.png -------------------------------------------------------------------------------- /Docs/screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Docs/screenshot2.png -------------------------------------------------------------------------------- /Docs/screenshot3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Docs/screenshot3.png -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 David Howard 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Source/Chapter01Window/Chapter01Window.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net7.0 6 | enable 7 | enable 8 | true 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Source/Chapter01Window/FirstApp.cs: -------------------------------------------------------------------------------- 1 | using Silk.NET.Vulkan; 2 | 3 | namespace Chapter01Window; 4 | 5 | public class FirstApp 6 | { 7 | private const int WIDTH = 800; 8 | private const int HEIGHT = 600; 9 | private LveWindow window = null!; 10 | 11 | private Vk vk = null!; 12 | 13 | 14 | public void Run() 15 | { 16 | window = new LveWindow(WIDTH, HEIGHT, "MyApp"); 17 | InitVulkan(); 18 | MainLoop(); 19 | CleanUp(); 20 | } 21 | 22 | 23 | private void InitVulkan() 24 | { 25 | vk = Vk.GetApi(); 26 | 27 | 28 | 29 | //uint extensionsCount = 0; 30 | //byte* nullBytes = null; 31 | //vk.EnumerateInstanceExtensionProperties(nullBytes, ref extensionsCount, null); 32 | 33 | //Console.WriteLine($" {extensionsCount} available extensions supported..."); 34 | } 35 | 36 | 37 | 38 | 39 | private void MainLoop() 40 | { 41 | window.Run(); 42 | } 43 | 44 | private void CleanUp() 45 | { 46 | window.Dispose(); 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /Source/Chapter01Window/LveWindow.cs: -------------------------------------------------------------------------------- 1 | using Silk.NET.Maths; 2 | using Silk.NET.Windowing; 3 | 4 | namespace Chapter01Window; 5 | 6 | public class LveWindow: IDisposable 7 | { 8 | private string windowName = ""; 9 | private int width = 800; 10 | private int height = 600; 11 | private IWindow window = null!; 12 | 13 | public LveWindow(int w, int h, string name) 14 | { 15 | width = w; 16 | height = h; 17 | windowName = name; 18 | 19 | initWindow(); 20 | } 21 | 22 | private void initWindow() 23 | { 24 | //Create a window. 25 | var options = WindowOptions.DefaultVulkan with 26 | { 27 | Size = new Vector2D(width, height), 28 | Title = windowName 29 | }; 30 | 31 | window = Window.Create(options); 32 | window.Initialize(); 33 | 34 | if (window.VkSurface is null) 35 | { 36 | throw new Exception("Windowing platform doesn't support Vulkan."); 37 | } 38 | 39 | } 40 | 41 | public void Run() 42 | { 43 | window.Run(); 44 | } 45 | 46 | public void Dispose() 47 | { 48 | window.Dispose(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Source/Chapter01Window/Program01.cs: -------------------------------------------------------------------------------- 1 | using Chapter01Window; 2 | 3 | 4 | var app = new FirstApp(); 5 | 6 | try 7 | { 8 | app.Run(); 9 | 10 | } 11 | catch (Exception ex) 12 | { 13 | Console.WriteLine($"Error!\n{ex.Message}"); 14 | throw; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /Source/Chapter02Shaders/FirstApp.cs: -------------------------------------------------------------------------------- 1 | using Silk.NET.Vulkan; 2 | using System.Reflection; 3 | 4 | namespace Chapter02Shaders; 5 | 6 | public class FirstApp 7 | { 8 | private const int WIDTH = 800; 9 | private const int HEIGHT = 600; 10 | 11 | 12 | private LveWindow window = null!; 13 | private LvePipeline pipeline = null!; 14 | 15 | private Vk vk = null!; 16 | 17 | 18 | public void Run() 19 | { 20 | window = new LveWindow(WIDTH, HEIGHT, "MyApp"); 21 | pipeline = new LvePipeline("simpleShader.vert.spv", "simpleShader.frag.spv"); 22 | 23 | InitVulkan(); 24 | MainLoop(); 25 | CleanUp(); 26 | } 27 | 28 | 29 | private void InitVulkan() 30 | { 31 | vk = Vk.GetApi(); 32 | 33 | 34 | //uint extensionsCount = 0; 35 | //byte* nullBytes = null; 36 | //vk.EnumerateInstanceExtensionProperties(nullBytes, ref extensionsCount, null); 37 | 38 | //Console.WriteLine($" {extensionsCount} available extensions supported..."); 39 | } 40 | 41 | 42 | 43 | 44 | private void MainLoop() 45 | { 46 | window.Run(); 47 | } 48 | 49 | private void CleanUp() 50 | { 51 | window.Dispose(); 52 | } 53 | 54 | 55 | } -------------------------------------------------------------------------------- /Source/Chapter02Shaders/LvePipeline.cs: -------------------------------------------------------------------------------- 1 |  2 | using System.Reflection; 3 | 4 | namespace Chapter02Shaders; 5 | 6 | public class LvePipeline 7 | { 8 | public LvePipeline(string vertPath, string fragPath) 9 | { 10 | createGraphicsPipeline(vertPath, fragPath); 11 | } 12 | 13 | 14 | private void createGraphicsPipeline(string vertPath, string fragPath) 15 | { 16 | var vertSource = getShaderBytes(vertPath); 17 | var fragSource = getShaderBytes(fragPath); 18 | 19 | Console.WriteLine($"shader bytes are {vertSource.Length} and {fragSource.Length}"); 20 | 21 | } 22 | 23 | private static byte[] getShaderBytes(string filename) 24 | { 25 | //foreach (var item in assembly.GetManifestResourceNames()) 26 | //{ 27 | // Console.WriteLine($"{item}"); 28 | //} 29 | //var resourceName = $"Chapter02Shaders.{filename.Replace('/', '.')}"; 30 | var assembly = Assembly.GetExecutingAssembly(); 31 | var resourceName = assembly.GetManifestResourceNames().FirstOrDefault(s => s.EndsWith(filename)); 32 | if (resourceName is null) throw new ApplicationException($"*** No shader file found with name {filename}\n*** Check that resourceName and try again! Did you forget to set glsl file to Embedded Resource/Do Not Copy?"); 33 | 34 | using var stream = assembly.GetManifestResourceStream(resourceName) ?? throw new ApplicationException($"*** No shader file found at {resourceName}\n*** Check that resourceName and try again! Did you forget to set glsl file to Embedded Resource/Do Not Copy?"); 35 | using var ms = new MemoryStream(); 36 | if (stream is null) return Array.Empty(); 37 | stream.CopyTo(ms); 38 | return ms.ToArray(); 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Source/Chapter02Shaders/LveWindow.cs: -------------------------------------------------------------------------------- 1 | using Silk.NET.Maths; 2 | using Silk.NET.Windowing; 3 | 4 | namespace Chapter02Shaders; 5 | 6 | public class LveWindow: IDisposable 7 | { 8 | private string windowName = ""; 9 | private int width = 800; 10 | private int height = 600; 11 | private IWindow window = null!; 12 | 13 | public LveWindow(int w, int h, string name) 14 | { 15 | width = w; 16 | height = h; 17 | windowName = name; 18 | 19 | initWindow(); 20 | } 21 | 22 | private void initWindow() 23 | { 24 | //Create a window. 25 | var options = WindowOptions.DefaultVulkan with 26 | { 27 | Size = new Vector2D(width, height), 28 | Title = windowName 29 | }; 30 | 31 | window = Window.Create(options); 32 | window.Initialize(); 33 | 34 | if (window.VkSurface is null) 35 | { 36 | throw new Exception("Windowing platform doesn't support Vulkan."); 37 | } 38 | 39 | } 40 | 41 | public void Run() 42 | { 43 | window.Run(); 44 | } 45 | 46 | public void Dispose() 47 | { 48 | window.Dispose(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Source/Chapter02Shaders/Program02.cs: -------------------------------------------------------------------------------- 1 | using Chapter02Shaders; 2 | 3 | 4 | var app = new FirstApp(); 5 | 6 | try 7 | { 8 | app.Run(); 9 | 10 | } 11 | catch (Exception ex) 12 | { 13 | Console.WriteLine($"Error!\n{ex.Message}"); 14 | throw; 15 | } 16 | 17 | 18 | -------------------------------------------------------------------------------- /Source/Chapter02Shaders/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | 4 | layout(location = 0) out vec4 outColor; 5 | 6 | void main() { 7 | outColor = vec4(1.0, 0.0, 0.0, 1.0); 8 | } -------------------------------------------------------------------------------- /Source/Chapter02Shaders/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter02Shaders/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter02Shaders/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_KHR_vulkan_glsl:enable 3 | 4 | vec2 positions[3] = vec2[] ( 5 | vec2(0.0, -0.5), 6 | vec2(0.5, 0.5), 7 | vec2(-0.5, 0.5) 8 | ); 9 | 10 | void main() { 11 | gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0); 12 | } 13 | -------------------------------------------------------------------------------- /Source/Chapter02Shaders/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter02Shaders/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter03PipelineSetup/FirstApp.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter03PipelineSetup; 2 | 3 | public class FirstApp 4 | { 5 | private const int WIDTH = 800; 6 | private const int HEIGHT = 600; 7 | 8 | 9 | private Vk vk = null!; 10 | 11 | private LveWindow window = null!; 12 | private LveDevice device = null!; 13 | private LvePipeline pipeline = null!; 14 | 15 | 16 | 17 | public void Run() 18 | { 19 | log.RestartTimer(); 20 | log.d("app run", "starting Run"); 21 | 22 | vk = Vk.GetApi(); 23 | log.d("app run", "got vk"); 24 | 25 | window = new LveWindow(WIDTH, HEIGHT, "MyApp"); 26 | log.d("app run", "got window"); 27 | 28 | device = new LveDevice(vk, window); 29 | log.d("app run", "got device"); 30 | 31 | pipeline = new LvePipeline( 32 | vk, device, 33 | "simpleShader.vert.spv", "simpleShader.frag.spv", 34 | LvePipeline.DefaultPipelineConfigInfo(WIDTH, HEIGHT) 35 | ); 36 | log.d("app run", "got pipeline"); 37 | 38 | MainLoop(); 39 | CleanUp(); 40 | } 41 | 42 | 43 | 44 | private void MainLoop() 45 | { 46 | window.Run(); 47 | } 48 | 49 | private void CleanUp() 50 | { 51 | window.Dispose(); 52 | } 53 | 54 | 55 | } -------------------------------------------------------------------------------- /Source/Chapter03PipelineSetup/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | //global using Silk.NET.Vulkan.Extensions.ImGui; 19 | global using Silk.NET.Windowing; 20 | //global using Silk.NET.Input.Extensions; 21 | 22 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 23 | global using Buffer = Silk.NET.Vulkan.Buffer; 24 | global using Image = Silk.NET.Vulkan.Image; 25 | 26 | namespace Chapter03PipelineSetup; 27 | 28 | -------------------------------------------------------------------------------- /Source/Chapter03PipelineSetup/LveWindow.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter03PipelineSetup; 2 | 3 | public class LveWindow: IDisposable 4 | { 5 | private string windowName = ""; 6 | private int width = 800; 7 | private int height = 600; 8 | private IWindow window = null!; 9 | 10 | public IVkSurface VkSurface => window.VkSurface ?? throw new ApplicationException("VkSurface is null!"); 11 | 12 | public LveWindow(int w, int h, string name) 13 | { 14 | width = w; 15 | height = h; 16 | windowName = name; 17 | 18 | initWindow(); 19 | } 20 | 21 | private void initWindow() 22 | { 23 | //Create a window. 24 | var options = WindowOptions.DefaultVulkan with 25 | { 26 | Size = new Vector2D(width, height), 27 | Title = windowName 28 | }; 29 | 30 | window = Window.Create(options); 31 | window.Initialize(); 32 | 33 | if (window.VkSurface is null) 34 | { 35 | throw new Exception("Windowing platform doesn't support Vulkan."); 36 | } 37 | 38 | } 39 | 40 | //public unsafe void CreateWindowSurface(Instance instance, out SurfaceKHR surface) 41 | //{ 42 | // if (window.VkSurface is null) throw new ApplicationException("In CreateWindowSurface, window.VkSurface is null!"); 43 | 44 | // surface = window.VkSurface.Create(instance.ToHandle(), null).ToSurface(); 45 | 46 | //} 47 | public void Run() 48 | { 49 | window.Run(); 50 | } 51 | 52 | public void Dispose() 53 | { 54 | window.Dispose(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Source/Chapter03PipelineSetup/Program03.cs: -------------------------------------------------------------------------------- 1 | using Chapter03PipelineSetup; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter03PipelineSetup/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | 4 | layout(location = 0) out vec4 outColor; 5 | 6 | void main() { 7 | outColor = vec4(1.0, 0.0, 0.0, 1.0); 8 | } -------------------------------------------------------------------------------- /Source/Chapter03PipelineSetup/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter03PipelineSetup/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter03PipelineSetup/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_KHR_vulkan_glsl:enable 3 | 4 | vec2 positions[3] = vec2[] ( 5 | vec2(0.0, -0.5), 6 | vec2(0.5, 0.5), 7 | vec2(-0.5, 0.5) 8 | ); 9 | 10 | void main() { 11 | gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0); 12 | } 13 | -------------------------------------------------------------------------------- /Source/Chapter03PipelineSetup/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter03PipelineSetup/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter04PipelineStages/FirstApp.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter04PipelineStages; 2 | 3 | public class FirstApp 4 | { 5 | private const int WIDTH = 800; 6 | private const int HEIGHT = 600; 7 | 8 | 9 | private Vk vk = null!; 10 | 11 | private LveWindow window = null!; 12 | private LveDevice device = null!; 13 | private LvePipeline pipeline = null!; 14 | 15 | 16 | 17 | public void Run() 18 | { 19 | log.RestartTimer(); 20 | log.d("app run", "starting Run"); 21 | 22 | vk = Vk.GetApi(); 23 | log.d("app run", "got vk"); 24 | 25 | window = new LveWindow(WIDTH, HEIGHT, "MyApp"); 26 | log.d("app run", "got window"); 27 | 28 | device = new LveDevice(vk, window); 29 | log.d("app run", "got device"); 30 | 31 | pipeline = new LvePipeline( 32 | vk, device, 33 | "simpleShader.vert.spv", "simpleShader.frag.spv", 34 | LvePipeline.DefaultPipelineConfigInfo(WIDTH, HEIGHT) 35 | ); 36 | log.d("app run", "got pipeline"); 37 | 38 | MainLoop(); 39 | CleanUp(); 40 | } 41 | 42 | 43 | 44 | private void MainLoop() 45 | { 46 | window.Run(); 47 | } 48 | 49 | private void CleanUp() 50 | { 51 | window.Dispose(); 52 | } 53 | 54 | 55 | } -------------------------------------------------------------------------------- /Source/Chapter04PipelineStages/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | //global using Silk.NET.Vulkan.Extensions.ImGui; 19 | global using Silk.NET.Windowing; 20 | //global using Silk.NET.Input.Extensions; 21 | 22 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 23 | global using Buffer = Silk.NET.Vulkan.Buffer; 24 | global using Image = Silk.NET.Vulkan.Image; 25 | 26 | 27 | namespace Chapter04PipelineStages; 28 | 29 | -------------------------------------------------------------------------------- /Source/Chapter04PipelineStages/LveWindow.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter04PipelineStages; 2 | 3 | public class LveWindow: IDisposable 4 | { 5 | private string windowName = ""; 6 | private int width = 800; 7 | private int height = 600; 8 | private IWindow window = null!; 9 | 10 | public IVkSurface VkSurface => window.VkSurface ?? throw new ApplicationException("VkSurface is null!"); 11 | 12 | public LveWindow(int w, int h, string name) 13 | { 14 | width = w; 15 | height = h; 16 | windowName = name; 17 | 18 | initWindow(); 19 | } 20 | 21 | private void initWindow() 22 | { 23 | //Create a window. 24 | var options = WindowOptions.DefaultVulkan with 25 | { 26 | Size = new Vector2D(width, height), 27 | Title = windowName 28 | }; 29 | 30 | window = Window.Create(options); 31 | window.Initialize(); 32 | 33 | if (window.VkSurface is null) 34 | { 35 | throw new Exception("Windowing platform doesn't support Vulkan."); 36 | } 37 | 38 | } 39 | 40 | //public unsafe void CreateWindowSurface(Instance instance, out SurfaceKHR surface) 41 | //{ 42 | // if (window.VkSurface is null) throw new ApplicationException("In CreateWindowSurface, window.VkSurface is null!"); 43 | 44 | // surface = window.VkSurface.Create(instance.ToHandle(), null).ToSurface(); 45 | 46 | //} 47 | public void Run() 48 | { 49 | window.Run(); 50 | } 51 | 52 | public void Dispose() 53 | { 54 | window.Dispose(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Source/Chapter04PipelineStages/Program04.cs: -------------------------------------------------------------------------------- 1 | using Chapter04PipelineStages; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter04PipelineStages/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | 4 | layout(location = 0) out vec4 outColor; 5 | 6 | void main() { 7 | outColor = vec4(1.0, 0.0, 0.0, 1.0); 8 | } -------------------------------------------------------------------------------- /Source/Chapter04PipelineStages/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter04PipelineStages/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter04PipelineStages/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_KHR_vulkan_glsl:enable 3 | 4 | vec2 positions[3] = vec2[] ( 5 | vec2(0.0, -0.5), 6 | vec2(0.5, 0.5), 7 | vec2(-0.5, 0.5) 8 | ); 9 | 10 | void main() { 11 | gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0); 12 | } 13 | -------------------------------------------------------------------------------- /Source/Chapter04PipelineStages/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter04PipelineStages/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter05SwapChain/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | //global using Silk.NET.Vulkan.Extensions.ImGui; 19 | global using Silk.NET.Windowing; 20 | //global using Silk.NET.Input.Extensions; 21 | 22 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 23 | global using Buffer = Silk.NET.Vulkan.Buffer; 24 | global using Image = Silk.NET.Vulkan.Image; 25 | global using Device = Silk.NET.Vulkan.Device; 26 | 27 | 28 | 29 | namespace Chapter05SwapChain; 30 | 31 | -------------------------------------------------------------------------------- /Source/Chapter05SwapChain/LveWindow.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter05SwapChain; 2 | 3 | public class LveWindow: IDisposable 4 | { 5 | private string windowName = ""; 6 | private int width = 800; 7 | private int height = 600; 8 | private IWindow window = null!; 9 | public IWindow GlfwWindow => window; 10 | 11 | public IVkSurface VkSurface => window.VkSurface ?? throw new ApplicationException("VkSurface is null!"); 12 | 13 | public LveWindow(int w, int h, string name) 14 | { 15 | width = w; 16 | height = h; 17 | windowName = name; 18 | 19 | initWindow(); 20 | } 21 | 22 | private void initWindow() 23 | { 24 | //Create a window. 25 | var options = WindowOptions.DefaultVulkan with 26 | { 27 | Size = new Vector2D(width, height), 28 | Title = windowName 29 | }; 30 | 31 | window = Window.Create(options); 32 | window.Initialize(); 33 | 34 | if (window.VkSurface is null) 35 | { 36 | throw new Exception("Windowing platform doesn't support Vulkan."); 37 | } 38 | 39 | } 40 | 41 | public Extent2D GetExtent() 42 | { 43 | return new((uint)width, (uint)height); 44 | } 45 | 46 | //public unsafe void CreateWindowSurface(Instance instance, out SurfaceKHR surface) 47 | //{ 48 | // if (window.VkSurface is null) throw new ApplicationException("In CreateWindowSurface, window.VkSurface is null!"); 49 | 50 | // surface = window.VkSurface.Create(instance.ToHandle(), null).ToSurface(); 51 | 52 | //} 53 | public void Run() 54 | { 55 | window.Run(); 56 | } 57 | 58 | public void Dispose() 59 | { 60 | window.Dispose(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Source/Chapter05SwapChain/Program05.cs: -------------------------------------------------------------------------------- 1 | using Chapter05SwapChain; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter05SwapChain/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | 4 | layout(location = 0) out vec4 outColor; 5 | 6 | void main() { 7 | outColor = vec4(1.0, 0.0, 0.0, 1.0); 8 | } -------------------------------------------------------------------------------- /Source/Chapter05SwapChain/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter05SwapChain/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter05SwapChain/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_KHR_vulkan_glsl:enable 3 | 4 | vec2 positions[3] = vec2[] ( 5 | vec2(0.0, -0.5), 6 | vec2(0.5, 0.5), 7 | vec2(-0.5, 0.5) 8 | ); 9 | 10 | void main() { 11 | gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0); 12 | } 13 | -------------------------------------------------------------------------------- /Source/Chapter05SwapChain/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter05SwapChain/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter06VertexBuffers/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | //global using Silk.NET.Vulkan.Extensions.ImGui; 19 | global using Silk.NET.Windowing; 20 | //global using Silk.NET.Input.Extensions; 21 | 22 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 23 | global using Buffer = Silk.NET.Vulkan.Buffer; 24 | global using Image = Silk.NET.Vulkan.Image; 25 | global using Device = Silk.NET.Vulkan.Device; 26 | 27 | 28 | 29 | namespace Chapter06VertexBuffers; 30 | 31 | -------------------------------------------------------------------------------- /Source/Chapter06VertexBuffers/LveWindow.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter06VertexBuffers; 2 | 3 | public class LveWindow: IDisposable 4 | { 5 | private string windowName = ""; 6 | private int width = 800; 7 | private int height = 600; 8 | private IWindow window = null!; 9 | public IWindow GlfwWindow => window; 10 | 11 | public IVkSurface VkSurface => window.VkSurface ?? throw new ApplicationException("VkSurface is null!"); 12 | 13 | public LveWindow(int w, int h, string name) 14 | { 15 | width = w; 16 | height = h; 17 | windowName = name; 18 | 19 | initWindow(); 20 | } 21 | 22 | private void initWindow() 23 | { 24 | //Create a window. 25 | var options = WindowOptions.DefaultVulkan with 26 | { 27 | Size = new Vector2D(width, height), 28 | Title = windowName 29 | }; 30 | 31 | window = Window.Create(options); 32 | window.Initialize(); 33 | 34 | if (window.VkSurface is null) 35 | { 36 | throw new Exception("Windowing platform doesn't support Vulkan."); 37 | } 38 | 39 | } 40 | 41 | public Extent2D GetExtent() 42 | { 43 | return new((uint)width, (uint)height); 44 | } 45 | 46 | //public unsafe void CreateWindowSurface(Instance instance, out SurfaceKHR surface) 47 | //{ 48 | // if (window.VkSurface is null) throw new ApplicationException("In CreateWindowSurface, window.VkSurface is null!"); 49 | 50 | // surface = window.VkSurface.Create(instance.ToHandle(), null).ToSurface(); 51 | 52 | //} 53 | public void Run() 54 | { 55 | window.Run(); 56 | } 57 | 58 | public void Dispose() 59 | { 60 | window.Dispose(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Source/Chapter06VertexBuffers/Program06.cs: -------------------------------------------------------------------------------- 1 | using Chapter06VertexBuffers; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter06VertexBuffers/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | 4 | layout(location = 0) out vec4 outColor; 5 | 6 | void main() { 7 | outColor = vec4(1.0, 0.0, 0.0, 1.0); 8 | } -------------------------------------------------------------------------------- /Source/Chapter06VertexBuffers/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter06VertexBuffers/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter06VertexBuffers/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_KHR_vulkan_glsl:enable 3 | 4 | layout(location = 0) in vec2 position; 5 | 6 | void main() { 7 | gl_Position = vec4(position, 0.0, 1.0); 8 | } 9 | -------------------------------------------------------------------------------- /Source/Chapter06VertexBuffers/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter06VertexBuffers/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter07FragmentInterpolation/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | //global using Silk.NET.Vulkan.Extensions.ImGui; 19 | global using Silk.NET.Windowing; 20 | //global using Silk.NET.Input.Extensions; 21 | 22 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 23 | global using Buffer = Silk.NET.Vulkan.Buffer; 24 | global using Image = Silk.NET.Vulkan.Image; 25 | global using Device = Silk.NET.Vulkan.Device; 26 | 27 | 28 | 29 | namespace Chapter07FragmentInterpolation; 30 | 31 | -------------------------------------------------------------------------------- /Source/Chapter07FragmentInterpolation/LveWindow.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter07FragmentInterpolation; 2 | 3 | public class LveWindow: IDisposable 4 | { 5 | private string windowName = ""; 6 | private int width = 800; 7 | private int height = 600; 8 | private IWindow window = null!; 9 | public IWindow GlfwWindow => window; 10 | 11 | public IVkSurface VkSurface => window.VkSurface ?? throw new ApplicationException("VkSurface is null!"); 12 | 13 | public LveWindow(int w, int h, string name) 14 | { 15 | width = w; 16 | height = h; 17 | windowName = name; 18 | 19 | initWindow(); 20 | } 21 | 22 | private void initWindow() 23 | { 24 | //Create a window. 25 | var options = WindowOptions.DefaultVulkan with 26 | { 27 | Size = new Vector2D(width, height), 28 | Title = windowName 29 | }; 30 | 31 | window = Window.Create(options); 32 | window.Initialize(); 33 | 34 | if (window.VkSurface is null) 35 | { 36 | throw new Exception("Windowing platform doesn't support Vulkan."); 37 | } 38 | 39 | } 40 | 41 | public Extent2D GetExtent() 42 | { 43 | return new((uint)width, (uint)height); 44 | } 45 | 46 | //public unsafe void CreateWindowSurface(Instance instance, out SurfaceKHR surface) 47 | //{ 48 | // if (window.VkSurface is null) throw new ApplicationException("In CreateWindowSurface, window.VkSurface is null!"); 49 | 50 | // surface = window.VkSurface.Create(instance.ToHandle(), null).ToSurface(); 51 | 52 | //} 53 | public void Run() 54 | { 55 | window.Run(); 56 | } 57 | 58 | public void Dispose() 59 | { 60 | window.Dispose(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Source/Chapter07FragmentInterpolation/Program07.cs: -------------------------------------------------------------------------------- 1 | using Chapter07FragmentInterpolation; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter07FragmentInterpolation/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | layout(location = 0) out vec4 outColor; 5 | 6 | void main() { 7 | outColor = vec4(fragColor, 1.0); 8 | } -------------------------------------------------------------------------------- /Source/Chapter07FragmentInterpolation/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter07FragmentInterpolation/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter07FragmentInterpolation/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_KHR_vulkan_glsl:enable 3 | 4 | layout(location = 0) in vec2 position; 5 | layout(location = 1) in vec3 color; 6 | 7 | layout(location = 0) out vec3 fragColor; 8 | 9 | void main() { 10 | gl_Position = vec4(position, 0.0, 1.0); 11 | fragColor = color; 12 | } 13 | -------------------------------------------------------------------------------- /Source/Chapter07FragmentInterpolation/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter07FragmentInterpolation/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter08DynamicViewports/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | //global using Silk.NET.Vulkan.Extensions.ImGui; 19 | global using Silk.NET.Windowing; 20 | //global using Silk.NET.Input.Extensions; 21 | 22 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 23 | global using Buffer = Silk.NET.Vulkan.Buffer; 24 | global using Image = Silk.NET.Vulkan.Image; 25 | global using Device = Silk.NET.Vulkan.Device; 26 | 27 | 28 | 29 | namespace Chapter08DynamicViewports; 30 | 31 | -------------------------------------------------------------------------------- /Source/Chapter08DynamicViewports/Program08.cs: -------------------------------------------------------------------------------- 1 | using Chapter08DynamicViewports; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter08DynamicViewports/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | layout(location = 0) out vec4 outColor; 5 | 6 | void main() { 7 | outColor = vec4(fragColor, 1.0); 8 | } -------------------------------------------------------------------------------- /Source/Chapter08DynamicViewports/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter08DynamicViewports/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter08DynamicViewports/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_KHR_vulkan_glsl:enable 3 | 4 | layout(location = 0) in vec2 position; 5 | layout(location = 1) in vec3 color; 6 | 7 | layout(location = 0) out vec3 fragColor; 8 | 9 | void main() { 10 | gl_Position = vec4(position, 0.0, 1.0); 11 | fragColor = color; 12 | } 13 | -------------------------------------------------------------------------------- /Source/Chapter08DynamicViewports/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter08DynamicViewports/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter09PushConstants/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | //global using Silk.NET.Vulkan.Extensions.ImGui; 19 | global using Silk.NET.Windowing; 20 | //global using Silk.NET.Input.Extensions; 21 | 22 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 23 | global using Buffer = Silk.NET.Vulkan.Buffer; 24 | global using Image = Silk.NET.Vulkan.Image; 25 | global using Device = Silk.NET.Vulkan.Device; 26 | 27 | 28 | 29 | namespace Chapter09PushConstants; 30 | 31 | -------------------------------------------------------------------------------- /Source/Chapter09PushConstants/Program09.cs: -------------------------------------------------------------------------------- 1 | using Chapter09PushConstants; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter09PushConstants/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) out vec4 outColor; 4 | 5 | layout(push_constant) uniform Push 6 | { 7 | vec4 offset; 8 | vec4 color; 9 | } push; 10 | 11 | 12 | 13 | void main() { 14 | outColor = vec4(push.color.xyz, 1.0); 15 | } -------------------------------------------------------------------------------- /Source/Chapter09PushConstants/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter09PushConstants/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter09PushConstants/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec2 position; 4 | layout(location = 1) in vec3 color; 5 | 6 | layout(push_constant) uniform Push 7 | { 8 | vec4 offset; 9 | vec4 color; 10 | } push; 11 | 12 | 13 | void main() { 14 | gl_Position = vec4(position + push.offset.xy, 0.0, 1.0); 15 | } 16 | 17 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Chapter09PushConstants/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter09PushConstants/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter10TwoDTransformations/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | //global using Silk.NET.Vulkan.Extensions.ImGui; 19 | global using Silk.NET.Windowing; 20 | //global using Silk.NET.Input.Extensions; 21 | 22 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 23 | global using Buffer = Silk.NET.Vulkan.Buffer; 24 | global using Image = Silk.NET.Vulkan.Image; 25 | global using Device = Silk.NET.Vulkan.Device; 26 | 27 | 28 | 29 | namespace Chapter10TwoDTransformations; 30 | 31 | -------------------------------------------------------------------------------- /Source/Chapter10TwoDTransformations/LveGameObject.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Chapter10TwoDTransformations; 3 | 4 | public class LveGameObject 5 | { 6 | static uint currentId = 0; 7 | 8 | // Id prop 9 | private uint id = 0; 10 | public uint Id => id; 11 | 12 | // other props 13 | private LveModel model = null!; 14 | public LveModel Model { get => model; set => model = value; } 15 | 16 | private Vector4 color = new(1.0f); 17 | public Vector4 Color { get => color; set => color = value; } 18 | 19 | 20 | private Transform2dComponent transform2d; 21 | public Transform2dComponent Transform2d { get => transform2d; set => transform2d = value; } 22 | 23 | 24 | public struct Transform2dComponent 25 | { 26 | public Vector2 Translation; 27 | public float Rotation; 28 | public Vector2 Scale; 29 | 30 | public Transform2dComponent() 31 | { 32 | Translation = Vector2.Zero; 33 | Rotation = 0f; 34 | Scale = Vector2.One; 35 | } 36 | 37 | 38 | public Matrix2X2 Mat2() 39 | { 40 | //var ret = Matrix2X2.Identity; 41 | float s = MathF.Sin(Rotation); 42 | float c = MathF.Cos(Rotation); 43 | Matrix2X2 rotMatrix = new(c, s, -s, c); 44 | 45 | Matrix2X2 scaleMatrix = new(Scale.X, 0.0f, 0.0f, Scale.Y); 46 | // Silk.Net maths must be backwards from tutorial 47 | return scaleMatrix * rotMatrix; 48 | } 49 | } 50 | 51 | 52 | public static LveGameObject CreateGameObject() 53 | { 54 | currentId++; 55 | return new LveGameObject(currentId); 56 | } 57 | 58 | private LveGameObject(uint id) 59 | { 60 | this.id = id; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Source/Chapter10TwoDTransformations/Program10.cs: -------------------------------------------------------------------------------- 1 | using Chapter10TwoDTransformations; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter10TwoDTransformations/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) out vec4 outColor; 4 | 5 | layout(push_constant) uniform Push 6 | { 7 | mat2 transform; 8 | vec4 offset; 9 | vec4 color; 10 | } push; 11 | 12 | 13 | 14 | void main() { 15 | outColor = vec4(push.color.xyz, 1.0); 16 | } -------------------------------------------------------------------------------- /Source/Chapter10TwoDTransformations/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter10TwoDTransformations/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter10TwoDTransformations/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec2 position; 4 | layout(location = 1) in vec3 color; 5 | 6 | layout(push_constant) uniform Push 7 | { 8 | mat2 transform; 9 | vec4 offset; 10 | vec4 color; 11 | } push; 12 | 13 | 14 | void main() { 15 | gl_Position = vec4(push.transform * position + push.offset.xy, 0.0, 1.0); 16 | } 17 | 18 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Chapter10TwoDTransformations/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter10TwoDTransformations/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter11RendererSystems/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | //global using Silk.NET.Vulkan.Extensions.ImGui; 19 | global using Silk.NET.Windowing; 20 | //global using Silk.NET.Input.Extensions; 21 | 22 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 23 | global using Buffer = Silk.NET.Vulkan.Buffer; 24 | global using Image = Silk.NET.Vulkan.Image; 25 | global using Device = Silk.NET.Vulkan.Device; 26 | 27 | 28 | 29 | namespace Chapter11RendererSystems; 30 | 31 | -------------------------------------------------------------------------------- /Source/Chapter11RendererSystems/LveGameObject.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Chapter11RendererSystems; 3 | 4 | public class LveGameObject 5 | { 6 | static uint currentId = 0; 7 | 8 | // Id prop 9 | private uint id = 0; 10 | public uint Id => id; 11 | 12 | // other props 13 | private LveModel model = null!; 14 | public LveModel Model { get => model; set => model = value; } 15 | 16 | private Vector4 color = new(1.0f); 17 | public Vector4 Color { get => color; set => color = value; } 18 | 19 | 20 | private Transform2dComponent transform2d; 21 | public Transform2dComponent Transform2d { get => transform2d; set => transform2d = value; } 22 | 23 | 24 | public struct Transform2dComponent 25 | { 26 | public Vector2 Translation; 27 | public float Rotation; 28 | public Vector2 Scale; 29 | 30 | public Transform2dComponent() 31 | { 32 | Translation = Vector2.Zero; 33 | Rotation = 0f; 34 | Scale = Vector2.One; 35 | } 36 | 37 | 38 | public Matrix2X2 Mat2() 39 | { 40 | //var ret = Matrix2X2.Identity; 41 | float s = MathF.Sin(Rotation); 42 | float c = MathF.Cos(Rotation); 43 | Matrix2X2 rotMatrix = new(c, s, -s, c); 44 | 45 | Matrix2X2 scaleMatrix = new(Scale.X, 0.0f, 0.0f, Scale.Y); 46 | // Silk.Net maths must be backwards from tutorial 47 | return scaleMatrix * rotMatrix; 48 | } 49 | } 50 | 51 | 52 | public static LveGameObject CreateGameObject() 53 | { 54 | currentId++; 55 | return new LveGameObject(currentId); 56 | } 57 | 58 | private LveGameObject(uint id) 59 | { 60 | this.id = id; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /Source/Chapter11RendererSystems/Program11.cs: -------------------------------------------------------------------------------- 1 | using Chapter11RendererSystems; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter11RendererSystems/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) out vec4 outColor; 4 | 5 | layout(push_constant) uniform Push 6 | { 7 | mat2 transform; 8 | vec4 offset; 9 | vec4 color; 10 | } push; 11 | 12 | 13 | 14 | void main() { 15 | outColor = vec4(push.color.xyz, 1.0); 16 | } -------------------------------------------------------------------------------- /Source/Chapter11RendererSystems/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter11RendererSystems/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter11RendererSystems/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec2 position; 4 | layout(location = 1) in vec3 color; 5 | 6 | layout(push_constant) uniform Push 7 | { 8 | mat2 transform; 9 | vec4 offset; 10 | vec4 color; 11 | } push; 12 | 13 | 14 | void main() { 15 | gl_Position = vec4(push.transform * position + push.offset.xy, 0.0, 1.0); 16 | } 17 | 18 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Chapter11RendererSystems/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter11RendererSystems/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter12EulerHomogeneousCoords/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | //global using Silk.NET.Vulkan.Extensions.ImGui; 19 | global using Silk.NET.Windowing; 20 | //global using Silk.NET.Input.Extensions; 21 | 22 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 23 | global using Buffer = Silk.NET.Vulkan.Buffer; 24 | global using Image = Silk.NET.Vulkan.Image; 25 | global using Device = Silk.NET.Vulkan.Device; 26 | 27 | 28 | 29 | namespace Chapter12EulerHomogeneousCoords; 30 | 31 | -------------------------------------------------------------------------------- /Source/Chapter12EulerHomogeneousCoords/Program12.cs: -------------------------------------------------------------------------------- 1 | using Chapter12EulerHomogeneousCoords; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter12EulerHomogeneousCoords/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | 5 | layout(location = 0) out vec4 outColor; 6 | 7 | layout(push_constant) uniform Push 8 | { 9 | mat4 transform; 10 | vec4 color; 11 | } push; 12 | 13 | 14 | 15 | void main() { 16 | outColor = vec4(fragColor, 1.0); 17 | } -------------------------------------------------------------------------------- /Source/Chapter12EulerHomogeneousCoords/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter12EulerHomogeneousCoords/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter12EulerHomogeneousCoords/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 position; 4 | layout(location = 1) in vec3 color; 5 | 6 | layout(location = 0) out vec3 fragColor; 7 | 8 | layout(push_constant) uniform Push 9 | { 10 | mat4 transform; 11 | vec4 color; 12 | } push; 13 | 14 | 15 | void main() { 16 | //gl_Position = vec4(push.transform * position + push.offset.xy, 0.0, 1.0); 17 | gl_Position = push.transform * vec4(position.xyz, 1.0); 18 | fragColor = color; 19 | } 20 | 21 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Chapter12EulerHomogeneousCoords/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter12EulerHomogeneousCoords/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter13ProjectionMatrices/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | //global using Silk.NET.Vulkan.Extensions.ImGui; 19 | global using Silk.NET.Windowing; 20 | //global using Silk.NET.Input.Extensions; 21 | 22 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 23 | global using Buffer = Silk.NET.Vulkan.Buffer; 24 | global using Image = Silk.NET.Vulkan.Image; 25 | global using Device = Silk.NET.Vulkan.Device; 26 | 27 | 28 | 29 | namespace Chapter13ProjectionMatrices; 30 | 31 | -------------------------------------------------------------------------------- /Source/Chapter13ProjectionMatrices/LveCamera.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter13ProjectionMatrices; 2 | 3 | public class LveCamera 4 | { 5 | 6 | private Matrix4x4 projectionMatrix = Matrix4x4.Identity; 7 | public Matrix4x4 GetProjection() => projectionMatrix; 8 | 9 | public LveCamera() 10 | { 11 | 12 | } 13 | 14 | public void SetOrthographicProjection(float left, float right, float top, float bottom, float near, float far) 15 | { 16 | projectionMatrix = Matrix4x4.Identity with 17 | { 18 | M11 = 2.0f / (right - left), 19 | M22 = 2.0f / (bottom - top), 20 | M33 = 1.0f / (far - near), 21 | M41 = -(right + left) / (right - left), 22 | M42 = -(bottom + top) / (bottom - top), 23 | M43 = -near / (far - near), 24 | }; 25 | } 26 | 27 | public void SetPerspectiveProjection(float fovy, float aspect, float near, float far) 28 | { 29 | Debug.Assert(MathF.Abs(aspect - float.Epsilon) > 0.0f); 30 | float tanHalfFovy = MathF.Tan(fovy / 2.0f); 31 | projectionMatrix = new() 32 | { 33 | M11 = 1.0f / (aspect * tanHalfFovy), 34 | M22 = 1.0f / tanHalfFovy, 35 | M33 = far / (far - near), 36 | M34 = 1.0f, 37 | M43 = -(far * near) / (far - near) 38 | }; 39 | } 40 | 41 | 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Source/Chapter13ProjectionMatrices/Program13.cs: -------------------------------------------------------------------------------- 1 | using Chapter13ProjectionMatrices; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter13ProjectionMatrices/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | 5 | layout(location = 0) out vec4 outColor; 6 | 7 | layout(push_constant) uniform Push 8 | { 9 | mat4 transform; 10 | vec4 color; 11 | } push; 12 | 13 | 14 | 15 | void main() { 16 | outColor = vec4(fragColor, 1.0); 17 | } -------------------------------------------------------------------------------- /Source/Chapter13ProjectionMatrices/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter13ProjectionMatrices/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter13ProjectionMatrices/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 position; 4 | layout(location = 1) in vec3 color; 5 | 6 | layout(location = 0) out vec3 fragColor; 7 | 8 | layout(push_constant) uniform Push 9 | { 10 | mat4 transform; 11 | vec4 color; 12 | } push; 13 | 14 | 15 | void main() { 16 | //gl_Position = vec4(push.transform * position + push.offset.xy, 0.0, 1.0); 17 | gl_Position = push.transform * vec4(position.xyz, 1.0); 18 | fragColor = color; 19 | } 20 | 21 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Chapter13ProjectionMatrices/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter13ProjectionMatrices/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter14CameraViewTransform/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | //global using Silk.NET.Vulkan.Extensions.ImGui; 19 | global using Silk.NET.Windowing; 20 | //global using Silk.NET.Input.Extensions; 21 | 22 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 23 | global using Buffer = Silk.NET.Vulkan.Buffer; 24 | global using Image = Silk.NET.Vulkan.Image; 25 | global using Device = Silk.NET.Vulkan.Device; 26 | 27 | 28 | 29 | namespace Chapter14CameraViewTransform; 30 | 31 | -------------------------------------------------------------------------------- /Source/Chapter14CameraViewTransform/Program14.cs: -------------------------------------------------------------------------------- 1 | using Chapter14CameraViewTransform; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter14CameraViewTransform/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | 5 | layout(location = 0) out vec4 outColor; 6 | 7 | layout(push_constant) uniform Push 8 | { 9 | mat4 transform; 10 | vec4 color; 11 | } push; 12 | 13 | 14 | 15 | void main() { 16 | outColor = vec4(fragColor, 1.0); 17 | } -------------------------------------------------------------------------------- /Source/Chapter14CameraViewTransform/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter14CameraViewTransform/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter14CameraViewTransform/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 position; 4 | layout(location = 1) in vec3 color; 5 | 6 | layout(location = 0) out vec3 fragColor; 7 | 8 | layout(push_constant) uniform Push 9 | { 10 | mat4 transform; 11 | vec4 color; 12 | } push; 13 | 14 | 15 | void main() { 16 | //gl_Position = vec4(push.transform * position + push.offset.xy, 0.0, 1.0); 17 | gl_Position = push.transform * vec4(position.xyz, 1.0); 18 | fragColor = color; 19 | } 20 | 21 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Chapter14CameraViewTransform/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter14CameraViewTransform/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter15GameLoopUserInput/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | //global using Silk.NET.Vulkan.Extensions.ImGui; 19 | global using Silk.NET.Windowing; 20 | //global using Silk.NET.Input.Extensions; 21 | 22 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 23 | global using Buffer = Silk.NET.Vulkan.Buffer; 24 | global using Image = Silk.NET.Vulkan.Image; 25 | global using Device = Silk.NET.Vulkan.Device; 26 | 27 | 28 | 29 | namespace Chapter15GameLoopUserInput; 30 | 31 | -------------------------------------------------------------------------------- /Source/Chapter15GameLoopUserInput/Program15.cs: -------------------------------------------------------------------------------- 1 | using Chapter15GameLoopUserInput; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter15GameLoopUserInput/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | 5 | layout(location = 0) out vec4 outColor; 6 | 7 | layout(push_constant) uniform Push 8 | { 9 | mat4 transform; 10 | vec4 color; 11 | } push; 12 | 13 | 14 | 15 | void main() { 16 | outColor = vec4(fragColor, 1.0); 17 | } -------------------------------------------------------------------------------- /Source/Chapter15GameLoopUserInput/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter15GameLoopUserInput/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter15GameLoopUserInput/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 position; 4 | layout(location = 1) in vec3 color; 5 | 6 | layout(location = 0) out vec3 fragColor; 7 | 8 | layout(push_constant) uniform Push 9 | { 10 | mat4 transform; 11 | vec4 color; 12 | } push; 13 | 14 | 15 | void main() { 16 | //gl_Position = vec4(push.transform * position + push.offset.xy, 0.0, 1.0); 17 | gl_Position = push.transform * vec4(position.xyz, 1.0); 18 | fragColor = color; 19 | } 20 | 21 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Chapter15GameLoopUserInput/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter15GameLoopUserInput/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter16IndexStagingBuffers/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | //global using Silk.NET.Vulkan.Extensions.ImGui; 19 | global using Silk.NET.Windowing; 20 | //global using Silk.NET.Input.Extensions; 21 | 22 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 23 | global using Buffer = Silk.NET.Vulkan.Buffer; 24 | global using Image = Silk.NET.Vulkan.Image; 25 | global using Device = Silk.NET.Vulkan.Device; 26 | 27 | 28 | 29 | namespace Chapter16IndexStagingBuffers; 30 | 31 | -------------------------------------------------------------------------------- /Source/Chapter16IndexStagingBuffers/Model/Builder.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Chapter16IndexStagingBuffers; 3 | 4 | public struct Builder 5 | { 6 | public Vertex[] Vertices; 7 | public uint[] Indices; 8 | 9 | public Builder() 10 | { 11 | Vertices = Array.Empty(); 12 | Indices = Array.Empty(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Source/Chapter16IndexStagingBuffers/Model/Vertex.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Chapter16IndexStagingBuffers; 3 | 4 | public struct Vertex 5 | { 6 | public Vector3 Position; 7 | public Vector3 Color; 8 | 9 | public Vertex(Vector3 pos, Vector3 color) 10 | { 11 | Position = pos; 12 | Color = color; 13 | } 14 | 15 | 16 | public static VertexInputBindingDescription[] GetBindingDescriptions() 17 | { 18 | var bindingDescriptions = new[] 19 | { 20 | new VertexInputBindingDescription() 21 | { 22 | Binding = 0, 23 | Stride = (uint)Unsafe.SizeOf(), 24 | InputRate = VertexInputRate.Vertex, 25 | } 26 | }; 27 | 28 | return bindingDescriptions; 29 | } 30 | 31 | public static VertexInputAttributeDescription[] GetAttributeDescriptions() 32 | { 33 | var attributeDescriptions = new[] 34 | { 35 | new VertexInputAttributeDescription() 36 | { 37 | Binding = 0, 38 | Location = 0, 39 | Format = Format.R32G32B32Sfloat, 40 | Offset = (uint)Marshal.OffsetOf(nameof(Position)), 41 | }, 42 | new VertexInputAttributeDescription() 43 | { 44 | Binding = 0, 45 | Location = 1, 46 | Format = Format.R32G32B32Sfloat, 47 | Offset = (uint)Marshal.OffsetOf(nameof(Color)), 48 | } 49 | }; 50 | 51 | return attributeDescriptions; 52 | 53 | } 54 | } -------------------------------------------------------------------------------- /Source/Chapter16IndexStagingBuffers/Program16.cs: -------------------------------------------------------------------------------- 1 | using Chapter16IndexStagingBuffers; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter16IndexStagingBuffers/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | 5 | layout(location = 0) out vec4 outColor; 6 | 7 | layout(push_constant) uniform Push 8 | { 9 | mat4 transform; 10 | vec4 color; 11 | } push; 12 | 13 | 14 | 15 | void main() { 16 | outColor = vec4(fragColor, 1.0); 17 | } -------------------------------------------------------------------------------- /Source/Chapter16IndexStagingBuffers/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter16IndexStagingBuffers/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter16IndexStagingBuffers/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 position; 4 | layout(location = 1) in vec3 color; 5 | 6 | layout(location = 0) out vec3 fragColor; 7 | 8 | layout(push_constant) uniform Push 9 | { 10 | mat4 transform; 11 | vec4 color; 12 | } push; 13 | 14 | 15 | void main() { 16 | //gl_Position = vec4(push.transform * position + push.offset.xy, 0.0, 1.0); 17 | gl_Position = push.transform * vec4(position.xyz, 1.0); 18 | fragColor = color; 19 | } 20 | 21 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Chapter16IndexStagingBuffers/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter16IndexStagingBuffers/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter17Loading3DModels/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | global using Silk.NET.Windowing; 19 | 20 | //global using Silk.NET.Vulkan.Extensions.ImGui; 21 | //global using Silk.NET.Input.Extensions; 22 | 23 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 24 | global using Buffer = Silk.NET.Vulkan.Buffer; 25 | global using Image = Silk.NET.Vulkan.Image; 26 | global using Device = Silk.NET.Vulkan.Device; 27 | 28 | 29 | 30 | namespace Chapter17Loading3DModels; 31 | 32 | -------------------------------------------------------------------------------- /Source/Chapter17Loading3DModels/Model/ColorHelper.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter17Loading3DModels; 2 | public static class Color3 3 | { 4 | public static Vector3 White => new(1f, 1f, 1f); 5 | public static Vector3 Black => new(0f, 0f, 0f); 6 | 7 | // my colors 8 | public static Vector3 RoughGreen => new(0f, 0.6f, 0f); 9 | 10 | // main 11 | public static Vector3 Red => new(1f, 0f, 0f); 12 | public static Vector3 Green => new(0f, 1f, 0f); 13 | public static Vector3 Blue => new(0f, 0f, 1f); 14 | 15 | // mix1 16 | public static Vector3 Yellow => new(1f, 1f, 0f); 17 | public static Vector3 Magenta => new(1f, 0f, 1f); 18 | public static Vector3 Cyan => new(0f, 1f, 1f); 19 | public static Vector3 Gray => new(0.5f, 0.5f, 0.5f); 20 | 21 | // others 22 | public static Vector3 Pink => new(1f, 0.75f, 0.8f); 23 | public static Vector3 Orange => new(1f, 0.65f, 0f); 24 | public static Vector3 Purple => new(0.6f, 0.4f, 0.8f); 25 | public static Vector3 Brown => new(0.6f, 0.4f, 0.2f); 26 | public static Vector3 Beige => new(0.96f, 0.96f, 0.86f); 27 | public static Vector3 Olive => new(0.5f, 0.5f, 0f); 28 | public static Vector3 Maroon => new(0.5f, 0f, 0f); 29 | public static Vector3 Navy => new(0f, 0f, 0.5f); 30 | public static Vector3 Teal => new(0f, 0.5f, 0.5f); 31 | 32 | // others2 33 | public static Vector3 Lime => new(0.75f, 1f, 0f); 34 | public static Vector3 Turquoise => new(0.25f, 0.88f, 0.82f); 35 | public static Vector3 Lavender => new(0.9f, 0.9f, 0.98f); 36 | public static Vector3 Coral => new(1f, 0.5f, 0.31f); 37 | public static Vector3 Salmon => new(0.98f, 0.5f, 0.45f); 38 | public static Vector3 Peach => new(1f, 0.8f, 0.64f); 39 | public static Vector3 Mint => new(0.6f, 1f, 0.8f); 40 | public static Vector3 PowderBlue => new(0.69f, 0.88f, 0.9f); 41 | public static Vector3 LightGray => new(0.83f, 0.83f, 0.83f); 42 | 43 | public static Vector3 WhiteSmoke => new(0.96f, 0.96f, 0.96f); 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /Source/Chapter17Loading3DModels/Model/Vertex.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Chapter17Loading3DModels; 3 | 4 | public struct Vertex 5 | { 6 | public Vector3 Position; 7 | public Vector3 Color; 8 | public Vector3 Normal; 9 | public Vector2 UV; 10 | 11 | public Vertex(Vector3 pos, Vector3 color) 12 | { 13 | Position = pos; 14 | Color = color; 15 | } 16 | 17 | 18 | 19 | public static VertexInputBindingDescription[] GetBindingDescriptions() 20 | { 21 | var bindingDescriptions = new[] 22 | { 23 | new VertexInputBindingDescription() 24 | { 25 | Binding = 0, 26 | Stride = (uint)Unsafe.SizeOf(), 27 | InputRate = VertexInputRate.Vertex, 28 | } 29 | }; 30 | 31 | return bindingDescriptions; 32 | } 33 | 34 | public static VertexInputAttributeDescription[] GetAttributeDescriptions() 35 | { 36 | var attributeDescriptions = new[] 37 | { 38 | new VertexInputAttributeDescription() 39 | { 40 | Binding = 0, 41 | Location = 0, 42 | Format = Format.R32G32B32Sfloat, 43 | Offset = (uint)Marshal.OffsetOf(nameof(Position)), 44 | }, 45 | new VertexInputAttributeDescription() 46 | { 47 | Binding = 0, 48 | Location = 1, 49 | Format = Format.R32G32B32Sfloat, 50 | Offset = (uint)Marshal.OffsetOf(nameof(Color)), 51 | } 52 | }; 53 | 54 | return attributeDescriptions; 55 | 56 | } 57 | } -------------------------------------------------------------------------------- /Source/Chapter17Loading3DModels/Program17.cs: -------------------------------------------------------------------------------- 1 | using Chapter17Loading3DModels; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter17Loading3DModels/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | 5 | layout(location = 0) out vec4 outColor; 6 | 7 | layout(push_constant) uniform Push 8 | { 9 | mat4 transform; 10 | vec4 color; 11 | } push; 12 | 13 | 14 | 15 | void main() { 16 | outColor = vec4(fragColor, 1.0); 17 | } -------------------------------------------------------------------------------- /Source/Chapter17Loading3DModels/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter17Loading3DModels/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter17Loading3DModels/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 position; 4 | layout(location = 1) in vec3 color; 5 | 6 | layout(location = 0) out vec3 fragColor; 7 | 8 | layout(push_constant) uniform Push 9 | { 10 | mat4 transform; 11 | vec4 color; 12 | } push; 13 | 14 | 15 | void main() { 16 | //gl_Position = vec4(push.transform * position + push.offset.xy, 0.0, 1.0); 17 | gl_Position = push.transform * vec4(position.xyz, 1.0); 18 | fragColor = color; 19 | } 20 | 21 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Chapter17Loading3DModels/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter17Loading3DModels/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter18DiffuseShading/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | global using Silk.NET.Windowing; 19 | 20 | //global using Silk.NET.Vulkan.Extensions.ImGui; 21 | //global using Silk.NET.Input.Extensions; 22 | 23 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 24 | global using Buffer = Silk.NET.Vulkan.Buffer; 25 | global using Image = Silk.NET.Vulkan.Image; 26 | global using Device = Silk.NET.Vulkan.Device; 27 | 28 | 29 | 30 | namespace Chapter18DiffuseShading; 31 | 32 | -------------------------------------------------------------------------------- /Source/Chapter18DiffuseShading/Model/ColorHelper.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter18DiffuseShading; 2 | public static class Color3 3 | { 4 | public static Vector3 White => new(1f, 1f, 1f); 5 | public static Vector3 Black => new(0f, 0f, 0f); 6 | 7 | // my colors 8 | public static Vector3 RoughGreen => new(0f, 0.6f, 0f); 9 | 10 | // main 11 | public static Vector3 Red => new(1f, 0f, 0f); 12 | public static Vector3 Green => new(0f, 1f, 0f); 13 | public static Vector3 Blue => new(0f, 0f, 1f); 14 | 15 | // mix1 16 | public static Vector3 Yellow => new(1f, 1f, 0f); 17 | public static Vector3 Magenta => new(1f, 0f, 1f); 18 | public static Vector3 Cyan => new(0f, 1f, 1f); 19 | public static Vector3 Gray => new(0.5f, 0.5f, 0.5f); 20 | 21 | // others 22 | public static Vector3 Pink => new(1f, 0.75f, 0.8f); 23 | public static Vector3 Orange => new(1f, 0.65f, 0f); 24 | public static Vector3 Purple => new(0.6f, 0.4f, 0.8f); 25 | public static Vector3 Brown => new(0.6f, 0.4f, 0.2f); 26 | public static Vector3 Beige => new(0.96f, 0.96f, 0.86f); 27 | public static Vector3 Olive => new(0.5f, 0.5f, 0f); 28 | public static Vector3 Maroon => new(0.5f, 0f, 0f); 29 | public static Vector3 Navy => new(0f, 0f, 0.5f); 30 | public static Vector3 Teal => new(0f, 0.5f, 0.5f); 31 | 32 | // others2 33 | public static Vector3 Lime => new(0.75f, 1f, 0f); 34 | public static Vector3 Turquoise => new(0.25f, 0.88f, 0.82f); 35 | public static Vector3 Lavender => new(0.9f, 0.9f, 0.98f); 36 | public static Vector3 Coral => new(1f, 0.5f, 0.31f); 37 | public static Vector3 Salmon => new(0.98f, 0.5f, 0.45f); 38 | public static Vector3 Peach => new(1f, 0.8f, 0.64f); 39 | public static Vector3 Mint => new(0.6f, 1f, 0.8f); 40 | public static Vector3 PowderBlue => new(0.69f, 0.88f, 0.9f); 41 | public static Vector3 LightGray => new(0.83f, 0.83f, 0.83f); 42 | 43 | public static Vector3 WhiteSmoke => new(0.96f, 0.96f, 0.96f); 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /Source/Chapter18DiffuseShading/Program18.cs: -------------------------------------------------------------------------------- 1 | using Chapter18DiffuseShading; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter18DiffuseShading/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | 5 | layout(location = 0) out vec4 outColor; 6 | 7 | layout(push_constant) uniform Push 8 | { 9 | mat4 transform; 10 | mat4 normalMatrix; 11 | } push; 12 | 13 | 14 | 15 | void main() { 16 | outColor = vec4(fragColor, 1.0); 17 | } -------------------------------------------------------------------------------- /Source/Chapter18DiffuseShading/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter18DiffuseShading/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter18DiffuseShading/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 position; 4 | layout(location = 1) in vec3 color; 5 | layout(location = 2) in vec3 normal; 6 | layout(location = 3) in vec2 uv; 7 | 8 | layout(location = 0) out vec3 fragColor; 9 | 10 | layout(push_constant) uniform Push 11 | { 12 | mat4 transform; 13 | mat4 normalMatrix; 14 | } push; 15 | 16 | 17 | const vec3 DIRECTION_TO_LIGHT = normalize(vec3(1.0, -3.0, -1.0)); 18 | const float AMBIENT = 0.02; 19 | 20 | void main() { 21 | gl_Position = push.transform * vec4(position.xyz, 1.0); 22 | 23 | // temporary: this is only correct in certain situations! 24 | // only works correctly if scale is uniform! 25 | //vec3 normalWorldSpace = normalize(mat3(push.modelMatrix) * normal); 26 | 27 | // use this to get the right result, but then this is more computationaly expensive 28 | //mat3 normalMatrix = transpose(inverse(mat3(push.modelMatrix))); 29 | //vec3 normalWorldSpace = normalize(normalMatrix * normal); 30 | 31 | 32 | // precompute normalMatrix and send it in with the attributes 33 | vec3 normalWorldSpace = normalize(mat3(push.normalMatrix) * normal); 34 | 35 | float lightIntensity = AMBIENT + max(dot(normalWorldSpace, DIRECTION_TO_LIGHT), 0); 36 | 37 | fragColor = lightIntensity * color; 38 | } 39 | 40 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Chapter18DiffuseShading/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter18DiffuseShading/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter19UniformBuffers/FrameInfo.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Chapter19UniformBuffers; 3 | 4 | public class FrameInfo 5 | { 6 | public int FrameIndex { get; set; } 7 | public float FrameTime { get; set; } 8 | public CommandBuffer CommandBuffer { get; init; } 9 | 10 | public OrthographicCamera Camera { get; init; } = null!; 11 | 12 | 13 | } 14 | 15 | 16 | -------------------------------------------------------------------------------- /Source/Chapter19UniformBuffers/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | global using Silk.NET.Windowing; 19 | 20 | //global using Silk.NET.Vulkan.Extensions.ImGui; 21 | //global using Silk.NET.Input.Extensions; 22 | 23 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 24 | global using Buffer = Silk.NET.Vulkan.Buffer; 25 | global using Image = Silk.NET.Vulkan.Image; 26 | global using Device = Silk.NET.Vulkan.Device; 27 | 28 | 29 | 30 | namespace Chapter19UniformBuffers; 31 | 32 | -------------------------------------------------------------------------------- /Source/Chapter19UniformBuffers/Model/ColorHelper.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter19UniformBuffers; 2 | public static class Color3 3 | { 4 | public static Vector3 White => new(1f, 1f, 1f); 5 | public static Vector3 Black => new(0f, 0f, 0f); 6 | 7 | // my colors 8 | public static Vector3 RoughGreen => new(0f, 0.6f, 0f); 9 | 10 | // main 11 | public static Vector3 Red => new(1f, 0f, 0f); 12 | public static Vector3 Green => new(0f, 1f, 0f); 13 | public static Vector3 Blue => new(0f, 0f, 1f); 14 | 15 | // mix1 16 | public static Vector3 Yellow => new(1f, 1f, 0f); 17 | public static Vector3 Magenta => new(1f, 0f, 1f); 18 | public static Vector3 Cyan => new(0f, 1f, 1f); 19 | public static Vector3 Gray => new(0.5f, 0.5f, 0.5f); 20 | 21 | // others 22 | public static Vector3 Pink => new(1f, 0.75f, 0.8f); 23 | public static Vector3 Orange => new(1f, 0.65f, 0f); 24 | public static Vector3 Purple => new(0.6f, 0.4f, 0.8f); 25 | public static Vector3 Brown => new(0.6f, 0.4f, 0.2f); 26 | public static Vector3 Beige => new(0.96f, 0.96f, 0.86f); 27 | public static Vector3 Olive => new(0.5f, 0.5f, 0f); 28 | public static Vector3 Maroon => new(0.5f, 0f, 0f); 29 | public static Vector3 Navy => new(0f, 0f, 0.5f); 30 | public static Vector3 Teal => new(0f, 0.5f, 0.5f); 31 | 32 | // others2 33 | public static Vector3 Lime => new(0.75f, 1f, 0f); 34 | public static Vector3 Turquoise => new(0.25f, 0.88f, 0.82f); 35 | public static Vector3 Lavender => new(0.9f, 0.9f, 0.98f); 36 | public static Vector3 Coral => new(1f, 0.5f, 0.31f); 37 | public static Vector3 Salmon => new(0.98f, 0.5f, 0.45f); 38 | public static Vector3 Peach => new(1f, 0.8f, 0.64f); 39 | public static Vector3 Mint => new(0.6f, 1f, 0.8f); 40 | public static Vector3 PowderBlue => new(0.69f, 0.88f, 0.9f); 41 | public static Vector3 LightGray => new(0.83f, 0.83f, 0.83f); 42 | 43 | public static Vector3 WhiteSmoke => new(0.96f, 0.96f, 0.96f); 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /Source/Chapter19UniformBuffers/Model/GlobalUbo.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter19UniformBuffers; 2 | 3 | public struct GlobalUbo 4 | { 5 | public Matrix4x4 ProjectionView; 6 | public Vector3 LightDirection; 7 | 8 | public GlobalUbo() 9 | { 10 | ProjectionView = Matrix4x4.Identity; 11 | LightDirection = new(1f, -3f, 1f); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Source/Chapter19UniformBuffers/Program19.cs: -------------------------------------------------------------------------------- 1 | using Chapter19UniformBuffers; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter19UniformBuffers/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | 5 | layout(location = 0) out vec4 outColor; 6 | 7 | layout(push_constant) uniform Push 8 | { 9 | mat4 transform; 10 | mat4 normalMatrix; 11 | } push; 12 | 13 | 14 | 15 | void main() { 16 | outColor = vec4(fragColor, 1.0); 17 | } -------------------------------------------------------------------------------- /Source/Chapter19UniformBuffers/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter19UniformBuffers/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter19UniformBuffers/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 position; 4 | layout(location = 1) in vec3 color; 5 | layout(location = 2) in vec3 normal; 6 | layout(location = 3) in vec2 uv; 7 | 8 | layout(location = 0) out vec3 fragColor; 9 | 10 | layout(push_constant) uniform Push 11 | { 12 | mat4 transform; 13 | mat4 normalMatrix; 14 | } push; 15 | 16 | 17 | const vec3 DIRECTION_TO_LIGHT = normalize(vec3(1.0, -3.0, -1.0)); 18 | const float AMBIENT = 0.02; 19 | 20 | void main() { 21 | gl_Position = push.transform * vec4(position.xyz, 1.0); 22 | 23 | // temporary: this is only correct in certain situations! 24 | // only works correctly if scale is uniform! 25 | //vec3 normalWorldSpace = normalize(mat3(push.modelMatrix) * normal); 26 | 27 | // use this to get the right result, but then this is more computationaly expensive 28 | //mat3 normalMatrix = transpose(inverse(mat3(push.modelMatrix))); 29 | //vec3 normalWorldSpace = normalize(normalMatrix * normal); 30 | 31 | 32 | // precompute normalMatrix and send it in with the attributes 33 | vec3 normalWorldSpace = normalize(mat3(push.normalMatrix) * normal); 34 | 35 | float lightIntensity = AMBIENT + max(dot(normalWorldSpace, DIRECTION_TO_LIGHT), 0); 36 | 37 | fragColor = lightIntensity * color; 38 | } 39 | 40 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Chapter19UniformBuffers/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter19UniformBuffers/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter19zNoCoherentAomSizeFix/FrameInfo.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Chapter19zNoCoherentAomSizeFix; 3 | 4 | public class FrameInfo 5 | { 6 | public int FrameIndex { get; set; } 7 | public float FrameTime { get; set; } 8 | public CommandBuffer CommandBuffer { get; init; } 9 | 10 | public OrthographicCamera Camera { get; init; } = null!; 11 | 12 | 13 | } 14 | 15 | 16 | -------------------------------------------------------------------------------- /Source/Chapter19zNoCoherentAomSizeFix/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | global using Silk.NET.Windowing; 19 | 20 | //global using Silk.NET.Vulkan.Extensions.ImGui; 21 | //global using Silk.NET.Input.Extensions; 22 | 23 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 24 | global using Buffer = Silk.NET.Vulkan.Buffer; 25 | global using Image = Silk.NET.Vulkan.Image; 26 | global using Device = Silk.NET.Vulkan.Device; 27 | 28 | 29 | 30 | namespace Chapter19zNoCoherentAomSizeFix; 31 | 32 | -------------------------------------------------------------------------------- /Source/Chapter19zNoCoherentAomSizeFix/Model/GlobalUbo.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter19zNoCoherentAomSizeFix; 2 | 3 | public struct GlobalUbo 4 | { 5 | public Matrix4x4 ProjectionView; 6 | public Vector3 LightDirection; 7 | 8 | public GlobalUbo() 9 | { 10 | ProjectionView = Matrix4x4.Identity; 11 | LightDirection = new(1f, -3f, 1f); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Source/Chapter19zNoCoherentAomSizeFix/Program19z.cs: -------------------------------------------------------------------------------- 1 | using Chapter19zNoCoherentAomSizeFix; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter19zNoCoherentAomSizeFix/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | 5 | layout(location = 0) out vec4 outColor; 6 | 7 | layout(push_constant) uniform Push 8 | { 9 | mat4 transform; 10 | mat4 normalMatrix; 11 | } push; 12 | 13 | 14 | 15 | void main() { 16 | outColor = vec4(fragColor, 1.0); 17 | } -------------------------------------------------------------------------------- /Source/Chapter19zNoCoherentAomSizeFix/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter19zNoCoherentAomSizeFix/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter19zNoCoherentAomSizeFix/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 position; 4 | layout(location = 1) in vec3 color; 5 | layout(location = 2) in vec3 normal; 6 | layout(location = 3) in vec2 uv; 7 | 8 | layout(location = 0) out vec3 fragColor; 9 | 10 | layout(push_constant) uniform Push 11 | { 12 | mat4 transform; 13 | mat4 normalMatrix; 14 | } push; 15 | 16 | 17 | const vec3 DIRECTION_TO_LIGHT = normalize(vec3(1.0, -3.0, -1.0)); 18 | const float AMBIENT = 0.02; 19 | 20 | void main() { 21 | gl_Position = push.transform * vec4(position.xyz, 1.0); 22 | 23 | // temporary: this is only correct in certain situations! 24 | // only works correctly if scale is uniform! 25 | //vec3 normalWorldSpace = normalize(mat3(push.modelMatrix) * normal); 26 | 27 | // use this to get the right result, but then this is more computationaly expensive 28 | //mat3 normalMatrix = transpose(inverse(mat3(push.modelMatrix))); 29 | //vec3 normalWorldSpace = normalize(normalMatrix * normal); 30 | 31 | 32 | // precompute normalMatrix and send it in with the attributes 33 | vec3 normalWorldSpace = normalize(mat3(push.normalMatrix) * normal); 34 | 35 | float lightIntensity = AMBIENT + max(dot(normalWorldSpace, DIRECTION_TO_LIGHT), 0); 36 | 37 | fragColor = lightIntensity * color; 38 | } 39 | 40 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Chapter19zNoCoherentAomSizeFix/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter19zNoCoherentAomSizeFix/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter20DescriptorSets/FrameInfo.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Chapter20DescriptorSets; 3 | 4 | public struct FrameInfo 5 | { 6 | public int FrameIndex;// { get; set; } 7 | public float FrameTime;// { get; set; } 8 | public CommandBuffer CommandBuffer;// { get; init; } 9 | public OrthographicCamera Camera;// { get; init; } = null!; 10 | public DescriptorSet GlobalDescriptorSet;// { get; init; } 11 | } 12 | 13 | 14 | -------------------------------------------------------------------------------- /Source/Chapter20DescriptorSets/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | global using Silk.NET.Windowing; 19 | 20 | //global using Silk.NET.Vulkan.Extensions.ImGui; 21 | //global using Silk.NET.Input.Extensions; 22 | 23 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 24 | global using Buffer = Silk.NET.Vulkan.Buffer; 25 | global using Image = Silk.NET.Vulkan.Image; 26 | global using Device = Silk.NET.Vulkan.Device; 27 | 28 | 29 | 30 | namespace Chapter20DescriptorSets; 31 | 32 | -------------------------------------------------------------------------------- /Source/Chapter20DescriptorSets/Model/ColorHelper.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter20DescriptorSets; 2 | public static class Color3 3 | { 4 | public static Vector3 White => new(1f, 1f, 1f); 5 | public static Vector3 Black => new(0f, 0f, 0f); 6 | 7 | // my colors 8 | public static Vector3 RoughGreen => new(0f, 0.6f, 0f); 9 | 10 | // main 11 | public static Vector3 Red => new(1f, 0f, 0f); 12 | public static Vector3 Green => new(0f, 1f, 0f); 13 | public static Vector3 Blue => new(0f, 0f, 1f); 14 | 15 | // mix1 16 | public static Vector3 Yellow => new(1f, 1f, 0f); 17 | public static Vector3 Magenta => new(1f, 0f, 1f); 18 | public static Vector3 Cyan => new(0f, 1f, 1f); 19 | public static Vector3 Gray => new(0.5f, 0.5f, 0.5f); 20 | 21 | // others 22 | public static Vector3 Pink => new(1f, 0.75f, 0.8f); 23 | public static Vector3 Orange => new(1f, 0.65f, 0f); 24 | public static Vector3 Purple => new(0.6f, 0.4f, 0.8f); 25 | public static Vector3 Brown => new(0.6f, 0.4f, 0.2f); 26 | public static Vector3 Beige => new(0.96f, 0.96f, 0.86f); 27 | public static Vector3 Olive => new(0.5f, 0.5f, 0f); 28 | public static Vector3 Maroon => new(0.5f, 0f, 0f); 29 | public static Vector3 Navy => new(0f, 0f, 0.5f); 30 | public static Vector3 Teal => new(0f, 0.5f, 0.5f); 31 | 32 | // others2 33 | public static Vector3 Lime => new(0.75f, 1f, 0f); 34 | public static Vector3 Turquoise => new(0.25f, 0.88f, 0.82f); 35 | public static Vector3 Lavender => new(0.9f, 0.9f, 0.98f); 36 | public static Vector3 Coral => new(1f, 0.5f, 0.31f); 37 | public static Vector3 Salmon => new(0.98f, 0.5f, 0.45f); 38 | public static Vector3 Peach => new(1f, 0.8f, 0.64f); 39 | public static Vector3 Mint => new(0.6f, 1f, 0.8f); 40 | public static Vector3 PowderBlue => new(0.69f, 0.88f, 0.9f); 41 | public static Vector3 LightGray => new(0.83f, 0.83f, 0.83f); 42 | 43 | public static Vector3 WhiteSmoke => new(0.96f, 0.96f, 0.96f); 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /Source/Chapter20DescriptorSets/Model/GlobalUbo.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter20DescriptorSets; 2 | 3 | public struct GlobalUbo 4 | { 5 | public Matrix4x4 ProjectionView; 6 | public Vector4 LightDirection; 7 | 8 | public GlobalUbo() 9 | { 10 | ProjectionView = Matrix4x4.Identity; 11 | LightDirection = new(1f, -3f, 1f, 0f); 12 | } 13 | 14 | public static uint SizeOf() => (uint)Unsafe.SizeOf(); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Source/Chapter20DescriptorSets/Program20.cs: -------------------------------------------------------------------------------- 1 | using Chapter20DescriptorSets; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter20DescriptorSets/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | 5 | layout(location = 0) out vec4 outColor; 6 | 7 | layout(push_constant) uniform Push 8 | { 9 | mat4 modelMatrix; 10 | mat4 normalMatrix; 11 | } push; 12 | 13 | 14 | 15 | void main() { 16 | outColor = vec4(fragColor, 1.0); 17 | } -------------------------------------------------------------------------------- /Source/Chapter20DescriptorSets/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter20DescriptorSets/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter20DescriptorSets/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 position; 4 | layout(location = 1) in vec3 color; 5 | layout(location = 2) in vec3 normal; 6 | layout(location = 3) in vec2 uv; 7 | 8 | layout(location = 0) out vec3 fragColor; 9 | 10 | layout(set = 0, binding = 0) uniform GlobalUbo 11 | { 12 | mat4 projectionViewMatrix; 13 | vec4 directionToLight; 14 | } ubo; 15 | 16 | layout(push_constant) uniform Push 17 | { 18 | mat4 modelMatrix; 19 | mat4 normalMatrix; 20 | } push; 21 | 22 | 23 | //const vec3 DIRECTION_TO_LIGHT = normalize(vec3(1.0, -3.0, -1.0)); 24 | const float AMBIENT = 0.02; 25 | 26 | void main() { 27 | gl_Position = ubo.projectionViewMatrix * push.modelMatrix * vec4(position.xyz, 1.0); 28 | 29 | // temporary: this is only correct in certain situations! 30 | // only works correctly if scale is uniform! 31 | //vec3 normalWorldSpace = normalize(mat3(push.modelMatrix) * normal); 32 | 33 | // use this to get the right result, but then this is more computationaly expensive 34 | //mat3 normalMatrix = transpose(inverse(mat3(push.modelMatrix))); 35 | //vec3 normalWorldSpace = normalize(normalMatrix * normal); 36 | 37 | 38 | // precompute normalMatrix and send it in with the attributes 39 | vec3 normalWorldSpace = normalize(mat3(push.normalMatrix) * normal); 40 | 41 | float lightIntensity = AMBIENT + max(dot(normalWorldSpace, ubo.directionToLight.xyz), 0); 42 | 43 | fragColor = lightIntensity * color; 44 | } 45 | 46 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Chapter20DescriptorSets/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter20DescriptorSets/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter20aDescriptorSetsNoBuilder/FrameInfo.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Chapter20aDescriptorSetsNoBuilder; 3 | 4 | public struct FrameInfo 5 | { 6 | public int FrameIndex;// { get; set; } 7 | public float FrameTime;// { get; set; } 8 | public CommandBuffer CommandBuffer;// { get; init; } 9 | public OrthographicCamera Camera;// { get; init; } = null!; 10 | public DescriptorSet GlobalDescriptorSet;// { get; init; } 11 | } 12 | 13 | 14 | -------------------------------------------------------------------------------- /Source/Chapter20aDescriptorSetsNoBuilder/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | global using Silk.NET.Windowing; 19 | 20 | //global using Silk.NET.Vulkan.Extensions.ImGui; 21 | //global using Silk.NET.Input.Extensions; 22 | 23 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 24 | global using Buffer = Silk.NET.Vulkan.Buffer; 25 | global using Image = Silk.NET.Vulkan.Image; 26 | global using Device = Silk.NET.Vulkan.Device; 27 | 28 | 29 | 30 | namespace Chapter20aDescriptorSetsNoBuilder; 31 | 32 | -------------------------------------------------------------------------------- /Source/Chapter20aDescriptorSetsNoBuilder/Model/GlobalUbo.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter20aDescriptorSetsNoBuilder; 2 | 3 | public struct GlobalUbo 4 | { 5 | public Matrix4x4 ProjectionView; 6 | public Vector4 LightDirection; 7 | 8 | public GlobalUbo() 9 | { 10 | ProjectionView = Matrix4x4.Identity; 11 | LightDirection = new(1f, -3f, 1f, 0f); 12 | } 13 | 14 | public static uint SizeOf() => (uint)Unsafe.SizeOf(); 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Source/Chapter20aDescriptorSetsNoBuilder/Program20alt.cs: -------------------------------------------------------------------------------- 1 | using Chapter20aDescriptorSetsNoBuilder; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter20aDescriptorSetsNoBuilder/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | 5 | layout(location = 0) out vec4 outColor; 6 | 7 | layout(push_constant) uniform Push 8 | { 9 | mat4 modelMatrix; 10 | mat4 normalMatrix; 11 | } push; 12 | 13 | 14 | 15 | void main() { 16 | outColor = vec4(fragColor, 1.0); 17 | } -------------------------------------------------------------------------------- /Source/Chapter20aDescriptorSetsNoBuilder/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter20aDescriptorSetsNoBuilder/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter20aDescriptorSetsNoBuilder/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 position; 4 | layout(location = 1) in vec3 color; 5 | layout(location = 2) in vec3 normal; 6 | layout(location = 3) in vec2 uv; 7 | 8 | layout(location = 0) out vec3 fragColor; 9 | 10 | layout(set = 0, binding = 0) uniform GlobalUbo 11 | { 12 | mat4 projectionViewMatrix; 13 | vec4 directionToLight; 14 | } ubo; 15 | 16 | layout(push_constant) uniform Push 17 | { 18 | mat4 modelMatrix; 19 | mat4 normalMatrix; 20 | } push; 21 | 22 | 23 | //const vec3 DIRECTION_TO_LIGHT = normalize(vec3(1.0, -3.0, -1.0)); 24 | const float AMBIENT = 0.02; 25 | 26 | void main() { 27 | gl_Position = ubo.projectionViewMatrix * push.modelMatrix * vec4(position.xyz, 1.0); 28 | 29 | // temporary: this is only correct in certain situations! 30 | // only works correctly if scale is uniform! 31 | //vec3 normalWorldSpace = normalize(mat3(push.modelMatrix) * normal); 32 | 33 | // use this to get the right result, but then this is more computationaly expensive 34 | //mat3 normalMatrix = transpose(inverse(mat3(push.modelMatrix))); 35 | //vec3 normalWorldSpace = normalize(normalMatrix * normal); 36 | 37 | 38 | // precompute normalMatrix and send it in with the attributes 39 | vec3 normalWorldSpace = normalize(mat3(push.normalMatrix) * normal); 40 | 41 | float lightIntensity = AMBIENT + max(dot(normalWorldSpace, ubo.directionToLight.xyz), 0); 42 | 43 | fragColor = lightIntensity * color; 44 | } 45 | 46 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Chapter20aDescriptorSetsNoBuilder/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter20aDescriptorSetsNoBuilder/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter21PointLights/FrameInfo.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Chapter21PointLights; 3 | 4 | public struct FrameInfo 5 | { 6 | public int FrameIndex;// { get; set; } 7 | public float FrameTime;// { get; set; } 8 | public CommandBuffer CommandBuffer;// { get; init; } 9 | public OrthographicCamera Camera;// { get; init; } = null!; 10 | public DescriptorSet GlobalDescriptorSet;// { get; init; } 11 | } 12 | 13 | 14 | -------------------------------------------------------------------------------- /Source/Chapter21PointLights/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | global using Silk.NET.Windowing; 19 | 20 | //global using Silk.NET.Vulkan.Extensions.ImGui; 21 | //global using Silk.NET.Input.Extensions; 22 | 23 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 24 | global using Buffer = Silk.NET.Vulkan.Buffer; 25 | global using Image = Silk.NET.Vulkan.Image; 26 | global using Device = Silk.NET.Vulkan.Device; 27 | 28 | 29 | 30 | namespace Chapter21PointLights; 31 | 32 | -------------------------------------------------------------------------------- /Source/Chapter21PointLights/Model/ColorHelper.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter21PointLights; 2 | public static class Color3 3 | { 4 | public static Vector3 White => new(1f, 1f, 1f); 5 | public static Vector3 Black => new(0f, 0f, 0f); 6 | 7 | // my colors 8 | public static Vector3 RoughGreen => new(0f, 0.6f, 0f); 9 | 10 | // main 11 | public static Vector3 Red => new(1f, 0f, 0f); 12 | public static Vector3 Green => new(0f, 1f, 0f); 13 | public static Vector3 Blue => new(0f, 0f, 1f); 14 | 15 | // mix1 16 | public static Vector3 Yellow => new(1f, 1f, 0f); 17 | public static Vector3 Magenta => new(1f, 0f, 1f); 18 | public static Vector3 Cyan => new(0f, 1f, 1f); 19 | public static Vector3 Gray => new(0.5f, 0.5f, 0.5f); 20 | 21 | // others 22 | public static Vector3 Pink => new(1f, 0.75f, 0.8f); 23 | public static Vector3 Orange => new(1f, 0.65f, 0f); 24 | public static Vector3 Purple => new(0.6f, 0.4f, 0.8f); 25 | public static Vector3 Brown => new(0.6f, 0.4f, 0.2f); 26 | public static Vector3 Beige => new(0.96f, 0.96f, 0.86f); 27 | public static Vector3 Olive => new(0.5f, 0.5f, 0f); 28 | public static Vector3 Maroon => new(0.5f, 0f, 0f); 29 | public static Vector3 Navy => new(0f, 0f, 0.5f); 30 | public static Vector3 Teal => new(0f, 0.5f, 0.5f); 31 | 32 | // others2 33 | public static Vector3 Lime => new(0.75f, 1f, 0f); 34 | public static Vector3 Turquoise => new(0.25f, 0.88f, 0.82f); 35 | public static Vector3 Lavender => new(0.9f, 0.9f, 0.98f); 36 | public static Vector3 Coral => new(1f, 0.5f, 0.31f); 37 | public static Vector3 Salmon => new(0.98f, 0.5f, 0.45f); 38 | public static Vector3 Peach => new(1f, 0.8f, 0.64f); 39 | public static Vector3 Mint => new(0.6f, 1f, 0.8f); 40 | public static Vector3 PowderBlue => new(0.69f, 0.88f, 0.9f); 41 | public static Vector3 LightGray => new(0.83f, 0.83f, 0.83f); 42 | 43 | public static Vector3 WhiteSmoke => new(0.96f, 0.96f, 0.96f); 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /Source/Chapter21PointLights/Model/GlobalUbo.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter21PointLights; 2 | 3 | public struct GlobalUbo 4 | { 5 | public Matrix4x4 ProjectionView; 6 | public Vector4 AmbientColor; 7 | public Vector4 LightPosition; 8 | public Vector4 LightColor; 9 | 10 | public GlobalUbo() 11 | { 12 | ProjectionView = Matrix4x4.Identity; 13 | AmbientColor = new(1f, 1f, 1f, 0.02f); 14 | LightPosition = new(-1f); 15 | LightColor = new(1f); 16 | } 17 | 18 | public static uint SizeOf() => (uint)Unsafe.SizeOf(); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Source/Chapter21PointLights/Program21.cs: -------------------------------------------------------------------------------- 1 | using Chapter21PointLights; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter21PointLights/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | 5 | layout(location = 0) out vec4 outColor; 6 | 7 | layout(push_constant) uniform Push 8 | { 9 | mat4 modelMatrix; 10 | mat4 normalMatrix; 11 | } push; 12 | 13 | 14 | 15 | void main() { 16 | outColor = vec4(fragColor, 1.0); 17 | } -------------------------------------------------------------------------------- /Source/Chapter21PointLights/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter21PointLights/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter21PointLights/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 position; 4 | layout(location = 1) in vec3 color; 5 | layout(location = 2) in vec3 normal; 6 | layout(location = 3) in vec2 uv; 7 | 8 | layout(location = 0) out vec3 fragColor; 9 | 10 | layout(set = 0, binding = 0) uniform GlobalUbo 11 | { 12 | mat4 projectionViewMatrix; 13 | vec4 ambientColor; 14 | vec4 lightPosition; 15 | vec4 lightColor; 16 | } ubo; 17 | 18 | layout(push_constant) uniform Push 19 | { 20 | mat4 modelMatrix; 21 | mat4 normalMatrix; 22 | } push; 23 | 24 | 25 | //const vec3 DIRECTION_TO_LIGHT = normalize(vec3(1.0, -3.0, -1.0)); 26 | //const float AMBIENT = 0.02; 27 | 28 | void main() { 29 | vec4 positionWorld = push.modelMatrix * vec4(position, 1.0); 30 | gl_Position = ubo.projectionViewMatrix * positionWorld; 31 | 32 | vec3 normalWorldSpace = normalize(mat3(push.normalMatrix) * normal); 33 | 34 | vec3 directionToLight = ubo.lightPosition.xyz - positionWorld.xyz; 35 | float attenuation = 1.0 / dot(directionToLight, directionToLight); // distance squared 36 | 37 | vec3 lightColor = ubo.lightColor.xyz * ubo.lightColor.w * attenuation; 38 | vec3 ambientLight = ubo.ambientColor.xyz * ubo.ambientColor.w; 39 | vec3 diffuseLight = lightColor * max(dot(normalWorldSpace, normalize(directionToLight)), 0); 40 | 41 | fragColor = (diffuseLight + ambientLight) * color; 42 | } 43 | 44 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Chapter21PointLights/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter21PointLights/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter22FragmentLighting/FrameInfo.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Chapter22FragmentLighting; 3 | 4 | public struct FrameInfo 5 | { 6 | public int FrameIndex;// { get; set; } 7 | public float FrameTime;// { get; set; } 8 | public CommandBuffer CommandBuffer;// { get; init; } 9 | public OrthographicCamera Camera;// { get; init; } = null!; 10 | public DescriptorSet GlobalDescriptorSet;// { get; init; } 11 | public Dictionary GameObjects; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /Source/Chapter22FragmentLighting/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | global using Silk.NET.Windowing; 19 | 20 | //global using Silk.NET.Vulkan.Extensions.ImGui; 21 | //global using Silk.NET.Input.Extensions; 22 | 23 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 24 | global using Buffer = Silk.NET.Vulkan.Buffer; 25 | global using Image = Silk.NET.Vulkan.Image; 26 | global using Device = Silk.NET.Vulkan.Device; 27 | 28 | 29 | 30 | namespace Chapter22FragmentLighting; 31 | 32 | -------------------------------------------------------------------------------- /Source/Chapter22FragmentLighting/Model/GlobalUbo.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter22FragmentLighting; 2 | 3 | public struct GlobalUbo 4 | { 5 | public Matrix4x4 ProjectionView; 6 | public Vector4 AmbientColor; 7 | public Vector4 LightPosition; 8 | public Vector4 LightColor; 9 | 10 | public GlobalUbo() 11 | { 12 | ProjectionView = Matrix4x4.Identity; 13 | AmbientColor = new(1f, 1f, 1f, 0.02f); 14 | LightPosition = new(-1f); 15 | LightColor = new(1f); 16 | } 17 | 18 | public static uint SizeOf() => (uint)Unsafe.SizeOf(); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Source/Chapter22FragmentLighting/Program22.cs: -------------------------------------------------------------------------------- 1 | using Chapter22FragmentLighting; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter22FragmentLighting/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | layout(location = 1) in vec3 fragPosWorld; 5 | layout(location = 2) in vec3 fragNormalWorld; 6 | 7 | layout(location = 0) out vec4 outColor; 8 | 9 | 10 | layout(set = 0, binding = 0) uniform GlobalUbo 11 | { 12 | mat4 projectionViewMatrix; 13 | vec4 ambientColor; 14 | vec4 lightPosition; 15 | vec4 lightColor; 16 | } ubo; 17 | 18 | layout(push_constant) uniform Push 19 | { 20 | mat4 modelMatrix; 21 | mat4 normalMatrix; 22 | } push; 23 | 24 | 25 | 26 | void main() { 27 | vec3 directionToLight = ubo.lightPosition.xyz - fragPosWorld; 28 | float attenuation = 1.0 / dot(directionToLight, directionToLight); // distance squared 29 | 30 | vec3 lightColor = ubo.lightColor.xyz * ubo.lightColor.w * attenuation; 31 | vec3 ambientLight = ubo.ambientColor.xyz * ubo.ambientColor.w; 32 | vec3 diffuseLight = lightColor * max(dot(normalize(fragNormalWorld), normalize(directionToLight)), 0); 33 | 34 | outColor = vec4((diffuseLight + ambientLight) * fragColor, 1.0); 35 | } -------------------------------------------------------------------------------- /Source/Chapter22FragmentLighting/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter22FragmentLighting/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter22FragmentLighting/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 position; 4 | layout(location = 1) in vec3 color; 5 | layout(location = 2) in vec3 normal; 6 | layout(location = 3) in vec2 uv; 7 | 8 | layout(location = 0) out vec3 fragColor; 9 | layout(location = 1) out vec3 fragPosWorld; 10 | layout(location = 2) out vec3 fragNormalWorld; 11 | 12 | layout(set = 0, binding = 0) uniform GlobalUbo 13 | { 14 | mat4 projectionViewMatrix; 15 | vec4 ambientColor; 16 | vec4 lightPosition; 17 | vec4 lightColor; 18 | } ubo; 19 | 20 | layout(push_constant) uniform Push 21 | { 22 | mat4 modelMatrix; 23 | mat4 normalMatrix; 24 | } push; 25 | 26 | 27 | //const vec3 DIRECTION_TO_LIGHT = normalize(vec3(1.0, -3.0, -1.0)); 28 | //const float AMBIENT = 0.02; 29 | 30 | void main() { 31 | vec4 positionWorld = push.modelMatrix * vec4(position, 1.0); 32 | gl_Position = ubo.projectionViewMatrix * positionWorld; 33 | 34 | fragNormalWorld = normalize(mat3(push.normalMatrix) * normal); 35 | fragPosWorld = positionWorld.xyz; 36 | fragColor = color; 37 | 38 | // vec3 directionToLight = ubo.lightPosition.xyz - positionWorld.xyz; 39 | // float attenuation = 1.0 / dot(directionToLight, directionToLight); // distance squared 40 | // 41 | // vec3 lightColor = ubo.lightColor.xyz * ubo.lightColor.w * attenuation; 42 | // vec3 ambientLight = ubo.ambientColor.xyz * ubo.ambientColor.w; 43 | // vec3 diffuseLight = lightColor * max(dot(normalWorldSpace, normalize(directionToLight)), 0); 44 | // 45 | // fragColor = (diffuseLight + ambientLight) * color; 46 | } 47 | 48 | 49 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Chapter22FragmentLighting/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter22FragmentLighting/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter24Billboards/FrameInfo.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Chapter24Billboards; 3 | 4 | public struct FrameInfo 5 | { 6 | public int FrameIndex;// { get; set; } 7 | public float FrameTime;// { get; set; } 8 | public CommandBuffer CommandBuffer;// { get; init; } 9 | public OrthographicCamera Camera;// { get; init; } = null!; 10 | public DescriptorSet GlobalDescriptorSet;// { get; init; } 11 | public Dictionary GameObjects; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /Source/Chapter24Billboards/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | global using Silk.NET.Windowing; 19 | 20 | //global using Silk.NET.Vulkan.Extensions.ImGui; 21 | //global using Silk.NET.Input.Extensions; 22 | 23 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 24 | global using Buffer = Silk.NET.Vulkan.Buffer; 25 | global using Image = Silk.NET.Vulkan.Image; 26 | global using Device = Silk.NET.Vulkan.Device; 27 | 28 | 29 | 30 | namespace Chapter24Billboards; 31 | 32 | -------------------------------------------------------------------------------- /Source/Chapter24Billboards/Model/ColorHelper.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter24Billboards; 2 | public static class Color3 3 | { 4 | public static Vector3 White => new(1f, 1f, 1f); 5 | public static Vector3 Black => new(0f, 0f, 0f); 6 | 7 | // my colors 8 | public static Vector3 RoughGreen => new(0f, 0.6f, 0f); 9 | 10 | // main 11 | public static Vector3 Red => new(1f, 0f, 0f); 12 | public static Vector3 Green => new(0f, 1f, 0f); 13 | public static Vector3 Blue => new(0f, 0f, 1f); 14 | 15 | // mix1 16 | public static Vector3 Yellow => new(1f, 1f, 0f); 17 | public static Vector3 Magenta => new(1f, 0f, 1f); 18 | public static Vector3 Cyan => new(0f, 1f, 1f); 19 | public static Vector3 Gray => new(0.5f, 0.5f, 0.5f); 20 | 21 | // others 22 | public static Vector3 Pink => new(1f, 0.75f, 0.8f); 23 | public static Vector3 Orange => new(1f, 0.65f, 0f); 24 | public static Vector3 Purple => new(0.6f, 0.4f, 0.8f); 25 | public static Vector3 Brown => new(0.6f, 0.4f, 0.2f); 26 | public static Vector3 Beige => new(0.96f, 0.96f, 0.86f); 27 | public static Vector3 Olive => new(0.5f, 0.5f, 0f); 28 | public static Vector3 Maroon => new(0.5f, 0f, 0f); 29 | public static Vector3 Navy => new(0f, 0f, 0.5f); 30 | public static Vector3 Teal => new(0f, 0.5f, 0.5f); 31 | 32 | // others2 33 | public static Vector3 Lime => new(0.75f, 1f, 0f); 34 | public static Vector3 Turquoise => new(0.25f, 0.88f, 0.82f); 35 | public static Vector3 Lavender => new(0.9f, 0.9f, 0.98f); 36 | public static Vector3 Coral => new(1f, 0.5f, 0.31f); 37 | public static Vector3 Salmon => new(0.98f, 0.5f, 0.45f); 38 | public static Vector3 Peach => new(1f, 0.8f, 0.64f); 39 | public static Vector3 Mint => new(0.6f, 1f, 0.8f); 40 | public static Vector3 PowderBlue => new(0.69f, 0.88f, 0.9f); 41 | public static Vector3 LightGray => new(0.83f, 0.83f, 0.83f); 42 | 43 | public static Vector3 WhiteSmoke => new(0.96f, 0.96f, 0.96f); 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /Source/Chapter24Billboards/Model/GlobalUbo.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter24Billboards; 2 | 3 | public struct GlobalUbo 4 | { 5 | public Matrix4x4 Projection; 6 | public Matrix4x4 View; 7 | public Vector4 AmbientColor; 8 | public Vector4 LightPosition; 9 | public Vector4 LightColor; 10 | 11 | public GlobalUbo() 12 | { 13 | Projection = Matrix4x4.Identity; 14 | View = Matrix4x4.Identity; 15 | AmbientColor = new(1f, 1f, 1f, 0.02f); 16 | LightPosition = new(1f, 2f, 1f, 0f); 17 | LightColor = new(1f); 18 | } 19 | 20 | public static uint SizeOf() => (uint)Unsafe.SizeOf(); 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Source/Chapter24Billboards/Program24.cs: -------------------------------------------------------------------------------- 1 | using Chapter24Billboards; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter24Billboards/Shaders/pointLight.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec2 fragOffset; 4 | layout(location = 0) out vec4 outColor; 5 | 6 | 7 | layout(set = 0, binding = 0) uniform GlobalUbo 8 | { 9 | mat4 projection; 10 | mat4 view; 11 | vec4 ambientColor; 12 | vec4 lightPosition; 13 | vec4 lightColor; 14 | } ubo; 15 | 16 | 17 | 18 | void main() { 19 | float dis = sqrt(dot(fragOffset, fragOffset)); 20 | if (dis >= 1.0) discard; 21 | outColor = vec4(ubo.lightColor.xyz, 1.0); 22 | } -------------------------------------------------------------------------------- /Source/Chapter24Billboards/Shaders/pointLight.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter24Billboards/Shaders/pointLight.frag.spv -------------------------------------------------------------------------------- /Source/Chapter24Billboards/Shaders/pointLight.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | //#extension GL_KHR_vulkan_glsl:enable 3 | 4 | 5 | const vec2 OFFSETS[6] = vec2[]( 6 | vec2(-1.0, -1.0), 7 | vec2(-1.0, 1.0), 8 | vec2(1.0, -1.0), 9 | vec2(1.0, -1.0), 10 | vec2(-1.0, 1.0), 11 | vec2(1.0, 1.0) 12 | ); 13 | 14 | layout (location = 0) out vec2 fragOffset; 15 | 16 | layout(set = 0, binding = 0) uniform GlobalUbo 17 | { 18 | mat4 projection; 19 | mat4 view; 20 | vec4 ambientColor; 21 | vec4 lightPosition; 22 | vec4 lightColor; 23 | } ubo; 24 | 25 | const float LIGHT_RADIUS = 0.06; 26 | 27 | void main() { 28 | fragOffset = OFFSETS[gl_VertexIndex]; 29 | vec3 cameraRightWorld = {ubo.view[0][0], ubo.view[1][0], ubo.view[2][0]}; 30 | vec3 cameraUpWorld = {ubo.view[0][1], ubo.view[1][1], ubo.view[2][1]}; 31 | 32 | vec3 positionWorld = ubo.lightPosition.xyz 33 | + LIGHT_RADIUS * fragOffset.x * cameraRightWorld 34 | + LIGHT_RADIUS * fragOffset.y * cameraUpWorld; 35 | 36 | gl_Position = ubo.projection * ubo.view * vec4(positionWorld, 1.0); 37 | } 38 | 39 | -------------------------------------------------------------------------------- /Source/Chapter24Billboards/Shaders/pointLight.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter24Billboards/Shaders/pointLight.vert.spv -------------------------------------------------------------------------------- /Source/Chapter24Billboards/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | layout(location = 1) in vec3 fragPosWorld; 5 | layout(location = 2) in vec3 fragNormalWorld; 6 | 7 | layout(location = 0) out vec4 outColor; 8 | 9 | 10 | layout(set = 0, binding = 0) uniform GlobalUbo 11 | { 12 | mat4 projection; 13 | mat4 view; 14 | vec4 ambientColor; 15 | vec4 lightPosition; 16 | vec4 lightColor; 17 | } ubo; 18 | 19 | layout(push_constant) uniform Push 20 | { 21 | mat4 modelMatrix; 22 | mat4 normalMatrix; 23 | } push; 24 | 25 | 26 | 27 | void main() { 28 | vec3 directionToLight = ubo.lightPosition.xyz - fragPosWorld; 29 | float attenuation = 1.0 / dot(directionToLight, directionToLight); // distance squared 30 | 31 | vec3 lightColor = ubo.lightColor.xyz * ubo.lightColor.w * attenuation; 32 | vec3 ambientLight = ubo.ambientColor.xyz * ubo.ambientColor.w; 33 | vec3 diffuseLight = lightColor * max(dot(normalize(fragNormalWorld), normalize(directionToLight)), 0); 34 | 35 | outColor = vec4((diffuseLight + ambientLight) * fragColor, 1.0); 36 | } -------------------------------------------------------------------------------- /Source/Chapter24Billboards/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter24Billboards/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter24Billboards/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 position; 4 | layout(location = 1) in vec3 color; 5 | layout(location = 2) in vec3 normal; 6 | layout(location = 3) in vec2 uv; 7 | 8 | layout(location = 0) out vec3 fragColor; 9 | layout(location = 1) out vec3 fragPosWorld; 10 | layout(location = 2) out vec3 fragNormalWorld; 11 | 12 | layout(set = 0, binding = 0) uniform GlobalUbo 13 | { 14 | mat4 projection; 15 | mat4 view; 16 | vec4 ambientColor; 17 | vec4 lightPosition; 18 | vec4 lightColor; 19 | } ubo; 20 | 21 | layout(push_constant) uniform Push 22 | { 23 | mat4 modelMatrix; 24 | mat4 normalMatrix; 25 | } push; 26 | 27 | 28 | //const vec3 DIRECTION_TO_LIGHT = normalize(vec3(1.0, -3.0, -1.0)); 29 | //const float AMBIENT = 0.02; 30 | 31 | void main() { 32 | vec4 positionWorld = push.modelMatrix * vec4(position, 1.0); 33 | gl_Position = ubo.projection * ubo.view * positionWorld; 34 | 35 | fragNormalWorld = normalize(mat3(push.normalMatrix) * normal); 36 | fragPosWorld = positionWorld.xyz; 37 | fragColor = color; 38 | 39 | // vec3 directionToLight = ubo.lightPosition.xyz - positionWorld.xyz; 40 | // float attenuation = 1.0 / dot(directionToLight, directionToLight); // distance squared 41 | // 42 | // vec3 lightColor = ubo.lightColor.xyz * ubo.lightColor.w * attenuation; 43 | // vec3 ambientLight = ubo.ambientColor.xyz * ubo.ambientColor.w; 44 | // vec3 diffuseLight = lightColor * max(dot(normalWorldSpace, normalize(directionToLight)), 0); 45 | // 46 | // fragColor = (diffuseLight + ambientLight) * color; 47 | } 48 | 49 | 50 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Chapter24Billboards/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter24Billboards/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter25MultiplePointLights/FrameInfo.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Chapter25MultiplePointLights; 3 | 4 | public struct FrameInfo 5 | { 6 | public int FrameIndex;// { get; set; } 7 | public float FrameTime;// { get; set; } 8 | public CommandBuffer CommandBuffer;// { get; init; } 9 | public OrthographicCamera Camera;// { get; init; } = null!; 10 | public DescriptorSet GlobalDescriptorSet;// { get; init; } 11 | public Dictionary GameObjects; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /Source/Chapter25MultiplePointLights/GlobalUbo.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter25MultiplePointLights; 2 | 3 | //[StructLayout(LayoutKind.Sequential)] 4 | //public struct Struct1 5 | //{ 6 | // [MarshalAs(UnmanagedType.ByValArray, SizeConst = sizeOfarray)] 7 | // private Struct2[] arrayStruct; 8 | //} 9 | 10 | //[StructLayout(LayoutKind.Sequential)] 11 | public struct GlobalUbo 12 | { 13 | public Matrix4x4 Projection; 14 | public Matrix4x4 View; 15 | public Vector4 AmbientColor; 16 | public PointLight PointLight1; 17 | public PointLight PointLight2; 18 | public PointLight PointLight3; 19 | public PointLight PointLight4; 20 | public PointLight PointLight5; 21 | public PointLight PointLight6; 22 | public int NumLights; 23 | 24 | public GlobalUbo() 25 | { 26 | Projection = Matrix4x4.Identity; 27 | View = Matrix4x4.Identity; 28 | AmbientColor = new(1f, 1f, 1f, 0.02f); 29 | } 30 | 31 | public static uint SizeOf() => (uint)Unsafe.SizeOf(); 32 | 33 | } 34 | 35 | 36 | public struct PointLight 37 | { 38 | public Vector4 Position; 39 | public Vector4 Color; 40 | } -------------------------------------------------------------------------------- /Source/Chapter25MultiplePointLights/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | global using Silk.NET.Windowing; 19 | 20 | //global using Silk.NET.Vulkan.Extensions.ImGui; 21 | //global using Silk.NET.Input.Extensions; 22 | 23 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 24 | global using Buffer = Silk.NET.Vulkan.Buffer; 25 | global using Image = Silk.NET.Vulkan.Image; 26 | global using Device = Silk.NET.Vulkan.Device; 27 | 28 | 29 | 30 | namespace Chapter25MultiplePointLights; 31 | 32 | -------------------------------------------------------------------------------- /Source/Chapter25MultiplePointLights/Model/PointLightComponent.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter25MultiplePointLights; 2 | 3 | public struct PointLightComponent 4 | { 5 | public float LightIntensity; 6 | 7 | public PointLightComponent(float intensity) 8 | { 9 | LightIntensity = intensity; 10 | } 11 | } -------------------------------------------------------------------------------- /Source/Chapter25MultiplePointLights/Program25.cs: -------------------------------------------------------------------------------- 1 | using Chapter25MultiplePointLights; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter25MultiplePointLights/Shaders/pointLight.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec2 fragOffset; 4 | layout(location = 0) out vec4 outColor; 5 | 6 | 7 | struct PointLight { 8 | vec4 position; // ignore w 9 | vec4 color; // w is intensity 10 | }; 11 | 12 | layout(set = 0, binding = 0) uniform GlobalUbo 13 | { 14 | mat4 projection; 15 | mat4 view; 16 | vec4 ambientColor; 17 | PointLight pointLight1; 18 | PointLight pointLight2; 19 | PointLight pointLight3; 20 | PointLight pointLight4; 21 | PointLight pointLight5; 22 | PointLight pointLight6; 23 | int numLights; 24 | } ubo; 25 | 26 | layout(push_constant) uniform Push 27 | { 28 | vec4 position; 29 | vec4 color; 30 | float radius; 31 | } push; 32 | 33 | const float M_PI = 3.1415926538; 34 | 35 | void main() { 36 | float dis = sqrt(dot(fragOffset, fragOffset)); 37 | if (dis >= 1.0) discard; 38 | float dis2 = dis * .9; 39 | float intensity = 1.0 - pow(dis2, 0.5); 40 | outColor = vec4(push.color.xyz * intensity, 1.0); 41 | } -------------------------------------------------------------------------------- /Source/Chapter25MultiplePointLights/Shaders/pointLight.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter25MultiplePointLights/Shaders/pointLight.frag.spv -------------------------------------------------------------------------------- /Source/Chapter25MultiplePointLights/Shaders/pointLight.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | //#extension GL_KHR_vulkan_glsl:enable 3 | 4 | 5 | const vec2 OFFSETS[6] = vec2[]( 6 | vec2(-1.0, -1.0), 7 | vec2(-1.0, 1.0), 8 | vec2(1.0, -1.0), 9 | vec2(1.0, -1.0), 10 | vec2(-1.0, 1.0), 11 | vec2(1.0, 1.0) 12 | ); 13 | 14 | layout (location = 0) out vec2 fragOffset; 15 | 16 | struct PointLight { 17 | vec4 position; // ignore w 18 | vec4 color; // w is intensity 19 | }; 20 | 21 | layout(set = 0, binding = 0) uniform GlobalUbo 22 | { 23 | mat4 projection; 24 | mat4 view; 25 | vec4 ambientColor; 26 | PointLight pointLight1; 27 | PointLight pointLight2; 28 | PointLight pointLight3; 29 | PointLight pointLight4; 30 | PointLight pointLight5; 31 | PointLight pointLight6; 32 | int numLights; 33 | } ubo; 34 | 35 | layout(push_constant) uniform Push 36 | { 37 | vec4 position; 38 | vec4 color; 39 | float radius; 40 | } push; 41 | 42 | 43 | //const float LIGHT_RADIUS = 0.06; 44 | 45 | void main() { 46 | fragOffset = OFFSETS[gl_VertexIndex]; 47 | vec3 cameraRightWorld = {ubo.view[0][0], ubo.view[1][0], ubo.view[2][0]}; 48 | vec3 cameraUpWorld = {ubo.view[0][1], ubo.view[1][1], ubo.view[2][1]}; 49 | 50 | vec3 positionWorld = push.position.xyz 51 | + push.radius * fragOffset.x * cameraRightWorld 52 | + push.radius * fragOffset.y * cameraUpWorld; 53 | 54 | gl_Position = ubo.projection * ubo.view * vec4(positionWorld, 1.0); 55 | } 56 | 57 | -------------------------------------------------------------------------------- /Source/Chapter25MultiplePointLights/Shaders/pointLight.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter25MultiplePointLights/Shaders/pointLight.vert.spv -------------------------------------------------------------------------------- /Source/Chapter25MultiplePointLights/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | layout(location = 1) in vec3 fragPosWorld; 5 | layout(location = 2) in vec3 fragNormalWorld; 6 | 7 | layout(location = 0) out vec4 outColor; 8 | 9 | 10 | struct PointLight { 11 | vec4 position; // ignore w 12 | vec4 color; // w is intensity 13 | }; 14 | 15 | layout(set = 0, binding = 0) uniform GlobalUbo 16 | { 17 | mat4 projection; 18 | mat4 view; 19 | vec4 ambientColor; 20 | PointLight pointLight1; 21 | PointLight pointLight2; 22 | PointLight pointLight3; 23 | PointLight pointLight4; 24 | PointLight pointLight5; 25 | PointLight pointLight6; 26 | int numLights; 27 | } ubo; 28 | 29 | layout(push_constant) uniform Push 30 | { 31 | mat4 modelMatrix; 32 | mat4 normalMatrix; 33 | } push; 34 | 35 | 36 | 37 | void main() { 38 | vec3 diffuseLight = ubo.ambientColor.xyz * ubo.ambientColor.w; 39 | vec3 surfaceNormal = normalize(fragNormalWorld); 40 | 41 | for (int i = 0; i < ubo.numLights; i++) 42 | { 43 | PointLight light = ubo.pointLight1; 44 | if (i == 1) light = ubo.pointLight2; 45 | else if (i == 2) light = ubo.pointLight3; 46 | else if (i == 3) light = ubo.pointLight4; 47 | else if (i == 4) light = ubo.pointLight5; 48 | else if (i == 5) light = ubo.pointLight6; 49 | 50 | //PointLight light = ubo.pointLight1; 51 | vec3 directionToLight = light.position.xyz - fragPosWorld; 52 | float attenuation = 1.0 / dot(directionToLight, directionToLight); // distance squared 53 | float cosAngIncidence = max(dot(surfaceNormal, normalize(directionToLight)), 0); 54 | vec3 intensity = light.color.xyz * light.color.w * attenuation; 55 | 56 | diffuseLight += intensity * cosAngIncidence; 57 | } 58 | 59 | 60 | outColor = vec4(diffuseLight * fragColor, 1.0); 61 | } -------------------------------------------------------------------------------- /Source/Chapter25MultiplePointLights/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter25MultiplePointLights/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter25MultiplePointLights/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 position; 4 | layout(location = 1) in vec3 color; 5 | layout(location = 2) in vec3 normal; 6 | layout(location = 3) in vec2 uv; 7 | 8 | layout(location = 0) out vec3 fragColor; 9 | layout(location = 1) out vec3 fragPosWorld; 10 | layout(location = 2) out vec3 fragNormalWorld; 11 | 12 | struct PointLight { 13 | vec4 position; // ignore w 14 | vec4 color; // w is intensity 15 | }; 16 | 17 | layout(set = 0, binding = 0) uniform GlobalUbo 18 | { 19 | mat4 projection; 20 | mat4 view; 21 | vec4 ambientColor; 22 | PointLight pointLight1; 23 | PointLight pointLight2; 24 | PointLight pointLight3; 25 | PointLight pointLight4; 26 | PointLight pointLight5; 27 | PointLight pointLight6; 28 | int numLights; 29 | } ubo; 30 | 31 | layout(push_constant) uniform Push 32 | { 33 | mat4 modelMatrix; 34 | mat4 normalMatrix; 35 | } push; 36 | 37 | 38 | //const vec3 DIRECTION_TO_LIGHT = normalize(vec3(1.0, -3.0, -1.0)); 39 | //const float AMBIENT = 0.02; 40 | 41 | void main() { 42 | vec4 positionWorld = push.modelMatrix * vec4(position, 1.0); 43 | gl_Position = ubo.projection * ubo.view * positionWorld; 44 | 45 | fragNormalWorld = normalize(mat3(push.normalMatrix) * normal); 46 | fragPosWorld = positionWorld.xyz; 47 | fragColor = color; 48 | 49 | // vec3 directionToLight = ubo.lightPosition.xyz - positionWorld.xyz; 50 | // float attenuation = 1.0 / dot(directionToLight, directionToLight); // distance squared 51 | // 52 | // vec3 lightColor = ubo.lightColor.xyz * ubo.lightColor.w * attenuation; 53 | // vec3 ambientLight = ubo.ambientColor.xyz * ubo.ambientColor.w; 54 | // vec3 diffuseLight = lightColor * max(dot(normalWorldSpace, normalize(directionToLight)), 0); 55 | // 56 | // fragColor = (diffuseLight + ambientLight) * color; 57 | } 58 | 59 | 60 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Chapter25MultiplePointLights/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter25MultiplePointLights/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter26SpecularLighting/FrameInfo.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Chapter26SpecularLighting; 3 | 4 | public struct FrameInfo 5 | { 6 | public int FrameIndex;// { get; set; } 7 | public float FrameTime;// { get; set; } 8 | public CommandBuffer CommandBuffer;// { get; init; } 9 | public ICamera Camera;// { get; init; } = null!; 10 | public DescriptorSet GlobalDescriptorSet;// { get; init; } 11 | public Dictionary GameObjects; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /Source/Chapter26SpecularLighting/GlobalUbo.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter26SpecularLighting; 2 | 3 | public struct GlobalUbo 4 | { 5 | public Matrix4x4 Projection; 6 | public Matrix4x4 View; 7 | public Vector4 FrontVec; 8 | public Vector4 AmbientColor; 9 | public PointLight PointLight1; 10 | public PointLight PointLight2; 11 | public PointLight PointLight3; 12 | public PointLight PointLight4; 13 | public PointLight PointLight5; 14 | public PointLight PointLight6; 15 | public int NumLights; 16 | 17 | public GlobalUbo() 18 | { 19 | Projection = Matrix4x4.Identity; 20 | View = Matrix4x4.Identity; 21 | FrontVec = Vector4.UnitZ; 22 | AmbientColor = new(1f, 1f, 1f, 0.02f); 23 | } 24 | 25 | public static uint SizeOf() => (uint)Unsafe.SizeOf(); 26 | 27 | } 28 | 29 | 30 | public struct PointLight 31 | { 32 | public Vector4 Position; 33 | public Vector4 Color; 34 | } -------------------------------------------------------------------------------- /Source/Chapter26SpecularLighting/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | global using Silk.NET.Windowing; 19 | 20 | //global using Silk.NET.Vulkan.Extensions.ImGui; 21 | //global using Silk.NET.Input.Extensions; 22 | 23 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 24 | global using Buffer = Silk.NET.Vulkan.Buffer; 25 | global using Image = Silk.NET.Vulkan.Image; 26 | global using Device = Silk.NET.Vulkan.Device; 27 | 28 | 29 | 30 | namespace Chapter26SpecularLighting; 31 | 32 | -------------------------------------------------------------------------------- /Source/Chapter26SpecularLighting/ICamera.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter26SpecularLighting 2 | { 3 | public interface ICamera 4 | { 5 | float AspectRatio { get; } 6 | bool EnableRotation { get; set; } 7 | Vector3 FrontVec { get; set; } 8 | Vector4 GetFrontVec4(); 9 | uint Hp { get; } 10 | float Pitch { get; set; } 11 | float PitchDegrees { get; } 12 | Vector3 Position { get; set; } 13 | Vector3 RightVec { get; set; } 14 | Vector3 UpVec { get; set; } 15 | uint Wp { get; } 16 | int Xp { get; } 17 | float Yaw { get; set; } 18 | float YawDegrees { get; } 19 | int Yp { get; } 20 | 21 | Matrix4x4 GetInverseViewMatrix(); 22 | Matrix4x4 GetProjectionMatrix(); 23 | //Matrix4x4 GetProjectionMatrixGlm(); 24 | Matrix4x4 GetViewMatrix(); 25 | //Matrix4x4 GetViewMatrixGlm(); 26 | void Pan(Vector3 vStart, Vector3 vStop); 27 | Vector2 Project(Vector3 mouse3d); 28 | void Reset(); 29 | void Resize(int xp, int yp, uint wp, uint hp); 30 | void Rotate(Vector2 vStart, Vector2 vStop); 31 | Vector3 UnProject(Vector2 mouse2d); 32 | void ZoomIncremental(float amount); 33 | void ZoomSetPrevious(); 34 | } 35 | } -------------------------------------------------------------------------------- /Source/Chapter26SpecularLighting/Model/PointLightComponent.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter26SpecularLighting; 2 | 3 | public struct PointLightComponent 4 | { 5 | public float LightIntensity; 6 | 7 | public PointLightComponent(float intensity) 8 | { 9 | LightIntensity = intensity; 10 | } 11 | } -------------------------------------------------------------------------------- /Source/Chapter26SpecularLighting/Program26.cs: -------------------------------------------------------------------------------- 1 | using Chapter26SpecularLighting; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter26SpecularLighting/Shaders/pointLight.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec2 fragOffset; 4 | layout(location = 0) out vec4 outColor; 5 | 6 | 7 | struct PointLight { 8 | vec4 position; // ignore w 9 | vec4 color; // w is intensity 10 | }; 11 | 12 | layout(set = 0, binding = 0) uniform GlobalUbo 13 | { 14 | mat4 projection; 15 | mat4 view; 16 | vec4 front; 17 | vec4 ambientColor; 18 | PointLight pointLight1; 19 | PointLight pointLight2; 20 | PointLight pointLight3; 21 | PointLight pointLight4; 22 | PointLight pointLight5; 23 | PointLight pointLight6; 24 | int numLights; 25 | } ubo; 26 | 27 | layout(push_constant) uniform Push 28 | { 29 | vec4 position; 30 | vec4 color; 31 | float radius; 32 | } push; 33 | 34 | const float M_PI = 3.1415926538; 35 | 36 | void main() { 37 | float dis = sqrt(dot(fragOffset, fragOffset)); 38 | if (dis >= 1.0) discard; 39 | float dis2 = dis * .9; 40 | float intensity = 1.0 - pow(dis2, 0.5); 41 | outColor = vec4(push.color.xyz * intensity, 1.0); 42 | } -------------------------------------------------------------------------------- /Source/Chapter26SpecularLighting/Shaders/pointLight.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter26SpecularLighting/Shaders/pointLight.frag.spv -------------------------------------------------------------------------------- /Source/Chapter26SpecularLighting/Shaders/pointLight.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | //#extension GL_KHR_vulkan_glsl:enable 3 | 4 | 5 | const vec2 OFFSETS[6] = vec2[]( 6 | vec2(-1.0, -1.0), 7 | vec2(-1.0, 1.0), 8 | vec2(1.0, -1.0), 9 | vec2(1.0, -1.0), 10 | vec2(-1.0, 1.0), 11 | vec2(1.0, 1.0) 12 | ); 13 | 14 | layout (location = 0) out vec2 fragOffset; 15 | 16 | struct PointLight { 17 | vec4 position; // ignore w 18 | vec4 color; // w is intensity 19 | }; 20 | 21 | layout(set = 0, binding = 0) uniform GlobalUbo 22 | { 23 | mat4 projection; 24 | mat4 view; 25 | vec4 front; 26 | vec4 ambientColor; 27 | PointLight pointLight1; 28 | PointLight pointLight2; 29 | PointLight pointLight3; 30 | PointLight pointLight4; 31 | PointLight pointLight5; 32 | PointLight pointLight6; 33 | int numLights; 34 | } ubo; 35 | 36 | layout(push_constant) uniform Push 37 | { 38 | vec4 position; 39 | vec4 color; 40 | float radius; 41 | } push; 42 | 43 | 44 | //const float LIGHT_RADIUS = 0.06; 45 | 46 | void main() { 47 | fragOffset = OFFSETS[gl_VertexIndex]; 48 | vec3 cameraRightWorld = {ubo.view[0][0], ubo.view[1][0], ubo.view[2][0]}; 49 | vec3 cameraUpWorld = {ubo.view[0][1], ubo.view[1][1], ubo.view[2][1]}; 50 | 51 | vec3 positionWorld = push.position.xyz 52 | + push.radius * fragOffset.x * cameraRightWorld 53 | + push.radius * fragOffset.y * cameraUpWorld; 54 | 55 | gl_Position = ubo.projection * ubo.view * vec4(positionWorld, 1.0); 56 | } 57 | 58 | -------------------------------------------------------------------------------- /Source/Chapter26SpecularLighting/Shaders/pointLight.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter26SpecularLighting/Shaders/pointLight.vert.spv -------------------------------------------------------------------------------- /Source/Chapter26SpecularLighting/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter26SpecularLighting/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter26SpecularLighting/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 position; 4 | layout(location = 1) in vec3 color; 5 | layout(location = 2) in vec3 normal; 6 | layout(location = 3) in vec2 uv; 7 | 8 | layout(location = 0) out vec3 fragColor; 9 | layout(location = 1) out vec3 fragPosWorld; 10 | layout(location = 2) out vec3 fragNormalWorld; 11 | 12 | struct PointLight { 13 | vec4 position; // ignore w 14 | vec4 color; // w is intensity 15 | }; 16 | 17 | layout(set = 0, binding = 0) uniform GlobalUbo 18 | { 19 | mat4 projection; 20 | mat4 view; 21 | vec4 front; 22 | vec4 ambientColor; 23 | PointLight pointLight1; 24 | PointLight pointLight2; 25 | PointLight pointLight3; 26 | PointLight pointLight4; 27 | PointLight pointLight5; 28 | PointLight pointLight6; 29 | int numLights; 30 | } ubo; 31 | 32 | layout(push_constant) uniform Push 33 | { 34 | mat4 modelMatrix; 35 | mat4 normalMatrix; 36 | } push; 37 | 38 | 39 | //const vec3 DIRECTION_TO_LIGHT = normalize(vec3(1.0, -3.0, -1.0)); 40 | //const float AMBIENT = 0.02; 41 | 42 | void main() { 43 | vec4 positionWorld = push.modelMatrix * vec4(position, 1.0); 44 | gl_Position = ubo.projection * ubo.view * positionWorld; 45 | 46 | fragNormalWorld = normalize(mat3(push.normalMatrix) * normal); 47 | fragPosWorld = positionWorld.xyz; 48 | fragColor = color; 49 | 50 | // vec3 directionToLight = ubo.lightPosition.xyz - positionWorld.xyz; 51 | // float attenuation = 1.0 / dot(directionToLight, directionToLight); // distance squared 52 | // 53 | // vec3 lightColor = ubo.lightColor.xyz * ubo.lightColor.w * attenuation; 54 | // vec3 ambientLight = ubo.ambientColor.xyz * ubo.ambientColor.w; 55 | // vec3 diffuseLight = lightColor * max(dot(normalWorldSpace, normalize(directionToLight)), 0); 56 | // 57 | // fragColor = (diffuseLight + ambientLight) * color; 58 | } 59 | 60 | 61 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Chapter26SpecularLighting/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter26SpecularLighting/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Chapter27AlphaBlending/BlittableHelper.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Chapter27AlphaBlending; 3 | 4 | public static class BlittableHelper 5 | { 6 | public static readonly bool IsBlittable; 7 | 8 | static BlittableHelper() 9 | { 10 | try 11 | { 12 | // Class test 13 | if (default(T) != null) 14 | { 15 | // Non-blittable types cannot allocate pinned handle 16 | GCHandle.Alloc(default(T), GCHandleType.Pinned).Free(); 17 | IsBlittable = true; 18 | } 19 | } 20 | catch { } 21 | } 22 | } -------------------------------------------------------------------------------- /Source/Chapter27AlphaBlending/FrameInfo.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Chapter27AlphaBlending; 3 | 4 | public struct FrameInfo 5 | { 6 | public int FrameIndex;// { get; set; } 7 | public float FrameTime;// { get; set; } 8 | public CommandBuffer CommandBuffer;// { get; init; } 9 | public ICamera Camera;// { get; init; } = null!; 10 | public DescriptorSet GlobalDescriptorSet;// { get; init; } 11 | public Dictionary GameObjects; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /Source/Chapter27AlphaBlending/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | global using Silk.NET.Windowing; 19 | 20 | //global using Silk.NET.Vulkan.Extensions.ImGui; 21 | //global using Silk.NET.Input.Extensions; 22 | 23 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 24 | global using Buffer = Silk.NET.Vulkan.Buffer; 25 | global using Image = Silk.NET.Vulkan.Image; 26 | global using Device = Silk.NET.Vulkan.Device; 27 | 28 | 29 | 30 | namespace Chapter27AlphaBlending; 31 | 32 | -------------------------------------------------------------------------------- /Source/Chapter27AlphaBlending/ICamera.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter27AlphaBlending 2 | { 3 | public interface ICamera 4 | { 5 | float AspectRatio { get; } 6 | bool EnableRotation { get; set; } 7 | Vector3 FrontVec { get; set; } 8 | Vector4 GetFrontVec4(); 9 | uint Hp { get; } 10 | float Pitch { get; set; } 11 | float PitchDegrees { get; } 12 | Vector3 Position { get; set; } 13 | Vector3 RightVec { get; set; } 14 | Vector3 UpVec { get; set; } 15 | uint Wp { get; } 16 | int Xp { get; } 17 | float Yaw { get; set; } 18 | float YawDegrees { get; } 19 | int Yp { get; } 20 | 21 | float Frustum { get; } 22 | 23 | Matrix4x4 GetInverseViewMatrix(); 24 | Matrix4x4 GetProjectionMatrix(); 25 | //Matrix4x4 GetProjectionMatrixGlm(); 26 | Matrix4x4 GetViewMatrix(); 27 | //Matrix4x4 GetViewMatrixGlm(); 28 | void Pan(Vector3 vStart, Vector3 vStop); 29 | Vector2 Project(Vector3 mouse3d); 30 | void Reset(); 31 | void Resize(int xp, int yp, uint wp, uint hp); 32 | void Rotate(Vector2 vStart, Vector2 vStop); 33 | Vector3 UnProject(Vector2 mouse2d); 34 | void ZoomIncremental(float amount); 35 | void ZoomSetPrevious(); 36 | } 37 | } -------------------------------------------------------------------------------- /Source/Chapter27AlphaBlending/Model/ColorHelper.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter27AlphaBlending; 2 | public static class Color3 3 | { 4 | public static Vector3 White => new(1f, 1f, 1f); 5 | public static Vector3 Black => new(0f, 0f, 0f); 6 | 7 | // my colors 8 | public static Vector3 RoughGreen => new(0f, 0.6f, 0f); 9 | 10 | // main 11 | public static Vector3 Red => new(1f, 0f, 0f); 12 | public static Vector3 Green => new(0f, 1f, 0f); 13 | public static Vector3 Blue => new(0f, 0f, 1f); 14 | 15 | // mix1 16 | public static Vector3 Yellow => new(1f, 1f, 0f); 17 | public static Vector3 Magenta => new(1f, 0f, 1f); 18 | public static Vector3 Cyan => new(0f, 1f, 1f); 19 | public static Vector3 Gray => new(0.5f, 0.5f, 0.5f); 20 | 21 | // others 22 | public static Vector3 Pink => new(1f, 0.75f, 0.8f); 23 | public static Vector3 Orange => new(1f, 0.65f, 0f); 24 | public static Vector3 Purple => new(0.6f, 0.4f, 0.8f); 25 | public static Vector3 Brown => new(0.6f, 0.4f, 0.2f); 26 | public static Vector3 Beige => new(0.96f, 0.96f, 0.86f); 27 | public static Vector3 Olive => new(0.5f, 0.5f, 0f); 28 | public static Vector3 Maroon => new(0.5f, 0f, 0f); 29 | public static Vector3 Navy => new(0f, 0f, 0.5f); 30 | public static Vector3 Teal => new(0f, 0.5f, 0.5f); 31 | 32 | // others2 33 | public static Vector3 Lime => new(0.75f, 1f, 0f); 34 | public static Vector3 Turquoise => new(0.25f, 0.88f, 0.82f); 35 | public static Vector3 Lavender => new(0.9f, 0.9f, 0.98f); 36 | public static Vector3 Coral => new(1f, 0.5f, 0.31f); 37 | public static Vector3 Salmon => new(0.98f, 0.5f, 0.45f); 38 | public static Vector3 Peach => new(1f, 0.8f, 0.64f); 39 | public static Vector3 Mint => new(0.6f, 1f, 0.8f); 40 | public static Vector3 PowderBlue => new(0.69f, 0.88f, 0.9f); 41 | public static Vector3 LightGray => new(0.83f, 0.83f, 0.83f); 42 | 43 | public static Vector3 WhiteSmoke => new(0.96f, 0.96f, 0.96f); 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /Source/Chapter27AlphaBlending/Model/PointLightComponent.cs: -------------------------------------------------------------------------------- 1 | namespace Chapter27AlphaBlending; 2 | 3 | public struct PointLightComponent 4 | { 5 | public float LightIntensity; 6 | 7 | public PointLightComponent(float intensity) 8 | { 9 | LightIntensity = intensity; 10 | } 11 | } -------------------------------------------------------------------------------- /Source/Chapter27AlphaBlending/Program27.cs: -------------------------------------------------------------------------------- 1 | using Chapter27AlphaBlending; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Chapter27AlphaBlending/Shaders/pointLight.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec2 fragOffset; 4 | layout(location = 0) out vec4 outColor; 5 | 6 | 7 | struct PointLight { 8 | vec4 position; // ignore w 9 | vec4 color; // w is intensity 10 | }; 11 | 12 | layout(set = 0, binding = 0) uniform GlobalUbo 13 | { 14 | mat4 projection; 15 | mat4 view; 16 | vec4 front; 17 | vec4 ambientColor; 18 | int numLights; 19 | int padding1; 20 | int padding2; 21 | int padding3; 22 | PointLight pointLights[10]; 23 | } ubo; 24 | 25 | layout(push_constant) uniform Push 26 | { 27 | vec4 position; 28 | vec4 color; 29 | float radius; 30 | } push; 31 | 32 | const float M_PI = 3.1415926538; 33 | 34 | void main() { 35 | float dis = sqrt(dot(fragOffset, fragOffset)); 36 | if (dis >= 1.0) discard; 37 | 38 | float cosDis = 0.5 * (cos(dis * M_PI) + 1.0); 39 | outColor = vec4(push.color.xyz + 0.5*cosDis, cosDis); 40 | } -------------------------------------------------------------------------------- /Source/Chapter27AlphaBlending/Shaders/pointLight.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter27AlphaBlending/Shaders/pointLight.frag.spv -------------------------------------------------------------------------------- /Source/Chapter27AlphaBlending/Shaders/pointLight.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_KHR_vulkan_glsl:enable 3 | 4 | 5 | const vec2 OFFSETS[6] = vec2[]( 6 | vec2(-1.0, -1.0), 7 | vec2(-1.0, 1.0), 8 | vec2(1.0, -1.0), 9 | vec2(1.0, -1.0), 10 | vec2(-1.0, 1.0), 11 | vec2(1.0, 1.0) 12 | ); 13 | 14 | layout (location = 0) out vec2 fragOffset; 15 | 16 | struct PointLight { 17 | vec4 position; // ignore w 18 | vec4 color; // w is intensity 19 | }; 20 | 21 | layout(set = 0, binding = 0) uniform GlobalUbo 22 | { 23 | mat4 projection; 24 | mat4 view; 25 | vec4 front; 26 | vec4 ambientColor; 27 | int numLights; 28 | int padding1; 29 | int padding2; 30 | int padding3; 31 | PointLight pointLights[10]; 32 | } ubo; 33 | 34 | layout(push_constant) uniform Push 35 | { 36 | vec4 position; 37 | vec4 color; 38 | float radius; 39 | } push; 40 | 41 | 42 | void main() { 43 | fragOffset = OFFSETS[gl_VertexIndex]; 44 | vec3 cameraRightWorld = {ubo.view[0][0], ubo.view[1][0], ubo.view[2][0]}; 45 | vec3 cameraUpWorld = {ubo.view[0][1], ubo.view[1][1], ubo.view[2][1]}; 46 | 47 | vec3 positionWorld = push.position.xyz 48 | + push.radius * fragOffset.x * cameraRightWorld 49 | + push.radius * fragOffset.y * cameraUpWorld; 50 | 51 | gl_Position = ubo.projection * ubo.view * vec4(positionWorld, 1.0); 52 | } 53 | 54 | -------------------------------------------------------------------------------- /Source/Chapter27AlphaBlending/Shaders/pointLight.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter27AlphaBlending/Shaders/pointLight.vert.spv -------------------------------------------------------------------------------- /Source/Chapter27AlphaBlending/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | layout(location = 1) in vec3 fragPosWorld; 5 | layout(location = 2) in vec3 fragNormalWorld; 6 | 7 | layout(location = 0) out vec4 outColor; 8 | 9 | 10 | struct PointLight { 11 | vec4 position; // ignore w 12 | vec4 color; // w is intensity 13 | }; 14 | 15 | layout(set = 0, binding = 0) uniform GlobalUbo 16 | { 17 | mat4 projection; 18 | mat4 view; 19 | vec4 front; 20 | vec4 ambientColor; 21 | int numLights; 22 | int padding1; 23 | int padding2; 24 | int padding3; 25 | PointLight pointLights[10]; 26 | } ubo; 27 | 28 | layout(push_constant) uniform Push 29 | { 30 | mat4 modelMatrix; 31 | mat4 normalMatrix; 32 | } push; 33 | 34 | 35 | 36 | void main() { 37 | vec3 diffuseLight = ubo.ambientColor.xyz * ubo.ambientColor.w; 38 | vec3 specularLight = vec3(0.0); 39 | vec3 surfaceNormal = normalize(fragNormalWorld); 40 | 41 | // already had front vec in camera 42 | vec3 viewDirection = -ubo.front.xyz; 43 | 44 | for (int i = 0; i < ubo.numLights; i++) 45 | { 46 | 47 | PointLight light = ubo.pointLights[i]; 48 | vec3 directionToLight = light.position.xyz - fragPosWorld; 49 | float attenuation = 1.0 / dot(directionToLight, directionToLight); // distance squared 50 | directionToLight = normalize(directionToLight); 51 | 52 | float cosAngIncidence = max(dot(surfaceNormal, directionToLight), 0); 53 | vec3 intensity = light.color.xyz * light.color.w * attenuation; 54 | 55 | diffuseLight += intensity * cosAngIncidence; 56 | 57 | // specular lighting 58 | vec3 halfAngle = normalize(directionToLight + viewDirection); 59 | float blinnTerm = dot(surfaceNormal, halfAngle); 60 | blinnTerm = clamp(blinnTerm, 0, 1); 61 | blinnTerm = pow(blinnTerm, 64.0); 62 | specularLight += intensity * blinnTerm; 63 | } 64 | 65 | 66 | outColor = vec4(diffuseLight * fragColor + specularLight * fragColor, 1.0); 67 | } -------------------------------------------------------------------------------- /Source/Chapter27AlphaBlending/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter27AlphaBlending/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Chapter27AlphaBlending/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 position; 4 | layout(location = 1) in vec3 color; 5 | layout(location = 2) in vec3 normal; 6 | layout(location = 3) in vec2 uv; 7 | 8 | layout(location = 0) out vec3 fragColor; 9 | layout(location = 1) out vec3 fragPosWorld; 10 | layout(location = 2) out vec3 fragNormalWorld; 11 | 12 | struct PointLight { 13 | vec4 position; // ignore w 14 | vec4 color; // w is intensity 15 | }; 16 | 17 | layout(set = 0, binding = 0) uniform GlobalUbo 18 | { 19 | mat4 projection; 20 | mat4 view; 21 | vec4 front; 22 | vec4 ambientColor; 23 | int numLights; 24 | int padding1; 25 | int padding2; 26 | int padding3; 27 | PointLight pointLights[10]; 28 | } ubo; 29 | 30 | layout(push_constant) uniform Push 31 | { 32 | mat4 modelMatrix; 33 | mat4 normalMatrix; 34 | } push; 35 | 36 | 37 | void main() { 38 | vec4 positionWorld = push.modelMatrix * vec4(position, 1.0); 39 | gl_Position = ubo.projection * ubo.view * positionWorld; 40 | 41 | fragNormalWorld = normalize(mat3(push.normalMatrix) * normal); 42 | fragPosWorld = positionWorld.xyz; 43 | fragColor = color; 44 | } 45 | 46 | 47 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Chapter27AlphaBlending/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Chapter27AlphaBlending/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Sandbox01MultiSampling/BlittableHelper.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Sandbox01MultiSampling; 3 | 4 | public static class BlittableHelper 5 | { 6 | public static readonly bool IsBlittable; 7 | 8 | static BlittableHelper() 9 | { 10 | try 11 | { 12 | // Class test 13 | if (default(T) != null) 14 | { 15 | // Non-blittable types cannot allocate pinned handle 16 | GCHandle.Alloc(default(T), GCHandleType.Pinned).Free(); 17 | IsBlittable = true; 18 | } 19 | } 20 | catch { } 21 | } 22 | } -------------------------------------------------------------------------------- /Source/Sandbox01MultiSampling/FrameInfo.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Sandbox01MultiSampling; 3 | 4 | public struct FrameInfo 5 | { 6 | public int FrameIndex;// { get; set; } 7 | public float FrameTime;// { get; set; } 8 | public CommandBuffer CommandBuffer;// { get; init; } 9 | public ICamera Camera;// { get; init; } = null!; 10 | public DescriptorSet GlobalDescriptorSet;// { get; init; } 11 | public Dictionary GameObjects; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /Source/Sandbox01MultiSampling/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | global using Silk.NET.Windowing; 19 | 20 | //global using Silk.NET.Vulkan.Extensions.ImGui; 21 | //global using Silk.NET.Input.Extensions; 22 | 23 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 24 | global using Buffer = Silk.NET.Vulkan.Buffer; 25 | global using Image = Silk.NET.Vulkan.Image; 26 | global using Device = Silk.NET.Vulkan.Device; 27 | 28 | 29 | 30 | namespace Sandbox01MultiSampling; 31 | 32 | -------------------------------------------------------------------------------- /Source/Sandbox01MultiSampling/ICamera.cs: -------------------------------------------------------------------------------- 1 | namespace Sandbox01MultiSampling 2 | { 3 | public interface ICamera 4 | { 5 | float AspectRatio { get; } 6 | bool EnableRotation { get; set; } 7 | Vector3 FrontVec { get; set; } 8 | Vector4 GetFrontVec4(); 9 | uint Hp { get; } 10 | float Pitch { get; set; } 11 | float PitchDegrees { get; } 12 | Vector3 Position { get; set; } 13 | Vector3 RightVec { get; set; } 14 | Vector3 UpVec { get; set; } 15 | uint Wp { get; } 16 | int Xp { get; } 17 | float Yaw { get; set; } 18 | float YawDegrees { get; } 19 | int Yp { get; } 20 | 21 | float Frustum { get; } 22 | 23 | Matrix4x4 GetInverseViewMatrix(); 24 | Matrix4x4 GetProjectionMatrix(); 25 | //Matrix4x4 GetProjectionMatrixGlm(); 26 | Matrix4x4 GetViewMatrix(); 27 | //Matrix4x4 GetViewMatrixGlm(); 28 | void Pan(Vector3 vStart, Vector3 vStop); 29 | Vector2 Project(Vector3 mouse3d); 30 | void Reset(); 31 | void Resize(int xp, int yp, uint wp, uint hp); 32 | void Rotate(Vector2 vStart, Vector2 vStop); 33 | Vector3 UnProject(Vector2 mouse2d); 34 | void ZoomIncremental(float amount); 35 | void ZoomSetPrevious(); 36 | } 37 | } -------------------------------------------------------------------------------- /Source/Sandbox01MultiSampling/Model/ColorHelper.cs: -------------------------------------------------------------------------------- 1 | namespace Sandbox01MultiSampling; 2 | public static class Color3 3 | { 4 | public static Vector3 White => new(1f, 1f, 1f); 5 | public static Vector3 Black => new(0f, 0f, 0f); 6 | 7 | // my colors 8 | public static Vector3 RoughGreen => new(0f, 0.6f, 0f); 9 | 10 | // main 11 | public static Vector3 Red => new(1f, 0f, 0f); 12 | public static Vector3 Green => new(0f, 1f, 0f); 13 | public static Vector3 Blue => new(0f, 0f, 1f); 14 | 15 | // mix1 16 | public static Vector3 Yellow => new(1f, 1f, 0f); 17 | public static Vector3 Magenta => new(1f, 0f, 1f); 18 | public static Vector3 Cyan => new(0f, 1f, 1f); 19 | public static Vector3 Gray => new(0.5f, 0.5f, 0.5f); 20 | 21 | // others 22 | public static Vector3 Pink => new(1f, 0.75f, 0.8f); 23 | public static Vector3 Orange => new(1f, 0.65f, 0f); 24 | public static Vector3 Purple => new(0.6f, 0.4f, 0.8f); 25 | public static Vector3 Brown => new(0.6f, 0.4f, 0.2f); 26 | public static Vector3 Beige => new(0.96f, 0.96f, 0.86f); 27 | public static Vector3 Olive => new(0.5f, 0.5f, 0f); 28 | public static Vector3 Maroon => new(0.5f, 0f, 0f); 29 | public static Vector3 Navy => new(0f, 0f, 0.5f); 30 | public static Vector3 Teal => new(0f, 0.5f, 0.5f); 31 | 32 | // others2 33 | public static Vector3 Lime => new(0.75f, 1f, 0f); 34 | public static Vector3 Turquoise => new(0.25f, 0.88f, 0.82f); 35 | public static Vector3 Lavender => new(0.9f, 0.9f, 0.98f); 36 | public static Vector3 Coral => new(1f, 0.5f, 0.31f); 37 | public static Vector3 Salmon => new(0.98f, 0.5f, 0.45f); 38 | public static Vector3 Peach => new(1f, 0.8f, 0.64f); 39 | public static Vector3 Mint => new(0.6f, 1f, 0.8f); 40 | public static Vector3 PowderBlue => new(0.69f, 0.88f, 0.9f); 41 | public static Vector3 LightGray => new(0.83f, 0.83f, 0.83f); 42 | 43 | public static Vector3 WhiteSmoke => new(0.96f, 0.96f, 0.96f); 44 | } 45 | 46 | 47 | -------------------------------------------------------------------------------- /Source/Sandbox01MultiSampling/Model/PointLightComponent.cs: -------------------------------------------------------------------------------- 1 | namespace Sandbox01MultiSampling; 2 | 3 | public struct PointLightComponent 4 | { 5 | public float LightIntensity; 6 | 7 | public PointLightComponent(float intensity) 8 | { 9 | LightIntensity = intensity; 10 | } 11 | } -------------------------------------------------------------------------------- /Source/Sandbox01MultiSampling/Program.cs: -------------------------------------------------------------------------------- 1 | using Sandbox01MultiSampling; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Sandbox01MultiSampling/Shaders/pointLight.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec2 fragOffset; 4 | layout(location = 0) out vec4 outColor; 5 | 6 | 7 | struct PointLight { 8 | vec4 position; // ignore w 9 | vec4 color; // w is intensity 10 | }; 11 | 12 | layout(set = 0, binding = 0) uniform GlobalUbo 13 | { 14 | mat4 projection; 15 | mat4 view; 16 | vec4 front; 17 | vec4 ambientColor; 18 | int numLights; 19 | int padding1; 20 | int padding2; 21 | int padding3; 22 | PointLight pointLights[10]; 23 | } ubo; 24 | 25 | layout(push_constant) uniform Push 26 | { 27 | vec4 position; 28 | vec4 color; 29 | float radius; 30 | } push; 31 | 32 | const float M_PI = 3.1415926538; 33 | 34 | void main() { 35 | float dis = sqrt(dot(fragOffset, fragOffset)); 36 | if (dis >= 1.0) discard; 37 | 38 | float cosDis = 0.5 * (cos(dis * M_PI) + 1.0); 39 | outColor = vec4(push.color.xyz + 0.5*cosDis, cosDis); 40 | } -------------------------------------------------------------------------------- /Source/Sandbox01MultiSampling/Shaders/pointLight.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Sandbox01MultiSampling/Shaders/pointLight.frag.spv -------------------------------------------------------------------------------- /Source/Sandbox01MultiSampling/Shaders/pointLight.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_KHR_vulkan_glsl:enable 3 | 4 | 5 | const vec2 OFFSETS[6] = vec2[]( 6 | vec2(-1.0, -1.0), 7 | vec2(-1.0, 1.0), 8 | vec2(1.0, -1.0), 9 | vec2(1.0, -1.0), 10 | vec2(-1.0, 1.0), 11 | vec2(1.0, 1.0) 12 | ); 13 | 14 | layout (location = 0) out vec2 fragOffset; 15 | 16 | struct PointLight { 17 | vec4 position; // ignore w 18 | vec4 color; // w is intensity 19 | }; 20 | 21 | layout(set = 0, binding = 0) uniform GlobalUbo 22 | { 23 | mat4 projection; 24 | mat4 view; 25 | vec4 front; 26 | vec4 ambientColor; 27 | int numLights; 28 | int padding1; 29 | int padding2; 30 | int padding3; 31 | PointLight pointLights[10]; 32 | } ubo; 33 | 34 | layout(push_constant) uniform Push 35 | { 36 | vec4 position; 37 | vec4 color; 38 | float radius; 39 | } push; 40 | 41 | 42 | void main() { 43 | fragOffset = OFFSETS[gl_VertexIndex]; 44 | vec3 cameraRightWorld = {ubo.view[0][0], ubo.view[1][0], ubo.view[2][0]}; 45 | vec3 cameraUpWorld = {ubo.view[0][1], ubo.view[1][1], ubo.view[2][1]}; 46 | 47 | vec3 positionWorld = push.position.xyz 48 | + push.radius * fragOffset.x * cameraRightWorld 49 | + push.radius * fragOffset.y * cameraUpWorld; 50 | 51 | gl_Position = ubo.projection * ubo.view * vec4(positionWorld, 1.0); 52 | } 53 | 54 | -------------------------------------------------------------------------------- /Source/Sandbox01MultiSampling/Shaders/pointLight.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Sandbox01MultiSampling/Shaders/pointLight.vert.spv -------------------------------------------------------------------------------- /Source/Sandbox01MultiSampling/Shaders/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | layout(location = 1) in vec3 fragPosWorld; 5 | layout(location = 2) in vec3 fragNormalWorld; 6 | 7 | layout(location = 0) out vec4 outColor; 8 | 9 | 10 | struct PointLight { 11 | vec4 position; // ignore w 12 | vec4 color; // w is intensity 13 | }; 14 | 15 | layout(set = 0, binding = 0) uniform GlobalUbo 16 | { 17 | mat4 projection; 18 | mat4 view; 19 | vec4 front; 20 | vec4 ambientColor; 21 | int numLights; 22 | int padding1; 23 | int padding2; 24 | int padding3; 25 | PointLight pointLights[10]; 26 | } ubo; 27 | 28 | layout(push_constant) uniform Push 29 | { 30 | mat4 modelMatrix; 31 | mat4 normalMatrix; 32 | } push; 33 | 34 | 35 | 36 | void main() { 37 | vec3 diffuseLight = ubo.ambientColor.xyz * ubo.ambientColor.w; 38 | vec3 specularLight = vec3(0.0); 39 | vec3 surfaceNormal = normalize(fragNormalWorld); 40 | 41 | // already had front vec in camera 42 | vec3 viewDirection = -ubo.front.xyz; 43 | 44 | for (int i = 0; i < ubo.numLights; i++) 45 | { 46 | 47 | PointLight light = ubo.pointLights[i]; 48 | vec3 directionToLight = light.position.xyz - fragPosWorld; 49 | float attenuation = 1.0 / dot(directionToLight, directionToLight); // distance squared 50 | directionToLight = normalize(directionToLight); 51 | 52 | float cosAngIncidence = max(dot(surfaceNormal, directionToLight), 0); 53 | vec3 intensity = light.color.xyz * light.color.w * attenuation; 54 | 55 | diffuseLight += intensity * cosAngIncidence; 56 | 57 | // specular lighting 58 | vec3 halfAngle = normalize(directionToLight + viewDirection); 59 | float blinnTerm = dot(surfaceNormal, halfAngle); 60 | blinnTerm = clamp(blinnTerm, 0, 1); 61 | blinnTerm = pow(blinnTerm, 64.0); 62 | specularLight += intensity * blinnTerm; 63 | } 64 | 65 | 66 | outColor = vec4(diffuseLight * fragColor + specularLight * fragColor, 1.0); 67 | } -------------------------------------------------------------------------------- /Source/Sandbox01MultiSampling/Shaders/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Sandbox01MultiSampling/Shaders/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Sandbox01MultiSampling/Shaders/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 position; 4 | layout(location = 1) in vec3 color; 5 | layout(location = 2) in vec3 normal; 6 | layout(location = 3) in vec2 uv; 7 | 8 | layout(location = 0) out vec3 fragColor; 9 | layout(location = 1) out vec3 fragPosWorld; 10 | layout(location = 2) out vec3 fragNormalWorld; 11 | 12 | struct PointLight { 13 | vec4 position; // ignore w 14 | vec4 color; // w is intensity 15 | }; 16 | 17 | layout(set = 0, binding = 0) uniform GlobalUbo 18 | { 19 | mat4 projection; 20 | mat4 view; 21 | vec4 front; 22 | vec4 ambientColor; 23 | int numLights; 24 | int padding1; 25 | int padding2; 26 | int padding3; 27 | PointLight pointLights[10]; 28 | } ubo; 29 | 30 | layout(push_constant) uniform Push 31 | { 32 | mat4 modelMatrix; 33 | mat4 normalMatrix; 34 | } push; 35 | 36 | 37 | void main() { 38 | vec4 positionWorld = push.modelMatrix * vec4(position, 1.0); 39 | gl_Position = ubo.projection * ubo.view * positionWorld; 40 | 41 | fragNormalWorld = normalize(mat3(push.normalMatrix) * normal); 42 | fragPosWorld = positionWorld.xyz; 43 | fragColor = color; 44 | } 45 | 46 | 47 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Sandbox01MultiSampling/Shaders/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Sandbox01MultiSampling/Shaders/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Sandbox02ImGui/Camera/ICamera.cs: -------------------------------------------------------------------------------- 1 | namespace Sandbox02ImGui 2 | { 3 | public interface ICamera 4 | { 5 | float AspectRatio { get; } 6 | bool EnableRotation { get; set; } 7 | Vector3 FrontVec { get; set; } 8 | Vector4 GetFrontVec4(); 9 | uint Hp { get; } 10 | float Pitch { get; set; } 11 | float PitchDegrees { get; } 12 | Vector3 Position { get; set; } 13 | Vector3 RightVec { get; set; } 14 | Vector3 UpVec { get; set; } 15 | uint Wp { get; } 16 | int Xp { get; } 17 | float Yaw { get; set; } 18 | float YawDegrees { get; } 19 | int Yp { get; } 20 | 21 | float Frustum { get; } 22 | 23 | Matrix4x4 GetInverseViewMatrix(); 24 | Matrix4x4 GetProjectionMatrix(); 25 | //Matrix4x4 GetProjectionMatrixGlm(); 26 | Matrix4x4 GetViewMatrix(); 27 | //Matrix4x4 GetViewMatrixGlm(); 28 | void Pan(Vector3 vStart, Vector3 vStop); 29 | Vector2 Project(Vector3 mouse3d); 30 | void Reset(); 31 | void Resize(int xp, int yp, uint wp, uint hp); 32 | void Rotate(Vector2 vStart, Vector2 vStop); 33 | Vector3 UnProject(Vector2 mouse2d); 34 | void ZoomIncremental(float amount); 35 | void ZoomSetPrevious(); 36 | } 37 | } -------------------------------------------------------------------------------- /Source/Sandbox02ImGui/Engine/FrameInfo.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Sandbox02ImGui; 3 | 4 | public struct FrameInfo 5 | { 6 | public int FrameIndex;// { get; set; } 7 | public float FrameTime;// { get; set; } 8 | public CommandBuffer CommandBuffer;// { get; init; } 9 | public ICamera Camera;// { get; init; } = null!; 10 | public DescriptorSet GlobalDescriptorSet;// { get; init; } 11 | public Dictionary GameObjects; 12 | } 13 | 14 | 15 | -------------------------------------------------------------------------------- /Source/Sandbox02ImGui/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | global using Silk.NET.Windowing; 19 | 20 | global using Silk.NET.Input.Extensions; 21 | global using Silk.NET.Vulkan.Extensions.ImGui; 22 | global using ImGuiNET; 23 | 24 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 25 | global using Buffer = Silk.NET.Vulkan.Buffer; 26 | global using Image = Silk.NET.Vulkan.Image; 27 | global using Device = Silk.NET.Vulkan.Device; 28 | 29 | 30 | 31 | namespace Sandbox02ImGui; 32 | 33 | -------------------------------------------------------------------------------- /Source/Sandbox02ImGui/Program.cs: -------------------------------------------------------------------------------- 1 | using Sandbox02ImGui; 2 | 3 | var app = new FirstApp(); 4 | 5 | try 6 | { 7 | app.Run(); 8 | 9 | } 10 | catch (Exception ex) 11 | { 12 | Console.WriteLine($"Error!\n{ex.Message}"); 13 | throw; 14 | } 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Sandbox02ImGui/Systems/ImGui/ImGuiFontConfig.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | 4 | using System; 5 | 6 | namespace Silk.NET.Vulkan.Extensions.ImGui 7 | { 8 | public readonly struct ImGuiFontConfig 9 | { 10 | public ImGuiFontConfig(string fontPath, int fontSize) 11 | { 12 | if (fontSize <= 0) throw new ArgumentOutOfRangeException(nameof(fontSize)); 13 | FontPath = fontPath ?? throw new ArgumentNullException(nameof(fontPath)); 14 | FontSize = fontSize; 15 | } 16 | 17 | public string FontPath { get; } 18 | public int FontSize { get; } 19 | } 20 | } -------------------------------------------------------------------------------- /Source/Sandbox02ImGui/Systems/PointLight/PointLightComponent.cs: -------------------------------------------------------------------------------- 1 | namespace Sandbox02ImGui; 2 | 3 | public struct PointLightComponent 4 | { 5 | public float LightIntensity; 6 | 7 | public PointLightComponent(float intensity) 8 | { 9 | LightIntensity = intensity; 10 | } 11 | } -------------------------------------------------------------------------------- /Source/Sandbox02ImGui/Systems/PointLight/pointLight.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec2 fragOffset; 4 | layout(location = 0) out vec4 outColor; 5 | 6 | 7 | struct PointLight { 8 | vec4 position; // ignore w 9 | vec4 color; // w is intensity 10 | }; 11 | 12 | layout(set = 0, binding = 0) uniform GlobalUbo 13 | { 14 | mat4 projection; 15 | mat4 view; 16 | vec4 front; 17 | vec4 ambientColor; 18 | int numLights; 19 | int padding1; 20 | int padding2; 21 | int padding3; 22 | PointLight pointLights[10]; 23 | } ubo; 24 | 25 | layout(push_constant) uniform Push 26 | { 27 | vec4 position; 28 | vec4 color; 29 | float radius; 30 | } push; 31 | 32 | const float M_PI = 3.1415926538; 33 | 34 | void main() { 35 | float dis = sqrt(dot(fragOffset, fragOffset)); 36 | if (dis >= 1.0) discard; 37 | 38 | float cosDis = 0.5 * (cos(dis * M_PI) + 1.0); 39 | outColor = vec4(push.color.xyz + 0.5*cosDis, cosDis); 40 | } -------------------------------------------------------------------------------- /Source/Sandbox02ImGui/Systems/PointLight/pointLight.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Sandbox02ImGui/Systems/PointLight/pointLight.frag.spv -------------------------------------------------------------------------------- /Source/Sandbox02ImGui/Systems/PointLight/pointLight.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_KHR_vulkan_glsl:enable 3 | 4 | 5 | const vec2 OFFSETS[6] = vec2[]( 6 | vec2(-1.0, -1.0), 7 | vec2(-1.0, 1.0), 8 | vec2(1.0, -1.0), 9 | vec2(1.0, -1.0), 10 | vec2(-1.0, 1.0), 11 | vec2(1.0, 1.0) 12 | ); 13 | 14 | layout (location = 0) out vec2 fragOffset; 15 | 16 | struct PointLight { 17 | vec4 position; // ignore w 18 | vec4 color; // w is intensity 19 | }; 20 | 21 | layout(set = 0, binding = 0) uniform GlobalUbo 22 | { 23 | mat4 projection; 24 | mat4 view; 25 | vec4 front; 26 | vec4 ambientColor; 27 | int numLights; 28 | int padding1; 29 | int padding2; 30 | int padding3; 31 | PointLight pointLights[10]; 32 | } ubo; 33 | 34 | layout(push_constant) uniform Push 35 | { 36 | vec4 position; 37 | vec4 color; 38 | float radius; 39 | } push; 40 | 41 | 42 | void main() { 43 | fragOffset = OFFSETS[gl_VertexIndex]; 44 | vec3 cameraRightWorld = {ubo.view[0][0], ubo.view[1][0], ubo.view[2][0]}; 45 | vec3 cameraUpWorld = {ubo.view[0][1], ubo.view[1][1], ubo.view[2][1]}; 46 | 47 | vec3 positionWorld = push.position.xyz 48 | + push.radius * fragOffset.x * cameraRightWorld 49 | + push.radius * fragOffset.y * cameraUpWorld; 50 | 51 | gl_Position = ubo.projection * ubo.view * vec4(positionWorld, 1.0); 52 | } 53 | 54 | -------------------------------------------------------------------------------- /Source/Sandbox02ImGui/Systems/PointLight/pointLight.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Sandbox02ImGui/Systems/PointLight/pointLight.vert.spv -------------------------------------------------------------------------------- /Source/Sandbox02ImGui/Systems/Simple/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | layout(location = 1) in vec3 fragPosWorld; 5 | layout(location = 2) in vec3 fragNormalWorld; 6 | 7 | layout(location = 0) out vec4 outColor; 8 | 9 | 10 | struct PointLight { 11 | vec4 position; // ignore w 12 | vec4 color; // w is intensity 13 | }; 14 | 15 | layout(set = 0, binding = 0) uniform GlobalUbo 16 | { 17 | mat4 projection; 18 | mat4 view; 19 | vec4 front; 20 | vec4 ambientColor; 21 | int numLights; 22 | int padding1; 23 | int padding2; 24 | int padding3; 25 | PointLight pointLights[10]; 26 | } ubo; 27 | 28 | layout(push_constant) uniform Push 29 | { 30 | mat4 modelMatrix; 31 | mat4 normalMatrix; 32 | } push; 33 | 34 | 35 | 36 | void main() { 37 | vec3 diffuseLight = ubo.ambientColor.xyz * ubo.ambientColor.w; 38 | vec3 specularLight = vec3(0.0); 39 | vec3 surfaceNormal = normalize(fragNormalWorld); 40 | 41 | // already had front vec in camera 42 | vec3 viewDirection = -ubo.front.xyz; 43 | 44 | for (int i = 0; i < ubo.numLights; i++) 45 | { 46 | 47 | PointLight light = ubo.pointLights[i]; 48 | vec3 directionToLight = light.position.xyz - fragPosWorld; 49 | float attenuation = 1.0 / dot(directionToLight, directionToLight); // distance squared 50 | directionToLight = normalize(directionToLight); 51 | 52 | float cosAngIncidence = max(dot(surfaceNormal, directionToLight), 0); 53 | vec3 intensity = light.color.xyz * light.color.w * attenuation; 54 | 55 | diffuseLight += intensity * cosAngIncidence; 56 | 57 | // specular lighting 58 | vec3 halfAngle = normalize(directionToLight + viewDirection); 59 | float blinnTerm = dot(surfaceNormal, halfAngle); 60 | blinnTerm = clamp(blinnTerm, 0, 1); 61 | blinnTerm = pow(blinnTerm, 64.0); 62 | specularLight += intensity * blinnTerm; 63 | } 64 | 65 | 66 | outColor = vec4(diffuseLight * fragColor + specularLight * fragColor, 1.0); 67 | } -------------------------------------------------------------------------------- /Source/Sandbox02ImGui/Systems/Simple/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Sandbox02ImGui/Systems/Simple/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Sandbox02ImGui/Systems/Simple/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 position; 4 | layout(location = 1) in vec3 color; 5 | layout(location = 2) in vec3 normal; 6 | layout(location = 3) in vec2 uv; 7 | 8 | layout(location = 0) out vec3 fragColor; 9 | layout(location = 1) out vec3 fragPosWorld; 10 | layout(location = 2) out vec3 fragNormalWorld; 11 | 12 | struct PointLight { 13 | vec4 position; // ignore w 14 | vec4 color; // w is intensity 15 | }; 16 | 17 | layout(set = 0, binding = 0) uniform GlobalUbo 18 | { 19 | mat4 projection; 20 | mat4 view; 21 | vec4 front; 22 | vec4 ambientColor; 23 | int numLights; 24 | int padding1; 25 | int padding2; 26 | int padding3; 27 | PointLight pointLights[10]; 28 | } ubo; 29 | 30 | layout(push_constant) uniform Push 31 | { 32 | mat4 modelMatrix; 33 | mat4 normalMatrix; 34 | } push; 35 | 36 | 37 | void main() { 38 | vec4 positionWorld = push.modelMatrix * vec4(position, 1.0); 39 | gl_Position = ubo.projection * ubo.view * positionWorld; 40 | 41 | fragNormalWorld = normalize(mat3(push.normalMatrix) * normal); 42 | fragPosWorld = positionWorld.xyz; 43 | fragColor = color; 44 | } 45 | 46 | 47 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Sandbox02ImGui/Systems/Simple/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Sandbox02ImGui/Systems/Simple/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Sandbox02ImGui/Utils/BlittableHelper.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Sandbox02ImGui; 3 | 4 | public static class BlittableHelper 5 | { 6 | public static readonly bool IsBlittable; 7 | 8 | static BlittableHelper() 9 | { 10 | try 11 | { 12 | // Class test 13 | if (default(T) != null) 14 | { 15 | // Non-blittable types cannot allocate pinned handle 16 | GCHandle.Alloc(default(T), GCHandleType.Pinned).Free(); 17 | IsBlittable = true; 18 | } 19 | } 20 | catch { } 21 | } 22 | } -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Camera/ICamera.cs: -------------------------------------------------------------------------------- 1 | namespace Sandbox03MeshShaders 2 | { 3 | public interface ICamera 4 | { 5 | float AspectRatio { get; } 6 | bool EnableRotation { get; set; } 7 | Vector3 FrontVec { get; set; } 8 | Vector4 GetFrontVec4(); 9 | uint Hp { get; } 10 | float Pitch { get; set; } 11 | float PitchDegrees { get; } 12 | Vector3 Position { get; set; } 13 | Vector3 RightVec { get; set; } 14 | Vector3 UpVec { get; set; } 15 | uint Wp { get; } 16 | int Xp { get; } 17 | float Yaw { get; set; } 18 | float YawDegrees { get; } 19 | int Yp { get; } 20 | 21 | float Frustum { get; } 22 | 23 | Matrix4x4 GetInverseViewMatrix(); 24 | Matrix4x4 GetProjectionMatrix(); 25 | //Matrix4x4 GetProjectionMatrixGlm(); 26 | Matrix4x4 GetViewMatrix(); 27 | //Matrix4x4 GetViewMatrixGlm(); 28 | void Pan(Vector3 vStart, Vector3 vStop); 29 | Vector2 Project(Vector3 mouse3d); 30 | void Reset(); 31 | void Resize(int xp, int yp, uint wp, uint hp); 32 | void Rotate(Vector2 vStart, Vector2 vStop); 33 | Vector3 UnProject(Vector2 mouse2d); 34 | void ZoomIncremental(float amount); 35 | void ZoomSetPrevious(); 36 | } 37 | } -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Engine/FrameInfo.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Sandbox03MeshShaders; 3 | 4 | public struct FrameInfo 5 | { 6 | public int FrameIndex;// { get; set; } 7 | public float FrameTime;// { get; set; } 8 | public CommandBuffer CommandBuffer;// { get; init; } 9 | public ICamera Camera;// { get; init; } = null!; 10 | public DescriptorSet GlobalDescriptorSet;// { get; init; } 11 | public Dictionary GameObjects; 12 | public Dictionary MeshObjects; 13 | } 14 | 15 | 16 | -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Globals.cs: -------------------------------------------------------------------------------- 1 | global using System.Runtime.CompilerServices; 2 | global using System.Runtime.InteropServices; 3 | global using System.Diagnostics; 4 | global using System.Reflection; 5 | global using System.Numerics; 6 | global using System.Drawing; 7 | global using System.Text; 8 | global using System.IO; 9 | 10 | global using Silk.NET.Core; 11 | global using Silk.NET.Core.Native; 12 | global using Silk.NET.Core.Contexts; 13 | global using Silk.NET.Input; 14 | global using Silk.NET.Maths; 15 | global using Silk.NET.Vulkan; 16 | global using Silk.NET.Vulkan.Extensions.EXT; 17 | global using Silk.NET.Vulkan.Extensions.KHR; 18 | global using Silk.NET.Windowing; 19 | 20 | global using Silk.NET.Input.Extensions; 21 | global using Silk.NET.Vulkan.Extensions.ImGui; 22 | global using ImGuiNET; 23 | 24 | global using Semaphore = Silk.NET.Vulkan.Semaphore; 25 | global using Buffer = Silk.NET.Vulkan.Buffer; 26 | global using Image = Silk.NET.Vulkan.Image; 27 | global using Device = Silk.NET.Vulkan.Device; 28 | 29 | 30 | 31 | namespace Sandbox03MeshShaders; 32 | 33 | -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Program.cs: -------------------------------------------------------------------------------- 1 | using Sandbox03MeshShaders; 2 | 3 | var app = new FirstApp(); 4 | 5 | //try 6 | //{ 7 | app.Run(); 8 | 9 | //} 10 | //catch (Exception ex) 11 | //{ 12 | // Console.WriteLine($"Error!\n{ex.Message}"); 13 | // throw; 14 | //} 15 | 16 | 17 | -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Systems/ImGui/ImGuiFontConfig.cs: -------------------------------------------------------------------------------- 1 | // Licensed to the .NET Foundation under one or more agreements. 2 | // The .NET Foundation licenses this file to you under the MIT license. 3 | 4 | using System; 5 | 6 | namespace Silk.NET.Vulkan.Extensions.ImGui 7 | { 8 | public readonly struct ImGuiFontConfig 9 | { 10 | public ImGuiFontConfig(string fontPath, int fontSize) 11 | { 12 | if (fontSize <= 0) throw new ArgumentOutOfRangeException(nameof(fontSize)); 13 | FontPath = fontPath ?? throw new ArgumentNullException(nameof(fontPath)); 14 | FontSize = fontSize; 15 | } 16 | 17 | public string FontPath { get; } 18 | public int FontSize { get; } 19 | } 20 | } -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Systems/MeshTest/SboMeshTest.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Sandbox03MeshShaders; 3 | public struct SboMeshTest 4 | { 5 | public uint TriangleCount; 6 | public float TriangleSpacing; 7 | public float TriangleWidth; 8 | public float TriangleHeight; 9 | 10 | public SboMeshTest() 11 | { 12 | TriangleCount = 3; 13 | TriangleSpacing = 1f; 14 | TriangleWidth = 1f; 15 | TriangleHeight = 1f; 16 | } 17 | 18 | public static uint SizeOf() => (uint)Unsafe.SizeOf(); 19 | } 20 | -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Systems/MeshTest/testMesh.frag: -------------------------------------------------------------------------------- 1 | /* 2 | * Based on - Vulkan Example - Using mesh shaders 3 | * 4 | * Copyright (C) 2022 by Sascha Willems - www.saschawillems.de 5 | * 6 | * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #version 460 10 | 11 | layout (location = 0) in VertexInput { 12 | vec4 color; 13 | } vertexInput; 14 | 15 | layout(location = 0) out vec4 outFragColor; 16 | 17 | 18 | void main() 19 | { 20 | outFragColor = vertexInput.color; 21 | } 22 | 23 | //layout(location = 0) in vec3 fragColor; 24 | // 25 | //layout(location = 0) out vec4 outColor; 26 | // 27 | //layout(push_constant) uniform Push 28 | //{ 29 | // mat4 modelMatrix; 30 | //} push; 31 | // 32 | // 33 | //void main() { 34 | // outColor = vec4(fragColor, 1.0); 35 | //} -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Systems/MeshTest/testMesh.task: -------------------------------------------------------------------------------- 1 | /* 2 | * Based on - Vulkan Example - Using mesh shaders 3 | * 4 | * Copyright (C) 2022 by Sascha Willems - www.saschawillems.de 5 | * 6 | * This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) 7 | */ 8 | 9 | #version 460 10 | #extension GL_EXT_mesh_shader : require 11 | 12 | layout(push_constant) uniform Push 13 | { 14 | mat4 modelMatrix; 15 | mat4 normalMatrix; 16 | } push; 17 | 18 | layout(set = 0, binding = 1) buffer SboMeshTest 19 | { 20 | uint triangleCount; 21 | float triangleSpacing; 22 | float triangleHeight; 23 | float triangleWidth; 24 | } sbo; 25 | 26 | 27 | void main() 28 | { 29 | EmitMeshTasksEXT(sbo.triangleCount, 1, 1); 30 | } 31 | 32 | -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Systems/PointLight/PointLightComponent.cs: -------------------------------------------------------------------------------- 1 | namespace Sandbox03MeshShaders; 2 | 3 | public struct PointLightComponent 4 | { 5 | public float LightIntensity; 6 | 7 | public PointLightComponent(float intensity) 8 | { 9 | LightIntensity = intensity; 10 | } 11 | } -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Systems/PointLight/pointLight.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec2 fragOffset; 4 | layout(location = 0) out vec4 outColor; 5 | 6 | 7 | struct PointLight { 8 | vec4 position; // ignore w 9 | vec4 color; // w is intensity 10 | }; 11 | 12 | layout(set = 0, binding = 0) uniform GlobalUbo 13 | { 14 | mat4 projection; 15 | mat4 view; 16 | vec4 front; 17 | vec4 ambientColor; 18 | int numLights; 19 | int padding1; 20 | int padding2; 21 | int padding3; 22 | PointLight pointLights[10]; 23 | } ubo; 24 | 25 | layout(push_constant) uniform Push 26 | { 27 | vec4 position; 28 | vec4 color; 29 | float radius; 30 | } push; 31 | 32 | const float M_PI = 3.1415926538; 33 | 34 | void main() { 35 | float dis = sqrt(dot(fragOffset, fragOffset)); 36 | if (dis >= 1.0) discard; 37 | 38 | float cosDis = 0.5 * (cos(dis * M_PI) + 1.0); 39 | outColor = vec4(push.color.xyz + 0.5*cosDis, cosDis); 40 | } -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Systems/PointLight/pointLight.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | #extension GL_KHR_vulkan_glsl:enable 3 | 4 | 5 | const vec2 OFFSETS[6] = vec2[]( 6 | vec2(-1.0, -1.0), 7 | vec2(-1.0, 1.0), 8 | vec2(1.0, -1.0), 9 | vec2(1.0, -1.0), 10 | vec2(-1.0, 1.0), 11 | vec2(1.0, 1.0) 12 | ); 13 | 14 | layout (location = 0) out vec2 fragOffset; 15 | 16 | struct PointLight { 17 | vec4 position; // ignore w 18 | vec4 color; // w is intensity 19 | }; 20 | 21 | layout(set = 0, binding = 0) uniform GlobalUbo 22 | { 23 | mat4 projection; 24 | mat4 view; 25 | vec4 front; 26 | vec4 ambientColor; 27 | int numLights; 28 | int padding1; 29 | int padding2; 30 | int padding3; 31 | PointLight pointLights[10]; 32 | } ubo; 33 | 34 | layout(push_constant) uniform Push 35 | { 36 | vec4 position; 37 | vec4 color; 38 | float radius; 39 | } push; 40 | 41 | 42 | void main() { 43 | fragOffset = OFFSETS[gl_VertexIndex]; 44 | vec3 cameraRightWorld = {ubo.view[0][0], ubo.view[1][0], ubo.view[2][0]}; 45 | vec3 cameraUpWorld = {ubo.view[0][1], ubo.view[1][1], ubo.view[2][1]}; 46 | 47 | vec3 positionWorld = push.position.xyz 48 | + push.radius * fragOffset.x * cameraRightWorld 49 | + push.radius * fragOffset.y * cameraUpWorld; 50 | 51 | gl_Position = ubo.projection * ubo.view * vec4(positionWorld, 1.0); 52 | } 53 | 54 | -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Systems/SPIRV/pointLight.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Sandbox03MeshShaders/Systems/SPIRV/pointLight.frag.spv -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Systems/SPIRV/pointLight.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Sandbox03MeshShaders/Systems/SPIRV/pointLight.vert.spv -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Systems/SPIRV/simpleShader.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Sandbox03MeshShaders/Systems/SPIRV/simpleShader.frag.spv -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Systems/SPIRV/simpleShader.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Sandbox03MeshShaders/Systems/SPIRV/simpleShader.vert.spv -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Systems/SPIRV/testMesh.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Sandbox03MeshShaders/Systems/SPIRV/testMesh.frag.spv -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Systems/SPIRV/testMesh.mesh.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Sandbox03MeshShaders/Systems/SPIRV/testMesh.mesh.spv -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Systems/SPIRV/testMesh.task.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stymee/SilkVulkanTutorial/3ffc7fb68e2b34bdf605fe272eed9b86c606f32b/Source/Sandbox03MeshShaders/Systems/SPIRV/testMesh.task.spv -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Systems/Simple/simpleShader.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | layout(location = 1) in vec3 fragPosWorld; 5 | layout(location = 2) in vec3 fragNormalWorld; 6 | 7 | layout(location = 0) out vec4 outColor; 8 | 9 | 10 | struct PointLight { 11 | vec4 position; // ignore w 12 | vec4 color; // w is intensity 13 | }; 14 | 15 | layout(set = 0, binding = 0) uniform GlobalUbo 16 | { 17 | mat4 projection; 18 | mat4 view; 19 | vec4 front; 20 | vec4 ambientColor; 21 | int numLights; 22 | int padding1; 23 | int padding2; 24 | int padding3; 25 | PointLight pointLights[10]; 26 | } ubo; 27 | 28 | layout(push_constant) uniform Push 29 | { 30 | mat4 modelMatrix; 31 | mat4 normalMatrix; 32 | } push; 33 | 34 | 35 | 36 | void main() { 37 | vec3 diffuseLight = ubo.ambientColor.xyz * ubo.ambientColor.w; 38 | vec3 specularLight = vec3(0.0); 39 | vec3 surfaceNormal = normalize(fragNormalWorld); 40 | 41 | // already had front vec in camera 42 | vec3 viewDirection = -ubo.front.xyz; 43 | 44 | for (int i = 0; i < ubo.numLights; i++) 45 | { 46 | 47 | PointLight light = ubo.pointLights[i]; 48 | vec3 directionToLight = light.position.xyz - fragPosWorld; 49 | float attenuation = 1.0 / dot(directionToLight, directionToLight); // distance squared 50 | directionToLight = normalize(directionToLight); 51 | 52 | float cosAngIncidence = max(dot(surfaceNormal, directionToLight), 0); 53 | vec3 intensity = light.color.xyz * light.color.w * attenuation; 54 | 55 | diffuseLight += intensity * cosAngIncidence; 56 | 57 | // specular lighting 58 | vec3 halfAngle = normalize(directionToLight + viewDirection); 59 | float blinnTerm = dot(surfaceNormal, halfAngle); 60 | blinnTerm = clamp(blinnTerm, 0, 1); 61 | blinnTerm = pow(blinnTerm, 64.0); 62 | specularLight += intensity * blinnTerm; 63 | } 64 | 65 | 66 | outColor = vec4(diffuseLight * fragColor + specularLight * fragColor, 1.0); 67 | } -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Systems/Simple/simpleShader.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 position; 4 | layout(location = 1) in vec3 color; 5 | layout(location = 2) in vec3 normal; 6 | layout(location = 3) in vec2 uv; 7 | 8 | layout(location = 0) out vec3 fragColor; 9 | layout(location = 1) out vec3 fragPosWorld; 10 | layout(location = 2) out vec3 fragNormalWorld; 11 | 12 | struct PointLight { 13 | vec4 position; // ignore w 14 | vec4 color; // w is intensity 15 | }; 16 | 17 | layout(set = 0, binding = 0) uniform GlobalUbo 18 | { 19 | mat4 projection; 20 | mat4 view; 21 | vec4 front; 22 | vec4 ambientColor; 23 | int numLights; 24 | int padding1; 25 | int padding2; 26 | int padding3; 27 | PointLight pointLights[10]; 28 | } ubo; 29 | 30 | layout(push_constant) uniform Push 31 | { 32 | mat4 modelMatrix; 33 | mat4 normalMatrix; 34 | } push; 35 | 36 | 37 | void main() { 38 | vec4 positionWorld = push.modelMatrix * vec4(position, 1.0); 39 | gl_Position = ubo.projection * ubo.view * positionWorld; 40 | 41 | fragNormalWorld = normalize(mat3(push.normalMatrix) * normal); 42 | fragPosWorld = positionWorld.xyz; 43 | fragColor = color; 44 | } 45 | 46 | 47 | //#extension GL_KHR_vulkan_glsl:enable -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Utils/BlittableHelper.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Sandbox03MeshShaders; 3 | 4 | public static class BlittableHelper 5 | { 6 | public static readonly bool IsBlittable; 7 | 8 | static BlittableHelper() 9 | { 10 | try 11 | { 12 | // Class test 13 | if (default(T) != null) 14 | { 15 | // Non-blittable types cannot allocate pinned handle 16 | GCHandle.Alloc(default(T), GCHandleType.Pinned).Free(); 17 | IsBlittable = true; 18 | } 19 | } 20 | catch { } 21 | } 22 | } -------------------------------------------------------------------------------- /Source/Sandbox03MeshShaders/Utils/FileUtil.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace Sandbox03MeshShaders; 3 | 4 | public sealed class FileUtil 5 | { 6 | public static byte[] GetShaderBytes(string filename, string renderSystemName) 7 | { 8 | var assembly = Assembly.GetExecutingAssembly(); 9 | foreach (var item in assembly.GetManifestResourceNames()) 10 | { 11 | Console.Write("."); 12 | Console.WriteLine($"{item}"); 13 | } 14 | var resourceName = assembly.GetManifestResourceNames().FirstOrDefault(s => s.EndsWith(filename)); 15 | if (resourceName is null) throw new ApplicationException($"*** In {renderSystemName}, No shader file found with name {filename}\n*** Check that resourceName and try again! Did you forget to set glsl file to Embedded Resource/Do Not Copy?"); 16 | 17 | using var stream = assembly.GetManifestResourceStream(resourceName) ?? throw new ApplicationException($"*** In {renderSystemName}, No shader file found at {resourceName}\n*** Check that resourceName and try again! Did you forget to set glsl file to Embedded Resource/Do Not Copy?"); 18 | using var ms = new MemoryStream(); 19 | if (stream is null) return Array.Empty(); 20 | stream.CopyTo(ms); 21 | return ms.ToArray(); 22 | 23 | } 24 | 25 | 26 | 27 | } 28 | --------------------------------------------------------------------------------