Skip to content

Commit

Permalink
Some readme updates
Browse files Browse the repository at this point in the history
  • Loading branch information
krupitskas committed Nov 22, 2024
1 parent 15e41c7 commit 246c5d9
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 22 deletions.
52 changes: 45 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,53 @@
s<div align="center">
<div align="center">

# `🌩️ Yasno`

**Personal DirectX 12 research p_renderer->GetDevice()-> oriented for fast iterations and easy usage**
**Personal DirectX 12 research oriented renderer for quick iterations and easy usage**

</div>
## Features

* Forward renderer
* GLTF format support loading
* Tonemapping
* RTX pathtracing
## Current research goal idea

Yasno has two modes - raster and pathtracing for reference image.
Reference pathtracing use RTX for tracing rays from the camera to the world. Raster right now not use any of RTX features (but will in the future like RTXGI, RTXAO)
* Main goal to achieve non blurry, not ghosty nice sharp looking picture which is close to the reference pathtracing image. I don't really want to use any TAA or upscaling for this research, so I want to revisit older technques like SMAA which expect image converge via single frame, however - will see..
* Second goal is to have very efficiient culling (up to each triangle)
* Third goal is to load UE5 matrix city demo and run it with this renderer (yeah, not soon)

### Current features

* Forward raster renderer mode
* RTX pathtracing renderer mode (materials WIP)
* GLTF format loading
* HDR Tonemapping (naive one, would be added more modes in the future like ACES and filmic)
* Bindless textures
* Single material, vertex, indices buffer
* Indirect draw (almost finished)

### Planned close next features

* RTX Pathtracing with multiframe accumulation
* Indirect frustum and occlusion cull via HZB
* RTXGI
* BRDF, BTDF and BSDF for different type materials to match pathtracing mode
* Utilize physical light units
* V Buffer
* Yasno architecture refactoring (right now it *very* messy)
* Shaders hot reloading (tracking for filesystem changes is there, but I want to make it right with include support)
* Finish naive techniques like
* CSM
* PCF
* PCSS
* OIT
* Volumetric fog
* SSLR, SSAO (with RTX fallback)
* DOF
* Color grading

### Planned long term features

* Apex and triangle culling
* Morph, skeletal animations
* Scene saving and loading (research OpenUSD)
* Texture streaming
* Async scene loading
Empty file added Shaders/CommonStructures.hlsl
Empty file.
23 changes: 22 additions & 1 deletion Shaders/HitRT.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,23 @@ struct Attributes

struct VertexLayout
{

float3 position;
float3 normal;
float4 tangent;
float2 texcoord_0;
};

inline uint PackInstanceID(uint material_id, uint geometry_id)
{
return ((geometry_id & 0x3FFF) << 10) | (material_id & 0x3FF);
}

inline void UnpackInstanceID(uint instanceID, out uint material_id, out uint geometry_id)
{
material_id = instanceID & 0x3FF;
geometry_id = (instanceID >> 10) & 0x3FFF;
}

StructuredBuffer<VertexLayout> VertexBuffer : register(t0);
StructuredBuffer<uint> IndexBuffer : register(t1);

Expand All @@ -36,6 +50,13 @@ void ClosestHit(inout HitInfo payload, Attributes attrib)

float3 barycentrics = float3(1.f - attrib.bary.x - attrib.bary.y, attrib.bary.x, attrib.bary.y);

uint material_id;
uint geometry_id;
UnpackInstanceID(primitive_index, material_id, geometry_id);

//VertexLayout vertex_data = GetVertexAttributes(geometry_id, primitive_index, barycentrics);


