Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class KeywordFloatRename
public float setVal, unsetVal;
}
List<KeywordFloatRename> m_KeywordFloatRename = new List<KeywordFloatRename>();
Dictionary<string, (string, System.Func<float, bool>)> m_ConditionalFloatRename;

/// <summary>
/// Type of property to rename.
Expand Down Expand Up @@ -220,6 +221,20 @@ public virtual void Convert(Material srcMaterial, Material dstMaterial)

dstMaterial.SetFloat(t.property, srcMaterial.IsKeywordEnabled(t.keyword) ? t.setVal : t.unsetVal);
}

// Handle conditional float renaming
if (m_ConditionalFloatRename != null)
{
foreach (var (oldName, (newName, condition)) in m_ConditionalFloatRename)
{
if (srcMaterial.HasProperty(oldName) &&
condition(srcMaterial.GetFloat(oldName)) &&
dstMaterial.HasProperty(newName))
{
dstMaterial.SetFloat(newName, 1.0f);
}
}
}
}

/// <summary>
Expand Down Expand Up @@ -316,6 +331,17 @@ public void RenameKeywordToFloat(string oldName, string newName, float setVal, f
m_KeywordFloatRename.Add(new KeywordFloatRename { keyword = oldName, property = newName, setVal = setVal, unsetVal = unsetVal });
}

/// <summary>
/// Rename a float property conditionally based on its value
/// </summary>
/// <param name="oldName">Old property name</param>
/// <param name="newName">New property name</param>
/// <param name="condition">Condition function that takes the float value and returns true if renaming should occur</param>
protected void RenameFloat(string oldName, string newName, System.Func<float, bool> condition)
{
(m_ConditionalFloatRename ??= new Dictionary<string, (string, System.Func<float, bool>)>())[oldName] = (newName, condition);
}

