-
Notifications
You must be signed in to change notification settings - Fork 1
Graphics
Namespace: WIDVE.Graphics
Location: WIDVE Unity Scripts/Graphics
The Graphics namespace contains an assortment of scripts and objects designed to make simple graphics techniques in Unity a bit easier to use.
Most of the Graphics scripts will work in any rendering pipeline. Any scripts that are specific to a single pipeline are placed in a subfolder with its own assembly definition file. These scripts will not be included in a project unless their Define Constraint is present in the Project Settings. Current render pipeline scripts and their define constraints are listed below.
| Render Pipeline | Define Constraint |
|---|---|
| UniversalRenderingPipeline | WIDVE_URP |
The ShaderProperties objects serves as a reference for all Color, float, Vector, and Texture properties of a specific shader. This is necessary because the code for accessing shader properties is accessible only within the Unity Editor, and not available when making a build. Any script or component that needs to access or edit a shader's properties should use a ShaderProperties object to do so.
Each ShaderProperties object references a single shader. Therefore, for each shader that needs to be used, a new ShaderProperties object must be created. This object should be given the same name as the original shader so it is easy to find. To set up the new ShaderProperties object, drag a shader into its SourceShader field and press the Set Properties button. All properties available to that shader will be cataloged and saved in the ShaderProperties object for future use.
Property names and settings are collected via script and should not be edited by hand. The only exception to this is certain float properties which represent an enum. There is an IsEnum checkbox for float properties that should be checked if the float property represents an integer enum value, and left unchecked otherwise. This is necessary because normal float values will be interpolated when interpolating between different materials, while enum float values will simply be set (as any interpolated value would likely be invalid). The code attempts to identify enum values by searching for Unity's [Enum...] attribute in the shader code, but if the shader code has an unusual structure this attribute may not be caught. In this case, the flag must be set manually.
| Property | Description |
|---|---|
SourceShader |
Properties will be collected from this shader |
ColorProperties |
List of all Color properties of the shader |
FloatProperties |
List of all float properties of the shader |
VectorProperties |
List of all Vector properties of the shader |
TextureProperties |
List of all Texture properties of the shader |
Note: not all Texture properties and operations are currently supported.
The FaceCamera component serves as a simple billboarding script. It makes objects face the camera in both the scene view and the game view.

The Fader script is a simpler version of the LerpMaterial script. Rather than lerp all properties of a material, the Fader script simply adjust the alpha value of all Color properties between 0 and 1 based on the provided value. Faders are controlled by an Interpolator.
If the material being faded is already a transparent material, then the FadeMode should be set to SingleMaterial. If the initial material is opaque, then the SeparateMaterials mode should be used. In this mode, two materials can be specified; both materials must use the same shader. The OpaqueMaterial will be used whenever the Fader's alpha value is set to 1, otherwise the TransparentMaterial will be used.
| Property | Description |
|---|---|
ShaderProperties |
The ShaderProperties object to use. Needs to match the shader used by the object's material in SingleMaterial mode. Needs to match the shader used by both materials in SeparateMaterials mode. |
Mode |
Specifies which objects will be affected. |
FadeMode |
Specifies whether the object uses a single material or separate materials when fading. |
MinAlpha |
Objects will not be given an alpha value lower than this value when fading out. |
MaxAlpha |
Objects will not be given an alpha value higher than this value when fading in. |

The Highlighter component activates an Interpolator when the object it is attached to get highlighted by a Selector. The Interpolator will lerp to 1 over the specified ActivationTime when the object is highlighted. Once the object is not longer highlighted, the Interpolator will lerp to 0 over the specified DeactivationTime.

The LerpColor component allows a color property on an object to interpolate between two colors. The LerpColor component is controlled by an interpolator.
| Property | Description |
|---|---|
ShaderProperties |
The ShaderProperties object to use. Needs to match the shader used by the object's material. |
Mode |
Specifies which objects will be affected. |
ColorProperty |
Selects which color property from the shader will be affected. |
ColorA |
This color will be used when the Interpolator value is 0. In most cases, should match the default color for the material. |
ColorB |
This color will be used when the Interpolator value is 1. |

The LerpGraphic component works the same way as the LerpColor component, except it affects colors on Graphic components, rather than materials. Most UI components will need to use LerpGraphic rather than LerpColor. The LerpGraphic component is controlled by an interpolator.

The LerpMaterial component is used to interpolate between two different materials. Both materials must use the same shader. The interpolation process uses a combination of MaterialPropertyBlocks and setting the object's material directly. All color, float, and vector properties will be interpolated, with the exception of enum values. Most material properties can be interpolated, but properties such as the Render Queue value and enum values cannot interpolate and will be set when switching from one material to another. The LerpMaterial component is controlled by an interpolator.
| Property | Description |
|---|---|
ShaderProperties |
The ShaderProperties object to use. Needs to match the shader used by MaterialA and MaterialB. |
Mode |
Specifies which objects will be affected. |
MaterialA |
This material will be used when the Interpolator value is 0. In most cases, should match the default material for the object. |
MaterialB |
This material will be used when the Interpolator value is 1. |

The LerpTMP component works the same way as the LerpColor component, except it affects colors on TextMeshPro components, rather than materials. The LerpTMP component is controlled by an interpolator.

The PerRendererColor component is used to override a single color property of a material on a per-object basis.

The PerRendererTexture component is used to override a single texture property of a material on a per-object basis.