Skip to content

Commit

Permalink
Version 0.9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
wesselfr committed Jun 1, 2023
1 parent 7c81f80 commit 7f35b55
Show file tree
Hide file tree
Showing 26 changed files with 383 additions and 79 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions RT/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
26 changes: 26 additions & 0 deletions RT/Core/Common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <Windows.h>
#include <wchar.h>
#include <Shlwapi.h>

#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
}
3 changes: 3 additions & 0 deletions RT/Core/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 0 additions & 2 deletions RT/Core/Config.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <ctype.h>
Expand Down
49 changes: 49 additions & 0 deletions RT/Core/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
52 changes: 28 additions & 24 deletions RT/RTgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion RT/RTmaterials.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
1 change: 1 addition & 0 deletions RT/Renderer/Backend/Common/include/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions RT/Renderer/Backend/DX12/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions RT/Renderer/Backend/DX12/assets/shaders/post_process.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 0 additions & 2 deletions RT/Renderer/Backend/DX12/src/GLTFLoader.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#define _CRT_SECURE_NO_WARNINGS

#define CGLTF_IMPLEMENTATION
#pragma warning(push, 0)
#include "../CGLTF/cgltf.h"
Expand Down
25 changes: 25 additions & 0 deletions RT/Renderer/Backend/DX12/src/GPUProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <implot.h>
#include <implot_internal.h>

#include "Core/String.h"

namespace RT
{

Expand Down Expand Up @@ -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();
}

Expand Down
1 change: 1 addition & 0 deletions RT/Renderer/Backend/DX12/src/GlobalDX.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ namespace RT
RT_ResourceHandle pink_checkerboard_texture;

RT_ResourceHandle billboard_quad;
RT_ResourceHandle cube;

RT_Arena *arena;

Expand Down
Loading

0 comments on commit 7f35b55

Please sign in to comment.