Posts

Showing posts with the label shadow

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

light mapping notes

 A few things that weren't completely obvious at first/ good to know You can make an object invisible, but still cast a shadow - click on the shadows drop down, there is a "shadows only" option To enable an object for light map baking, set it to Static by ticking the box in the Inspector. Similarly, to make a light part of the bake, set its mode to "Baked" or "Mixed" (Inspector) Occlusion can be tweaked and baked - it's in the light map settings - should save you from adding a SSAO post processing layer! An object can contribute to baked global illumination, you need to tick the box that allows this (in the mesh renderer) In the light map settings, the Multiple Importance Sampling check box can speed up a bake, but lead to noisy results. Lightmaps can actually have different UVs to the standard texture. Unity can autogenerate these  if you choose so, in the FBX import settings. If you wish to make these yourself, assign them to the UV1 set. Standar...