Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PROJECT5: Somanshu Agarwal #30

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
44968e9
Add files via upload
somanshu25 Oct 20, 2019
68f36e6
Add files via upload
somanshu25 Oct 20, 2019
705f894
Changes till Part 2.5
reliang Oct 23, 2019
be68f64
Changes till Part 2.6
reliang Oct 23, 2019
4aad4dc
Changes for part 2.7 and 2.8
Oct 23, 2019
10fb4a4
Chnages till 3.4.1
Oct 24, 2019
3fb4703
Changes till Part 3.4
Oct 24, 2019
a222c3b
Changes till 3.4
Oct 24, 2019
011e5db
Changes till Part3
DishaJindal Oct 25, 2019
0de64cd
Changes till 3.6 working almost
somanshu25 Oct 25, 2019
7e086c6
Code working
haCo77 Oct 26, 2019
6be01ea
Changes in code working
haCo77 Oct 26, 2019
9f277cc
Update README.md
somanshu25 Oct 26, 2019
5adce96
Update README.md
somanshu25 Oct 26, 2019
eab0f84
Update README.md
somanshu25 Oct 26, 2019
ef86310
Update README.md
somanshu25 Oct 26, 2019
16ea25b
Update README.md
somanshu25 Oct 26, 2019
7d3adba
Update README.md
somanshu25 Oct 26, 2019
a24b11d
Update README.md
somanshu25 Oct 26, 2019
febe7df
Update README.md
somanshu25 Oct 26, 2019
55a61c1
Update README.md
somanshu25 Oct 26, 2019
991e7d7
Update README.md
somanshu25 Oct 26, 2019
a1361d0
Images added
Oct 26, 2019
d9e5cfe
Update README.md
somanshu25 Oct 26, 2019
e941e25
Update README.md
somanshu25 Oct 26, 2019
36c5403
Update README.md
somanshu25 Oct 26, 2019
236cc08
Update README.md
somanshu25 Oct 26, 2019
b1d8eb2
Update README.md
somanshu25 Oct 26, 2019
6fff66f
Update README.md
somanshu25 Oct 26, 2019
f662f6c
Update README.md
somanshu25 Oct 26, 2019
a15683b
Update README.md
somanshu25 Oct 26, 2019
1e822ab
Update README.md
somanshu25 Oct 27, 2019
5546b34
Update README.md
somanshu25 Oct 27, 2019
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
72 changes: 66 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,71 @@
**University of Pennsylvania, CIS 565: GPU Programming and Architecture,
Project 5 - DirectX Procedural Raytracing**

