Skip to content

Commit

Permalink
Merge pull request #16 from JuanDiegoMontoya/tray-racing
Browse files Browse the repository at this point in the history
Ray tracing
  • Loading branch information
JuanDiegoMontoya authored Nov 5, 2024
2 parents 0b1951a + 4db9580 commit be82e48
Show file tree
Hide file tree
Showing 85 changed files with 5,556 additions and 1,866 deletions.
18 changes: 9 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(Frogfood)

set(CMAKE_CXX_STANDARD 20)

option(FROGRENDER_FSR2_ENABLE "Enable FSR2 for examples that support it (currently 03_gltf_viewer). Windows only!" FALSE)
option(FROGRENDER_FSR2_ENABLE "Enable FidelityFX Super Resolution 2. Windows only!" FALSE)

find_package(Vulkan REQUIRED)

Expand Down Expand Up @@ -50,8 +50,6 @@ add_executable(frogRender
src/Fvog/detail/SamplerCache2.h
src/Fvog/detail/SamplerCache2.cpp
src/Fvog/detail/Hash2.h
src/Pipelines2.h
src/Pipelines2.cpp
src/Fvog/TriviallyCopyableByteSpan.h
src/ImGui/imgui_impl_fvog.cpp
src/ImGui/imgui_impl_fvog.h
Expand All @@ -60,6 +58,14 @@ add_executable(frogRender
src/Scene.h
src/Scene.cpp
src/Renderables.h
src/Fvog/AccelerationStructure.h
src/Fvog/AccelerationStructure.cpp
src/debug/ForwardRenderer.h
src/debug/ForwardRenderer.cpp
src/techniques/ao/RayTracedAO.h
src/techniques/ao/RayTracedAO.cpp
src/PipelineManager.h
src/PipelineManager.cpp
)

target_compile_options(frogRender
Expand Down Expand Up @@ -90,11 +96,6 @@ endif()

add_subdirectory(external)

add_custom_target(copy_shaders ALL COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/data/shaders ${CMAKE_CURRENT_BINARY_DIR}/shaders)
add_custom_target(copy_models ALL COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/data/models ${CMAKE_CURRENT_BINARY_DIR}/models)
add_custom_target(copy_textures ALL COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/data/textures ${CMAKE_CURRENT_BINARY_DIR}/textures)
add_custom_target(copy_config ALL COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/data/config ${CMAKE_CURRENT_BINARY_DIR}/config)

if (FROGRENDER_FSR2_ENABLE)
set(FSR2_LIBS ffx_fsr2_api_x64 ffx_fsr2_api_vk_x64)
target_compile_definitions(frogRender PUBLIC FROGRENDER_FSR2_ENABLE)
Expand Down Expand Up @@ -134,7 +135,6 @@ target_link_libraries(frogRender
glslang-default-resource-limits
SPIRV
)
add_dependencies(frogRender copy_shaders copy_models copy_textures copy_config)

target_compile_definitions(glm INTERFACE GLM_FORCE_DEPTH_ZERO_TO_ONE VK_NO_PROTOTYPES GLFW_INCLUDE_NONE ImTextureID=ImU64)

Expand Down
10 changes: 10 additions & 0 deletions CMakeSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
"name": "FROGRENDER_FSR2_ENABLE",
"value": "True",
"type": "BOOL"
},
{
"name": "TRACY_ENABLE",
"value": "True",
"type": "BOOL"
}
]
},
Expand All @@ -51,6 +56,11 @@
"name": "FROGRENDER_FSR2_ENABLE",
"value": "True",
"type": "BOOL"
},
{
"name": "TRACY_ENABLE",
"value": "False",
"type": "BOOL"
}
]
}
Expand Down
47 changes: 37 additions & 10 deletions data/config/defaultLayout.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ DockId=0x00000004,0

[Window][glTF Viewer]
Pos=1572,24
Size=348,355
Size=348,366
Collapsed=0
DockId=0x00000007,0
DockId=0x00000013,0

