Categories
Uncategorized

Using MetalKit part 13

Let’s pick up where we left off in Part 12. Using the same playground we worked on last time, we will learn about lighting and 3D objects today. Remember the sun eclipse we worked on a couple of weeks ago? It’s back! Well, we are going to remove the sun and just focus on the planet this time. […]

Categories
Uncategorized

Using MetalKit part 12

Today we continue working on that beautiful fractal, so let’s pick up where we left off in Part 11. Using the same playground we worked on last time, we will next see how to bring it to life, that is, animate it. For that, we will use uniforms again. We introduced them in Part 5 in case you want to […]

Categories
Uncategorized

Using MetalKit part 11

Let’s continue our journey into the wonderful world of shaders using the Metal Shading Language (MSL) by picking up where we left off in Part 10. Using the same playground we worked on last time, we will next try to get close to making art using MSL math functions such as sin, cos, pow, abs, fmod, clamp, mix, step and smoothstep. First, let’s look at our “sun eclipse” code from […]

Categories
Uncategorized

Using MetalKit part 10

Today we will look at the only other type of Metal function we have not used before, the kernel function or compute shader. You will often hear a variation of intermixed words from both of them. The kernel is used for compute tasks, that is, massively parallel computations done on the GPU. Some examples include: image processing, scientific simulations, and so on. A […]

Categories
Uncategorized

Using MetalKit part 9

I bet many of you missed the MetalKit series, so today we are returning back to it, and we will learn how to draw 3D content in Metal. Let’s continue working on our playground and pick up where we left off in part 8 of the series. We will render a 3D cube by the end of this episode but […]

Categories
Uncategorized

Ray tracing in a Swift playground part 5

Let’s continue working on our ray tracer and pick up where we left off last week. Now that we know how to generate spheres of different materials and know how to look at them from different angles, let’s see how we can generate way more than just 3 spheres. In pixel.swift let’s create a new random_scene() method: This method generates roughly 25 smaller spheres and […]

Categories
Uncategorized

Ray tracing in a Swift playground part 4

Let’s continue working on our ray tracer and pick up where we left off last week. First, as you are already used to, we’ll do more code cleaning. I went ahead and replaced all classes with structs, and also used proper naming conventions (such as capitalization of types) this time. You can see the modified code in […]

Categories
Uncategorized

Ray tracing in a Swift playground part 3

Let’s continue working on our ray tracer and pick up where we left off last week. If we want to render spheres of different materials, Peter Shirley recommends creating an abstract material class that encapsulates behavior. As a computer scientist myself, I couldn’t agree more! The material class will let us produce a scattered ray and calculate how much it was […]

Categories
Uncategorized

Ray tracing in a Swift playground part 2

Let’s continue working on our ray tracer and pick up where we left off last week. I want to thank Caroline, Jessy, Jeff and Mike for providing valuable feedback and performance improvement suggestions while working on this project. First, as usual, we will do some code cleanup. In the first part we used the vec3.swift class because we wanted to understand the underlying data structures […]

Categories
Uncategorized

Ray tracing in a Swift playground

Today we are porting a ray tracer from Peter Shirley’s mini book, into a Swift playground. Since I am not going to describe what Ray Tracing is and how it works, I am inviting you to go ahead and read this book as it’s free for Kindle subscribers. If you are not a subscriber, just buy the book like I did. Paying […]