Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SG2]Imposter nodes and documents #7865

Open
wants to merge 21 commits into
base: sg2/main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 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
69 changes: 69 additions & 0 deletions com.unity.sg2/Documentation~/Imposter-Sample-Node.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Imposter Sample Node

## Description

Uses the UV coordinates generated by the Imposter UV node to sample an specific imposter texture.
This creates the illusion of a 3D object on a billboard object because the imposter texture's frame changes based on the camera direction and angle.
If the imposter object has more than one texture to sample (e.g. color, normal, mask, occlusion, etc,), multiple Imposter Sample nodes can be used.
## Ports

| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| Texture | Input | Texture2D | The texture asset to sample |
tracychen1234 marked this conversation as resolved.
Show resolved Hide resolved
| Sampler | Input | Sampler State | The texture sampler to use for sampling the texture |
| UV0 | Input | Vector2 | The virtual UV for the base frame |
| UV1 | Input | Vector2 | The virtual UV for the second frame |
| UV2 | Input | Vector2 | The virtual UV for the third frame |
| Grid | Input | Vector4 | The current UV grid, which is used to find the corresponding sample frames |
| Weights | Input | Float | The blending values in between the slected three frames|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a Vector4

| RGBA | Output | Vector3 | A vector4 from the sampled texture |
tracychen1234 marked this conversation as resolved.
Show resolved Hide resolved
| RGB | Output | Vector3 | A vector3 from the sampled texture |
| R | Output | Float | The r channel of the sampled texture |
| G | Output | Float | The g channel of the sampled texture |
| B | Output | Float | The b channel of the sampled texture |
| A | Output | Float | The a channel of the sampled texture |

## Controls

The Imposter Sample Node [!include[nodes-controls](./snippets/nodes-controls.md)]

<table>
<thead>
<tr>
<th><strong>Name</strong></th>
<th><strong>Sample Type</strong></th>
<th colspan="2"><strong>Description</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="3"><strong>Type</strong></td>
<td rowspan="3">Dropdown</td>
<td colspan="2">Select whether to sample three frames or one frame.</td>
</tr>
<tr>
<td><strong>Three Frames</strong></td>
<td>Blends between three frames to get the smoothest result.</td>
</tr>
<tr>
<td><strong>One Frame</strong></td>
<td>Calculates only one frame for better performance. UV1, UV2 and Weights inputs won't be shown.</td>
</tr>
</tbody>
</table>

## Generated code example

[!include[nodes-generated-code](./snippets/nodes-generated-code.md)], based on the selected Mode on the Imposter Sample Node node:

### ThreeFrames

```
ImposterSample( Texture.tex, TexelSize, Weights, Grid, UV0, UV1, UV2, Sampler.samplerstate, RGBA);
```

### OneFrame

```
ImposterSample_oneFrame( Texture.tex, TexelSize, Weights, Grid, UV0, UV1, UV2, Sampler.samplerstate, RGBA);
```
73 changes: 73 additions & 0 deletions com.unity.sg2/Documentation~/Imposter-UV-Node.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Imposter UV Node

## Description

The Imposter UV Node calculates the billboard position and the UV coordinates needed by the Imposter Sample node.
## Ports

| Name | Direction | Type | Description |
|:------------ |:-------------|:-----|:---|
| In Position | Input | Vector3 | The postion in Object space |
| In UV | Input | Vector4 | The UV coordinates of the mesh |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be a Vector2. We won't ever need the other two channels.

| Frames | Input | Float | The number of the imposter frames in each axis|
tracychen1234 marked this conversation as resolved.
Show resolved Hide resolved
| Size | Input | Float | The size of the imposter |
tracychen1234 marked this conversation as resolved.
Show resolved Hide resolved
| Offset | Input | Float | The offset value from the pivot |
tracychen1234 marked this conversation as resolved.
Show resolved Hide resolved
| Frame Clipping Threshold | Input | Float | The clamping value for the neighboring frames most useful when parallax mapping is enabled |
| Texture Size | Input | Float | The resolution of the texture. |
tracychen1234 marked this conversation as resolved.
Show resolved Hide resolved
| HemiSphere | Input | Boolean | If it's true, calculates the imposter grid and UVs base on hemisphere type.This is Useful if the imposter object will only be seen from above |
| Parallax | Input | Float | Parallax strength, if it equals to 0 than he parallax related control won't affect the outputs.|
| Height map | Input | Texture2D | The height map texture to sample |
| Sampler | Input | Sampler State | The texture sampler to use for sampling the texture |
| Height Map Channel | Input | Int | The channle of the height map to sample for parallax mapping, if any|
tracychen1234 marked this conversation as resolved.
Show resolved Hide resolved
| Out Positon | Output | Vector3 | The output billboard position |
| UV0 | Output | Vector2 | The virtual UV for the base frame |
| UV1 | Output | Vector2 | The virtual UV for the second frame |
| UV2 | Output | Vector2 | The virtual UV for the third frame |
| Grid | Output | Vector4 | The current UV grid, which is used to find the corresponding sample frames |
| Weights | Output | Vector4 | he blending values in between the slected three frames |