* (TODO) YOUR NAME HERE
* (TODO) [LinkedIn](), [personal website](), [twitter](), etc.
* Tested on: (TODO) Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab)
* SOMANSHU AGARWAL
* [LinkedIn](https://www.linkedin.com/in/somanshu25)
* Tested on: Windows 10, Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz 16GB (SIGLAB)

### (TODO: Your README)
![](https://github.com/somanshu25/Project5-DirectX-Procedural-Raytracing/blob/master/images/gif_scene_new.gif)

Include screenshots, analysis, etc. (Remember, this is public, so don't put
anything here that you don't want to share with the world.)
### Table of Contents

1. [Introduction](#Introduction)
2. [RayTracing](#RayTracing)
3. [Code Section](#Code-Section)
4. [Performace Analysis](#Performance-Analysis)
5. [Bloopers](#Bloopers)
6. [References](#References)

### Introduction
The project aims at doing ray tracing rendering of a scene using DXR API. The issue with raytracing with the geometries is that we need all the shadeers at once for perfroming rendering, which requires lot of computation and almost impossible to do. The Microsoft came up with DXR API's which help use to perform the rayracing thorugh lot of optimization techniques. The steps in the project helped to learn how the pipeline is generated by using CPU code and how the logic for rendering is written using GPU kernels and parallel computation is used for processing.

The readme gives the brief understanding about the raytracing, about the CPU and GPU codes and finally a performace analysis of the DXR rattrcing with trying the maximum depth of a ray. I have included some bloopers in the end to mention some of my mistakes I was ding while coding in the project.

### RayTracing

Raytracing is the technique used to render scenes and created the images. In raytracing, when a ray from the camera through the pixel co-rodinate of the screen space to the object, which is `radiance ray`,, we find the position and the normal corresponding to the intersection between the object geomentry and the ray. To render the object at the position, we create a light ray which goes to the light source (it's a point source in raytracing) and check whether it is blocked by some other geometry on the way to the light source. If it is blocked, then it's called a `shadow ray` and we render the shadow(black) color at that position. If it goes directly to the light source, we render the color of the obejct. We render the backgorund color if it misses our place surface(made of two triangles) and geometries, it is rendered as a background color. If the object is reflective, then we generate two rays, one which goes to the light source and the other as reflective ray which follows the same logic as radiance ray above. The ray is meant ot be dead if it bounces more than the maximum recursion depth of the ray.

<p align="center"><img src="https://github.com/somanshu25/Project5-DirectX-Procedural-Raytracing/blob/master/images/raytrace.jpg" width="500"/></p>

### Code Section:

While coding, the parts are divided into tow main parts: CPU and GPU section codes.

a. In CPU section, we create the pipeline which could be later on used by the GPU section to render. Note that in raytracing, we need to make sure that all the data is available when the GPU is doing the rendering as compared to rasterization. So, we store the geometries in CPU section of the code and for GPU to access the GPU section, we create dynamic allocation of the memory in the heap and define the dscriptors which gives us the mapping of the CPU and GPU pointers. Here, to create a scene, we first create a transformation of all the objects in their local space (each of then can have their own coordinate space) to the bottom level space which has the same reference coordinate system. After getting the bottom level, we then create the transformation to the scene by creating the instance of the bottom level geometries (also called as Bottom Level Accelearted Structure here) and creating a scene as the Top-Level Accelerated Structure, which we see as the visualization. In our case, we are dealing with two types of geometries, geometries defined by vertices and indices and the other as procedural geometires defined through Axis Aligned Geometry Box(AABB).

<p align="center"><img src="https://github.com/somanshu25/Project5-DirectX-Procedural-Raytracing/blob/master/images/pipeline.png" width="500"/></p>

b. In GPU section, we perform the ray generation from the camera which goes from the camera to the world space with the given information of the pixel co-ordinate of the sreeen space and the camera to world projection transformation. Using the ray generated, we perform the intersection test for all the geometries at local space of the geometry, where we can get through teh inverse transformation of the matrix we got from going to local space to the bottom level space. Once finding the poition and normal of the position if it intersects, we render the poision using raytracing algorithm. We create the shades for the miss also so that we can render those points as some colors in our screen space. In our case, we have intersection test for triangel geometries, test for Analytical Primities (includes AABB Box, Sphere) and the MetaBalls. The references used for intersection tests are provided at the [last section of the readme](#References). We create the hitgroups for pair of each genpmetry and ray. Among the geomtries/hitgroups it intersected, we take the closest hit geometry and render the point.

### Performance Analysis

In one of the steps after wrting the CPU code, ray generation and `TraceRay()` fucntion and Miss shaders , here is the image how it looks like with the Analytical Primitives (AABB Box and Spheres):

<p align="center"><img src="https://github.com/somanshu25/Project5-DirectX-Procedural-Raytracing/blob/master/images/Capture1.PNG" width="700"/></p>

The above has the plane rendered and the background color is shown which implies there is no geometry there.

The performance analysis of FPS with varying the depth is shown below:

<p align="center"><img src="https://github.com/somanshu25/Project5-DirectX-Procedural-Raytracing/blob/master/images/imageChart.png" width="700"/></p>

We see that the FPS is decreasing as we are increasing the maximum depth of the ray which is expected.

### Bloopers

Some of the bloopers are below:

1. The folwwing happened when I was calculating the potential for the Metaball. I was creating the inverse functino from cetner to radii but should have been the opposite. Because of this, the metaballs were coming bigger and some different glitters were coming.

<p align="center"><img src="https://github.com/somanshu25/Project5-DirectX-Procedural-Raytracing/blob/master/images/capture2.PNG" width="600"/></p>

2. Also, I didn't have the linear interpolate function correctly because of which I couldn't differentiate between the plane and the background.

<p align="center"><img src="https://github.com/somanshu25/Project5-DirectX-Procedural-Raytracing/blob/master/images/capture_no_plane_background_diff.PNG" width="600"/></p>

## References

1. [Nvidia Tutorial on DXR raytracing](https://developer.nvidia.com/rtx/raytracing/dxr/DX12-Raytracing-tutorial-Part-2)
2. [Phong Reflection Model](https://en.wikipedia.org/wiki/Phong_reflection_model)
3. [Schlick's approximation](https://en.wikipedia.org/wiki/Schlick%27s_approximation)
4. DirectX documentation and Structure Definitions on Internet
Binary file added images/Capture1.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/Geometry_scaling.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/NDC Coordinates.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/accelerated_structure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/capture2.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/capture_no_plane_background_diff.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/gif_scene_new.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/imageChart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 25 additions & 10 deletions src/D3D12RaytracingProceduralGeometry/AnalyticPrimitives.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,34 @@ bool RaySolidSphereIntersectionTest(in Ray ray, out float thit, out float tmax,
// You can hardcode the local centers/radii of the spheres, just try to maintain them between 1 and -1 (and > 0 for the radii).
bool RayMultipleSpheresIntersectionTest(in Ray ray, out float thit, out ProceduralPrimitiveAttributes attr)
{
// Define the spheres in local space (within the aabb)
float3 center = float3(-0.2, 0, -0.2);
float radius = 0.7f;
float3 centers[3] = { float3(-0.2, 0, -0.2) , float3(0.6, 0.6, 0.6) ,float3(0.6, -0.6, 0.7) };
float radius[3] = { 0.4f , 0.25f, 0.2f };

thit = RayTCurrent();
thit = RayTCurrent();

float tmax;
if (RaySphereIntersectionTest(ray, thit, tmax, attr, center, radius))
{
return true;
}
bool hit = false;

return false;
float tmin = thit;
float tmax;
ProceduralPrimitiveAttributes attrmin;
for (uint i = 0; i < 3; i++)
{

ProceduralPrimitiveAttributes attr2;
if (RaySphereIntersectionTest(ray, thit, tmax, attr2, centers[i], radius[i]))
{
if (thit < tmin) {
tmin = thit;
attr = attr2;
hit = true;
}
}
}

thit = tmin;
return hit;

}

#endif // ANALYTICPRIMITIVES_H
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down Expand Up @@ -220,6 +220,7 @@ PrebuildCheck.bat</Command>
</FxCompile>
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\..\..\..\..\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Platform.targets" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="..\..\..\..\..\..\..\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Platform.targets" />
</ItemGroup>
<ItemGroup>
<FxCompile Include="Raytracing.hlsl">
Expand Down
Loading