From 7f35b551770f47f5a95cb62f5937f4d2a4158b5f Mon Sep 17 00:00:00 2001 From: Wesselfr Date: Thu, 1 Jun 2023 15:21:45 +0200 Subject: [PATCH] Version 0.9.2 --- CMakeLists.txt | 2 +- README.md | 10 +- RT/Core/CMakeLists.txt | 1 + RT/Core/Common.c | 26 +++ RT/Core/Common.h | 3 + RT/Core/Config.cpp | 2 - RT/Core/String.h | 49 +++++ RT/RTgr.c | 52 ++--- RT/RTmaterials.c | 2 +- RT/Renderer/Backend/Common/include/Renderer.h | 1 + RT/Renderer/Backend/DX12/CMakeLists.txt | 1 + .../include_shared/shared_common.hlsl.h | 5 +- .../include_shared/shared_tweakvars.hlsl.h | 8 +- .../DX12/assets/shaders/post_process.hlsl | 4 + RT/Renderer/Backend/DX12/src/GLTFLoader.cpp | 2 - RT/Renderer/Backend/DX12/src/GPUProfiler.cpp | 25 +++ RT/Renderer/Backend/DX12/src/GlobalDX.h | 1 + .../Backend/DX12/src/RenderBackend.cpp | 200 ++++++++++++++++-- RT/Renderer/Backend/DX12/src/WinIncludes.h | 20 +- RT/material_viewer.cpp | 4 +- d1/arch/ogl/gr.c | 9 +- d1/arch/sdl/event.c | 16 ++ d1/arch/sdl/joy.c | 4 + d1/assets/textures/ceil019.material | 2 + d1/include/internal.h | 2 - d1/main/lighting.c | 11 +- 26 files changed, 383 insertions(+), 79 deletions(-) create mode 100644 RT/Core/Common.c create mode 100644 d1/assets/textures/ceil019.material diff --git a/CMakeLists.txt b/CMakeLists.txt index 97b7f30..2ad71bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ D1X_RAYTRACER_NAME="D1X_RAYTRACER" D1X_RAYTRACER_VERSION_MAJORi=0 D1X_RAYTRACER_VERSION_MINORi=9 -D1X_RAYTRACER_VERSION_MICROi=1 +D1X_RAYTRACER_VERSION_MICROi=2 #DXX-Retro last used version DXX_VERSION_MAJORi=0 diff --git a/README.md b/README.md index f351df0..41db30a 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,21 @@ -![scrn0003](https://github.com/BredaUniversityGames/DXX-Raytracer/assets/34250026/2acfa740-8f79-4e78-a977-02a4fc3d79b9) +![scrn0000](https://github.com/BredaUniversityGames/DXX-Raytracer-dev/assets/34250026/f15332ca-9a68-4ed9-ac61-6c82edde27a0) # DXX Raytracer -DXX Raytracer is a fork of the [DXX Retro](https://github.com/CDarrow/DXX-Retro) project for Windows. DXX Raytracer uses modern raytracing techniques to update the graphics of the beloved retro game known as Descent. +DXX Raytracer is a source port of the [DXX Retro](https://github.com/CDarrow/DXX-Retro) project for Windows. DXX Raytracer uses modern raytracing techniques to update the graphics of the beloved retro game known as Descent. This build of the game uses the shareware assets. If you have bought the original version of Descent 1995, you can replace the descent.pig and descent.hog files with your versions to play the whole game. ## Features +- Pathtracing - Physically-based rendering - Soft shadows -- Pathtraced global illumination +- Global illumination - Bloom - Temporal anti-aliasing - Motion blur - Post-processing (Vignette, tonemap, etc.) -## Community discord -You can join the community discord to make suggestions, report bugs, or just to hang around: https://discord.gg/vaEH5ryjvc - ## Instructions - SHIFT + ALT + F1: Open debug menus, more on those below - SHIFT + ALT + F2: Toggle depth testing for debug lines diff --git a/RT/Core/CMakeLists.txt b/RT/Core/CMakeLists.txt index 2cdc144..414aad0 100644 --- a/RT/Core/CMakeLists.txt +++ b/RT/Core/CMakeLists.txt @@ -13,6 +13,7 @@ add_library(RT_CORE INTERFACE target_sources(RT_CORE INTERFACE "${CMAKE_CURRENT_LIST_DIR}/Config.cpp" "${CMAKE_CURRENT_LIST_DIR}/Arena.c" +"${CMAKE_CURRENT_LIST_DIR}/Common.c" "${CMAKE_CURRENT_LIST_DIR}/String.c" "${CMAKE_CURRENT_LIST_DIR}/VirtualMemory.c" ) \ No newline at end of file diff --git a/RT/Core/Common.c b/RT/Core/Common.c new file mode 100644 index 0000000..8665847 --- /dev/null +++ b/RT/Core/Common.c @@ -0,0 +1,26 @@ +#include +#include +#include + +#pragma comment(lib, "shlwapi") + +#include "Core/Common.h" +#include "Core/Arena.h" +#include "Core/String.h" + +#define SUPPORT_STRING "For support, screenshot this message and visit the #support channel in our discord server:\n https://discord.gg/9dm93hKrnp\nOr create an issue on our GitHub:\nhttps://github.com/BredaUniversityGames/DXX-Raytracer" + +void RT_FATAL_ERROR_(const char *explanation, const char *title, const char *file, int line) +{ + char file_stripped[256]; + RT_SaneStrncpy(file_stripped, file, RT_ARRAY_COUNT(file_stripped)); + + PathStripPathA(file_stripped); + + char *message = RT_ArenaPrintF(&g_thread_arena, "Location:\n%s:%d\n\nExplanation:\n%s\n\n" SUPPORT_STRING, file_stripped, line, explanation); + MessageBoxA(NULL, message, title, MB_OK|MB_ICONERROR); + + __debugbreak(); // If you're using a debugger, now is your chance to debug. + + ExitProcess(1); // goodbye forever +} diff --git a/RT/Core/Common.h b/RT/Core/Common.h index 8d9c850..0dda3bf 100644 --- a/RT/Core/Common.h +++ b/RT/Core/Common.h @@ -7,6 +7,9 @@ #define RT_ASSERT(x) assert(x) #define RT_INVALID_DEFAULT_CASE default: { RT_ASSERT(!"Invalid default case!"); } break; +RT_API void RT_FATAL_ERROR_(const char *explanation, const char *title, const char *file, int line); +#define RT_FATAL_ERROR(explanation) RT_FATAL_ERROR_(explanation, "Fatal Error", __FILE__, __LINE__) + #define ALWAYS(x) (RT_ASSERT(x), x) #define NEVER(x) (RT_ASSERT(!(x)), x) diff --git a/RT/Core/Config.cpp b/RT/Core/Config.cpp index 2b71673..fc14a06 100644 --- a/RT/Core/Config.cpp +++ b/RT/Core/Config.cpp @@ -1,5 +1,3 @@ -#define _CRT_SECURE_NO_WARNINGS - #include #include #include diff --git a/RT/Core/String.h b/RT/Core/String.h index e9c0b53..0004ea5 100644 --- a/RT/Core/String.h +++ b/RT/Core/String.h @@ -19,6 +19,55 @@ // to print counted strings. #define RT_ExpandString(s) (int)(s).count, (s).bytes +// Just does what strncpy does but also null terminates the string if it doesn't fit in the destination buffer. +// BECAUSE THAT'S WHAT IT SHOULD DO. WHO WROTE STRNCPY. WHAT THE HECK. +static inline char *RT_SaneStrncpy(char *dst, const char *src, size_t count) +{ + if (count > 0) + { + size_t src_count = strlen(src); + size_t cpy_count = RT_MIN(src_count, count - 1); + + if (cpy_count > 0) + { + memcpy(dst, src, cpy_count); + } + + // always null terminate... + dst[cpy_count] = '\0'; + } + return dst; +} + +static inline char *RT_FormatHumanReadableBytes(RT_Arena *arena, size_t bytes) +{ + size_t log = 0; + for (size_t x = bytes / 1024; x > 0; x /= 1024) log += 1; + + char *string = NULL; + if (log == 0) + { + string = RT_ArenaPrintF(arena, "%zuB", bytes); + } + else if (log == 1) + { + string = RT_ArenaPrintF(arena, "%zuKiB", bytes / 1024); + } + else if (log == 2) + { + string = RT_ArenaPrintF(arena, "%zuMiB", bytes / 1024 / 1024); + } + else if (log == 3) + { + string = RT_ArenaPrintF(arena, "%zuGiB", bytes / 1024 / 1024 / 1024); + } + else if (log >= 4) + { + string = RT_ArenaPrintF(arena, "%zuTiB", bytes / 1024 / 1024 / 1024 / 1024); + } + return string; +} + static inline RT_String RT_StringFromCString(const char *c_string) { size_t count = 0; diff --git a/RT/RTgr.c b/RT/RTgr.c index 2669f94..906e831 100644 --- a/RT/RTgr.c +++ b/RT/RTgr.c @@ -263,34 +263,26 @@ void gr_palette_read(ubyte* pal) } } -float last_r = 0, last_g = 0, last_b = 0; -int do_pal_step = 0; -int ogl_brightness_ok = 0; -int ogl_brightness_r = 0, ogl_brightness_g = 0, ogl_brightness_b = 0; -static int old_b_r = 0, old_b_g = 0, old_b_b = 0; +int screen_flash_mul = 1; void gr_palette_step_up(int r, int g, int b) { - old_b_r = ogl_brightness_r; - old_b_g = ogl_brightness_g; - old_b_b = ogl_brightness_b; + RT_Vec4 screen_flash_color = { 0, 0, 0, 1 }; - ogl_brightness_r = max(r + gr_palette_gamma, 0); - ogl_brightness_g = max(g + gr_palette_gamma, 0); - ogl_brightness_b = max(b + gr_palette_gamma, 0); + r = r * screen_flash_mul; + g = g * screen_flash_mul; + b = b * screen_flash_mul; - if (!ogl_brightness_ok) - { - last_r = ogl_brightness_r / 63.0; - last_g = ogl_brightness_g / 63.0; - last_b = ogl_brightness_b / 63.0; + screen_flash_color.x = (float)max((r + gr_palette_gamma), 0); + screen_flash_color.y = (float)max((g + gr_palette_gamma), 0); + screen_flash_color.z = (float)max((b + gr_palette_gamma), 0); - do_pal_step = (r || g || b || gr_palette_gamma); - } - else - { - do_pal_step = 0; - } + screen_flash_color.x = screen_flash_color.x / 63.0f; + screen_flash_color.y = screen_flash_color.y / 63.0f; + screen_flash_color.z = screen_flash_color.z / 63.0f; + + RT_RendererIO* io = RT_GetRendererIO(); + io->screen_overlay_color = screen_flash_color; } void gr_flip(void) @@ -826,13 +818,15 @@ void RT_DrawPolyModel(const int meshnumber, const int objNum, ubyte object_type, assert(objNum > 0 || objNum < MAX_OBJECTS); + RT_ResourceHandle handle = mesh_handles[meshnumber]; + // Render mesh - RT_RaytraceMesh(mesh_handles[meshnumber], &mat, &old_poly_matrix[objNum]); + RT_RaytraceMesh(handle, &mat, &old_poly_matrix[objNum]); old_poly_matrix[objNum] = mat; } } -void RT_DrawSubPolyModel(const RT_ResourceHandle submodel, const RT_Mat4* const submodel_transform, const RT_Mat4* const submodel_transform_prev) +void RT_DrawSubPolyModel(RT_ResourceHandle submodel, const RT_Mat4* const submodel_transform, const RT_Mat4* const submodel_transform_prev) { if (RT_RESOURCE_HANDLE_VALID(submodel)) { @@ -1010,6 +1004,16 @@ void RT_StartImGuiFrame(void) igPopID(); igUnindent(0); } + if (igCollapsingHeader_TreeNodeFlags("Miscellaneous", ImGuiTreeNodeFlags_None)) + { + igPushID_Str("Miscellaneous"); + igIndent(0); + + igSliderInt("Flash screen multiplier", &screen_flash_mul, 1, 100, "%d", 0); + + igPopID(); + igUnindent(0); + } igUnindent(0); igPopID(); diff --git a/RT/RTmaterials.c b/RT/RTmaterials.c index eda5e60..3270371 100644 --- a/RT/RTmaterials.c +++ b/RT/RTmaterials.c @@ -185,7 +185,7 @@ void RT_InitAllBitmaps(void) // the indirection of the Textures / ObjBitmaps / ObjBitmapPtrs arrays. // - Daniel 01/03/2023 - for (uint16_t bm_index = 0; bm_index < MAX_BITMAP_FILES; bm_index++) + for (uint16_t bm_index = 1; bm_index < MAX_BITMAP_FILES; bm_index++) { grs_bitmap *bitmap = &GameBitmaps[bm_index]; diff --git a/RT/Renderer/Backend/Common/include/Renderer.h b/RT/Renderer/Backend/Common/include/Renderer.h index ef93bb9..825a99e 100644 --- a/RT/Renderer/Backend/Common/include/Renderer.h +++ b/RT/Renderer/Backend/Common/include/Renderer.h @@ -102,6 +102,7 @@ typedef struct RT_RendererIO // in: bool scene_transition; // set to true on a frame where there is a jumpcut or scene transition to avoid ghosting bool debug_line_depth_enabled; + RT_Vec4 screen_overlay_color; // in/out: int debug_render_mode; diff --git a/RT/Renderer/Backend/DX12/CMakeLists.txt b/RT/Renderer/Backend/DX12/CMakeLists.txt index 99b0150..8ac98d9 100644 --- a/RT/Renderer/Backend/DX12/CMakeLists.txt +++ b/RT/Renderer/Backend/DX12/CMakeLists.txt @@ -92,6 +92,7 @@ set_target_properties ( Renderer PROPERTIES set_property(TARGET Renderer PROPERTY CXX_STANDARD 17) add_compile_definitions(UNICODE=1) +add_compile_definitions(_CRT_SECURE_NO_WARNINGS) # microsoft is a menace target_include_directories(Renderer PUBLIC "include" diff --git a/RT/Renderer/Backend/DX12/assets/shaders/include_shared/shared_common.hlsl.h b/RT/Renderer/Backend/DX12/assets/shaders/include_shared/shared_common.hlsl.h index 676bc55..7441ba6 100644 --- a/RT/Renderer/Backend/DX12/assets/shaders/include_shared/shared_common.hlsl.h +++ b/RT/Renderer/Backend/DX12/assets/shaders/include_shared/shared_common.hlsl.h @@ -10,7 +10,7 @@ // ------------------------------------------------------------------ // Defines, constants, etc -#define RT_PIXEL_DEBUG 0 +#define RT_PIXEL_DEBUG 0 // TODO(daniel): Make this be dependent on the build configuration and make it stand out in the GPU profiler so you can tell it apart from actual work #define GROUP_X 16 #define GROUP_Y 16 #define BLUE_NOISE_TEX_COUNT 16 @@ -80,6 +80,9 @@ struct GlobalConstantBuffer uint debug_render_mode; uint lights_count; + // Color overlay for being shot at or picking up items. + float4 screen_color_overlay; + // Viewport offset, effectively offsets the center of the viewport after projecting float viewport_offset_y; float3 sky_color_top; diff --git a/RT/Renderer/Backend/DX12/assets/shaders/include_shared/shared_tweakvars.hlsl.h b/RT/Renderer/Backend/DX12/assets/shaders/include_shared/shared_tweakvars.hlsl.h index ffcb669..26a56a9 100644 --- a/RT/Renderer/Backend/DX12/assets/shaders/include_shared/shared_tweakvars.hlsl.h +++ b/RT/Renderer/Backend/DX12/assets/shaders/include_shared/shared_tweakvars.hlsl.h @@ -1,11 +1,9 @@ // ------------------------------------------------------------------------------------------------------------ // Tweak variables file. -// Each tweak variable declared is accessible in HLSL and C++ through the TweakVars struct, with sub-structs -// per category: -// +// Each tweak variable declared is accessible in HLSL and C++ through the TweakVars struct: // TweakVars vars; -// vars.pt.enable_pbr = false; -// vars.svgf.depth_sigma = 420; +// vars.enable_pbr = false; +// vars.svgf_depth_sigma = 420; // // The following are supported: // TWEAK_CATEGORY_BEGIN(name) // begin a category diff --git a/RT/Renderer/Backend/DX12/assets/shaders/post_process.hlsl b/RT/Renderer/Backend/DX12/assets/shaders/post_process.hlsl index f56ae61..8a3d163 100644 --- a/RT/Renderer/Backend/DX12/assets/shaders/post_process.hlsl +++ b/RT/Renderer/Backend/DX12/assets/shaders/post_process.hlsl @@ -236,5 +236,9 @@ void PostProcessCS(int2 co : SV_DispatchThreadID) } float3 final_color = lerp(color, debug_color, debug_blend_factor); + + //Adding the color overlay for picking stuff up/damaged to the final color. + final_color = final_color + g_global_cb.screen_color_overlay.xyz; + img_color[co] = float4(final_color, 1.0); } \ No newline at end of file diff --git a/RT/Renderer/Backend/DX12/src/GLTFLoader.cpp b/RT/Renderer/Backend/DX12/src/GLTFLoader.cpp index c4b8302..95ef85c 100644 --- a/RT/Renderer/Backend/DX12/src/GLTFLoader.cpp +++ b/RT/Renderer/Backend/DX12/src/GLTFLoader.cpp @@ -1,5 +1,3 @@ -#define _CRT_SECURE_NO_WARNINGS - #define CGLTF_IMPLEMENTATION #pragma warning(push, 0) #include "../CGLTF/cgltf.h" diff --git a/RT/Renderer/Backend/DX12/src/GPUProfiler.cpp b/RT/Renderer/Backend/DX12/src/GPUProfiler.cpp index 4cd6ca2..926639c 100644 --- a/RT/Renderer/Backend/DX12/src/GPUProfiler.cpp +++ b/RT/Renderer/Backend/DX12/src/GPUProfiler.cpp @@ -5,6 +5,8 @@ #include #include +#include "Core/String.h" + namespace RT { @@ -287,6 +289,29 @@ namespace RT ImGui::Unindent(8.0f); } + + ImGui::SetNextItemOpen(true, ImGuiCond_Once); + if (ImGui::CollapsingHeader("Memory Usage")) + { + ImGui::Indent(8.0f); + + DXGI_QUERY_VIDEO_MEMORY_INFO info; + if (SUCCEEDED(g_d3d.dxgi_adapter4->QueryVideoMemoryInfo(0, DXGI_MEMORY_SEGMENT_GROUP_LOCAL, &info))) + { + MemoryScope temp; + + ImGui::Text("Current Usage: %s", RT_FormatHumanReadableBytes(temp, info.CurrentUsage)); + ImGui::Text("Total Budget: %s", RT_FormatHumanReadableBytes(temp, info.Budget)); + ImGui::Text("Current Reservation: %s", RT_FormatHumanReadableBytes(temp, info.CurrentReservation)); + ImGui::Text("Available for Reservation: %s", RT_FormatHumanReadableBytes(temp, info.AvailableForReservation)); + } + else + { + ImGui::Text("Failed to query video memory info"); + } + + ImGui::Unindent(8.0f); + } } ImGui::End(); } diff --git a/RT/Renderer/Backend/DX12/src/GlobalDX.h b/RT/Renderer/Backend/DX12/src/GlobalDX.h index c882cb9..dc88026 100644 --- a/RT/Renderer/Backend/DX12/src/GlobalDX.h +++ b/RT/Renderer/Backend/DX12/src/GlobalDX.h @@ -276,6 +276,7 @@ namespace RT RT_ResourceHandle pink_checkerboard_texture; RT_ResourceHandle billboard_quad; + RT_ResourceHandle cube; RT_Arena *arena; diff --git a/RT/Renderer/Backend/DX12/src/RenderBackend.cpp b/RT/Renderer/Backend/DX12/src/RenderBackend.cpp index 7c7f715..f5186c7 100644 --- a/RT/Renderer/Backend/DX12/src/RenderBackend.cpp +++ b/RT/Renderer/Backend/DX12/src/RenderBackend.cpp @@ -211,8 +211,7 @@ namespace IDxcBlobEncoding *shader_text = nullptr; DeferRelease(shader_text); - hr = g_d3d.dxc_utils->LoadFile(file_name, &codepage, &shader_text); - RT_ASSERT(SUCCEEDED(hr)); + DX_CALL(g_d3d.dxc_utils->LoadFile(file_name, &codepage, &shader_text)); const wchar_t* arguments[] = { @@ -237,12 +236,11 @@ namespace dxc_defines[i].Value = (LPCWSTR)defines[i]; } - hr = g_d3d.dxc_compiler->Compile(shader_text, file_name, entry_point, target_profile, - arguments, RT_ARRAY_COUNT(arguments), - dxc_defines, num_defines, - g_d3d.dxc_include_handler, &result); + DX_CALL(g_d3d.dxc_compiler->Compile(shader_text, file_name, entry_point, target_profile, + arguments, RT_ARRAY_COUNT(arguments), + dxc_defines, num_defines, + g_d3d.dxc_include_handler, &result)); DeferRelease(result); - RT_ASSERT(SUCCEEDED(hr)); result->GetStatus(&hr); @@ -290,12 +288,11 @@ namespace ID3DBlob* serialized_root_sig; ID3DBlob* error; - HRESULT hr = D3D12SerializeVersionedRootSignature(&versioned_root_sig_desc, &serialized_root_sig, &error); - if (!SUCCEEDED(hr) || error) + DX_CALL(D3D12SerializeVersionedRootSignature(&versioned_root_sig_desc, &serialized_root_sig, &error)); + + if (error) { - OutputDebugStringA(static_cast(error->GetBufferPointer())); - SafeRelease(error); - RT_ASSERT(false); + RT_FATAL_ERROR((char*)error->GetBufferPointer()); } SafeRelease(error); @@ -374,7 +371,7 @@ namespace if (featureOptions.RaytracingTier < D3D12_RAYTRACING_TIER_1_0) { - RT_ASSERT(!"Raytracing is not supported by the hardware"); + RT_FATAL_ERROR("Raytracing is not supported on this system."); } #if defined(_DEBUG) @@ -1931,6 +1928,174 @@ void RenderBackend::Init(const RT_RendererInitParams* render_init_params) g_d3d.billboard_quad = UploadMesh(params); } + // ------------------------------------------------------------------ + // Create "missing model" cube + + { + RT_Vec3 positions[] = { + // Front face + { -0.5, -0.5, 0.5, }, // Vertex 0 + { 0.5, -0.5, 0.5, }, // Vertex 1 + { 0.5, 0.5, 0.5, }, // Vertex 2 + { -0.5, 0.5, 0.5, }, // Vertex 3 + + // Back face + { -0.5, -0.5, -0.5, }, // Vertex 4 + { 0.5, -0.5, -0.5, }, // Vertex 5 + { 0.5, 0.5, -0.5, }, // Vertex 6 + { -0.5, 0.5, -0.5, }, // Vertex 7 + + // Left face + { -0.5, -0.5, -0.5, }, // Vertex 8 + { -0.5, -0.5, 0.5, }, // Vertex 9 + { -0.5, 0.5, 0.5, }, // Vertex 10 + { -0.5, 0.5, -0.5, }, // Vertex 11 + + // Right face + { 0.5, -0.5, -0.5, }, // Vertex 12 + { 0.5, -0.5, 0.5, }, // Vertex 13 + { 0.5, 0.5, 0.5, }, // Vertex 14 + { 0.5, 0.5, -0.5, }, // Vertex 15 + + // Top face + { -0.5, 0.5, 0.5, }, // Vertex 16 + { 0.5, 0.5, 0.5, }, // Vertex 17 + { 0.5, 0.5, -0.5, }, // Vertex 18 + { -0.5, 0.5, -0.5, }, // Vertex 19 + + // Bottom face + { -0.5, -0.5, 0.5, }, // Vertex 20 + { 0.5, -0.5, 0.5, }, // Vertex 21 + { 0.5, -0.5, -0.5, }, // Vertex 22 + { -0.5, -0.5, -0.5, }, // Vertex 23 + }; + + RT_Vec3 normals[] = { + // Front face + { 0.0, 0.0, 1.0, }, // Vertex 0 + { 0.0, 0.0, 1.0, }, // Vertex 1 + { 0.0, 0.0, 1.0, }, // Vertex 2 + { 0.0, 0.0, 1.0, }, // Vertex 3 + + // Back face + { 0.0, 0.0, -1.0, }, // Vertex 4 + { 0.0, 0.0, -1.0, }, // Vertex 5 + { 0.0, 0.0, -1.0, }, // Vertex 6 + { 0.0, 0.0, -1.0, }, // Vertex 7 + + // Left face + { -1.0, 0.0, 0.0, }, // Vertex 8 + { -1.0, 0.0, 0.0, }, // Vertex 9 + { -1.0, 0.0, 0.0, }, // Vertex 10 + { -1.0, 0.0, 0.0, }, // Vertex 11 + + // Right face + { 1.0, 0.0, 0.0, }, // Vertex 12 + { 1.0, 0.0, 0.0, }, // Vertex 13 + { 1.0, 0.0, 0.0, }, // Vertex 14 + { 1.0, 0.0, 0.0, }, // Vertex 15 + + // Top face + { 0.0, 1.0, 0.0, }, // Vertex 16 + { 0.0, 1.0, 0.0, }, // Vertex 17 + { 0.0, 1.0, 0.0, }, // Vertex 18 + { 0.0, 1.0, 0.0, }, // Vertex 19 + + // Bottom face + { 0.0, -1.0, 0.0, }, // Vertex 20 + { 0.0, -1.0, 0.0, }, // Vertex 21 + { 0.0, -1.0, 0.0, }, // Vertex 22 + { 0.0, -1.0, 0.0, }, // Vertex 23 + }; + + RT_Vec2 uvs[] = { + // Front face + { 0.0, 0.0, }, // Vertex 0 + { 1.0, 0.0, }, // Vertex 1 + { 1.0, 1.0, }, // Vertex 2 + { 0.0, 1.0, }, // Vertex 3 + + // Back face + { 1.0, 0.0, }, // Vertex 4 + { 0.0, 0.0, }, // Vertex 5 + { 0.0, 1.0, }, // Vertex 6 + { 1.0, 1.0, }, // Vertex 7 + + // Left face + { 0.0, 0.0, }, // Vertex 8 + { 1.0, 0.0, }, // Vertex 9 + { 1.0, 1.0, }, // Vertex 10 + { 0.0, 1.0, }, // Vertex 11 + + // Right face + { 1.0, 0.0, }, // Vertex 12 + { 0.0, 0.0, }, // Vertex 13 + { 0.0, 1.0, }, // Vertex 14 + { 1.0, 1.0, }, // Vertex 15 + + // Top face + { 0.0, 1.0, }, // Vertex 16 + { 1.0, 1.0, }, // Vertex 17 + { 1.0, 0.0, }, // Vertex 18 + { 0.0, 0.0, }, // Vertex 19 + + // Bottom face + { 1.0, 1.0, }, // Vertex 20 + { 0.0, 1.0, }, // Vertex 21 + { 0.0, 0.0, }, // Vertex 22 + { 1.0, 0.0, }, // Vertex 23 + }; + + RT_Triangle triangles[12] = {}; + for (size_t face_index = 0; face_index < RT_ARRAY_COUNT(triangles) / 2; face_index += 2) + { + size_t i = 4*face_index; + + RT_Triangle *t0 = &triangles[face_index + 0]; + RT_Triangle *t1 = &triangles[face_index + 1]; + + t0->pos0 = positions[i + 0]; + t0->pos1 = positions[i + 1]; + t0->pos2 = positions[i + 2]; + + t1->pos0 = positions[i + 0]; + t1->pos1 = positions[i + 2]; + t1->pos2 = positions[i + 3]; + + t0->normal0 = normals[i + 0]; + t0->normal1 = normals[i + 1]; + t0->normal2 = normals[i + 2]; + + t1->normal0 = normals[i + 0]; + t1->normal1 = normals[i + 2]; + t1->normal2 = normals[i + 3]; + + t0->uv0 = uvs[i + 0]; + t0->uv1 = uvs[i + 1]; + t0->uv2 = uvs[i + 2]; + + t1->uv0 = uvs[i + 0]; + t1->uv1 = uvs[i + 2]; + t1->uv2 = uvs[i + 3]; + + t0->color = RT_PackRGBA(RT_Vec4Make(1, 1, 1, 1)); + t1->color = RT_PackRGBA(RT_Vec4Make(1, 1, 1, 1)); + + // 0 should be an unused, pink checkerboard material + t0->material_edge_index = RT_TRIANGLE_MATERIAL_INSTANCE_OVERRIDE; + t1->material_edge_index = RT_TRIANGLE_MATERIAL_INSTANCE_OVERRIDE; + } + + RT_GenerateTangents(triangles, RT_ARRAY_COUNT(triangles)); + + RT_UploadMeshParams params = {}; + params.name = "Cube"; + params.triangles = triangles; + params.triangle_count = RT_ARRAY_COUNT(triangles); + + g_d3d.cube = UploadMesh(params); + } + InitDearImGui(); } @@ -2230,6 +2395,7 @@ void RenderBackend::EndScene() scene_cb->debug_flags = debug_flags; scene_cb->lights_count = g_d3d.lights_count; scene_cb->viewport_offset_y = g_d3d.viewport_offset_y; + scene_cb->screen_color_overlay = g_d3d.io.screen_overlay_color; D3D12_CPU_DESCRIPTOR_HANDLE cbv = frame->descriptors.GetCPUDescriptor(D3D12GlobalDescriptors_CBV_GlobalConstantBuffer); @@ -2242,9 +2408,7 @@ void RenderBackend::EndScene() { TweakVars* frame_tweakvars = frame->tweak_vars.As(); memcpy(frame_tweakvars, &tweak_vars, sizeof(TweakVars)); - D3D12_CPU_DESCRIPTOR_HANDLE cbv = frame->descriptors.GetCPUDescriptor(D3D12GlobalDescriptors_CBV_TweakVars); - D3D12_CONSTANT_BUFFER_VIEW_DESC cbv_desc = {}; cbv_desc.BufferLocation = frame->tweak_vars.gpu; cbv_desc.SizeInBytes = (UINT)frame->tweak_vars.size; @@ -2609,7 +2773,11 @@ void RenderBackend::RaytraceMesh(const RT_RenderMeshParams& render_mesh_params) { FrameData *frame = CurrentFrameData(); MeshResource* mesh_resource = g_mesh_slotmap.Find(render_mesh_params.mesh_handle); - RT_ASSERT(mesh_resource); + + if (!mesh_resource) + { + mesh_resource = g_mesh_slotmap.Find(g_d3d.cube); + } // ------------------------------------------------------------------ // Add mesh to hitgroup shader table diff --git a/RT/Renderer/Backend/DX12/src/WinIncludes.h b/RT/Renderer/Backend/DX12/src/WinIncludes.h index 020319b..7304e57 100644 --- a/RT/Renderer/Backend/DX12/src/WinIncludes.h +++ b/RT/Renderer/Backend/DX12/src/WinIncludes.h @@ -41,25 +41,23 @@ using namespace Microsoft::WRL; #include #include "Core/Common.h" +#include "Core/Arena.h" -inline void ExplainHRESULT(HRESULT hr) +inline void ExplainHRESULT(HRESULT hr, char *title, char *file, int line) { - wchar_t *message = nullptr; + char *message = nullptr; - FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER| + FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER| FORMAT_MESSAGE_FROM_SYSTEM| FORMAT_MESSAGE_IGNORE_INSERTS, NULL, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (wchar_t *)&message, + (char *)&message, 0, NULL); - OutputDebugStringW(L"HRESULT FAILED:\n"); - OutputDebugStringW(message); - OutputDebugStringW(L"\n"); - - LocalFree(message); + char *formatted = RT_ArenaPrintF(&g_thread_arena, "\nError code: 0x%X\n\n%s", (uint32_t)hr, message); + RT_FATAL_ERROR_(formatted, title, file, line); } #define DX_CALL(hr_) \ @@ -67,9 +65,7 @@ inline void ExplainHRESULT(HRESULT hr) HRESULT dx_call_hr = hr_; \ if (FAILED(dx_call_hr)) \ { \ - OutputDebugStringA("DX_CALL failed at " __FILE__ ":" RT_STRINGIFY(__LINE__) "\n"); \ - ExplainHRESULT(dx_call_hr); \ - RT_ASSERT(!"HRESULT FAILED"); \ + ExplainHRESULT(dx_call_hr, "Fatal DirectX Error", __FILE__, __LINE__); \ } \ } \ while (false) diff --git a/RT/material_viewer.cpp b/RT/material_viewer.cpp index 6b6558b..46f9b58 100644 --- a/RT/material_viewer.cpp +++ b/RT/material_viewer.cpp @@ -484,7 +484,7 @@ void RT_DoMaterialViewerMenus() } } - if (ImGui::Begin("Material Editor", nullptr, ImGuiWindowFlags_MenuBar)) + if (ImGui::Begin("Material Editor", nullptr, ImGuiWindowFlags_MenuBar|ImGuiWindowFlags_AlwaysVerticalScrollbar)) { if (ImGui::BeginMenuBar()) { @@ -585,7 +585,7 @@ void RT_DoMaterialViewerMenus() bool first_drawn_texture = true; - for (uint16_t bm_index = 1; bm_index < MAX_BITMAP_FILES; bm_index++) + for (uint16_t bm_index = 0; bm_index < MAX_BITMAP_FILES; bm_index++) { grs_bitmap *bitmap = &GameBitmaps[bm_index]; diff --git a/d1/arch/ogl/gr.c b/d1/arch/ogl/gr.c index be3191f..522b176 100644 --- a/d1/arch/ogl/gr.c +++ b/d1/arch/ogl/gr.c @@ -784,6 +784,11 @@ int gr_init(int mode) return 0; } +//NOTE (sam) +//I moved this code here to remove some very unneeded externals in internal.h no reason for them to be there. +int ogl_brightness_ok = 0; +int ogl_brightness_r = 0, ogl_brightness_g = 0, ogl_brightness_b = 0; +static int old_b_r = 0, old_b_g = 0, old_b_b = 0; void gr_close() { ogl_brightness_r = ogl_brightness_g = ogl_brightness_b = 0; @@ -956,10 +961,6 @@ void ogl_do_palfx(void) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } -int ogl_brightness_ok = 0; -int ogl_brightness_r = 0, ogl_brightness_g = 0, ogl_brightness_b = 0; -static int old_b_r = 0, old_b_g = 0, old_b_b = 0; - void gr_palette_step_up(int r, int g, int b) { old_b_r = ogl_brightness_r; diff --git a/d1/arch/sdl/event.c b/d1/arch/sdl/event.c index a27ce2f..14d56f2 100644 --- a/d1/arch/sdl/event.c +++ b/d1/arch/sdl/event.c @@ -242,6 +242,22 @@ void RT_Event_Poll(ImGuiIO* io, SDL_Event* ev, int* clean_uniframe, int* idle) ImGuiIO_AddFocusEvent(io, false); } break; + case SDL_JOYBUTTONDOWN: + case SDL_JOYBUTTONUP: + joy_button_handler((SDL_JoyButtonEvent*)&event); + idle = 0; + break; + case SDL_JOYAXISMOTION: + if (joy_axis_handler((SDL_JoyAxisEvent*)&event)) + idle = 0; + break; + case SDL_JOYHATMOTION: + joy_hat_handler((SDL_JoyHatEvent*)&event); + idle = 0; + break; + case SDL_JOYBALLMOTION: + break; + case SDL_QUIT: { d_event qevent = { EVENT_QUIT }; call_default_handler(&qevent); diff --git a/d1/arch/sdl/joy.c b/d1/arch/sdl/joy.c index 4713380..427c52c 100644 --- a/d1/arch/sdl/joy.c +++ b/d1/arch/sdl/joy.c @@ -69,7 +69,9 @@ void joy_button_handler(SDL_JoyButtonEvent *jbe) event.type = (jbe->type == SDL_JOYBUTTONDOWN) ? EVENT_JOYSTICK_BUTTON_DOWN : EVENT_JOYSTICK_BUTTON_UP; event.button = button; +#if 0 RT_LOGF(RT_LOGSERVERITY_INFO, "Sending event %s, button %d\n", (jbe->type == SDL_JOYBUTTONDOWN) ? "EVENT_JOYSTICK_BUTTON_DOWN" : "EVENT_JOYSTICK_JOYSTICK_UP", event.button); +#endif event_send((d_event *)&event); } @@ -125,7 +127,9 @@ int joy_axis_handler(SDL_JoyAxisEvent *jae) event.type = EVENT_JOYSTICK_MOVED; event.axis = axis; event.value = Joystick.axis_value[axis] = jae->value/256; +#if 0 RT_LOGF(RT_LOGSERVERITY_INFO, "Sending event EVENT_JOYSTICK_MOVED, axis: %d, value: %d\n", event.axis, event.value); +#endif event_send((d_event *)&event); return 1; diff --git a/d1/assets/textures/ceil019.material b/d1/assets/textures/ceil019.material new file mode 100644 index 0000000..196bb60 --- /dev/null +++ b/d1/assets/textures/ceil019.material @@ -0,0 +1,2 @@ +roughness = 0.548000 +metalness = 1.000000 diff --git a/d1/include/internal.h b/d1/include/internal.h index 85c6217..b08950a 100644 --- a/d1/include/internal.h +++ b/d1/include/internal.h @@ -14,8 +14,6 @@ void ogl_init_texture_list_internal(void); void ogl_smash_texture_list_internal(void); void ogl_vivify_texture_list_internal(void); -extern int ogl_brightness_ok; -extern int ogl_brightness_r, ogl_brightness_g, ogl_brightness_b; extern int ogl_fullscreen; extern int GL_TEXTURE_2D_enabled; diff --git a/d1/main/lighting.c b/d1/main/lighting.c index 1bbeb1f..9cfa279 100644 --- a/d1/main/lighting.c +++ b/d1/main/lighting.c @@ -220,7 +220,11 @@ void apply_light(g3s_lrgb obj_light_emission, int obj_seg, vms_vector *obj_pos, #define FLASH_SCALE (3*F1_0/FLASH_LEN_FIXED_SECONDS) // ---------------------------------------------------------------------------------------------- +#ifndef RT_DX12 void cast_muzzle_flash_light(int n_render_vertices, int *render_vertices, int *vert_segnum_list) +#else +void cast_muzzle_flash_light() +#endif { fix64 current_time; int i; @@ -528,7 +532,6 @@ g3s_lrgb compute_light_emission(int objnum) RT_RaytraceSubmitLight(flare); } #endif - return lemission; } @@ -549,6 +552,7 @@ void set_dynamic_light(void) if (!Do_dynamic_light) return; +#ifndef RT_DX12 light_time += FrameTime; if (light_time < (F1_0/60)) // it's enough to stress the CPU 60 times per second return; @@ -587,6 +591,9 @@ void set_dynamic_light(void) } cast_muzzle_flash_light(n_render_vertices, render_vertices, vert_segnum_list); +#else + cast_muzzle_flash_light(); +#endif for (objnum=0; objnum<=Highest_object_index; objnum++) { @@ -596,8 +603,10 @@ void set_dynamic_light(void) obj_light_emission = compute_light_emission(objnum); +#ifndef RT_DX12 if (((obj_light_emission.r+obj_light_emission.g+obj_light_emission.b)/3) > 0) apply_light(obj_light_emission, obj->segnum, objpos, n_render_vertices, render_vertices, vert_segnum_list, objnum); +#endif } }