Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -1,5 +1,5 @@
# Contact Shadows
The Contact Shadows [Volume Override](Volume-Components.md) specifies properties which control the behavior of Contacts Shadows. Contact Shadows are shadows that The High Definition Render Pipeline (HDRP) [ray marches](Glossary.md#RayMarching) in screen space inside the depth buffer. The goal of using Contact Shadows is to capture small details that regular shadow mapping algorithms fail to capture.
Contact Shadows are shadows that HDRP [ray marches](Glossary.md#RayMarching) in screen space, inside the depth buffer, at a close range. Use Contact Shadows to provide shadows for geometry details that regular shadow mapping algorithms usually fail to capture.


## Enabling Contact Shadows
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,140 +1,65 @@
# Example: How to create a custom rendering effect using the Render Objects Renderer Feature
---
uid: urp-how-to-custom-effect-render-objects
---

URP draws objects in the **DrawOpaqueObjects** and **DrawTransparentObjects** passes. You might need to draw objects at a different point in the frame rendering, or interpret and write rendering data (like depth and stencil) in alternate ways. The [Render Objects Renderer Feature](renderer-feature-render-objects.md) lets you do such customizations by letting you draw objects on a certain layer, at a certain time, with specific overrides.
# Example of creating a custom rendering effect using a Render Objects Renderer Feature in URP

The example on this page describes how to create a custom rendering effect with the Render Objects Renderer Feature.
The [Render Objects Renderer Feature](renderer-feature-render-objects) lets you draw objects at a specific point in the frame rendering loop. You can interpret and write rendering data such as depth and stencil in different ways, or draw a set of GameObjects at a certain time.

## Example overview
The following example uses a Render Objects Renderer Feature to draw a GameObject in a different color if it's behind other GameObjects.

The example on this page demonstrates how to implement the following effect:
![A character created from 3 simple capsules for the body and arms. The character is red, but as it moves behind a wall, the hidden parts are rendered blue.](../Images/how-to-render-objects/character-goes-behind-object.gif)

* There is a character in the Scene.
First, create a GameObject and attach it to a new [layer](https://docs.unity3d.com/Manual/Layers.html).

![Character](../Images/how-to-render-objects/character.png)
1. Create a GameObject in your scene.
1. In the **Inspector** window, open the **Layer** dropdown and add a new layer. You can call the layer **DrawBehind**.
1. Set the GameObject to the new layer.

* When the character goes behind GameObjects, Unity draws the character silhouette with a different Material.
Next, create a Render Objects Renderer Feature that renders only the new layer, on top of the scene.

![Character goes behind GameObjects](../Images/how-to-render-objects/character-goes-behind-object.gif)
1. In the **Project** window, select the [URP Renderer asset](../universalrp-asset) your project uses, for example **Settings** > **PC_Renderer**.
1. To create a Render Objects Renderer Feature, select **Add Renderer Feature** in the **Inspector** window, then select **Render Objects**.
1. To make the Renderer Feature draw only the layer with the GameObject, open the **Render Objects (Render Objects)** dropdown, then set **Layer Mask** to the layer.
1. Set **Event** to the **AfterRenderingOpaques** injection point. For more information about custom pass injection points, refer to [Custom Pass injection points](../customize/custom-pass-injection-points).

## Prerequisites
Next, adjust the Renderer Feature so it renders only the parts hidden behind other GameObjects, and in a different color.

This example requires the following:
1. Open the **Overrides** dropdown, then select **Depth** and set **Depth Test** to **Greater**.

* A Unity project with the URP package installed.
The Renderer Feature now only renders a pixel if its depth is greater than the current pixel in the depth buffer, which means the new pixel is behind another GameObject.

* The **Scriptable Render Pipeline Settings** property refers to a URP asset (**Project Settings** > **Graphics** > **Scriptable Render Pipeline Settings**).
1. [Create a new material](../shaders-in-universalrp) that uses the **Universal Render Pipeline/Unlit** shader.
1. Set the **Base Map** color to a color of your choice.
1. In the Renderer Feature, in the **Overrides** section, set **Material** to the material you created.

## Create example Scene and GameObjects<a name="example-objects"></a>
When you move the GameObject behind other GameObjects, Unity now renders the hidden parts in the color you selected.

To follow the steps in this example, create a new Scene with the following GameObjects:
![The red characters moves behind a wall. Unity renders the hidden parts using a blue material.](../Images/how-to-render-objects/character-depth-test-greater.gif)

1. Create a Cube. Set its **Scale** values so that it looks like a wall.
## Fix overlapping areas of a GameObject

![Cube that represents a wall](../Images/how-to-render-objects/rendobj-cube-wall.png)
If you use a complex GameObject, the Renderer Feature might draw overlapping parts as though they're hidden. This is because the depth of one part is greater than the overlapping part.

2. Create a Material and assign it the `Universal Render Pipeline/Lit` shader. Select the base color (for example, red). Call the Material `Character`.
![A capsule with a smaller capsule attached. The Renderer Feature renders part of the larger capsule using the blue material, because it's behind the smaller part.](../Images/how-to-render-objects/rendobj-depth-greater-see-through.png)

3. Create a basic character and assign it the Character Material. In this example, the character consists of three capsules: the big capsule in the center represents the body, and the two smaller capsules represent the hands.
To fix this issue, disable rendering the whole GameObject, and create a new Renderer Feature that renders the non-hidden parts. Follow these steps:

![The character consisting of three capsules](../Images/how-to-render-objects/character-views-side-top-persp.png)
1. In the URP Renderer asset, open the **Opaque Layer Mask** dropdown and disable the layer you added.

To make it easier to manipulate the character in the Scene, add the three Capsules as child GameObjects under the Character GameObject.
Unity now doesn't draw the layer in the opaque render pass. The Renderer Feature still draws the hidden parts, because it's in a different render pass.

![Character objects in Hierarchy](../Images/how-to-render-objects/character-in-hierarchy.png)
![Unity does not draw the character unless it's behind an object](../Images/how-to-render-objects/rendobj-character-only-behind.png)

4. Create a Material and assign it the `Universal Render Pipeline/Unlit` shader. Select the base color that you would like the character to have when it's behind GameObjects (for example, blue). Call the Material `CharacterBehindObjects`.
1. Add a new Render Objects Renderer Feature.
1. Set **Layer Mask** to the new layer, so this Renderer Feature draws the GameObject.
1. Set **Event** to the **AfterRenderingOpaques** injection point.
1. To avoid the first Renderer Feature affecting the depth calculations in the new Renderer Feature, disable **Write Depth** in the **Overrides** section of the first Renderer Feature.

Now you have the setup necessary to follow the steps in this example.
The first Renderer Feature draws the hidden parts, and the second Renderer Feature draws the rest of the GameObject.

## Example implementation
![A character created from 3 simple capsules for the body and arms. The character is red, but as it moves behind a wall, the hidden parts are rendered blue.](../Images/how-to-render-objects/character-goes-behind-object.gif)

This section assumes that you created a Scene as described in section [Example Scene and GameObjects](#example-objects).
## Additional resources

The example implementation uses two Render Objects Renderer Features: one to draw parts of the character that are behind other GameObjects, and another one to draw the parts of the character that are in front of other GameObjects.

### Create a Renderer Feature to draw the character behind GameObjects

Follow these steps to create a Renderer Feature to draw the character behind GameObjects.

1. Select a URP Renderer.

![Select a URP Renderer](../Images/how-to-render-objects/rendobj-select-urp-renderer.png)

2. In the Inspector, click **Add Renderer Feature** and select **Render Objects**.

![Add Render Object Renderer Feature](../Images/how-to-render-objects/rendobj-add-rend-obj.png)

Select the **Name** field and enter the name of the new Renderer Feature, for example, **DrawCharacterBehind**.

3. This example uses Layers to filter the GameObjects to render. Create a new Layer and call it **Character**.

![Create new Layer called Character](../Images/how-to-render-objects/rendobj-new-layer-character.png)

4. Select the **Character** GameObject and assign it to the `Character` Layer. To do this, open the Layer drop down and select `Character`.
![Assign Character GameObject to Character Layer](../Images/how-to-render-objects/rendobj-assign-character-gameobject-layer.png)

5. In the `DrawCharacterBehind` Renderer Feature, in **Filters** > **Layer Mask**, select `Character`. With this setting, this Renderer Feature renders GameObjects only in the Layer `Character`.

6. In **Overrides** > **Material**, select the `CharacterBehindObjects` Material.

The Renderer Feature overrides the Material of a GameObject with the selected Material.

![Layer Mask, Material Override](../Images/how-to-render-objects/rendobj-change-layer-override-material.png)

7. The intended behavior is that the Renderer Feature renders the character with the `CharacterBehindObjects` Material only when the character is behind other GameObjects.

To achieve this, select the **Depth** check box, and set the **Depth Test** property to **Greater**.

![Set Depth Test to Greater](../Images/how-to-render-objects/rendobj-depth-greater.png)

With these settings, Unity renders the character with the `CharacterBehindObjects` Material only when the character is behind another GameObject. However, Unity also renders parts of the character using the `CharacterBehindObjects` Material, because some parts of the character occlude the character itself.

![Unity renders parts of the character using the `CharacterBehindObjects` Material](../Images/how-to-render-objects/character-depth-test-greater.gif)

### Create an extra Renderer Feature to avoid the self see-through effect

The settings in the previous section result in the self see-through effect for the following reason:

* When performing the Opaque rendering pass of the URP Renderer, Unity renders all GameObjects belonging to the character with the `Character` Material and writes depth values to the Depth buffer. This happens before Unity starts executing the `DrawCharacterBehind` Renderer Feature, because, by default, new Render Objects Renderer Features have the value **AfterRenderingOpaques** in the **Event** property.

The **Event** property defines the injection point where Unity injects Render Passes from the Render Objects Renderer Feature. The event when URP Renderer draws GameObjects in the **Opaque Layer Mask** is the **BeforeRenderingOpaques** event.

* When executing the `DrawCharacterBehind` Renderer Feature, Unity performs the depth test using the condition specified in the **Depth Test** property. In the following screenshot, a bigger capsule occludes part of the smaller capsule, and the depth test passes for that part of the smaller capsule. The Renderer Feature overrides the Material for that part.

![Self see-through effect](../Images/how-to-render-objects/rendobj-depth-greater-see-through.png)

The following steps describe how to avoid such behavior and ensure that Unity draws all parts of the character with proper Materials.

1. In the URP asset, in **Filtering** > **Opaque Layer Mask**, clear the check mark next to the `Character` Layer.

![Clear the check mark next to the `Character` Layer](../Images/how-to-render-objects/rendobj-in-urp-asset-clear-character.png)

Now Unity does not render the character unless it's behind a GameObject.

![Unity does not render the character unless it's behind an object](../Images/how-to-render-objects/rendobj-character-only-behind.png)

2. Add a new Render Objects Renderer Feature, and call it `Character`.

3. In the `Character` Renderer Feature, in **Filters** > **Layer Mask**, select the `Character` Layer.

![Set Layer Mask Filter to Character Layer](../Images/how-to-render-objects/rendobj-render-objects-character.png)

Now Unity renders the character with the `Character` Material even when the character is behind GameObjects.

This happens because the `DrawCharacterBehind` Renderer Feature writes values to the depth buffer. When Unity executes the `Character` Renderer Feature, the pixels on the character appear to be in front of the pixels that Unity has drawn previously, and Unity draws on top of those pixels.

4. In the `DrawCharacterBehind` Renderer Feature, In **Overrides** > **Depth**, clear the **Write Depth** check box. With this setting, the `DrawCharacterBehind` Renderer Feature does not make changes to the depth buffer and the `Character` Renderer Feature does not draw the character when it's behind GameObjects.

![Clear Write Depth](../Images/how-to-render-objects/rendobj-render-objects-no-write-depth.png)

The example is complete. When the character goes behind GameObjects, Unity draws the character silhouette with the `CharacterBehindObjects` Material.

![Character goes behind objects](../Images/how-to-render-objects/character-goes-behind-object.gif)

With the extra `Character` Renderer Feature, Unity renders GameObjects as follows:

1. URP Renderer does not render the `Character` GameObject in the **BeforeRenderingOpaques** event, because the `Character` Layer is excluded from the **Opaque Layer Mask** list.

2. The `DrawCharacterBehind` Renderer Feature draws parts of the character that are behind other GameObjects. This happens in the **AfterRenderingOpaques** event.

3. The `Character` Renderer Feature draws parts of the character that are in front of other GameObjects. This happens in the **AfterRenderingOpaques** event, and after executing the `DrawCharacterBehind` Renderer Feature.
- [Renderer Objects Renderer Feature reference](renderer-feature-render-objects)
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Terrain Lit shader

URP uses the Terrain Lit shader for Unity Terrain. This shader is a simpler version of the [Lit shader](lit-shader.md). A Terrain can use a Terrain Lit Material with up to eight [Terrain Layers](https://docs.unity3d.com/Manual/class-TerrainLayer.html).
URP uses the Terrain Lit shader for Unity Terrain. This shader is a simpler version of the [Lit shader](lit-shader).

For more information about Terrain Layers, refer to [Terrain Layers](../class-TerrainLayer.md).

![A Terrain GameObject rendered with the Terrain Lit shader.](Images/terrain/terrain-rendered-with-terrain-lit.png)<br/>*A Terrain GameObject rendered with the Terrain Lit shader.*

Expand Down
31 changes: 31 additions & 0 deletions Packages/com.unity.visualeffectgraph/Documentation~/Arithmetic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Arithmetic Operators

Perform mathematical calculations on input data.

| **Page** | **Description** |
| --- | --- |
| [Absolute](Operator-Absolute.md) | Calculate the absolute value of an input. |
| [Add](Operator-Add.md) | Calculate the sum of all inputs. |
| [Divide](Operator-Divide.md) | Divide the first input sequentially by all other inputs. |
| [Fractional](Operator-Fractional.md) | Extract the fractional part of an input. |
| [Inverse Lerp](Operator-InverseLerp.md) | Calculate the fraction representing how far a value is between two values. |
| [Lerp](Operator-Lerp.md) | Calculate a linear interpolation between two values. |
| [Modulo](Operator-Modulo.md) | Calculate the remainder of dividing of one value by another. |
| [Multiply](Operator-Multiply.md) | Multiply all inputs together. |
| [Negate](Operator-Negate.md) | Multiply an input value by -1 to invert its sign. |
| [One Minus](Operator-OneMinus.md) | Subtract an input value from one. |
| [Power](Operator-Power.md) | Raise one input to the power of another input. |
| [Reciprocal](Operator-Reciprocal.md) | Calculate the result of dividing 1 by an input value. |
| [Sign](Operator-Sign.md) | Return whether an input is positive, negative, or 0. |
| [Smoothstep](Operator-Smoothstep.md) | Calculate smooth Hermite interpolation between two values. |
| [Square Root](Operator-SquareRoot.md) | Calculate the square root of an input. |
| [Step](Operator-Step.md) | Compare an input value to a threshold and return whether an input is above or below the threshold |
| [Subtract](Operator-Subtract.md) | Subtract one or more inputs from another input. |

## Additional resources

- [Clamp](Clamp.md)
- [Remap](Remap.md)
- [Math](Math.md)


15 changes: 15 additions & 0 deletions Packages/com.unity.visualeffectgraph/Documentation~/Attribute.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Attribute Blocks

Write values to the [Attributes](Attributes.md) of particles.

| **Page** | **Description** |
| --- | --- |
| [Curve](Block-SetAttributeFromCurve.md) | Write values to an attribute based on a sample from an Animation Curve or Gradient. |
| [Derived > Calculate Mass from Volume](Block-CalculateMassFromVolume.md) | Set the mass of a particle based on its scale and density. |
| [Map](Block-SetAttributeFromMap.md) | Sample data from textures and store them in attributes. |
| [Set](Block-SetAttribute.md) | Write values to an attribute directly, or use random modes to set attributes to random values. |

## Additional resources

- [Attributes](Attributes.md)
- [Standard Attribute Reference](Reference-Attributes.md)
18 changes: 18 additions & 0 deletions Packages/com.unity.visualeffectgraph/Documentation~/Bitwise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Bitwise Operators

Perform bitwise logical operations on inputs.

| **Page** | **Description** |
| --- | --- |
| [And](Operator-BitwiseAnd.md) | Perform a bitwise AND operation, which outputs 1 if both bits are 1. |
| [Complement](Operator-BitwiseComplement.md) | Perform a bitwise NOT operation to invert each bit. |
| [Left Shift](Operator-BitwiseLeftShift.md) | Shift an input value left by a specified number of bits. |
| [Or](Operator-BitwiseOr.md) | Perform a bitwise OR operation, which outputs 1 if either bit is 1. |
| [Right Shift](Operator-BitwiseRightShift.md) | Shift an input value right by a specified number of bits. |
| [Xor](Operator-BitwiseXor.md) | Perform a bitwise XOR operation, which outputs 1 if only one bit is 1. |

## Additional resources

- [Logic Operators](Logic.md)
- [Math Operators](Math.md)

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Collision Blocks reference

Configure how particles collide with shapes or the depth buffer.

| **Page** | **Description** |
| --- | --- |
| [Collide with AABox](Block-CollideWithAABox.md) | Define an axis-aligned box volume that particles collide with. |
| [Collide with Cone](Block-CollideWithCone.md) | Define a truncated cone volume that particles collide with. |
| [Collide with Depth Buffer](Block-CollideWithDepthBuffer.md) | Make particles collide with the depth buffer of a camera. |
| [Collide with Plane](Block-CollideWithPlane.md) | Define a flat plane with infinite extents that particles collide with. |
| [Collide with Signed Distance Field](Block-CollideWithSignedDistanceField.md) | Create a complex shape that particles collide with. |
| [Collide with Sphere](Block-CollideWithSphere.md) | Define a spherical volume that particles collide with. |

## Additional resources

- [Signed Distance Fields in the Visual Effect Graph](sdf-in-vfx-graph.md)
- [VFX Graph Learning Templates](https://www.youtube.com/watch?v=DKVdg8DsIVY) on the Unity YouTube channel
Loading