100 Days of Graphics: Days 8 – 14 29 July 2017

Favorite Result

Wolf 3D model in a sky background. The wolf appears translucent and glass-like.
An early attempt at refraction.


Picture of a street.
This is a still from a 3D cubemap render.

The week started off as a dive into how to use cubemaps.

Cubemaps are pretty interesting and seem so useful for rending gorgeous scenery. They’re actually pretty easy to use too! Simply use a 3D vector to sample the cubemap. The tricky issue is creating the 3D vectors to use to sample.

If you’re using the camera’s orientation, you’ll have to essentially create 4 separate vectors (one for each corner of the render plane) and interpolate between the vectors based on the fragment coordinate on the render plane.

Thankfully, modern engines handle the interpolation for us. We usually just have to supply the camera’s looking direction or a model’s vertex position to the fragment shader.

The image above came from my¬†Shader Toy script which performs a cubemap rendering entirely in a fragment shader. The code actually demonstrates how to calculate the vector to use to sample the cubemap based on the fragment’s position! Check it out!

Object To Shadron

The later half of the week took a bit of a deviation. I wanted to explore the OpenGL tool Shadron a bit better and continue playing with cubemaps.

An unfortunate problem with Shadron is its inability to import custom 3D models. Technically there’s nothing stopping you from using a custom mode. The only problem is that you need to specify each vertex individually in a hard-coded manner.

Until there’s a way to upload models as a Vertex Array Object, we’re forced to do this. To make this slightly more convenient, I took a break to learn Python a bit and wrote a quick script that converts a Wavefront Object file (.obj) into a format that Shadron can use!

The python script is available on my github and free to use! I have some minor optimizations to make with it before I call it finished, but it’s working well so far. Another problem is that it takes a long time to compile Shadron programs using custom models because the output Shadron file is so large. Even for a modest wolf model with 434 verticies, 434 texCoords, 434 normals, and 843 faces, it produces a 5,000 line file! I’m exploring options to reduce this, but it’s unlikely to get much better without exploring compression (and then decompressing inside a shader).

For now, compile times take a few minutes, but the results are worth it! Plus, Shadron is smart enough where if you don’t touch the code that renders the model, it won’t recompile the large input shadron file.

Post Metadata


100 Days of Graphics