Skip to content

Yifan Lu Lab2 #18

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,65 @@ Extra credit if you can find all FIVE bugs.
- In the README, create a link to your shader toy solution with the bugs corrected
- In the README, describe each bug you found and include a sentence about HOW you found it.
- Make sure all three of your shadertoys are set to UNLISTED or PUBLIC (so we can see them!)


# Final Result
[Correct Shadertoy Link](https://www.shadertoy.com/view/lXfyD2)

![image](https://github.com/user-attachments/assets/713999cf-661d-4e3d-88e9-ad71f65a406b)

# Bugs
## Bug1
Typo of vec2 and uv.

Found it thru shadertoy compiler error warning.

## Bug2

I fix Bug1 by changing
```
vec uv2 = 2.0 * uv - vec2(1.0);
```

to

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

So the Bug2 raycast(uv, dir, eye, ref); is resolved automatically.

## Bug3
In function raycast, the H is computed like:
```
H *= len * iResolution.x / iResolution.x;
```

However, it should be computed as
```
H *= len * iResolution.x / iResolution.y;
```

How I found it:

1. The shperes' shape is scaled in the horizontatl direction.
2. The SDF of spheres is correct.
3. So there is something wrong with ray's direction.
4. Check the raycast function and each vector.
5. iResolution.x / iResolution.x looks suspicious.


## Bug4
Compared to the correct scene, current scene has reflected color from other surfaces. So I guess there is something wrong with the reflected color.

In line 75, the original shader get the dir to the reflect surface via ``` dir = reflect(eye, nor); ```

It is wrong because the direction should be the next marching ray direction instead of eye direction.

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

## Bug5
The floor seems cut off in the scene compared to the correct one. It may because the rays stopped too early before reaching the floor.
In the marching function, add more iterations for rays to expand farther.