torsdag 18 maj 2017

Textures

We have already made a huge improvement to our fur shader, simply by making the hair placement randomized.
Instead of calculating whether or not each fragment should be colored in the fragment shader, we now use a texture and apply that on the entire pig. By using a texture, we can make sure that the same dots get colored in on each shell (this is what creates the illusion of cohesive strands of hair), but we only have to make the calculations once. 
To do this, we had to add support for textures to our program. Funnily enough, we haven't implemented support for loading textures from images, the way textures are often used. For that we would have to import a library that can translate an image file to an array of numbers. What we do now is simply generate that list of numbers ourselves. Right now, our fur texture only stores opacities (which should be 1 for the hairy spots or 0 for the non-hairy spots) and we use a random function to determine the spots on the texture that become colored in. 
By using the same seed for our random function but taking fewer values, we get a second texture that has fewer hairs than the first one but all in the same positions as the first. By using the denser texture on the shells close to the body, and the sparser one further out, we create an effect of having hairs of different lengths. Since we haven't worked on lighting and varying the colors between the strands of hair, this is difficult to see right now. From the side, however, you can see that there are two distinct layers to the fur. We plan to add more soon. By using several different densities that get successively lower further out from the body, we can achieve quite natural looking fur. 

Today's bonus picture is from when we first started experimenting with code-generated textures and accidentally gave our piglet shoes and pants.

Inga kommentarer:

Skicka en kommentar