Triplanar 3

Its been a while since I posted a shader, so here’s one that i did a while back for design purposes. Its a Triplanar shader that does not require a texture – the checker pattern is the result of a little shader math. This is great for layout purposes, as you can simply stretch and skew an object all you want, and still get an accurate read on how it sizes up on other objects in the level.
The shader is Unlit and is quite simple compared the the other Triplanar shaders I wrote, since it is used for prototyping more than anything. It does use blending, although you could try cutoff blending like in Triplanar 2.

triplanar3.cgfx
File Size: 3 kb
File Type: cgfx

Download File


triplanar3.shader
File Size: 3 kb
File Type: shader

Download File


CG Shaders -Team Fortress 2

I actually first attempted this years ago when I was first learning shaders but looking back on it I missed out on a few details. Today I know a bit more and can read the equations a bit better, so I think that this is pretty close. I downloaded the mesh and textures for the heavy, which made things a lot more clear as well.There were definitely some things to be learned from this, namely how important specular and rim lighting are for the TF2 look. They use 2 phong highlights both of which are modulated by a rim falloff, in addition to constant rim lighting. They also use a specular exponent map, which adjusts the power of the specularity on a per pixel level. This causes very broad highlights that are also varied across the surface and gives it a very distinctive look. Hopefully I’ll be able to use what i learned on some of my other shaders.

Maya CGFX File:

tf2.cgfx
File Size: 10 kb
File Type: cgfx

Download File


Unity SHADER File:

tf2.shader
File Size: 12 kb
File Type: shader

Download File


CG Shaders – Warped Lighting

This is one I just made up – not sure if anyone else is doing something similar, although i wouldn’t be surprised since its pretty simple. Basically I use a texture to warp the lighting value prior to sampling the light ramp. This causes a bit of disruption to the normally perfectly clean transitions between light values. Depending on the style you are going for this might be beneficial. Here is regular Ramped lighting and Warped Ramp Lighting
Depending on your texture you can achieve a variety of effects:
Liquification
Strokes
Patterning
Blotching

Maya CGFX File:

warpedlighting.cgfx
File Size: 11 kb
File Type: cgfx

Download File


Unity SHADER File:

warpedlighting.shader
File Size: 11 kb
File Type: shader

Download File


CG Shaders – Crosshatching

I figured i would give crosshatching a shot, since it seems to be semi-important. A lot of games with a non-photo-real art style use this to varying degrees but it is often done directly on the texture. This means that it will not actually react to the light at all. This paper presented a technique that is reactive to light, by using varying amounts of hatching and blending between them.For simplicity’s sake i only used 3 textures instead of 6, since i hatching on light areas is confusing. Instead I just use a pure white for the brightest 2 areas and begin hatching in the midtones using the heaviest hatching on the darkest 2 areas, where its hard to notice the difference. This allows me to cram everything into the RGB channels of a single texture before splitting them out and recombining them in the shader. I used the blending technique found here to calculate the hatching level.

It also includes a offset and intensity modifier to let you control the shadow level where hatching starts and the intensity of the hatching respectively. Here it is pushed back into only the deepest shadows with the original hatching texture and an alternate I made (I found you could use it for more types of tone mapping than hatching). I like this because i think it helps the shapes in the deeper shadows read a bit better.
I did have to rip out multiple lights from the shader to keep it the same between Maya and Unity, as there is no way to make this work that i know of with multiple lights in Unity. I may try some fakery later to get them back, but i wasn’t totally happy with them anyway – Ramped lighting doesn’t seem to blend additively very well, but that may just be my ramps.

Maya CGFX File:

crosshatch.cgfx
File Size: 11 kb
File Type: cgfx

Download File


Unity SHADER File:

crosshatch.shader
File Size: 11 kb
File Type: shader

Download File


CG Shaders – Outline 2

Minor update with 100% more Fresnel Outlines! In order to allow thick outlines, I added an intensity modifier which allows me to skip powering entirely. Since we need sharp outlines, I just floor the resulting value and let the intensity modifiers do the work adjusting the thickness instead. Like the geometry outlines, it can also be thickened according to the light. Here it is with the geometry outline in blue and Fresnel outlines in red
I’m still not completely satisfied with these. Because of Unity’s light system it costs 4 passes  when it should rightfully only cost 2 like it does in Maya . Additionally it misses a lot of interior lines that a more robust solution might be able to catch. In any case, here it is. If i improve it in the future i’ll post that as well.

Maya CGFX File:

outline2.cgfx
File Size: 9 kb
File Type: cgfx

Download File


Unity SHADER File:

outline2.shader
File Size: 16 kb
File Type: shader

Download File


CG Shaders – Outline

This is a fairly simple extension of my ramp shader. It uses an early pass to inflate the vertices via the vertex normal and color them. This produces an outline that is rendered in world space and fades appropriately in the distance.  Potentially you could model your own outline mesh and get similar results but this is somewhat impractical for building a whole game, so its worth knowing how to do.
You can also shift the outline according to the light direction, giving you thicker outlines in the shadows.
I plan to explore a other methods to generate other lines, as this is only really useful for thin contour lines. Frensel lines should be able to enhance these, bridging gaps and thickening them up.

Maya CGFX File:

outline.cgfx
File Size: 8 kb
File Type: cgfx

Download File


Unity SHADER File:

outline.shader
File Size: 12 kb
File Type: shader

Download File