Singularity/Library/PackageCache/com.unity.shadergraph@12.1.11/Documentation~/Calculate-Level-Of-Detail-T...
2024-05-06 11:45:45 -07:00

4.5 KiB
Raw Blame History

Calculate Level Of Detail Texture 2D node

The Calculate Level of Detail Texture 2D node takes an input Texture 2D and outputs the mip level of a Texture sample. This node is useful in situations where you need to know the mip level of a Texture, such as when you might want to modify the mip level before sampling in your shader.

An image of the Graph window, that shows a Calculate Level of Detail Texture 2D node.

The Calculate Level of Detail Texture 2D node also has a clamped and unclamped mode:

  • Clamped: The node clamps the returned mip level to the actual mips available on the Texture. The node uses the CalculateLevelOfDetail HLSL intrinsic function. Use this mode when you want to know which mip to sample your Texture from and restrict the result to an existing mip.

  • Unclamped: The node returns the ideal mip level, based on an idealized Texture with all its mips present. The node uses the CalculateLevelOfDetailUnclamped HLSL intrinsic function. Use this mode when you need a more generic value for your mip level.

For example, a Texture might only have 3 mips: a 64×64 mip, a 32×32 mip, and a 16×16 mip. When you use the Calculate Level Of Detail Texture 2D node in its Clamped mode, the node restricts the LOD output to one of the 3 mips on the Texture, even if the ideal mip level might be a smaller resolution, such as an 8×8 version. In its Unclamped mode, the node outputs the ideal 8×8 mip level, even though it doesn't exist on the Texture.

Note

On platforms where these HLSL functions don't exist, Shader Graph determines an appropriate approximation to use, instead.

Create Node menu category

The Calculate Level of Detail Texture 2D node is under the Input > Texture category in the Create Node menu.

Compatibility

[!includenodes-compatibility-all]

[!includenodes-fragment-only]

Inputs

[!includenodes-inputs]

Name Type Binding Description
Texture Texture 2D None The Texture to use in the mip level calculation.
UV Vector 2 UV The UV coordinate to use to calculate the Texture's mip level.
Sampler SamplerState None The Sampler State and corresponding settings to use to calculate the Texture's mip level.

Controls

[!includenodes-single-control]

Name Type Options Description
Clamp Toggle True, False When enabled, Shader Graph clamps the output mip level to the actual mips present on the provided Texture input. When disabled, Shader Graph returns an ideal mip level, based on an idealized Texture with all its mips present.

Outputs

[!includenodes-single-output]

Name Type Description
LOD Float The final calculated mip level of the Texture.

Example graph usage

In the following example, a Calculate Level of Detail Texture 2D node calculates the mip level of the Leaves_Albedo Texture for a set of UV coordinates and a specific Sampler State. It sends the calculated mip level for the Texture to the LOD input port on a Sample Texture 2D LOD node, which samples the same Texture:

An image of the Graph window, that shows a Texture 2D asset node connected to a Calculate Level of Detail Texture 2D node. The node sends the calculated mip level as an input to the LOD input port on a Sample Texture 2D LOD node.

[!includenodes-related]