const float3 A = float3(1, 0, 0);
const float3 B = float3(0, 1, 0);
const float3 C = float3(0, 0, 1);
Expand Down
2 changes: 2 additions & 0 deletions Yasno/Graphics/Primitive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace ysn
{
struct Primitive
{
uint32_t index = 0;

PsoId pso_id = -1;
PsoId shadow_pso_id = -1;

Expand Down
12 changes: 12 additions & 0 deletions Yasno/Graphics/RenderScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ namespace ysn
std::vector<D3D12_SAMPLER_DESC> sampler_descs;
};

// TODO: Move to some shared place between C++ and HLSL
inline uint32_t PackInstanceID(uint32_t material_id, uint32_t geometry_id)
{
return ((geometry_id & 0x3FFF) << 10) | (material_id & 0x3FF);
}

inline void UnpackInstanceID(uint32_t instance_id, uint32_t& material_id, uint32_t& geometry_id)
{
material_id = instance_id & 0x3FF;
geometry_id = (instance_id >> 10) & 0x3FFF;
}

// Per instance data for rendering
YSN_SHADER_STRUCT RenderInstanceData
{
Expand Down
4 changes: 2 additions & 2 deletions Yasno/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
int WINAPI wWinMain(_In_ HINSTANCE hinstance, _In_opt_ HINSTANCE, _In_ LPWSTR, _In_ int)
{
ysn::Application::Create(hinstance);
auto window = ysn::Application::Get().CreateRenderWindow(L"Yasno", 1980, 1020, false);
auto window = ysn::Application::Get().CreateRenderWindow(L"Yasno", 1920, 1080, false);

auto yasno_core = std::make_shared<ysn::Yasno>(L"Yasno", 1980, 1020);
auto yasno_core = std::make_shared<ysn::Yasno>(L"Yasno", 1920, 1080);
yasno_core->SetWindow(window);
window->RegisterCallbacks(yasno_core);
window->Show();
Expand Down
12 changes: 9 additions & 3 deletions Yasno/Renderer/RaytracingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ ysn::AccelerationStructureBuffers ysn::RaytracingContext::CreateBottomLevelAS(wi
void ysn::RaytracingContext::CreateTopLevelAS(
wil::com_ptr<ID3D12Device5> device,
wil::com_ptr<ID3D12GraphicsCommandList4> command_list,
const std::vector<std::pair<wil::com_ptr<ID3D12Resource>, DirectX::XMMATRIX>>& input_instances)
const std::vector<TlasInput>& input_instances)
{
// Gather all the instances into the builder helper
for (size_t i = 0; i < input_instances.size(); i++)
{
tlas_generator.AddInstance(input_instances[i].first.get(), input_instances[i].second, static_cast<uint32_t>(i), static_cast<uint32_t>(0));
tlas_generator.AddInstance(input_instances[i].blas.get(), input_instances[i].transform, input_instances[i].instance_id, static_cast<uint32_t>(0));
}

// As for the bottom-level AS, the building the AS requires some scratch space
Expand Down Expand Up @@ -178,7 +178,13 @@ void ysn::RaytracingContext::CreateAccelerationStructures(wil::com_ptr<ID3D12Gra

// Build the bottom AS from the Triangle vertex buffer
AccelerationStructureBuffers bottomLevelBuffers = CreateBottomLevelAS(renderer->GetDevice(), command_list, vertex_buffers);
instances.emplace_back(bottomLevelBuffers.result, transform.transform);

TlasInput tlas_input;
tlas_input.blas = bottomLevelBuffers.result;
tlas_input.transform = transform.transform;
tlas_input.instance_id = PackInstanceID(primitive.material_id, primitive.index);

instances.emplace_back(tlas_input);

blas_res.push_back(bottomLevelBuffers.result);

Expand Down
11 changes: 9 additions & 2 deletions Yasno/Renderer/RaytracingContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ namespace ysn
uint32_t index_count;
};

struct TlasInput
{
wil::com_ptr<ID3D12Resource> blas;
DirectX::XMMATRIX transform;
uint32_t instance_id = 0;
};

struct RaytracingContext
{
AccelerationStructureBuffers CreateBottomLevelAS(
Expand All @@ -41,7 +48,7 @@ namespace ysn
void CreateTopLevelAS(
wil::com_ptr<ID3D12Device5> device,
wil::com_ptr<ID3D12GraphicsCommandList4> command_list,
const std::vector<std::pair<wil::com_ptr<ID3D12Resource>, DirectX::XMMATRIX>>& instances);
const std::vector<TlasInput>& instances);

void CreateTlasSrv(std::shared_ptr<ysn::DxRenderer> renderer);

Expand All @@ -52,7 +59,7 @@ namespace ysn
std::vector<wil::com_ptr<ID3D12Resource>> blas_res;

AccelerationStructureBuffers tlas_buffers;
std::vector<std::pair<wil::com_ptr<ID3D12Resource>, DirectX::XMMATRIX>> instances;
std::vector<TlasInput> instances;
};

}
3 changes: 3 additions & 0 deletions Yasno/Renderer/ShaderStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ namespace ysn
return false;
}

dxc_include_handler->LoadSource(L"", m_include_blob.get());

return true;
}

Expand Down Expand Up @@ -173,6 +175,7 @@ namespace ysn
}

