shader development in unity

Saturday, August 22, 2009 | |

In the last weeks I concentrated on shader development, especially the skin shading.

I hadn't used ShaderLab, the shader language of Unity, before and the syntax was... well, a little bit tricky in the beginning. But after studying the build-in shaders a little bit, I quickly became familiar with it. The basic concepts of vertex- and pixelshaders I already knew from the time I wrote shaders in HLSL for a small testgame with Microsofts XNA Framework.

The first thing I implemented was a replacement for the ambient light. Ambient light is in most cases doesn't look very pretty, because it's the same color and brightness just everywhere. Instead of that I used a cubemap, to look up the color for each direction with something like this:

half3 col = tex2D(_ColorTex, i.uv).rgb * _BaseColor.rgb;
half3 ambient = texCUBE( _AmbientCube, i.worldNorm ).rgb;
return float4(col * ambient, 1);

The Cubemap I use is created from an environment map, which was filtered with free tool from ATI called CubeMapGen. To calculate all the light that comes from one direction, I used a Base Filter Angle of 180° and the Filter Type "Cosine". The result will basically look like a lambert shader with global illumination (without shadows or occlusion of course).

On the left:
Diffuse shader with a static value for the ambientlight
(+ directional light)

On the right:
Diffuse shader with a variable ambientlight sampled from a cubemap
(+ directional light)

0 comment(s):

Post a Comment

Note: Only a member of this blog may post a comment.