Create a Shadertoy account. Either fork this shadertoy, or create a new shadertoy and copy the code from the Debugging Puzzle.
Let's practice debugging! We have a broken shader. It should produce output that looks like this: Unbelievably beautiful shader
It don't do that. Correct THREE of the FIVE bugs that are messing up the output. You are STRONGLY ENCOURAGED to work with a partner and pair program to force you to talk about your debugging thought process out loud.
Extra credit if you can find all FIVE bugs.
- Create a pull request to this repository
- In the README, include the names of both your team members
- 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!)
Typo of vec2 and uv.
Found it thru shadertoy compiler error warning.
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.
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:
- The shperes' shape is scaled in the horizontatl direction.
- The SDF of spheres is correct.
- So there is something wrong with ray's direction.
- Check the raycast function and each vector.
- iResolution.x / iResolution.x looks suspicious.
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);
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.