Extend or change the asset shader

The asset was designed with the most common use cases in mind. This means that the effect order and features have been carefully crafted to cover the most frequent project requirements. However, these carefully designed defaults may not perfectly match your specific project's unique needs. In such cases, you may want to modify a particular effect's implementation, change effect execution order, or add entirely new effects. Let's explore these customization options.

Before we start, let's cover the basics. The main shader file is located here:

In this file we'll add or change the base properties of the shader that the effects use. You don't need to worry about the other shader variants files since the asset will automatically update them based on the changes made to the base "AllIn13DShader" file. The main shader only defines the shader properties and shader passes, the rest of the code is scattered across these files:

But you only need to know about these: - AllIn13DShader_Features: Shader keywords that define the effects - AllIn13DShader_FragmentEffects: Fragment Shader or Color effects code - AllIn13DShader_AlphaEffects: Alpha or Transparency effects code - AllIn13DShader_VertexEffects: Vertex or Mesh effects code - AllIn13DShader_UVEffects: Uv or Texture Coordinates effects code - AllIn13DShaderCore: Order of the effects

Now that we've covered the basics, let's get into the steps to make custom changes to better match your requirements.

Modify effect implementation

First we'll need to localize the shader keyword of the effect we need to change. Say we want to change the Emission effect code. So we'll go into the Material Inspector, hover the mouse over the effect and we'll get the shader keyword name (the name of the effect in code):

Alternatively, you can also enter the main shader and look for "Hue", there you'll find the Keyword name in the [Toogle(SHADER KEYWORD)]:

Once you have that, open the relevant effects file. In this case, since it's a color effect, we'll open "AllIn13DShader_FragmentEffects" and look for the shader keyword "_HUE_SHIFT_ON" and we'll find:

And if we Ctrl+Click on the HueShift method or Ctrl+Shift+F "HueShift(" we'll find the effect implementation that we can change however we want:

Change the effect order

Just like before, we'll first locate the shader keyword, once we have it, we'll go into the "AllIn13DShaderCore" file. If we search again for the Hue effect shader keyword we'll find it here:

To change the order of the effect we just need to move this block or code up or down. For example if we want the Hue Shift to happen after the Contrast And Brightness effect, we'll move it to after the current line 391.

Add a new effect

The easiest way to add a new effect is to find a similar one and repicate what it's doing. Since we are using Hue Shift as an example let's make a new test color effect called "Color Tint Sine" that will do a tint animation using a sine wave. Probably a terrible effect, but let's do it for teaching purposes.

1.Let's start at the base "AllIn13DShader" file, look for the Hue Shift reference we are using and add the properties for our new effect:

Here I copied the whole Hue Shift block and started renaming and tweaking the properties to match the new effect requirements.

2.Next step is to declare the shader keyword. To do so we'll go into "AllIn13DShader_Features" and create the new shader keword that we already defined in step 1 (inside the [Toggle(SHADER KEYWORD)]:

3.Declare the shader properties so that the effect code can use them. To do so we scroll down in the AllIn13DShader_Features file, find how Hue Shift is doing it and replicate it with our new properties:

4.Finally we add the effect code. As we saw in Modify effect implementation we'll go to "AllIn13DShader_FragmentEffects", search again for the shader keyword "_HUE_SHIFT_ON" (the effect we are using as a template) and add the effect logic below like this:

This implementation is just an example. With these knowledge and using other effects as a template I'm sure you'll able to create any effect you wish. Also using ChatGPT or Claude may be helpful to you in this process since these tools are very good at following patterns to generate new content and code.

Last updated