Posts

Showing posts with the label toon

slightly better outlines

  This approach to outlines is a bit more robust & adds outlines to areas within the shape's silhouette - eg details around say the nose and eyes, vs just the outline of the head. It utilises passes - first drawing the shape as normal with a standard struct input and void surf... then adding outlines on top using a vert-frag shader. This is quite cool to see both surface and vert frag shaders being mixed Things to note - we Cull the Front...We're essentially rendering the inside of the mesh as the outlines. I've found an explanation online about this shader, pasted below the code.. From the docs - UNITY_MATRIX_IT_MV Inverse transpose of model * view matrix.   I'm not entirely sure what is happening with this code - but I'm fairly sure we're taking the vertex normal and multiplying it by something, before getting it into screenspace.  Shader "Dave/Unlit/advancedOutline" {     Properties     {         _MainTex...

Custom toon shader lighting model thing

Here's a custom lighting model that uses a texture (ideally it will be a horizontal greyscale gradient) to create toonshading style shading bands.. You know the kind... Diffuse is calculated as in Lamber - dot product of surface normal and light direction the h value here is not the halfway vector - it is a float that takes the diffuse value, halves it and adds 0.5 to get a value between 0 and 1. Remember if the vector is facing away from the other in a dot product, it will return a value of minus one. -1 x 0.5 +0.5 will be 0. This h value is then assigned to a float2  "rh", which acts as a UV value for the variable "ramp". We now have a greyscale value from the texture. The final colour is calculated by multiplying the albedo by light colour and the ramp value. I guess you could also multiply it by the attenuation if you were after a non-flat shader too    Shader "Dave/ToonRamp"{     Properties{         _Color ("Color",color)=...