Light

URP has only one main light. It must be the directional light. If it is not set in the Sun Source, then the brightest directional light is the main light. Test it with the light direction.

half4 color = half4(_MainLightPosition.xyz, 1.0);

Stencil

Manual: https://docs.unity3d.com/Manual/SL-Stencil.html YouTube: https://www.youtube.com/watch?v=-NB2TR8IjE8

The stencil buffer stores an 8-bit integer value for each pixel in the frame buffer. Stencil test happens before executing the fragment shader. It will compare the value with the reference value. If the test fails, it will not perform the depth test and the rest of the processing.

Stencil does 2 things:

  1. Ref, ReadMask, Comp configure the test the test is: (ref & readMask) comparison (stencilBufferValue & readMask)
  2. Ref, WriteMask, Pass, Fail, ZFail parameters to configure the stencil write operation Pass and Failcommands decide what to do with the test result. ZFail is for passing the stencil test but failing depth test.

Unity Shader Graph vs. ShaderLab

  • Scene Depth
SAMPLE_TEXTURE2D_X(_CameraDepthTexture, sampler_CameraDepthTexture, UnityStereoTransformScreenSpaceTex(uv)).r;

Mischellaneaous

unity_ObjectToWorld’s w components is the transform’s xyz.

Linear Color Space

The traditional color space is gamma, but linear gives more precise results. Textures tend to be saved in gamma color space, while shaders expect the linear color space.

In Gamma color space workflow, rendering pipeline use colors and textures in the game color space. Textures would not have gamma correction removed in a shader. Unchecking the sRGB (Color Texture) would bypass sRGB sampling in Color Space: Gamma. In linear color space workflow, we can work in linear color space if textures were created in linear and gamma color space. Gamma correction is removed in shaders.