├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── LearnHoudini-01 ├── LearnHoudini.hip └── LearnHoudini.py ├── LearnMetal-01 ├── LearnMetal.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── kevintsuixu.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── kevintsuixu.xcuserdatad │ │ └── xcschemes │ │ └── xcschememanagement.plist └── LearnMetal │ ├── AppDelegate.swift │ ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── IMG_LOGO_x120.jpg │ │ └── IMG_LOGO_x180.jpg │ ├── Background.imageset │ │ ├── Background.png │ │ └── Contents.json │ ├── Contents.json │ └── IMG_LOGO.imageset │ │ ├── Contents.json │ │ └── IMG_LOGO.png │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── SceneDelegate.swift │ └── ViewController.swift ├── LearnMetal-02 ├── LearnMetal.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ ├── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ │ └── xcuserdata │ │ │ └── kevintsuixu.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── kevintsuixu.xcuserdatad │ │ └── xcschemes │ │ └── xcschememanagement.plist └── LearnMetal │ ├── AppDelegate.swift │ ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ ├── Contents.json │ │ ├── IMG_LOGO_x120.jpg │ │ └── IMG_LOGO_x180.jpg │ ├── Background.imageset │ │ ├── Background.png │ │ └── Contents.json │ ├── Contents.json │ └── IMG_LOGO.imageset │ │ ├── Contents.json │ │ └── IMG_LOGO.png │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── SceneDelegate.swift │ ├── Shaders.metal │ └── ViewController.swift ├── LearnVulkan-01 ├── CMakeLists.txt └── empty_window │ └── empty_window.cpp ├── LearnVulkan-02 ├── CMakeLists.txt └── draw_the_triangle │ ├── draw_the_triangle.cpp │ └── shaders │ ├── draw_the_triangle.frag │ └── draw_the_triangle.vert ├── LearnVulkan-03 ├── CMakeLists.txt └── draw_with_buffers │ ├── draw_with_buffers.cpp │ └── shaders │ ├── draw_with_buffers.frag │ └── draw_with_buffers.vert ├── LearnVulkan-04 ├── CMakeLists.txt └── draw_with_texture │ ├── draw_with_texture.cpp │ ├── shaders │ ├── draw_with_texture.frag │ └── draw_with_texture.vert │ └── textures │ └── botw_mifa.png ├── LearnVulkan-05 ├── CMakeLists.txt └── draw_the_scene │ ├── appicons │ ├── vulkan_renderer.icns │ ├── vulkan_renderer.ico │ ├── vulkan_renderer.png │ └── vulkan_renderer_small.png │ ├── draw_the_scene.cpp │ ├── models │ ├── hylian_shield.obj │ ├── master_sword.obj │ └── steath.obj │ ├── shaders │ ├── draw_the_scene.frag │ ├── draw_the_scene.vert │ ├── draw_the_scene_bg.frag │ └── draw_the_scene_bg.vert │ └── textures │ ├── background.png │ ├── hylian_shield_c.png │ ├── hylian_shield_o.png │ ├── master_sword_c.png │ ├── master_sword_o.png │ ├── steath_c.png │ └── steath_o.png ├── LearnVulkan-06 ├── CMakeLists.txt └── draw_with_PBR │ ├── appicons │ ├── renderer_logo.png │ ├── vulkan_renderer.icns │ ├── vulkan_renderer.ico │ ├── vulkan_renderer.png │ └── vulkan_renderer_small.png │ ├── draw_with_PBR.cpp │ ├── models │ ├── axis_guide.obj │ ├── cube.obj │ ├── hylian_shield.obj │ ├── master_sword.obj │ ├── sky_sphere.obj │ ├── sphere.obj │ ├── steath.obj │ └── viking_room.obj │ ├── shaders │ ├── draw_with_PBR.frag │ ├── draw_with_PBR.vert │ ├── draw_with_PBR_bg.frag │ ├── draw_with_PBR_bg.vert │ ├── draw_with_PBR_legacy.frag │ └── draw_with_PBR_legacy.vert │ └── textures │ ├── background.png │ ├── cubemap_X0.png │ ├── cubemap_X1.png │ ├── cubemap_Y2.png │ ├── cubemap_Y3.png │ ├── cubemap_Z4.png │ ├── cubemap_Z5.png │ ├── default_black.png │ ├── default_grey.png │ ├── default_grid.png │ ├── default_grid_n.png │ ├── default_normal.png │ ├── default_white.png │ ├── hylian_shield_c.png │ ├── hylian_shield_m.png │ ├── hylian_shield_n.png │ ├── hylian_shield_o.png │ ├── hylian_shield_r.png │ ├── master_sword_c.png │ ├── master_sword_m.png │ ├── master_sword_n.png │ ├── master_sword_o.png │ ├── master_sword_r.png │ ├── steath_c.png │ ├── steath_m.png │ ├── steath_n.png │ ├── steath_o.png │ ├── steath_r.png │ └── viking_room.png ├── LearnVulkan-07 ├── CMakeLists.txt └── draw_with_shadow │ ├── appicons │ ├── vulkan_renderer.icns │ ├── vulkan_renderer.ico │ ├── vulkan_renderer.png │ └── vulkan_renderer_small.png │ ├── draw_with_shadow.cpp │ ├── models │ ├── axis_guide.obj │ ├── cube.obj │ ├── sphere.obj │ ├── stage.obj │ └── stilized_house.obj │ ├── shaders │ ├── draw_with_shadow_base.frag │ ├── draw_with_shadow_base.vert │ ├── draw_with_shadow_bg.frag │ ├── draw_with_shadow_bg.vert │ ├── draw_with_shadow_sm.frag │ └── draw_with_shadow_sm.vert │ └── textures │ ├── background.png │ ├── cubemap_X0.png │ ├── cubemap_X1.png │ ├── cubemap_Y2.png │ ├── cubemap_Y3.png │ ├── cubemap_Z4.png │ ├── cubemap_Z5.png │ ├── default_black.png │ ├── default_grey.png │ ├── default_grid.png │ ├── default_grid_n.png │ ├── default_normal.png │ ├── default_white.png │ ├── stilized_house_ao.png │ ├── stilized_house_bc.png │ ├── stilized_house_m.png │ ├── stilized_house_n.png │ └── stilized_house_r.png ├── LearnVulkan-08 ├── CMakeLists.txt └── draw_with_instance │ ├── appicons │ ├── vulkan_renderer.icns │ ├── vulkan_renderer.ico │ ├── vulkan_renderer.png │ └── vulkan_renderer_small.png │ ├── draw_with_instance.cpp │ ├── models │ ├── antarctic_meteorite.obj │ ├── axis_guide.obj │ ├── cube.obj │ ├── galaxy_dome.obj │ ├── jupiter.obj │ ├── sphere.obj │ └── stage.obj │ ├── shaders │ ├── draw_with_instance_base.frag │ ├── draw_with_instance_base.vert │ ├── draw_with_instance_base_instanced.vert │ ├── draw_with_instance_bg.frag │ ├── draw_with_instance_bg.vert │ ├── draw_with_instance_sky.frag │ ├── draw_with_instance_sky.vert │ ├── draw_with_instance_sm.frag │ ├── draw_with_instance_sm.vert │ └── draw_with_instance_sm_instanced.vert │ └── textures │ ├── antarctic_meteorite_bc.png │ ├── background.png │ ├── cubemap_X0.png │ ├── cubemap_X1.png │ ├── cubemap_Y2.png │ ├── cubemap_Y3.png │ ├── cubemap_Z4.png │ ├── cubemap_Z5.png │ ├── default_black.png │ ├── default_grey.png │ ├── default_grid.png │ ├── default_grid_n.png │ ├── default_normal.png │ ├── default_white.png │ ├── galaxy_dome.png │ └── jupiter_bc.png ├── LearnVulkan-09 ├── CMakeLists.txt └── draw_with_deferred │ ├── appicons │ ├── vulkan_renderer.icns │ ├── vulkan_renderer.ico │ ├── vulkan_renderer.png │ └── vulkan_renderer_small.png │ ├── draw_with_deferred.cpp │ ├── models │ ├── axis_guide.obj │ ├── cube.obj │ ├── galaxy_dome.obj │ ├── grass_01.obj │ ├── grass_02.obj │ ├── rock_01.obj │ ├── rock_02.obj │ ├── skydome.obj │ ├── sphere.obj │ ├── stage.obj │ └── terrain.obj │ ├── shaders │ ├── draw_with_deferred_base.frag │ ├── draw_with_deferred_base.vert │ ├── draw_with_deferred_base_instanced.vert │ ├── draw_with_deferred_bg.frag │ ├── draw_with_deferred_bg.vert │ ├── draw_with_deferred_lighting.frag │ ├── draw_with_deferred_scene.frag │ ├── draw_with_deferred_sky.frag │ ├── draw_with_deferred_sky.vert │ ├── draw_with_deferred_sm.frag │ ├── draw_with_deferred_sm.vert │ └── draw_with_deferred_sm_instanced.vert │ └── textures │ ├── background.png │ ├── cubemap_X0.png │ ├── cubemap_X1.png │ ├── cubemap_Y2.png │ ├── cubemap_Y3.png │ ├── cubemap_Z4.png │ ├── cubemap_Z5.png │ ├── default_black.png │ ├── default_grey.png │ ├── default_grid.png │ ├── default_grid_n.png │ ├── default_normal.png │ ├── default_white.png │ ├── grass_ao.png │ ├── grass_bc.png │ ├── grass_ev.png │ ├── grass_ms.png │ ├── grass_n.png │ ├── grass_r.png │ ├── rock_01_bc.png │ ├── rock_01_n.png │ ├── rock_01_r.png │ ├── rock_02_bc.png │ ├── rock_02_n.png │ ├── rock_02_r.png │ ├── skydome.png │ ├── terrain_ao.png │ ├── terrain_bc.png │ ├── terrain_ev.png │ ├── terrain_n.png │ └── terrain_r.png ├── README.md └── cmake ├── FindDirectFB.cmake ├── FindWayland.cmake └── FindXCB.cmake /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | 9 | # Precompiled Headers 10 | *.gch 11 | *.pch 12 | 13 | # Compiled Dynamic libraries 14 | *.so 15 | *.dylib 16 | *.dll 17 | 18 | # Fortran module files 19 | *.mod 20 | *.smod 21 | 22 | # Compiled Static libraries 23 | *.lai 24 | *.la 25 | *.a 26 | *.lib 27 | 28 | # Executables 29 | *.exe 30 | *.out 31 | *.app 32 | 33 | # Remove Temps 34 | *.DS_Store 35 | build/* -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Third_Party/glfw"] 2 | path = Third_Party/glfw 3 | url = https://github.com/glfw/glfw.git 4 | [submodule "Third_Party/glm"] 5 | path = Third_Party/glm 6 | url = https://github.com/g-truc/glm.git 7 | [submodule "Third_Party/stb"] 8 | path = Third_Party/stb 9 | url = https://github.com/nothings/stb 10 | [submodule "Third_Party/tinyobjloader"] 11 | path = Third_Party/tinyobjloader 12 | url = https://github.com/tinyobjloader/tinyobjloader 13 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5 FATAL_ERROR) 2 | cmake_policy(VERSION 3.5) 3 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") 4 | 5 | set(PROJNAME LearnVulkan) 6 | 7 | project(${PROJNAME}) 8 | 9 | include_directories(Third_Party) 10 | include_directories(Third_Party/glfw) 11 | include_directories(Third_Party/glm) 12 | include_directories(Third_Party/stb) 13 | include_directories(Third_Party/tinyobjloader) 14 | 15 | # Use FindVulkan module added with CMAKE 3.7 16 | if(NOT CMAKE_VERSION VERSION_LESS 3.7.0) 17 | message(STATUS "Using module to find Vulkan") 18 | find_package(Vulkan) 19 | endif() 20 | 21 | if(UNIX AND NOT APPLE) 22 | set(LINUX TRUE) 23 | endif() 24 | 25 | if(LINUX) 26 | OPTION(USE_D2D_WSI "Build the project using Direct to Display swapchain" OFF) 27 | OPTION(USE_DIRECTFB_WSI "Build the project using DirectFB swapchain" OFF) 28 | OPTION(USE_WAYLAND_WSI "Build the project using Wayland swapchain" OFF) 29 | OPTION(USE_HEADLESS "Build the project using headless extension swapchain" OFF) 30 | endif() 31 | 32 | if(WIN32) 33 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_WIN32_KHR") 34 | elseif(LINUX) 35 | find_package(Threads REQUIRED) 36 | if(USE_D2D_WSI) 37 | MESSAGE("Using direct to display extension...") 38 | add_definitions(-D_DIRECT2DISPLAY) 39 | elseif(USE_DIRECTFB_WSI) 40 | find_package(DirectFB REQUIRED) 41 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_DIRECTFB_EXT") 42 | include_directories(${DIRECTFB_INCLUDE_DIR}) 43 | elseif(USE_WAYLAND_WSI) 44 | find_program(PKG_CONFIG pkg-config) 45 | if(NOT PKG_CONFIG) 46 | message(FATAL_ERROR "pkg-config binary not found") 47 | endif() 48 | find_package(Wayland REQUIRED) 49 | if(NOT WAYLAND_FOUND) 50 | message(FATAL_ERROR "Wayland development package not found") 51 | endif() 52 | pkg_check_modules(WAYLAND_PROTOCOLS REQUIRED wayland-protocols) 53 | if(NOT WAYLAND_PROTOCOLS_FOUND) 54 | message(FATAL_ERROR "Wayland protocols package not found") 55 | endif() 56 | find_program(WAYLAND_SCANNER wayland-scanner) 57 | if(NOT WAYLAND_SCANNER) 58 | message(FATAL_ERROR "wayland-scanner binary not found") 59 | endif() 60 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_WAYLAND_KHR") 61 | include_directories(${WAYLAND_INCLUDE_DIR}) 62 | pkg_get_variable(protocol_dir wayland-protocols pkgdatadir) 63 | execute_process(COMMAND ${WAYLAND_SCANNER} client-header ${protocol_dir}/stable/xdg-shell/xdg-shell.xml ${CMAKE_BINARY_DIR}/xdg-shell-client-protocol.h 64 | COMMAND ${WAYLAND_SCANNER} private-code ${protocol_dir}/stable/xdg-shell/xdg-shell.xml ${CMAKE_BINARY_DIR}/xdg-shell-protocol.c) 65 | include_directories(${CMAKE_BINARY_DIR}) 66 | elseif(USE_HEADLESS) 67 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_HEADLESS_EXT") 68 | else(USE_D2D_WSI) 69 | find_package(XCB REQUIRED) 70 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_XCB_KHR") 71 | endif(USE_D2D_WSI) 72 | elseif(APPLE) 73 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVK_USE_PLATFORM_MACOS_MVK -DVK_EXAMPLE_XCODE_GENERATED") 74 | # Todo : android? 75 | endif(WIN32) 76 | 77 | if(NOT Vulkan_FOUND) 78 | message(FATAL_ERROR "Could not find Vulkan library!") 79 | else() 80 | message(STATUS "Vulkan include dir: ${Vulkan_INCLUDE_DIRS}") 81 | include_directories(${Vulkan_INCLUDE_DIRS}) 82 | message(STATUS "Vulkan library dir: ${Vulkan_LIBRARY}") 83 | endif() 84 | 85 | # Set preprocessor defines 86 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DNOMINMAX -D_USE_MATH_DEFINES") 87 | 88 | # Clang specific stuff 89 | if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") 90 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-switch-enum") 91 | endif() 92 | 93 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 94 | set(CMAKE_CXX_STANDARD 17) 95 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 96 | 97 | # Compiler specific stuff 98 | if(MSVC) 99 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") 100 | elseif(APPLE) 101 | if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") 102 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fobjc-arc -ObjC++") 103 | else() 104 | SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fobjc-arc -xobjective-c++") 105 | endif() 106 | endif(MSVC) 107 | 108 | if(WIN32) 109 | # Nothing here (yet) 110 | elseif(APPLE) 111 | link_libraries(${Vulkan_LIBRARY} "-framework AppKit" "-framework QuartzCore") 112 | else(WIN32) 113 | link_libraries(${XCB_LIBRARIES} ${Vulkan_LIBRARY} ${Vulkan_LIBRARY} ${DIRECTFB_LIBRARIES} ${WAYLAND_CLIENT_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) 114 | endif(WIN32) 115 | 116 | set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) 117 | set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) 118 | set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) 119 | 120 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}") 121 | 122 | add_subdirectory(Third_Party/glfw) 123 | add_subdirectory(Third_Party/glm) 124 | add_subdirectory(Third_Party/tinyobjloader) 125 | add_subdirectory(LearnVulkan-01) 126 | add_subdirectory(LearnVulkan-02) 127 | add_subdirectory(LearnVulkan-03) 128 | add_subdirectory(LearnVulkan-04) 129 | add_subdirectory(LearnVulkan-05) 130 | add_subdirectory(LearnVulkan-06) 131 | add_subdirectory(LearnVulkan-07) 132 | add_subdirectory(LearnVulkan-08) 133 | add_subdirectory(LearnVulkan-09) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Kevin Tsui 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 | -------------------------------------------------------------------------------- /LearnHoudini-01/LearnHoudini.hip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnHoudini-01/LearnHoudini.hip -------------------------------------------------------------------------------- /LearnHoudini-01/LearnHoudini.py: -------------------------------------------------------------------------------- 1 | node = hou.pwd() #获取当前节点 2 | geo = node.geometry() #获取当前节点的geo 3 | 4 | #创建顶点位置 5 | point_positions = ((0,0,0), (1,0,0), (1,1,0), (0,1,0)) 6 | #创建顶点位置索引 7 | poly_point_indices = ((0,1,2), (2,3,0)) 8 | 9 | points = [] 10 | for position in point_positions: 11 | #为当前geo创建Point 12 | point = geo.createPoint() 13 | point.setPosition(position) 14 | points.append(point) 15 | 16 | geo.addAttrib(hou.attribType.Vertex, "N", hou.Vector3(0, 0, 0)) #初始化法线参数 17 | geo.addAttrib(hou.attribType.Vertex, "uv", hou.Vector3(0, 0, 0)) #初始化UV参数 18 | for point_indices in poly_point_indices: 19 | #为当前geo创建Polygon 20 | poly = geo.createPolygon() 21 | list_index = poly_point_indices.index(point_indices) #获取当前循环数 22 | for point_index in point_indices: 23 | #为当前geo创建Vertex 24 | point = points[point_index] #通过Index找到对应的点 25 | vertex = poly.addVertex(point) #创建Vertex 26 | if list_index%2 == 0: #和2取余 27 | normal = hou.Vector3(0, 0, 1) #正方向法线 28 | else: 29 | normal = hou.Vector3(0, 0, -1) #反方向法线 30 | #设置法线属性 31 | vertex.setAttribValue("N", normal) 32 | #设置UV属性 33 | uv = hou.Vector3(point.position()[0], point.position()[1], 0) 34 | vertex.setAttribValue("uv", uv) -------------------------------------------------------------------------------- /LearnMetal-01/LearnMetal.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LearnMetal-01/LearnMetal.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /LearnMetal-01/LearnMetal.xcodeproj/project.xcworkspace/xcuserdata/kevintsuixu.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnMetal-01/LearnMetal.xcodeproj/project.xcworkspace/xcuserdata/kevintsuixu.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /LearnMetal-01/LearnMetal.xcodeproj/xcuserdata/kevintsuixu.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | LearnMetal.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /LearnMetal-01/LearnMetal/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // LearnMetal 4 | // 5 | // Created by kevintsuixu on 2022/3/20. 6 | // 7 | 8 | import UIKit 9 | 10 | @main 11 | class AppDelegate: UIResponder, UIApplicationDelegate { 12 | 13 | 14 | 15 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 16 | // Override point for customization after application launch. 17 | return true 18 | } 19 | 20 | // MARK: UISceneSession Lifecycle 21 | 22 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 23 | // Called when a new scene session is being created. 24 | // Use this method to select a configuration to create the new scene with. 25 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 26 | } 27 | 28 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 29 | // Called when the user discards a scene session. 30 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 31 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 32 | } 33 | 34 | 35 | } 36 | 37 | -------------------------------------------------------------------------------- /LearnMetal-01/LearnMetal/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /LearnMetal-01/LearnMetal/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "filename" : "IMG_LOGO_x120.jpg", 35 | "idiom" : "iphone", 36 | "scale" : "2x", 37 | "size" : "60x60" 38 | }, 39 | { 40 | "filename" : "IMG_LOGO_x180.jpg", 41 | "idiom" : "iphone", 42 | "scale" : "3x", 43 | "size" : "60x60" 44 | }, 45 | { 46 | "idiom" : "ipad", 47 | "scale" : "1x", 48 | "size" : "20x20" 49 | }, 50 | { 51 | "idiom" : "ipad", 52 | "scale" : "2x", 53 | "size" : "20x20" 54 | }, 55 | { 56 | "idiom" : "ipad", 57 | "scale" : "1x", 58 | "size" : "29x29" 59 | }, 60 | { 61 | "idiom" : "ipad", 62 | "scale" : "2x", 63 | "size" : "29x29" 64 | }, 65 | { 66 | "idiom" : "ipad", 67 | "scale" : "1x", 68 | "size" : "40x40" 69 | }, 70 | { 71 | "idiom" : "ipad", 72 | "scale" : "2x", 73 | "size" : "40x40" 74 | }, 75 | { 76 | "idiom" : "ipad", 77 | "scale" : "1x", 78 | "size" : "76x76" 79 | }, 80 | { 81 | "idiom" : "ipad", 82 | "scale" : "2x", 83 | "size" : "76x76" 84 | }, 85 | { 86 | "idiom" : "ipad", 87 | "scale" : "2x", 88 | "size" : "83.5x83.5" 89 | }, 90 | { 91 | "idiom" : "ios-marketing", 92 | "scale" : "1x", 93 | "size" : "1024x1024" 94 | } 95 | ], 96 | "info" : { 97 | "author" : "xcode", 98 | "version" : 1 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /LearnMetal-01/LearnMetal/Assets.xcassets/AppIcon.appiconset/IMG_LOGO_x120.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnMetal-01/LearnMetal/Assets.xcassets/AppIcon.appiconset/IMG_LOGO_x120.jpg -------------------------------------------------------------------------------- /LearnMetal-01/LearnMetal/Assets.xcassets/AppIcon.appiconset/IMG_LOGO_x180.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnMetal-01/LearnMetal/Assets.xcassets/AppIcon.appiconset/IMG_LOGO_x180.jpg -------------------------------------------------------------------------------- /LearnMetal-01/LearnMetal/Assets.xcassets/Background.imageset/Background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnMetal-01/LearnMetal/Assets.xcassets/Background.imageset/Background.png -------------------------------------------------------------------------------- /LearnMetal-01/LearnMetal/Assets.xcassets/Background.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Background.png", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /LearnMetal-01/LearnMetal/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /LearnMetal-01/LearnMetal/Assets.xcassets/IMG_LOGO.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "IMG_LOGO.png", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /LearnMetal-01/LearnMetal/Assets.xcassets/IMG_LOGO.imageset/IMG_LOGO.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnMetal-01/LearnMetal/Assets.xcassets/IMG_LOGO.imageset/IMG_LOGO.png -------------------------------------------------------------------------------- /LearnMetal-01/LearnMetal/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /LearnMetal-01/LearnMetal/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /LearnMetal-01/LearnMetal/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | $(PRODUCT_MODULE_NAME).SceneDelegate 36 | UISceneStoryboardFile 37 | Main 38 | 39 | 40 | 41 | 42 | UIApplicationSupportsIndirectInputEvents 43 | 44 | UILaunchStoryboardName 45 | LaunchScreen 46 | UIMainStoryboardFile 47 | Main 48 | UIRequiredDeviceCapabilities 49 | 50 | armv7 51 | 52 | UISupportedInterfaceOrientations 53 | 54 | UIInterfaceOrientationPortrait 55 | UIInterfaceOrientationLandscapeLeft 56 | UIInterfaceOrientationLandscapeRight 57 | 58 | UISupportedInterfaceOrientations~ipad 59 | 60 | UIInterfaceOrientationPortrait 61 | UIInterfaceOrientationPortraitUpsideDown 62 | UIInterfaceOrientationLandscapeLeft 63 | UIInterfaceOrientationLandscapeRight 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /LearnMetal-01/LearnMetal/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // LearnMetal 4 | // 5 | // Created by kevintsuixu on 2022/3/20. 6 | // 7 | 8 | import UIKit 9 | 10 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 11 | 12 | var window: UIWindow? 13 | 14 | 15 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 16 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 17 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 18 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 19 | guard let _ = (scene as? UIWindowScene) else { return } 20 | } 21 | 22 | func sceneDidDisconnect(_ scene: UIScene) { 23 | // Called as the scene is being released by the system. 24 | // This occurs shortly after the scene enters the background, or when its session is discarded. 25 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 26 | // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). 27 | } 28 | 29 | func sceneDidBecomeActive(_ scene: UIScene) { 30 | // Called when the scene has moved from an inactive state to an active state. 31 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 32 | } 33 | 34 | func sceneWillResignActive(_ scene: UIScene) { 35 | // Called when the scene will move from an active state to an inactive state. 36 | // This may occur due to temporary interruptions (ex. an incoming phone call). 37 | } 38 | 39 | func sceneWillEnterForeground(_ scene: UIScene) { 40 | // Called as the scene transitions from the background to the foreground. 41 | // Use this method to undo the changes made on entering the background. 42 | } 43 | 44 | func sceneDidEnterBackground(_ scene: UIScene) { 45 | // Called as the scene transitions from the foreground to the background. 46 | // Use this method to save data, release shared resources, and store enough scene-specific state information 47 | // to restore the scene back to its current state. 48 | } 49 | 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /LearnMetal-01/LearnMetal/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // LearnMetal 4 | // 5 | // Created by kevintsuixu on 2022/3/20. 6 | // 7 | 8 | import UIKit 9 | 10 | class ViewController: UIViewController { 11 | 12 | override func viewDidLoad() { 13 | super.viewDidLoad() 14 | // Do any additional setup after loading the view. 15 | } 16 | 17 | 18 | } 19 | 20 | -------------------------------------------------------------------------------- /LearnMetal-02/LearnMetal.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LearnMetal-02/LearnMetal.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /LearnMetal-02/LearnMetal.xcodeproj/project.xcworkspace/xcuserdata/kevintsuixu.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnMetal-02/LearnMetal.xcodeproj/project.xcworkspace/xcuserdata/kevintsuixu.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /LearnMetal-02/LearnMetal.xcodeproj/xcuserdata/kevintsuixu.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | LearnMetal.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /LearnMetal-02/LearnMetal/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // LearnMetal 4 | // 5 | // Created by kevintsuixu on 2022/3/20. 6 | // 7 | 8 | import UIKit 9 | 10 | @main 11 | class AppDelegate: UIResponder, UIApplicationDelegate { 12 | 13 | 14 | 15 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 16 | // Override point for customization after application launch. 17 | return true 18 | } 19 | 20 | // MARK: UISceneSession Lifecycle 21 | 22 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 23 | // Called when a new scene session is being created. 24 | // Use this method to select a configuration to create the new scene with. 25 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 26 | } 27 | 28 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 29 | // Called when the user discards a scene session. 30 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 31 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 32 | } 33 | 34 | 35 | } 36 | 37 | -------------------------------------------------------------------------------- /LearnMetal-02/LearnMetal/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /LearnMetal-02/LearnMetal/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "filename" : "IMG_LOGO_x120.jpg", 35 | "idiom" : "iphone", 36 | "scale" : "2x", 37 | "size" : "60x60" 38 | }, 39 | { 40 | "filename" : "IMG_LOGO_x180.jpg", 41 | "idiom" : "iphone", 42 | "scale" : "3x", 43 | "size" : "60x60" 44 | }, 45 | { 46 | "idiom" : "ipad", 47 | "scale" : "1x", 48 | "size" : "20x20" 49 | }, 50 | { 51 | "idiom" : "ipad", 52 | "scale" : "2x", 53 | "size" : "20x20" 54 | }, 55 | { 56 | "idiom" : "ipad", 57 | "scale" : "1x", 58 | "size" : "29x29" 59 | }, 60 | { 61 | "idiom" : "ipad", 62 | "scale" : "2x", 63 | "size" : "29x29" 64 | }, 65 | { 66 | "idiom" : "ipad", 67 | "scale" : "1x", 68 | "size" : "40x40" 69 | }, 70 | { 71 | "idiom" : "ipad", 72 | "scale" : "2x", 73 | "size" : "40x40" 74 | }, 75 | { 76 | "idiom" : "ipad", 77 | "scale" : "1x", 78 | "size" : "76x76" 79 | }, 80 | { 81 | "idiom" : "ipad", 82 | "scale" : "2x", 83 | "size" : "76x76" 84 | }, 85 | { 86 | "idiom" : "ipad", 87 | "scale" : "2x", 88 | "size" : "83.5x83.5" 89 | }, 90 | { 91 | "idiom" : "ios-marketing", 92 | "scale" : "1x", 93 | "size" : "1024x1024" 94 | } 95 | ], 96 | "info" : { 97 | "author" : "xcode", 98 | "version" : 1 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /LearnMetal-02/LearnMetal/Assets.xcassets/AppIcon.appiconset/IMG_LOGO_x120.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnMetal-02/LearnMetal/Assets.xcassets/AppIcon.appiconset/IMG_LOGO_x120.jpg -------------------------------------------------------------------------------- /LearnMetal-02/LearnMetal/Assets.xcassets/AppIcon.appiconset/IMG_LOGO_x180.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnMetal-02/LearnMetal/Assets.xcassets/AppIcon.appiconset/IMG_LOGO_x180.jpg -------------------------------------------------------------------------------- /LearnMetal-02/LearnMetal/Assets.xcassets/Background.imageset/Background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnMetal-02/LearnMetal/Assets.xcassets/Background.imageset/Background.png -------------------------------------------------------------------------------- /LearnMetal-02/LearnMetal/Assets.xcassets/Background.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "Background.png", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /LearnMetal-02/LearnMetal/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /LearnMetal-02/LearnMetal/Assets.xcassets/IMG_LOGO.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "IMG_LOGO.png", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /LearnMetal-02/LearnMetal/Assets.xcassets/IMG_LOGO.imageset/IMG_LOGO.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnMetal-02/LearnMetal/Assets.xcassets/IMG_LOGO.imageset/IMG_LOGO.png -------------------------------------------------------------------------------- /LearnMetal-02/LearnMetal/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /LearnMetal-02/LearnMetal/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /LearnMetal-02/LearnMetal/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | $(PRODUCT_MODULE_NAME).SceneDelegate 36 | UISceneStoryboardFile 37 | Main 38 | 39 | 40 | 41 | 42 | UIApplicationSupportsIndirectInputEvents 43 | 44 | UILaunchStoryboardName 45 | LaunchScreen 46 | UIMainStoryboardFile 47 | Main 48 | UIRequiredDeviceCapabilities 49 | 50 | armv7 51 | 52 | UISupportedInterfaceOrientations 53 | 54 | UIInterfaceOrientationPortrait 55 | UIInterfaceOrientationLandscapeLeft 56 | UIInterfaceOrientationLandscapeRight 57 | 58 | UISupportedInterfaceOrientations~ipad 59 | 60 | UIInterfaceOrientationPortrait 61 | UIInterfaceOrientationPortraitUpsideDown 62 | UIInterfaceOrientationLandscapeLeft 63 | UIInterfaceOrientationLandscapeRight 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /LearnMetal-02/LearnMetal/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // LearnMetal 4 | // 5 | // Created by kevintsuixu on 2022/3/20. 6 | // 7 | 8 | import UIKit 9 | 10 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 11 | 12 | var window: UIWindow? 13 | 14 | 15 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 16 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 17 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 18 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 19 | guard let _ = (scene as? UIWindowScene) else { return } 20 | } 21 | 22 | func sceneDidDisconnect(_ scene: UIScene) { 23 | // Called as the scene is being released by the system. 24 | // This occurs shortly after the scene enters the background, or when its session is discarded. 25 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 26 | // The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). 27 | } 28 | 29 | func sceneDidBecomeActive(_ scene: UIScene) { 30 | // Called when the scene has moved from an inactive state to an active state. 31 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 32 | } 33 | 34 | func sceneWillResignActive(_ scene: UIScene) { 35 | // Called when the scene will move from an active state to an inactive state. 36 | // This may occur due to temporary interruptions (ex. an incoming phone call). 37 | } 38 | 39 | func sceneWillEnterForeground(_ scene: UIScene) { 40 | // Called as the scene transitions from the background to the foreground. 41 | // Use this method to undo the changes made on entering the background. 42 | } 43 | 44 | func sceneDidEnterBackground(_ scene: UIScene) { 45 | // Called as the scene transitions from the foreground to the background. 46 | // Use this method to save data, release shared resources, and store enough scene-specific state information 47 | // to restore the scene back to its current state. 48 | } 49 | 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /LearnMetal-02/LearnMetal/Shaders.metal: -------------------------------------------------------------------------------- 1 | // 2 | // Shaders.metal 3 | // LearnMetal 4 | // 5 | // Created by kevintsuixu on 2022/3/20. 6 | // 7 | 8 | #include 9 | using namespace metal; 10 | 11 | // 创建一个顶点结构体,包含顶点位置和颜色 12 | struct Vertex{ 13 | float4 position [[position]]; 14 | float4 color; 15 | }; 16 | 17 | /** 创建VertexShader*/ 18 | vertex Vertex basic_vertex(constant Vertex *vertices [[buffer(0)]],uint vid [[vertex_id]]){ 19 | return vertices[vid]; 20 | } 21 | 22 | /** 创建FragmentShader*/ 23 | fragment float4 basic_fragment(Vertex vert [[stage_in]]){ 24 | return vert.color; 25 | } 26 | -------------------------------------------------------------------------------- /LearnMetal-02/LearnMetal/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // LearnMetal 4 | // 5 | // Created by kevintsuixu on 2022/3/20. 6 | // 7 | 8 | import UIKit 9 | import Metal 10 | import simd 11 | 12 | class ViewController: UIViewController { 13 | 14 | // 创建顶点结构体,包含顶点位置和顶点色 15 | struct Vertex { 16 | var position: vector_float4 17 | var color: vector_float4 18 | } 19 | 20 | // 创建顶点数据 21 | let vertexData = [Vertex(position: [0.0, 1.0, 0.0, 1.0], color: [1,0,0,1]),Vertex(position: [-1.0, -1.0, 0.0, 1.0], color: [0,1,0,1]),Vertex(position: [ 1.0, -1.0, 0.0, 1.0], color: [0,0,1,1])] 22 | 23 | var device: MTLDevice! // 指定硬件 24 | var metalLayer: CAMetalLayer! // 绘制图层 25 | var vertexBuffer: MTLBuffer! // VertexBuffer 26 | var pipelineState: MTLRenderPipelineState! // 渲染管线 27 | var commandQueue: MTLCommandQueue! // 指令队列 28 | 29 | var timer: CADisplayLink! // 显示器刷新率同步计时器 30 | 31 | override func viewDidLoad() { 32 | super.viewDidLoad() 33 | // Do any additional setup after loading the view. 34 | 35 | /**-------------------------------------------------*/ 36 | /** 指定默认硬件设备**/ 37 | device = MTLCreateSystemDefaultDevice() 38 | 39 | /**-------------------------------------------------*/ 40 | /** 创建CAMetalLayer**/ 41 | metalLayer = CAMetalLayer() // 创建一个新的CAMetalLayer 42 | metalLayer.device = device // 指定MTLDevice 43 | metalLayer.pixelFormat = .bgra8Unorm // 设置像素格式 8bit的RGBA 44 | metalLayer.framebufferOnly = true // 除非需要采样本层生成的贴图或开启新的绘制线程,设为true 45 | metalLayer.frame = view.layer.frame // 匹配view的layer帧数 46 | view.layer.addSublayer(metalLayer) // 加入主层,新创建的CAMetalLayer为子层 47 | 48 | /**-------------------------------------------------*/ 49 | /** 创建VertexBuffer*/ 50 | // 计算VertexData的存储大小 51 | let dataSize = vertexData.count * MemoryLayout.size(ofValue: vertexData[0]) 52 | // 在指定硬件的GPU上创建一个新的Buffer,从CPU往GPU的Buffer上发送数据。这里创建了一个空白的Buffer 53 | vertexBuffer = device.makeBuffer(bytes: vertexData, length: dataSize, options: []) 54 | 55 | /**-------------------------------------------------*/ 56 | /** 创建RenderPipeline渲染管线*/ 57 | // 通过调用makeDefaultLibrary可以访问所有预编译的Shader 58 | let defaultLibrary = device.makeDefaultLibrary()! 59 | let fragmentProgram = defaultLibrary.makeFunction(name: "basic_fragment") 60 | let vertexProgram = defaultLibrary.makeFunction(name: "basic_vertex") 61 | // 配置RenderPipeline参数,渲染输出的层就是CAMetalLayer本身 62 | let pipelineStateDescriptor = MTLRenderPipelineDescriptor() 63 | pipelineStateDescriptor.vertexFunction = vertexProgram 64 | pipelineStateDescriptor.fragmentFunction = fragmentProgram 65 | pipelineStateDescriptor.colorAttachments[0].pixelFormat = .bgra8Unorm 66 | // 编译RenderPipeline为PipelineState,调用更加高效 67 | pipelineState = try! device.makeRenderPipelineState(descriptor: pipelineStateDescriptor) 68 | 69 | /**-------------------------------------------------*/ 70 | /** 创建指令队列*/ 71 | commandQueue = device.makeCommandQueue() 72 | 73 | /**-------------------------------------------------*/ 74 | /** 初始化计时器*/ 75 | timer = CADisplayLink(target: self, selector: #selector(gameloop)) 76 | timer.add(to: RunLoop.main, forMode: .default) 77 | 78 | } // viewDidLoad 79 | 80 | func render() { 81 | /**-------------------------------------------------*/ 82 | /** 创建Render Pass Descriptor, 指定贴图渲染到什么位置,ClearColor等参数*/ 83 | guard let drawable = metalLayer?.nextDrawable() else { return } // 拿到之前上一帧的绘制 84 | let renderPassDescriptor = MTLRenderPassDescriptor() 85 | renderPassDescriptor.colorAttachments[0].texture = drawable.texture // 拿到绘制的贴图 86 | renderPassDescriptor.colorAttachments[0].loadAction = .clear // 贴图绘制之前先Clear 87 | renderPassDescriptor.colorAttachments[0].clearColor = MTLClearColor(red: 0.0, green: 104.0/255.0, blue: 55.0/255.0, alpha: 1.0) 88 | 89 | /**-------------------------------------------------*/ 90 | /** 创建指令队列的Buffer*/ 91 | let commandBuffer = commandQueue.makeCommandBuffer()! 92 | 93 | /**-------------------------------------------------*/ 94 | /** 创建指令队列的编码器*/ 95 | let renderEncoder = commandBuffer.makeRenderCommandEncoder(descriptor: renderPassDescriptor)! 96 | renderEncoder.setRenderPipelineState(pipelineState) 97 | renderEncoder.setVertexBuffer(vertexBuffer, offset: 0, index: 0) // 指定VertexBuffer 98 | renderEncoder.drawPrimitives(type: .triangle, vertexStart: 0, vertexCount: 3, instanceCount: 1) 99 | renderEncoder.endEncoding() 100 | 101 | /**-------------------------------------------------*/ 102 | /** 发送渲染指令*/ 103 | commandBuffer.present(drawable) // 确保GPU持有现在正在绘制的贴图 104 | commandBuffer.commit() // 发送指令 105 | } // render 106 | 107 | @objc func gameloop() { 108 | autoreleasepool { 109 | self.render() 110 | } 111 | } // gameloop 112 | 113 | } // class UIViewController 114 | 115 | -------------------------------------------------------------------------------- /LearnVulkan-01/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Function for building single example 2 | function(buildExample EXAMPLE_NAME) 3 | SET(EXAMPLE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/${EXAMPLE_NAME}) 4 | message(STATUS "Generating project file for example in ${EXAMPLE_FOLDER}") 5 | # Main 6 | # file(GLOB SOURCE *.cpp ${BASE_HEADERS} ${EXAMPLE_FOLDER}/*.cpp) 7 | SET(MAIN_CPP ${EXAMPLE_FOLDER}/${EXAMPLE_NAME}.cpp) 8 | if(EXISTS ${EXAMPLE_FOLDER}/main.cpp) 9 | SET(MAIN_CPP ${EXAMPLE_FOLDER}/main.cpp) 10 | ENDIF() 11 | if(EXISTS ${EXAMPLE_FOLDER}/${EXAMPLE_NAME}.h) 12 | SET(MAIN_HEADER ${EXAMPLE_FOLDER}/${EXAMPLE_NAME}.h) 13 | ENDIF() 14 | if(WIN32) 15 | add_executable(${EXAMPLE_NAME} WIN32 ${MAIN_CPP}) 16 | target_link_libraries(${EXAMPLE_NAME} ${Vulkan_LIBRARY} ${WINLIBS}) 17 | else(WIN32) 18 | add_executable(${EXAMPLE_NAME} ${MAIN_CPP}) 19 | target_link_libraries(${EXAMPLE_NAME}) 20 | endif(WIN32) 21 | 22 | set (CURRENT_WORKING_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) 23 | set_target_properties(${EXAMPLE_NAME} PROPERTIES WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) 24 | if(WIN32) 25 | set_target_properties(${EXAMPLE_NAME} PROPERTIES LINK_FLAGS /SUBSYSTEM:CONSOLE VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) 26 | endif(WIN32) 27 | if(APPLE) 28 | set_target_properties(${EXAMPLE_NAME} PROPERTIES XCODE_GENERATE_SCHEME TRUE XCODE_SCHEME_WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) 29 | endif(APPLE) 30 | target_link_libraries(${EXAMPLE_NAME} glfw glm) 31 | endfunction(buildExample) 32 | 33 | # Build all examples 34 | function(buildExamples) 35 | foreach(EXAMPLE ${EXAMPLES}) 36 | buildExample(${EXAMPLE}) 37 | endforeach(EXAMPLE) 38 | endfunction(buildExamples) 39 | 40 | set(EXAMPLES 41 | empty_window 42 | ) 43 | 44 | buildExamples() 45 | -------------------------------------------------------------------------------- /LearnVulkan-01/empty_window/empty_window.cpp: -------------------------------------------------------------------------------- 1 | // Copyright LearnVulkan-01: Empty Window, @xukai. All Rights Reserved. 2 | #define GLFW_INCLUDE_VULKAN 3 | #include 4 | 5 | #define GLM_FORCE_RADIANS 6 | #define GLM_FORCE_DEPTH_ZERO_TO_ONE 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | int main() { 13 | glfwInit(); 14 | 15 | glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); 16 | GLFWwindow* window = glfwCreateWindow(800, 600, "LearnVulkan-01: Empty Window", nullptr, nullptr); 17 | 18 | uint32_t extensionCount = 0; 19 | vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr); 20 | 21 | std::cout << extensionCount << " extensions supported\n"; 22 | 23 | glm::mat4 matrix; 24 | glm::vec4 vec; 25 | auto test = matrix * vec; 26 | 27 | while(!glfwWindowShouldClose(window)) { 28 | glfwPollEvents(); 29 | } 30 | 31 | glfwDestroyWindow(window); 32 | 33 | glfwTerminate(); 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /LearnVulkan-02/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Function for building single example 2 | function(buildExample EXAMPLE_NAME) 3 | SET(EXAMPLE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/${EXAMPLE_NAME}) 4 | message(STATUS "Generating project file for example in ${EXAMPLE_FOLDER}") 5 | # Main 6 | # file(GLOB SOURCE *.cpp ${BASE_HEADERS} ${EXAMPLE_FOLDER}/*.cpp) 7 | SET(MAIN_CPP ${EXAMPLE_FOLDER}/${EXAMPLE_NAME}.cpp) 8 | if(EXISTS ${EXAMPLE_FOLDER}/main.cpp) 9 | SET(MAIN_CPP ${EXAMPLE_FOLDER}/main.cpp) 10 | endif() 11 | if(EXISTS ${EXAMPLE_FOLDER}/${EXAMPLE_NAME}.h) 12 | SET(MAIN_HEADER ${EXAMPLE_FOLDER}/${EXAMPLE_NAME}.h) 13 | endif() 14 | if(WIN32) 15 | add_compile_options("$<$:/utf-8>") 16 | add_compile_options("$<$:/utf-8>") 17 | add_executable(${EXAMPLE_NAME} WIN32 ${MAIN_CPP}) 18 | target_link_libraries(${EXAMPLE_NAME} ${Vulkan_LIBRARY} ${WINLIBS}) 19 | else(WIN32) 20 | add_executable(${EXAMPLE_NAME} ${MAIN_CPP}) 21 | target_link_libraries(${EXAMPLE_NAME}) 22 | endif(WIN32) 23 | 24 | set (CURRENT_WORKING_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) 25 | set(SHADERS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${EXAMPLE_NAME}/shaders) 26 | set (SHADER_DEST ${CURRENT_WORKING_DIR}/Resources/Shaders) 27 | 28 | # Compile shader 29 | add_custom_command( 30 | OUTPUT SHADER_COMPILE 31 | COMMAND ${CMAKE_COMMAND} -E make_directory ${SHADER_DEST} 32 | COMMAND glslc ARGS ${SHADERS_SRC}/${EXAMPLE_NAME}.frag -o ${SHADER_DEST}/${EXAMPLE_NAME}_frag.spv 33 | COMMAND glslc ARGS ${SHADERS_SRC}/${EXAMPLE_NAME}.vert -o ${SHADER_DEST}/${EXAMPLE_NAME}_vert.spv 34 | WORKING_DIRECTORY ${SHADERS_SRC} 35 | DEPENDS ${SHADERS_SRC} ${SHADER_SOURCES} 36 | COMMENT "Compiling Shaders" 37 | VERBATIM 38 | ) 39 | 40 | set(COMPILE_SHADER_TARGET ${EXAMPLE_NAME}_shader) 41 | set(SHADER_SOURCES ${SHADERS_SRC}/${EXAMPLE_NAME}.frag ${SHADERS_SRC}/${EXAMPLE_NAME}.vert) 42 | add_custom_target(${COMPILE_SHADER_TARGET} ALL DEPENDS SHADER_COMPILE SOURCES ${SHADER_SOURCES}) 43 | add_dependencies (${EXAMPLE_NAME} ${COMPILE_SHADER_TARGET}) 44 | 45 | set_target_properties(${EXAMPLE_NAME} PROPERTIES WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 46 | set_target_properties(${EXAMPLE_NAME} PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF) 47 | if(WIN32) 48 | set_target_properties(${EXAMPLE_NAME} PROPERTIES LINK_FLAGS /SUBSYSTEM:CONSOLE VS_DEBUGGER_WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 49 | endif(WIN32) 50 | if(APPLE) 51 | set_target_properties(${EXAMPLE_NAME} PROPERTIES XCODE_GENERATE_SCHEME TRUE XCODE_SCHEME_WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 52 | endif(APPLE) 53 | target_link_libraries(${EXAMPLE_NAME} glfw glm) 54 | endfunction(buildExample) 55 | 56 | # Build all examples 57 | function(buildExamples) 58 | foreach(EXAMPLE ${EXAMPLES}) 59 | buildExample(${EXAMPLE}) 60 | endforeach(EXAMPLE) 61 | endfunction(buildExamples) 62 | 63 | set(EXAMPLES 64 | draw_the_triangle 65 | ) 66 | 67 | buildExamples() 68 | -------------------------------------------------------------------------------- /LearnVulkan-02/draw_the_triangle/shaders/draw_the_triangle.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | 5 | layout(location = 0) out vec4 outColor; 6 | 7 | void main() { 8 | outColor = vec4(fragColor, 1.0); 9 | } 10 | -------------------------------------------------------------------------------- /LearnVulkan-02/draw_the_triangle/shaders/draw_the_triangle.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) out vec3 fragColor; 4 | 5 | vec2 positions[3] = vec2[]( 6 | vec2(0.0, -1.0), 7 | vec2(1.0, 1.0), 8 | vec2(-1.0, 1.0) 9 | ); 10 | 11 | vec3 colors[3] = vec3[]( 12 | vec3(1.0, 0.0, 0.0), 13 | vec3(0.0, 1.0, 0.0), 14 | vec3(0.0, 0.0, 1.0) 15 | ); 16 | 17 | void main() { 18 | gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0); 19 | fragColor = colors[gl_VertexIndex]; 20 | } 21 | -------------------------------------------------------------------------------- /LearnVulkan-03/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Function for building single example 2 | function(buildExample EXAMPLE_NAME) 3 | SET(EXAMPLE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/${EXAMPLE_NAME}) 4 | message(STATUS "Generating project file for example in ${EXAMPLE_FOLDER}") 5 | # Main 6 | # file(GLOB SOURCE *.cpp ${BASE_HEADERS} ${EXAMPLE_FOLDER}/*.cpp) 7 | SET(MAIN_CPP ${EXAMPLE_FOLDER}/${EXAMPLE_NAME}.cpp) 8 | if(EXISTS ${EXAMPLE_FOLDER}/main.cpp) 9 | SET(MAIN_CPP ${EXAMPLE_FOLDER}/main.cpp) 10 | endif() 11 | if(EXISTS ${EXAMPLE_FOLDER}/${EXAMPLE_NAME}.h) 12 | SET(MAIN_HEADER ${EXAMPLE_FOLDER}/${EXAMPLE_NAME}.h) 13 | endif() 14 | if(WIN32) 15 | add_compile_options("$<$:/utf-8>") 16 | add_compile_options("$<$:/utf-8>") 17 | add_executable(${EXAMPLE_NAME} WIN32 ${MAIN_CPP}) 18 | target_link_libraries(${EXAMPLE_NAME} ${Vulkan_LIBRARY} ${WINLIBS}) 19 | else(WIN32) 20 | add_executable(${EXAMPLE_NAME} ${MAIN_CPP}) 21 | target_link_libraries(${EXAMPLE_NAME}) 22 | endif(WIN32) 23 | 24 | set (CURRENT_WORKING_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) 25 | set(SHADERS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${EXAMPLE_NAME}/shaders) 26 | set (SHADER_DEST ${CURRENT_WORKING_DIR}/Resources/Shaders) 27 | 28 | # Compile shader 29 | add_custom_command( 30 | OUTPUT SHADER_COMPILE 31 | COMMAND ${CMAKE_COMMAND} -E make_directory ${SHADER_DEST} 32 | COMMAND glslc ARGS ${SHADERS_SRC}/${EXAMPLE_NAME}.frag -o ${SHADER_DEST}/${EXAMPLE_NAME}_frag.spv 33 | COMMAND glslc ARGS ${SHADERS_SRC}/${EXAMPLE_NAME}.vert -o ${SHADER_DEST}/${EXAMPLE_NAME}_vert.spv 34 | WORKING_DIRECTORY ${SHADERS_SRC} 35 | DEPENDS ${SHADERS_SRC} ${SHADER_SOURCES} 36 | COMMENT "Compiling Shaders" 37 | VERBATIM 38 | ) 39 | 40 | set(COMPILE_SHADER_TARGET ${EXAMPLE_NAME}_shader) 41 | set(SHADER_SOURCES ${SHADERS_SRC}/${EXAMPLE_NAME}.frag ${SHADERS_SRC}/${EXAMPLE_NAME}.vert) 42 | add_custom_target(${COMPILE_SHADER_TARGET} ALL DEPENDS SHADER_COMPILE SOURCES ${SHADER_SOURCES}) 43 | add_dependencies (${EXAMPLE_NAME} ${COMPILE_SHADER_TARGET}) 44 | 45 | set_target_properties(${EXAMPLE_NAME} PROPERTIES WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 46 | set_target_properties(${EXAMPLE_NAME} PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF) 47 | if(WIN32) 48 | set_target_properties(${EXAMPLE_NAME} PROPERTIES LINK_FLAGS /SUBSYSTEM:CONSOLE VS_DEBUGGER_WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 49 | endif(WIN32) 50 | if(APPLE) 51 | set_target_properties(${EXAMPLE_NAME} PROPERTIES XCODE_GENERATE_SCHEME TRUE XCODE_SCHEME_WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 52 | endif(APPLE) 53 | target_link_libraries(${EXAMPLE_NAME} glfw glm) 54 | endfunction(buildExample) 55 | 56 | # Build all examples 57 | function(buildExamples) 58 | foreach(EXAMPLE ${EXAMPLES}) 59 | buildExample(${EXAMPLE}) 60 | endforeach(EXAMPLE) 61 | endfunction(buildExamples) 62 | 63 | set(EXAMPLES 64 | draw_with_buffers 65 | ) 66 | 67 | buildExamples() 68 | -------------------------------------------------------------------------------- /LearnVulkan-03/draw_with_buffers/shaders/draw_with_buffers.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec3 fragColor; 4 | 5 | layout(location = 0) out vec4 outColor; 6 | 7 | void main() 8 | { 9 | outColor = vec4(fragColor, 1.0); 10 | } 11 | -------------------------------------------------------------------------------- /LearnVulkan-03/draw_with_buffers/shaders/draw_with_buffers.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(set = 0, binding = 0) uniform UniformBufferObject 4 | { 5 | mat4 model; 6 | mat4 view; 7 | mat4 proj; 8 | } ubo; 9 | 10 | layout(location = 0) in vec3 inPosition; 11 | layout(location = 1) in vec3 inColor; 12 | 13 | layout(location = 0) out vec3 fragColor; 14 | 15 | void main() 16 | { 17 | // Render object with MVP 18 | gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0); 19 | fragColor = inColor; 20 | } 21 | -------------------------------------------------------------------------------- /LearnVulkan-04/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Function for building single example 2 | function(buildProject PROJECT_NAME) 3 | SET(EXAMPLE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}) 4 | message(STATUS "Generating project file for example in ${EXAMPLE_FOLDER}") 5 | # Main 6 | # file(GLOB SOURCE *.cpp ${BASE_HEADERS} ${EXAMPLE_FOLDER}/*.cpp) 7 | SET(MAIN_CPP ${EXAMPLE_FOLDER}/${PROJECT_NAME}.cpp) 8 | if(EXISTS ${EXAMPLE_FOLDER}/main.cpp) 9 | SET(MAIN_CPP ${EXAMPLE_FOLDER}/main.cpp) 10 | endif() 11 | if(EXISTS ${EXAMPLE_FOLDER}/${PROJECT_NAME}.h) 12 | SET(MAIN_HEADER ${EXAMPLE_FOLDER}/${PROJECT_NAME}.h) 13 | endif() 14 | if(WIN32) 15 | add_compile_options("$<$:/utf-8>") 16 | add_compile_options("$<$:/utf-8>") 17 | add_executable(${PROJECT_NAME} WIN32 ${MAIN_CPP}) 18 | target_link_libraries(${PROJECT_NAME} ${Vulkan_LIBRARY} ${WINLIBS}) 19 | else(WIN32) 20 | add_executable(${PROJECT_NAME} ${MAIN_CPP}) 21 | target_link_libraries(${PROJECT_NAME}) 22 | endif(WIN32) 23 | 24 | set (CURRENT_WORKING_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) 25 | set (SHADERS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/shaders) 26 | set (TEXTURE_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/textures) 27 | set (SHADERS_DEST ${CURRENT_WORKING_DIR}/Resources/Shaders) 28 | set (TEXTURE_DEST ${CURRENT_WORKING_DIR}/Resources/Textures) 29 | 30 | # Compile shader and copy texures 31 | add_custom_command( 32 | OUTPUT SHADER_COMPILE 33 | COMMAND ${CMAKE_COMMAND} -E make_directory ${SHADERS_DEST} 34 | COMMAND glslc ARGS ${SHADERS_SRC}/${PROJECT_NAME}.frag -o ${SHADERS_DEST}/${PROJECT_NAME}_frag.spv 35 | COMMAND glslc ARGS ${SHADERS_SRC}/${PROJECT_NAME}.vert -o ${SHADERS_DEST}/${PROJECT_NAME}_vert.spv 36 | WORKING_DIRECTORY ${SHADERS_SRC} 37 | DEPENDS ${SHADERS_SRC} ${SHADER_SOURCES} 38 | VERBATIM 39 | COMMENT "Compiling Shaders!" 40 | COMMAND ${CMAKE_COMMAND} -E copy ${TEXTURE_SRC}/botw_mifa.png ${TEXTURE_DEST}/botw_mifa.png 41 | COMMENT "Copying Textures!" 42 | ) 43 | 44 | set(COMPILE_SHADER_TARGET ${PROJECT_NAME}_shader) 45 | set(SHADER_SOURCES ${SHADERS_SRC}/${PROJECT_NAME}.frag ${SHADERS_SRC}/${PROJECT_NAME}.vert) 46 | add_custom_target(${COMPILE_SHADER_TARGET} ALL DEPENDS SHADER_COMPILE SOURCES ${SHADER_SOURCES}) 47 | add_dependencies (${PROJECT_NAME} ${COMPILE_SHADER_TARGET}) 48 | 49 | set_target_properties(${PROJECT_NAME} PROPERTIES WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 50 | set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF) 51 | if(WIN32) 52 | set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS /SUBSYSTEM:CONSOLE VS_DEBUGGER_WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 53 | endif(WIN32) 54 | if(APPLE) 55 | set_target_properties(${PROJECT_NAME} PROPERTIES XCODE_GENERATE_SCHEME TRUE XCODE_SCHEME_WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 56 | endif(APPLE) 57 | target_link_libraries(${PROJECT_NAME} glfw glm) 58 | endfunction(buildProject) 59 | 60 | # Build all examples 61 | function(buildProjects) 62 | foreach(PROJECT ${PROJECTS}) 63 | buildProject(${PROJECT}) 64 | endforeach(PROJECT) 65 | endfunction(buildProjects) 66 | 67 | set(PROJECTS 68 | draw_with_texture 69 | ) 70 | 71 | buildProjects() 72 | -------------------------------------------------------------------------------- /LearnVulkan-04/draw_with_texture/shaders/draw_with_texture.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(binding = 1) uniform sampler2D texSampler; 4 | 5 | layout(location = 0) in vec3 fragColor; 6 | layout(location = 1) in vec2 fragTexCoord; 7 | 8 | layout(location = 0) out vec4 outColor; 9 | 10 | void main() 11 | { 12 | outColor = vec4(fragColor * texture(texSampler, fragTexCoord).rgb, 1.0); 13 | } 14 | -------------------------------------------------------------------------------- /LearnVulkan-04/draw_with_texture/shaders/draw_with_texture.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(set = 0, binding = 0) uniform UniformBufferObject 4 | { 5 | mat4 model; 6 | mat4 view; 7 | mat4 proj; 8 | } ubo; 9 | 10 | layout(location = 0) in vec3 inPosition; 11 | layout(location = 1) in vec3 inColor; 12 | layout(location = 2) in vec2 inTexCoord; 13 | 14 | layout(location = 0) out vec3 fragColor; 15 | layout(location = 1) out vec2 fragTexCoord; 16 | 17 | void main() 18 | { 19 | // Render object with MVP 20 | gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0); 21 | fragColor = inColor; 22 | fragTexCoord = inTexCoord; 23 | } 24 | -------------------------------------------------------------------------------- /LearnVulkan-04/draw_with_texture/textures/botw_mifa.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-04/draw_with_texture/textures/botw_mifa.png -------------------------------------------------------------------------------- /LearnVulkan-05/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Function for building single example 2 | include(CMakeParseArguments) 3 | 4 | function(AddIconToBinary AppSources) 5 | set(Options) 6 | set(OneValueArgs OUTFILE_BASENAME) 7 | set(MultiValueArgs ICONS) 8 | cmake_parse_arguments(ARG "${Options}" "${OneValueArgs}" "${MultiValueArgs}" ${ARGN}) 9 | if (NOT ARG_ICONS) 10 | message(FATAL_ERROR "No ICONS argument given to AddIconToBinary") 11 | endif() 12 | if (ARG_UNPARSED_ARGUMENTS) 13 | message(FATAL_ERROR "Unexpected arguments to ecm_add_app_icon: ${ARG_UNPARSED_ARGUMENTS}") 14 | endif() 15 | foreach (icon ${ARG_ICONS}) 16 | get_filename_component(IconFull ${icon} ABSOLUTE) 17 | get_filename_component(IconType ${IconFull} EXT) 18 | get_filename_component(IconName ${IconFull} NAME_WE) 19 | if (APPLE) 20 | if (${IconType} STREQUAL ".icns") 21 | set(IconFullOutput ${CMAKE_CURRENT_BINARY_DIR}/${IconName}.icns) 22 | configure_file(${IconFull} ${IconFullOutput} COPYONLY) 23 | set(MACOSX_BUNDLE_ICON_FILE ${IconName}.icns PARENT_SCOPE) 24 | set(${AppSources} "${${AppSources}};${IconFullOutput}" PARENT_SCOPE) 25 | set_source_files_properties(${IconFullOutput} PROPERTIES MACOSX_PACKAGE_LOCATION Resources) 26 | return() 27 | endif() 28 | endif() 29 | if (MSVC) 30 | if (${IconType} STREQUAL ".ico") 31 | set(IconFullOutput ${CMAKE_CURRENT_BINARY_DIR}/${IconName}.ico) 32 | configure_file(${IconFull} ${IconFullOutput} COPYONLY) 33 | file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${IconName}.rc.in" "IDI_ICON1 ICON DISCARDABLE\"${IconName}.ico\"\n") 34 | add_custom_command( 35 | OUTPUT "${IconName}.rc" 36 | COMMAND ${CMAKE_COMMAND} 37 | ARGS -E copy "${IconName}.rc.in" "${IconName}.rc" 38 | DEPENDS "${IconName}.ico" 39 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") 40 | set(${AppSources} "${${AppSources}};${IconName}.rc" PARENT_SCOPE) 41 | return() 42 | endif() 43 | endif() 44 | endforeach() 45 | return() 46 | endfunction() 47 | 48 | function(buildProject PROJECT_NAME) 49 | SET(EXAMPLE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}) 50 | message(STATUS "Generating project file for example in ${EXAMPLE_FOLDER}") 51 | # Main 52 | # file(GLOB SOURCE *.cpp ${BASE_HEADERS} ${EXAMPLE_FOLDER}/*.cpp) 53 | SET(MAIN_CPP ${EXAMPLE_FOLDER}/${PROJECT_NAME}.cpp) 54 | set (CURRENT_WORKING_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) 55 | set (ICONS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/appicons) 56 | set (ICONS_DEST ${CURRENT_WORKING_DIR}/Resources/Appicons) 57 | set (SHADERS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/shaders) 58 | set (SHADERS_DEST ${CURRENT_WORKING_DIR}/Resources/Shaders) 59 | set (RESOURCES_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}) 60 | set (RESOURCES_DEST ${CURRENT_WORKING_DIR}/Resources) 61 | 62 | if(EXISTS ${EXAMPLE_FOLDER}/main.cpp) 63 | SET(MAIN_CPP ${EXAMPLE_FOLDER}/main.cpp) 64 | endif() 65 | if(EXISTS ${EXAMPLE_FOLDER}/${PROJECT_NAME}.h) 66 | SET(MAIN_HEADER ${EXAMPLE_FOLDER}/${PROJECT_NAME}.h) 67 | endif() 68 | # Set application icon 69 | AddIconToBinary(MAIN_CPP ICONS ${ICONS_SRC}/vulkan_renderer.ico ${ICONS_SRC}/vulkan_renderer.icns) 70 | if(WIN32) 71 | add_compile_options("$<$:/utf-8>") 72 | add_compile_options("$<$:/utf-8>") 73 | add_executable(${PROJECT_NAME} WIN32 ${MAIN_CPP}) 74 | target_link_libraries(${PROJECT_NAME} ${Vulkan_LIBRARY} ${WINLIBS}) 75 | else(WIN32) 76 | add_executable(${PROJECT_NAME} ${MAIN_CPP}) 77 | target_link_libraries(${PROJECT_NAME}) 78 | endif(WIN32) 79 | 80 | # Compile shader and copy texures 81 | add_custom_command( 82 | OUTPUT SHADER_COMPILE 83 | COMMAND ${CMAKE_COMMAND} -E make_directory ${SHADERS_DEST} 84 | COMMAND glslc ARGS ${SHADERS_SRC}/${PROJECT_NAME}.frag -o ${SHADERS_DEST}/${PROJECT_NAME}_frag.spv 85 | COMMAND glslc ARGS ${SHADERS_SRC}/${PROJECT_NAME}.vert -o ${SHADERS_DEST}/${PROJECT_NAME}_vert.spv 86 | COMMAND glslc ARGS ${SHADERS_SRC}/${PROJECT_NAME}_bg.frag -o ${SHADERS_DEST}/${PROJECT_NAME}_bg_frag.spv 87 | COMMAND glslc ARGS ${SHADERS_SRC}/${PROJECT_NAME}_bg.vert -o ${SHADERS_DEST}/${PROJECT_NAME}_bg_vert.spv 88 | WORKING_DIRECTORY ${SHADERS_SRC} 89 | DEPENDS ${SHADERS_SRC} ${SHADER_SOURCES} 90 | COMMENT "Compiling Shaders!" 91 | VERBATIM 92 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${ICONS_SRC}/ ${ICONS_DEST}/ 93 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCES_SRC}/textures/ ${RESOURCES_DEST}/Textures/ 94 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCES_SRC}/models/ ${RESOURCES_DEST}/Models/ 95 | COMMENT "Copying Resources Success!" 96 | VERBATIM 97 | ) 98 | 99 | set(COMPILE_SHADER_TARGET ${PROJECT_NAME}_shader) 100 | set(SHADER_SOURCES ${SHADERS_SRC}/${PROJECT_NAME}.frag ${SHADERS_SRC}/${PROJECT_NAME}.vert ${SHADERS_SRC}/${PROJECT_NAME}_bg.frag ${SHADERS_SRC}/${PROJECT_NAME}_bg.vert) 101 | add_custom_target(${COMPILE_SHADER_TARGET} ALL DEPENDS SHADER_COMPILE SOURCES ${SHADER_SOURCES}) 102 | add_dependencies (${PROJECT_NAME} ${COMPILE_SHADER_TARGET}) 103 | 104 | set_target_properties(${PROJECT_NAME} PROPERTIES WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 105 | set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF) 106 | if(WIN32) 107 | set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS /SUBSYSTEM:CONSOLE VS_DEBUGGER_WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 108 | endif(WIN32) 109 | if(APPLE) 110 | set_target_properties(${PROJECT_NAME} PROPERTIES XCODE_GENERATE_SCHEME TRUE XCODE_SCHEME_WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 111 | endif(APPLE) 112 | target_link_libraries(${PROJECT_NAME} glfw glm) 113 | endfunction(buildProject) 114 | 115 | # Build all examples 116 | function(buildProjects) 117 | foreach(PROJECT ${PROJECTS}) 118 | buildProject(${PROJECT}) 119 | endforeach(PROJECT) 120 | endfunction(buildProjects) 121 | 122 | set(PROJECTS 123 | draw_the_scene 124 | ) 125 | 126 | buildProjects() 127 | -------------------------------------------------------------------------------- /LearnVulkan-05/draw_the_scene/appicons/vulkan_renderer.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-05/draw_the_scene/appicons/vulkan_renderer.icns -------------------------------------------------------------------------------- /LearnVulkan-05/draw_the_scene/appicons/vulkan_renderer.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-05/draw_the_scene/appicons/vulkan_renderer.ico -------------------------------------------------------------------------------- /LearnVulkan-05/draw_the_scene/appicons/vulkan_renderer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-05/draw_the_scene/appicons/vulkan_renderer.png -------------------------------------------------------------------------------- /LearnVulkan-05/draw_the_scene/appicons/vulkan_renderer_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-05/draw_the_scene/appicons/vulkan_renderer_small.png -------------------------------------------------------------------------------- /LearnVulkan-05/draw_the_scene/shaders/draw_the_scene.frag: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-05/draw_the_scene/shaders/draw_the_scene.frag -------------------------------------------------------------------------------- /LearnVulkan-05/draw_the_scene/shaders/draw_the_scene.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | // push constants block 4 | layout( push_constant ) uniform constants 5 | { 6 | float time; 7 | } global; 8 | 9 | layout(set = 0, binding = 0) uniform UniformBufferObject 10 | { 11 | mat4 model; 12 | mat4 view; 13 | mat4 proj; 14 | } ubo; 15 | 16 | layout(location = 0) in vec3 inPosition; 17 | layout(location = 1) in vec3 inColor; 18 | layout(location = 2) in vec2 inTexCoord; 19 | 20 | layout(location = 0) out vec3 fragColor; 21 | layout(location = 1) out vec2 fragTexCoord; 22 | 23 | void main() 24 | { 25 | // vec3 newPosition = vec3(inPosition.x, inPosition.y, inPosition.z + sin(global.time) * 0.25); 26 | // Render object with MVP 27 | gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0); 28 | fragColor = inColor; 29 | fragTexCoord = inTexCoord; 30 | } -------------------------------------------------------------------------------- /LearnVulkan-05/draw_the_scene/shaders/draw_the_scene_bg.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(binding = 1) uniform sampler2D texSampler; 4 | 5 | layout(location = 0) in vec3 fragColor; 6 | layout(location = 1) in vec2 fragTexCoord; 7 | 8 | layout(location = 0) out vec4 outColor; 9 | 10 | void main() { 11 | outColor = vec4(texture(texSampler, fragTexCoord).rgb, 1.0); 12 | } 13 | -------------------------------------------------------------------------------- /LearnVulkan-05/draw_the_scene/shaders/draw_the_scene_bg.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) out vec3 fragColor; 4 | layout(location = 1) out vec2 fragTexCoord; 5 | 6 | vec2 positions[6] = vec2[]( 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 | vec2(1.0, 1.0) 13 | ); 14 | 15 | vec3 colors[6] = vec3[]( 16 | vec3(1.0, 0.0, 0.0), 17 | vec3(0.0, 1.0, 0.0), 18 | vec3(0.0, 0.0, 1.0), 19 | vec3(0.0, 0.0, 1.0), 20 | vec3(0.0, 1.0, 0.0), 21 | vec3(1.0, 0.0, 0.0) 22 | ); 23 | 24 | vec2 uvs[6] = vec2[]( 25 | vec2(0.0, 0.0), 26 | vec2(1.0, 1.0), 27 | vec2(0.0, 1.0), 28 | vec2(0.0, 0.0), 29 | vec2(1.0, 0.0), 30 | vec2(1.0, 1.0) 31 | ); 32 | 33 | void main() { 34 | gl_Position = vec4(positions[gl_VertexIndex], 1.0, 1.0); 35 | fragColor = colors[gl_VertexIndex]; 36 | fragTexCoord = uvs[gl_VertexIndex]; 37 | } 38 | -------------------------------------------------------------------------------- /LearnVulkan-05/draw_the_scene/textures/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-05/draw_the_scene/textures/background.png -------------------------------------------------------------------------------- /LearnVulkan-05/draw_the_scene/textures/hylian_shield_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-05/draw_the_scene/textures/hylian_shield_c.png -------------------------------------------------------------------------------- /LearnVulkan-05/draw_the_scene/textures/hylian_shield_o.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-05/draw_the_scene/textures/hylian_shield_o.png -------------------------------------------------------------------------------- /LearnVulkan-05/draw_the_scene/textures/master_sword_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-05/draw_the_scene/textures/master_sword_c.png -------------------------------------------------------------------------------- /LearnVulkan-05/draw_the_scene/textures/master_sword_o.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-05/draw_the_scene/textures/master_sword_o.png -------------------------------------------------------------------------------- /LearnVulkan-05/draw_the_scene/textures/steath_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-05/draw_the_scene/textures/steath_c.png -------------------------------------------------------------------------------- /LearnVulkan-05/draw_the_scene/textures/steath_o.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-05/draw_the_scene/textures/steath_o.png -------------------------------------------------------------------------------- /LearnVulkan-06/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Function for building single example 2 | include(CMakeParseArguments) 3 | 4 | function(AddIconToBinary AppSources) 5 | set(Options) 6 | set(OneValueArgs OUTFILE_BASENAME) 7 | set(MultiValueArgs ICONS) 8 | cmake_parse_arguments(ARG "${Options}" "${OneValueArgs}" "${MultiValueArgs}" ${ARGN}) 9 | if (NOT ARG_ICONS) 10 | message(FATAL_ERROR "No ICONS argument given to AddIconToBinary") 11 | endif() 12 | if (ARG_UNPARSED_ARGUMENTS) 13 | message(FATAL_ERROR "Unexpected arguments to ecm_add_app_icon: ${ARG_UNPARSED_ARGUMENTS}") 14 | endif() 15 | foreach (icon ${ARG_ICONS}) 16 | get_filename_component(IconFull ${icon} ABSOLUTE) 17 | get_filename_component(IconType ${IconFull} EXT) 18 | get_filename_component(IconName ${IconFull} NAME_WE) 19 | if (APPLE) 20 | if (${IconType} STREQUAL ".icns") 21 | set(IconFullOutput ${CMAKE_CURRENT_BINARY_DIR}/${IconName}.icns) 22 | configure_file(${IconFull} ${IconFullOutput} COPYONLY) 23 | set(MACOSX_BUNDLE_ICON_FILE ${IconName}.icns PARENT_SCOPE) 24 | set(${AppSources} "${${AppSources}};${IconFullOutput}" PARENT_SCOPE) 25 | set_source_files_properties(${IconFullOutput} PROPERTIES MACOSX_PACKAGE_LOCATION Resources) 26 | return() 27 | endif() 28 | endif() 29 | if (MSVC) 30 | if (${IconType} STREQUAL ".ico") 31 | set(IconFullOutput ${CMAKE_CURRENT_BINARY_DIR}/${IconName}.ico) 32 | configure_file(${IconFull} ${IconFullOutput} COPYONLY) 33 | file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${IconName}.rc.in" "IDI_ICON1 ICON DISCARDABLE\"${IconName}.ico\"\n") 34 | add_custom_command( 35 | OUTPUT "${IconName}.rc" 36 | COMMAND ${CMAKE_COMMAND} 37 | ARGS -E copy "${IconName}.rc.in" "${IconName}.rc" 38 | DEPENDS "${IconName}.ico" 39 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") 40 | set(${AppSources} "${${AppSources}};${IconName}.rc" PARENT_SCOPE) 41 | return() 42 | endif() 43 | endif() 44 | endforeach() 45 | return() 46 | endfunction() 47 | 48 | function(buildProject PROJECT_NAME) 49 | SET(EXAMPLE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}) 50 | message(STATUS "Generating project file for example in ${EXAMPLE_FOLDER}") 51 | # Main 52 | # file(GLOB SOURCE *.cpp ${BASE_HEADERS} ${EXAMPLE_FOLDER}/*.cpp) 53 | SET(MAIN_CPP ${EXAMPLE_FOLDER}/${PROJECT_NAME}.cpp) 54 | set (CURRENT_WORKING_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) 55 | set (ICONS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/appicons) 56 | set (ICONS_DEST ${CURRENT_WORKING_DIR}/Resources/Appicons) 57 | set (SHADERS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/shaders) 58 | set (SHADERS_DEST ${CURRENT_WORKING_DIR}/Resources/Shaders) 59 | set (RESOURCES_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}) 60 | set (RESOURCES_DEST ${CURRENT_WORKING_DIR}/Resources) 61 | 62 | if(EXISTS ${EXAMPLE_FOLDER}/main.cpp) 63 | SET(MAIN_CPP ${EXAMPLE_FOLDER}/main.cpp) 64 | endif() 65 | if(EXISTS ${EXAMPLE_FOLDER}/${PROJECT_NAME}.h) 66 | SET(MAIN_HEADER ${EXAMPLE_FOLDER}/${PROJECT_NAME}.h) 67 | endif() 68 | # Set application icon 69 | AddIconToBinary(MAIN_CPP ICONS ${ICONS_SRC}/vulkan_renderer.ico ${ICONS_SRC}/vulkan_renderer.icns) 70 | if(WIN32) 71 | add_compile_options("$<$:/utf-8>") 72 | add_compile_options("$<$:/utf-8>") 73 | add_executable(${PROJECT_NAME} WIN32 ${MAIN_CPP}) 74 | target_link_libraries(${PROJECT_NAME} ${Vulkan_LIBRARY} ${WINLIBS}) 75 | else(WIN32) 76 | add_executable(${PROJECT_NAME} ${MAIN_CPP}) 77 | target_link_libraries(${PROJECT_NAME}) 78 | endif(WIN32) 79 | 80 | # Compile shader and copy texures 81 | add_custom_command( 82 | OUTPUT SHADER_COMPILE 83 | COMMAND ${CMAKE_COMMAND} -E make_directory ${SHADERS_DEST} 84 | COMMAND glslc ARGS ${SHADERS_SRC}/${PROJECT_NAME}.frag -o ${SHADERS_DEST}/${PROJECT_NAME}_frag.spv 85 | COMMAND glslc ARGS ${SHADERS_SRC}/${PROJECT_NAME}.vert -o ${SHADERS_DEST}/${PROJECT_NAME}_vert.spv 86 | COMMAND glslc ARGS ${SHADERS_SRC}/${PROJECT_NAME}_bg.frag -o ${SHADERS_DEST}/${PROJECT_NAME}_bg_frag.spv 87 | COMMAND glslc ARGS ${SHADERS_SRC}/${PROJECT_NAME}_bg.vert -o ${SHADERS_DEST}/${PROJECT_NAME}_bg_vert.spv 88 | WORKING_DIRECTORY ${SHADERS_SRC} 89 | DEPENDS ${SHADERS_SRC} ${SHADER_SOURCES} 90 | COMMENT "Compiling Shaders Success!" 91 | VERBATIM 92 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${ICONS_SRC}/ ${ICONS_DEST}/ 93 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCES_SRC}/textures/ ${RESOURCES_DEST}/Textures/ 94 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCES_SRC}/models/ ${RESOURCES_DEST}/Models/ 95 | COMMENT "Copying Resources Success!" 96 | VERBATIM 97 | ) 98 | 99 | set(COMPILE_SHADER_TARGET ${PROJECT_NAME}_shader) 100 | set(SHADER_SOURCES ${SHADERS_SRC}/${PROJECT_NAME}.frag ${SHADERS_SRC}/${PROJECT_NAME}.vert ${SHADERS_SRC}/${PROJECT_NAME}_bg.frag ${SHADERS_SRC}/${PROJECT_NAME}_bg.vert) 101 | add_custom_target(${COMPILE_SHADER_TARGET} ALL DEPENDS SHADER_COMPILE SOURCES ${SHADER_SOURCES}) 102 | add_dependencies (${PROJECT_NAME} ${COMPILE_SHADER_TARGET}) 103 | 104 | set_target_properties(${PROJECT_NAME} PROPERTIES WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 105 | set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF) 106 | if(WIN32) 107 | set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS /SUBSYSTEM:CONSOLE VS_DEBUGGER_WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 108 | endif(WIN32) 109 | if(APPLE) 110 | set_target_properties(${PROJECT_NAME} PROPERTIES XCODE_GENERATE_SCHEME TRUE XCODE_SCHEME_WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 111 | endif(APPLE) 112 | target_link_libraries(${PROJECT_NAME} glfw glm) 113 | endfunction(buildProject) 114 | 115 | # Build all examples 116 | function(buildProjects) 117 | foreach(PROJECT ${PROJECTS}) 118 | buildProject(${PROJECT}) 119 | endforeach(PROJECT) 120 | endfunction(buildProjects) 121 | 122 | set(PROJECTS 123 | draw_with_PBR 124 | ) 125 | 126 | buildProjects() 127 | -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/appicons/renderer_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/appicons/renderer_logo.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/appicons/vulkan_renderer.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/appicons/vulkan_renderer.icns -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/appicons/vulkan_renderer.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/appicons/vulkan_renderer.ico -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/appicons/vulkan_renderer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/appicons/vulkan_renderer.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/appicons/vulkan_renderer_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/appicons/vulkan_renderer_small.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/models/cube.obj: -------------------------------------------------------------------------------- 1 | # File exported by Houdini 19.5.303 (www.sidefx.com) 2 | # 26 points 3 | # 144 vertices 4 | # 48 primitives 5 | # Bounds: [-0.5, -0.5, -0.5] to [0.5, 0.5, 0.5] 6 | g 7 | v 0.5 -0.5 -0.5 0.641600609 0.984740019 0.872882724 8 | v 0 -0.5 -0.5 0.800463796 0.761958241 0.501227975 9 | v 0.5 3.0616168e-17 -0.5 0.510895014 0.819262505 0.63925755 10 | v 0 3.0616168e-17 -0.5 0.77547431 0.693467021 0.213471174 11 | v -0.5 -0.5 -0.5 0.879505873 0.0383398533 0.351008534 12 | v 0.5 0.5 -0.5 0.205040097 0.160255671 0.0788230896 13 | v -0.5 3.0616168e-17 -0.5 0.522060633 0.105645657 0.736733079 14 | v 0 0.5 -0.5 0.885056257 0.576628089 0.343753338 15 | v -0.5 0.5 -0.5 0.595740199 0.0770806074 0.441300392 16 | v 0.5 -1.53080837e-16 0.5 0.828005791 0.254462719 0.0464098454 17 | v 0 -0.5 0.5 0.904596567 0.851359248 0.727070212 18 | v 0.5 -0.5 0.5 0.401968122 0.327856302 0.211637378 19 | v 0 -1.53080837e-16 0.5 0.881155372 0.617560983 0.920350313 20 | v 0.5 0.5 0.5 0.716899872 0.943809748 0.181561232 21 | v -0.5 -0.5 0.5 0.397275209 0.256250858 0.653677464 22 | v 0 0.5 0.5 0.841456175 0.038292408 0.9832654 23 | v -0.5 -1.53080837e-16 0.5 0.767640114 0.336983681 0.676131248 24 | v -0.5 0.5 0.5 0.810458899 0.219314694 0.300493121 25 | v 0.5 -0.5 -6.1232336e-17 0.744812131 0.285871506 0.0717102289 26 | v 0 -0.5 -6.1232336e-17 0.306950212 0.451083064 0.172329426 27 | v -0.5 -0.5 -6.1232336e-17 0.27325058 0.167408705 0.548660636 28 | v 0.5 0.5 6.1232336e-17 0.657864928 0.44863975 0.5115242 29 | v 0.5 -6.1232336e-17 -5.62409909e-33 0.490953088 0.0884310007 0.35540092 30 | v -0.5 0.5 6.1232336e-17 0.749197125 0.666402221 0.310608864 31 | v 0 0.5 6.1232336e-17 0.73199892 0.451219559 0.496567488 32 | v -0.5 -6.1232336e-17 -5.62409909e-33 0.142397285 0.632946968 0.939323068 33 | vt 0 0 0 34 | vt 0.5 0 0 35 | vt 0 0.5 0 36 | vt 0.5 0.5 0 37 | vt 1 0 0 38 | vt 0 1 0 39 | vt 1 0.5 0 40 | vt 0.5 1 0 41 | vt 1 1 0 42 | vn 0.577350378 -0.577350318 -0.577350318 43 | vn 0 -0.707106829 -0.707106829 44 | vn 0.707106829 0 -0.707106829 45 | vn 0 0 -1 46 | vn -0.577350259 -0.577350318 -0.577350318 47 | vn 0.577350259 0.577350318 -0.577350318 48 | vn -0.707106709 0 -0.707106769 49 | vn 0 0.707106709 -0.707106769 50 | vn -0.577350378 0.577350318 -0.577350318 51 | vn 0.707106769 0 0.707106709 52 | vn 0 -0.707106769 0.707106709 53 | vn 0.577350318 -0.577350378 0.577350318 54 | vn 0 0 1 55 | vn 0.577350318 0.577350259 0.577350318 56 | vn -0.577350318 -0.577350259 0.577350318 57 | vn 0 0.707106769 0.707106769 58 | vn -0.707106769 0 0.707106769 59 | vn -0.577350318 0.577350378 0.577350318 60 | vn 0.707106769 -0.707106709 0 61 | vn 0 -1 0 62 | vn -0.707106709 -0.707106769 0 63 | vn 0.707106709 0.707106769 0 64 | vn 1 0 0 65 | vn -0.707106769 0.707106709 0 66 | vn 0 1 0 67 | vn -1 0 0 68 | g 69 | usemtl WorldGridMaterial 70 | f 1/1/1 2/2/2 3/3/3 71 | f 2/2/2 4/4/4 3/3/3 72 | f 2/2/2 5/5/5 4/4/4 73 | f 3/3/3 4/4/4 6/6/6 74 | f 5/5/5 7/7/7 4/4/4 75 | f 4/4/4 8/8/8 6/6/6 76 | f 4/4/4 7/7/7 8/8/8 77 | f 7/7/7 9/9/9 8/8/8 78 | f 10/7/10 11/2/11 12/5/12 79 | f 10/7/10 13/4/13 11/2/11 80 | f 14/9/14 13/4/13 10/7/10 81 | f 13/4/13 15/1/15 11/2/11 82 | f 14/9/14 16/8/16 13/4/13 83 | f 13/4/13 17/3/17 15/1/15 84 | f 16/8/16 17/3/17 13/4/13 85 | f 16/8/16 18/6/18 17/3/17 86 | f 19/7/19 2/2/2 1/5/1 87 | f 19/7/19 20/4/20 2/2/2 88 | f 12/9/12 20/4/20 19/7/19 89 | f 20/4/20 5/1/5 2/2/2 90 | f 12/9/12 11/8/11 20/4/20 91 | f 20/4/20 21/3/21 5/1/5 92 | f 11/8/11 21/3/21 20/4/20 93 | f 11/8/11 15/6/15 21/3/21 94 | f 22/7/22 3/2/3 6/5/6 95 | f 22/7/22 23/4/23 3/2/3 96 | f 14/9/14 23/4/23 22/7/22 97 | f 23/4/23 1/1/1 3/2/3 98 | f 14/9/14 10/8/10 23/4/23 99 | f 23/4/23 19/3/19 1/1/1 100 | f 10/8/10 19/3/19 23/4/23 101 | f 10/8/10 12/6/12 19/3/19 102 | f 24/7/24 8/2/8 9/5/9 103 | f 24/7/24 25/4/25 8/2/8 104 | f 18/9/18 25/4/25 24/7/24 105 | f 25/4/25 6/1/6 8/2/8 106 | f 18/9/18 16/8/16 25/4/25 107 | f 25/4/25 22/3/22 6/1/6 108 | f 16/8/16 22/3/22 25/4/25 109 | f 16/8/16 14/6/14 22/3/22 110 | f 21/7/21 7/2/7 5/5/5 111 | f 21/7/21 26/4/26 7/2/7 112 | f 15/9/15 26/4/26 21/7/21 113 | f 26/4/26 9/1/9 7/2/7 114 | f 15/9/15 17/8/17 26/4/26 115 | f 26/4/26 24/3/24 9/1/9 116 | f 17/8/17 24/3/24 26/4/26 117 | f 17/8/17 18/6/18 24/3/24 118 | -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/shaders/draw_with_PBR.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | // push constants block 4 | layout( push_constant ) uniform constants 5 | { 6 | float time; 7 | } global; 8 | 9 | struct Light 10 | { 11 | vec4 position; // position.w represents type of light 12 | vec4 color; // color.w represents light intensity 13 | vec4 direction; // direction.w represents range 14 | vec4 info; // (only used for spot lights) info.x represents light inner cone angle, info.y represents light outer cone angle 15 | }; 16 | 17 | layout(set = 0, binding = 1) uniform UniformBufferObjectView 18 | { 19 | Light directional_lights[4]; 20 | Light point_lights[4]; 21 | Light spot_lights[4]; 22 | ivec4 lights_count; // [0] for directional_lights, [1] for point_lights, [2] for spot_lights 23 | vec4 camera_position; 24 | } view; 25 | 26 | uint DIRECTIONAL_LIGHTS = view.lights_count[0]; 27 | uint POINT_LIGHTS = view.lights_count[1]; 28 | uint SPOT_LIGHTS = view.lights_count[2]; 29 | uint SKY_MAXMIPS = view.lights_count[3]; 30 | 31 | layout(set = 0, binding = 2) uniform samplerCube skycube; // sky cubemap 32 | layout(set = 0, binding = 3) uniform sampler2D sampler1; // basecolor 33 | layout(set = 0, binding = 4) uniform sampler2D sampler2; // metalic 34 | layout(set = 0, binding = 5) uniform sampler2D sampler3; // roughness 35 | layout(set = 0, binding = 6) uniform sampler2D sampler4; // normalmap 36 | layout(set = 0, binding = 7) uniform sampler2D sampler5; // ambient occlution 37 | 38 | layout(location = 0) in vec3 fragPosition; 39 | layout(location = 1) in vec3 fragNormal; 40 | layout(location = 2) in vec3 fragColor; 41 | layout(location = 3) in vec2 fragTexCoord; 42 | 43 | layout(location = 0) out vec4 outColor; 44 | 45 | 46 | const float PI = 3.14159265359; 47 | 48 | vec3 F0 = vec3(0.04); 49 | 50 | // [0] Frensel Schlick 51 | vec3 F_Schlick(vec3 f0, float f90, float u) 52 | { 53 | return f0 + (f90 - f0) * pow(1.0 - u, 5.0); 54 | } 55 | 56 | // [1] IBL Defuse Irradiance 57 | vec3 F_Schlick_Roughness(vec3 F0, float cos_theta, float roughness) 58 | { 59 | return F0 + (max(vec3(1.0 - roughness), F0) - F0) * pow(1.0 - cos_theta, 5.0); 60 | } 61 | 62 | // [0] Diffuse Term 63 | float Fr_DisneyDiffuse(float NdotV, float NdotL, float LdotH, float roughness) 64 | { 65 | float E_bias = 0.0 * (1.0 - roughness) + 0.5 * roughness; 66 | float E_factor = 1.0 * (1.0 - roughness) + (1.0 / 1.51) * roughness; 67 | float fd90 = E_bias + 2.0 * LdotH * LdotH * roughness; 68 | vec3 f0 = vec3(1.0); 69 | float light_scatter = F_Schlick(f0, fd90, NdotL).r; 70 | float view_scatter = F_Schlick(f0, fd90, NdotV).r; 71 | return light_scatter * view_scatter * E_factor; 72 | } 73 | 74 | // [0] Specular Microfacet Model 75 | float V_SmithGGXCorrelated(float NdotV, float NdotL, float roughness) 76 | { 77 | float alphaRoughnessSq = roughness * roughness; 78 | 79 | float GGXV = NdotL * sqrt(NdotV * NdotV * (1.0 - alphaRoughnessSq) + alphaRoughnessSq); 80 | float GGXL = NdotV * sqrt(NdotL * NdotL * (1.0 - alphaRoughnessSq) + alphaRoughnessSq); 81 | 82 | float GGX = GGXV + GGXL; 83 | if (GGX > 0.0) 84 | { 85 | return 0.5 / GGX; 86 | } 87 | return 0.0; 88 | } 89 | 90 | // [0] GGX Normal Distribution Function 91 | float D_GGX(float NdotH, float roughness) 92 | { 93 | float alphaRoughnessSq = roughness * roughness; 94 | float f = (NdotH * alphaRoughnessSq - NdotH) * NdotH + 1.0; 95 | return alphaRoughnessSq / (PI * f * f); 96 | } 97 | 98 | float saturate(float t) 99 | { 100 | return clamp(t, 0.0, 1.0); 101 | } 102 | 103 | vec3 saturate(vec3 t) 104 | { 105 | return clamp(t, 0.0, 1.0); 106 | } 107 | 108 | float lerp(float f1, float f2, float a) 109 | { 110 | return ((1.0 - a) * f1 + a * f2); 111 | } 112 | 113 | vec3 lerp(vec3 v1, vec3 v2, float a) 114 | { 115 | return ((1.0 - a) * v1 + a * v2); 116 | } 117 | 118 | vec3 calcNormal() 119 | { 120 | vec3 pos_dx = dFdx(fragPosition); 121 | vec3 pos_dy = dFdy(fragPosition); 122 | vec3 st1 = dFdx(vec3(fragTexCoord, 0.0)); 123 | vec3 st2 = dFdy(vec3(fragTexCoord, 0.0)); 124 | vec3 T = (st2.t * pos_dx - st1.t * pos_dy) / (st1.s * st2.t - st2.s * st1.t); 125 | vec3 N = normalize(fragNormal); 126 | T = normalize(T - N * dot(N, T)); 127 | vec3 B = normalize(cross(N, T)); 128 | mat3 TBN = mat3(T, B, N); 129 | 130 | return normalize(TBN[2].xyz); 131 | } 132 | 133 | vec3 calcNormal(vec3 n) 134 | { 135 | vec3 pos_dx = dFdx(fragPosition); 136 | vec3 pos_dy = dFdy(fragPosition); 137 | vec3 st1 = dFdx(vec3(fragTexCoord, 0.0)); 138 | vec3 st2 = dFdy(vec3(fragTexCoord, 0.0)); 139 | vec3 T = (st2.t * pos_dx - st1.t * pos_dy) / (st1.s * st2.t - st2.s * st1.t); 140 | vec3 N = normalize(fragNormal); 141 | T = normalize(T - N * dot(N, T)); 142 | vec3 B = normalize(cross(N, T)); 143 | mat3 TBN = mat3(T, B, N); 144 | 145 | return normalize(TBN * normalize(2.0 * n - 1.0)); 146 | } 147 | 148 | vec3 get_directional_light_direction(uint index) 149 | { 150 | return -view.directional_lights[index].direction.xyz; 151 | } 152 | 153 | vec3 apply_directional_light(uint index, vec3 normal) 154 | { 155 | vec3 world_to_light = -view.directional_lights[index].direction.xyz; 156 | 157 | world_to_light = normalize(world_to_light); 158 | 159 | float ndotl = clamp(dot(normal, world_to_light), 0.0, 1.0); 160 | 161 | return ndotl * view.directional_lights[index].color.w * view.directional_lights[index].color.rgb; 162 | } 163 | 164 | #define REFLECTION_CAPTURE_ROUGHEST_MIP 1 165 | #define REFLECTION_CAPTURE_ROUGHNESS_MIP_SCALE 1.2 166 | /** 167 | * Compute absolute mip for a reflection capture cubemap given a roughness. 168 | */ 169 | float compute_reflection_mip_from_roughness(float roughness, float cubemap_max_mip) 170 | { 171 | // Heuristic that maps roughness to mip level 172 | // This is done in a way such that a certain mip level will always have the same roughness, regardless of how many mips are in the texture 173 | // Using more mips in the cubemap just allows sharper reflections to be supported 174 | float level_from_1x1 = REFLECTION_CAPTURE_ROUGHEST_MIP - REFLECTION_CAPTURE_ROUGHNESS_MIP_SCALE * log2(max(roughness, 0.001)); 175 | return cubemap_max_mip - 1 - level_from_1x1; 176 | } 177 | 178 | vec2 EnvBRDFApproxLazarov(float Roughness, float NoV) 179 | { 180 | // [ Lazarov 2013, "Getting More Physical in Call of Duty: Black Ops II" ] 181 | // Adaptation to fit our G term. 182 | const vec4 c0 = { -1, -0.0275, -0.572, 0.022 }; 183 | const vec4 c1 = { 1, 0.0425, 1.04, -0.04 }; 184 | vec4 r = Roughness * c0 + c1; 185 | float a004 = min(r.x * r.x, exp2(-9.28 * NoV)) * r.x + r.y; 186 | vec2 AB = vec2(-1.04, 1.04) * a004 + r.zw; 187 | return AB; 188 | } 189 | 190 | vec3 EnvBRDFApprox( vec3 SpecularColor, float Roughness, float NoV ) 191 | { 192 | vec2 AB = EnvBRDFApproxLazarov(Roughness, NoV); 193 | 194 | // Anything less than 2% is physically impossible and is instead considered to be shadowing 195 | // Note: this is needed for the 'specular' show flag to work, since it uses a SpecularColor of 0 196 | float F90 = saturate( 50.0 * SpecularColor.g ); 197 | 198 | return SpecularColor * AB.x + F90 * AB.y; 199 | } 200 | 201 | float GetSpecularOcclusion(float NoV, float RoughnessSq, float AO) 202 | { 203 | return saturate( pow( NoV + AO, RoughnessSq ) - 1 + AO ); 204 | } 205 | 206 | float DielectricSpecularToF0(float Specular) 207 | { 208 | return F0.x * 2.0f * Specular; 209 | } 210 | 211 | vec3 ComputeF0(float Specular, vec3 BaseColor, float Metallic) 212 | { 213 | // clamp pure black base color to get clear coat 214 | BaseColor = clamp(BaseColor, F0, vec3(1.0f)); 215 | return lerp(DielectricSpecularToF0(Specular).xxx, BaseColor, Metallic.x); 216 | } 217 | 218 | void main() 219 | { 220 | // DEBUG ARGS 221 | //vec3 base_color = vec3(0.3); 222 | //float metallic = 1.0; 223 | //float roughness = 0.1; 224 | //vec3 normal = calcNormal(); 225 | //vec3 ambient_occlution = vec3(1.0); 226 | 227 | vec3 base_color = texture(sampler1, fragTexCoord).rgb; 228 | float metallic = saturate(texture(sampler2, fragTexCoord).r); 229 | float roughness = saturate(texture(sampler3, fragTexCoord).r); 230 | vec3 normal = calcNormal(texture(sampler4, fragTexCoord).rgb); 231 | vec3 ambient_occlution = texture(sampler5, fragTexCoord).rgb; 232 | 233 | roughness = max(0.01, roughness); 234 | 235 | 236 | vec3 N = normal; 237 | vec3 V = normalize(view.camera_position.xyz - fragPosition); 238 | float NdotV = saturate(dot(N, V)); 239 | 240 | 241 | // Direct Lighting : DisneyDiffuse + SpecularGGX 242 | vec3 direct_lighting = vec3(0.0); 243 | vec3 diffuse_color = base_color.rgb * (1.0 - metallic); 244 | for (uint i = 0u; i < DIRECTIONAL_LIGHTS; ++i) 245 | { 246 | vec3 L = get_directional_light_direction(i); 247 | vec3 H = normalize(V + L); 248 | 249 | float LdotH = saturate(dot(L, H)); 250 | float NdotH = saturate(dot(N, H)); 251 | float NdotL = saturate(dot(N, L)); 252 | 253 | float F90 = saturate(50.0 * F0.r); 254 | vec3 F = F_Schlick(F0, F90, LdotH); 255 | float Vis = V_SmithGGXCorrelated(NdotV, NdotL, roughness); 256 | float D = D_GGX(NdotH, roughness); 257 | vec3 Fr = F * D * Vis; 258 | 259 | float Fd = Fr_DisneyDiffuse(NdotV, NdotL, LdotH, roughness); 260 | 261 | vec3 direct_diffuse = diffuse_color * (vec3(1.0) - F) * Fd; 262 | vec3 direct_specular = Fr; 263 | 264 | // TODO : Add energy presevation (i.e. attenuation of the specular layer onto the diffuse component 265 | // TODO : Add specular microfacet multiple scattering term (energy-conservation) 266 | 267 | direct_lighting += apply_directional_light(i, N) * (direct_diffuse + direct_specular); 268 | } 269 | 270 | 271 | // Indirect Lighting : Simple lambert diffuse as indirect lighting 272 | vec3 indirect_lighting = diffuse_color.rgb / PI * ambient_occlution; 273 | 274 | 275 | // Reflection Specular : Image based lighting 276 | vec3 specular = ComputeF0(0.5, base_color, metallic); 277 | vec3 reflection_brdf = EnvBRDFApprox(specular, roughness, NdotV); 278 | float ratio = 1.00 / 1.52; 279 | vec3 I = V; 280 | vec3 R = refract(I, normalize(N), ratio); 281 | float mip = compute_reflection_mip_from_roughness(roughness, SKY_MAXMIPS); 282 | vec3 reflection_L = textureLod(skycube, R, mip).rgb * 10.0; 283 | float reflection_V = GetSpecularOcclusion(NdotV, roughness * roughness, ambient_occlution.x); 284 | vec3 reflection_color = reflection_L * reflection_V * reflection_brdf; 285 | 286 | 287 | vec3 final_color = direct_lighting + indirect_lighting * 0.3 + reflection_color; 288 | //final_color = base_color * ambient_occlution; 289 | // Gamma correct 290 | final_color = pow(final_color, vec3(0.4545)); 291 | 292 | outColor = vec4(final_color, 1.0); 293 | } -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/shaders/draw_with_PBR.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | // push constants block 4 | layout( push_constant ) uniform constants 5 | { 6 | float time; 7 | } global; 8 | 9 | layout(set = 0, binding = 0) uniform UniformBufferObject 10 | { 11 | mat4 model; 12 | mat4 view; 13 | mat4 proj; 14 | } ubo; 15 | 16 | layout(location = 0) in vec3 inPosition; 17 | layout(location = 1) in vec3 inNormal; 18 | layout(location = 2) in vec3 inColor; 19 | layout(location = 3) in vec2 inTexCoord; 20 | 21 | layout(location = 0) out vec3 fragPosition; 22 | layout(location = 1) out vec3 fragNormal; 23 | layout(location = 2) out vec3 fragColor; 24 | layout(location = 3) out vec2 fragTexCoord; 25 | 26 | void main() 27 | { 28 | //vec3 newPosition = vec3(inPosition.x, inPosition.y, inPosition.z + sin(global.time) * 0.25); 29 | // Render object with MVP 30 | gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0); 31 | fragPosition = (ubo.model * vec4(inPosition, 1.0)).rgb; 32 | fragNormal = (ubo.model * vec4(normalize(inNormal), 1.0)).rgb; 33 | fragColor = inColor; 34 | fragTexCoord = inTexCoord; 35 | } 36 | -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/shaders/draw_with_PBR_bg.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(binding = 2) uniform sampler2D skycubeSampler; 4 | layout(binding = 3) uniform sampler2D backgroundSampler; 5 | 6 | layout(location = 0) in vec3 fragColor; 7 | layout(location = 1) in vec2 fragTexCoord; 8 | 9 | layout(location = 0) out vec4 outColor; 10 | 11 | void main() { 12 | vec3 color = texture(backgroundSampler, fragTexCoord).rgb; 13 | 14 | // Gamma correct 15 | color = pow(color, vec3(0.4545)); 16 | 17 | outColor = vec4(color, 1.0); 18 | } 19 | -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/shaders/draw_with_PBR_bg.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) out vec3 fragColor; 4 | layout(location = 1) out vec2 fragTexCoord; 5 | 6 | vec2 positions[6] = vec2[]( 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 | vec2(1.0, 1.0) 13 | ); 14 | 15 | vec3 colors[6] = vec3[]( 16 | vec3(1.0, 0.0, 0.0), 17 | vec3(0.0, 1.0, 0.0), 18 | vec3(0.0, 0.0, 1.0), 19 | vec3(0.0, 0.0, 1.0), 20 | vec3(0.0, 1.0, 0.0), 21 | vec3(1.0, 0.0, 0.0) 22 | ); 23 | 24 | vec2 uvs[6] = vec2[]( 25 | vec2(0.0, 0.0), 26 | vec2(1.0, 1.0), 27 | vec2(0.0, 1.0), 28 | vec2(0.0, 0.0), 29 | vec2(1.0, 0.0), 30 | vec2(1.0, 1.0) 31 | ); 32 | 33 | void main() { 34 | gl_Position = vec4(positions[gl_VertexIndex], 1.0, 1.0); 35 | fragColor = colors[gl_VertexIndex]; 36 | fragTexCoord = uvs[gl_VertexIndex]; 37 | } 38 | -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/shaders/draw_with_PBR_legacy.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | // push constants block 4 | layout( push_constant ) uniform constants 5 | { 6 | float time; 7 | } global; 8 | 9 | struct Light 10 | { 11 | vec4 position; // position.w represents type of light 12 | vec4 color; // color.w represents light intensity 13 | vec4 direction; // direction.w represents range 14 | vec4 info; // (only used for spot lights) info.x represents light inner cone angle, info.y represents light outer cone angle 15 | }; 16 | 17 | layout(set = 0, binding = 1) uniform UniformBufferObjectView 18 | { 19 | Light directional_lights[4]; 20 | Light point_lights[4]; 21 | Light spot_lights[4]; 22 | ivec4 lights_count; // [0] for directional_lights, [1] for point_lights, [2] for spot_lights 23 | vec4 camera_position; 24 | } view; 25 | 26 | uint DIRECTIONAL_LIGHTS = view.lights_count[0]; 27 | uint POINT_LIGHTS = view.lights_count[1]; 28 | uint SPOT_LIGHTS = view.lights_count[2]; 29 | uint AREA_LIGHTS = view.lights_count[3]; 30 | 31 | layout(set = 0, binding = 2) uniform sampler2D sampler1; // c 32 | layout(set = 0, binding = 3) uniform sampler2D sampler2; // m 33 | layout(set = 0, binding = 4) uniform sampler2D sampler3; // r 34 | layout(set = 0, binding = 5) uniform sampler2D sampler4; // n 35 | layout(set = 0, binding = 6) uniform sampler2D sampler5; // o 36 | 37 | layout(location = 0) in vec3 fragPosition; 38 | layout(location = 1) in vec3 fragNormal; 39 | layout(location = 2) in vec3 fragColor; 40 | layout(location = 3) in vec2 fragTexCoord; 41 | 42 | layout(location = 0) out vec4 outColor; 43 | 44 | 45 | const float PI = 3.14159265359; 46 | 47 | vec3 F0 = vec3(0.04); 48 | 49 | // [0] Frensel Schlick 50 | vec3 F_Schlick(vec3 f0, float f90, float u) 51 | { 52 | return f0 + (f90 - f0) * pow(1.0 - u, 5.0); 53 | } 54 | 55 | // [1] IBL Defuse Irradiance 56 | vec3 F_Schlick_Roughness(vec3 F0, float cos_theta, float roughness) 57 | { 58 | return F0 + (max(vec3(1.0 - roughness), F0) - F0) * pow(1.0 - cos_theta, 5.0); 59 | } 60 | 61 | // [0] Diffuse Term 62 | float Fr_DisneyDiffuse(float NdotV, float NdotL, float LdotH, float roughness) 63 | { 64 | float E_bias = 0.0 * (1.0 - roughness) + 0.5 * roughness; 65 | float E_factor = 1.0 * (1.0 - roughness) + (1.0 / 1.51) * roughness; 66 | float fd90 = E_bias + 2.0 * LdotH * LdotH * roughness; 67 | vec3 f0 = vec3(1.0); 68 | float light_scatter = F_Schlick(f0, fd90, NdotL).r; 69 | float view_scatter = F_Schlick(f0, fd90, NdotV).r; 70 | return light_scatter * view_scatter * E_factor; 71 | } 72 | 73 | // [0] Specular Microfacet Model 74 | float V_SmithGGXCorrelated(float NdotV, float NdotL, float roughness) 75 | { 76 | float alphaRoughnessSq = roughness * roughness; 77 | 78 | float GGXV = NdotL * sqrt(NdotV * NdotV * (1.0 - alphaRoughnessSq) + alphaRoughnessSq); 79 | float GGXL = NdotV * sqrt(NdotL * NdotL * (1.0 - alphaRoughnessSq) + alphaRoughnessSq); 80 | 81 | float GGX = GGXV + GGXL; 82 | if (GGX > 0.0) 83 | { 84 | return 0.5 / GGX; 85 | } 86 | return 0.0; 87 | } 88 | 89 | // [0] GGX Normal Distribution Function 90 | float D_GGX(float NdotH, float roughness) 91 | { 92 | float alphaRoughnessSq = roughness * roughness; 93 | float f = (NdotH * alphaRoughnessSq - NdotH) * NdotH + 1.0; 94 | return alphaRoughnessSq / (PI * f * f); 95 | } 96 | 97 | float saturate(float t) 98 | { 99 | return clamp(t, 0.0, 1.0); 100 | } 101 | 102 | vec3 saturate(vec3 t) 103 | { 104 | return clamp(t, 0.0, 1.0); 105 | } 106 | 107 | vec3 calcNormal() 108 | { 109 | vec3 pos_dx = dFdx(fragPosition); 110 | vec3 pos_dy = dFdy(fragPosition); 111 | vec3 st1 = dFdx(vec3(fragTexCoord, 0.0)); 112 | vec3 st2 = dFdy(vec3(fragTexCoord, 0.0)); 113 | vec3 T = (st2.t * pos_dx - st1.t * pos_dy) / (st1.s * st2.t - st2.s * st1.t); 114 | vec3 N = normalize(fragNormal); 115 | T = normalize(T - N * dot(N, T)); 116 | vec3 B = normalize(cross(N, T)); 117 | mat3 TBN = mat3(T, B, N); 118 | 119 | return normalize(TBN[2].xyz); 120 | } 121 | 122 | vec3 calcNormal(vec3 n) 123 | { 124 | vec3 pos_dx = dFdx(fragPosition); 125 | vec3 pos_dy = dFdy(fragPosition); 126 | vec3 st1 = dFdx(vec3(fragTexCoord, 0.0)); 127 | vec3 st2 = dFdy(vec3(fragTexCoord, 0.0)); 128 | vec3 T = (st2.t * pos_dx - st1.t * pos_dy) / (st1.s * st2.t - st2.s * st1.t); 129 | vec3 N = normalize(fragNormal); 130 | T = normalize(T - N * dot(N, T)); 131 | vec3 B = normalize(cross(N, T)); 132 | mat3 TBN = mat3(T, B, N); 133 | 134 | return normalize(TBN * (2.0 * n - 1.0)); 135 | } 136 | 137 | vec3 get_directional_light_direction(uint index) 138 | { 139 | return -view.directional_lights[index].direction.xyz; 140 | } 141 | 142 | vec3 apply_directional_light(uint index, vec3 normal) 143 | { 144 | vec3 world_to_light = -view.directional_lights[index].direction.xyz; 145 | 146 | world_to_light = normalize(world_to_light); 147 | 148 | float ndotl = clamp(dot(normal, world_to_light), 0.0, 1.0); 149 | 150 | return ndotl * view.directional_lights[index].color.w * view.directional_lights[index].color.rgb; 151 | } 152 | 153 | void main() 154 | { 155 | vec3 base_color = vec3(0.01); 156 | float metallic = 1.0; 157 | float roughness = 0.1; 158 | vec3 normal = calcNormal(); 159 | vec3 ambient_occlution = vec3(1.0); 160 | 161 | //vec3 base_color = texture(sampler1, fragTexCoord).rgb; 162 | //float metallic = saturate(texture(sampler2, fragTexCoord).r); 163 | //float roughness = saturate(texture(sampler3, fragTexCoord).r); 164 | //vec3 normal = calcNormal(texture(sampler4, fragTexCoord).rgb); 165 | //vec3 ambient_occlution = texture(sampler5, fragTexCoord).rgb; 166 | 167 | vec3 N = normal; 168 | vec3 V = normalize(view.camera_position.xyz - fragPosition); 169 | float NdotV = saturate(dot(N, V)); 170 | 171 | vec3 LightContribution = vec3(0.0); 172 | //vec3 diffuse_color = base_color.rgb * (1.0 - metallic); 173 | vec3 diffuse_color = base_color.rgb / PI; 174 | 175 | for (uint i = 0U; i < DIRECTIONAL_LIGHTS; ++i) 176 | { 177 | vec3 L = get_directional_light_direction(i); 178 | vec3 H = normalize(V + L); 179 | 180 | float LdotH = saturate(dot(L, H)); 181 | float NdotH = saturate(dot(N, H)); 182 | float NdotL = saturate(dot(N, L)); 183 | 184 | float F90 = saturate(50.0 * F0.r); 185 | vec3 F = F_Schlick(F0, F90, LdotH); 186 | float Vis = V_SmithGGXCorrelated(NdotV, NdotL, roughness); 187 | float D = D_GGX(NdotH, roughness); 188 | vec3 Fr = F * D * Vis; 189 | 190 | float Fd = Fr_DisneyDiffuse(NdotV, NdotL, LdotH, roughness); 191 | 192 | LightContribution += apply_directional_light(i, N) * (diffuse_color * (vec3(1.0) - F) * Fd + Fr); 193 | } 194 | 195 | // [1] Tempory irradiance to fix dark metals 196 | // TODO: add specular irradiance for realistic metals 197 | vec3 irradiance = vec3(0.5); 198 | vec3 F = F_Schlick_Roughness(F0, max(dot(N, V), 0.0), roughness * roughness * roughness * roughness); 199 | vec3 ibl_diffuse = irradiance * base_color.rgb; 200 | 201 | vec3 ambient_color = ibl_diffuse; 202 | 203 | outColor = vec4(0.3 * ambient_color + LightContribution, 1.0); 204 | } 205 | -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/shaders/draw_with_PBR_legacy.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | // push constants block 4 | layout( push_constant ) uniform constants 5 | { 6 | float time; 7 | } global; 8 | 9 | layout(set = 0, binding = 0) uniform UniformBufferObject 10 | { 11 | mat4 model; 12 | mat4 view; 13 | mat4 proj; 14 | } ubo; 15 | 16 | layout(location = 0) in vec3 inPosition; 17 | layout(location = 1) in vec3 inNormal; 18 | layout(location = 2) in vec3 inColor; 19 | layout(location = 3) in vec2 inTexCoord; 20 | 21 | layout(location = 0) out vec3 fragPosition; 22 | layout(location = 1) out vec3 fragNormal; 23 | layout(location = 2) out vec3 fragColor; 24 | layout(location = 3) out vec2 fragTexCoord; 25 | 26 | void main() 27 | { 28 | //vec3 newPosition = vec3(inPosition.x, inPosition.y, inPosition.z + sin(global.time) * 0.25); 29 | // Render object with MVP 30 | gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0); 31 | fragPosition = (ubo.model * vec4(inPosition, 1.0)).rgb; 32 | fragNormal = mat3(ubo.model) * normalize(inNormal); 33 | fragColor = inColor; 34 | fragTexCoord = inTexCoord; 35 | } 36 | -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/background.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/cubemap_X0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/cubemap_X0.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/cubemap_X1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/cubemap_X1.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/cubemap_Y2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/cubemap_Y2.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/cubemap_Y3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/cubemap_Y3.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/cubemap_Z4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/cubemap_Z4.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/cubemap_Z5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/cubemap_Z5.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/default_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/default_black.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/default_grey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/default_grey.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/default_grid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/default_grid.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/default_grid_n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/default_grid_n.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/default_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/default_normal.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/default_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/default_white.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/hylian_shield_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/hylian_shield_c.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/hylian_shield_m.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/hylian_shield_m.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/hylian_shield_n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/hylian_shield_n.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/hylian_shield_o.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/hylian_shield_o.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/hylian_shield_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/hylian_shield_r.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/master_sword_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/master_sword_c.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/master_sword_m.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/master_sword_m.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/master_sword_n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/master_sword_n.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/master_sword_o.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/master_sword_o.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/master_sword_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/master_sword_r.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/steath_c.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/steath_c.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/steath_m.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/steath_m.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/steath_n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/steath_n.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/steath_o.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/steath_o.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/steath_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/steath_r.png -------------------------------------------------------------------------------- /LearnVulkan-06/draw_with_PBR/textures/viking_room.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-06/draw_with_PBR/textures/viking_room.png -------------------------------------------------------------------------------- /LearnVulkan-07/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Function for building single example 2 | include(CMakeParseArguments) 3 | 4 | function(AddIconToBinary AppSources) 5 | set(Options) 6 | set(OneValueArgs OUTFILE_BASENAME) 7 | set(MultiValueArgs ICONS) 8 | cmake_parse_arguments(ARG "${Options}" "${OneValueArgs}" "${MultiValueArgs}" ${ARGN}) 9 | if (NOT ARG_ICONS) 10 | message(FATAL_ERROR "No ICONS argument given to AddIconToBinary") 11 | endif() 12 | if (ARG_UNPARSED_ARGUMENTS) 13 | message(FATAL_ERROR "Unexpected arguments to ecm_add_app_icon: ${ARG_UNPARSED_ARGUMENTS}") 14 | endif() 15 | foreach (icon ${ARG_ICONS}) 16 | get_filename_component(IconFull ${icon} ABSOLUTE) 17 | get_filename_component(IconType ${IconFull} EXT) 18 | get_filename_component(IconName ${IconFull} NAME_WE) 19 | if (APPLE) 20 | if (${IconType} STREQUAL ".icns") 21 | set(IconFullOutput ${CMAKE_CURRENT_BINARY_DIR}/${IconName}.icns) 22 | configure_file(${IconFull} ${IconFullOutput} COPYONLY) 23 | set(MACOSX_BUNDLE_ICON_FILE ${IconName}.icns PARENT_SCOPE) 24 | set(${AppSources} "${${AppSources}};${IconFullOutput}" PARENT_SCOPE) 25 | set_source_files_properties(${IconFullOutput} PROPERTIES MACOSX_PACKAGE_LOCATION Resources) 26 | return() 27 | endif() 28 | endif() 29 | if (MSVC) 30 | if (${IconType} STREQUAL ".ico") 31 | set(IconFullOutput ${CMAKE_CURRENT_BINARY_DIR}/${IconName}.ico) 32 | configure_file(${IconFull} ${IconFullOutput} COPYONLY) 33 | file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${IconName}.rc.in" "IDI_ICON1 ICON DISCARDABLE\"${IconName}.ico\"\n") 34 | add_custom_command( 35 | OUTPUT "${IconName}.rc" 36 | COMMAND ${CMAKE_COMMAND} 37 | ARGS -E copy "${IconName}.rc.in" "${IconName}.rc" 38 | DEPENDS "${IconName}.ico" 39 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") 40 | set(${AppSources} "${${AppSources}};${IconName}.rc" PARENT_SCOPE) 41 | return() 42 | endif() 43 | endif() 44 | endforeach() 45 | return() 46 | endfunction() 47 | 48 | function(buildProject PROJECT_NAME) 49 | SET(EXAMPLE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}) 50 | message(STATUS "Generating project file for example in ${EXAMPLE_FOLDER}") 51 | # Main 52 | # file(GLOB SOURCE *.cpp ${BASE_HEADERS} ${EXAMPLE_FOLDER}/*.cpp) 53 | SET(MAIN_CPP ${EXAMPLE_FOLDER}/${PROJECT_NAME}.cpp) 54 | set (CURRENT_WORKING_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) 55 | set (ICONS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/appicons) 56 | set (ICONS_DEST ${CURRENT_WORKING_DIR}/Resources/Appicons) 57 | set (SHADERS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/shaders) 58 | set (SHADERS_DEST ${CURRENT_WORKING_DIR}/Resources/Shaders) 59 | set (RESOURCES_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}) 60 | set (RESOURCES_DEST ${CURRENT_WORKING_DIR}/Resources) 61 | 62 | if(EXISTS ${EXAMPLE_FOLDER}/main.cpp) 63 | SET(MAIN_CPP ${EXAMPLE_FOLDER}/main.cpp) 64 | endif() 65 | if(EXISTS ${EXAMPLE_FOLDER}/${PROJECT_NAME}.h) 66 | SET(MAIN_HEADER ${EXAMPLE_FOLDER}/${PROJECT_NAME}.h) 67 | endif() 68 | # Set application icon 69 | AddIconToBinary(MAIN_CPP ICONS ${ICONS_SRC}/vulkan_renderer.ico ${ICONS_SRC}/vulkan_renderer.icns) 70 | if(WIN32) 71 | add_compile_options("$<$:/utf-8>") 72 | add_compile_options("$<$:/utf-8>") 73 | add_executable(${PROJECT_NAME} WIN32 ${MAIN_CPP}) 74 | target_link_libraries(${PROJECT_NAME} ${Vulkan_LIBRARY} ${WINLIBS}) 75 | else(WIN32) 76 | add_executable(${PROJECT_NAME} ${MAIN_CPP}) 77 | target_link_libraries(${PROJECT_NAME}) 78 | endif(WIN32) 79 | 80 | # Compile shader and copy texures 81 | add_custom_command( 82 | OUTPUT SHADER_COMPILE 83 | COMMAND ${CMAKE_COMMAND} -E make_directory ${SHADERS_DEST} 84 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_base.frag -o ${SHADERS_DEST}/${PROJECT_NAME}_base_frag.spv 85 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_base.vert -o ${SHADERS_DEST}/${PROJECT_NAME}_base_vert.spv 86 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_bg.frag -o ${SHADERS_DEST}/${PROJECT_NAME}_bg_frag.spv 87 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_bg.vert -o ${SHADERS_DEST}/${PROJECT_NAME}_bg_vert.spv 88 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_sm.frag -o ${SHADERS_DEST}/${PROJECT_NAME}_sm_frag.spv 89 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_sm.vert -o ${SHADERS_DEST}/${PROJECT_NAME}_sm_vert.spv 90 | WORKING_DIRECTORY ${SHADERS_SRC} 91 | DEPENDS ${SHADERS_SRC} ${SHADER_SOURCES} 92 | COMMENT "Compiling Shaders Success!" 93 | VERBATIM 94 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${ICONS_SRC}/ ${ICONS_DEST}/ 95 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCES_SRC}/textures/ ${RESOURCES_DEST}/Textures/ 96 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCES_SRC}/models/ ${RESOURCES_DEST}/Models/ 97 | COMMENT "Copying Resources Success!" 98 | VERBATIM 99 | ) 100 | 101 | set(COMPILE_SHADER_TARGET ${PROJECT_NAME}_shader) 102 | set(SHADER_SOURCES ${SHADERS_SRC}/${PROJECT_NAME}_base.frag ${SHADERS_SRC}/${PROJECT_NAME}_base.vert ${SHADERS_SRC}/${PROJECT_NAME}_bg.frag ${SHADERS_SRC}/${PROJECT_NAME}_bg.vert ${SHADERS_SRC}/${PROJECT_NAME}_sm.frag ${SHADERS_SRC}/${PROJECT_NAME}_sm.vert) 103 | add_custom_target(${COMPILE_SHADER_TARGET} ALL DEPENDS SHADER_COMPILE SOURCES ${SHADER_SOURCES}) 104 | add_dependencies (${PROJECT_NAME} ${COMPILE_SHADER_TARGET}) 105 | 106 | set_target_properties(${PROJECT_NAME} PROPERTIES WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 107 | set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF) 108 | if(WIN32) 109 | set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS /SUBSYSTEM:CONSOLE VS_DEBUGGER_WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 110 | endif(WIN32) 111 | if(APPLE) 112 | set_target_properties(${PROJECT_NAME} PROPERTIES XCODE_GENERATE_SCHEME TRUE XCODE_SCHEME_WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 113 | endif(APPLE) 114 | target_link_libraries(${PROJECT_NAME} glfw glm) 115 | endfunction(buildProject) 116 | 117 | # Build all examples 118 | function(buildProjects) 119 | foreach(PROJECT ${PROJECTS}) 120 | buildProject(${PROJECT}) 121 | endforeach(PROJECT) 122 | endfunction(buildProjects) 123 | 124 | set(PROJECTS 125 | draw_with_shadow 126 | ) 127 | 128 | buildProjects() 129 | -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/appicons/vulkan_renderer.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/appicons/vulkan_renderer.icns -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/appicons/vulkan_renderer.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/appicons/vulkan_renderer.ico -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/appicons/vulkan_renderer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/appicons/vulkan_renderer.png -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/appicons/vulkan_renderer_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/appicons/vulkan_renderer_small.png -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/models/cube.obj: -------------------------------------------------------------------------------- 1 | # File exported by Houdini 19.5.493 (www.sidefx.com) 2 | # 26 points 3 | # 144 vertices 4 | # 48 primitives 5 | # Bounds: [-0.5, -0.5, -0.5] to [0.5, 0.5, 0.5] 6 | g 7 | v 0.5 -0.5 0.5 8 | v 0 -0.5 0.5 9 | v 0.5 -0.5 -3.0616168e-17 10 | v 0 -0.5 -3.0616168e-17 11 | v -0.5 -0.5 0.5 12 | v 0.5 -0.5 -0.5 13 | v -0.5 -0.5 -3.0616168e-17 14 | v 0 -0.5 -0.5 15 | v -0.5 -0.5 -0.5 16 | v 0.5 0.5 1.53080837e-16 17 | v 0 0.5 0.5 18 | v 0.5 0.5 0.5 19 | v 0 0.5 1.53080837e-16 20 | v 0.5 0.5 -0.5 21 | v -0.5 0.5 0.5 22 | v 0 0.5 -0.5 23 | v -0.5 0.5 1.53080837e-16 24 | v -0.5 0.5 -0.5 25 | v 0.5 -6.1232336e-17 0.5 26 | v 0 -6.1232336e-17 0.5 27 | v -0.5 -6.1232336e-17 0.5 28 | v 0.5 6.1232336e-17 -0.5 29 | v 0.5 -5.62409909e-33 6.1232336e-17 30 | v -0.5 6.1232336e-17 -0.5 31 | v 0 6.1232336e-17 -0.5 32 | v -0.5 -5.62409909e-33 6.1232336e-17 33 | vt 0 0 0 34 | vt 0.5 0 0 35 | vt 0 0.5 0 36 | vt 0.5 0.5 0 37 | vt 1 0 0 38 | vt 0 1 0 39 | vt 1 0.5 0 40 | vt 0.5 1 0 41 | vt 1 1 0 42 | vn 0.577350378 -0.577350318 0.577350318 43 | vn 0 -0.707106829 0.707106829 44 | vn 0.707106829 -0.707106829 0 45 | vn 0 -1 0 46 | vn -0.577350259 -0.577350318 0.577350318 47 | vn 0.577350259 -0.577350318 -0.577350318 48 | vn -0.707106709 -0.707106769 0 49 | vn 0 -0.707106769 -0.707106709 50 | vn -0.577350378 -0.577350318 -0.577350318 51 | vn 0.707106769 0.707106709 0 52 | vn 0 0.707106709 0.707106769 53 | vn 0.577350318 0.577350318 0.577350378 54 | vn 0 1 0 55 | vn 0.577350318 0.577350318 -0.577350259 56 | vn -0.577350318 0.577350318 0.577350259 57 | vn 0 0.707106769 -0.707106769 58 | vn -0.707106769 0.707106769 0 59 | vn -0.577350318 0.577350318 -0.577350378 60 | vn 0.707106769 0 0.707106709 61 | vn 0 0 1 62 | vn -0.707106709 0 0.707106769 63 | vn 0.707106709 0 -0.707106769 64 | vn 1 0 0 65 | vn -0.707106769 0 -0.707106709 66 | vn 0 0 -1 67 | vn -1 0 0 68 | g 69 | usemtl WorldGridMaterial 70 | f 1/1/1 2/2/2 3/3/3 71 | f 2/2/2 4/4/4 3/3/3 72 | f 2/2/2 5/5/5 4/4/4 73 | f 3/3/3 4/4/4 6/6/6 74 | f 5/5/5 7/7/7 4/4/4 75 | f 4/4/4 8/8/8 6/6/6 76 | f 4/4/4 7/7/7 8/8/8 77 | f 7/7/7 9/9/9 8/8/8 78 | f 10/7/10 11/2/11 12/5/12 79 | f 10/7/10 13/4/13 11/2/11 80 | f 14/9/14 13/4/13 10/7/10 81 | f 13/4/13 15/1/15 11/2/11 82 | f 14/9/14 16/8/16 13/4/13 83 | f 13/4/13 17/3/17 15/1/15 84 | f 16/8/16 17/3/17 13/4/13 85 | f 16/8/16 18/6/18 17/3/17 86 | f 19/7/19 2/2/2 1/5/1 87 | f 19/7/19 20/4/20 2/2/2 88 | f 12/9/12 20/4/20 19/7/19 89 | f 20/4/20 5/1/5 2/2/2 90 | f 12/9/12 11/8/11 20/4/20 91 | f 20/4/20 21/3/21 5/1/5 92 | f 11/8/11 21/3/21 20/4/20 93 | f 11/8/11 15/6/15 21/3/21 94 | f 22/7/22 3/2/3 6/5/6 95 | f 22/7/22 23/4/23 3/2/3 96 | f 14/9/14 23/4/23 22/7/22 97 | f 23/4/23 1/1/1 3/2/3 98 | f 14/9/14 10/8/10 23/4/23 99 | f 23/4/23 19/3/19 1/1/1 100 | f 10/8/10 19/3/19 23/4/23 101 | f 10/8/10 12/6/12 19/3/19 102 | f 24/7/24 8/2/8 9/5/9 103 | f 24/7/24 25/4/25 8/2/8 104 | f 18/9/18 25/4/25 24/7/24 105 | f 25/4/25 6/1/6 8/2/8 106 | f 18/9/18 16/8/16 25/4/25 107 | f 25/4/25 22/3/22 6/1/6 108 | f 16/8/16 22/3/22 25/4/25 109 | f 16/8/16 14/6/14 22/3/22 110 | f 21/7/21 7/2/7 5/5/5 111 | f 21/7/21 26/4/26 7/2/7 112 | f 15/9/15 26/4/26 21/7/21 113 | f 26/4/26 9/1/9 7/2/7 114 | f 15/9/15 17/8/17 26/4/26 115 | f 26/4/26 24/3/24 9/1/9 116 | f 17/8/17 24/3/24 26/4/26 117 | f 17/8/17 18/6/18 24/3/24 118 | -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/shaders/draw_with_shadow_base.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | // push constants block 4 | layout( push_constant ) uniform constants 5 | { 6 | float time; 7 | } global; 8 | 9 | layout(set = 0, binding = 0) uniform uniformbuffer 10 | { 11 | mat4 model; 12 | mat4 view; 13 | mat4 proj; 14 | } ubo; 15 | 16 | layout(location = 0) in vec3 inPosition; 17 | layout(location = 1) in vec3 inNormal; 18 | layout(location = 2) in vec3 inColor; 19 | layout(location = 3) in vec2 inTexCoord; 20 | 21 | layout(location = 0) out vec3 outPosition; 22 | layout(location = 1) out vec3 outPositionWS; 23 | layout(location = 2) out vec3 outNormal; 24 | layout(location = 3) out vec3 outColor; 25 | layout(location = 4) out vec2 outTexCoord; 26 | 27 | void main() 28 | { 29 | // Render object with MVP 30 | gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0); 31 | outPosition = inPosition; 32 | outPositionWS = (ubo.model * vec4(inPosition, 1.0)).rgb; 33 | outNormal = (ubo.model * vec4(normalize(inNormal), 1.0)).rgb; 34 | outColor = inColor; 35 | outTexCoord = inTexCoord; 36 | } -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/shaders/draw_with_shadow_bg.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(binding = 4) uniform sampler2D backgroundSampler; 4 | 5 | layout(location = 0) in vec3 fragColor; 6 | layout(location = 1) in vec2 fragTexCoord; 7 | 8 | layout(location = 0) out vec4 outColor; 9 | 10 | void main() { 11 | vec3 color = texture(backgroundSampler, fragTexCoord).rgb; 12 | 13 | // Gamma correct 14 | color = pow(color, vec3(0.4545)); 15 | 16 | outColor = vec4(color, 1.0); 17 | } -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/shaders/draw_with_shadow_bg.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) out vec3 fragColor; 4 | layout(location = 1) out vec2 fragTexCoord; 5 | 6 | vec2 positions[6] = vec2[]( 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 | vec2(1.0, 1.0) 13 | ); 14 | 15 | vec3 colors[6] = vec3[]( 16 | vec3(1.0, 0.0, 0.0), 17 | vec3(0.0, 1.0, 0.0), 18 | vec3(0.0, 0.0, 1.0), 19 | vec3(0.0, 0.0, 1.0), 20 | vec3(0.0, 1.0, 0.0), 21 | vec3(1.0, 0.0, 0.0) 22 | ); 23 | 24 | vec2 uvs[6] = vec2[]( 25 | vec2(0.0, 0.0), 26 | vec2(1.0, 1.0), 27 | vec2(0.0, 1.0), 28 | vec2(0.0, 0.0), 29 | vec2(1.0, 0.0), 30 | vec2(1.0, 1.0) 31 | ); 32 | 33 | void main() { 34 | gl_Position = vec4(positions[gl_VertexIndex], 1.0, 1.0); 35 | fragColor = colors[gl_VertexIndex]; 36 | fragTexCoord = uvs[gl_VertexIndex]; 37 | } -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/shaders/draw_with_shadow_sm.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) out vec4 outColor; 4 | 5 | void main() 6 | { 7 | outColor = vec4(1.0, 1.0, 1.0, 1.0); 8 | } -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/shaders/draw_with_shadow_sm.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(set = 0, binding = 0) uniform uniformbuffer 4 | { 5 | mat4 model; 6 | mat4 view; 7 | mat4 proj; 8 | } ubo; 9 | 10 | layout(location = 0) in vec3 inPosition; 11 | layout(location = 1) in vec3 inNormal; 12 | layout(location = 2) in vec3 inColor; 13 | layout(location = 3) in vec2 inTexCoord; 14 | 15 | void main() 16 | { 17 | gl_Position = ubo.proj * ubo.view * ubo.model * vec4(inPosition, 1.0); 18 | } -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/textures/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/textures/background.png -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/textures/cubemap_X0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/textures/cubemap_X0.png -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/textures/cubemap_X1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/textures/cubemap_X1.png -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/textures/cubemap_Y2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/textures/cubemap_Y2.png -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/textures/cubemap_Y3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/textures/cubemap_Y3.png -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/textures/cubemap_Z4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/textures/cubemap_Z4.png -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/textures/cubemap_Z5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/textures/cubemap_Z5.png -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/textures/default_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/textures/default_black.png -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/textures/default_grey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/textures/default_grey.png -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/textures/default_grid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/textures/default_grid.png -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/textures/default_grid_n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/textures/default_grid_n.png -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/textures/default_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/textures/default_normal.png -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/textures/default_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/textures/default_white.png -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/textures/stilized_house_ao.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/textures/stilized_house_ao.png -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/textures/stilized_house_bc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/textures/stilized_house_bc.png -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/textures/stilized_house_m.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/textures/stilized_house_m.png -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/textures/stilized_house_n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/textures/stilized_house_n.png -------------------------------------------------------------------------------- /LearnVulkan-07/draw_with_shadow/textures/stilized_house_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-07/draw_with_shadow/textures/stilized_house_r.png -------------------------------------------------------------------------------- /LearnVulkan-08/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Function for building single example 2 | include(CMakeParseArguments) 3 | 4 | function(AddIconToBinary AppSources) 5 | set(Options) 6 | set(OneValueArgs OUTFILE_BASENAME) 7 | set(MultiValueArgs ICONS) 8 | cmake_parse_arguments(ARG "${Options}" "${OneValueArgs}" "${MultiValueArgs}" ${ARGN}) 9 | if (NOT ARG_ICONS) 10 | message(FATAL_ERROR "No ICONS argument given to AddIconToBinary") 11 | endif() 12 | if (ARG_UNPARSED_ARGUMENTS) 13 | message(FATAL_ERROR "Unexpected arguments to ecm_add_app_icon: ${ARG_UNPARSED_ARGUMENTS}") 14 | endif() 15 | foreach (icon ${ARG_ICONS}) 16 | get_filename_component(IconFull ${icon} ABSOLUTE) 17 | get_filename_component(IconType ${IconFull} EXT) 18 | get_filename_component(IconName ${IconFull} NAME_WE) 19 | if (APPLE) 20 | if (${IconType} STREQUAL ".icns") 21 | set(IconFullOutput ${CMAKE_CURRENT_BINARY_DIR}/${IconName}.icns) 22 | configure_file(${IconFull} ${IconFullOutput} COPYONLY) 23 | set(MACOSX_BUNDLE_ICON_FILE ${IconName}.icns PARENT_SCOPE) 24 | set(${AppSources} "${${AppSources}};${IconFullOutput}" PARENT_SCOPE) 25 | set_source_files_properties(${IconFullOutput} PROPERTIES MACOSX_PACKAGE_LOCATION Resources) 26 | return() 27 | endif() 28 | endif() 29 | if (MSVC) 30 | if (${IconType} STREQUAL ".ico") 31 | set(IconFullOutput ${CMAKE_CURRENT_BINARY_DIR}/${IconName}.ico) 32 | configure_file(${IconFull} ${IconFullOutput} COPYONLY) 33 | file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${IconName}.rc.in" "IDI_ICON1 ICON DISCARDABLE\"${IconName}.ico\"\n") 34 | add_custom_command( 35 | OUTPUT "${IconName}.rc" 36 | COMMAND ${CMAKE_COMMAND} 37 | ARGS -E copy "${IconName}.rc.in" "${IconName}.rc" 38 | DEPENDS "${IconName}.ico" 39 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") 40 | set(${AppSources} "${${AppSources}};${IconName}.rc" PARENT_SCOPE) 41 | return() 42 | endif() 43 | endif() 44 | endforeach() 45 | return() 46 | endfunction() 47 | 48 | function(buildProject PROJECT_NAME) 49 | SET(EXAMPLE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}) 50 | message(STATUS "Generating project file for example in ${EXAMPLE_FOLDER}") 51 | # Main 52 | # file(GLOB SOURCE *.cpp ${BASE_HEADERS} ${EXAMPLE_FOLDER}/*.cpp) 53 | SET(MAIN_CPP ${EXAMPLE_FOLDER}/${PROJECT_NAME}.cpp) 54 | set (CURRENT_WORKING_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) 55 | set (ICONS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/appicons) 56 | set (ICONS_DEST ${CURRENT_WORKING_DIR}/Resources/Appicons) 57 | set (SHADERS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/shaders) 58 | set (SHADERS_DEST ${CURRENT_WORKING_DIR}/Resources/Shaders) 59 | set (RESOURCES_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}) 60 | set (RESOURCES_DEST ${CURRENT_WORKING_DIR}/Resources) 61 | 62 | if(EXISTS ${EXAMPLE_FOLDER}/main.cpp) 63 | SET(MAIN_CPP ${EXAMPLE_FOLDER}/main.cpp) 64 | endif() 65 | if(EXISTS ${EXAMPLE_FOLDER}/${PROJECT_NAME}.h) 66 | SET(MAIN_HEADER ${EXAMPLE_FOLDER}/${PROJECT_NAME}.h) 67 | endif() 68 | # Set application icon 69 | AddIconToBinary(MAIN_CPP ICONS ${ICONS_SRC}/vulkan_renderer.ico ${ICONS_SRC}/vulkan_renderer.icns) 70 | if(WIN32) 71 | add_compile_options("$<$:/utf-8>") 72 | add_compile_options("$<$:/utf-8>") 73 | add_executable(${PROJECT_NAME} WIN32 ${MAIN_CPP}) 74 | target_link_libraries(${PROJECT_NAME} ${Vulkan_LIBRARY} ${WINLIBS}) 75 | else(WIN32) 76 | add_executable(${PROJECT_NAME} ${MAIN_CPP}) 77 | target_link_libraries(${PROJECT_NAME}) 78 | endif(WIN32) 79 | 80 | # Compile shader and copy texures 81 | add_custom_command( 82 | OUTPUT SHADER_COMPILE 83 | COMMAND ${CMAKE_COMMAND} -E make_directory ${SHADERS_DEST} 84 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_base.frag -o ${SHADERS_DEST}/${PROJECT_NAME}_base_frag.spv 85 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_base.vert -o ${SHADERS_DEST}/${PROJECT_NAME}_base_vert.spv 86 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_base_instanced.vert -o ${SHADERS_DEST}/${PROJECT_NAME}_base_instanced_vert.spv 87 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_sm.frag -o ${SHADERS_DEST}/${PROJECT_NAME}_sm_frag.spv 88 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_sm.vert -o ${SHADERS_DEST}/${PROJECT_NAME}_sm_vert.spv 89 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_sm_instanced.vert -o ${SHADERS_DEST}/${PROJECT_NAME}_sm_instanced_vert.spv 90 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_bg.frag -o ${SHADERS_DEST}/${PROJECT_NAME}_bg_frag.spv 91 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_bg.vert -o ${SHADERS_DEST}/${PROJECT_NAME}_bg_vert.spv 92 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_sky.frag -o ${SHADERS_DEST}/${PROJECT_NAME}_sky_frag.spv 93 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_sky.vert -o ${SHADERS_DEST}/${PROJECT_NAME}_sky_vert.spv 94 | WORKING_DIRECTORY ${SHADERS_SRC} 95 | DEPENDS ${SHADERS_SRC} ${SHADER_SOURCES} 96 | COMMENT "Compiling Shaders Success!" 97 | VERBATIM 98 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${ICONS_SRC}/ ${ICONS_DEST}/ 99 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCES_SRC}/textures/ ${RESOURCES_DEST}/Textures/ 100 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCES_SRC}/models/ ${RESOURCES_DEST}/Models/ 101 | COMMENT "Copying Resources Success!" 102 | VERBATIM 103 | ) 104 | 105 | set(COMPILE_SHADER_TARGET ${PROJECT_NAME}_shader) 106 | set(SHADER_SOURCES ${SHADERS_SRC}/${PROJECT_NAME}_base.frag ${SHADERS_SRC}/${PROJECT_NAME}_base.vert ${SHADERS_SRC}/${PROJECT_NAME}_bg.frag ${SHADERS_SRC}/${PROJECT_NAME}_bg.vert ${SHADERS_SRC}/${PROJECT_NAME}_sm.frag ${SHADERS_SRC}/${PROJECT_NAME}_sm.vert) 107 | add_custom_target(${COMPILE_SHADER_TARGET} ALL DEPENDS SHADER_COMPILE SOURCES ${SHADER_SOURCES}) 108 | add_dependencies (${PROJECT_NAME} ${COMPILE_SHADER_TARGET}) 109 | 110 | set_target_properties(${PROJECT_NAME} PROPERTIES WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 111 | set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF) 112 | if(WIN32) 113 | set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS /SUBSYSTEM:CONSOLE VS_DEBUGGER_WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 114 | endif(WIN32) 115 | if(APPLE) 116 | set_target_properties(${PROJECT_NAME} PROPERTIES XCODE_GENERATE_SCHEME TRUE XCODE_SCHEME_WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 117 | endif(APPLE) 118 | target_link_libraries(${PROJECT_NAME} glfw glm) 119 | endfunction(buildProject) 120 | 121 | # Build all examples 122 | function(buildProjects) 123 | foreach(PROJECT ${PROJECTS}) 124 | buildProject(${PROJECT}) 125 | endforeach(PROJECT) 126 | endfunction(buildProjects) 127 | 128 | set(PROJECTS 129 | draw_with_instance 130 | ) 131 | 132 | buildProjects() 133 | -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/appicons/vulkan_renderer.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-08/draw_with_instance/appicons/vulkan_renderer.icns -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/appicons/vulkan_renderer.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-08/draw_with_instance/appicons/vulkan_renderer.ico -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/appicons/vulkan_renderer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-08/draw_with_instance/appicons/vulkan_renderer.png -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/appicons/vulkan_renderer_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-08/draw_with_instance/appicons/vulkan_renderer_small.png -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/models/cube.obj: -------------------------------------------------------------------------------- 1 | # File exported by Houdini 19.5.493 (www.sidefx.com) 2 | # 26 points 3 | # 144 vertices 4 | # 48 primitives 5 | # Bounds: [-0.5, -0.5, -0.5] to [0.5, 0.5, 0.5] 6 | g 7 | v 0.5 -0.5 0.5 8 | v 0 -0.5 0.5 9 | v 0.5 -0.5 -3.0616168e-17 10 | v 0 -0.5 -3.0616168e-17 11 | v -0.5 -0.5 0.5 12 | v 0.5 -0.5 -0.5 13 | v -0.5 -0.5 -3.0616168e-17 14 | v 0 -0.5 -0.5 15 | v -0.5 -0.5 -0.5 16 | v 0.5 0.5 1.53080837e-16 17 | v 0 0.5 0.5 18 | v 0.5 0.5 0.5 19 | v 0 0.5 1.53080837e-16 20 | v 0.5 0.5 -0.5 21 | v -0.5 0.5 0.5 22 | v 0 0.5 -0.5 23 | v -0.5 0.5 1.53080837e-16 24 | v -0.5 0.5 -0.5 25 | v 0.5 -6.1232336e-17 0.5 26 | v 0 -6.1232336e-17 0.5 27 | v -0.5 -6.1232336e-17 0.5 28 | v 0.5 6.1232336e-17 -0.5 29 | v 0.5 -5.62409909e-33 6.1232336e-17 30 | v -0.5 6.1232336e-17 -0.5 31 | v 0 6.1232336e-17 -0.5 32 | v -0.5 -5.62409909e-33 6.1232336e-17 33 | vt 0 0 0 34 | vt 0.5 0 0 35 | vt 0 0.5 0 36 | vt 0.5 0.5 0 37 | vt 1 0 0 38 | vt 0 1 0 39 | vt 1 0.5 0 40 | vt 0.5 1 0 41 | vt 1 1 0 42 | vn 0.577350378 -0.577350318 0.577350318 43 | vn 0 -0.707106829 0.707106829 44 | vn 0.707106829 -0.707106829 0 45 | vn 0 -1 0 46 | vn -0.577350259 -0.577350318 0.577350318 47 | vn 0.577350259 -0.577350318 -0.577350318 48 | vn -0.707106709 -0.707106769 0 49 | vn 0 -0.707106769 -0.707106709 50 | vn -0.577350378 -0.577350318 -0.577350318 51 | vn 0.707106769 0.707106709 0 52 | vn 0 0.707106709 0.707106769 53 | vn 0.577350318 0.577350318 0.577350378 54 | vn 0 1 0 55 | vn 0.577350318 0.577350318 -0.577350259 56 | vn -0.577350318 0.577350318 0.577350259 57 | vn 0 0.707106769 -0.707106769 58 | vn -0.707106769 0.707106769 0 59 | vn -0.577350318 0.577350318 -0.577350378 60 | vn 0.707106769 0 0.707106709 61 | vn 0 0 1 62 | vn -0.707106709 0 0.707106769 63 | vn 0.707106709 0 -0.707106769 64 | vn 1 0 0 65 | vn -0.707106769 0 -0.707106709 66 | vn 0 0 -1 67 | vn -1 0 0 68 | g 69 | usemtl WorldGridMaterial 70 | f 1/1/1 2/2/2 3/3/3 71 | f 2/2/2 4/4/4 3/3/3 72 | f 2/2/2 5/5/5 4/4/4 73 | f 3/3/3 4/4/4 6/6/6 74 | f 5/5/5 7/7/7 4/4/4 75 | f 4/4/4 8/8/8 6/6/6 76 | f 4/4/4 7/7/7 8/8/8 77 | f 7/7/7 9/9/9 8/8/8 78 | f 10/7/10 11/2/11 12/5/12 79 | f 10/7/10 13/4/13 11/2/11 80 | f 14/9/14 13/4/13 10/7/10 81 | f 13/4/13 15/1/15 11/2/11 82 | f 14/9/14 16/8/16 13/4/13 83 | f 13/4/13 17/3/17 15/1/15 84 | f 16/8/16 17/3/17 13/4/13 85 | f 16/8/16 18/6/18 17/3/17 86 | f 19/7/19 2/2/2 1/5/1 87 | f 19/7/19 20/4/20 2/2/2 88 | f 12/9/12 20/4/20 19/7/19 89 | f 20/4/20 5/1/5 2/2/2 90 | f 12/9/12 11/8/11 20/4/20 91 | f 20/4/20 21/3/21 5/1/5 92 | f 11/8/11 21/3/21 20/4/20 93 | f 11/8/11 15/6/15 21/3/21 94 | f 22/7/22 3/2/3 6/5/6 95 | f 22/7/22 23/4/23 3/2/3 96 | f 14/9/14 23/4/23 22/7/22 97 | f 23/4/23 1/1/1 3/2/3 98 | f 14/9/14 10/8/10 23/4/23 99 | f 23/4/23 19/3/19 1/1/1 100 | f 10/8/10 19/3/19 23/4/23 101 | f 10/8/10 12/6/12 19/3/19 102 | f 24/7/24 8/2/8 9/5/9 103 | f 24/7/24 25/4/25 8/2/8 104 | f 18/9/18 25/4/25 24/7/24 105 | f 25/4/25 6/1/6 8/2/8 106 | f 18/9/18 16/8/16 25/4/25 107 | f 25/4/25 22/3/22 6/1/6 108 | f 16/8/16 22/3/22 25/4/25 109 | f 16/8/16 14/6/14 22/3/22 110 | f 21/7/21 7/2/7 5/5/5 111 | f 21/7/21 26/4/26 7/2/7 112 | f 15/9/15 26/4/26 21/7/21 113 | f 26/4/26 9/1/9 7/2/7 114 | f 15/9/15 17/8/17 26/4/26 115 | f 26/4/26 24/3/24 9/1/9 116 | f 17/8/17 24/3/24 26/4/26 117 | f 17/8/17 18/6/18 24/3/24 118 | -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/shaders/draw_with_instance_base.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | // push constants block 4 | layout( push_constant ) uniform constants 5 | { 6 | float time; 7 | float roughness; 8 | float metallic; 9 | uint specConstants; 10 | uint specConstantsCount; 11 | } global; 12 | 13 | layout(set = 0, binding = 0) uniform uniformbuffer 14 | { 15 | mat4 model; 16 | mat4 view; 17 | mat4 proj; 18 | } ubo; 19 | 20 | // Vertex attributes 21 | layout(location = 0) in vec3 inPosition; 22 | layout(location = 1) in vec3 inNormal; 23 | layout(location = 2) in vec3 inColor; 24 | layout(location = 3) in vec2 inTexCoord; 25 | 26 | layout(location = 0) out vec3 outPosition; 27 | layout(location = 1) out vec3 outPositionWS; 28 | layout(location = 2) out vec3 outNormal; 29 | layout(location = 3) out vec3 outColor; 30 | layout(location = 4) out vec2 outTexCoord; 31 | 32 | void main() 33 | { 34 | // Render object with MVP 35 | vec3 position = inPosition; 36 | gl_Position = ubo.proj * ubo.view * ubo.model * vec4(position, 1.0); 37 | outPosition = position; 38 | outPositionWS = (ubo.model * vec4(position, 1.0)).rgb; 39 | outNormal = (ubo.model * vec4(normalize(inNormal), 1.0)).rgb; 40 | outColor = inColor; 41 | outTexCoord = inTexCoord; 42 | } -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/shaders/draw_with_instance_base_instanced.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | // push constants block 4 | layout( push_constant ) uniform constants 5 | { 6 | float time; 7 | float roughness; 8 | float metallic; 9 | uint specConstants; 10 | uint specConstantsCount; 11 | } global; 12 | 13 | layout(set = 0, binding = 0) uniform uniformbuffer 14 | { 15 | mat4 model; 16 | mat4 view; 17 | mat4 proj; 18 | } ubo; 19 | 20 | // Vertex attributes 21 | layout(location = 0) in vec3 inPosition; 22 | layout(location = 1) in vec3 inNormal; 23 | layout(location = 2) in vec3 inColor; 24 | layout(location = 3) in vec2 inTexCoord; 25 | 26 | // Instanced attributes 27 | layout (location = 4) in vec3 inInstancePosition; 28 | layout (location = 5) in vec3 inInstanceRotation; 29 | layout (location = 6) in float inInstancePScale; 30 | layout (location = 7) in uint inInstanceTexIndex; 31 | 32 | layout(location = 0) out vec3 outPosition; 33 | layout(location = 1) out vec3 outPositionWS; 34 | layout(location = 2) out vec3 outNormal; 35 | layout(location = 3) out vec3 outColor; 36 | layout(location = 4) out vec2 outTexCoord; 37 | 38 | // https://www.ronja-tutorials.com/post/041-hsv-colorspace/ 39 | vec3 Hue2RGB(float hue) { 40 | hue = fract(hue); //only use fractional part of hue, making it loop 41 | float r = abs(hue * 6 - 3) - 1; //red 42 | float g = 2 - abs(hue * 6 - 2); //green 43 | float b = 2 - abs(hue * 6 - 4); //blue 44 | vec3 rgb = vec3(r,g,b); //combine components 45 | rgb = clamp(rgb,0.0,1.0); //clamp between 0 and 1 46 | return rgb; 47 | } 48 | 49 | mat4 MakeRotMatrix(vec3 R) 50 | { 51 | mat4 mx, my, mz; 52 | // rotate around x 53 | float s = sin(R.x); 54 | float c = cos(R.x); 55 | mx[0] = vec4(c, 0.0, s, 0.0); 56 | mx[1] = vec4(0.0, 1.0, 0.0, 0.0); 57 | mx[2] = vec4(-s, 0.0, c, 0.0); 58 | mx[3] = vec4(0.0, 0.0, 0.0, 1.0); 59 | // rotate around y 60 | s = sin(R.y); 61 | c = cos(R.y); 62 | my[0] = vec4(c, s, 0.0, 0.0); 63 | my[1] = vec4(-s, c, 0.0, 0.0); 64 | my[2] = vec4(0.0, 0.0, 1.0, 0.0); 65 | my[3] = vec4(0.0, 0.0, 0.0, 1.0); 66 | // rot around z 67 | s = sin(R.z); 68 | c = cos(R.z); 69 | mz[0] = vec4(1.0, 0.0, 0.0, 0.0); 70 | mz[1] = vec4(0.0, c, s, 0.0); 71 | mz[2] = vec4(0.0, -s, c, 0.0); 72 | mz[3] = vec4(0.0, 0.0, 0.0, 1.0); 73 | 74 | mat4 rotMat = mz * my * mx; 75 | return rotMat; 76 | } 77 | 78 | void main() 79 | { 80 | mat4 rotMat = MakeRotMatrix(inInstanceRotation); 81 | vec3 position = (inPosition * inInstancePScale) * mat3(rotMat) + inInstancePosition; 82 | gl_Position = ubo.proj * ubo.view * ubo.model * vec4(position, 1.0); 83 | outPosition = position; 84 | outPositionWS = (ubo.model * vec4(position, 1.0)).rgb; 85 | outNormal = (ubo.model * vec4(normalize(inNormal), 1.0)).rgb * mat3(rotMat); 86 | outColor = Hue2RGB(inInstanceTexIndex / 256.0f); 87 | outTexCoord = inTexCoord; 88 | } -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/shaders/draw_with_instance_bg.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(binding = 4) uniform sampler2D backgroundSampler; 4 | 5 | layout(location = 0) in vec3 fragColor; 6 | layout(location = 1) in vec2 fragTexCoord; 7 | 8 | layout(location = 0) out vec4 outColor; 9 | 10 | void main() { 11 | vec3 color = texture(backgroundSampler, fragTexCoord).rgb; 12 | 13 | // Gamma correct 14 | color = pow(color, vec3(0.4545)); 15 | 16 | outColor = vec4(color, 1.0); 17 | } -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/shaders/draw_with_instance_bg.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) out vec3 fragColor; 4 | layout(location = 1) out vec2 fragTexCoord; 5 | 6 | vec2 positions[6] = vec2[]( 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 | vec2(1.0, 1.0) 13 | ); 14 | 15 | vec3 colors[6] = vec3[]( 16 | vec3(1.0, 0.0, 0.0), 17 | vec3(0.0, 1.0, 0.0), 18 | vec3(0.0, 0.0, 1.0), 19 | vec3(0.0, 0.0, 1.0), 20 | vec3(0.0, 1.0, 0.0), 21 | vec3(1.0, 0.0, 0.0) 22 | ); 23 | 24 | vec2 uvs[6] = vec2[]( 25 | vec2(0.0, 0.0), 26 | vec2(1.0, 1.0), 27 | vec2(0.0, 1.0), 28 | vec2(0.0, 0.0), 29 | vec2(1.0, 0.0), 30 | vec2(1.0, 1.0) 31 | ); 32 | 33 | void main() { 34 | gl_Position = vec4(positions[gl_VertexIndex], 1.0, 1.0); 35 | fragColor = colors[gl_VertexIndex]; 36 | fragTexCoord = uvs[gl_VertexIndex]; 37 | } -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/shaders/draw_with_instance_sky.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(binding = 4) uniform sampler2D skydomeSampler; 4 | 5 | layout(location = 0) in vec3 fragPosition; 6 | layout(location = 1) in vec3 fragPositionWS; 7 | layout(location = 2) in vec3 fragNormal; 8 | layout(location = 3) in vec3 fragColor; 9 | layout(location = 4) in vec2 fragTexCoord; 10 | 11 | layout(location = 0) out vec4 outColor; 12 | 13 | void main() { 14 | vec3 color = texture(skydomeSampler, fragTexCoord).rgb; 15 | 16 | // Gamma correct 17 | color = pow(color, vec3(0.4545)); 18 | 19 | outColor = vec4(color, 1.0); 20 | } -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/shaders/draw_with_instance_sky.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | 4 | layout(set = 0, binding = 0) uniform uniformbuffer 5 | { 6 | mat4 model; 7 | mat4 view; 8 | mat4 proj; 9 | } ubo; 10 | 11 | // Vertex attributes 12 | layout(location = 0) in vec3 inPosition; 13 | layout(location = 1) in vec3 inNormal; 14 | layout(location = 2) in vec3 inColor; 15 | layout(location = 3) in vec2 inTexCoord; 16 | 17 | layout(location = 0) out vec3 outPosition; 18 | layout(location = 1) out vec3 outPositionWS; 19 | layout(location = 2) out vec3 outNormal; 20 | layout(location = 3) out vec3 outColor; 21 | layout(location = 4) out vec2 outTexCoord; 22 | 23 | void main() 24 | { 25 | // Render object with MVP 26 | vec3 position = inPosition; 27 | gl_Position = ubo.proj * ubo.view * ubo.model * vec4(position, 1.0); 28 | outPosition = position; 29 | outPositionWS = (ubo.model * vec4(position, 1.0)).rgb; 30 | outNormal = (ubo.model * vec4(normalize(inNormal), 1.0)).rgb; 31 | outColor = inColor; 32 | outTexCoord = inTexCoord; 33 | } -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/shaders/draw_with_instance_sm.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) out vec4 outColor; 4 | 5 | void main() 6 | { 7 | outColor = vec4(1.0, 1.0, 1.0, 1.0); 8 | } -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/shaders/draw_with_instance_sm.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | // push constants block 4 | layout( push_constant ) uniform constants 5 | { 6 | float time; 7 | float roughness; 8 | float metallic; 9 | uint specConstants; 10 | uint specConstantsCount; 11 | } global; 12 | 13 | layout(set = 0, binding = 0) uniform uniformbuffer 14 | { 15 | mat4 model; 16 | mat4 view; 17 | mat4 proj; 18 | } ubo; 19 | 20 | layout(location = 0) in vec3 inPosition; 21 | layout(location = 1) in vec3 inNormal; 22 | layout(location = 2) in vec3 inColor; 23 | layout(location = 3) in vec2 inTexCoord; 24 | 25 | void main() 26 | { 27 | vec3 position = inPosition; 28 | gl_Position = ubo.proj * ubo.view * ubo.model * vec4(position, 1.0); 29 | } -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/shaders/draw_with_instance_sm_instanced.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | // push constants block 4 | layout( push_constant ) uniform constants 5 | { 6 | float time; 7 | float roughness; 8 | float metallic; 9 | uint specConstants; 10 | uint specConstantsCount; 11 | } global; 12 | 13 | layout(set = 0, binding = 0) uniform uniformbuffer 14 | { 15 | mat4 model; 16 | mat4 view; 17 | mat4 proj; 18 | } ubo; 19 | 20 | layout(location = 0) in vec3 inPosition; 21 | layout(location = 1) in vec3 inNormal; 22 | layout(location = 2) in vec3 inColor; 23 | layout(location = 3) in vec2 inTexCoord; 24 | 25 | // Instanced attributes 26 | layout (location = 4) in vec3 inInstancePosition; 27 | layout (location = 5) in vec3 inInstanceRotation; 28 | layout (location = 6) in float inInstancePScale; 29 | layout (location = 7) in uint inInstanceTexIndex; 30 | 31 | mat4 MakeRotMatrix(vec3 R) 32 | { 33 | mat4 mx, my, mz; 34 | // rotate around x 35 | float s = sin(R.x); 36 | float c = cos(R.x); 37 | mx[0] = vec4(c, 0.0, s, 0.0); 38 | mx[1] = vec4(0.0, 1.0, 0.0, 0.0); 39 | mx[2] = vec4(-s, 0.0, c, 0.0); 40 | mx[3] = vec4(0.0, 0.0, 0.0, 1.0); 41 | // rotate around y 42 | s = sin(R.y); 43 | c = cos(R.y); 44 | my[0] = vec4(c, s, 0.0, 0.0); 45 | my[1] = vec4(-s, c, 0.0, 0.0); 46 | my[2] = vec4(0.0, 0.0, 1.0, 0.0); 47 | my[3] = vec4(0.0, 0.0, 0.0, 1.0); 48 | // rot around z 49 | s = sin(R.z); 50 | c = cos(R.z); 51 | mz[0] = vec4(1.0, 0.0, 0.0, 0.0); 52 | mz[1] = vec4(0.0, c, s, 0.0); 53 | mz[2] = vec4(0.0, -s, c, 0.0); 54 | mz[3] = vec4(0.0, 0.0, 0.0, 1.0); 55 | 56 | mat4 rotMat = mz * my * mx; 57 | return rotMat; 58 | } 59 | 60 | void main() 61 | { 62 | mat4 rotMat = MakeRotMatrix(inInstanceRotation); 63 | vec3 position = (inPosition * inInstancePScale) * mat3(rotMat) + inInstancePosition; 64 | gl_Position = ubo.proj * ubo.view * ubo.model * vec4(position, 1.0); 65 | } -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/textures/antarctic_meteorite_bc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-08/draw_with_instance/textures/antarctic_meteorite_bc.png -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/textures/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-08/draw_with_instance/textures/background.png -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/textures/cubemap_X0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-08/draw_with_instance/textures/cubemap_X0.png -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/textures/cubemap_X1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-08/draw_with_instance/textures/cubemap_X1.png -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/textures/cubemap_Y2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-08/draw_with_instance/textures/cubemap_Y2.png -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/textures/cubemap_Y3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-08/draw_with_instance/textures/cubemap_Y3.png -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/textures/cubemap_Z4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-08/draw_with_instance/textures/cubemap_Z4.png -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/textures/cubemap_Z5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-08/draw_with_instance/textures/cubemap_Z5.png -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/textures/default_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-08/draw_with_instance/textures/default_black.png -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/textures/default_grey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-08/draw_with_instance/textures/default_grey.png -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/textures/default_grid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-08/draw_with_instance/textures/default_grid.png -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/textures/default_grid_n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-08/draw_with_instance/textures/default_grid_n.png -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/textures/default_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-08/draw_with_instance/textures/default_normal.png -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/textures/default_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-08/draw_with_instance/textures/default_white.png -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/textures/galaxy_dome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-08/draw_with_instance/textures/galaxy_dome.png -------------------------------------------------------------------------------- /LearnVulkan-08/draw_with_instance/textures/jupiter_bc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-08/draw_with_instance/textures/jupiter_bc.png -------------------------------------------------------------------------------- /LearnVulkan-09/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Function for building single example 2 | include(CMakeParseArguments) 3 | 4 | function(AddIconToBinary AppSources) 5 | set(Options) 6 | set(OneValueArgs OUTFILE_BASENAME) 7 | set(MultiValueArgs ICONS) 8 | cmake_parse_arguments(ARG "${Options}" "${OneValueArgs}" "${MultiValueArgs}" ${ARGN}) 9 | if (NOT ARG_ICONS) 10 | message(FATAL_ERROR "No ICONS argument given to AddIconToBinary") 11 | endif() 12 | if (ARG_UNPARSED_ARGUMENTS) 13 | message(FATAL_ERROR "Unexpected arguments to ecm_add_app_icon: ${ARG_UNPARSED_ARGUMENTS}") 14 | endif() 15 | foreach (icon ${ARG_ICONS}) 16 | get_filename_component(IconFull ${icon} ABSOLUTE) 17 | get_filename_component(IconType ${IconFull} EXT) 18 | get_filename_component(IconName ${IconFull} NAME_WE) 19 | if (APPLE) 20 | if (${IconType} STREQUAL ".icns") 21 | set(IconFullOutput ${CMAKE_CURRENT_BINARY_DIR}/${IconName}.icns) 22 | configure_file(${IconFull} ${IconFullOutput} COPYONLY) 23 | set(MACOSX_BUNDLE_ICON_FILE ${IconName}.icns PARENT_SCOPE) 24 | set(${AppSources} "${${AppSources}};${IconFullOutput}" PARENT_SCOPE) 25 | set_source_files_properties(${IconFullOutput} PROPERTIES MACOSX_PACKAGE_LOCATION Resources) 26 | return() 27 | endif() 28 | endif() 29 | if (MSVC) 30 | if (${IconType} STREQUAL ".ico") 31 | set(IconFullOutput ${CMAKE_CURRENT_BINARY_DIR}/${IconName}.ico) 32 | configure_file(${IconFull} ${IconFullOutput} COPYONLY) 33 | file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${IconName}.rc.in" "IDI_ICON1 ICON DISCARDABLE\"${IconName}.ico\"\n") 34 | add_custom_command( 35 | OUTPUT "${IconName}.rc" 36 | COMMAND ${CMAKE_COMMAND} 37 | ARGS -E copy "${IconName}.rc.in" "${IconName}.rc" 38 | DEPENDS "${IconName}.ico" 39 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") 40 | set(${AppSources} "${${AppSources}};${IconName}.rc" PARENT_SCOPE) 41 | return() 42 | endif() 43 | endif() 44 | endforeach() 45 | return() 46 | endfunction() 47 | 48 | function(buildProject PROJECT_NAME) 49 | SET(EXAMPLE_FOLDER ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}) 50 | message(STATUS "Generating project file for example in ${EXAMPLE_FOLDER}") 51 | # Main 52 | # file(GLOB SOURCE *.cpp ${BASE_HEADERS} ${EXAMPLE_FOLDER}/*.cpp) 53 | SET(MAIN_CPP ${EXAMPLE_FOLDER}/${PROJECT_NAME}.cpp) 54 | set (CURRENT_WORKING_DIR ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}) 55 | set (ICONS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/appicons) 56 | set (ICONS_DEST ${CURRENT_WORKING_DIR}/Resources/Appicons) 57 | set (SHADERS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}/shaders) 58 | set (SHADERS_DEST ${CURRENT_WORKING_DIR}/Resources/Shaders) 59 | set (RESOURCES_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}) 60 | set (RESOURCES_DEST ${CURRENT_WORKING_DIR}/Resources) 61 | 62 | if(EXISTS ${EXAMPLE_FOLDER}/main.cpp) 63 | SET(MAIN_CPP ${EXAMPLE_FOLDER}/main.cpp) 64 | endif() 65 | if(EXISTS ${EXAMPLE_FOLDER}/${PROJECT_NAME}.h) 66 | SET(MAIN_HEADER ${EXAMPLE_FOLDER}/${PROJECT_NAME}.h) 67 | endif() 68 | # Set application icon 69 | AddIconToBinary(MAIN_CPP ICONS ${ICONS_SRC}/vulkan_renderer.ico ${ICONS_SRC}/vulkan_renderer.icns) 70 | if(WIN32) 71 | add_compile_options("$<$:/utf-8>") 72 | add_compile_options("$<$:/utf-8>") 73 | add_executable(${PROJECT_NAME} WIN32 ${MAIN_CPP}) 74 | target_link_libraries(${PROJECT_NAME} ${Vulkan_LIBRARY} ${WINLIBS}) 75 | else(WIN32) 76 | add_executable(${PROJECT_NAME} ${MAIN_CPP}) 77 | target_link_libraries(${PROJECT_NAME}) 78 | endif(WIN32) 79 | 80 | # Compile shader and copy texures 81 | add_custom_command( 82 | OUTPUT SHADER_COMPILE 83 | COMMAND ${CMAKE_COMMAND} -E make_directory ${SHADERS_DEST} 84 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_base.frag -o ${SHADERS_DEST}/${PROJECT_NAME}_base_frag.spv 85 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_base.vert -o ${SHADERS_DEST}/${PROJECT_NAME}_base_vert.spv 86 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_base_instanced.vert -o ${SHADERS_DEST}/${PROJECT_NAME}_base_instanced_vert.spv 87 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_scene.frag -o ${SHADERS_DEST}/${PROJECT_NAME}_scene_frag.spv 88 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_lighting.frag -o ${SHADERS_DEST}/${PROJECT_NAME}_lighting_frag.spv 89 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_sm.frag -o ${SHADERS_DEST}/${PROJECT_NAME}_sm_frag.spv 90 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_sm.vert -o ${SHADERS_DEST}/${PROJECT_NAME}_sm_vert.spv 91 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_sm_instanced.vert -o ${SHADERS_DEST}/${PROJECT_NAME}_sm_instanced_vert.spv 92 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_bg.frag -o ${SHADERS_DEST}/${PROJECT_NAME}_bg_frag.spv 93 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_bg.vert -o ${SHADERS_DEST}/${PROJECT_NAME}_bg_vert.spv 94 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_sky.frag -o ${SHADERS_DEST}/${PROJECT_NAME}_sky_frag.spv 95 | COMMAND glslc ARGS -g ${SHADERS_SRC}/${PROJECT_NAME}_sky.vert -o ${SHADERS_DEST}/${PROJECT_NAME}_sky_vert.spv 96 | WORKING_DIRECTORY ${SHADERS_SRC} 97 | DEPENDS ${SHADERS_SRC} ${SHADER_SOURCES} 98 | COMMENT "Compiling Shaders Success!" 99 | VERBATIM 100 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${ICONS_SRC}/ ${ICONS_DEST}/ 101 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCES_SRC}/textures/ ${RESOURCES_DEST}/Textures/ 102 | COMMAND ${CMAKE_COMMAND} -E copy_directory ${RESOURCES_SRC}/models/ ${RESOURCES_DEST}/Models/ 103 | COMMENT "Copying Resources Success!" 104 | VERBATIM 105 | ) 106 | 107 | set(COMPILE_SHADER_TARGET ${PROJECT_NAME}_shader) 108 | set(SHADER_SOURCES 109 | ${SHADERS_SRC}/${PROJECT_NAME}_base.frag 110 | ${SHADERS_SRC}/${PROJECT_NAME}_base.vert 111 | ${SHADERS_SRC}/${PROJECT_NAME}_base_instanced.vert 112 | ${SHADERS_SRC}/${PROJECT_NAME}_lighting.frag 113 | ${SHADERS_SRC}/${PROJECT_NAME}_scene.frag 114 | ${SHADERS_SRC}/${PROJECT_NAME}_bg.frag 115 | ${SHADERS_SRC}/${PROJECT_NAME}_bg.vert 116 | ${SHADERS_SRC}/${PROJECT_NAME}_sky.frag 117 | ${SHADERS_SRC}/${PROJECT_NAME}_sky.vert 118 | ${SHADERS_SRC}/${PROJECT_NAME}_sm.frag 119 | ${SHADERS_SRC}/${PROJECT_NAME}_sm.vert) 120 | add_custom_target(${COMPILE_SHADER_TARGET} ALL DEPENDS SHADER_COMPILE SOURCES ${SHADER_SOURCES}) 121 | add_dependencies (${PROJECT_NAME} ${COMPILE_SHADER_TARGET}) 122 | 123 | set_target_properties(${PROJECT_NAME} PROPERTIES WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 124 | set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF) 125 | if(WIN32) 126 | set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS /SUBSYSTEM:CONSOLE VS_DEBUGGER_WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 127 | endif(WIN32) 128 | if(APPLE) 129 | set_target_properties(${PROJECT_NAME} PROPERTIES XCODE_GENERATE_SCHEME TRUE XCODE_SCHEME_WORKING_DIRECTORY ${CURRENT_WORKING_DIR}) 130 | endif(APPLE) 131 | target_link_libraries(${PROJECT_NAME} glfw glm) 132 | endfunction(buildProject) 133 | 134 | # Build all examples 135 | function(buildProjects) 136 | foreach(PROJECT ${PROJECTS}) 137 | buildProject(${PROJECT}) 138 | endforeach(PROJECT) 139 | endfunction(buildProjects) 140 | 141 | set(PROJECTS 142 | draw_with_deferred 143 | ) 144 | 145 | buildProjects() 146 | -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/appicons/vulkan_renderer.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/appicons/vulkan_renderer.icns -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/appicons/vulkan_renderer.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/appicons/vulkan_renderer.ico -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/appicons/vulkan_renderer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/appicons/vulkan_renderer.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/appicons/vulkan_renderer_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/appicons/vulkan_renderer_small.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/models/cube.obj: -------------------------------------------------------------------------------- 1 | # File exported by Houdini 19.5.493 (www.sidefx.com) 2 | # 26 points 3 | # 144 vertices 4 | # 48 primitives 5 | # Bounds: [-0.5, -0.5, -0.5] to [0.5, 0.5, 0.5] 6 | g 7 | v 0.5 -0.5 0.5 8 | v 0 -0.5 0.5 9 | v 0.5 -0.5 -3.0616168e-17 10 | v 0 -0.5 -3.0616168e-17 11 | v -0.5 -0.5 0.5 12 | v 0.5 -0.5 -0.5 13 | v -0.5 -0.5 -3.0616168e-17 14 | v 0 -0.5 -0.5 15 | v -0.5 -0.5 -0.5 16 | v 0.5 0.5 1.53080837e-16 17 | v 0 0.5 0.5 18 | v 0.5 0.5 0.5 19 | v 0 0.5 1.53080837e-16 20 | v 0.5 0.5 -0.5 21 | v -0.5 0.5 0.5 22 | v 0 0.5 -0.5 23 | v -0.5 0.5 1.53080837e-16 24 | v -0.5 0.5 -0.5 25 | v 0.5 -6.1232336e-17 0.5 26 | v 0 -6.1232336e-17 0.5 27 | v -0.5 -6.1232336e-17 0.5 28 | v 0.5 6.1232336e-17 -0.5 29 | v 0.5 -5.62409909e-33 6.1232336e-17 30 | v -0.5 6.1232336e-17 -0.5 31 | v 0 6.1232336e-17 -0.5 32 | v -0.5 -5.62409909e-33 6.1232336e-17 33 | vt 0 0 0 34 | vt 0.5 0 0 35 | vt 0 0.5 0 36 | vt 0.5 0.5 0 37 | vt 1 0 0 38 | vt 0 1 0 39 | vt 1 0.5 0 40 | vt 0.5 1 0 41 | vt 1 1 0 42 | vn 0.577350378 -0.577350318 0.577350318 43 | vn 0 -0.707106829 0.707106829 44 | vn 0.707106829 -0.707106829 0 45 | vn 0 -1 0 46 | vn -0.577350259 -0.577350318 0.577350318 47 | vn 0.577350259 -0.577350318 -0.577350318 48 | vn -0.707106709 -0.707106769 0 49 | vn 0 -0.707106769 -0.707106709 50 | vn -0.577350378 -0.577350318 -0.577350318 51 | vn 0.707106769 0.707106709 0 52 | vn 0 0.707106709 0.707106769 53 | vn 0.577350318 0.577350318 0.577350378 54 | vn 0 1 0 55 | vn 0.577350318 0.577350318 -0.577350259 56 | vn -0.577350318 0.577350318 0.577350259 57 | vn 0 0.707106769 -0.707106769 58 | vn -0.707106769 0.707106769 0 59 | vn -0.577350318 0.577350318 -0.577350378 60 | vn 0.707106769 0 0.707106709 61 | vn 0 0 1 62 | vn -0.707106709 0 0.707106769 63 | vn 0.707106709 0 -0.707106769 64 | vn 1 0 0 65 | vn -0.707106769 0 -0.707106709 66 | vn 0 0 -1 67 | vn -1 0 0 68 | g 69 | usemtl WorldGridMaterial 70 | f 1/1/1 2/2/2 3/3/3 71 | f 2/2/2 4/4/4 3/3/3 72 | f 2/2/2 5/5/5 4/4/4 73 | f 3/3/3 4/4/4 6/6/6 74 | f 5/5/5 7/7/7 4/4/4 75 | f 4/4/4 8/8/8 6/6/6 76 | f 4/4/4 7/7/7 8/8/8 77 | f 7/7/7 9/9/9 8/8/8 78 | f 10/7/10 11/2/11 12/5/12 79 | f 10/7/10 13/4/13 11/2/11 80 | f 14/9/14 13/4/13 10/7/10 81 | f 13/4/13 15/1/15 11/2/11 82 | f 14/9/14 16/8/16 13/4/13 83 | f 13/4/13 17/3/17 15/1/15 84 | f 16/8/16 17/3/17 13/4/13 85 | f 16/8/16 18/6/18 17/3/17 86 | f 19/7/19 2/2/2 1/5/1 87 | f 19/7/19 20/4/20 2/2/2 88 | f 12/9/12 20/4/20 19/7/19 89 | f 20/4/20 5/1/5 2/2/2 90 | f 12/9/12 11/8/11 20/4/20 91 | f 20/4/20 21/3/21 5/1/5 92 | f 11/8/11 21/3/21 20/4/20 93 | f 11/8/11 15/6/15 21/3/21 94 | f 22/7/22 3/2/3 6/5/6 95 | f 22/7/22 23/4/23 3/2/3 96 | f 14/9/14 23/4/23 22/7/22 97 | f 23/4/23 1/1/1 3/2/3 98 | f 14/9/14 10/8/10 23/4/23 99 | f 23/4/23 19/3/19 1/1/1 100 | f 10/8/10 19/3/19 23/4/23 101 | f 10/8/10 12/6/12 19/3/19 102 | f 24/7/24 8/2/8 9/5/9 103 | f 24/7/24 25/4/25 8/2/8 104 | f 18/9/18 25/4/25 24/7/24 105 | f 25/4/25 6/1/6 8/2/8 106 | f 18/9/18 16/8/16 25/4/25 107 | f 25/4/25 22/3/22 6/1/6 108 | f 16/8/16 22/3/22 25/4/25 109 | f 16/8/16 14/6/14 22/3/22 110 | f 21/7/21 7/2/7 5/5/5 111 | f 21/7/21 26/4/26 7/2/7 112 | f 15/9/15 26/4/26 21/7/21 113 | f 26/4/26 9/1/9 7/2/7 114 | f 15/9/15 17/8/17 26/4/26 115 | f 26/4/26 24/3/24 9/1/9 116 | f 17/8/17 24/3/24 26/4/26 117 | f 17/8/17 18/6/18 24/3/24 118 | -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/shaders/draw_with_deferred_base.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | // push constants block 4 | layout( push_constant ) uniform constants 5 | { 6 | float time; 7 | float roughness; 8 | float metallic; 9 | uint specConstants; 10 | uint specConstantsCount; 11 | } global; 12 | 13 | layout(set = 0, binding = 0) uniform uniformbuffer 14 | { 15 | mat4 model; 16 | mat4 view; 17 | mat4 proj; 18 | } ubo; 19 | 20 | // Vertex attributes 21 | layout(location = 0) in vec3 inPosition; 22 | layout(location = 1) in vec3 inNormal; 23 | layout(location = 2) in vec3 inColor; 24 | layout(location = 3) in vec2 inTexCoord; 25 | 26 | layout(location = 0) out vec3 outPosition; 27 | layout(location = 1) out vec3 outNormal; 28 | layout(location = 2) out vec3 outColor; 29 | layout(location = 3) out vec2 outTexCoord; 30 | 31 | void main() 32 | { 33 | // Render object with MVP 34 | vec3 position = inPosition; 35 | gl_Position = ubo.proj * ubo.view * ubo.model * vec4(position, 1.0); 36 | outPosition = (ubo.model * vec4(position, 1.0)).rgb; 37 | outNormal = (ubo.model * vec4(normalize(inNormal), 1.0)).rgb; 38 | outColor = inColor; 39 | outTexCoord = inTexCoord; 40 | } -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/shaders/draw_with_deferred_base_instanced.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | // push constants block 4 | layout( push_constant ) uniform constants 5 | { 6 | float time; 7 | float roughness; 8 | float metallic; 9 | uint specConstants; 10 | uint specConstantsCount; 11 | } global; 12 | 13 | layout(set = 0, binding = 0) uniform uniformbuffer 14 | { 15 | mat4 model; 16 | mat4 view; 17 | mat4 proj; 18 | } ubo; 19 | 20 | // Vertex attributes 21 | layout(location = 0) in vec3 inPosition; 22 | layout(location = 1) in vec3 inNormal; 23 | layout(location = 2) in vec3 inColor; 24 | layout(location = 3) in vec2 inTexCoord; 25 | 26 | // Instanced attributes 27 | layout (location = 4) in vec3 inInstancePosition; 28 | layout (location = 5) in vec3 inInstanceRotation; 29 | layout (location = 6) in float inInstancePScale; 30 | layout (location = 7) in uint inInstanceTexIndex; 31 | 32 | layout(location = 0) out vec3 outPosition; 33 | layout(location = 1) out vec3 outNormal; 34 | layout(location = 2) out vec3 outColor; 35 | layout(location = 3) out vec2 outTexCoord; 36 | 37 | 38 | // https://www.ronja-tutorials.com/post/041-hsv-colorspace/ 39 | vec3 Hue2RGB(float hue) { 40 | hue = fract(hue); //only use fractional part of hue, making it loop 41 | float r = abs(hue * 6 - 3) - 1; //red 42 | float g = 2 - abs(hue * 6 - 2); //green 43 | float b = 2 - abs(hue * 6 - 4); //blue 44 | vec3 rgb = vec3(r,g,b); //combine components 45 | rgb = clamp(rgb,0.0,1.0); //clamp between 0 and 1 46 | return rgb; 47 | } 48 | 49 | mat4 MakeRotMatrix(vec3 R) 50 | { 51 | mat4 mx, my, mz; 52 | // rotate around x 53 | float s = sin(R.x); 54 | float c = cos(R.x); 55 | mx[0] = vec4(c, 0.0, s, 0.0); 56 | mx[1] = vec4(0.0, 1.0, 0.0, 0.0); 57 | mx[2] = vec4(-s, 0.0, c, 0.0); 58 | mx[3] = vec4(0.0, 0.0, 0.0, 1.0); 59 | // rotate around y 60 | s = sin(R.y); 61 | c = cos(R.y); 62 | my[0] = vec4(c, s, 0.0, 0.0); 63 | my[1] = vec4(-s, c, 0.0, 0.0); 64 | my[2] = vec4(0.0, 0.0, 1.0, 0.0); 65 | my[3] = vec4(0.0, 0.0, 0.0, 1.0); 66 | // rot around z 67 | s = sin(R.z); 68 | c = cos(R.z); 69 | mz[0] = vec4(1.0, 0.0, 0.0, 0.0); 70 | mz[1] = vec4(0.0, c, s, 0.0); 71 | mz[2] = vec4(0.0, -s, c, 0.0); 72 | mz[3] = vec4(0.0, 0.0, 0.0, 1.0); 73 | 74 | mat4 rotMat = mz * my * mx; 75 | return rotMat; 76 | } 77 | 78 | void main() 79 | { 80 | mat4 rotMat = MakeRotMatrix(inInstanceRotation); 81 | vec3 position = (inPosition * inInstancePScale) * mat3(rotMat) + inInstancePosition; 82 | gl_Position = ubo.proj * ubo.view * ubo.model * vec4(position, 1.0); 83 | outPosition = (ubo.model * vec4(position, 1.0)).rgb; 84 | outNormal = (ubo.model * vec4(normalize(inNormal), 1.0)).rgb * mat3(rotMat); 85 | outColor = Hue2RGB(inInstanceTexIndex / 256.0f); 86 | outTexCoord = inTexCoord; 87 | } -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/shaders/draw_with_deferred_bg.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(binding = 4) uniform sampler2D backgroundSampler; 4 | 5 | layout(location = 0) in vec3 fragColor; 6 | layout(location = 1) in vec2 fragTexCoord; 7 | 8 | layout(location = 0) out vec4 outColor; 9 | 10 | void main() { 11 | vec3 color = texture(backgroundSampler, fragTexCoord).rgb; 12 | 13 | // Gamma correct 14 | color = pow(color, vec3(0.4545)); 15 | 16 | outColor = vec4(color, 1.0); 17 | } -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/shaders/draw_with_deferred_bg.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) out vec3 fragColor; 4 | layout(location = 1) out vec2 fragTexCoord; 5 | 6 | vec2 positions[6] = vec2[]( 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 | vec2(1.0, -1.0) 13 | ); 14 | 15 | vec3 colors[6] = vec3[]( 16 | vec3(1.0, 0.0, 0.0), 17 | vec3(0.0, 0.0, 1.0), 18 | vec3(0.0, 1.0, 0.0), 19 | vec3(1.0, 0.0, 0.0), 20 | vec3(0.0, 1.0, 0.0), 21 | vec3(0.0, 0.0, 1.0) 22 | ); 23 | 24 | vec2 uvs[6] = vec2[]( 25 | vec2(0.0, 0.0), 26 | vec2(0.0, 1.0), 27 | vec2(1.0, 1.0), 28 | vec2(0.0, 0.0), 29 | vec2(1.0, 1.0), 30 | vec2(1.0, 0.0) 31 | ); 32 | 33 | void main() { 34 | gl_Position = vec4(positions[gl_VertexIndex], 1.0, 1.0); 35 | fragColor = colors[gl_VertexIndex]; 36 | fragTexCoord = uvs[gl_VertexIndex]; 37 | } -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/shaders/draw_with_deferred_scene.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | // Use this constant to control the flow of the shader depending on the SPEC_CONSTANTS value 4 | // selected at pipeline creation time 5 | layout (constant_id = 0) const int SPEC_CONSTANTS = 0; 6 | 7 | layout(set = 0, binding = 2) uniform samplerCube skycubemap; // cubemap 8 | layout(set = 0, binding = 3) uniform sampler2D shadowmap; // shadowmap 9 | layout(set = 0, binding = 4) uniform sampler2D sampler1; // basecolor 10 | layout(set = 0, binding = 5) uniform sampler2D sampler2; // metalic 11 | layout(set = 0, binding = 6) uniform sampler2D sampler3; // roughness 12 | layout(set = 0, binding = 7) uniform sampler2D sampler4; // normal 13 | layout(set = 0, binding = 8) uniform sampler2D sampler5; // ambient occlution 14 | layout(set = 0, binding = 9) uniform sampler2D sampler6; // emissive 15 | layout(set = 0, binding = 10) uniform sampler2D sampler7; // mask 16 | 17 | layout(location = 0) in vec3 fragPosition; 18 | layout(location = 1) in vec3 fragNormal; 19 | layout(location = 2) in vec3 fragColor; 20 | layout(location = 3) in vec2 fragTexCoord; 21 | 22 | layout(location = 0) out vec4 outSceneColor; 23 | layout(location = 1) out vec4 outGBufferA; 24 | layout(location = 2) out vec4 outGBufferB; 25 | layout(location = 3) out vec4 outGBufferC; 26 | layout(location = 4) out vec4 outGBufferD; 27 | 28 | 29 | vec3 ComputeNormal() 30 | { 31 | vec3 pos_dx = dFdx(fragPosition); 32 | vec3 pos_dy = dFdy(fragPosition); 33 | vec3 st1 = dFdx(vec3(fragTexCoord, 0.0)); 34 | vec3 st2 = dFdy(vec3(fragTexCoord, 0.0)); 35 | vec3 T = (st2.t * pos_dx - st1.t * pos_dy) / (st1.s * st2.t - st2.s * st1.t); 36 | vec3 N = normalize(fragNormal); 37 | T = normalize(T - N * dot(N, T)); 38 | vec3 B = normalize(cross(N, T)); 39 | mat3 TBN = mat3(T, B, N); 40 | 41 | return normalize(TBN[2].xyz); 42 | } 43 | 44 | 45 | vec3 ComputeNormal(vec3 n) 46 | { 47 | vec3 pos_dx = dFdx(fragPosition); 48 | vec3 pos_dy = dFdy(fragPosition); 49 | vec3 st1 = dFdx(vec3(fragTexCoord, 0.0)); 50 | vec3 st2 = dFdy(vec3(fragTexCoord, 0.0)); 51 | vec3 T = (st2.t * pos_dx - st1.t * pos_dy) / (st1.s * st2.t - st2.s * st1.t); 52 | vec3 N = normalize(fragNormal); 53 | T = normalize(T - N * dot(N, T)); 54 | vec3 B = normalize(cross(N, T)); 55 | mat3 TBN = mat3(T, B, N); 56 | 57 | return normalize(TBN * normalize(2.0 * n - 1.0)); 58 | } 59 | 60 | 61 | void main() 62 | { 63 | vec3 VertexColor = fragColor; 64 | 65 | vec3 BaseColor = texture(sampler1, fragTexCoord).rgb; 66 | float Metallic = texture(sampler2, fragTexCoord).r; 67 | float Roughness = texture(sampler3, fragTexCoord).r; 68 | vec3 Normal = ComputeNormal(texture(sampler4, fragTexCoord).rgb); 69 | vec3 AmbientOcclution = texture(sampler5, fragTexCoord).rgb; 70 | vec3 Emissive = texture(sampler6, fragTexCoord).rgb; 71 | vec3 OpacityMask = texture(sampler7, fragTexCoord).rgb; 72 | 73 | Roughness = max(0.01, Roughness); 74 | float AO = AmbientOcclution.r; 75 | vec3 NormalPacked = (normalize(Normal) + 1.0) / 2.0; 76 | float Mask = OpacityMask.r; 77 | 78 | outSceneColor = vec4(Emissive, Mask);; 79 | outGBufferA = vec4(vec3(NormalPacked), 1.0); 80 | outGBufferB = vec4(vec3(Metallic, 1.0, Roughness), 1.0); 81 | outGBufferC = vec4(vec3(BaseColor), AO); 82 | outGBufferD = vec4(vec3(fragPosition), 1.0); 83 | } 84 | -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/shaders/draw_with_deferred_sky.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | struct light 4 | { 5 | vec4 position; // position.w represents type of light 6 | vec4 color; // color.w represents light intensity 7 | vec4 direction; // direction.w represents range 8 | vec4 info; // (only used for spot lights) info.x represents light inner cone angle, info.y represents light outer cone angle 9 | }; 10 | 11 | layout(set = 0, binding = 1) uniform uniformbuffer 12 | { 13 | mat4 shadowmapSpace; 14 | mat4 localToWorld; 15 | vec4 cameraInfo; 16 | light directionalLights[4]; 17 | light pointLights[4]; 18 | light spotLights[4]; 19 | ivec4 lightsCount; // [0] for directionalLights, [1] for pointLights, [2] for spotLights 20 | float zNear; 21 | float zFar; 22 | } view; 23 | layout(set = 0, binding = 2) uniform samplerCube CubemapSampler; 24 | layout(set = 0, binding = 3) uniform sampler2D ShadowMapSampler; 25 | layout(set = 0, binding = 4) uniform sampler2D SkydomeSampler; 26 | 27 | layout(location = 0) in vec3 fragPosition; 28 | layout(location = 1) in vec3 fragNormal; 29 | layout(location = 2) in vec3 fragColor; 30 | layout(location = 3) in vec2 fragTexCoord; 31 | 32 | layout(location = 0) out vec4 outColor; 33 | 34 | void main() { 35 | vec3 SkydomeColor = texture(SkydomeSampler, fragTexCoord).rgb; 36 | 37 | vec3 N = -fragNormal; // skydome's normal point to the centre of sphere 38 | vec3 P = fragPosition; 39 | vec3 V = normalize(view.cameraInfo.xyz - P); 40 | vec3 I = V; 41 | float ratio = 1.00 / 1.52; 42 | vec3 R = refract(I, normalize(N), ratio); 43 | vec3 CubeMapColor = textureLod(CubemapSampler, R, 0).rgb * 10.0; 44 | 45 | // Gamma correct 46 | vec3 FinalColor = pow(SkydomeColor, vec3(0.4545)); 47 | 48 | outColor = vec4(FinalColor, 1.0); 49 | } -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/shaders/draw_with_deferred_sky.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | 4 | layout(set = 0, binding = 0) uniform uniformbuffer 5 | { 6 | mat4 model; 7 | mat4 view; 8 | mat4 proj; 9 | } ubo; 10 | 11 | // Vertex attributes 12 | layout(location = 0) in vec3 inPosition; 13 | layout(location = 1) in vec3 inNormal; 14 | layout(location = 2) in vec3 inColor; 15 | layout(location = 3) in vec2 inTexCoord; 16 | 17 | layout(location = 0) out vec3 outPosition; 18 | layout(location = 1) out vec3 outNormal; 19 | layout(location = 2) out vec3 outColor; 20 | layout(location = 3) out vec2 outTexCoord; 21 | 22 | void main() 23 | { 24 | // Render object with MVP 25 | vec3 position = inPosition; 26 | gl_Position = ubo.proj * ubo.view * ubo.model * vec4(position, 1.0); 27 | outPosition = (ubo.model * vec4(position, 1.0)).rgb; 28 | outNormal = (ubo.model * vec4(normalize(inNormal), 1.0)).rgb; 29 | outColor = inColor; 30 | outTexCoord = inTexCoord; 31 | } -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/shaders/draw_with_deferred_sm.frag: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) out vec4 outColor; 4 | 5 | void main() 6 | { 7 | outColor = vec4(1.0, 1.0, 1.0, 1.0); 8 | } -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/shaders/draw_with_deferred_sm.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | // push constants block 4 | layout( push_constant ) uniform constants 5 | { 6 | float time; 7 | float roughness; 8 | float metallic; 9 | uint specConstants; 10 | uint specConstantsCount; 11 | } global; 12 | 13 | layout(set = 0, binding = 0) uniform uniformbuffer 14 | { 15 | mat4 model; 16 | mat4 view; 17 | mat4 proj; 18 | } ubo; 19 | 20 | layout(location = 0) in vec3 inPosition; 21 | layout(location = 1) in vec3 inNormal; 22 | layout(location = 2) in vec3 inColor; 23 | layout(location = 3) in vec2 inTexCoord; 24 | 25 | void main() 26 | { 27 | vec3 position = inPosition; 28 | gl_Position = ubo.proj * ubo.view * ubo.model * vec4(position, 1.0); 29 | } -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/shaders/draw_with_deferred_sm_instanced.vert: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | // push constants block 4 | layout( push_constant ) uniform constants 5 | { 6 | float time; 7 | float roughness; 8 | float metallic; 9 | uint specConstants; 10 | uint specConstantsCount; 11 | } global; 12 | 13 | layout(set = 0, binding = 0) uniform uniformbuffer 14 | { 15 | mat4 model; 16 | mat4 view; 17 | mat4 proj; 18 | } ubo; 19 | 20 | layout(location = 0) in vec3 inPosition; 21 | layout(location = 1) in vec3 inNormal; 22 | layout(location = 2) in vec3 inColor; 23 | layout(location = 3) in vec2 inTexCoord; 24 | 25 | // Instanced attributes 26 | layout (location = 4) in vec3 inInstancePosition; 27 | layout (location = 5) in vec3 inInstanceRotation; 28 | layout (location = 6) in float inInstancePScale; 29 | layout (location = 7) in uint inInstanceTexIndex; 30 | 31 | mat4 MakeRotMatrix(vec3 R) 32 | { 33 | mat4 mx, my, mz; 34 | // rotate around x 35 | float s = sin(R.x); 36 | float c = cos(R.x); 37 | mx[0] = vec4(c, 0.0, s, 0.0); 38 | mx[1] = vec4(0.0, 1.0, 0.0, 0.0); 39 | mx[2] = vec4(-s, 0.0, c, 0.0); 40 | mx[3] = vec4(0.0, 0.0, 0.0, 1.0); 41 | // rotate around y 42 | s = sin(R.y); 43 | c = cos(R.y); 44 | my[0] = vec4(c, s, 0.0, 0.0); 45 | my[1] = vec4(-s, c, 0.0, 0.0); 46 | my[2] = vec4(0.0, 0.0, 1.0, 0.0); 47 | my[3] = vec4(0.0, 0.0, 0.0, 1.0); 48 | // rot around z 49 | s = sin(R.z); 50 | c = cos(R.z); 51 | mz[0] = vec4(1.0, 0.0, 0.0, 0.0); 52 | mz[1] = vec4(0.0, c, s, 0.0); 53 | mz[2] = vec4(0.0, -s, c, 0.0); 54 | mz[3] = vec4(0.0, 0.0, 0.0, 1.0); 55 | 56 | mat4 rotMat = mz * my * mx; 57 | return rotMat; 58 | } 59 | 60 | void main() 61 | { 62 | mat4 rotMat = MakeRotMatrix(inInstanceRotation); 63 | vec3 position = (inPosition * inInstancePScale) * mat3(rotMat) + inInstancePosition; 64 | gl_Position = ubo.proj * ubo.view * ubo.model * vec4(position, 1.0); 65 | } -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/background.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/cubemap_X0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/cubemap_X0.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/cubemap_X1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/cubemap_X1.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/cubemap_Y2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/cubemap_Y2.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/cubemap_Y3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/cubemap_Y3.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/cubemap_Z4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/cubemap_Z4.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/cubemap_Z5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/cubemap_Z5.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/default_black.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/default_black.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/default_grey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/default_grey.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/default_grid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/default_grid.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/default_grid_n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/default_grid_n.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/default_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/default_normal.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/default_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/default_white.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/grass_ao.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/grass_ao.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/grass_bc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/grass_bc.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/grass_ev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/grass_ev.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/grass_ms.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/grass_ms.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/grass_n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/grass_n.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/grass_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/grass_r.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/rock_01_bc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/rock_01_bc.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/rock_01_n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/rock_01_n.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/rock_01_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/rock_01_r.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/rock_02_bc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/rock_02_bc.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/rock_02_n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/rock_02_n.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/rock_02_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/rock_02_r.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/skydome.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/skydome.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/terrain_ao.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/terrain_ao.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/terrain_bc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/terrain_bc.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/terrain_ev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/terrain_ev.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/terrain_n.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/terrain_n.png -------------------------------------------------------------------------------- /LearnVulkan-09/draw_with_deferred/textures/terrain_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iceprincefounder/GamedevLessons/272d64ef11fce3fc1dd501c4f49710547c85247e/LearnVulkan-09/draw_with_deferred/textures/terrain_r.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GamedevLessons 2 | 游戏开发笔记 3 | 4 | ## Get the Examples 5 | ``` 6 | git clone --recurse-submodules https://github.com/iceprincefounder/GamedevLessons.git 7 | ``` -------------------------------------------------------------------------------- /cmake/FindDirectFB.cmake: -------------------------------------------------------------------------------- 1 | # Try to find DirectFB 2 | # 3 | # This will define: 4 | # 5 | # DIRECTFB_FOUND - True if DirectFB is found 6 | # DIRECTFB_LIBRARIES - Link these to use DirectFB 7 | # DIRECTFB_INCLUDE_DIR - Include directory for DirectFB 8 | # DIRECTFB_DEFINITIONS - Compiler flags for using DirectFB 9 | # 10 | # Redistribution and use is allowed according to the terms of the BSD license. 11 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 12 | 13 | IF (NOT WIN32) 14 | FIND_PACKAGE(PkgConfig) 15 | PKG_CHECK_MODULES(PKG_DIRECTFB QUIET directfb) 16 | 17 | SET(DIRECTFB_DEFINITIONS ${PKG_DIRECTFB_CFLAGS}) 18 | 19 | FIND_PATH(DIRECTFB_INCLUDE_DIR NAMES directfb.h HINTS ${PKG_DIRECTFB_INCLUDE_DIRS}) 20 | 21 | FIND_LIBRARY(DIRECTFB_LIBRARIES NAMES directfb HINTS ${PKG_DIRECTFB_LIBRARY_DIRS}) 22 | 23 | include(FindPackageHandleStandardArgs) 24 | 25 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(DIRECTFB DEFAULT_MSG DIRECTFB_LIBRARIES DIRECTFB_INCLUDE_DIR) 26 | 27 | MARK_AS_ADVANCED(DIRECTFB_INCLUDE_DIR DIRECTFB_LIBRARIES) 28 | ENDIF () 29 | -------------------------------------------------------------------------------- /cmake/FindWayland.cmake: -------------------------------------------------------------------------------- 1 | # Try to find Wayland on a Unix system 2 | # 3 | # This will define: 4 | # 5 | # WAYLAND_FOUND - True if Wayland is found 6 | # WAYLAND_LIBRARIES - Link these to use Wayland 7 | # WAYLAND_INCLUDE_DIR - Include directory for Wayland 8 | # WAYLAND_DEFINITIONS - Compiler flags for using Wayland 9 | # 10 | # In addition the following more fine grained variables will be defined: 11 | # 12 | # WAYLAND_CLIENT_FOUND WAYLAND_CLIENT_INCLUDE_DIR WAYLAND_CLIENT_LIBRARIES 13 | # WAYLAND_SERVER_FOUND WAYLAND_SERVER_INCLUDE_DIR WAYLAND_SERVER_LIBRARIES 14 | # WAYLAND_EGL_FOUND WAYLAND_EGL_INCLUDE_DIR WAYLAND_EGL_LIBRARIES 15 | # 16 | # Copyright (c) 2013 Martin Gräßlin 17 | # 18 | # Redistribution and use is allowed according to the terms of the BSD license. 19 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 20 | 21 | IF (NOT WIN32) 22 | IF (WAYLAND_INCLUDE_DIR AND WAYLAND_LIBRARIES) 23 | # In the cache already 24 | SET(WAYLAND_FIND_QUIETLY TRUE) 25 | ENDIF () 26 | 27 | # Use pkg-config to get the directories and then use these values 28 | # in the FIND_PATH() and FIND_LIBRARY() calls 29 | FIND_PACKAGE(PkgConfig) 30 | PKG_CHECK_MODULES(PKG_WAYLAND QUIET wayland-client wayland-server wayland-egl wayland-cursor) 31 | 32 | SET(WAYLAND_DEFINITIONS ${PKG_WAYLAND_CFLAGS}) 33 | 34 | FIND_PATH(WAYLAND_CLIENT_INCLUDE_DIR NAMES wayland-client.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS}) 35 | FIND_PATH(WAYLAND_SERVER_INCLUDE_DIR NAMES wayland-server.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS}) 36 | FIND_PATH(WAYLAND_EGL_INCLUDE_DIR NAMES wayland-egl.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS}) 37 | FIND_PATH(WAYLAND_CURSOR_INCLUDE_DIR NAMES wayland-cursor.h HINTS ${PKG_WAYLAND_INCLUDE_DIRS}) 38 | 39 | FIND_LIBRARY(WAYLAND_CLIENT_LIBRARIES NAMES wayland-client HINTS ${PKG_WAYLAND_LIBRARY_DIRS}) 40 | FIND_LIBRARY(WAYLAND_SERVER_LIBRARIES NAMES wayland-server HINTS ${PKG_WAYLAND_LIBRARY_DIRS}) 41 | FIND_LIBRARY(WAYLAND_EGL_LIBRARIES NAMES wayland-egl HINTS ${PKG_WAYLAND_LIBRARY_DIRS}) 42 | FIND_LIBRARY(WAYLAND_CURSOR_LIBRARIES NAMES wayland-cursor HINTS ${PKG_WAYLAND_LIBRARY_DIRS}) 43 | 44 | set(WAYLAND_INCLUDE_DIR ${WAYLAND_CLIENT_INCLUDE_DIR} ${WAYLAND_SERVER_INCLUDE_DIR} ${WAYLAND_EGL_INCLUDE_DIR} ${WAYLAND_CURSOR_INCLUDE_DIR}) 45 | 46 | set(WAYLAND_LIBRARIES ${WAYLAND_CLIENT_LIBRARIES} ${WAYLAND_SERVER_LIBRARIES} ${WAYLAND_EGL_LIBRARIES} ${WAYLAND_CURSOR_LIBRARIES}) 47 | 48 | list(REMOVE_DUPLICATES WAYLAND_INCLUDE_DIR) 49 | 50 | include(FindPackageHandleStandardArgs) 51 | 52 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_CLIENT DEFAULT_MSG WAYLAND_CLIENT_LIBRARIES WAYLAND_CLIENT_INCLUDE_DIR) 53 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_SERVER DEFAULT_MSG WAYLAND_SERVER_LIBRARIES WAYLAND_SERVER_INCLUDE_DIR) 54 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_EGL DEFAULT_MSG WAYLAND_EGL_LIBRARIES WAYLAND_EGL_INCLUDE_DIR) 55 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND_CURSOR DEFAULT_MSG WAYLAND_CURSOR_LIBRARIES WAYLAND_CURSOR_INCLUDE_DIR) 56 | FIND_PACKAGE_HANDLE_STANDARD_ARGS(WAYLAND DEFAULT_MSG WAYLAND_LIBRARIES WAYLAND_INCLUDE_DIR) 57 | 58 | MARK_AS_ADVANCED( 59 | WAYLAND_INCLUDE_DIR WAYLAND_LIBRARIES 60 | WAYLAND_CLIENT_INCLUDE_DIR WAYLAND_CLIENT_LIBRARIES 61 | WAYLAND_SERVER_INCLUDE_DIR WAYLAND_SERVER_LIBRARIES 62 | WAYLAND_EGL_INCLUDE_DIR WAYLAND_EGL_LIBRARIES 63 | WAYLAND_CURSOR_INCLUDE_DIR WAYLAND_CURSOR_LIBRARIES 64 | ) 65 | 66 | ENDIF () 67 | -------------------------------------------------------------------------------- /cmake/FindXCB.cmake: -------------------------------------------------------------------------------- 1 | # - FindXCB 2 | # 3 | # Copyright 2015 Valve Coporation 4 | 5 | find_package(PkgConfig) 6 | 7 | if(NOT XCB_FIND_COMPONENTS) 8 | set(XCB_FIND_COMPONENTS xcb) 9 | endif() 10 | 11 | include(FindPackageHandleStandardArgs) 12 | set(XCB_FOUND true) 13 | set(XCB_INCLUDE_DIRS "") 14 | set(XCB_LIBRARIES "") 15 | foreach(comp ${XCB_FIND_COMPONENTS}) 16 | # component name 17 | string(TOUPPER ${comp} compname) 18 | string(REPLACE "-" "_" compname ${compname}) 19 | # header name 20 | string(REPLACE "xcb-" "" headername xcb/${comp}.h) 21 | # library name 22 | set(libname ${comp}) 23 | 24 | pkg_check_modules(PC_${comp} QUIET ${comp}) 25 | 26 | find_path(${compname}_INCLUDE_DIR NAMES ${headername} 27 | HINTS 28 | ${PC_${comp}_INCLUDEDIR} 29 | ${PC_${comp}_INCLUDE_DIRS} 30 | ) 31 | 32 | find_library(${compname}_LIBRARY NAMES ${libname} 33 | HINTS 34 | ${PC_${comp}_LIBDIR} 35 | ${PC_${comp}_LIBRARY_DIRS} 36 | ) 37 | 38 | find_package_handle_standard_args(${comp} 39 | FOUND_VAR ${comp}_FOUND 40 | REQUIRED_VARS ${compname}_INCLUDE_DIR ${compname}_LIBRARY) 41 | mark_as_advanced(${compname}_INCLUDE_DIR ${compname}_LIBRARY) 42 | 43 | list(APPEND XCB_INCLUDE_DIRS ${${compname}_INCLUDE_DIR}) 44 | list(APPEND XCB_LIBRARIES ${${compname}_LIBRARY}) 45 | 46 | if(NOT ${comp}_FOUND) 47 | set(XCB_FOUND false) 48 | endif() 49 | endforeach() 50 | 51 | list(REMOVE_DUPLICATES XCB_INCLUDE_DIRS) --------------------------------------------------------------------------------