Posts

Showing posts with the label fragment

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

fragment vertex/vertex fragment shaders in unity

Fragment Vertex shaders are a different beast to surface shaders. We are able to access vertex data and control pixels in much finer detail. Below is a simple frag/vert shader. The framework is similar to the surface shaders we've been looking at, only the usual CGPROGRAM block now sits within a Pass block, that lives in the SubShader. I haven't included a Properties block, but that remains unchanged. The first thing is we now have #pragmas for the frag and vert functions and also #include the UnityCG.cginc file, that contains lots of handy shader functions There are other files we can include when we are working with lighting and shadows. Next up in the framework is the "appdata" struct - it essentially has all the vertex data that our 3d model holds. Here we've go the vertex variable as a float4 type, and we use the POSITION attribute. The "vertex" name can be arbitrary. You can also list other data, such as normals, color (multiple) and UVs & they...