Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3719b93
Debug renderer WIP1.
Williscool13 Apr 27, 2025
1b70045
Debug renderer draw cube implemented and functional.
Williscool13 Apr 27, 2025
9ff7a0c
Sphere Debug Rendering.
Williscool13 Apr 28, 2025
242057e
Wrap debug rendering in macros.
Williscool13 Apr 28, 2025
38ae892
Static debug rendering functions.
Williscool13 Apr 28, 2025
80dc98e
Dynamically resizing instance buffer for Instanced Debug Rendering.
Williscool13 Apr 28, 2025
da958e0
Line Debug Rendering
Williscool13 Apr 29, 2025
925c21e
Slight optimizations to debug renderer, updated visualization.
Williscool13 Apr 29, 2025
0e5ca8c
New monitor hard-coded resolution. Implemented line drawing for jolt …
Williscool13 Apr 30, 2025
5f50d35
Triangle debug rendering.
Williscool13 May 2, 2025
446c5a6
Fully implemented (Slow) physics debug rendering.
Williscool13 May 2, 2025
24b8d91
Fix compile issue for release builds (disable physics draw in release).
Williscool13 May 2, 2025
dd087b8
Composite debug draws with final image to skip TAA, tone-mapping, and…
Williscool13 May 2, 2025
247f899
Pack normals to allow use of UNORM formats.
Williscool13 May 3, 2025
f3a254c
Jitter and Unjitter debug draws for consistency with depth buffer. Me…
Williscool13 May 4, 2025
93d44e3
Mesh highlight WIP2. Refactor name of resource destroyers.
Williscool13 May 4, 2025
ac925d6
Mesh highlighter WIP3.
Williscool13 May 4, 2025
93cf181
Debug highlighter outputs to a stencil buffer.
Williscool13 May 5, 2025
b821fd8
Render constants cleanup.
Williscool13 May 5, 2025
a1cb4c9
Save Image debug refactor WIP.
Williscool13 May 5, 2025
c654b2d
Debug highlighter now correctly outputs only the outline of the objec…
Williscool13 May 6, 2025
81ed57d
Reduce code duplication from different save image function types.
Williscool13 May 6, 2025
399beda
Minor updates to the debug renderer for release builds.
Williscool13 May 7, 2025
45a7b9c
Specify vulkan version to try to fix CI.
Williscool13 May 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/windows-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
- name: Install Vulkan SDK
uses: humbletim/install-vulkan-sdk@c2aa128094d42ba02959a660f03e0a4e012192f9
with:
version: latest
version: 1.3.296.0
cache: true

- name: Configure CMake
Expand Down
21 changes: 14 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
cmake_minimum_required(VERSION 3.28)
project(WillEngine)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 23)

add_definitions(-DVK_NO_PROTOTYPES)

add_definitions(-DGLM_FORCE_DEPTH_ZERO_TO_ONE)
add_definitions(-DGLM_ENABLE_EXPERIMENTAL)
add_definitions(-DJPH_DEBUG_RENDERER)

#add_definitions(-DJPH_PROFILE_ENABLED=0)
#add_definitions(-DJPH_DEBUG_RENDERER=0)
add_definitions(-DJPH_ENABLE_ASSERTS=1)
add_definitions(-DJPH_ENABLE_ASSERT_MESSAGES=1)

