Friday, September 18, 2015

Day 26: Culling Me Softly

Today was another day to hop into the strange ways of Cg shaders in Unity. Previously, I had just produced a purple surface for the ball. After learning about Properties as uniforms and being able to customize the input and output structures, I was able to create a texture whose color varied based on its world position in space, which showed the interpolation of colors across vertices.

I also looked at how certain values can be debugged by setting everything to a certain color or making only one color stick out, but I can't help but feel it amounts to tracing statements. I'll probably give a throw at the way Visual Studio debugs Cg shaders since it worked well with me on HLSL.

I also learned how discarding works in Cg and differentiating between back and front face culling. Thankfully it's only a single statement (oddly different from the call of an actual programming language; all you have to do is say Cull Off, Cull Front, or Cull Back before CGPROGRAM runs), and we can view the triangles above a y value of 0 either by all triangles with culling off:

Or differentiate between both the front facing triangles on the outside with back faces culled and the inside triangles with front faces culled:


The neat thing about this is that we can produce two culls at once by passing through the shader multiple times (Multipass!). This may be a bit more expensive, but allows us to color the inside as well as the outside of the sphere by way of coloring each side of the triangle.

Next up? Transparency! Should be a quick, fun thrill.

No comments:

Post a Comment