Posts

Showing posts with the label pass

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...

Fragment/Vertex shader Casting and Receiving shadows

 There're two parts to this - lets focus on the first Pass block -  The first block allows the shader to receive shadows. The previous ones were all flat. The LightMode tag sets it to Forward lighting, which changes it from the default Deferred lighting that Unity uses.  We have some extra #pragma stuff that I don't really understand - apparently it's there so we can have complete control over the lighting? Some extra #includes are present as well...more functions to do with lighting. In our appdata struct we're using the NORMAL now. In the v2f we call the "position"  variable "pos", because later on a TRANSFER_SHADOW function requires that specific name within the struct. It won't recognise "vertex". There's also a SHADOW_COORDS variable, to tell the shadow where to go. In our vert function we convert the vertex to screenspace, calculate its worldspace normal, then get the dot product between the normal & the light's positi...

Stencil Buffers Pt 1 - cut a hole in an object

This is quite cool stuff. You can essentially cut out areas of other objects, by using the stencil buffer There are two shaders below- one for the "hole" or the "window", the "cutter outer", whatever you wish to call it. And one for the wall or thing you're "cutting" into. The main CGPROGRAM block remains simple, the changes happen at the start of the SubShader. Firstly we ensure we draw the hole before the geometry, by giving it the Geometry-1 queue tag. The smaller the value, the sooner an object is drawn. We disable writing to the zbuffer for the whole subshader, as well as with colors (colormask 0). The stencil has it's own sub block - in it, we define Ref with the value of 1. Comp is the comparision which compares the object's pixels with Ref. We "always" want to write to the stencil buffer using our cutter object's pixels, so it "always" passes this comparison & does what the Pass operation wants - i...

hologram shader, Pass, colormask, transparent

This shader creates a fresnel style inner rim glow on an object. It uses the dot product between the surface normal and the view direction vector. To give it a transparent/ghostly feel we set the alpha to the rim-glow effect. In order to actually get it transparent, we add "alpha:fade" to our #pragma and also assign the Transparent Queue tag. A "problem" that arises is that we can see the internal faces of an object when it has a complex shape -eg the inside of the mouth cavity. This *might* be desirable in a true x-ray shader? However, if you wanted to have the outer surface occlude the inner parts, then we must add a Pass. This will take place before the pass that occurs within the CGPROGRAM. We add a Zwrite On within the pass, which enables writing to the depth buffer and set the ColorMask to 0, so we don't write any colour data - only the Z info.      Shader "Dave/Hologram"{     Properties{         _RimColor("Rim Color", co...