## Controls

The Imposter UV Node [!include[nodes-controls](./snippets/nodes-controls.md)]

<table>
<thead>
<tr>
<th><strong>Name</strong></th>
<th><strong>Sample Type</strong></th>
<th colspan="2"><strong>Description</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="3"><strong>Type</strong></td>
<td rowspan="3">Dropdown</td>
<td colspan="2">Select whether to sample three frames or one frame.</td>
</tr>
<tr>
<td><strong>Three Frames</strong></td>
<td>Blends between three frames to get the smoothest result.</td>
</tr>
<tr>
<td><strong>One Frame</strong></td>
<td>Calculates only one frame for better performance. UV1, UV2 and Weights outputs won't be shown.</td>
</tr>
</tbody>
</table>

## Generated code example

[!include[nodes-generated-code](./snippets/nodes-generated-code.md)], based on the selected Mode on the Imposter Sample Node node:

### ThreeFrames

```
ImposterUV(Pos, inUV, Frames, Offset, Size, imposterFrameClip, HemiSphere, Parallax, HeightMapChannel, ss, HeightMap, TextureSize, OutPos, Weights, Grid, UV0, UV1, UV2)
```

### OneFrame

```
ImposterUV_oneFrame(Pos, inUV, Frames, Offset, Size, imposterFrameClip, HemiSphere, Parallax, HeightMapChannel, ss, HeightMap, TextureSize, OutPos, Grid, UV0);
```
23 changes: 23 additions & 0 deletions com.unity.sg2/Documentation~/previews/ImposterSample.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Description
Uses the UV coordinates generated by the Imposter UV node to sample an specific imposter texture.
This creates the illusion of a 3D object on a billboard object because the imposter texture's frame changes based on the camera direction and angle.

## Inputs
**Texture** - The texture asset to sample.
**Sampler** - The texture sampler to use for sampling the texture.
**UV0** - The virtual UV for the base frame.
**UV1** - The virtual UV for the second frame.
**UV2** - The virtual UV for the third frame.
**Grid** - The current UV grid, which is used to find the corresponding sample frames.
**Weights** - The blending values in between the slected three frames.

## Output
**RGBA** - A vector4 from the sampled texture.
**RGB** - A vector3 from the sampled texture.
**R** - The r channel of the sampled texture.
**G** - The g channel of the sampled texture.
**B** - The b channel of the sampled texture.
**A** - The a channel of the sampled texture.

## Controls
**Sample Type** - Select whether to sample three frames or one frame, three frames for smoother result, one frame for better performance.
26 changes: 26 additions & 0 deletions com.unity.sg2/Documentation~/previews/ImposterUV.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## Description
Calculates the billboard positon and the virtual UVs for sampling.

## Inputs
**InPosition** - The postion in Object space.
**In UV** - The UV coordinates of the mesh.
**Frames** - The number of the imposter frames in each axis.
**Size** - The size of the imposter.
**Offset** - The offset value from the pivot.
**Frame Clipping Threshold** - The clamping value for the neighboring frames most useful when parallax mapping is enabled.
**Texture Size** - The texture resolution.
**Height Map** - The height map texture to sample.
**Sampler** - The texture sampler to use for sampling the texture.
**Parallax** - Parallax strength.
**Height Map Channel** - The channle of the height map to sample for parallax mapping, if any.
**HemiSphere** - If it's true, calculates the imposter grid and UVs base on hemisphere type. Useful if the object is only seen from above.

## Output
**OutPosition** - The output billboard position.
**UV0** - The virtual UV for the base frame.
**UV1** - The virtual UV for the second frame.
**UV2** - The virtual UV for the third frame.
**Grid** - The current UV grid using to find the sample frames.

## Controls
**Sample Type** - Select whether to sample three frames or one frame, three frames for smoother result, one frame for better performance.
Loading