Skip to content

Commit

Permalink
Working on vertex pulling
Browse files Browse the repository at this point in the history
  • Loading branch information
krupitskas committed Sep 29, 2024
1 parent 044c9ff commit c07951e
Show file tree
Hide file tree
Showing 92 changed files with 919 additions and 624 deletions.
4 changes: 4 additions & 0 deletions Docs/Docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Documentation

## Math

57 changes: 57 additions & 0 deletions Docs/Tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Tasks


## To-Do

* Finish vertex pulling <-
* Shader reflection
* Reverse Z
* Provide material indices in path tracing
* Output albedo/normals with RTX mode
* Add indirect draw for forward pipeline
* Add console commands
* UI input func
* Add GPU frustum culling
* Finish shader hot reload
* Invest in robustness
* Add, delete gltf objects
* Resize window / fullscreen / vsync
* Output all stats - textures, vertex, index buffer
* Improve camera
* Remove wil::com_ptr and shared ptr as much as possible
* Dispatch rays SRV issue
* Invest into better abstraction
* Add GPU occlusion culling - HZB
* Finish path tracing
* Add VBuffer and GBuffer
* Add more lights - spot and point
* Add gizmos and scene description to actually manipulate it
* Add loading saving of the scene

## Visual fancy stuff

* ACES
* Bloom
* SSAO
* SSR
* TAA
* Motion Blur
* Depth Of Field
* DDGI
* Area lights
* OIT
* Magnify pixels (steal from AMD)
* GPU Particles

## Hardware fancy stuff

* Sampler feedback
* Work Graph
* Direct SR
*



## Known issues:

*
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@
**Personal DirectX 12 research renderer oriented for fast iterations and easy usage**

</div>

## First class citizens:
1. Triangle/Mesh render efficency
2. RTX features (reflections, shadows, AO)
3. Indirect as much as possible (Work graphs in the future)
4. Real world lighting values to keep consistency

## Current Features

* Forward renderer
* GLTF format support loading
* Tonemapping
* RTX pathtracing
* Bindless textures

5 changes: 5 additions & 0 deletions Shaders/BasePassVertex.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ cbuffer SceneParameters : register(b3)
uint shadows_enabled;
};


// TODO: Implement vertex pulling
//ByteAddressBuffer IndicesBuffer : register(t1);
//ByteAddressBuffer VerticesBuffer : register(t2);

VS2RS main(IA2VS input)
{
VS2RS output;
Expand Down
6 changes: 4 additions & 2 deletions Shaders/HitRT.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// D3D12_RAYTRACING_SHADER_CONFIG pipeline subobjet.
struct HitInfo
{
float4 colorAndDistance;
float4 color_distance;
};

// Attributes output by the raytracing when hitting a surface,
Expand All @@ -22,6 +22,8 @@ struct Attributes
[shader("closesthit")]
void ClosestHit(inout HitInfo payload, Attributes attrib)
{
Texture2D albedo_texture = ResourceDescriptorHeap[3];

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

const float3 A = float3(1, 0, 0);
Expand All @@ -30,5 +32,5 @@ void ClosestHit(inout HitInfo payload, Attributes attrib)

float3 hit_color = A * barycentrics.x + B * barycentrics.y + C * barycentrics.z;

payload.colorAndDistance = float4(hit_color, RayTCurrent());
payload.color_distance = float4(hit_color, RayTCurrent());
}
8 changes: 3 additions & 5 deletions Shaders/MissRT.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@
// D3D12_RAYTRACING_SHADER_CONFIG pipeline subobjet.
struct HitInfo
{
float4 colorAndDistance;
float4 color_distance;
};

// Attributes output by the raytracing when hitting a surface,
// here the barycentric coordinates
// Attributes output by the raytracing when hitting a surface, here the barycentric coordinates
struct Attributes
{
float2 bary;
};


[shader("miss")]
void Miss(inout HitInfo payload : SV_RayPayload)
{
payload.colorAndDistance = float4(0.2f, 0.2f, 0.8f, -1.f);
payload.color_distance = float4(0.2f, 0.2f, 0.8f, -1.f);
}
11 changes: 7 additions & 4 deletions Shaders/RayGenRT.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// D3D12_RAYTRACING_SHADER_CONFIG pipeline subobjet.
struct HitInfo
{
float4 colorAndDistance;
float4 color_distance;
};

// Attributes output by the raytracing when hitting a surface,
Expand All @@ -33,14 +33,17 @@ cbuffer CameraParameters : register(b0)
}

// Raytracing acceleration structure, accessed as a SRV
RaytracingAccelerationStructure SceneBVH : register(t0);
RaytracingAccelerationStructure SceneBVH : register(t0);

ByteAddressBuffer IndicesBuffer : register(t1);
ByteAddressBuffer VerticesBuffer : register(t2);

[shader("raygeneration")]
void RayGen()
{
// Initialize the ray payload
HitInfo payload;
payload.colorAndDistance = float4(0, 0, 0, 0);
payload.color_distance = float4(0, 0, 0, 0);

// Get the location within the dispatched 2D grid of work items
// (often maps to pixels, so this could represent a pixel coordinate).
Expand Down Expand Up @@ -109,5 +112,5 @@ void RayGen()
payload
);