[Window][###viewport_window]
Pos=337,24
Size=1233,758
Size=1233,764
Collapsed=0
DockId=0x0000000F,0
DockId=0x00000011,0

[Window][###mag]
Pos=0,703
Expand Down Expand Up @@ -70,9 +70,9 @@ DockId=0x00000009,0

[Window][Dear ImGui Demo]
Pos=337,24
Size=1233,758
Size=1233,764
Collapsed=0
DockId=0x0000000F,1
DockId=0x00000011,1

[Window][ Shadow]
Pos=1572,381
Expand All @@ -90,7 +90,7 @@ DockId=0x0000000E,0
Pos=0,24
Size=335,271
Collapsed=0
DockId=0x0000000D,1
DockId=0x0000000D,2

[Window][Perf##perf_window]
Pos=337,784
Expand Down Expand Up @@ -125,7 +125,30 @@ DockId=0x0000000E,0
Pos=0,24
Size=335,271
Collapsed=0
DockId=0x0000000D,2
DockId=0x0000000D,3

[Window][###shadow_window]
Pos=1572,392
Size=348,371
Collapsed=0
DockId=0x00000014,0

[Window][Performance##perf_window]
Pos=337,790
Size=1233,290
Collapsed=0
DockId=0x00000012,0

[Window][###geometry_inspector]
Pos=60,60
Size=177,150
Collapsed=0

[Window][Ambient Occlusion]
Pos=1572,392
Size=348,371
Collapsed=0
DockId=0x00000014,1

[Docking][Data]
DockSpace ID=0x4BBE4C7A Window=0x4647B76E Pos=0,24 Size=1920,1056 Split=X Selected=0xE87781F4
Expand All @@ -136,11 +159,15 @@ DockSpace ID=0x4BBE4C7A Window=0x4647B76E Pos=0,24 Size=1920,1056 Spli
DockNode ID=0x0000000C Parent=0x00000005 SizeRef=213,377 Selected=0x213C89B5
DockNode ID=0x00000006 Parent=0x4BBE4C7A SizeRef=1583,1056 Split=X
DockNode ID=0x00000001 Parent=0x00000006 SizeRef=1233,1056 Split=Y Selected=0x91EB2F4F
DockNode ID=0x0000000F Parent=0x00000001 SizeRef=1233,758 CentralNode=1 Selected=0x91EB2F4F
DockNode ID=0x0000000F Parent=0x00000001 SizeRef=1233,758 Split=Y Selected=0x91EB2F4F
DockNode ID=0x00000011 Parent=0x0000000F SizeRef=1233,764 CentralNode=1 Selected=0x91EB2F4F
DockNode ID=0x00000012 Parent=0x0000000F SizeRef=1233,290 Selected=0xED41464D
DockNode ID=0x00000010 Parent=0x00000001 SizeRef=1233,296 Selected=0xE030F72F
DockNode ID=0x00000002 Parent=0x00000006 SizeRef=348,1056 Split=Y Selected=0xFCCC74B6
DockNode ID=0x00000003 Parent=0x00000002 SizeRef=348,739 Split=Y Selected=0xFCCC74B6
DockNode ID=0x00000007 Parent=0x00000003 SizeRef=348,355 Selected=0xBE92E3B2
DockNode ID=0x00000007 Parent=0x00000003 SizeRef=348,355 Split=Y Selected=0xBE92E3B2
DockNode ID=0x00000013 Parent=0x00000007 SizeRef=348,366 Selected=0xBE92E3B2
DockNode ID=0x00000014 Parent=0x00000007 SizeRef=348,371 Selected=0x4D526E22
DockNode ID=0x00000008 Parent=0x00000003 SizeRef=348,382 Split=Y Selected=0xFCCC74B6
DockNode ID=0x00000009 Parent=0x00000008 SizeRef=348,178 Selected=0x4F8C3FAB
DockNode ID=0x0000000A Parent=0x00000008 SizeRef=348,202 Selected=0x21E9B10B
Expand Down
4 changes: 1 addition & 3 deletions data/shaders/CalibrateHdr.comp.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ FVOG_DECLARE_ARGUMENTS(CalibrateHdrArguments)
};

#ifndef __cplusplus
FVOG_DECLARE_STORAGE_IMAGES(image2D);

void main()
{
const ivec2 gid = ivec2(gl_GlobalInvocationID.xy);
Expand All @@ -35,4 +33,4 @@ void main()

imageStore(Fvog_image2D(outputImageIndex), gid, vec4(color, 1.0));
}
#endif
#endif
66 changes: 66 additions & 0 deletions data/shaders/Math.h.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@
// Constants
const float M_PI = 3.141592654;


// Functions
vec3 PolarToCartesian(float phi, float theta)
{
const float sinTheta = sin(theta);
return vec3(
cos(phi) * sinTheta,
sin(phi) * sinTheta,
cos(theta)
);
}

// PDF: solid_angle_mapping_PDF (see bottom of this file)
vec3 RandVecInCone(vec2 xi, vec3 N, float angle)
{
float phi = 2.0 * M_PI * xi.x;
Expand Down Expand Up @@ -114,4 +126,58 @@ vec3 TurboColormap(float x)
);
}

bool isfinite(float x)
{
return !isnan(x) && !isinf(x);
}

bvec2 isfinite(vec2 x)
{
return bvec2(isfinite(x.x), isfinite(x.y));
}

bvec3 isfinite(vec3 x)
{
return bvec3(isfinite(x.x), isfinite(x.y), isfinite(x.z));
}

bvec4 isfinite(vec4 x)
{
return bvec4(isfinite(x.x), isfinite(x.y), isfinite(x.z), isfinite(x.w));
}

// Stolen from void
vec3 map_to_unit_sphere(vec2 uv)
{
float cos_theta = 2.0 * uv.x - 1.0;
float phi = 2.0 * M_PI * uv.y;
float sin_theta = sqrt(1.0 - cos_theta * cos_theta);
float sin_phi = sin(phi);
float cos_phi = cos(phi);

return vec3(sin_theta * cos_phi, cos_theta, sin_theta * sin_phi);
}

vec3 map_to_unit_hemisphere_cosine_weighted(vec2 uv, vec3 n)
{
vec3 p = map_to_unit_sphere(uv);
return n + p;
}

// From void
float solid_angle_mapping_PDF(float theta_max)
{
return 1.0 / (2.0 * M_PI * (1.0 - cos(theta_max)));
}

float uniform_hemisphere_PDF()
{
return 1.0 / (2.0 * M_PI);
}

float cosine_weighted_hemisphere_PDF(float cosTheta)
{
return cosTheta / M_PI;
}

#endif // MATH_H
11 changes: 6 additions & 5 deletions data/shaders/Pbr.h.glsl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef PBR_H
#define PBR_H

#include "Math.h.glsl"
#include "Color.h.glsl"
#include "ShadeDeferredPbr.h.glsl"

Expand Down Expand Up @@ -34,11 +35,11 @@ float D_GGX(float NoH, float roughness)
//roughness = max(roughness, 1e-3);

// Hack to prevent zero in the denominator
NoH = min(NoH, 0.9999);
//NoH = min(NoH, 0.9999);

float a = NoH * roughness;
float k = roughness / (1.0 - NoH * NoH + a * a);
return k * k * (1.0 / 3.1415926);
float k = roughness / clamp(1.0 - NoH * NoH + a * a, 0.0001, 0.9999);
return k * k * (1.0 / M_PI);
}

// Visibility (geometric shadowing and masking)
Expand All @@ -65,7 +66,7 @@ vec3 F_Schlick3(float u, vec3 f0, float f90)
// Lambertian diffuse BRDF
float Fd_Lambert()
{
return 1.0 / 3.1415926;
return 1.0 / M_PI;
}

// Disney diffuse BRDF. Apparently not energy-conserving, but takes into account surface roughness, unlike Lambert's
Expand All @@ -74,7 +75,7 @@ float Fd_Burley(float NoV, float NoL, float LoH, float roughness)
float f90 = 0.5 + 2.0 * roughness * LoH * LoH;
float lightScatter = F_Schlick1(NoL, 1.0, f90);
float viewScatter = F_Schlick1(NoV, 1.0, f90);
return lightScatter * viewScatter * (1.0 / 3.1415926);
return lightScatter * viewScatter * (1.0 / M_PI);
}

struct Surface
Expand Down
Loading

0 comments on commit be82e48

Please sign in to comment.