Wednesday, February 6, 2013

Week 2 - Hatching

This week we talked about lighting and we touched on the concept of toon shading.

When I went through some of the shader assignments I saw that one of the toon shader upgrades was to add hatching support. I looked up screenshots from a hatching shader and found several images similar to the one below.


The first step is to create multiple textures of differing density. One texture with very low density, up to one with high density. Next we want to calculate the diffuse (intensity) of the surface based on the direction of the light. Based on the intensity of the light at that point, we can assign 1 scalar, acting as a weight, for each texture. In our fragment shader we sample all the textures at the same specified texture coordinate, each time we sample we multiply by the assigned weight:

vec4 color1 = texture2D(HatchTexture1,texCoord) * weight1;

Once we have sampled all the textures we add all the colors together per fragment. This should give us the line drawing effect we are looking for.


No comments:

Post a Comment