├── src ├── CMakeLists.txt ├── Shaders │ ├── Include │ │ └── Shaders.h │ ├── Cache │ │ ├── EmbeddedShaders.cpp │ │ ├── EmbeddedShaders.h │ │ ├── Default_fs_glsl.h │ │ ├── Default_fs_essl.h │ │ ├── Default_vs_glsl.h │ │ ├── Default_vs_essl.h │ │ ├── Default_fs_mtl.h │ │ ├── Default_fs_spv.h │ │ ├── Default_vs_mtl.h │ │ └── Default_vs_spv.h │ ├── Source │ │ ├── varying.def.sc │ │ ├── Default.vs │ │ ├── Default.fs │ │ ├── ShaderHelper.h │ │ ├── Common.shader │ │ ├── CommonFS.shader │ │ ├── bgfx_compute.sh │ │ └── bgfx_shader.sh │ └── CMakeLists.txt └── App │ ├── CMakeLists.txt │ └── Source │ ├── index.html │ └── App.cpp ├── doc ├── BAM_Web.png ├── BAM_MacOS.png ├── BAM_Ubuntu.png └── BAM_Windows.png ├── .gitmodules ├── CMakeLists.txt ├── .gitignore ├── LICENSE ├── ext └── CMakeLists.txt ├── README.md └── azure-pipelines.yml /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(App) 2 | add_subdirectory(Shaders) 3 | -------------------------------------------------------------------------------- /doc/BAM_Web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CedricGuillemet/bam/HEAD/doc/BAM_Web.png -------------------------------------------------------------------------------- /doc/BAM_MacOS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CedricGuillemet/bam/HEAD/doc/BAM_MacOS.png -------------------------------------------------------------------------------- /doc/BAM_Ubuntu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CedricGuillemet/bam/HEAD/doc/BAM_Ubuntu.png -------------------------------------------------------------------------------- /doc/BAM_Windows.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CedricGuillemet/bam/HEAD/doc/BAM_Windows.png -------------------------------------------------------------------------------- /src/Shaders/Include/Shaders.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace App { 6 | bgfx::ProgramHandle LoadProgram(const char* vertexShaderName, const char* fragmentShaderName); 7 | } 8 | -------------------------------------------------------------------------------- /src/Shaders/Cache/EmbeddedShaders.cpp: -------------------------------------------------------------------------------- 1 | #include "EmbeddedShaders.h" 2 | #include "bgfx_utils.h" 3 | static const bgfx::EmbeddedShader embeddedShaders[] = 4 | { 5 | BGFX_EMBEDDED_SHADER(Default_vs), 6 | BGFX_EMBEDDED_SHADER(Default_fs), 7 | BGFX_EMBEDDED_SHADER_END() 8 | }; 9 | #include "ShaderHelper.h" 10 | -------------------------------------------------------------------------------- /src/Shaders/Source/varying.def.sc: -------------------------------------------------------------------------------- 1 | vec2 a_texcoord0 : TEXCOORD0; 2 | vec4 a_color0 : COLOR0; 3 | vec3 a_position : POSITION; 4 | vec3 a_normal : NORMAL; 5 | 6 | 7 | vec2 v_texcoord0 : TEXCOORD0; 8 | vec3 v_position : POSITION; 9 | vec3 v_normal : NORMAL; 10 | vec4 v_color0 : COLOR0; 11 | vec3 v_positionWorld : TEXCOORD1; 12 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "ext/ImGuizmo"] 2 | path = ext/ImGuizmo 3 | url = https://github.com/CedricGuillemet/ImGuizmo 4 | [submodule "ext/bgfx.cmake"] 5 | path = ext/bgfx.cmake 6 | url = https://github.com/bkaradzic/bgfx.cmake.git 7 | [submodule "ext/imgui"] 8 | path = ext/imgui 9 | url = https://github.com/ocornut/imgui.git 10 | -------------------------------------------------------------------------------- /src/Shaders/Source/Default.vs: -------------------------------------------------------------------------------- 1 | $input a_position, a_normal 2 | $output v_normal 3 | 4 | #include "bgfx_shader.sh" 5 | #include "Common.shader" 6 | 7 | void main() 8 | { 9 | mat4 mvp = mul(u_viewProjection, u_world); 10 | gl_Position = mul(mvp, vec4(a_position, 1.0) ); 11 | v_normal = mul(u_world, vec4(a_normal, 0.0)).xyz; 12 | } 13 | -------------------------------------------------------------------------------- /src/Shaders/Source/Default.fs: -------------------------------------------------------------------------------- 1 | $input v_normal 2 | 3 | #include "bgfx_shader.sh" 4 | #include "CommonFS.shader" 5 | #include "Common.shader" 6 | 7 | void main() 8 | { 9 | float halfNormal = dot(normalize(v_normal.xyz), normalize(vec3(0.7, 0.4, 0.3))) * 0.5 + 0.5; 10 | float light = halfNormal * halfNormal; 11 | gl_FragColor = vec4(0.9, 0.6, 0.4, 1.0) * light; 12 | } 13 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.6) 2 | project (App) 3 | # Add project's cmake modules to path 4 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/.) 5 | set(CMAKE_CXX_STANDARD 17) 6 | set(CMAKE_CSS_STANDARD_REQUIRED ON) 7 | 8 | SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON) 9 | 10 | set(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo" CACHE STRING "Configuration types" FORCE) 11 | 12 | add_subdirectory(ext) 13 | add_subdirectory(src) -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | 34 | # Caches 35 | .DS_Store 36 | 37 | # Build folders 38 | build/ 39 | buildweb/ 40 | bin/ -------------------------------------------------------------------------------- /src/Shaders/Source/ShaderHelper.h: -------------------------------------------------------------------------------- 1 | namespace App { 2 | bgfx::ProgramHandle LoadProgram(const char* vertexShaderName, const char* fragmentShaderName) 3 | { 4 | auto& caps = *bgfx::getCaps(); 5 | bgfx::ShaderHandle vsh = createEmbeddedShader(embeddedShaders, caps.rendererType, vertexShaderName); 6 | bgfx::ShaderHandle fsh = createEmbeddedShader(embeddedShaders, caps.rendererType, fragmentShaderName); 7 | 8 | BX_ASSERT(isValid(vsh) && isValid(fsh), "Failed to create Embedded shaders"); 9 | 10 | return createProgram(vsh, fsh, true); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Shaders/Cache/EmbeddedShaders.h: -------------------------------------------------------------------------------- 1 | // generated by CMake 2 | #include 3 | #include 4 | #ifdef WIN32 5 | #include "Default_vs_dx9.h" 6 | #include "Default_vs_dx11.h" 7 | #endif 8 | #include "Default_vs_glsl.h" 9 | #ifdef __APPLE__ 10 | #include "Default_vs_mtl.h" 11 | #endif 12 | #include "Default_vs_spv.h" 13 | #include "Default_vs_essl.h" 14 | #ifdef WIN32 15 | #include "Default_fs_dx9.h" 16 | #include "Default_fs_dx11.h" 17 | #endif 18 | #include "Default_fs_glsl.h" 19 | #ifdef __APPLE__ 20 | #include "Default_fs_mtl.h" 21 | #endif 22 | #include "Default_fs_spv.h" 23 | #include "Default_fs_essl.h" 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Cedric Guillemet 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 | -------------------------------------------------------------------------------- /ext/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ################################################################ 2 | ### BGFX 3 | 4 | set(BGFX_BUILD_EXAMPLES OFF CACHE BOOL "") 5 | set(BGFX_USE_DEBUG_SUFFIX OFF CACHE BOOL "Add 'd' suffix to debug output targets") 6 | 7 | add_subdirectory(bgfx.cmake EXCLUDE_FROM_ALL) 8 | 9 | target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_DEBUG_UNIFORM=0) 10 | target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_MAX_VERTEX_STREAMS=30) 11 | target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_MAX_COMMAND_BUFFER_SIZE=12582912) 12 | target_compile_definitions(example-common PRIVATE USE_ENTRY=1) 13 | 14 | if (NOT EMSCRIPTEN) 15 | target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_MULTITHREADED=1) 16 | if(APPLE) 17 | # no Vulkan on Apple but Metal 18 | target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_RENDERER_VULKAN=0) 19 | target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_RENDERER_METAL=1) 20 | target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_WAIT_FOR_FLIP=1) 21 | elseif(UNIX) 22 | target_compile_definitions(bgfx PRIVATE BGFX_CONFIG_RENDERER_OPENGL=33) 23 | endif() 24 | endif() 25 | 26 | ################################################################ 27 | ### IMGUI 28 | 29 | file(GLOB IMGUI_SRC_FILES 30 | imgui/*.h 31 | imgui/*.cpp 32 | ) 33 | 34 | add_library(imgui ${IMGUI_SRC_FILES}) 35 | 36 | target_include_directories(imgui 37 | PUBLIC "imgui" 38 | ) 39 | 40 | ################################################################ 41 | ### IMGUIZMO 42 | 43 | file(GLOB IMGUIZMO_SRC_FILES 44 | ImGuizmo/*.h 45 | ImGuizmo/*.cpp 46 | ) 47 | 48 | add_library(ImGuizmo ${IMGUIZMO_SRC_FILES}) 49 | target_link_libraries(ImGuizmo imgui) 50 | target_include_directories(ImGuizmo 51 | PUBLIC "ImGuizmo" 52 | ) -------------------------------------------------------------------------------- /src/Shaders/Cache/Default_fs_glsl.h: -------------------------------------------------------------------------------- 1 | static const uint8_t Default_fs_glsl[250] = 2 | { 3 | 0x46, 0x53, 0x48, 0x0b, 0xe3, 0xc2, 0x5c, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe7, 0x00, // FSH....e........ 4 | 0x00, 0x00, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x76, 0x65, 0x63, 0x33, 0x20, 0x76, // ..varying vec3 v 5 | 0x5f, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x3b, 0x0a, 0x76, 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, // _normal;.void ma 6 | 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, // in ().{. float 7 | 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, // tmpvar_1;. tmpv 8 | 0x61, 0x72, 0x5f, 0x31, 0x20, 0x3d, 0x20, 0x28, 0x28, 0x64, 0x6f, 0x74, 0x20, 0x28, 0x0a, 0x20, // ar_1 = ((dot (. 9 | 0x20, 0x20, 0x20, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x28, 0x76, 0x5f, 0x6e, // normalize(v_n 10 | 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x29, 0x0a, 0x20, 0x20, 0x2c, 0x20, 0x76, 0x65, 0x63, 0x33, 0x28, // ormal). , vec3( 11 | 0x30, 0x2e, 0x38, 0x31, 0x33, 0x37, 0x33, 0x33, 0x35, 0x2c, 0x20, 0x30, 0x2e, 0x34, 0x36, 0x34, // 0.8137335, 0.464 12 | 0x39, 0x39, 0x30, 0x36, 0x2c, 0x20, 0x30, 0x2e, 0x33, 0x34, 0x38, 0x37, 0x34, 0x32, 0x39, 0x29, // 9906, 0.3487429) 13 | 0x29, 0x20, 0x2a, 0x20, 0x30, 0x2e, 0x35, 0x29, 0x20, 0x2b, 0x20, 0x30, 0x2e, 0x35, 0x29, 0x3b, // ) * 0.5) + 0.5); 14 | 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, // . gl_FragColor 15 | 0x3d, 0x20, 0x28, 0x76, 0x65, 0x63, 0x34, 0x28, 0x30, 0x2e, 0x39, 0x2c, 0x20, 0x30, 0x2e, 0x36, // = (vec4(0.9, 0.6 16 | 0x2c, 0x20, 0x30, 0x2e, 0x34, 0x2c, 0x20, 0x31, 0x2e, 0x30, 0x29, 0x20, 0x2a, 0x20, 0x28, 0x74, // , 0.4, 1.0) * (t 17 | 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x20, 0x2a, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, // mpvar_1 * tmpvar 18 | 0x5f, 0x31, 0x29, 0x29, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // _1));.}... 19 | }; 20 | -------------------------------------------------------------------------------- /src/App/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB_RECURSE SRC_FILES 2 | Source/*.h 3 | Source/*.cpp 4 | ) 5 | 6 | if (EMSCRIPTEN) 7 | SET(EXE_NAME "index") 8 | else() 9 | SET(EXE_NAME "App") 10 | endif() 11 | 12 | ADD_EXECUTABLE(${EXE_NAME} ${SRC_FILES}) 13 | 14 | set_target_properties(${EXE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}/bin ) 15 | set_target_properties(${EXE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_SOURCE_DIR}/bin ) 16 | set_target_properties(${EXE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_SOURCE_DIR}/bin ) 17 | set_target_properties(${EXE_NAME} PROPERTIES DEBUG_POSTFIX "_d") 18 | set_target_properties(${EXE_NAME} PROPERTIES RELWITHDEBINFO_POSTFIX "RelWithDebInfo") 19 | set_target_properties(${EXE_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/bin") 20 | 21 | target_link_libraries(${EXE_NAME} bx) 22 | target_link_libraries(${EXE_NAME} bimg) 23 | target_link_libraries(${EXE_NAME} bgfx) 24 | target_link_libraries(${EXE_NAME} example-common) 25 | target_link_libraries(${EXE_NAME} Shaders) 26 | 27 | if(MSVC) 28 | set_target_properties(${EXE_NAME} PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:WINDOWS") 29 | set_target_properties(${EXE_NAME} PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS") 30 | set_target_properties(${EXE_NAME} PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/SUBSYSTEM:WINDOWS") 31 | 32 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup") 33 | set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup") 34 | 35 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 36 | endif() 37 | 38 | if (EMSCRIPTEN) 39 | set_target_properties(${EXE_NAME} PROPERTIES LINK_FLAGS "-s USE_WEBGL2=1 -s WASM=1 -s FULL_ES3=1 -s ALLOW_MEMORY_GROWTH=1 --shell-file ${CMAKE_CURRENT_SOURCE_DIR}/Source/index.html") 40 | add_definitions(-D_X86_) 41 | SET(CMAKE_EXECUTABLE_SUFFIX ".html") 42 | endif() 43 | 44 | add_definitions(-DENTRY_CONFIG_IMPLEMENT_MAIN=1) 45 | 46 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SRC_FILES}) -------------------------------------------------------------------------------- /src/Shaders/Cache/Default_fs_essl.h: -------------------------------------------------------------------------------- 1 | static const uint8_t Default_fs_essl[262] = 2 | { 3 | 0x46, 0x53, 0x48, 0x0b, 0xe3, 0xc2, 0x5c, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf3, 0x00, // FSH....e........ 4 | 0x00, 0x00, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, // ..varying highp 5 | 0x76, 0x65, 0x63, 0x33, 0x20, 0x76, 0x5f, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x3b, 0x0a, 0x76, // vec3 v_normal;.v 6 | 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. 7 | 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x74, 0x6d, 0x70, 0x76, // highp float tmpv 8 | 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, // ar_1;. tmpvar_1 9 | 0x20, 0x3d, 0x20, 0x28, 0x28, 0x64, 0x6f, 0x74, 0x20, 0x28, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6e, // = ((dot (. n 10 | 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x28, 0x76, 0x5f, 0x6e, 0x6f, 0x72, 0x6d, 0x61, // ormalize(v_norma 11 | 0x6c, 0x29, 0x0a, 0x20, 0x20, 0x2c, 0x20, 0x76, 0x65, 0x63, 0x33, 0x28, 0x30, 0x2e, 0x38, 0x31, // l). , vec3(0.81 12 | 0x33, 0x37, 0x33, 0x33, 0x35, 0x2c, 0x20, 0x30, 0x2e, 0x34, 0x36, 0x34, 0x39, 0x39, 0x30, 0x36, // 37335, 0.4649906 13 | 0x2c, 0x20, 0x30, 0x2e, 0x33, 0x34, 0x38, 0x37, 0x34, 0x32, 0x39, 0x29, 0x29, 0x20, 0x2a, 0x20, // , 0.3487429)) * 14 | 0x30, 0x2e, 0x35, 0x29, 0x20, 0x2b, 0x20, 0x30, 0x2e, 0x35, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x67, // 0.5) + 0.5);. g 15 | 0x6c, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x20, 0x3d, 0x20, 0x28, 0x76, // l_FragColor = (v 16 | 0x65, 0x63, 0x34, 0x28, 0x30, 0x2e, 0x39, 0x2c, 0x20, 0x30, 0x2e, 0x36, 0x2c, 0x20, 0x30, 0x2e, // ec4(0.9, 0.6, 0. 17 | 0x34, 0x2c, 0x20, 0x31, 0x2e, 0x30, 0x29, 0x20, 0x2a, 0x20, 0x28, 0x74, 0x6d, 0x70, 0x76, 0x61, // 4, 1.0) * (tmpva 18 | 0x72, 0x5f, 0x31, 0x20, 0x2a, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x29, 0x29, // r_1 * tmpvar_1)) 19 | 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // ;.}... 20 | }; 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BAM! framework 2 | 3 | Linux [![Build Status](https://cedricguillemet.visualstudio.com/Bam/_apis/build/status/CedricGuillemet.bam?branchName=main&jobName=Ubuntu_Clang)](https://cedricguillemet.visualstudio.com/Bam/_build/latest?definitionId=4&branchName=main) 4 | Emscripten [![Build Status](https://cedricguillemet.visualstudio.com/Bam/_apis/build/status/CedricGuillemet.bam?branchName=main&jobName=Ubuntu_Emscripten)](https://cedricguillemet.visualstudio.com/Bam/_build/latest?definitionId=4&branchName=main) 5 | 6 | MacOS [![Build Status](https://cedricguillemet.visualstudio.com/Bam/_apis/build/status/CedricGuillemet.bam?branchName=main&jobName=macOS)](https://cedricguillemet.visualstudio.com/Bam/_build/latest?definitionId=4&branchName=main) 7 | Windows [![Build Status](https://cedricguillemet.visualstudio.com/Bam/_apis/build/status/CedricGuillemet.bam?branchName=main&jobName=win32_x64)](https://cedricguillemet.visualstudio.com/Bam/_build/latest?definitionId=4&branchName=main) 8 | 9 | 10 | A template/framework for experiments using bgfx/dear imgui/imguizmo. 11 | Fork this repo, clone it and start hacking. 12 | Build for Win32/Linux/MacOS and Web with 1 repo, 1 codebase. 13 | Goal is to clone, write the first line of code and build for your platform within 5 Min. 14 | 15 | ![MacOS](doc/BAM_MacOS.png) 16 | ![Windows](doc/BAM_Windows.png) 17 | ![Ubuntu](doc/BAM_Ubuntu.png) 18 | ![Web](doc/BAM_Web.png) 19 | 20 | I encourage you to add any 'must have' sub-repo and extend the sample app accordingly. 21 | (As long as it's not Boost.) 22 | 23 | ## Build 24 | 25 | Binary output directory is `bin/` 26 | 27 | ### Clone repo 28 | ``` 29 | git clone https://github.com/CedricGuillemet/bam.git --recurse-submodules 30 | ``` 31 | 32 | ### Windows 33 | ``` 34 | mkdir build 35 | cd build 36 | cmake .. -G "Visual Studio 16 2019" -A x64 37 | ``` 38 | And open .sln with Visual Studio 39 | 40 | ### Mac 41 | ``` 42 | mkdir build 43 | cd build 44 | cmake .. -G Xcode 45 | ``` 46 | 47 | And open project with Xcode 48 | 49 | ### Linux 50 | ``` 51 | mkdir build 52 | cd build 53 | cmake .. -G Ninja 54 | ninja 55 | ``` 56 | 57 | ### Web 58 | 59 | Clone and activate emsdk https://github.com/emscripten-core/emsdk 60 | Install your favorite build tool supported by cmake (ninja, make, ...) 61 | ``` 62 | mkdir build 63 | cd build 64 | emcmake cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release 65 | ninja 66 | ``` 67 | #### Test web 68 | 69 | In `bin` folder: 70 | 71 | ``` 72 | python3 -m http.server 73 | ``` 74 | -------------------------------------------------------------------------------- /azure-pipelines.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | - main 3 | 4 | pr: 5 | - main 6 | 7 | jobs: 8 | - job: macOS 9 | pool: 10 | vmImage: 'macOS-10.15' 11 | 12 | steps: 13 | - script: | 14 | git submodule update --init --recursive 15 | displayName: 'Checkout dependencies' 16 | 17 | - script: | 18 | mkdir build 19 | cd build 20 | cmake .. -GXcode 21 | displayName: 'Generate MacOS solution' 22 | 23 | - task: Xcode@5 24 | inputs: 25 | xcWorkspacePath: 'build/App.xcodeproj' 26 | scheme: 'App' 27 | sdk: 'macosx' 28 | useXcpretty: false 29 | configuration: RelWithDebInfo 30 | displayName: 'Build MacOS' 31 | 32 | - job: win32_x64 33 | timeoutInMinutes: 30 34 | pool: 35 | vmImage: 'windows-latest' 36 | 37 | steps: 38 | - script: | 39 | git submodule update --init --recursive 40 | displayName: 'Checkout dependencies' 41 | 42 | - script: | 43 | mkdir build 44 | cd build 45 | cmake -G "Visual Studio 16 2019" -A x64 -DBGFX_CONFIG_MEMORY_TRACKING=ON -DBGFX_CONFIG_DEBUG=ON .. 46 | displayName: 'Generate Win32_x64 solution' 47 | 48 | - task: MSBuild@1 49 | inputs: 50 | solution: 'build/App.sln' 51 | maximumCpuCount: true 52 | configuration: 'RelWithDebInfo' 53 | displayName: 'Build WIN32_x64' 54 | 55 | - job: Ubuntu_Clang 56 | timeoutInMinutes: 30 57 | pool: 58 | vmImage: 'ubuntu-latest' 59 | 60 | variables: 61 | CC: clang-8 62 | CXX: clang++-8 63 | 64 | steps: 65 | - script: | 66 | git submodule update --init --recursive 67 | displayName: 'Checkout dependencies' 68 | - script: | 69 | sudo apt-get update 70 | sudo apt-get install libgl1-mesa-dev clang-8 libc++-8-dev libc++abi-8-dev ninja-build 71 | displayName: 'Install packages' 72 | - script: | 73 | mkdir build 74 | cd build 75 | cmake .. -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo 76 | ninja 77 | displayName: 'Build X11' 78 | 79 | - job: Ubuntu_Emscripten 80 | timeoutInMinutes: 30 81 | pool: 82 | vmImage: 'ubuntu-latest' 83 | 84 | steps: 85 | - script: | 86 | git submodule update --init --recursive 87 | displayName: 'Checkout dependencies' 88 | - script: | 89 | sudo apt-get update 90 | sudo apt-get install libgl1-mesa-dev clang-8 libc++-8-dev libc++abi-8-dev ninja-build 91 | git clone https://github.com/emscripten-core/emsdk.git 92 | ./emsdk/emsdk install latest 93 | displayName: 'Install packages' 94 | - script: | 95 | ./emsdk/emsdk activate latest 96 | source ./emsdk/emsdk_env.sh 97 | mkdir build 98 | cd build 99 | emcmake cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release 100 | ninja 101 | displayName: 'Build Emscripten' 102 | -------------------------------------------------------------------------------- /src/Shaders/Cache/Default_vs_glsl.h: -------------------------------------------------------------------------------- 1 | static const uint8_t Default_vs_glsl[438] = 2 | { 3 | 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0xe3, 0xc2, 0x5c, 0x65, 0x02, 0x00, 0x10, 0x75, // VSH........e...u 4 | 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x04, // _viewProjection. 5 | 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x75, 0x5f, 0x77, 0x6f, 0x72, 0x6c, // ..........u_worl 6 | 0x64, 0x04, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76, 0x01, 0x00, 0x00, 0x61, // d..........v...a 7 | 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x76, 0x65, 0x63, 0x33, 0x20, 0x61, 0x5f, // ttribute vec3 a_ 8 | 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x3b, 0x0a, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, // normal;.attribut 9 | 0x65, 0x20, 0x76, 0x65, 0x63, 0x33, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, // e vec3 a_positio 10 | 0x6e, 0x3b, 0x0a, 0x76, 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x76, 0x65, 0x63, 0x33, 0x20, // n;.varying vec3 11 | 0x76, 0x5f, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, // v_normal;.unifor 12 | 0x6d, 0x20, 0x6d, 0x61, 0x74, 0x34, 0x20, 0x75, 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, // m mat4 u_viewPro 13 | 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, // jection;.uniform 14 | 0x20, 0x6d, 0x61, 0x74, 0x34, 0x20, 0x75, 0x5f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x3b, 0x0a, 0x76, // mat4 u_world;.v 15 | 0x6f, 0x69, 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, // oid main ().{. 16 | 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x3b, 0x0a, 0x20, // vec4 tmpvar_1;. 17 | 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x77, 0x20, 0x3d, 0x20, 0x31, 0x2e, // tmpvar_1.w = 1. 18 | 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x78, 0x79, // 0;. tmpvar_1.xy 19 | 0x7a, 0x20, 0x3d, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, // z = a_position;. 20 | 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x3d, 0x20, // gl_Position = 21 | 0x28, 0x28, 0x75, 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, // ((u_viewProjecti 22 | 0x6f, 0x6e, 0x20, 0x2a, 0x20, 0x75, 0x5f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x29, 0x20, 0x2a, 0x20, // on * u_world) * 23 | 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x76, 0x65, 0x63, // tmpvar_1);. vec 24 | 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, // 4 tmpvar_2;. tm 25 | 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x2e, 0x77, 0x20, 0x3d, 0x20, 0x30, 0x2e, 0x30, 0x3b, 0x0a, // pvar_2.w = 0.0;. 26 | 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x2e, 0x78, 0x79, 0x7a, 0x20, 0x3d, // tmpvar_2.xyz = 27 | 0x20, 0x61, 0x5f, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x3b, 0x0a, 0x20, 0x20, 0x76, 0x5f, 0x6e, // a_normal;. v_n 28 | 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x20, 0x3d, 0x20, 0x28, 0x75, 0x5f, 0x77, 0x6f, 0x72, 0x6c, 0x64, // ormal = (u_world 29 | 0x20, 0x2a, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, 0x29, 0x2e, 0x78, 0x79, 0x7a, // * tmpvar_2).xyz 30 | 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // ;.}... 31 | }; 32 | -------------------------------------------------------------------------------- /src/Shaders/Cache/Default_vs_essl.h: -------------------------------------------------------------------------------- 1 | static const uint8_t Default_vs_essl[480] = 2 | { 3 | 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0xe3, 0xc2, 0x5c, 0x65, 0x02, 0x00, 0x10, 0x75, // VSH........e...u 4 | 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x04, // _viewProjection. 5 | 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x75, 0x5f, 0x77, 0x6f, 0x72, 0x6c, // ..........u_worl 6 | 0x64, 0x04, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0, 0x01, 0x00, 0x00, 0x61, // d..............a 7 | 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, // ttribute highp v 8 | 0x65, 0x63, 0x33, 0x20, 0x61, 0x5f, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x3b, 0x0a, 0x61, 0x74, // ec3 a_normal;.at 9 | 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, // tribute highp ve 10 | 0x63, 0x33, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x76, // c3 a_position;.v 11 | 0x61, 0x72, 0x79, 0x69, 0x6e, 0x67, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, // arying highp vec 12 | 0x33, 0x20, 0x76, 0x5f, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x3b, 0x0a, 0x75, 0x6e, 0x69, 0x66, // 3 v_normal;.unif 13 | 0x6f, 0x72, 0x6d, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x6d, 0x61, 0x74, 0x34, 0x20, 0x75, // orm highp mat4 u 14 | 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3b, // _viewProjection; 15 | 0x0a, 0x75, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x6d, // .uniform highp m 16 | 0x61, 0x74, 0x34, 0x20, 0x75, 0x5f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x3b, 0x0a, 0x76, 0x6f, 0x69, // at4 u_world;.voi 17 | 0x64, 0x20, 0x6d, 0x61, 0x69, 0x6e, 0x20, 0x28, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x68, 0x69, // d main ().{. hi 18 | 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, // ghp vec4 tmpvar_ 19 | 0x31, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x2e, 0x77, 0x20, // 1;. tmpvar_1.w 20 | 0x3d, 0x20, 0x31, 0x2e, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, // = 1.0;. tmpvar_ 21 | 0x31, 0x2e, 0x78, 0x79, 0x7a, 0x20, 0x3d, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, // 1.xyz = a_positi 22 | 0x6f, 0x6e, 0x3b, 0x0a, 0x20, 0x20, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, // on;. gl_Positio 23 | 0x6e, 0x20, 0x3d, 0x20, 0x28, 0x28, 0x75, 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, // n = ((u_viewProj 24 | 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x2a, 0x20, 0x75, 0x5f, 0x77, 0x6f, 0x72, 0x6c, 0x64, // ection * u_world 25 | 0x29, 0x20, 0x2a, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x31, 0x29, 0x3b, 0x0a, 0x20, // ) * tmpvar_1);. 26 | 0x20, 0x68, 0x69, 0x67, 0x68, 0x70, 0x20, 0x76, 0x65, 0x63, 0x34, 0x20, 0x74, 0x6d, 0x70, 0x76, // highp vec4 tmpv 27 | 0x61, 0x72, 0x5f, 0x32, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, 0x61, 0x72, 0x5f, 0x32, // ar_2;. tmpvar_2 28 | 0x2e, 0x77, 0x20, 0x3d, 0x20, 0x30, 0x2e, 0x30, 0x3b, 0x0a, 0x20, 0x20, 0x74, 0x6d, 0x70, 0x76, // .w = 0.0;. tmpv 29 | 0x61, 0x72, 0x5f, 0x32, 0x2e, 0x78, 0x79, 0x7a, 0x20, 0x3d, 0x20, 0x61, 0x5f, 0x6e, 0x6f, 0x72, // ar_2.xyz = a_nor 30 | 0x6d, 0x61, 0x6c, 0x3b, 0x0a, 0x20, 0x20, 0x76, 0x5f, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x20, // mal;. v_normal 31 | 0x3d, 0x20, 0x28, 0x75, 0x5f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x20, 0x2a, 0x20, 0x74, 0x6d, 0x70, // = (u_world * tmp 32 | 0x76, 0x61, 0x72, 0x5f, 0x32, 0x29, 0x2e, 0x78, 0x79, 0x7a, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, // var_2).xyz;.}... 33 | }; 34 | -------------------------------------------------------------------------------- /src/Shaders/Source/Common.shader: -------------------------------------------------------------------------------- 1 | #define PI 3.14159265359 2 | #define SQRT2 1.414213562373095 3 | 4 | #define TwoPI (PI*2.0) 5 | 6 | 7 | uniform mat4 u_viewRot; 8 | uniform mat4 u_viewProjection; 9 | uniform mat4 u_viewInverse; 10 | uniform mat4 u_world; 11 | uniform mat4 u_worldViewProjection; 12 | uniform vec4 u_viewport; 13 | 14 | 15 | uniform vec4 u_mouse; // x,y, lbut down, rbut down 16 | uniform vec4 u_keyModifier; // ctrl, alt, shift 17 | uniform vec4 u_inputIndices[2]; 18 | 19 | uniform vec4 u_pass; // uiPass, passNumber, frame, localFrame 20 | uniform vec4 u_target; // targetIndex, vertexSpace, mipmapNumber, mipmapCount 21 | uniform vec4 u_textureSize[8]; 22 | 23 | vec2 Rotate2D(vec2 v, float a) 24 | { 25 | float s = sin(a); 26 | float c = cos(a); 27 | mat2 m = mat2(c, -s, s, c); 28 | return mul(v, m); 29 | } 30 | vec3 InvertCubeY(vec3 dir) 31 | { 32 | return vec3(dir.x, -dir.y, dir.z); 33 | } 34 | float Circle(vec2 uv, float radius, float t) 35 | { 36 | float r = length(uv-vec2(0.5, 0.5)); 37 | float h = sin(acos(r/radius)); 38 | return mix(1.0-smoothstep(radius-0.001, radius, length(uv-vec2(0.5, 0.5))), h, t); 39 | } 40 | 41 | vec4 boxmap( sampler2D sam, in vec3 p, in vec3 n, in float k ) 42 | { 43 | vec3 m = pow( abs(n), vec3(k, k, k) ); 44 | vec4 x = texture2D( sam, p.yz ); 45 | vec4 y = texture2D( sam, p.zx ); 46 | vec4 z = texture2D( sam, p.xy ); 47 | return (x*m.x + y*m.y + z*m.z)/(m.x+m.y+m.z); 48 | } 49 | 50 | vec2 boxUV(vec3 p, vec3 n) 51 | { 52 | vec2 uv = p.xy; 53 | uv = mix(uv, p.zy*sign(n.x), (abs(n.x)>0.5)?1.0:0.0 ); 54 | uv = mix(uv, p.zx*sign(n.y), (abs(n.y)>0.5)?1.0:0.0 ); 55 | return uv; 56 | } 57 | 58 | vec2 envMapEquirect(vec3 wcNormal, float flipEnvMap) { 59 | //I assume envMap texture2D has been flipped the WebGL way (pixel 0,0 is a the bottom) 60 | //therefore we flip wcNorma.y as acos(1) = 0 61 | float phi = acos(-wcNormal.y); 62 | float theta = atan2(flipEnvMap * wcNormal.x, wcNormal.z) + PI; 63 | return vec2(theta / TwoPI, 1.0 - phi / PI); 64 | } 65 | 66 | vec2 envMapEquirect(vec3 wcNormal) { 67 | //-1.0 for left handed coordinate system oriented texture (usual case) 68 | return envMapEquirect(wcNormal, -1.0); 69 | } 70 | 71 | float Smooth( float x ) 72 | { 73 | return smoothstep( 0., 1., saturate( x ) ); 74 | } 75 | 76 | // distance functions 77 | 78 | float Cylinder( vec3 p, float r, float height ) 79 | { 80 | float d = length( p.xz ) - r; 81 | d = max( d, abs( p.y ) - height ); 82 | return d; 83 | } 84 | 85 | float Substract( float a, float b ) 86 | { 87 | return max( a, -b ); 88 | } 89 | 90 | float SubstractRound( float a, float b, float r ) 91 | { 92 | vec2 u = max( vec2( r + a, r - b ), vec2( 0.0, 0.0 ) ); 93 | return min( -r, max( a, -b ) ) + length( u ); 94 | } 95 | 96 | float Union( float a, float b ) 97 | { 98 | return min( a, b ); 99 | } 100 | 101 | float Box( vec3 p, vec3 b ) 102 | { 103 | vec3 d = abs( p ) - b; 104 | return min( max( d.x, max( d.y, d.z ) ), 0.0 ) + length( max( d, 0.0 ) ); 105 | } 106 | 107 | float Sphere( vec3 p, float s ) 108 | { 109 | return length( p ) - s; 110 | } 111 | 112 | float Torus( vec3 p, float sr, float lr ) 113 | { 114 | return length( vec2( length( p.xz ) - lr, p.y ) ) - sr; 115 | } 116 | 117 | float Disc( vec3 p, float r, float t ) 118 | { 119 | float l = length( p.xz ) - r; 120 | return l < 0. ? abs( p.y ) - t : length( vec2( p.y, l ) ) - t; 121 | } 122 | 123 | float UnionRound( float a, float b, float k ) 124 | { 125 | float h = clamp( 0.5 + 0.5 * ( b - a ) / k, 0.0, 1.0 ); 126 | return mix( b, a, h ) - k * h * ( 1.0 - h ); 127 | } 128 | 129 | float sdRoundBox( vec3 p, vec3 b, float r ) 130 | { 131 | vec3 d = abs(p) - b; 132 | return length(max(d,0.0)) - r 133 | + min(max(d.x,max(d.y,d.z)),0.0); // remove this line for an only partially signed sdf 134 | } 135 | -------------------------------------------------------------------------------- /src/App/Source/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | App 7 | 80 | 81 | 82 |
83 | 84 | 114 | {{{ SCRIPT }}} 115 | 116 | -------------------------------------------------------------------------------- /src/Shaders/Source/CommonFS.shader: -------------------------------------------------------------------------------- 1 | 2 | mat3 cotangent_frame( vec3 N, vec3 p, vec2 uv ) 3 | { 4 | // get edge vectors of the pixel triangle 5 | vec3 dp1 = dFdx( p ); 6 | vec3 dp2 = dFdy( p ); 7 | vec2 duv1 = dFdx( uv ); 8 | vec2 duv2 = dFdy( uv ); 9 | 10 | // solve the linear system 11 | vec3 dp2perp = cross( dp2, N ); 12 | vec3 dp1perp = cross( N, dp1 ); 13 | vec3 T = dp2perp * duv1.x + dp1perp * duv2.x; 14 | vec3 B = dp2perp * duv1.y + dp1perp * duv2.y; 15 | 16 | // construct a scale-invariant frame 17 | float invmax = inversesqrt( max( dot(T,T), dot(B,B) ) ); 18 | return mat3( T * invmax, B * invmax, N ); 19 | } 20 | 21 | float GetHeight(sampler2D heightSampler, vec2 texCoords) 22 | { 23 | return texture2D(heightSampler, texCoords).r; 24 | } 25 | 26 | //Parallax Occlusion Mapping from: https://learnopengl.com/Advanced-Lighting/Parallax-Mapping 27 | vec2 ParallaxMapping(sampler2D heightSampler, vec2 texCoords, vec3 viewDir, float depthFactor) 28 | { 29 | float height_scale = depthFactor; 30 | // number of depth layers 31 | float minLayers = 8.0; 32 | float maxLayers = 32.0; 33 | float numLayers = mix(maxLayers, minLayers, min(abs(viewDir.z), 1.0)); 34 | // calculate the size of each layer 35 | float layerDepth = 1.0 / numLayers; 36 | // depth of current layer 37 | float currentLayerDepth = 0.0; 38 | // the amount to shift the texture coordinates per layer (from vector P) 39 | vec2 P = viewDir.xy * height_scale; 40 | vec2 deltaTexCoords = P / numLayers; 41 | 42 | // get initial values 43 | vec2 currentTexCoords = texCoords; 44 | float currentDepthMapValue = GetHeight(heightSampler, currentTexCoords); 45 | 46 | while(currentLayerDepth < currentDepthMapValue) 47 | { 48 | // shift texture coordinates along direction of P 49 | currentTexCoords -= deltaTexCoords; 50 | // get depthmap value at current texture coordinates 51 | currentDepthMapValue = GetHeight(heightSampler, currentTexCoords); 52 | // get depth of next layer 53 | currentLayerDepth += layerDepth; 54 | } 55 | 56 | // get texture coordinates before collision (reverse operations) 57 | vec2 prevTexCoords = currentTexCoords + deltaTexCoords; 58 | 59 | // get depth after and before collision for linear interpolation 60 | float afterDepth = currentDepthMapValue - currentLayerDepth; 61 | float beforeDepth = GetHeight(heightSampler, prevTexCoords) + layerDepth - currentLayerDepth; 62 | 63 | // interpolation of texture coordinates 64 | float weight = afterDepth / (afterDepth - beforeDepth); 65 | vec2 finalTexCoords = mix(currentTexCoords, prevTexCoords, weight); 66 | 67 | return finalTexCoords; 68 | } 69 | 70 | vec3 hash3( vec2 p ) 71 | { 72 | vec3 q = vec3( dot(p,vec2(127.1,311.7)), 73 | dot(p,vec2(269.5,183.3)), 74 | dot(p,vec2(419.2,371.9)) ); 75 | return fract(sin(q)*43758.5453); 76 | } 77 | 78 | /* 79 | vec4 cubemap2D( sampler2D sam, in vec3 d ) 80 | { 81 | vec3 n = abs(d); 82 | vec3 s = dFdx(d); 83 | vec3 t = dFdy(d); 84 | if(n.x>n.y && n.x>n.z) {d=d.xyz;s=s.xyz;t=t.xyz;} 85 | else if(n.y>n.x && n.y>n.z) {d=d.yzx;s=s.yzx;t=t.yzx;} 86 | else {d=d.zxy;s=s.zxy;t=t.zxy;} 87 | vec2 q = d.yz/d.x; 88 | return texture2Dgrad( sam, 89 | 0.5*q + 0.5, 90 | 0.5*(s.yz-q*s.x)/d.x, 91 | 0.5*(t.yz-q*t.x)/d.x ); 92 | } 93 | */ 94 | 95 | /* 96 | SAMPLER2D(Sampler0, 0); 97 | SAMPLER2D(Sampler1, 1); 98 | SAMPLER2D(Sampler2, 2); 99 | SAMPLER2D(Sampler3, 3); 100 | SAMPLER2D(Sampler4, 4); 101 | SAMPLER2D(Sampler5, 5); 102 | SAMPLER2D(Sampler6, 6); 103 | SAMPLER2D(Sampler7, 7); 104 | SAMPLERCUBE(CubeSampler0, 8); 105 | SAMPLERCUBE(CubeSampler1, 9); 106 | SAMPLERCUBE(CubeSampler2, 10); 107 | SAMPLERCUBE(CubeSampler3, 11); 108 | SAMPLERCUBE(CubeSampler4, 12); 109 | SAMPLERCUBE(CubeSampler5, 13); 110 | SAMPLERCUBE(CubeSampler6, 14); 111 | SAMPLERCUBE(CubeSampler7, 15); 112 | */ 113 | -------------------------------------------------------------------------------- /src/Shaders/Cache/Default_fs_mtl.h: -------------------------------------------------------------------------------- 1 | static const uint8_t Default_fs_mtl[642] = 2 | { 3 | 0x46, 0x53, 0x48, 0x0b, 0xe3, 0xc2, 0x5c, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6c, 0x02, // FSH....e......l. 4 | 0x00, 0x00, 0x23, 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x6d, 0x65, 0x74, 0x61, // ..#include .#inclu 6 | 0x64, 0x65, 0x20, 0x3c, 0x73, 0x69, 0x6d, 0x64, 0x2f, 0x73, 0x69, 0x6d, 0x64, 0x2e, 0x68, 0x3e, // de 7 | 0x0a, 0x0a, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, // ..using namespac 8 | 0x65, 0x20, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, // e metal;..struct 9 | 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, // xlatMtlMain_out 10 | 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x62, 0x67, // .{. float4 bg 11 | 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x20, 0x5b, 0x5b, 0x63, // fx_FragData0 [[c 12 | 0x6f, 0x6c, 0x6f, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x73, // olor(0)]];.};..s 13 | 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, // truct xlatMtlMai 14 | 0x6e, 0x5f, 0x69, 0x6e, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, // n_in.{. float 15 | 0x33, 0x20, 0x76, 0x5f, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x20, 0x5b, 0x5b, 0x75, 0x73, 0x65, // 3 v_normal [[use 16 | 0x72, 0x28, 0x6c, 0x6f, 0x63, 0x6e, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, // r(locn0)]];.};.. 17 | 0x66, 0x72, 0x61, 0x67, 0x6d, 0x65, 0x6e, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, // fragment xlatMtl 18 | 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, // Main_out xlatMtl 19 | 0x4d, 0x61, 0x69, 0x6e, 0x28, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, // Main(xlatMtlMain 20 | 0x5f, 0x69, 0x6e, 0x20, 0x69, 0x6e, 0x20, 0x5b, 0x5b, 0x73, 0x74, 0x61, 0x67, 0x65, 0x5f, 0x69, // _in in [[stage_i 21 | 0x6e, 0x5d, 0x5d, 0x29, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, // n]]).{. xlatM 22 | 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, // tlMain_out out = 23 | 0x20, 0x7b, 0x7d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x20, 0x5f, // {};. float _ 24 | 0x31, 0x30, 0x36, 0x20, 0x3d, 0x20, 0x28, 0x64, 0x6f, 0x74, 0x28, 0x66, 0x61, 0x73, 0x74, 0x3a, // 106 = (dot(fast: 25 | 0x3a, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x28, 0x69, 0x6e, 0x2e, 0x76, 0x5f, // :normalize(in.v_ 26 | 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x29, 0x2c, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x33, 0x28, // normal), float3( 27 | 0x30, 0x2e, 0x38, 0x31, 0x33, 0x37, 0x33, 0x33, 0x34, 0x35, 0x38, 0x35, 0x31, 0x38, 0x39, 0x38, // 0.81373345851898 28 | 0x31, 0x39, 0x33, 0x33, 0x35, 0x39, 0x33, 0x37, 0x35, 0x2c, 0x20, 0x30, 0x2e, 0x34, 0x36, 0x34, // 193359375, 0.464 29 | 0x39, 0x39, 0x30, 0x35, 0x35, 0x36, 0x32, 0x34, 0x30, 0x30, 0x38, 0x31, 0x37, 0x38, 0x37, 0x31, // 9905562400817871 30 | 0x30, 0x39, 0x33, 0x37, 0x35, 0x2c, 0x20, 0x30, 0x2e, 0x33, 0x34, 0x38, 0x37, 0x34, 0x32, 0x39, // 09375, 0.3487429 31 | 0x30, 0x32, 0x32, 0x37, 0x38, 0x39, 0x30, 0x30, 0x31, 0x34, 0x36, 0x34, 0x38, 0x34, 0x33, 0x37, // 0227890014648437 32 | 0x35, 0x29, 0x29, 0x20, 0x2a, 0x20, 0x30, 0x2e, 0x35, 0x29, 0x20, 0x2b, 0x20, 0x30, 0x2e, 0x35, // 5)) * 0.5) + 0.5 33 | 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, // ;. out.bgfx_F 34 | 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, 0x20, 0x3d, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, // ragData0 = float 35 | 0x34, 0x28, 0x30, 0x2e, 0x38, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x37, 0x36, 0x31, 0x35, 0x38, // 4(0.899999976158 36 | 0x31, 0x34, 0x32, 0x30, 0x38, 0x39, 0x38, 0x34, 0x33, 0x37, 0x35, 0x2c, 0x20, 0x30, 0x2e, 0x36, // 14208984375, 0.6 37 | 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x33, 0x38, 0x34, 0x31, 0x38, 0x35, 0x37, 0x39, 0x31, // 0000002384185791 38 | 0x30, 0x31, 0x35, 0x36, 0x32, 0x35, 0x2c, 0x20, 0x30, 0x2e, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, // 015625, 0.400000 39 | 0x30, 0x30, 0x35, 0x39, 0x36, 0x30, 0x34, 0x36, 0x34, 0x34, 0x37, 0x37, 0x35, 0x33, 0x39, 0x30, // 0059604644775390 40 | 0x36, 0x32, 0x35, 0x2c, 0x20, 0x31, 0x2e, 0x30, 0x29, 0x20, 0x2a, 0x20, 0x28, 0x5f, 0x31, 0x30, // 625, 1.0) * (_10 41 | 0x36, 0x20, 0x2a, 0x20, 0x5f, 0x31, 0x30, 0x36, 0x29, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72, // 6 * _106);. r 42 | 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6f, 0x75, 0x74, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, 0x00, // eturn out;.}.... 43 | 0x00, 0x00, // .. 44 | }; 45 | -------------------------------------------------------------------------------- /src/Shaders/Cache/Default_fs_spv.h: -------------------------------------------------------------------------------- 1 | static const uint8_t Default_fs_spv[726] = 2 | { 3 | 0x46, 0x53, 0x48, 0x0b, 0xe3, 0xc2, 0x5c, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x02, // FSH....e........ 4 | 0x00, 0x00, 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x73, 0x00, // ....#.........s. 5 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, // ................ 6 | 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, // ......GLSL.std.4 7 | 0x35, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, // 50.............. 8 | 0x00, 0x00, 0x0f, 0x00, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, // ..............ma 9 | 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x10, 0x00, // in....=...H..... 10 | 0x03, 0x00, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x05, 0x00, // ................ 11 | 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, // ..............ma 12 | 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x76, 0x5f, // in........=...v_ 13 | 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x06, 0x00, 0x48, 0x00, // normal........H. 14 | 0x00, 0x00, 0x62, 0x67, 0x66, 0x78, 0x5f, 0x46, 0x72, 0x61, 0x67, 0x44, 0x61, 0x74, 0x61, 0x30, // ..bgfx_FragData0 15 | 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x3d, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, // ..G...=......... 16 | 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x48, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, // ..G...H......... 17 | 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, 0x00, 0x03, 0x00, // ..........!..... 18 | 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x20, 0x00, // .............. . 19 | 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x08, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x04, 0x00, // ................ 20 | 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x03, 0x00, // ................ 21 | 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0xd6, 0x50, // ..+.......$....P 22 | 0x50, 0x3f, 0x2b, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x3e, 0x13, // P?+.......%...>. 23 | 0xee, 0x3e, 0x2b, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x6e, 0x8e, // .>+.......&...n. 24 | 0xb2, 0x3e, 0x2c, 0x00, 0x06, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x24, 0x00, // .>,.......'...$. 25 | 0x00, 0x00, 0x25, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x06, 0x00, // ..%...&...+..... 26 | 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x2b, 0x00, 0x04, 0x00, 0x06, 0x00, // ..)......?+..... 27 | 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x66, 0x66, 0x66, 0x3f, 0x2b, 0x00, 0x04, 0x00, 0x06, 0x00, // ..0...fff?+..... 28 | 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x9a, 0x99, 0x19, 0x3f, 0x2b, 0x00, 0x04, 0x00, 0x06, 0x00, // ..1......?+..... 29 | 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0xcd, 0xcc, 0xcc, 0x3e, 0x2b, 0x00, 0x04, 0x00, 0x06, 0x00, // ..2......>+..... 30 | 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x2c, 0x00, 0x07, 0x00, 0x08, 0x00, // ..3......?,..... 31 | 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x32, 0x00, // ..4...0...1...2. 32 | 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x01, 0x00, // ..3... ...<..... 33 | 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x3d, 0x00, // ......;...<...=. 34 | 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x47, 0x00, 0x00, 0x00, 0x03, 0x00, // ...... ...G..... 35 | 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x47, 0x00, 0x00, 0x00, 0x48, 0x00, // ......;...G...H. 36 | 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, 0x00, // ......6......... 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, 0x00, // ................ 38 | 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x3d, 0x00, // ..=.......>...=. 39 | 0x00, 0x00, 0x0c, 0x00, 0x06, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x01, 0x00, // ..........j..... 40 | 0x00, 0x00, 0x45, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x94, 0x00, 0x05, 0x00, 0x06, 0x00, // ..E...>......... 41 | 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x6a, 0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x85, 0x00, // ..k...j...'..... 42 | 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x29, 0x00, // ......l...k...). 43 | 0x00, 0x00, 0x81, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x6d, 0x00, 0x00, 0x00, 0x6c, 0x00, // ..........m...l. 44 | 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x85, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x70, 0x00, // ..)...........p. 45 | 0x00, 0x00, 0x6d, 0x00, 0x00, 0x00, 0x6d, 0x00, 0x00, 0x00, 0x8e, 0x00, 0x05, 0x00, 0x08, 0x00, // ..m...m......... 46 | 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x3e, 0x00, // ..r...4...p...>. 47 | 0x03, 0x00, 0x48, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, // ..H...r.......8. 48 | 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, // ...... 49 | }; 50 | -------------------------------------------------------------------------------- /src/Shaders/Cache/Default_vs_mtl.h: -------------------------------------------------------------------------------- 1 | static const uint8_t Default_vs_mtl[783] = 2 | { 3 | 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0xe3, 0xc2, 0x5c, 0x65, 0x02, 0x00, 0x07, 0x75, // VSH........e...u 4 | 0x5f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x04, 0x01, 0x40, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, // _world..@....... 5 | 0x10, 0x75, 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, // .u_viewProjectio 6 | 0x6e, 0x04, 0x01, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc8, 0x02, 0x00, 0x00, 0x23, // n..............# 7 | 0x69, 0x6e, 0x63, 0x6c, 0x75, 0x64, 0x65, 0x20, 0x3c, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x5f, 0x73, // include .#include 9 | 0x3c, 0x73, 0x69, 0x6d, 0x64, 0x2f, 0x73, 0x69, 0x6d, 0x64, 0x2e, 0x68, 0x3e, 0x0a, 0x0a, 0x75, // ..u 10 | 0x73, 0x69, 0x6e, 0x67, 0x20, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x20, 0x6d, // sing namespace m 11 | 0x65, 0x74, 0x61, 0x6c, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x5f, 0x47, // etal;..struct _G 12 | 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, // lobal.{. floa 13 | 0x74, 0x34, 0x78, 0x34, 0x20, 0x75, 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x65, // t4x4 u_viewProje 14 | 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, // ction;. float 15 | 0x34, 0x78, 0x34, 0x20, 0x75, 0x5f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, // 4x4 u_world;.};. 16 | 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, // .struct xlatMtlM 17 | 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x0a, 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, // ain_out.{. fl 18 | 0x6f, 0x61, 0x74, 0x33, 0x20, 0x5f, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, 0x6f, 0x69, 0x6e, 0x74, // oat3 _entryPoint 19 | 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x76, 0x5f, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x20, // Output_v_normal 20 | 0x5b, 0x5b, 0x75, 0x73, 0x65, 0x72, 0x28, 0x6c, 0x6f, 0x63, 0x6e, 0x30, 0x29, 0x5d, 0x5d, 0x3b, // [[user(locn0)]]; 21 | 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x20, 0x67, 0x6c, 0x5f, 0x50, // . float4 gl_P 22 | 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5b, 0x5b, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, // osition [[positi 23 | 0x6f, 0x6e, 0x5d, 0x5d, 0x3b, 0x0a, 0x7d, 0x3b, 0x0a, 0x0a, 0x73, 0x74, 0x72, 0x75, 0x63, 0x74, // on]];.};..struct 24 | 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x6e, 0x0a, // xlatMtlMain_in. 25 | 0x7b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x33, 0x20, 0x61, 0x5f, 0x6e, // {. float3 a_n 26 | 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x20, 0x5b, 0x5b, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, // ormal [[attribut 27 | 0x65, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6c, 0x6f, 0x61, // e(0)]];. floa 28 | 0x74, 0x33, 0x20, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x5b, 0x5b, // t3 a_position [[ 29 | 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x28, 0x31, 0x29, 0x5d, 0x5d, 0x3b, 0x0a, // attribute(1)]];. 30 | 0x7d, 0x3b, 0x0a, 0x0a, 0x76, 0x65, 0x72, 0x74, 0x65, 0x78, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, // };..vertex xlatM 31 | 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x5f, 0x6f, 0x75, 0x74, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, // tlMain_out xlatM 32 | 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, 0x28, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, // tlMain(xlatMtlMa 33 | 0x69, 0x6e, 0x5f, 0x69, 0x6e, 0x20, 0x69, 0x6e, 0x20, 0x5b, 0x5b, 0x73, 0x74, 0x61, 0x67, 0x65, // in_in in [[stage 34 | 0x5f, 0x69, 0x6e, 0x5d, 0x5d, 0x2c, 0x20, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x74, 0x20, // _in]], constant 35 | 0x5f, 0x47, 0x6c, 0x6f, 0x62, 0x61, 0x6c, 0x26, 0x20, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x20, // _Global& _mtl_u 36 | 0x5b, 0x5b, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x28, 0x30, 0x29, 0x5d, 0x5d, 0x29, 0x0a, 0x7b, // [[buffer(0)]]).{ 37 | 0x0a, 0x20, 0x20, 0x20, 0x20, 0x78, 0x6c, 0x61, 0x74, 0x4d, 0x74, 0x6c, 0x4d, 0x61, 0x69, 0x6e, // . xlatMtlMain 38 | 0x5f, 0x6f, 0x75, 0x74, 0x20, 0x6f, 0x75, 0x74, 0x20, 0x3d, 0x20, 0x7b, 0x7d, 0x3b, 0x0a, 0x20, // _out out = {};. 39 | 0x20, 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, // out.gl_Positi 40 | 0x6f, 0x6e, 0x20, 0x3d, 0x20, 0x28, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x75, 0x5f, 0x76, // on = (_mtl_u.u_v 41 | 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x2a, 0x20, // iewProjection * 42 | 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x75, 0x5f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x29, 0x20, // _mtl_u.u_world) 43 | 0x2a, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x28, 0x69, 0x6e, 0x2e, 0x61, 0x5f, 0x70, 0x6f, // * float4(in.a_po 44 | 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x31, 0x2e, 0x30, 0x29, 0x3b, 0x0a, 0x20, 0x20, // sition, 1.0);. 45 | 0x20, 0x20, 0x6f, 0x75, 0x74, 0x2e, 0x5f, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, 0x6f, 0x69, 0x6e, // out._entryPoin 46 | 0x74, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x5f, 0x76, 0x5f, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, // tOutput_v_normal 47 | 0x20, 0x3d, 0x20, 0x28, 0x5f, 0x6d, 0x74, 0x6c, 0x5f, 0x75, 0x2e, 0x75, 0x5f, 0x77, 0x6f, 0x72, // = (_mtl_u.u_wor 48 | 0x6c, 0x64, 0x20, 0x2a, 0x20, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x34, 0x28, 0x69, 0x6e, 0x2e, 0x61, // ld * float4(in.a 49 | 0x5f, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x2c, 0x20, 0x30, 0x2e, 0x30, 0x29, 0x29, 0x2e, 0x78, // _normal, 0.0)).x 50 | 0x79, 0x7a, 0x3b, 0x0a, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6f, // yz;. return o 51 | 0x75, 0x74, 0x3b, 0x0a, 0x7d, 0x0a, 0x0a, 0x00, 0x02, 0x02, 0x00, 0x01, 0x00, 0x80, 0x00, // ut;.}.......... 52 | }; 53 | -------------------------------------------------------------------------------- /src/Shaders/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB SHADER_FILES Source/*.vs 2 | Source/*.fs 3 | Source/*.cs 4 | Source/*.shader 5 | Source/*.sh 6 | Source/*.sc 7 | ) 8 | 9 | set(shaders_output "${CMAKE_CURRENT_SOURCE_DIR}/Cache") 10 | set(shaders_inc_file "${shaders_output}/EmbeddedShaders.h") 11 | set(shaders_cpp_file "${shaders_output}/EmbeddedShaders.cpp") 12 | 13 | function (AddShaders extension type dx11Profile) 14 | set(OUTPUT_TARGET_LIST "") 15 | foreach(SHADER ${SHADER_FILES}) 16 | get_filename_component(FILE_NAME ${SHADER} NAME_WE) 17 | get_filename_component(FILE_NAME_EXT ${SHADER} EXT) 18 | 19 | if(${FILE_NAME_EXT} STREQUAL ".${extension}") 20 | if(WIN32) 21 | set(SHADER_OUTPUT_TARGET "${shaders_output}/${FILE_NAME}_${extension}_dx11.h") 22 | message(${SHADER_OUTPUT_TARGET}) 23 | 24 | add_custom_command( 25 | OUTPUT ${SHADER_OUTPUT_TARGET} 26 | COMMAND "$" -f ${SHADER} -o ${SHADER_OUTPUT_TARGET} --platform windows -p ${dx11Profile} -O 3 --type ${type} --bin2c ${FILE_NAME}_${extension}_dx11 27 | COMMAND "$" -f ${SHADER} -o "${shaders_output}/${FILE_NAME}_${extension}_dx9.h" --platform windows -p ${dx11Profile} -O 3 --type ${type} --bin2c ${FILE_NAME}_${extension}_dx9 28 | COMMAND "$" -f ${SHADER} -o "${shaders_output}/${FILE_NAME}_${extension}_glsl.h" --platform asm.js -p 120 --type ${type} --bin2c ${FILE_NAME}_${extension}_glsl 29 | COMMAND "$" -f ${SHADER} -o "${shaders_output}/${FILE_NAME}_${extension}_mtl.h" --platform osx -p metal --type ${type} --bin2c ${FILE_NAME}_${extension}_mtl 30 | COMMAND "$" -f ${SHADER} -o "${shaders_output}/${FILE_NAME}_${extension}_spv.h" --platform linux -p spirv --type ${type} --bin2c ${FILE_NAME}_${extension}_spv 31 | COMMAND "$" -f ${SHADER} -o "${shaders_output}/${FILE_NAME}_${extension}_essl.h" --platform android --type ${type} --bin2c ${FILE_NAME}_${extension}_essl 32 | DEPENDS ${SHADER} 33 | COMMENT "Compiling shader ${SHADER}") 34 | elseif(APPLE OR (UNIX AND NOT EMSCRIPTEN)) 35 | message("Compiling shaders on MacOS. HLSL will not be built.") 36 | set(SHADER_OUTPUT_TARGET "${shaders_output}/${FILE_NAME}_${extension}_mtl.h") 37 | message(${SHADER_OUTPUT_TARGET}) 38 | 39 | add_custom_command( 40 | OUTPUT ${SHADER_OUTPUT_TARGET} 41 | #COMMAND "$" -f ${SHADER} -o ${SHADER_OUTPUT_TARGET} --platform windows -p ${dx11Profile} -O 3 --type ${type} --bin2c ${FILE_NAME}_${extension}_dx11 42 | #COMMAND "$" -f ${SHADER} -o "${shaders_output}/${FILE_NAME}_${extension}_dx9.h" --platform windows -p ${dx11Profile} -O 3 --type ${type} --bin2c ${FILE_NAME}_${extension}_dx9 43 | COMMAND "$" -f ${SHADER} -o "${shaders_output}/${FILE_NAME}_${extension}_glsl.h" --platform asm.js -p 120 --type ${type} --bin2c ${FILE_NAME}_${extension}_glsl 44 | COMMAND "$" -f ${SHADER} -o "${shaders_output}/${FILE_NAME}_${extension}_mtl.h" --platform osx -p metal --type ${type} --bin2c ${FILE_NAME}_${extension}_mtl 45 | COMMAND "$" -f ${SHADER} -o "${shaders_output}/${FILE_NAME}_${extension}_spv.h" --platform linux -p spirv --type ${type} --bin2c ${FILE_NAME}_${extension}_spv 46 | COMMAND "$" -f ${SHADER} -o "${shaders_output}/${FILE_NAME}_${extension}_essl.h" --platform android --type ${type} --bin2c ${FILE_NAME}_${extension}_essl 47 | DEPENDS ${SHADER} 48 | COMMENT "Compiling shader ${SHADER}") 49 | else() 50 | message("Unsupported platform for building shaders. Skipped.") 51 | endif() 52 | FILE(APPEND ${shaders_inc_file} "#ifdef WIN32\n#include \"${FILE_NAME}_${extension}_dx9.h\"\n") 53 | FILE(APPEND ${shaders_inc_file} "#include \"${FILE_NAME}_${extension}_dx11.h\"\n#endif\n") 54 | FILE(APPEND ${shaders_inc_file} "#include \"${FILE_NAME}_${extension}_glsl.h\"\n") 55 | FILE(APPEND ${shaders_inc_file} "#ifdef __APPLE__\n#include \"${FILE_NAME}_${extension}_mtl.h\"\n#endif\n") 56 | FILE(APPEND ${shaders_inc_file} "#include \"${FILE_NAME}_${extension}_spv.h\"\n") 57 | FILE(APPEND ${shaders_inc_file} "#include \"${FILE_NAME}_${extension}_essl.h\"\n") 58 | set(OUTPUT_TARGET_LIST ${OUTPUT_TARGET_LIST} ${SHADER_OUTPUT_TARGET}) 59 | FILE(APPEND ${shaders_cpp_file} "BGFX_EMBEDDED_SHADER(${FILE_NAME}_${extension}),\n") 60 | endif() 61 | endforeach(SHADER) 62 | set(SHADER_OUTPUT_FILES ${SHADER_OUTPUT_FILES} ${OUTPUT_TARGET_LIST} PARENT_SCOPE) 63 | endfunction() 64 | 65 | #if(WIN32) 66 | FILE(WRITE ${shaders_inc_file} "// generated by CMake\n#include \n#include \n") 67 | FILE(WRITE ${shaders_cpp_file} "// generated by CMake\n") 68 | FILE(WRITE ${shaders_cpp_file} "#include \"EmbeddedShaders.h\"\n#include \"bgfx_utils.h\"\nstatic const bgfx::EmbeddedShader embeddedShaders[] =\n{\n") 69 | 70 | AddShaders("vs" "vertex" "vs_5_0") 71 | AddShaders("cs" "compute" "ps_5_0") 72 | AddShaders("fs" "fragment" "ps_5_0") 73 | 74 | FILE(APPEND ${shaders_cpp_file} "BGFX_EMBEDDED_SHADER_END()\n};\n#include \"ShaderHelper.h\"\n") 75 | #endif() 76 | 77 | add_library(Shaders ${SHADER_FILES} ${shaders_inc_file} ${shaders_cpp_file} ${SHADER_OUTPUT_FILES} "Include/Shaders.h" "Source/ShaderHelper.h") 78 | target_link_libraries(Shaders bgfx bx example-common) 79 | target_include_directories(Shaders 80 | PUBLIC "Include" 81 | PRIVATE "Source") 82 | source_group( "Shader Files" FILES ${SHADER_FILES}) 83 | 84 | 85 | -------------------------------------------------------------------------------- /src/Shaders/Cache/Default_vs_spv.h: -------------------------------------------------------------------------------- 1 | static const uint8_t Default_vs_spv[1427] = 2 | { 3 | 0x56, 0x53, 0x48, 0x0b, 0x00, 0x00, 0x00, 0x00, 0xe3, 0xc2, 0x5c, 0x65, 0x02, 0x00, 0x07, 0x75, // VSH........e...u 4 | 0x5f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x04, 0x00, 0x40, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, // _world..@....... 5 | 0x10, 0x75, 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, 0x69, 0x6f, // .u_viewProjectio 6 | 0x6e, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, 0x05, 0x00, 0x00, 0x03, // n..........L.... 7 | 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x08, 0x00, 0x7b, 0x00, 0x00, 0x00, 0x00, // .#.........{.... 8 | 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, // ................ 9 | 0x00, 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30, 0x00, // ...GLSL.std.450. 10 | 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, // ................ 11 | 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, // ...........main. 12 | 0x00, 0x00, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x47, 0x00, 0x00, 0x00, 0x4b, // ...;...>...G...K 13 | 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x05, 0x00, 0x00, 0x00, 0xf4, 0x01, 0x00, 0x00, 0x05, // ................ 14 | 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x05, // .......main..... 15 | 0x00, 0x06, 0x00, 0x17, 0x00, 0x00, 0x00, 0x55, 0x6e, 0x69, 0x66, 0x6f, 0x72, 0x6d, 0x42, 0x6c, // .......UniformBl 16 | 0x6f, 0x63, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x08, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, // ock............. 17 | 0x00, 0x00, 0x00, 0x75, 0x5f, 0x76, 0x69, 0x65, 0x77, 0x50, 0x72, 0x6f, 0x6a, 0x65, 0x63, 0x74, // ...u_viewProject 18 | 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x05, 0x00, 0x17, 0x00, 0x00, 0x00, 0x01, // ion............. 19 | 0x00, 0x00, 0x00, 0x75, 0x5f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x00, 0x05, 0x00, 0x03, 0x00, 0x19, // ...u_world...... 20 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x61, // ...........;...a 21 | 0x5f, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x05, 0x00, 0x3e, // _normal........> 22 | 0x00, 0x00, 0x00, 0x61, 0x5f, 0x70, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x05, // ...a_position... 23 | 0x00, 0x0a, 0x00, 0x47, 0x00, 0x00, 0x00, 0x40, 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, 0x6f, 0x69, // ...G...@entryPoi 24 | 0x6e, 0x74, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, 0x2e, 0x67, 0x6c, 0x5f, 0x50, 0x6f, 0x73, 0x69, // ntOutput.gl_Posi 25 | 0x74, 0x69, 0x6f, 0x6e, 0x00, 0x00, 0x00, 0x05, 0x00, 0x09, 0x00, 0x4b, 0x00, 0x00, 0x00, 0x40, // tion.......K...@ 26 | 0x65, 0x6e, 0x74, 0x72, 0x79, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x4f, 0x75, 0x74, 0x70, 0x75, 0x74, // entryPointOutput 27 | 0x2e, 0x76, 0x5f, 0x6e, 0x6f, 0x72, 0x6d, 0x61, 0x6c, 0x00, 0x00, 0x48, 0x00, 0x04, 0x00, 0x17, // .v_normal..H.... 28 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x17, // ...........H.... 29 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, // .......#.......H 30 | 0x00, 0x05, 0x00, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10, // ................ 31 | 0x00, 0x00, 0x00, 0x48, 0x00, 0x04, 0x00, 0x17, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, // ...H............ 32 | 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x17, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x23, // ...H...........# 33 | 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x17, 0x00, 0x00, 0x00, 0x01, // ...@...H........ 34 | 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, 0x00, 0x17, // ...........G.... 35 | 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x19, 0x00, 0x00, 0x00, 0x22, // .......G......." 36 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x19, 0x00, 0x00, 0x00, 0x21, // .......G.......! 37 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x3b, 0x00, 0x00, 0x00, 0x1e, // .......G...;.... 38 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x1e, // .......G...>.... 39 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x47, 0x00, 0x00, 0x00, 0x0b, // .......G...G.... 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x4b, 0x00, 0x00, 0x00, 0x1e, // .......G...K.... 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x02, 0x00, 0x00, 0x00, 0x21, // ...............! 42 | 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00, 0x06, // ................ 43 | 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x06, // ... ............ 44 | 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x09, 0x00, 0x00, 0x00, 0x06, // ................ 45 | 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00, 0x12, 0x00, 0x00, 0x00, 0x20, // ............... 46 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x12, 0x00, 0x00, 0x00, 0x13, // .......+........ 47 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x18, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, 0x09, // ................ 48 | 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x04, 0x00, 0x17, 0x00, 0x00, 0x00, 0x14, // ................ 49 | 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x18, 0x00, 0x00, 0x00, 0x02, // ....... ........ 50 | 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x18, 0x00, 0x00, 0x00, 0x19, // .......;........ 51 | 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x02, // ....... ........ 52 | 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x12, 0x00, 0x00, 0x00, 0x1d, // .......+........ 53 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x22, // .......+......." 54 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x2b, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x2c, // ......?+......., 55 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x01, // ....... ...:.... 56 | 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x3b, // .......;...:...; 57 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x3a, 0x00, 0x00, 0x00, 0x3e, // .......;...:...> 58 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x46, 0x00, 0x00, 0x00, 0x03, // ....... ...F.... 59 | 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x46, 0x00, 0x00, 0x00, 0x47, // .......;...F...G 60 | 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x03, // ....... ...J.... 61 | 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x4a, 0x00, 0x00, 0x00, 0x4b, // .......;...J...K 62 | 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, // .......6........ 63 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x05, // ................ 64 | 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x3b, // ...=.......<...; 65 | 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x3e, // ...=.......?...> 66 | 0x00, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x19, // ...A.......e.... 67 | 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, 0x66, // .......=.......f 68 | 0x00, 0x00, 0x00, 0x65, 0x00, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x67, // ...e...A.......g 69 | 0x00, 0x00, 0x00, 0x19, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x14, // ...........=.... 70 | 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, 0x67, 0x00, 0x00, 0x00, 0x92, 0x00, 0x05, 0x00, 0x14, // ...h...g........ 71 | 0x00, 0x00, 0x00, 0x69, 0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, 0x51, // ...i...f...h...Q 72 | 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x00, // .......k...?.... 73 | 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x3f, // ...Q.......l...? 74 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x6d, // .......Q.......m 75 | 0x00, 0x00, 0x00, 0x3f, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x50, 0x00, 0x07, 0x00, 0x09, // ...?.......P.... 76 | 0x00, 0x00, 0x00, 0x6e, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x6d, // ...n...k...l...m 77 | 0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x90, 0x00, 0x05, 0x00, 0x09, 0x00, 0x00, 0x00, 0x70, // ..."...........p 78 | 0x00, 0x00, 0x00, 0x6e, 0x00, 0x00, 0x00, 0x69, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, // ...n...i...Q.... 79 | 0x00, 0x00, 0x00, 0x73, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x51, // ...s...<.......Q 80 | 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x01, // .......t...<.... 81 | 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x75, 0x00, 0x00, 0x00, 0x3c, // ...Q.......u...< 82 | 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x50, 0x00, 0x07, 0x00, 0x09, 0x00, 0x00, 0x00, 0x76, // .......P.......v 83 | 0x00, 0x00, 0x00, 0x73, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00, 0x75, 0x00, 0x00, 0x00, 0x2c, // ...s...t...u..., 84 | 0x00, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00, 0x1a, 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x19, // ...A.......w.... 85 | 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, 0x78, // .......=.......x 86 | 0x00, 0x00, 0x00, 0x77, 0x00, 0x00, 0x00, 0x90, 0x00, 0x05, 0x00, 0x09, 0x00, 0x00, 0x00, 0x79, // ...w...........y 87 | 0x00, 0x00, 0x00, 0x76, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x08, 0x00, 0x07, // ...v...x...O.... 88 | 0x00, 0x00, 0x00, 0x7a, 0x00, 0x00, 0x00, 0x79, 0x00, 0x00, 0x00, 0x79, 0x00, 0x00, 0x00, 0x00, // ...z...y...y.... 89 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x47, // ...........>...G 90 | 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x4b, 0x00, 0x00, 0x00, 0x7a, // ...p...>...K...z 91 | 0x00, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x00, 0x01, // .......8........ 92 | 0x00, 0x80, 0x00, // ... 93 | }; 94 | -------------------------------------------------------------------------------- /src/App/Source/App.cpp: -------------------------------------------------------------------------------- 1 | #include "common.h" 2 | #include "bgfx_utils.h" 3 | #include "imgui/imgui.h" 4 | #include "Shaders.h" 5 | 6 | namespace App 7 | { 8 | 9 | struct PosNormalVertex 10 | { 11 | float m_x; 12 | float m_y; 13 | float m_z; 14 | uint32_t m_normal; 15 | 16 | static void init() 17 | { 18 | ms_layout 19 | .begin() 20 | .add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float) 21 | .add(bgfx::Attrib::Normal, 4, bgfx::AttribType::Uint8, true, true) 22 | .end(); 23 | } 24 | 25 | static bgfx::VertexLayout ms_layout; 26 | }; 27 | 28 | bgfx::VertexLayout PosNormalVertex::ms_layout; 29 | 30 | static PosNormalVertex s_cubeVertices[24] = 31 | { 32 | {-1.0f, 1.0f, 1.0f, encodeNormalRgba8( 0.0f, 0.0f, 1.0f) }, 33 | { 1.0f, 1.0f, 1.0f, encodeNormalRgba8( 0.0f, 0.0f, 1.0f) }, 34 | {-1.0f, -1.0f, 1.0f, encodeNormalRgba8( 0.0f, 0.0f, 1.0f) }, 35 | { 1.0f, -1.0f, 1.0f, encodeNormalRgba8( 0.0f, 0.0f, 1.0f) }, 36 | {-1.0f, 1.0f, -1.0f, encodeNormalRgba8( 0.0f, 0.0f, -1.0f) }, 37 | { 1.0f, 1.0f, -1.0f, encodeNormalRgba8( 0.0f, 0.0f, -1.0f) }, 38 | {-1.0f, -1.0f, -1.0f, encodeNormalRgba8( 0.0f, 0.0f, -1.0f) }, 39 | { 1.0f, -1.0f, -1.0f, encodeNormalRgba8( 0.0f, 0.0f, -1.0f) }, 40 | {-1.0f, 1.0f, 1.0f, encodeNormalRgba8( 0.0f, 1.0f, 0.0f) }, 41 | { 1.0f, 1.0f, 1.0f, encodeNormalRgba8( 0.0f, 1.0f, 0.0f) }, 42 | {-1.0f, 1.0f, -1.0f, encodeNormalRgba8( 0.0f, 1.0f, 0.0f) }, 43 | { 1.0f, 1.0f, -1.0f, encodeNormalRgba8( 0.0f, 1.0f, 0.0f) }, 44 | {-1.0f, -1.0f, 1.0f, encodeNormalRgba8( 0.0f, -1.0f, 0.0f) }, 45 | { 1.0f, -1.0f, 1.0f, encodeNormalRgba8( 0.0f, -1.0f, 0.0f) }, 46 | {-1.0f, -1.0f, -1.0f, encodeNormalRgba8( 0.0f, -1.0f, 0.0f) }, 47 | { 1.0f, -1.0f, -1.0f, encodeNormalRgba8( 0.0f, -1.0f, 0.0f) }, 48 | { 1.0f, -1.0f, 1.0f, encodeNormalRgba8( 1.0f, 0.0f, 0.0f) }, 49 | { 1.0f, 1.0f, 1.0f, encodeNormalRgba8( 1.0f, 0.0f, 0.0f) }, 50 | { 1.0f, -1.0f, -1.0f, encodeNormalRgba8( 1.0f, 0.0f, 0.0f) }, 51 | { 1.0f, 1.0f, -1.0f, encodeNormalRgba8( 1.0f, 0.0f, 0.0f) }, 52 | {-1.0f, -1.0f, 1.0f, encodeNormalRgba8(-1.0f, 0.0f, 0.0f) }, 53 | {-1.0f, 1.0f, 1.0f, encodeNormalRgba8(-1.0f, 0.0f, 0.0f) }, 54 | {-1.0f, -1.0f, -1.0f, encodeNormalRgba8(-1.0f, 0.0f, 0.0f) }, 55 | {-1.0f, 1.0f, -1.0f, encodeNormalRgba8(-1.0f, 0.0f, 0.0f) }, 56 | }; 57 | 58 | static const uint16_t s_cubeIndices[36] = 59 | { 60 | 0, 2, 1, 61 | 1, 2, 3, 62 | 4, 5, 6, 63 | 5, 7, 6, 64 | 65 | 8, 10, 9, 66 | 9, 10, 11, 67 | 12, 13, 14, 68 | 13, 15, 14, 69 | 70 | 16, 18, 17, 71 | 17, 18, 19, 72 | 20, 21, 22, 73 | 21, 23, 22, 74 | }; 75 | 76 | 77 | #ifdef __EMSCRIPTEN__ 78 | #include 79 | EM_JS(void, HideLoader, (), { document.getElementById("loader").style.display = "none"; }); 80 | #else 81 | void HideLoader() {} 82 | #endif 83 | 84 | 85 | class App : public entry::AppI 86 | { 87 | public: 88 | App(const char* _name, const char* _description, const char* _url) 89 | : entry::AppI(_name, _description, _url) 90 | { 91 | } 92 | 93 | void init(int32_t _argc, const char* const* _argv, uint32_t _width, uint32_t _height) override 94 | { 95 | Args args(_argc, _argv); 96 | 97 | m_width = _width; 98 | m_height = _height; 99 | m_debug = BGFX_DEBUG_NONE; 100 | m_reset = BGFX_RESET_VSYNC; 101 | 102 | bgfx::Init init; 103 | init.type = args.m_type; 104 | init.vendorId = args.m_pciId; 105 | init.resolution.width = m_width; 106 | init.resolution.height = m_height; 107 | init.resolution.reset = m_reset; 108 | bgfx::init(init); 109 | 110 | // Enable debug text. 111 | bgfx::setDebug(m_debug); 112 | 113 | // Set view 0 clear state. 114 | bgfx::setViewClear(0 115 | , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH 116 | , 0 117 | , 1.0f 118 | , 0 119 | ); 120 | 121 | m_timeOffset = bx::getHPCounter(); 122 | 123 | imguiCreate(); 124 | 125 | // Create vertex stream declaration. 126 | PosNormalVertex::init(); 127 | 128 | // Create static vertex buffer. 129 | m_vbh = bgfx::createVertexBuffer( 130 | bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) ) 131 | , PosNormalVertex::ms_layout 132 | ); 133 | 134 | bx::mtxIdentity(m_world); 135 | 136 | // Create static index buffer. 137 | m_ibh = bgfx::createIndexBuffer(bgfx::makeRef(s_cubeIndices, sizeof(s_cubeIndices) ) ); 138 | 139 | m_worldUniform = bgfx::createUniform("u_world", bgfx::UniformType::Mat4); 140 | m_viewProjectionUniform = bgfx::createUniform("u_viewProjection", bgfx::UniformType::Mat4); 141 | 142 | // Create program from shaders. 143 | m_program = LoadProgram("Default_vs", "Default_fs"); 144 | 145 | HideLoader(); 146 | } 147 | 148 | virtual int shutdown() override 149 | { 150 | imguiDestroy(); 151 | 152 | // Shutdown bgfx. 153 | bgfx::shutdown(); 154 | 155 | return 0; 156 | } 157 | 158 | void editTransform(const float* view, const float* projection, float* world) 159 | { 160 | static ImGuizmo::OPERATION mCurrentGizmoOperation(ImGuizmo::TRANSLATE); 161 | static ImGuizmo::MODE mCurrentGizmoMode(ImGuizmo::WORLD); 162 | if (ImGui::IsKeyPressed(90)) 163 | mCurrentGizmoOperation = ImGuizmo::TRANSLATE; 164 | if (ImGui::IsKeyPressed(69)) 165 | mCurrentGizmoOperation = ImGuizmo::ROTATE; 166 | if (ImGui::IsKeyPressed(82)) // r Key 167 | mCurrentGizmoOperation = ImGuizmo::SCALE; 168 | if (ImGui::RadioButton("Translate", mCurrentGizmoOperation == ImGuizmo::TRANSLATE)) 169 | mCurrentGizmoOperation = ImGuizmo::TRANSLATE; 170 | ImGui::SameLine(); 171 | if (ImGui::RadioButton("Rotate", mCurrentGizmoOperation == ImGuizmo::ROTATE)) 172 | mCurrentGizmoOperation = ImGuizmo::ROTATE; 173 | ImGui::SameLine(); 174 | if (ImGui::RadioButton("Scale", mCurrentGizmoOperation == ImGuizmo::SCALE)) 175 | mCurrentGizmoOperation = ImGuizmo::SCALE; 176 | float matrixTranslation[3], matrixRotation[3], matrixScale[3]; 177 | ImGuizmo::DecomposeMatrixToComponents(world, matrixTranslation, matrixRotation, matrixScale); 178 | ImGui::InputFloat3("Tr", matrixTranslation); 179 | ImGui::InputFloat3("Rt", matrixRotation); 180 | ImGui::InputFloat3("Sc", matrixScale); 181 | ImGuizmo::RecomposeMatrixFromComponents(matrixTranslation, matrixRotation, matrixScale, world); 182 | 183 | if (mCurrentGizmoOperation != ImGuizmo::SCALE) 184 | { 185 | if (ImGui::RadioButton("Local", mCurrentGizmoMode == ImGuizmo::LOCAL)) 186 | mCurrentGizmoMode = ImGuizmo::LOCAL; 187 | ImGui::SameLine(); 188 | if (ImGui::RadioButton("World", mCurrentGizmoMode == ImGuizmo::WORLD)) 189 | mCurrentGizmoMode = ImGuizmo::WORLD; 190 | } 191 | static bool useSnap(false); 192 | if (ImGui::IsKeyPressed(83)) 193 | useSnap = !useSnap; 194 | ImGui::Checkbox("Snap", &useSnap); 195 | ImGui::SameLine(); 196 | static float snap[3] = {1, 1, 1}; 197 | switch (mCurrentGizmoOperation) 198 | { 199 | case ImGuizmo::TRANSLATE: 200 | ImGui::InputFloat3("Snap", snap); 201 | break; 202 | case ImGuizmo::ROTATE: 203 | ImGui::InputFloat("Angle Snap", snap); 204 | break; 205 | case ImGuizmo::SCALE: 206 | ImGui::InputFloat("Scale Snap", snap); 207 | break; 208 | default: 209 | break; 210 | } 211 | ImGuiIO& io = ImGui::GetIO(); 212 | ImGuizmo::SetRect(0, 0, io.DisplaySize.x, io.DisplaySize.y); 213 | ImGuizmo::Manipulate(view, projection, mCurrentGizmoOperation, mCurrentGizmoMode, world, NULL, useSnap ? snap : NULL); 214 | } 215 | bool update() override 216 | { 217 | if (!entry::processEvents(m_width, m_height, m_debug, m_reset, &m_mouseState) ) 218 | { 219 | imguiBeginFrame(m_mouseState.m_mx 220 | , m_mouseState.m_my 221 | , (m_mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0) 222 | | (m_mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0) 223 | | (m_mouseState.m_buttons[entry::MouseButton::Middle] ? IMGUI_MBUT_MIDDLE : 0) 224 | , m_mouseState.m_mz 225 | , uint16_t(m_width) 226 | , uint16_t(m_height) 227 | ); 228 | 229 | const bx::Vec3 at = { 0.0f, 0.0f, 0.0f }; 230 | const bx::Vec3 eye = { 3.0f, 4.0f, 5.0f }; 231 | 232 | // Set view and projection matrix for view 0. 233 | float view[16]; 234 | bx::mtxLookAt(view, eye, at, {0.f, 1.f, 0.f}); 235 | 236 | float proj[16]; 237 | bx::mtxProj(proj, 60.0f, float(m_width)/float(m_height), 0.1f, 100.0f, bgfx::getCaps()->homogeneousDepth); 238 | 239 | float viewProj[16]; 240 | bx::mtxMul(viewProj, view, proj); 241 | 242 | bgfx::setUniform(m_worldUniform, m_world); 243 | bgfx::setUniform(m_viewProjectionUniform, viewProj); 244 | 245 | // Transform dialog 246 | ImGui::SetNextWindowPos( 247 | ImVec2(10.0f, 10.0f) 248 | , ImGuiCond_FirstUseEver 249 | ); 250 | ImGui::SetNextWindowSize( 251 | ImVec2(m_width / 5.0f, m_height / 3.5f) 252 | , ImGuiCond_FirstUseEver 253 | ); 254 | ImGui::Begin("Transform" 255 | , NULL 256 | , 0 257 | ); 258 | 259 | editTransform(view, proj, m_world); 260 | ImGui::End(); 261 | 262 | imguiEndFrame(); 263 | 264 | float time = (float)( (bx::getHPCounter()-m_timeOffset)/double(bx::getHPFrequency() ) ); 265 | 266 | bgfx::setViewRect(0, 0, 0, m_width, m_height); 267 | bgfx::setViewClear(0 268 | , BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH 269 | , 0x20304030 270 | , 1.0f 271 | , 0 272 | ); 273 | bgfx::discard(); 274 | bgfx::touch(0); 275 | 276 | // Set view 0 default viewport. 277 | bgfx::setViewRect(0, 0, 0, uint16_t(m_width), uint16_t(m_height) ); 278 | 279 | uint64_t state = BGFX_STATE_WRITE_MASK | BGFX_STATE_DEPTH_TEST_LESS; 280 | 281 | // Set vertex and index buffer. 282 | bgfx::setVertexBuffer(0, m_vbh); 283 | bgfx::setIndexBuffer(m_ibh); 284 | 285 | // Set render states. 286 | bgfx::setState(state); 287 | 288 | // Submit primitive for rendering to view 0. 289 | bgfx::submit(0, m_program); 290 | 291 | // Advance to next frame. Rendering thread will be kicked to 292 | // process submitted rendering primitives. 293 | bgfx::frame(); 294 | 295 | return true; 296 | } 297 | 298 | return false; 299 | } 300 | 301 | entry::MouseState m_mouseState; 302 | 303 | uint32_t m_width; 304 | uint32_t m_height; 305 | uint32_t m_debug; 306 | uint32_t m_reset; 307 | int64_t m_timeOffset; 308 | float m_world[16]; 309 | 310 | bgfx::VertexBufferHandle m_vbh; 311 | bgfx::IndexBufferHandle m_ibh; 312 | bgfx::ProgramHandle m_program; 313 | bgfx::UniformHandle m_worldUniform; 314 | bgfx::UniformHandle m_viewProjectionUniform; 315 | }; 316 | 317 | } // namespace 318 | 319 | ENTRY_IMPLEMENT_MAIN( 320 | App::App 321 | , "App" 322 | , "" 323 | , "" 324 | ); 325 | -------------------------------------------------------------------------------- /src/Shaders/Source/bgfx_compute.sh: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2019 Branimir Karadzic. All rights reserved. 3 | * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause 4 | */ 5 | 6 | #ifndef BGFX_COMPUTE_H_HEADER_GUARD 7 | #define BGFX_COMPUTE_H_HEADER_GUARD 8 | 9 | #include "bgfx_shader.sh" 10 | 11 | #ifndef __cplusplus 12 | 13 | #if BGFX_SHADER_LANGUAGE_GLSL 14 | # define __UAV_REG_0 4 15 | # define __UAV_REG_1 5 16 | # define __UAV_REG_2 6 17 | # define __UAV_REG_3 7 18 | #else 19 | # define __UAV_REG_0 16 20 | # define __UAV_REG_1 17 21 | # define __UAV_REG_2 18 22 | # define __UAV_REG_3 19 23 | #endif // BGFX_SHADER_LANGUAGE_GLSL 24 | 25 | #define FRAMEBUFFER_IMAGE2D_RW(_name, _format, _reg) IMAGE2D_RW(_name, _format, __UAV_REG_ ## _reg) 26 | 27 | #if BGFX_SHADER_LANGUAGE_GLSL 28 | 29 | #define SHARED shared 30 | 31 | #define __IMAGE_XX(_name, _format, _reg, _image, _access) \ 32 | layout(_format, binding=_reg) _access uniform highp _image _name 33 | 34 | #define readwrite 35 | #define IMAGE2D_RO( _name, _format, _reg) __IMAGE_XX(_name, _format, _reg, image2D, readonly) 36 | #define UIMAGE2D_RO(_name, _format, _reg) __IMAGE_XX(_name, _format, _reg, uimage2D, readonly) 37 | #define IMAGE2D_WR( _name, _format, _reg) __IMAGE_XX(_name, _format, _reg, image2D, writeonly) 38 | #define UIMAGE2D_WR(_name, _format, _reg) __IMAGE_XX(_name, _format, _reg, uimage2D, writeonly) 39 | #define IMAGE2D_RW( _name, _format, _reg) __IMAGE_XX(_name, _format, _reg, image2D, readwrite) 40 | #define UIMAGE2D_RW(_name, _format, _reg) __IMAGE_XX(_name, _format, _reg, uimage2D, readwrite) 41 | 42 | #define IMAGE2D_ARRAY_RO( _name, _format, _reg) __IMAGE_XX(_name, _format, _reg, image2DArray, readonly) 43 | #define UIMAGE2D_ARRAY_RO(_name, _format, _reg) __IMAGE_XX(_name, _format, _reg, uimage2DArray, readonly) 44 | #define IMAGE2D_ARRAY_WR( _name, _format, _reg) __IMAGE_XX(_name, _format, _reg, image2DArray, writeonly) 45 | #define UIMAGE2D_ARRAY_WR(_name, _format, _reg) __IMAGE_XX(_name, _format, _reg, uimage2DArray, writeonly) 46 | #define IMAGE2D_ARRAY_RW( _name, _format, _reg) __IMAGE_XX(_name, _format, _reg, image2DArray, readwrite) 47 | #define UIMAGE2D_ARRAY_RW(_name, _format, _reg) __IMAGE_XX(_name, _format, _reg, uimage2DArray, readwrite) 48 | 49 | #define IMAGE3D_RO( _name, _format, _reg) __IMAGE_XX(_name, _format, _reg, image3D, readonly) 50 | #define UIMAGE3D_RO(_name, _format, _reg) __IMAGE_XX(_name, _format, _reg, uimage3D, readonly) 51 | #define IMAGE3D_WR( _name, _format, _reg) __IMAGE_XX(_name, _format, _reg, image3D, writeonly) 52 | #define UIMAGE3D_WR(_name, _format, _reg) __IMAGE_XX(_name, _format, _reg, uimage3D, writeonly) 53 | #define IMAGE3D_RW( _name, _format, _reg) __IMAGE_XX(_name, _format, _reg, image3D, readwrite) 54 | #define UIMAGE3D_RW(_name, _format, _reg) __IMAGE_XX(_name, _format, _reg, uimage3D, readwrite) 55 | 56 | #define __BUFFER_XX(_name, _type, _reg, _access) \ 57 | layout(std430, binding=_reg) _access buffer _name ## Buffer \ 58 | { \ 59 | _type _name[]; \ 60 | } 61 | 62 | #define BUFFER_RO(_name, _type, _reg) __BUFFER_XX(_name, _type, _reg, readonly) 63 | #define BUFFER_RW(_name, _type, _reg) __BUFFER_XX(_name, _type, _reg, readwrite) 64 | #define BUFFER_WR(_name, _type, _reg) __BUFFER_XX(_name, _type, _reg, writeonly) 65 | 66 | #define NUM_THREADS(_x, _y, _z) layout (local_size_x = _x, local_size_y = _y, local_size_z = _z) in; 67 | 68 | #define atomicFetchAndAdd(_mem, _data, _original) _original = atomicAdd(_mem, _data) 69 | #define atomicFetchAndAnd(_mem, _data, _original) _original = atomicAnd(_mem, _data) 70 | #define atomicFetchAndMax(_mem, _data, _original) _original = atomicMax(_mem, _data) 71 | #define atomicFetchAndMin(_mem, _data, _original) _original = atomicMin(_mem, _data) 72 | #define atomicFetchAndOr(_mem, _data, _original) _original = atomicOr(_mem, _data) 73 | #define atomicFetchAndXor(_mem, _data, _original) _original = atomicXor(_mem, _data) 74 | #define atomicFetchAndExchange(_mem, _data, _original) _original = atomicExchange(_mem, _data) 75 | #define atomicFetchCompareExchange(_mem, _compare, _data, _original) _original = atomicCompSwap(_mem,_compare, _data) 76 | 77 | #else 78 | 79 | #define SHARED groupshared 80 | 81 | #define r32ui uint 82 | #define rg32ui uint2 83 | #define rgba32ui uint4 84 | #define r32f float 85 | #define r16f float 86 | #define rg16f float2 87 | #define rgba16f float4 88 | #if BGFX_SHADER_LANGUAGE_HLSL 89 | # define rgba8 unorm float4 90 | # define rg8 unorm float2 91 | # define r8 unorm float 92 | #else 93 | # define rgba8 float4 94 | # define rg8 float2 95 | # define r8 float 96 | #endif // BGFX_SHADER_LANGUAGE_HLSL 97 | #define rgba32f float4 98 | 99 | #define IMAGE2D_RO( _name, _format, _reg) \ 100 | Texture2D<_format> _name ## Texture : REGISTER(t, _reg); \ 101 | static BgfxROImage2D_ ## _format _name = { _name ## Texture } 102 | 103 | #define UIMAGE2D_RO(_name, _format, _reg) IMAGE2D_RO(_name, _format, _reg) 104 | 105 | #define IMAGE2D_RW( _name, _format, _reg) \ 106 | RWTexture2D<_format> _name ## Texture : REGISTER(u, _reg); \ 107 | static BgfxRWImage2D_ ## _format _name = { _name ## Texture } 108 | 109 | #define IMAGE2D_WR( _name, _format, _reg) IMAGE2D_RW(_name, _format, _reg) 110 | #define UIMAGE2D_WR(_name, _format, _reg) IMAGE2D_RW(_name, _format, _reg) 111 | #define UIMAGE2D_RW(_name, _format, _reg) IMAGE2D_RW(_name, _format, _reg) 112 | 113 | #define IMAGE2D_ARRAY_RO(_name, _format, _reg) \ 114 | Texture2DArray<_format> _name ## Texture : REGISTER(t, _reg); \ 115 | static BgfxROImage2DArray_ ## _format _name = { _name ## Texture } 116 | 117 | #define UIMAGE2D_ARRAY_RO(_name, _format, _reg) IMAGE2D_ARRAY_RO(_name, _format, _reg) 118 | 119 | #define IMAGE2D_ARRAY_RW(_name, _format, _reg) \ 120 | RWTexture2DArray<_format> _name ## Texture : REGISTER(u, _reg); \ 121 | static BgfxRWImage2DArray_ ## _format _name = { _name ## Texture } 122 | 123 | #define UIMAGE2D_ARRAY_RW(_name, _format, _reg) IMAGE2D_ARRAY_RW(_name, _format, _reg) 124 | #define IMAGE2D_ARRAY_WR( _name, _format, _reg) IMAGE2D_ARRAY_RW(_name, _format, _reg) 125 | #define UIMAGE2D_ARRAY_WR(_name, _format, _reg) IMAGE2D_ARRAY_RW(_name, _format, _reg) 126 | 127 | #define IMAGE3D_RO( _name, _format, _reg) \ 128 | Texture3D<_format> _name ## Texture : REGISTER(t, _reg); \ 129 | static BgfxROImage3D_ ## _format _name = { _name ## Texture } 130 | 131 | #define UIMAGE3D_RO(_name, _format, _reg) IMAGE3D_RO(_name, _format, _reg) 132 | 133 | #define IMAGE3D_RW( _name, _format, _reg) \ 134 | RWTexture3D<_format> _name ## Texture : REGISTER(u, _reg); \ 135 | static BgfxRWImage3D_ ## _format _name = { _name ## Texture } 136 | 137 | #define UIMAGE3D_RW(_name, _format, _reg) IMAGE3D_RW(_name, _format, _reg) 138 | #define IMAGE3D_WR( _name, _format, _reg) IMAGE3D_RW(_name, _format, _reg) 139 | #define UIMAGE3D_WR(_name, _format, _reg) IMAGE3D_RW(_name, _format, _reg) 140 | 141 | #if BGFX_SHADER_LANGUAGE_METAL 142 | #define BUFFER_RO(_name, _struct, _reg) StructuredBuffer<_struct> _name : REGISTER(t, _reg) 143 | #define BUFFER_RW(_name, _struct, _reg) RWStructuredBuffer <_struct> _name : REGISTER(u, _reg) 144 | #define BUFFER_WR(_name, _struct, _reg) BUFFER_RW(_name, _struct, _reg) 145 | #else 146 | #define BUFFER_RO(_name, _struct, _reg) Buffer<_struct> _name : REGISTER(t, _reg) 147 | #define BUFFER_RW(_name, _struct, _reg) RWBuffer<_struct> _name : REGISTER(u, _reg) 148 | #define BUFFER_WR(_name, _struct, _reg) BUFFER_RW(_name, _struct, _reg) 149 | #endif 150 | 151 | #define NUM_THREADS(_x, _y, _z) [numthreads(_x, _y, _z)] 152 | 153 | #define __IMAGE_IMPL_S(_format, _storeComponents, _type, _loadComponents) \ 154 | \ 155 | struct BgfxROImage2D_ ## _format \ 156 | { \ 157 | Texture2D<_format> m_texture; \ 158 | }; \ 159 | \ 160 | struct BgfxRWImage2D_ ## _format \ 161 | { \ 162 | RWTexture2D<_format> m_texture; \ 163 | }; \ 164 | \ 165 | struct BgfxROImage2DArray_ ## _format \ 166 | { \ 167 | Texture2DArray<_format> m_texture; \ 168 | }; \ 169 | \ 170 | struct BgfxRWImage2DArray_ ## _format \ 171 | { \ 172 | RWTexture2DArray<_format> m_texture; \ 173 | }; \ 174 | \ 175 | struct BgfxROImage3D_ ## _format \ 176 | { \ 177 | Texture3D<_format> m_texture; \ 178 | }; \ 179 | \ 180 | struct BgfxRWImage3D_ ## _format \ 181 | { \ 182 | RWTexture3D<_format> m_texture; \ 183 | }; \ 184 | 185 | #define __IMAGE_IMPL_A(_format, _storeComponents, _type, _loadComponents) \ 186 | __IMAGE_IMPL_S(_format, _storeComponents, _type, _loadComponents) \ 187 | \ 188 | _type imageLoad(BgfxROImage2D_ ## _format _image, ivec2 _uv) \ 189 | { \ 190 | return _image.m_texture[_uv]._loadComponents; \ 191 | } \ 192 | \ 193 | ivec2 imageSize(BgfxROImage2D_ ## _format _image) \ 194 | { \ 195 | uvec2 result; \ 196 | _image.m_texture.GetDimensions(result.x, result.y); \ 197 | return ivec2(result); \ 198 | } \ 199 | \ 200 | _type imageLoad(BgfxRWImage2D_ ## _format _image, ivec2 _uv) \ 201 | { \ 202 | return _image.m_texture[_uv]._loadComponents; \ 203 | } \ 204 | \ 205 | ivec2 imageSize(BgfxRWImage2D_ ## _format _image) \ 206 | { \ 207 | uvec2 result; \ 208 | _image.m_texture.GetDimensions(result.x, result.y); \ 209 | return ivec2(result); \ 210 | } \ 211 | \ 212 | void imageStore(BgfxRWImage2D_ ## _format _image, ivec2 _uv, _type _value) \ 213 | { \ 214 | _image.m_texture[_uv] = _value._storeComponents; \ 215 | } \ 216 | \ 217 | _type imageLoad(BgfxROImage2DArray_ ## _format _image, ivec3 _uvw) \ 218 | { \ 219 | return _image.m_texture[_uvw]._loadComponents; \ 220 | } \ 221 | \ 222 | ivec3 imageSize(BgfxROImage2DArray_ ## _format _image) \ 223 | { \ 224 | uvec3 result; \ 225 | _image.m_texture.GetDimensions(result.x, result.y, result.z); \ 226 | return ivec3(result); \ 227 | } \ 228 | \ 229 | _type imageLoad(BgfxRWImage2DArray_ ## _format _image, ivec3 _uvw) \ 230 | { \ 231 | return _image.m_texture[_uvw]._loadComponents; \ 232 | } \ 233 | \ 234 | void imageStore(BgfxRWImage2DArray_ ## _format _image, ivec3 _uvw, _type _value) \ 235 | { \ 236 | _image.m_texture[_uvw] = _value._storeComponents; \ 237 | } \ 238 | \ 239 | ivec3 imageSize(BgfxRWImage2DArray_ ## _format _image) \ 240 | { \ 241 | uvec3 result; \ 242 | _image.m_texture.GetDimensions(result.x, result.y, result.z); \ 243 | return ivec3(result); \ 244 | } \ 245 | \ 246 | _type imageLoad(BgfxROImage3D_ ## _format _image, ivec3 _uvw) \ 247 | { \ 248 | return _image.m_texture[_uvw]._loadComponents; \ 249 | } \ 250 | \ 251 | ivec3 imageSize(BgfxROImage3D_ ## _format _image) \ 252 | { \ 253 | uvec3 result; \ 254 | _image.m_texture.GetDimensions(result.x, result.y, result.z); \ 255 | return ivec3(result); \ 256 | } \ 257 | \ 258 | _type imageLoad(BgfxRWImage3D_ ## _format _image, ivec3 _uvw) \ 259 | { \ 260 | return _image.m_texture[_uvw]._loadComponents; \ 261 | } \ 262 | \ 263 | ivec3 imageSize(BgfxRWImage3D_ ## _format _image) \ 264 | { \ 265 | uvec3 result; \ 266 | _image.m_texture.GetDimensions(result.x, result.y, result.z); \ 267 | return ivec3(result); \ 268 | } \ 269 | \ 270 | void imageStore(BgfxRWImage3D_ ## _format _image, ivec3 _uvw, _type _value) \ 271 | { \ 272 | _image.m_texture[_uvw] = _value._storeComponents; \ 273 | } 274 | 275 | #define __IMAGE_IMPL_ATOMIC(_format, _storeComponents, _type, _loadComponents) \ 276 | \ 277 | void imageAtomicAdd(BgfxRWImage2D_ ## _format _image, ivec2 _uv, _type _value) \ 278 | { \ 279 | InterlockedAdd(_image.m_texture[_uv], _value._storeComponents); \ 280 | } \ 281 | 282 | 283 | __IMAGE_IMPL_A(rgba8, xyzw, vec4, xyzw) 284 | __IMAGE_IMPL_A(rg8, xy, vec4, xyyy) 285 | __IMAGE_IMPL_A(r8, x, vec4, xxxx) 286 | __IMAGE_IMPL_A(rg16f, xy, vec4, xyyy) 287 | #if BGFX_SHADER_LANGUAGE_HLSL 288 | __IMAGE_IMPL_S(rgba16f, xyzw, vec4, xyzw) 289 | __IMAGE_IMPL_S(r16f, x, vec4, xxxx) 290 | #else 291 | __IMAGE_IMPL_A(rgba16f, xyzw, vec4, xyzw) 292 | __IMAGE_IMPL_A(r16f, x, vec4, xxxx) 293 | #endif // BGFX_SHADER_LANGUAGE_HLSL 294 | __IMAGE_IMPL_A(r32f, x, vec4, xxxx) 295 | __IMAGE_IMPL_A(rgba32f, xyzw, vec4, xyzw) 296 | __IMAGE_IMPL_A(r32ui, x, uvec4, xxxx) 297 | __IMAGE_IMPL_A(rg32ui, xy, uvec4, xyyy) 298 | __IMAGE_IMPL_A(rgba32ui, xyzw, uvec4, xyzw) 299 | 300 | __IMAGE_IMPL_ATOMIC(r32ui, x, uvec4, xxxx) 301 | 302 | #define atomicAdd(_mem, _data) InterlockedAdd(_mem, _data) 303 | #define atomicAnd(_mem, _data) InterlockedAnd(_mem, _data) 304 | #define atomicMax(_mem, _data) InterlockedMax(_mem, _data) 305 | #define atomicMin(_mem, _data) InterlockedMin(_mem, _data) 306 | #define atomicOr(_mem, _data) InterlockedOr(_mem, _data) 307 | #define atomicXor(_mem, _data) InterlockedXor(_mem, _data) 308 | #define atomicFetchAndAdd(_mem, _data, _original) InterlockedAdd(_mem, _data, _original) 309 | #define atomicFetchAndAnd(_mem, _data, _original) InterlockedAnd(_mem, _data, _original) 310 | #define atomicFetchAndMax(_mem, _data, _original) InterlockedMax(_mem, _data, _original) 311 | #define atomicFetchAndMin(_mem, _data, _original) InterlockedMin(_mem, _data, _original) 312 | #define atomicFetchAndOr(_mem, _data, _original) InterlockedOr(_mem, _data, _original) 313 | #define atomicFetchAndXor(_mem, _data, _original) InterlockedXor(_mem, _data, _original) 314 | #define atomicFetchAndExchange(_mem, _data, _original) InterlockedExchange(_mem, _data, _original) 315 | #define atomicFetchCompareExchange(_mem, _compare, _data, _original) InterlockedCompareExchange(_mem,_compare, _data, _original) 316 | 317 | // InterlockedCompareStore 318 | 319 | #define barrier() GroupMemoryBarrierWithGroupSync() 320 | #define memoryBarrier() GroupMemoryBarrierWithGroupSync() 321 | #define memoryBarrierAtomicCounter() GroupMemoryBarrierWithGroupSync() 322 | #define memoryBarrierBuffer() AllMemoryBarrierWithGroupSync() 323 | #define memoryBarrierImage() GroupMemoryBarrierWithGroupSync() 324 | #define memoryBarrierShared() GroupMemoryBarrierWithGroupSync() 325 | #define groupMemoryBarrier() GroupMemoryBarrierWithGroupSync() 326 | 327 | #endif // BGFX_SHADER_LANGUAGE_GLSL 328 | 329 | #define dispatchIndirect( \ 330 | _buffer \ 331 | , _offset \ 332 | , _numX \ 333 | , _numY \ 334 | , _numZ \ 335 | ) \ 336 | _buffer[_offset*2+0] = uvec4(_numX, _numY, _numZ, 0u) 337 | 338 | #define drawIndirect( \ 339 | _buffer \ 340 | , _offset \ 341 | , _numVertices \ 342 | , _numInstances \ 343 | , _startVertex \ 344 | , _startInstance \ 345 | ) \ 346 | _buffer[_offset*2+0] = uvec4(_numVertices, _numInstances, _startVertex, _startInstance) 347 | 348 | #define drawIndexedIndirect( \ 349 | _buffer \ 350 | , _offset \ 351 | , _numIndices \ 352 | , _numInstances \ 353 | , _startIndex \ 354 | , _startVertex \ 355 | , _startInstance \ 356 | ) \ 357 | _buffer[_offset*2+0] = uvec4(_numIndices, _numInstances, _startIndex, _startVertex); \ 358 | _buffer[_offset*2+1] = uvec4(_startInstance, 0u, 0u, 0u) 359 | 360 | #endif // __cplusplus 361 | 362 | #endif // BGFX_COMPUTE_H_HEADER_GUARD 363 | -------------------------------------------------------------------------------- /src/Shaders/Source/bgfx_shader.sh: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011-2019 Branimir Karadzic. All rights reserved. 3 | * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause 4 | */ 5 | 6 | #ifndef BGFX_SHADER_H_HEADER_GUARD 7 | #define BGFX_SHADER_H_HEADER_GUARD 8 | 9 | #if !defined(BGFX_CONFIG_MAX_BONES) 10 | # define BGFX_CONFIG_MAX_BONES 32 11 | #endif // !defined(BGFX_CONFIG_MAX_BONES) 12 | 13 | #ifndef __cplusplus 14 | 15 | #if BGFX_SHADER_LANGUAGE_HLSL > 3 16 | # define BRANCH [branch] 17 | # define LOOP [loop] 18 | # define UNROLL [unroll] 19 | #else 20 | # define BRANCH 21 | # define LOOP 22 | # define UNROLL 23 | #endif // BGFX_SHADER_LANGUAGE_HLSL > 3 24 | 25 | #if BGFX_SHADER_LANGUAGE_HLSL > 3 && BGFX_SHADER_TYPE_FRAGMENT 26 | # define EARLY_DEPTH_STENCIL [earlydepthstencil] 27 | #else 28 | # define EARLY_DEPTH_STENCIL 29 | #endif // BGFX_SHADER_LANGUAGE_HLSL > 3 && BGFX_SHADER_TYPE_FRAGMENT 30 | 31 | #if BGFX_SHADER_LANGUAGE_GLSL 32 | # define ARRAY_BEGIN(_type, _name, _count) _type _name[_count] = _type[]( 33 | # define ARRAY_END() ) 34 | #else 35 | # define ARRAY_BEGIN(_type, _name, _count) _type _name[_count] = { 36 | # define ARRAY_END() } 37 | #endif // BGFX_SHADER_LANGUAGE_GLSL 38 | 39 | #if BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL 40 | # define CONST(_x) static const _x 41 | # define dFdx(_x) ddx(_x) 42 | # define dFdy(_y) ddy(-_y) 43 | # define inversesqrt(_x) rsqrt(_x) 44 | # define fract(_x) frac(_x) 45 | 46 | # define bvec2 bool2 47 | # define bvec3 bool3 48 | # define bvec4 bool4 49 | 50 | # if BGFX_SHADER_LANGUAGE_HLSL > 4 51 | # define REGISTER(_type, _reg) register(_type[_reg]) 52 | # else 53 | # define REGISTER(_type, _reg) register(_type ## _reg) 54 | # endif // BGFX_SHADER_LANGUAGE_HLSL 55 | 56 | # if BGFX_SHADER_LANGUAGE_HLSL > 3 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL 57 | # if BGFX_SHADER_LANGUAGE_HLSL > 4 || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL 58 | # define dFdxCoarse(_x) ddx_coarse(_x) 59 | # define dFdxFine(_x) ddx_fine(_x) 60 | # define dFdyCoarse(_y) ddy_coarse(-_y) 61 | # define dFdyFine(_y) ddy_fine(-_y) 62 | # endif // BGFX_SHADER_LANGUAGE_HLSL > 4 63 | 64 | # if BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL 65 | float intBitsToFloat(int _x) { return asfloat(_x); } 66 | vec2 intBitsToFloat(uint2 _x) { return asfloat(_x); } 67 | vec3 intBitsToFloat(uint3 _x) { return asfloat(_x); } 68 | vec4 intBitsToFloat(uint4 _x) { return asfloat(_x); } 69 | # endif // BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL 70 | 71 | float uintBitsToFloat(uint _x) { return asfloat(_x); } 72 | vec2 uintBitsToFloat(uint2 _x) { return asfloat(_x); } 73 | vec3 uintBitsToFloat(uint3 _x) { return asfloat(_x); } 74 | vec4 uintBitsToFloat(uint4 _x) { return asfloat(_x); } 75 | 76 | uint floatBitsToUint(float _x) { return asuint(_x); } 77 | uvec2 floatBitsToUint(vec2 _x) { return asuint(_x); } 78 | uvec3 floatBitsToUint(vec3 _x) { return asuint(_x); } 79 | uvec4 floatBitsToUint(vec4 _x) { return asuint(_x); } 80 | 81 | int floatBitsToInt(float _x) { return asint(_x); } 82 | ivec2 floatBitsToInt(vec2 _x) { return asint(_x); } 83 | ivec3 floatBitsToInt(vec3 _x) { return asint(_x); } 84 | ivec4 floatBitsToInt(vec4 _x) { return asint(_x); } 85 | 86 | uint bitfieldReverse(uint _x) { return reversebits(_x); } 87 | uint2 bitfieldReverse(uint2 _x) { return reversebits(_x); } 88 | uint3 bitfieldReverse(uint3 _x) { return reversebits(_x); } 89 | uint4 bitfieldReverse(uint4 _x) { return reversebits(_x); } 90 | 91 | # if !BGFX_SHADER_LANGUAGE_SPIRV 92 | uint packHalf2x16(vec2 _x) 93 | { 94 | return (f32tof16(_x.y)<<16) | f32tof16(_x.x); 95 | } 96 | 97 | vec2 unpackHalf2x16(uint _x) 98 | { 99 | return vec2(f16tof32(_x & 0xffff), f16tof32(_x >> 16) ); 100 | } 101 | # endif // !BGFX_SHADER_LANGUAGE_SPIRV 102 | 103 | struct BgfxSampler2D 104 | { 105 | SamplerState m_sampler; 106 | Texture2D m_texture; 107 | }; 108 | 109 | struct BgfxISampler2D 110 | { 111 | Texture2D m_texture; 112 | }; 113 | 114 | struct BgfxUSampler2D 115 | { 116 | Texture2D m_texture; 117 | }; 118 | 119 | struct BgfxSampler2DArray 120 | { 121 | SamplerState m_sampler; 122 | Texture2DArray m_texture; 123 | }; 124 | 125 | struct BgfxSampler2DShadow 126 | { 127 | SamplerComparisonState m_sampler; 128 | Texture2D m_texture; 129 | }; 130 | 131 | struct BgfxSampler2DArrayShadow 132 | { 133 | SamplerComparisonState m_sampler; 134 | Texture2DArray m_texture; 135 | }; 136 | 137 | struct BgfxSampler3D 138 | { 139 | SamplerState m_sampler; 140 | Texture3D m_texture; 141 | }; 142 | 143 | struct BgfxISampler3D 144 | { 145 | Texture3D m_texture; 146 | }; 147 | 148 | struct BgfxUSampler3D 149 | { 150 | Texture3D m_texture; 151 | }; 152 | 153 | struct BgfxSamplerCube 154 | { 155 | SamplerState m_sampler; 156 | TextureCube m_texture; 157 | }; 158 | 159 | struct BgfxSamplerCubeShadow 160 | { 161 | SamplerComparisonState m_sampler; 162 | TextureCube m_texture; 163 | }; 164 | 165 | struct BgfxSampler2DMS 166 | { 167 | Texture2DMS m_texture; 168 | }; 169 | 170 | vec4 bgfxTexture2D(BgfxSampler2D _sampler, vec2 _coord) 171 | { 172 | return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); 173 | } 174 | 175 | vec4 bgfxTexture2DLod(BgfxSampler2D _sampler, vec2 _coord, float _level) 176 | { 177 | return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level); 178 | } 179 | 180 | vec4 bgfxTexture2DLodOffset(BgfxSampler2D _sampler, vec2 _coord, float _level, ivec2 _offset) 181 | { 182 | return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level, _offset); 183 | } 184 | 185 | vec4 bgfxTexture2DProj(BgfxSampler2D _sampler, vec3 _coord) 186 | { 187 | vec2 coord = _coord.xy * rcp(_coord.z); 188 | return _sampler.m_texture.Sample(_sampler.m_sampler, coord); 189 | } 190 | 191 | vec4 bgfxTexture2DProj(BgfxSampler2D _sampler, vec4 _coord) 192 | { 193 | vec2 coord = _coord.xy * rcp(_coord.w); 194 | return _sampler.m_texture.Sample(_sampler.m_sampler, coord); 195 | } 196 | 197 | vec4 bgfxTexture2DGrad(BgfxSampler2D _sampler, vec2 _coord, vec2 _dPdx, vec2 _dPdy) 198 | { 199 | return _sampler.m_texture.SampleGrad(_sampler.m_sampler, _coord, _dPdx, _dPdy); 200 | } 201 | 202 | vec4 bgfxTexture2DArray(BgfxSampler2DArray _sampler, vec3 _coord) 203 | { 204 | return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); 205 | } 206 | 207 | vec4 bgfxTexture2DArrayLod(BgfxSampler2DArray _sampler, vec3 _coord, float _lod) 208 | { 209 | return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _lod); 210 | } 211 | 212 | vec4 bgfxTexture2DArrayLodOffset(BgfxSampler2DArray _sampler, vec3 _coord, float _level, ivec2 _offset) 213 | { 214 | return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level, _offset); 215 | } 216 | 217 | float bgfxShadow2D(BgfxSampler2DShadow _sampler, vec3 _coord) 218 | { 219 | return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, _coord.xy, _coord.z); 220 | } 221 | 222 | float bgfxShadow2DProj(BgfxSampler2DShadow _sampler, vec4 _coord) 223 | { 224 | vec3 coord = _coord.xyz * rcp(_coord.w); 225 | return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, coord.xy, coord.z); 226 | } 227 | 228 | vec4 bgfxShadow2DArray(BgfxSampler2DArrayShadow _sampler, vec4 _coord) 229 | { 230 | return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, _coord.xyz, _coord.w); 231 | } 232 | 233 | vec4 bgfxTexture3D(BgfxSampler3D _sampler, vec3 _coord) 234 | { 235 | return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); 236 | } 237 | 238 | vec4 bgfxTexture3DLod(BgfxSampler3D _sampler, vec3 _coord, float _level) 239 | { 240 | return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level); 241 | } 242 | 243 | ivec4 bgfxTexture3D(BgfxISampler3D _sampler, vec3 _coord) 244 | { 245 | uvec3 size; 246 | _sampler.m_texture.GetDimensions(size.x, size.y, size.z); 247 | return _sampler.m_texture.Load(ivec4(_coord * size, 0) ); 248 | } 249 | 250 | uvec4 bgfxTexture3D(BgfxUSampler3D _sampler, vec3 _coord) 251 | { 252 | uvec3 size; 253 | _sampler.m_texture.GetDimensions(size.x, size.y, size.z); 254 | return _sampler.m_texture.Load(ivec4(_coord * size, 0) ); 255 | } 256 | 257 | vec4 bgfxTextureCube(BgfxSamplerCube _sampler, vec3 _coord) 258 | { 259 | return _sampler.m_texture.Sample(_sampler.m_sampler, _coord); 260 | } 261 | 262 | vec4 bgfxTextureCubeLod(BgfxSamplerCube _sampler, vec3 _coord, float _level) 263 | { 264 | return _sampler.m_texture.SampleLevel(_sampler.m_sampler, _coord, _level); 265 | } 266 | 267 | float bgfxShadowCube(BgfxSamplerCubeShadow _sampler, vec4 _coord) 268 | { 269 | return _sampler.m_texture.SampleCmpLevelZero(_sampler.m_sampler, _coord.xyz, _coord.w); 270 | } 271 | 272 | vec4 bgfxTexelFetch(BgfxSampler2D _sampler, ivec2 _coord, int _lod) 273 | { 274 | return _sampler.m_texture.Load(ivec3(_coord, _lod) ); 275 | } 276 | 277 | vec4 bgfxTexelFetchOffset(BgfxSampler2D _sampler, ivec2 _coord, int _lod, ivec2 _offset) 278 | { 279 | return _sampler.m_texture.Load(ivec3(_coord, _lod), _offset ); 280 | } 281 | 282 | vec2 bgfxTextureSize(BgfxSampler2D _sampler, int _lod) 283 | { 284 | vec2 result; 285 | _sampler.m_texture.GetDimensions(result.x, result.y); 286 | return result; 287 | } 288 | 289 | vec4 bgfxTextureGather(BgfxSampler2D _sampler, vec2 _coord) 290 | { 291 | return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord ); 292 | } 293 | vec4 bgfxTextureGatherOffset(BgfxSampler2D _sampler, vec2 _coord, ivec2 _offset) 294 | { 295 | return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord, _offset ); 296 | } 297 | vec4 bgfxTextureGather(BgfxSampler2DArray _sampler, vec3 _coord) 298 | { 299 | return _sampler.m_texture.GatherRed(_sampler.m_sampler, _coord ); 300 | } 301 | 302 | ivec4 bgfxTexelFetch(BgfxISampler2D _sampler, ivec2 _coord, int _lod) 303 | { 304 | return _sampler.m_texture.Load(ivec3(_coord, _lod) ); 305 | } 306 | 307 | uvec4 bgfxTexelFetch(BgfxUSampler2D _sampler, ivec2 _coord, int _lod) 308 | { 309 | return _sampler.m_texture.Load(ivec3(_coord, _lod) ); 310 | } 311 | 312 | vec4 bgfxTexelFetch(BgfxSampler2DMS _sampler, ivec2 _coord, int _sampleIdx) 313 | { 314 | return _sampler.m_texture.Load(_coord, _sampleIdx); 315 | } 316 | 317 | vec4 bgfxTexelFetch(BgfxSampler2DArray _sampler, ivec3 _coord, int _lod) 318 | { 319 | return _sampler.m_texture.Load(ivec4(_coord, _lod) ); 320 | } 321 | 322 | vec4 bgfxTexelFetch(BgfxSampler3D _sampler, ivec3 _coord, int _lod) 323 | { 324 | return _sampler.m_texture.Load(ivec4(_coord, _lod) ); 325 | } 326 | 327 | vec3 bgfxTextureSize(BgfxSampler3D _sampler, int _lod) 328 | { 329 | vec3 result; 330 | _sampler.m_texture.GetDimensions(result.x, result.y, result.z); 331 | return result; 332 | } 333 | 334 | # define SAMPLER2D(_name, _reg) \ 335 | uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \ 336 | uniform Texture2D _name ## Texture : REGISTER(t, _reg); \ 337 | static BgfxSampler2D _name = { _name ## Sampler, _name ## Texture } 338 | # define ISAMPLER2D(_name, _reg) \ 339 | uniform Texture2D _name ## Texture : REGISTER(t, _reg); \ 340 | static BgfxISampler2D _name = { _name ## Texture } 341 | # define USAMPLER2D(_name, _reg) \ 342 | uniform Texture2D _name ## Texture : REGISTER(t, _reg); \ 343 | static BgfxUSampler2D _name = { _name ## Texture } 344 | # define sampler2D BgfxSampler2D 345 | # define texture2D(_sampler, _coord) bgfxTexture2D(_sampler, _coord) 346 | # define texture2DLod(_sampler, _coord, _level) bgfxTexture2DLod(_sampler, _coord, _level) 347 | # define texture2DLodOffset(_sampler, _coord, _level, _offset) bgfxTexture2DLodOffset(_sampler, _coord, _level, _offset) 348 | # define texture2DProj(_sampler, _coord) bgfxTexture2DProj(_sampler, _coord) 349 | # define texture2DGrad(_sampler, _coord, _dPdx, _dPdy) bgfxTexture2DGrad(_sampler, _coord, _dPdx, _dPdy) 350 | 351 | # define SAMPLER2DARRAY(_name, _reg) \ 352 | uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \ 353 | uniform Texture2DArray _name ## Texture : REGISTER(t, _reg); \ 354 | static BgfxSampler2DArray _name = { _name ## Sampler, _name ## Texture } 355 | # define sampler2DArray BgfxSampler2DArray 356 | # define texture2DArray(_sampler, _coord) bgfxTexture2DArray(_sampler, _coord) 357 | # define texture2DArrayLod(_sampler, _coord, _lod) bgfxTexture2DArrayLod(_sampler, _coord, _lod) 358 | # define texture2DArrayLodOffset(_sampler, _coord, _level, _offset) bgfxTexture2DArrayLodOffset(_sampler, _coord, _level, _offset) 359 | 360 | # define SAMPLER2DMS(_name, _reg) \ 361 | uniform Texture2DMS _name ## Texture : REGISTER(t, _reg); \ 362 | static BgfxSampler2DMS _name = { _name ## Texture } 363 | # define sampler2DMS BgfxSampler2DMS 364 | 365 | # define SAMPLER2DSHADOW(_name, _reg) \ 366 | uniform SamplerComparisonState _name ## SamplerComparison : REGISTER(s, _reg); \ 367 | uniform Texture2D _name ## Texture : REGISTER(t, _reg); \ 368 | static BgfxSampler2DShadow _name = { _name ## SamplerComparison, _name ## Texture } 369 | # define sampler2DShadow BgfxSampler2DShadow 370 | # define shadow2D(_sampler, _coord) bgfxShadow2D(_sampler, _coord) 371 | # define shadow2DProj(_sampler, _coord) bgfxShadow2DProj(_sampler, _coord) 372 | 373 | # define SAMPLER2DARRAYSHADOW(_name, _reg) \ 374 | SamplerComparisonState _name ## SamplerComparison : REGISTER(s, _reg); \ 375 | Texture2DArray _name ## Texture : REGISTER(t, _reg); \ 376 | BgfxSampler2DArrayShadow _name = { _name ## SamplerComparison, _name ## Texture } 377 | # define sampler2DArrayShadow BgfxSampler2DArrayShadow 378 | # define shadow2DArray(_sampler, _coord) bgfxShadow2DArray(_sampler, _coord) 379 | 380 | # define SAMPLER3D(_name, _reg) \ 381 | uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \ 382 | uniform Texture3D _name ## Texture : REGISTER(t, _reg); \ 383 | static BgfxSampler3D _name = { _name ## Sampler, _name ## Texture } 384 | # define ISAMPLER3D(_name, _reg) \ 385 | uniform Texture3D _name ## Texture : REGISTER(t, _reg); \ 386 | static BgfxISampler3D _name = { _name ## Texture } 387 | # define USAMPLER3D(_name, _reg) \ 388 | uniform Texture3D _name ## Texture : REGISTER(t, _reg); \ 389 | static BgfxUSampler3D _name = { _name ## Texture } 390 | # define sampler3D BgfxSampler3D 391 | # define texture3D(_sampler, _coord) bgfxTexture3D(_sampler, _coord) 392 | # define texture3DLod(_sampler, _coord, _level) bgfxTexture3DLod(_sampler, _coord, _level) 393 | 394 | # define SAMPLERCUBE(_name, _reg) \ 395 | uniform SamplerState _name ## Sampler : REGISTER(s, _reg); \ 396 | uniform TextureCube _name ## Texture : REGISTER(t, _reg); \ 397 | static BgfxSamplerCube _name = { _name ## Sampler, _name ## Texture } 398 | # define samplerCube BgfxSamplerCube 399 | # define textureCube(_sampler, _coord) bgfxTextureCube(_sampler, _coord) 400 | # define textureCubeLod(_sampler, _coord, _level) bgfxTextureCubeLod(_sampler, _coord, _level) 401 | 402 | # define SAMPLERCUBESHADOW(_name, _reg) \ 403 | uniform SamplerComparisonState _name ## SamplerComparison : REGISTER(s, _reg); \ 404 | uniform TextureCube _name ## Texture : REGISTER(t, _reg); \ 405 | static BgfxSamplerCubeShadow _name = { _name ## SamplerComparison, _name ## Texture } 406 | # define samplerCubeShadow BgfxSamplerCubeShadow 407 | # define shadowCube(_sampler, _coord) bgfxShadowCube(_sampler, _coord) 408 | 409 | # define texelFetch(_sampler, _coord, _lod) bgfxTexelFetch(_sampler, _coord, _lod) 410 | # define texelFetchOffset(_sampler, _coord, _lod, _offset) bgfxTexelFetchOffset(_sampler, _coord, _lod, _offset) 411 | # define textureSize(_sampler, _lod) bgfxTextureSize(_sampler, _lod) 412 | # define textureGather(_sampler, _coord) bgfxTextureGather(_sampler, _coord) 413 | # define textureGatherOffset(_sampler, _coord, _offset) bgfxTextureGatherOffset(_sampler, _coord, _offset) 414 | # else 415 | 416 | # define sampler2DShadow sampler2D 417 | 418 | vec4 bgfxTexture2DProj(sampler2D _sampler, vec3 _coord) 419 | { 420 | return tex2Dproj(_sampler, vec4(_coord.xy, 0.0, _coord.z) ); 421 | } 422 | 423 | vec4 bgfxTexture2DProj(sampler2D _sampler, vec4 _coord) 424 | { 425 | return tex2Dproj(_sampler, _coord); 426 | } 427 | 428 | float bgfxShadow2D(sampler2DShadow _sampler, vec3 _coord) 429 | { 430 | #if 0 431 | float occluder = tex2D(_sampler, _coord.xy).x; 432 | return step(_coord.z, occluder); 433 | #else 434 | return tex2Dproj(_sampler, vec4(_coord.xy, _coord.z, 1.0) ).x; 435 | #endif // 0 436 | } 437 | 438 | float bgfxShadow2DProj(sampler2DShadow _sampler, vec4 _coord) 439 | { 440 | #if 0 441 | vec3 coord = _coord.xyz * rcp(_coord.w); 442 | float occluder = tex2D(_sampler, coord.xy).x; 443 | return step(coord.z, occluder); 444 | #else 445 | return tex2Dproj(_sampler, _coord).x; 446 | #endif // 0 447 | } 448 | 449 | # define SAMPLER2D(_name, _reg) uniform sampler2D _name : REGISTER(s, _reg) 450 | # define SAMPLER2DMS(_name, _reg) uniform sampler2DMS _name : REGISTER(s, _reg) 451 | # define texture2D(_sampler, _coord) tex2D(_sampler, _coord) 452 | # define texture2DProj(_sampler, _coord) bgfxTexture2DProj(_sampler, _coord) 453 | 454 | # define SAMPLER2DARRAY(_name, _reg) SAMPLER2D(_name, _reg) 455 | # define texture2DArray(_sampler, _coord) texture2D(_sampler, (_coord).xy) 456 | # define texture2DArrayLod(_sampler, _coord, _lod) texture2DLod(_sampler, _coord, _lod) 457 | 458 | # define SAMPLER2DSHADOW(_name, _reg) uniform sampler2DShadow _name : REGISTER(s, _reg) 459 | # define shadow2D(_sampler, _coord) bgfxShadow2D(_sampler, _coord) 460 | # define shadow2DProj(_sampler, _coord) bgfxShadow2DProj(_sampler, _coord) 461 | 462 | # define SAMPLER3D(_name, _reg) uniform sampler3D _name : REGISTER(s, _reg) 463 | # define texture3D(_sampler, _coord) tex3D(_sampler, _coord) 464 | 465 | # define SAMPLERCUBE(_name, _reg) uniform samplerCUBE _name : REGISTER(s, _reg) 466 | # define textureCube(_sampler, _coord) texCUBE(_sampler, _coord) 467 | 468 | # if BGFX_SHADER_LANGUAGE_HLSL == 2 469 | # define texture2DLod(_sampler, _coord, _level) tex2D(_sampler, (_coord).xy) 470 | # define texture2DGrad(_sampler, _coord, _dPdx, _dPdy) tex2D(_sampler, _coord) 471 | # define texture3DLod(_sampler, _coord, _level) tex3D(_sampler, (_coord).xyz) 472 | # define textureCubeLod(_sampler, _coord, _level) texCUBE(_sampler, (_coord).xyz) 473 | # else 474 | # define texture2DLod(_sampler, _coord, _level) tex2Dlod(_sampler, vec4( (_coord).xy, 0.0, _level) ) 475 | # define texture2DGrad(_sampler, _coord, _dPdx, _dPdy) tex2Dgrad(_sampler, _coord, _dPdx, _dPdy) 476 | # define texture3DLod(_sampler, _coord, _level) tex3Dlod(_sampler, vec4( (_coord).xyz, _level) ) 477 | # define textureCubeLod(_sampler, _coord, _level) texCUBElod(_sampler, vec4( (_coord).xyz, _level) ) 478 | # endif // BGFX_SHADER_LANGUAGE_HLSL == 2 479 | 480 | # endif // BGFX_SHADER_LANGUAGE_HLSL > 3 481 | 482 | vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_mtx, _vec); } 483 | vec3 instMul(mat3 _mtx, vec3 _vec) { return mul(_vec, _mtx); } 484 | vec4 instMul(vec4 _vec, mat4 _mtx) { return mul(_mtx, _vec); } 485 | vec4 instMul(mat4 _mtx, vec4 _vec) { return mul(_vec, _mtx); } 486 | 487 | bvec2 lessThan(vec2 _a, vec2 _b) { return _a < _b; } 488 | bvec3 lessThan(vec3 _a, vec3 _b) { return _a < _b; } 489 | bvec4 lessThan(vec4 _a, vec4 _b) { return _a < _b; } 490 | 491 | bvec2 lessThanEqual(vec2 _a, vec2 _b) { return _a <= _b; } 492 | bvec3 lessThanEqual(vec3 _a, vec3 _b) { return _a <= _b; } 493 | bvec4 lessThanEqual(vec4 _a, vec4 _b) { return _a <= _b; } 494 | 495 | bvec2 greaterThan(vec2 _a, vec2 _b) { return _a > _b; } 496 | bvec3 greaterThan(vec3 _a, vec3 _b) { return _a > _b; } 497 | bvec4 greaterThan(vec4 _a, vec4 _b) { return _a > _b; } 498 | 499 | bvec2 greaterThanEqual(vec2 _a, vec2 _b) { return _a >= _b; } 500 | bvec3 greaterThanEqual(vec3 _a, vec3 _b) { return _a >= _b; } 501 | bvec4 greaterThanEqual(vec4 _a, vec4 _b) { return _a >= _b; } 502 | 503 | bvec2 notEqual(vec2 _a, vec2 _b) { return _a != _b; } 504 | bvec3 notEqual(vec3 _a, vec3 _b) { return _a != _b; } 505 | bvec4 notEqual(vec4 _a, vec4 _b) { return _a != _b; } 506 | 507 | bvec2 equal(vec2 _a, vec2 _b) { return _a == _b; } 508 | bvec3 equal(vec3 _a, vec3 _b) { return _a == _b; } 509 | bvec4 equal(vec4 _a, vec4 _b) { return _a == _b; } 510 | 511 | float mix(float _a, float _b, float _t) { return lerp(_a, _b, _t); } 512 | vec2 mix(vec2 _a, vec2 _b, vec2 _t) { return lerp(_a, _b, _t); } 513 | vec3 mix(vec3 _a, vec3 _b, vec3 _t) { return lerp(_a, _b, _t); } 514 | vec4 mix(vec4 _a, vec4 _b, vec4 _t) { return lerp(_a, _b, _t); } 515 | 516 | float mod(float _a, float _b) { return _a - _b * floor(_a / _b); } 517 | vec2 mod(vec2 _a, vec2 _b) { return _a - _b * floor(_a / _b); } 518 | vec3 mod(vec3 _a, vec3 _b) { return _a - _b * floor(_a / _b); } 519 | vec4 mod(vec4 _a, vec4 _b) { return _a - _b * floor(_a / _b); } 520 | 521 | #else 522 | # define CONST(_x) const _x 523 | # define atan2(_x, _y) atan(_x, _y) 524 | # define mul(_a, _b) ( (_a) * (_b) ) 525 | # define saturate(_x) clamp(_x, 0.0, 1.0) 526 | # define SAMPLER2D(_name, _reg) uniform sampler2D _name 527 | # define SAMPLER2DMS(_name, _reg) uniform sampler2DMS _name 528 | # define SAMPLER3D(_name, _reg) uniform sampler3D _name 529 | # define SAMPLERCUBE(_name, _reg) uniform samplerCube _name 530 | # define SAMPLER2DSHADOW(_name, _reg) uniform sampler2DShadow _name 531 | 532 | # define SAMPLER2DARRAY(_name, _reg) uniform sampler2DArray _name 533 | # define SAMPLER2DMSARRAY(_name, _reg) uniform sampler2DMSArray _name 534 | # define SAMPLERCUBEARRAY(_name, _reg) uniform samplerCubeArray _name 535 | # define SAMPLER2DARRAYSHADOW(_name, _reg) uniform sampler2DArrayShadow _name 536 | 537 | # define ISAMPLER2D(_name, _reg) uniform isampler2D _name 538 | # define USAMPLER2D(_name, _reg) uniform usampler2D _name 539 | # define ISAMPLER3D(_name, _reg) uniform isampler3D _name 540 | # define USAMPLER3D(_name, _reg) uniform usampler3D _name 541 | 542 | # if BGFX_SHADER_LANGUAGE_GLSL >= 130 543 | # define texture2D(_sampler, _coord) texture2D(_sampler, _coord) 544 | # define texture2DArray(_sampler, _coord) texture2D(_sampler, _coord) 545 | # define texture3D(_sampler, _coord) texture2D(_sampler, _coord) 546 | # endif // BGFX_SHADER_LANGUAGE_GLSL >= 130 547 | 548 | vec3 instMul(vec3 _vec, mat3 _mtx) { return mul(_vec, _mtx); } 549 | vec3 instMul(mat3 _mtx, vec3 _vec) { return mul(_mtx, _vec); } 550 | vec4 instMul(vec4 _vec, mat4 _mtx) { return mul(_vec, _mtx); } 551 | vec4 instMul(mat4 _mtx, vec4 _vec) { return mul(_mtx, _vec); } 552 | 553 | float rcp(float _a) { return 1.0/_a; } 554 | vec2 rcp(vec2 _a) { return vec2(1.0)/_a; } 555 | vec3 rcp(vec3 _a) { return vec3(1.0)/_a; } 556 | vec4 rcp(vec4 _a) { return vec4(1.0)/_a; } 557 | #endif // BGFX_SHADER_LANGUAGE_* 558 | 559 | vec2 vec2_splat(float _x) { return vec2(_x, _x); } 560 | vec3 vec3_splat(float _x) { return vec3(_x, _x, _x); } 561 | vec4 vec4_splat(float _x) { return vec4(_x, _x, _x, _x); } 562 | 563 | #if BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL 564 | uvec2 uvec2_splat(uint _x) { return uvec2(_x, _x); } 565 | uvec3 uvec3_splat(uint _x) { return uvec3(_x, _x, _x); } 566 | uvec4 uvec4_splat(uint _x) { return uvec4(_x, _x, _x, _x); } 567 | #endif // BGFX_SHADER_LANGUAGE_GLSL >= 130 || BGFX_SHADER_LANGUAGE_HLSL || BGFX_SHADER_LANGUAGE_PSSL || BGFX_SHADER_LANGUAGE_SPIRV || BGFX_SHADER_LANGUAGE_METAL 568 | 569 | mat4 mtxFromRows(vec4 _0, vec4 _1, vec4 _2, vec4 _3) 570 | { 571 | #if BGFX_SHADER_LANGUAGE_GLSL 572 | return transpose(mat4(_0, _1, _2, _3) ); 573 | #else 574 | return mat4(_0, _1, _2, _3); 575 | #endif // BGFX_SHADER_LANGUAGE_GLSL 576 | } 577 | 578 | mat4 mtxFromCols(vec4 _0, vec4 _1, vec4 _2, vec4 _3) 579 | { 580 | #if BGFX_SHADER_LANGUAGE_GLSL 581 | return mat4(_0, _1, _2, _3); 582 | #else 583 | return transpose(mat4(_0, _1, _2, _3) ); 584 | #endif // BGFX_SHADER_LANGUAGE_GLSL 585 | } 586 | #define u_alphaRef u_alphaRef4.x 587 | 588 | #endif // __cplusplus 589 | 590 | #endif // BGFX_SHADER_H_HEADER_GUARD 591 | --------------------------------------------------------------------------------