IDxcOperationResult* dxc_op_result;

if (auto result = dxc_compiler->Compile(dxc_text_blob,
filename.c_str(),
parameters->entry_point.c_str(),
Expand Down
2 changes: 2 additions & 0 deletions Yasno/Renderer/ShaderStorage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,7 @@ namespace ysn
std::optional<std::time_t> GetShaderModificationTime(const std::filesystem::path& shader_path);
std::map<std::wstring, std::time_t> m_shaders_modified_time;
#endif

//wil::com_ptr<IDxcBlob> m_include_blob;
};
}
3 changes: 1 addition & 2 deletions Yasno/Renderer/nv_helpers_dx12/TopLevelASGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ namespace nv_helpers_dx12
memcpy(instanceDescs[i].Transform, &m, sizeof(instanceDescs[i].Transform));
// Get access to the bottom level
instanceDescs[i].AccelerationStructure = m_instances[i].bottomLevelAS->GetGPUVirtualAddress();
// Visibility mask, always visible here - TODO: should be accessible from
// outside
// Visibility mask, always visible here - TODO: should be accessible from outside
instanceDescs[i].InstanceMask = 0xFF;
}

Expand Down
5 changes: 5 additions & 0 deletions Yasno/System/GltfLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,8 @@ static BuildMeshResult BuildMeshes(ysn::Model& model, const tinygltf::Model& glt
{
BuildMeshResult result;

uint32_t primitive_index_count = 0;

for (const tinygltf::Mesh& gltf_mesh : gltf_model.meshes)
{
ysn::Mesh mesh;
Expand All @@ -588,8 +590,11 @@ static BuildMeshResult BuildMeshes(ysn::Model& model, const tinygltf::Model& glt
BuildPrimitiveTopology(primitive, gltf_primitive.mode);

primitive.material_id = gltf_primitive.material;
primitive.index = primitive_index_count;

mesh.primitives.push_back(primitive);

primitive_index_count++;
}

result.primitives_count += gltf_mesh.primitives.size();
Expand Down
13 changes: 8 additions & 5 deletions Yasno/Yasno/Yasno.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ namespace ysn

bool load_result = false;

{
LoadingParameters loading_parameters;
loading_parameters.model_modifier = XMMatrixScaling(0.01f, 0.01f, 0.01f);
load_result = LoadGltfFromFile(m_render_scene, GetVirtualFilesystemPath(L"Assets/Sponza/Sponza.gltf"), loading_parameters);
}
//{
// LoadingParameters loading_parameters;
// loading_parameters.model_modifier = XMMatrixScaling(0.01f, 0.01f, 0.01f);
// load_result = LoadGltfFromFile(m_render_scene, GetVirtualFilesystemPath(L"Assets/Sponza/Sponza.gltf"), loading_parameters);
//}

{
LoadingParameters loading_parameters;
Expand Down Expand Up @@ -478,6 +478,9 @@ namespace ysn
renderer->GetDevice()->CreateShaderResourceView(m_render_scene.instance_buffer.resource.get(), &srv_desc, m_render_scene.instance_buffer_srv.cpu);
}

{
}

}

for (auto& model : m_render_scene.models)
Expand Down

0 comments on commit 246c5d9

Please sign in to comment.