gOutput[launchIndex] = float4(payload.colorAndDistance.rgb, 1.f);
gOutput[launchIndex] = float4(payload.color_distance.rgb, 1.f);
}
7 changes: 6 additions & 1 deletion Yasno/Graphics/Material.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#pragma once

#include <Renderer/PipelineStateObject.hpp>

namespace ysn
{
class Material
struct Material
{
Material(std::string name) : pso(name) {}

PipelineStateObject pso;
// wil::com_ptr<ID3D12RootSignature> pRootSignature;
// wil::com_ptr<ID3D12PipelineState> pPipelineState;
};
Expand Down
7 changes: 6 additions & 1 deletion Yasno/Graphics/Mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

namespace ysn
{
class Mesh
struct Mesh
{
uint32_t vertex_buffer_offset = 0;
uint32_t vertex_buffer_size = 0;

uint32_t index_buffer_offset = 0;
uint32_t vertex_buffer_size = 0;
};
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "Primitives.hpp"
#include "Primitive.hpp"

#include <vector>

#include <RHI/VertexFactory.hpp>
#include <Renderer/VertexStorage.hpp>

#include <System/Application.hpp>

#include "RHI/D3D12Renderer.hpp"
#include "Renderer/DxRenderer.hpp"

namespace ysn
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@

#include <wil/com.h>

#include <RHI/VertexFactory.hpp>
#include <Renderer/VertexStorage.hpp>

namespace ysn
{
struct Primitive
{
};

// TODO: Meh
struct MeshPrimitive
{
wil::com_ptr<ID3D12Resource> vertex_buffer;
Expand Down
6 changes: 6 additions & 0 deletions Yasno/Graphics/RenderObjectId.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

namespace ysn
{
using RenderObjectId = std::uint32_t;
}
15 changes: 15 additions & 0 deletions Yasno/Graphics/RenderScene.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
#include "RenderScene.hpp"

namespace ysn
{
RenderObjectId RenderScene::AddObject()
{

return 0;
}


void RenderScene::DeleteObject(RenderObjectId object)
{

}
}
57 changes: 48 additions & 9 deletions Yasno/Graphics/RenderScene.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,56 @@
#pragma once

#include <DirectXMath.h>

#include <vector>
#include <memory>

#include <Graphics/Material.hpp>
#include <Graphics/Mesh.hpp>
#include <Graphics/RenderObjectId.hpp>
#include <Yasno/Lights.hpp>
#include <Yasno/CameraController.hpp>

class RenderSceneNode
namespace ysn
{
struct NodeTransformation
{
DirectX::XMFLOAT4X4 model;
};

};
// Model desciption info
struct Model
{
std::string name = "Unnamed Model";
bool should_cast_shadow = false;
};

class RenderScene
{
public:
std::vector<RenderSceneNode> nodes;
struct RenderScene
{
std::shared_ptr<Camera> camera;
FpsCameraController camera_controler;

DirectionalLight directional_light;
EnvironmentLight environment_light;

std::vector<Model> models;
std::vector<NodeTransformation> transformations;
std::vector<Mesh> meshes;
std::vector<Material> materials;

RenderObjectId AddObject();

// Switches pointers between current object and last one, decrement num_objects and deletes it later.
void DeleteObject(RenderObjectId object);

uint32_t GetModelCount() const
{
return num_objects;
}

private:
// Keep track of live objects to render
uint32_t num_objects = 0;
};
}

bool SaveToDisk();
bool LoadFromDisk();
};
6 changes: 6 additions & 0 deletions Yasno/Graphics/RtxMaterial.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "RtxMaterial.hpp"

namespace ysn
{

}
6 changes: 6 additions & 0 deletions Yasno/Graphics/RtxMaterial.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

namespace ysn
{

}
5 changes: 5 additions & 0 deletions Yasno/Graphics/SurfaceMaterial.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "SurfaceMaterial.hpp"

namespace ysn
{
}
30 changes: 30 additions & 0 deletions Yasno/Graphics/SurfaceMaterial.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include <DirectXMath.h>

namespace ysn
{
#define ALBEDO_ENABLED_BIT 0
#define METALLIC_ROUGHNESS_ENABLED_BIT 1
#define NORMAL_ENABLED_BIT 2
#define OCCLUSION_ENABLED_BIT 3
#define EMISSIVE_ENABLED_BIT 4


// Default PBR material
struct SurfaceShaderParameters
{
DirectX::XMFLOAT4 base_color_factor;
float metallic_factor;
float roughness_factor;

// Encods which textures are active
int32_t texture_enable_bitmask;

int32_t albedo_texture_index;
int32_t metallic_roughness_texture_index;
int32_t normal_texture_index;
int32_t occlusion_texture_index;
int32_t emissive_texture_index;
};
}
Loading

0 comments on commit c07951e

Please sign in to comment.