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
Expand Up @@ -337,6 +337,8 @@ private void ClearEditorsList()
private void ForceSave()
{
EditorUtility.SetDirty(target);
AssetDatabase.SaveAssetIfDirty(target);
AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public LightStats GetLightStatsByLayer(int layerID, ref LayerBatch layer)
returnStats.totalNormalMapUsage++;
if (light.volumeIntensity > 0 && light.volumetricEnabled)
returnStats.totalVolumetricUsage++;
if (light.volumeIntensity > 0 && light.volumetricEnabled && RendererLighting.CanCastShadows(light, layerID))
if (RendererLighting.CanCastVolumetricShadows(light, layer.endLayerValue))
returnStats.totalVolumetricShadowUsage++;

returnStats.blendStylesUsed |= (uint)(1 << light.blendStyleIndex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,9 @@ internal static bool CanCastShadows(Light2D light, int layerToRender)
return light.shadowsEnabled && light.shadowIntensity > 0 && light.IsLitLayer(layerToRender);
}

private static bool CanCastVolumetricShadows(Light2D light, int endLayerValue)
internal static bool CanCastVolumetricShadows(Light2D light, int endLayerValue)
{
var topMostLayerValue = light.GetTopMostLitLayer();
return light.volumetricShadowsEnabled && light.shadowVolumeIntensity > 0 && topMostLayerValue == endLayerValue;
return light.volumeIntensity > 0 && light.volumetricEnabled && light.volumetricShadowsEnabled && light.shadowVolumeIntensity > 0 && light.GetTopMostLitLayer() == endLayerValue;
}

internal static void RenderLight(IRenderPass2D pass, CommandBuffer cmd, Light2D light, bool isVolume, int blendStyleIndex, int layerToRender, bool hasShadows, bool batchingSupported, ref int shadowLightCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ private static void Execute(RasterCommandBuffer cmd, PassData passData, ref Laye
layerBatch.endLayerValue != light.GetTopMostLitLayer()))
continue;

var useShadows = passData.layerBatch.lightStats.useShadows && layerBatch.shadowIndices.Contains(j);
var useShadows = (!passData.isVolumetric && passData.layerBatch.lightStats.useShadows) || (passData.isVolumetric && passData.layerBatch.lightStats.useVolumetricShadowLights);
useShadows &= layerBatch.shadowIndices.Contains(j);
var lightMaterial = passData.rendererData.GetLightMaterial(light, passData.isVolumetric, useShadows);
var lightMesh = light.lightMesh;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ internal class PassData
internal Renderer2DData rendererData;
internal TextureHandle[] shadowTextures;
internal TextureHandle shadowDepth;
internal bool isVolumetric;
}

public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData rendererData, ref LayerBatch layerBatch, int batchIndex, bool isVolumetric = false)
Expand All @@ -52,6 +53,7 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData

