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

Lab02: Ruipeng Wang #9

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
96 changes: 96 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,100 @@
# lab02-debugging
1. In the line 97, there was a compile error:

```cpp
vec uv2 = 2.0 * uv - vec2(1.0);
```

which should be:

```cpp
vec2 uv2 = 2.0 * uv - vec2(1.0);
```

2. After fixing bug 1, the shader compiles successfully and it looks like this:

![Screenshot 2024-09-18 at 10.28.47 AM.png](Screenshot_2024-09-18_at_10.28.47_AM.png)

It seems that the SDF is not at the right place. And it does not look like a sphere. So, I assume there will be a bug in the x and y. And I found out that in the line 11.

```cpp
textH *= len * iResolution.x / iResolution.x;
```

which should be:

```cpp
textH *= len * iResolution.x / iResolution.y;
```

The aspect ratio calculation is incorrect, which can lead to distortion in the image.

3. Now, the shader looks like this:

![image.png](image.png)

I found out that the screen is only outputting 1/4 of what we expected. I assume that there is some uv issue since ray march seems fine after all. Then I found out that uv2 is declared but never used. So I changed line 100 from

```cpp
raycast(uv, dir, eye, ref);
```

to

```cpp
raycast(uv2, dir, eye, ref);
```

4. The scenes transform seems fine now:

![image.png](image%201.png)

However, there are still some issue. Like the material of the sphere is not ray marching. I also noticed that there are some strange warp around the sphere:

![image.png](image%202.png)

I think this should be some ray marching precision problem. In the line 22, I changed the m:

```cpp
if(m < 0.01)
```

to

```cpp
if(m < 0.001)
```

Then, the floor turns out to be cutoff more, but the warp seems better:

![image.png](image%203.png)

This appears to be a cutoff issue if the distance is too far, so I adjust the iteration cutoff distance in line 18:

```cpp
for(int i = 0; i < 64; ++i)
```

into

```cpp
for(int i = 0; i < 256; ++i)
```

5. The only problem left here is that there is no reflection:

![image.png](image%204.png)

So, I went to the ray marching logic and, thanks to my friend Crystal, I found out that in line 75 the ray should be:

```cpp
dir = reflect(dir, nor);
```

Everything seems fine now!

![image.png](image%205.png)


# Setup

Expand Down
Binary file added Screenshot_2024-09-18_at_10.28.47_AM.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 image 1.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 image 2.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 image 3.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 image 4.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 image 5.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 image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.