static MaterialUpgrader GetUpgrader(List<MaterialUpgrader> upgraders, Material material)
{
if (material == null || material.shader == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ HDRP implements an exponential fog, where density varies exponentially with dist
Instead of using a constant color, fog can use the background sky as a source for color. In this case, HDRP samples the color from different mipmaps of the cubemap generated from the current sky settings. The chosen mip varies linearly between the lowest resolution and the highest resolution mipmaps, depending on the distance from the Camera and the values in the fog component’s **Mip Fog** properties. You can also choose to limit the resolution of the highest mip that HDRP uses. Doing this adds a volumetric effect to the fog and is less resource intensive to use than actual volumetric fog.

Optionally, you can enable volumetric fog for GameObjects close to the camera. It realistically simulates the interaction of lights with fog, which allows for physically plausible rendering of glow and crepuscular rays, which are beams of light that stream through gaps in objects like clouds and trees from a central point.

**Note:** Volumetric fog doesn't support [light rendering layers](Light-Layers).
Original file line number Diff line number Diff line change
Expand Up @@ -457,18 +457,17 @@ private void Update()

private bool IsDirty()
{
if (lightCullResult == null)
return false;

bool isDirty = false;

// Refresh if layers are added or removed
isDirty |= Light2DManager.GetCachedSortingLayer().Count() != batchList.Sum(x => x.LayerNames.Count());
isDirty |= cachedSceneHandle != SceneManager.GetActiveScene().handle;
isDirty |= cachedCamPos != Camera.main?.transform.position;

if (lightCullResult != null)
{
isDirty |= totalLightCount != lightCullResult.visibleLights.Count();
isDirty |= totalShadowCount != lightCullResult.visibleShadows.Count();
}
isDirty |= totalLightCount != lightCullResult.visibleLights.Count();
isDirty |= totalShadowCount != lightCullResult.visibleShadows.Count();

return isDirty;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ public StandardUpgrader(string oldShaderName)
}

RenameFloat("_Mode", "_Surface");
RenameFloat("_Mode", "_AlphaClip", renderingMode => renderingMode == 1.0f);
RenameTexture("_MainTex", "_BaseMap");
RenameColor("_Color", "_BaseColor");
RenameFloat("_GlossyReflections", "_EnvironmentReflections");
Expand Down
16 changes: 8 additions & 8 deletions Packages/com.unity.shadergraph/Documentation~/Branch-Node.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Branch Node
# Branch node

## Description
The Branch node adds a dynamic branch to the shader, which outputs a different value depending on whether the input is true or false.

Provides a dynamic branch to the shader. If input **Predicate** is true, this node returns input **True**, otherwise it returns input **False**. The **Branch Node** evaluates the **Predicate** per vertex or per pixel depending on shader stage. Both sides of the branch are evaluated in the shader, and the branch not used is discarded.
Both sides of the branch are evaluated in the shader, and the output from the unused path is discarded.

## Ports

| Name | Direction | Type | Binding | Description |
| **Name** | **Direction** | **Type** | **Binding** | **Description** |
|:----------|:----------|:---------------|:--------|:------------|
| Predicate | Input | Boolean | None | Determines which input to return. |
| True | Input | Dynamic Vector | None | Returned if **Predicate** is true. |
| False | Input | Dynamic Vector | None | Returned if **Predicate** is false. |
| Out | Output | Dynamic Vector | None | Output value |
| **Predicate** | Input | Boolean | None | The input to test the value of. If you input a float, all values are evaluated as `true` except `0`. |
| **True** | Input | Dynamic Vector | None | The value to output as **Out** if **Predicate** is true. |
| **False** | Input | Dynamic Vector | None | The value to output as **Out** if **Predicate** is false. |
| **Out** | Output | Dynamic Vector | None | Outputs either **True** or **False**. |

## Generated Code Example

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ This node applies a deformation to a normalized IrisUV coordinate to simulate th

| name | **Direction** | type | description |
| -------------------------- | ------------- | ------- | ------------------------------------------------------------ |
| **IrisUV** | Input | Vector2 | Position of the fragment to shade in object space. |
| **Pupil Radius** | Input | float | Direction of the incident ray in object space. Either from the camera in rasterization or from the previous bounce in ray tracing. |
| **Maximal Pupil Aperture** | Input | float | The normal of the eye surface in object space. |
| **Minimal Pupil Aperture** | Input | float | The index of refraction of the eye (**1.333** by default). |
| **Pupil Apertur** | Input | float | Distance between the end of the cornea and the iris plane. For the default model, this value should be **0.02** |
| **IrisUV** | Output | Vector2 | Position of the refracted point on the iris plane in object space. |
| **Iris UV** | Input | Vector2 | Normalized UV coordinates that can be used to sample either a texture or procedurally generate an Iris Texture. |
| **Pupil Radius** | Input | float | Radius of the pupil in the iris texture as a percentage. |
| **Pupil Aperture** | Input | float | Set the current diameter of the pupil opening. |
| **Maximal Pupil Aperture** | Input | float | Define the largest size the pupil opening can reach. |
| **Minimal Pupil Aperture** | Input | float | Define the smallest size the pupil opening can reach. |
Original file line number Diff line number Diff line change
@@ -1,65 +1,53 @@
# Custom Interpolators
# Add a custom interpolator

## Description
To pass custom data from the vertex shader to the fragment shader, add a custom interpolator to the vertex context of the Master Stack.

The Custom Interpolator feature provides fine-grained control over the specific calculations Shader Graph uses to bring data from the vertex stage to the pixel stage.

There are two target audiences for Custom Interpolators:
There are two target audiences for custom interpolators:

* Technical Directors and Lead Technical Artists setting up environments for their teams.
* Graphics programmers helping artists to optimize content performance.

**Note:** If you use the Built-In Render Pipeline, refer to [Input vertex data into a shader](https://docs.unity3d.com/Manual/SL-VertexProgramInputs.html) instead.

## Supported data types
Custom interpolators support float, vec2, vec3, and vec4 options.

Custom interpolators support float, vector 2, vector 3, and vector 4 types.

## Channel limits
The Custom Interpolator feature supports a maximum of 32 channels. A channel is equivalent to four floats. Each float is an interpolator variable.
Different platforms and GPUs have different interpolator variable limits. Exceeding the interpolator limitations of your target platform prevents your shaders from compiling. For detailed information about the number of interpolators supported by common interfaces, see the Unity documentation on [Shader semantics](https://docs.unity3d.com/Manual/SL-ShaderSemantics.html), and view the section **Interpolator count limits**. Test your Custom Interpolators on your target configuration to ensure that your content compiles properly.
Technical directors can set warnings and errors to help their team members avoid creating graphs with too many channels to be compatible with their target pipeline, platform, or GPU. See **Creating channel warnings and errors** below.

## How to use
To use this feature, create a Custom Interpolator block in the Vertex context of the Master Stack and set a name and a data type. Create a vertex node to write data to that interpolator. Use the interpolator in your graph, then connect your graph to the relevant block in the Fragment context.
These instructions include a contextual example illustrating the process of using a Custom Interpolator to fetch per-vertex data from a texture.
To read the HLSL you use to replicate this behavior with the Built In Render Pipeline, see the Unity documentation on [Shader semantics](https://docs.unity3d.com/Manual/SL-ShaderSemantics.html) and view the section **Vertex ID: SV_VertexID**.
A custom interpolator supports a maximum of 32 channels. A channel is equivalent to four floats. Each float is an interpolator variable.

### Creating channel warnings and errors
Different platforms and GPUs may have different limits, which might prevent your shaders compiling. Test your custom interpolators on your build targets to make sure your shaders compile properly. For more information, refer to the **Interpolator count limits** section in [Input vertex data into a shader](https://docs.unity3d.com/Manual/SL-VertexProgramInputs.html).

It is not possible to limit the number of channels a user can create in a Shader Graph. However, it is possible to create alerts to let users know when they are close to or exceeding a certain number of channels.
The **Warning Threshold** lets users know that they are approaching the channel limit, and the **Error Threshold** informs them if they have reached or surpassed that limit. The **Warning Threshold** value must be between 8 and 32 channels. The **Error Threshold** value must be higher than the **Warning Threshold**, and has a minimum value of 8 channels.
To configure these parameters, go to the Unity Editor [Project Settings](https://docs.unity3d.com/Manual/comp-ManagerGroup.html) menu and open the **Custom Interpolator Channel Settings**.
You can't limit the number of channels another user creates in a shader graph. However, to warn users about the limits, go to [Project Settings](https://docs.unity3d.com/Manual/comp-ManagerGroup.html) and set the following:

### Adding a Custom Interpolator block to the Master Stack
- **Warning Threshold** to tell users when they approach the channel limit. The range is 8 to 32 channels.
- **Error Threshold** to tell users when they reach or exceed the channel limit. The minimum value is 8 channels, and it must be higher than the **Warning Threshold**.

![](images/custom-interpolators-3.gif) ![](images/custom-interpolators-2.png)
## Add a custom interpolator block to the Master Stack

1. Right-click in the **Vertex** contex to create a block node.
1. Right-click in the **Vertex** context to create a block node.
2. Select **Custom Interpolator**.
3. Select a data type.
4. Enter a name for this interpolator.
3. In the **Node Settings** tab of the **Graph Inspector** window, select a data type, for example **Vector 4**.
4. In the same tab, enter a name for the interpolator.

In the illustrated example, you use the Vector 4 (vec4) data type.
## Write data to the interpolator

### Writing data to the interpolator
1. Right-click in your graph to create a node.
2. Select the type, for example **Vertex ID**.

![](images/custom-interpolators-1.png)
Custom interpolator blocks support many types of data, so you can connect the data from many other nodes including UV nodes and color nodes.

1. Right-click in your graph to create a node.
2. Select the type **Vertex ID**.
3. Connect this node to the Custom Interpolator block.
3. Connect the node to the custom interpolator block.

In the example, you write Vertex ID values from your graph into the Custom Interpolator.
The graph now writes Vertex ID values into the custom interpolator.

### Reading data from the interpolator
## Read data from the interpolator

1. Right-click in your graph to create a node.
2. Select **Custom Interpolator**.
3. Connect the Custom Interpolator node to the relevant block in the Fragment context.

![](images/custom-interpolators-4.png)

In this example, you connect to the **Base Color** block in order to pass the Vertex ID from the vertex shader to the fragment shader and use it as color output.
3. Connect the **Custom Interpolator** node to the relevant block in the **Fragment** context, for example **Base Color** to use the Vertex ID as color output.

### Deleting the block from the Master Stack
## Delete a custom interpolator

If you delete a Custom Interpolator which is associated with nodes that are still in your graph, Unity displays an alert. If you want to keep using these nodes, you can create a new Custom Interpolator and associate them with it. This prevents the alert from appearing.
If you delete a custom interpolator that's associated with nodes that are still in your graph, Unity displays an alert. If you want to keep using these nodes, you can create a new custom interpolator and associate the nodes with it. This prevents the alert from appearing.
19 changes: 10 additions & 9 deletions Packages/com.unity.shadergraph/Documentation~/Dither-Node.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# Dither Node
# Dither node

## Description
The Dither node adds a structured form of noise to the input. Use the Dither node to reduce the color bands that might appear if you move from a high number of colors to a low number (quantizing), or to simulate transparency by adding random alpha pixels to an opaque object.

Dither is an intentional form of noise used to randomize quantization error. It is used to prevent large-scale patterns such as color banding in images. The **Dither** node applies dithering in screen-space to ensure a uniform distribution of the pattern. This can be adjusted by connecting another node to input **Screen Position**.
The Dither node applies dithering in screen space to ensure a uniform distribution of the pattern. To change the space the node uses, connect another node to the **Screen Position** input, such as a [UV node](UV-Nodes.md).

This [Node](Node.md) is commonly used as an input to **Alpha Clip Threshold** on the [Master Node](Master-Stack.md) to give the appearance of transparency to an opaque item. This is useful for creating geometry that appears to be transparent but has the advantages of rendering as opaque, such as writing depth or being rendered in deferred.
To use a dither pattern for transparency, connect the Dither node to the **Alpha Clip Threshold** input in the [Master Stack](Master-Stack.md). As a result, when you adjust the overall alpha value of the material, some pixels are discarded because the alpha value is lower than their alpha clip threshold. This technique is useful for creating geometry that appears to be transparent but has the advantages of rendering as opaque, such as writing to the depth buffer or rendering using a deferred [rendering path](https://docs.unity3d.com/Manual/built-in-rendering-paths.html).

## Ports

| Name | Direction | Type | Binding | Description |
| **Name** | **Direction** | **Type** | **Binding** | **Description** |
|:------------ |:-------------|:-----|:---|:---|
| In | Input | Dynamic Vector | None | Input value |
| Screen Position | Input | Vector 4 | Screen Position | Coordinates used to apply dither pattern |
| Out | Output | Dynamic Vector | None | Output value |
| **In** | Input | Dynamic vector | None | The input to dither. The noise stays within the overall minimum and maximum range of the input values. |
| **Screen Position** | Input | Vector 4 | Screen Position | The coordinates Unity uses to calculate the dither pattern. For more information about the options, refer to the [Screen Position node](Screen-Position-Node.md). |
| **Out** | Output | Dynamic vector | None | The dithered output. |

## Generated Code Example
## Generated code example

The following example code represents one possible outcome of this node.

Expand All @@ -33,3 +33,4 @@ void Unity_Dither_float4(float4 In, float4 ScreenPosition, out float4 Out)
Out = In - DITHER_THRESHOLDS[index];
}
```

Loading