# #if WILL_ENGINE_DEBUG
# ##endif
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DWILL_ENGINE_DEBUG=1)
add_definitions(-DJPH_DEBUG_RENDERER)
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
add_definitions(-DWILL_ENGINE_RELEASE=1)
endif ()
Expand Down Expand Up @@ -48,7 +49,7 @@ add_subdirectory(extern/fastgltf/deps) # simdjson
# Jolt Physics
set(PHYSICS_REPO_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/extern/JoltPhysics")
include(extern/JoltPhysics/Jolt/Jolt.cmake)
set(CMAKE_CXX_STANDARD 20) # Jolt sets it to 17
set(CMAKE_CXX_STANDARD 23) # Jolt sets it to 17

include_directories(${CMAKE_SOURCE_DIR})

Expand Down Expand Up @@ -131,8 +132,8 @@ set(PHYSICS_SOURCES
src/physics/physics_utils.h
src/physics/physics_utils.cpp
src/physics/physics_constants.h
src/physics/debug/debug_renderer.cpp
src/physics/debug/debug_renderer.h
src/physics/debug/jolt_debug_renderer.cpp
src/physics/debug/jolt_debug_renderer.h
src/physics/physics_body.h
)

Expand Down Expand Up @@ -263,7 +264,13 @@ set(TEMP_SOURCES
src/renderer/pipelines/geometry/transparent_pipeline/transparent_pipeline_types.h
src/renderer/pipelines/basic/basic_compute/basic_compute_pipeline_types.h
src/renderer/pipelines/visibility_pass/visibility_pass_pipeline_types.h

src/renderer/pipelines/debug/debug_renderer.cpp
src/renderer/pipelines/debug/debug_renderer.h
src/renderer/pipelines/debug/debug_renderer_types.h
src/renderer/pipelines/debug/debug_composite_pipeline.cpp
src/renderer/pipelines/debug/debug_composite_pipeline.h
src/renderer/pipelines/debug/debug_highlighter.cpp
src/renderer/pipelines/debug/debug_highlighter.h
)

add_executable(WillEngine main.cpp
Expand Down
16 changes: 8 additions & 8 deletions assets/settings.willengine
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
},
"cameraSettings": {
"position": [
-19.169994354248047,
105.9618911743164,
36.455501556396484
-7.438582420349121,
34.399600982666016,
47.61833953857422
],
"rotation": [
-0.14886538684368134,
-0.2690022885799408,
-0.04212456941604614,
0.9506327509880066
0.025229064747691154,
-0.12272556871175766,
0.0031201005913317204,
0.9921150803565979
],
"fov": 1.3089969158172607,
"aspectRatio": 1.4861111640930176,
"aspectRatio": 1.7777777910232544,
"nearPlane": 1000.0,
"farPlane": 0.10000000149011612
},
Expand Down
1 change: 1 addition & 0 deletions shaders/ambient_occlusion/ground_truth/gtao_main_pass.comp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ void main() {

// Get view space normal by sampling normal buffer and converting from world to view (code not relevant)
vec3 viewNormal = texture(normalBuffer, uv).rgb;
viewNormal = unpackNormal(viewNormal);

if (pushConstants.debug == 2){
imageStore(debugImage, screenPos, vec4(viewNormal, 1.0f));
Expand Down
29 changes: 29 additions & 0 deletions shaders/debug/debug_composite.comp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#version 460

#include "scene.glsl"

layout (local_size_x = 16, local_size_y = 16) in;

// layout (std140, set = 0, binding = 0) uniform SceneData - scene.glsl

layout(set = 1, binding = 0) uniform sampler2D debugImage;
layout(set = 1, binding = 1, rgba16) uniform image2D finalImage;

void main() {
ivec2 pixelCoord = ivec2(gl_GlobalInvocationID.xy);
if (any(greaterThan(pixelCoord, ivec2(sceneData.renderTargetSize)))) {
return;
}
vec2 uv = (vec2(pixelCoord) + 0.5) / sceneData.renderTargetSize;
vec4 mainColor = imageLoad(finalImage, pixelCoord);

vec2 debugUv = uv;
// Flip (Main image is flipped in PP)
debugUv.y = 1 - debugUv.y;
// Unjitter
debugUv += sceneData.jitter.xy / 2.0f;
vec4 debugColor = texture(debugImage, debugUv);

vec4 finalColor = mix(mainColor, debugColor, debugColor.a);
imageStore(finalImage, pixelCoord, finalColor);
}
9 changes: 9 additions & 0 deletions shaders/debug/debug_highlighter.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#version 460

layout (location = 0) in vec3 inColor;

layout (location = 0) out vec4 imageTarget;

void main() {
imageTarget = vec4(inColor, 1.0);
}
21 changes: 21 additions & 0 deletions shaders/debug/debug_highlighter.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#version 460

#include "scene.glsl"

layout(location = 0) in vec3 inPosition;

layout(location = 0) out vec3 outColor;

// layout (std140, set = 0, binding = 0) uniform SceneData - scene.glsl

layout (push_constant) uniform PushConstants {
mat4 modelMatrix;
vec4 color;
} push;

void main() {
gl_Position = sceneData.viewProj * push.modelMatrix * vec4(inPosition, 1.0);
// fixed depth offset so that the whole object can be seen in most cases
gl_Position.z += 0.001;
outColor = push.color.xyz;
}
60 changes: 60 additions & 0 deletions shaders/debug/debug_highlighter_processing.comp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#version 460

#include "scene.glsl"

layout (local_size_x = 16, local_size_y = 16) in;

// layout (std140, set = 0, binding = 0) uniform SceneData - scene.glsl

layout(set = 1, binding = 0, r8ui) uniform uimage2D highlighterStencil;
layout(set = 1, binding = 1, rgba16) uniform image2D debugTarget;

const int OUTLINE_THICKNESS = 2;

void main() {
ivec2 pixelCoord = ivec2(gl_GlobalInvocationID.xy);
if (any(greaterThan(pixelCoord, ivec2(sceneData.renderTargetSize)))) {
return;
}

uint stencilValue = imageLoad(highlighterStencil, pixelCoord).r;

if (stencilValue == 0) {
return;
}

bool isEdge = false;

for (int thickness = 1; thickness <= OUTLINE_THICKNESS; thickness++) {
for (int dir = 0; dir < 4; dir++) {
ivec2 offset;
if (dir == 0) offset = ivec2(thickness, 0); // Right
if (dir == 1) offset = ivec2(-thickness, 0); // Left
if (dir == 2) offset = ivec2(0, thickness); // Down
if (dir == 3) offset = ivec2(0, -thickness); // Up

ivec2 neighborCoord = pixelCoord + offset;

if (all(greaterThanEqual(neighborCoord, ivec2(0))) &&
all(lessThan(neighborCoord, ivec2(sceneData.renderTargetSize)))) {
uint neighborValue = imageLoad(highlighterStencil, neighborCoord).r;
if (neighborValue == 0) {
isEdge = true;
break;
}
} else {
isEdge = true;
break;
}
}

if (isEdge) {
break;
}
}

if (isEdge) {
vec4 outlineColor = vec4(1.0, 0.647, 0.0, 1.0);
imageStore(debugTarget, pixelCoord, outlineColor);
}
}
10 changes: 10 additions & 0 deletions shaders/debug/debug_renderer.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#version 460

layout (location = 0) in vec3 inColor;

layout (location = 0) out vec4 imageTarget;

void main() {
// 0 indicates this won't do light calculations in deferred resolve
imageTarget = vec4(inColor, 1.0);
}
16 changes: 16 additions & 0 deletions shaders/debug/debug_renderer.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#version 460

#include "scene.glsl"

layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inColor;

layout(location = 0) out vec3 outColor;

// layout (std140, set = 0, binding = 0) uniform SceneData - scene.glsl

void main() {
gl_Position = sceneData.viewProj * vec4(inPosition, 1.0);
gl_Position.xy += gl_Position.w * sceneData.jitter.xy;
outColor = inColor;
}
10 changes: 10 additions & 0 deletions shaders/debug/debug_renderer_instanced.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#version 460

layout (location = 0) in vec3 inColor;

layout (location = 0) out vec4 imageTarget;

void main() {
// 0 indicates this won't do light calculations in deferred resolve
imageTarget = vec4(inColor, 1.0);
}
26 changes: 26 additions & 0 deletions shaders/debug/debug_renderer_instanced.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#version 460

layout(location = 0) in vec3 inPosition;

layout(location = 0) out vec3 outColor;

#include "scene.glsl"

struct Instance{
mat4 transform;
vec3 color;
float padding;
};

// layout (std140, set = 0, binding = 0) uniform SceneData - scene.glsl

layout(std140, set = 1, binding = 0) readonly buffer InstanceBuffer {
Instance instances[];
} instances;

void main() {
Instance instance = instances.instances[gl_InstanceIndex];
gl_Position = sceneData.viewProj * instance.transform * vec4(inPosition, 1.0);
gl_Position.xy += gl_Position.w * sceneData.jitter.xy;
outColor = instance.color;
}
3 changes: 1 addition & 2 deletions shaders/deferredMrt.frag
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ void main() {
roughness *= metalRoughSample.g;
}


normalTarget = vec4(normalize(inViewNormal), 0.0f);
normalTarget = vec4(packNormal(normalize(inViewNormal)), 0.0f);
albedoTarget = vec4(albedo.xyz, 1.0f);
pbrTarget = vec4(metallic, roughness, 0.0f, inHasTransparent);

Expand Down
5 changes: 4 additions & 1 deletion shaders/deferredResolve.comp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#version 460
#extension GL_EXT_nonuniform_qualifier: enable

#include "common.glsl"
#include "scene.glsl"
#include "pbr.glsl"
#include "environment.glsl"
Expand Down Expand Up @@ -86,6 +87,8 @@ void main() {
}
float depth = texture(depthBuffer, uv).r;
vec3 viewNormal = texture(normalRenderTarget, uv).rgb;
viewNormal = unpackNormal(viewNormal);

vec4 pbrData = texture(pbrRenderTarget, uv);
vec3 viewPosition = reconstructPosition(uv, depth);

Expand Down Expand Up @@ -174,7 +177,7 @@ void main() {
imageStore(outputImage, screenPos, albedo);
break;
case 4:
imageStore(outputImage, screenPos, vec4(worldN * 0.5f + 0.5f, 1.0f));
imageStore(outputImage, screenPos, vec4(packNormal(viewNormal), 1.0f));
break;
case 5:
imageStore(outputImage, screenPos, pbrData);
Expand Down
6 changes: 3 additions & 3 deletions shaders/environment/environment.frag
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#version 450

#include "common.glsl"
#include "scene.glsl"

layout (location = 0) in vec3 uv;
Expand All @@ -21,11 +22,10 @@ void main()
direction.y = -direction.y;
vec3 envColor = textureLod(environmentMap, direction, 0).rgb;

// 0 = environment map flag
// 0 = "do not calculate lighting" flag
albedoTarget = vec4(envColor, 0.0);

vec3 normal = mat3(sceneData.view) * -direction;
normalTarget = vec4(normal, 0.0f);
normalTarget = vec4(packNormal(mat3(sceneData.view) * -direction), 0.0f);
pbrTarget = vec4(0.0f);

vec2 currNdc = inCurrMvpPosition.xy / inCurrMvpPosition.w;
Expand Down
16 changes: 16 additions & 0 deletions shaders/include/common.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,20 @@ bool nearlyEqual(float a, float b, float epsilon) {
return abs(a - b) <= epsilon;
}

vec3 unpackNormal(vec3 packedNormal) {
#ifdef REMAP_NORMALS
return packedNormal * 2.0 - 1.0;
#else
return packedNormal;
#endif
}

vec3 packNormal(vec3 normal) {
#ifdef REMAP_NORMALS
return normal * 0.5 + 0.5;
#else
return normal;
#endif
}

#endif // COMMON_GLSL
4 changes: 2 additions & 2 deletions shaders/terrain/terrain.frag
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
#extension GL_EXT_buffer_reference: require
#extension GL_EXT_nonuniform_qualifier: enable

#include "common.glsl"
#include "scene.glsl"
#include "structure.glsl"


// world space
layout (location = 0) in vec3 inPosition;
layout (location = 1) in vec3 inNormal;
Expand Down Expand Up @@ -41,7 +41,7 @@ float smoothBlend(float value, float threshold, float range) {
}

void main() {
normalTarget = vec4(mat3(sceneData.view) * normalize(inNormal), 0.0f);
normalTarget = vec4(packNormal(mat3(sceneData.view) * normalize(inNormal)), 0.0f);;

float slope = 1.0 - abs(dot(normalize(inNormal), vec3(0.0, 1.0, 0.0)));
float height = inPosition.y;
Expand Down
Loading