

In the node, however, we only need to reference the main function name.
Unity 2019 shadow cascades code#
Since we’re defining our own function, we need the source code to tell the compiler which precision format our function uses. This is because the Shader Graph compiler appends the precision format to each function name. You’ll notice that the include file has `_half` at the end of the function name, but our name option doesn’t. In the Name box, we’ve entered “MainLight”. Now, we need to tell the node which function to use. In the Source input, navigate to the include file, and select the Asset to reference. Now that we have our inputs and outputs, we can reference the include file. Then, add the new input for WorldPos (world position). Add two new outputs for DistanceAtten (distance attenuation) and ShadowAtten (shadow attenuation). This function includes some new input and output data, so let’s go back to our Custom Function node and add them. ShadowAtten = mainLight.shadowAttenuation Light mainLight = GetMainLight(shadowCoord) ĭistanceAtten = mainLight.distanceAttenuation Half4 shadowCoord = TransformWorldToShadowCoord(WorldPos) Half4 shadowCoord = ComputeScreenPos(clipPos) Half4 clipPos = TransformWorldToHClip(WorldPos) The function looks like this: void MainLight_half(float3 WorldPos, out half3 Direction, out half3 Color, out half DistanceAtten, out half ShadowAtten) For now, we’ll only focus on the `MainLight_half` function. Start by opening the `CustomLighting` include file in the Assets > Include folder of the project. This also means that we have one unified location to debug the code from. This lets you author more complicated functions in a proper code editor before injecting it into the graph. Our next function gets attenuation values from the main light in addition to the direction and color.Īs this is a more complicated function, let's switch to file mode, and use an HLSL include file.
Unity 2019 shadow cascades how to#
Since we now know how to get light data using the Custom Function node, we can expand on our function. Right-click the node, select Create Group from Selection, and then rename the group title to describe what your node is doing. Now, it’s a good idea to add this node to a group so that you can mark down what it’s doing. Your custom function should now look like this: #if SHADERGRAPH_PREVIEW We can use this information to assign the Direction and Color outputs. Use the built-in function `GetMainLight()` from the LWRP package. This is where we actually get our light data. Next, we’ll use `#else` to tell the compiler what to do when not in a preview. Start by defining your fallback values for the output ports.

`#ifdef` tells the compiler to use different code in different situations. Because the preview boxes on nodes don’t have access to light data, we need to tell the node what to display on the in-graph preview boxes. First, we’re going to use a flag called `#ifdef SHADERGRAPH_PREVIEW`.