using (var builder = graph.AddUnsafePass<PassData>(!isVolumetric ? k_ShadowPass : k_ShadowVolumetricPass, out var passData, !isVolumetric ? m_ProfilingSampler : m_ProfilingSamplerVolume))
{
passData.isVolumetric = isVolumetric;
passData.layerBatch = layerBatch;
passData.rendererData = rendererData;
passData.shadowTextures = universal2DResourceData.shadowTextures[batchIndex];
Expand All @@ -73,6 +75,9 @@ public void Render(RenderGraph graph, ContextContainer frameData, Renderer2DData
var index = data.layerBatch.shadowIndices[i];
var light = data.layerBatch.lights[index];

if (data.isVolumetric && !RendererLighting.CanCastVolumetricShadows(light, data.layerBatch.endLayerValue))
continue;

// Shadow Pass
ExecuteShadowPass(cmd, data, light, i);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,13 @@ half3 ReconstructNormal(float2 uv, float linearDepth, float3 vpos, float2 pixelD
#if defined(_SOURCE_DEPTH_LOW)
return half3(normalize(cross(ddy(vpos), ddx(vpos))));
#else
float2 delta = float2(_SourceSize.zw * 2.0);

pixelDensity = rcp(pixelDensity);
float2 delta = float2(_SourceSize.zw * 2.0) * rcp(pixelDensity);

// Sample the neighbour fragments
float2 lUV = float2(-delta.x, 0.0) * pixelDensity;
float2 rUV = float2(delta.x, 0.0) * pixelDensity;
float2 uUV = float2(0.0, delta.y) * pixelDensity;
float2 dUV = float2(0.0, -delta.y) * pixelDensity;
float2 lUV = float2(-delta.x, 0.0);
float2 rUV = float2(delta.x, 0.0);
float2 uUV = float2(0.0, delta.y);
float2 dUV = float2(0.0, -delta.y);

float3 l1 = float3(uv + lUV, 0.0); l1.z = SampleAndGetLinearEyeDepth(l1.xy); // Left1
float3 r1 = float3(uv + rUV, 0.0); r1.z = SampleAndGetLinearEyeDepth(r1.xy); // Right1
Expand Down Expand Up @@ -316,17 +314,17 @@ half3 ReconstructNormal(float2 uv, float linearDepth, float3 vpos, float2 pixelD
// h == 1.0 && v == 1.0: p1 = right, p2 = up
// h == 0.0 && v == 1.0: p1 = up, p2 = left
// Calculate the view space positions for the three points...
half3 P1;
half3 P2;
float3 P1;
float3 P2;
if (closest_vertical == 0)
{
P1 = half3(closest_horizontal == 0 ? l1 : d1);
P2 = half3(closest_horizontal == 0 ? d1 : r1);
P1 = closest_horizontal == 0 ? l1 : d1;
P2 = closest_horizontal == 0 ? d1 : r1;
}
else
{
P1 = half3(closest_horizontal == 0 ? u1 : r1);
P2 = half3(closest_horizontal == 0 ? l1 : u1);
P1 = closest_horizontal == 0 ? u1 : r1;
P2 = closest_horizontal == 0 ? l1 : u1;
}

// Use the cross product to calculate the normal...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
if(intensity < 1)\
{\
half4 shadowTex = SAMPLE_TEXTURE2D(_ShadowTex, sampler_ShadowTex, input.shadowUV); \
half4 shadowIntensity = 1-max(shadowTex.r, shadowTex.g * 1-shadowTex.b);\
color.rgb = (color.rgb * shadowIntensity) + (color.rgb * intensity*(1 - shadowIntensity));\
half shadowIntensity = 1 - max(shadowTex.r, shadowTex.g * (1 - shadowTex.b));\
color.rgb = (color.rgb * shadowIntensity) + (color.rgb * intensity * (1 - shadowIntensity));\
}

#define TRANSFER_SHADOWS(output)\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ To add a [node](Node.md) to your shader graph, follow these steps:

To connect [ports](Port.md) between two existing [nodes](Node.md) or with the [master stack](Master-Stack.md), select and drag the desired port to the target.

The line resulting from that connection is called an [edge](Edge.md).
The line resulting from that connection is called a [wire](Wire.md).

You can only connect an output port to an input port, or vice-versa, and you can't connect two ports of the same node together.

Expand Down Expand Up @@ -64,6 +64,6 @@ To add a new [block node](Block-Node.md) to the [master stack](Master-Stack.md),

* [Nodes](Node.md)
* [Ports](Port.md)
* [Edges](Edge.md)
* [Wires](Wire.md)
* [Master Stack](Master-Stack.md)
* [Block nodes](Block-Node.md)
8 changes: 4 additions & 4 deletions Packages/com.unity.shadergraph/Documentation~/Data-Types.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Description

There are a number of **Data Types** in [Shader Graph](index.md). Each **Port** on a [Node](Node.md) has an associated **Data Type** that defines what edges can be connected to it. The **Data Types** have colors for usability, these colors are applied to ports and edges of that **Data Type**.
There are a number of **Data Types** in [Shader Graph](index.md). Each **Port** on a [Node](Node.md) has an associated **Data Type** that defines what wires can be connected to it. The **Data Types** have colors for usability, these colors are applied to ports and wires of that **Data Type**.

Some **Data Types** have associated [Property Types](Property-Types.md) for exposing these values to the [Inspector](https://docs.unity3d.com/Manual/UsingTheInspector.html) for [Materials](https://docs.unity3d.com/Manual/class-Material.html) that use the shader.

Expand Down Expand Up @@ -35,17 +35,17 @@ All **Vector** types can be promoted or truncated to match any **Vector** type [

## Dynamic Data Types

Some **Data Types** are dynamic. This means a port using these **Data Types** can change their underlying **Concrete Data Type** based on what **Data Type** is connected to it. By default, [Nodes](Node.md) using dynamic **Data Types** can only have one **Concrete Data Type**, meaning that once a connected edge has applied its **Data Type** to that port, all other **Dynamic Data Type** slots of that [Node](Node.md) will apply the same **Data Type**.
Some **Data Types** are dynamic. This means a port using these **Data Types** can change their underlying **Concrete Data Type** based on what **Data Type** is connected to it. By default, [Nodes](Node.md) using dynamic **Data Types** can only have one **Concrete Data Type**, meaning that once a connected wire has applied its **Data Type** to that port, all other **Dynamic Data Type** slots of that [Node](Node.md) will apply the same **Data Type**.

One notable exception to this is the [Multiply Node](Multiply-Node.md) which allows both **Dynamic** **Matrix** and **Vector** types.

### Dynamic Vector

The **Dynamic Vector** type allows connected edges of any **Vector** type. All connected edges are automatically truncated to the type with the lowest dimension, unless the lowest dimension is 1, in which case the **Float** is promoted.
The **Dynamic Vector** type allows connected wires of any **Vector** type. All connected wires are automatically truncated to the type with the lowest dimension, unless the lowest dimension is 1, in which case the **Float** is promoted.

### Dynamic Matrix

The **Dynamic Matrix** type allows connected edges of any **Matrix** type. All connected edges are automatically truncated to the type with the lowest dimension.
The **Dynamic Matrix** type allows connected wires of any **Matrix** type. All connected wires are automatically truncated to the type with the lowest dimension.

### Dynamic

Expand Down
11 changes: 0 additions & 11 deletions Packages/com.unity.shadergraph/Documentation~/Edge.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Description

Defines a **Float** value in the shader. If [Port](Port.md) **X** is not connected with an [Edge](Edge.md) this [Node](Node.md) defines a constant **Float**.
Defines a **Float** value in the shader. If [Port](Port.md) **X** is not connected with a [Wire](Wire.md) this [Node](Node.md) defines a constant **Float**.

## Ports

Expand Down
6 changes: 3 additions & 3 deletions Packages/com.unity.shadergraph/Documentation~/Node.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

## Description

A **Node** defines an input, output or operation on the Shader Graph, depending on its available [Ports](Port.md). A **Node** may have any number of input and/or output ports. You create a Shader Graph by connecting these ports with [Edges](Edge.md). A **Node** might also have any number of **Controls**, these are controls on the **Node** that do not have ports.
A **Node** defines an input, output or operation on the Shader Graph, depending on its available [Ports](Port.md). A **Node** may have any number of input and/or output ports. You create a Shader Graph by connecting these ports with [Wires](Wire.md). A **Node** might also have any number of **Controls**, these are controls on the **Node** that do not have ports.

You can collapse a **Node** by clicking the **Collapse** button in the top-right corner of the **Node**. This will hide all unconnected ports.

For components of a **Node** see:
* [Port](Port.md)
* [Edge](Edge.md)
* [Wire](Wire.md)

There are many available **Nodes** in Shader Graph. For a full list of all available **Nodes** see the [Node Library](Node-Library.md).

Expand All @@ -25,7 +25,7 @@ Right clicking on a **Node** will open a context menu. This menu contains many o
| Item | Description |
|:------------|:------------|
| Copy Shader | Copies the generated HLSL code at this stage in the graph to the clipboard |
| Disconnect All | Removes all edges from all ports on the **Node(s)** |
| Disconnect All | Removes all wires from all ports on the **Node(s)** |
| Cut | Cuts selected **Node(s)** to the clipboard |
| Copy | Copies selected **Nodes(s)** to the clipboard |
| Paste | Pastes **Node(s)** in the clipboard |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## Description

Some input [Ports](Port.md) might have **Port Bindings**. This means there is an expectation of the data that should be supplied to the [Port](Port.md), such as a **Normal Vector** or **UV**. However, a **Port Binding** only affects a [Port](Port.md) that does not have a connected [Edge](Edge.md). These [Ports](Port.md) still have a regular [Data Type](Data-Types.md) that define what [Edges](Edge.md) can be connected to them.
Some input [Ports](Port.md) might have **Port Bindings**. This means there is an expectation of the data that should be supplied to the [Port](Port.md), such as a **Normal Vector** or **UV**. However, a **Port Binding** only affects a [Port](Port.md) that does not have a connected [Wire](Wire.md). These [Ports](Port.md) still have a regular [Data Type](Data-Types.md) that define what [Wires](Wire.md) can be connected to them.

In practice this means that if no [Edge](Edge.md) is connected to the [Port](Port.md) the default data used in that port will be taken from its **Port Binding**. A full list of **Port Bindings** and their associated default options is found below.
In practice this means that if no [Wire](Wire.md) is connected to the [Port](Port.md) the default data used in that port will be taken from its **Port Binding**. A full list of **Port Bindings** and their associated default options is found below.

## Port Bindings List

Expand Down
10 changes: 5 additions & 5 deletions Packages/com.unity.shadergraph/Documentation~/Port.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

## Description

A **Port** defines an input or output on a [Node](Node.md). Connecting [Edges](Edge.md) to a **Port** allows data to flow through the Shader Graph node network.
A **Port** defines an input or output on a [Node](Node.md). Connecting [Wires](Wire.md) to a **Port** allows data to flow through the Shader Graph node network.

Each **Port** has a [Data Type](Data-Types.md) which defines what edges can be connected to it. Each data type has an associated color for identifying its type.
Each **Port** has a [Data Type](Data-Types.md) which defines what wires can be connected to it. Each data type has an associated color for identifying its type.

Only one edge can be connected to any input **Port** but multiple edges can be connected to an output **Port**.
Only one wire can be connected to any input **Port** but multiple wires can be connected to an output **Port**.

You can open a contextual [Create Node Menu](Create-Node-Menu.md) by dragging an edge from a **Port** with left mouse button and releasing it in an empty area of the workspace.
You can open a contextual [Create Node Menu](Create-Node-Menu.md) by dragging a wire from a **Port** with left mouse button and releasing it in an empty area of the workspace.

### Default Inputs

Each **Input Port**, a **Port** on the left side of a node implying that it is for inputting data into the node, has a **Default Input**. This appears as a small field connected to the **Port** when there is no edge connected. This field will display an input for the ports data type unless the **Port** has a [Port Binding](Port-Bindings.md). If a **Port** does have a port binding the default input field might display a special field, such as a dropdown for selecting UV channels, or just a label to help you understand the intended input, such as coordinate space labels for geometry data.
Each **Input Port**, a **Port** on the left side of a node implying that it is for inputting data into the node, has a **Default Input**. This appears as a small field connected to the **Port** when there is no wire connected. This field will display an input for the ports data type unless the **Port** has a [Port Binding](Port-Bindings.md). If a **Port** does have a port binding the default input field might display a special field, such as a dropdown for selecting UV channels, or just a label to help you understand the intended input, such as coordinate space labels for geometry data.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ To set the default precision for the entire graph to **Single** or **Half**, ope
Select a node to access its precision setting. The precision you set for a node determines the precision of the data types which that node uses for its calculations.

### Precision Inheritance
All nodes use the **Inherit** precision mode by default. In this mode, a node that has one or more edge connections takes on the precision mode of an incoming [edge](Edge.md). Nodes that do not have any edge connections take on **Graph Precision**. If you change the **Graph Precision** mode, the precision of those nodes also changes.
All nodes use the **Inherit** precision mode by default. In this mode, a node that has one or more wire connections takes on the precision mode of an incoming [wire](Wire.md). Nodes that do not have any wire connections take on **Graph Precision**. If you change the **Graph Precision** mode, the precision of those nodes also changes.

| **Inputs on the node** | **Final precision determined by inheritance** |
|------------------------------------|--------------------------------------------|
Expand All @@ -49,7 +49,7 @@ All nodes use the **Inherit** precision mode by default. In this mode, a node th

Simple inheritance refers to the inheritance behaviour of a node with only one precision type on its inputs.

In the figure below, Node A has the **Inherit** mode. Because it has no incoming edge, it takes the **Graph Precision**, which is **Half**. Node B also has the **Inherit** mode, so it inherits the **Half** precision mode from Node A.
In the figure below, Node A has the **Inherit** mode. Because it has no incoming wire, it takes the **Graph Precision**, which is **Half**. Node B also has the **Inherit** mode, so it inherits the **Half** precision mode from Node A.

![Diagram showing a simple precision inheritance.](images/precisionmodes1.png)

Expand All @@ -59,7 +59,7 @@ Complex inheritance refers to the inheritance behaviour of a node with multiple

A node reads precision settings from each input port. If you connect a node to several others with a variety of precision modes, the node with the highest resolution determines the precision mode for the group.

In the figure below, node D has the **Inherit** mode. It receives input from the adjacent edges via inputs 1 and 2. Node B passes the **Half** mode through input 1. Node C passes the **Single** mode through input 2. Because **Single** is 32-bit and **Half** only 16-bit, **Single** takes precedence, so Node D uses **Single** precision.
In the figure below, node D has the **Inherit** mode. It receives input from the adjacent wires via inputs 1 and 2. Node B passes the **Half** mode through input 1. Node C passes the **Single** mode through input 2. Because **Single** is 32-bit and **Half** only 16-bit, **Single** takes precedence, so Node D uses **Single** precision.

![Diagram showing a complex precision inheritance.](images/precisionmodes2.png)

Expand Down
Loading
Loading