How are shaders given values in Unity´s built in Bloom image effect.

Hi all,
the scripts for Unity’s built in Bloom effect can be found in Bloom.js which can be imported as part of the standard image effects package.

This script has various shaders like public var screenBlendShader : Shader;

I cannot figure out where or how this shader is given a value . Is it automagically mapped through some intricate naming scheme, or what is going on ?

Any help is appreciated.

/Magnus

You can’t set parameters on a shader instance*. You need to create a material that uses the shader then set parameters on that material. Unity’s image effects will all do this. Graphics.Blit will also set up some default parameters (eg. _MainTex) on any material you pass into it.

*Although there is a static API for setting globals.

Edit: I may have misunderstood which values you were referring to. You can provide default values for serialized properties of scripts using the inspector. These default values get saved in the script meta data and can be exported into packages.

Hi Gibbonator,
thanks !

It is the last type of values you mention to which I am referring. So basically a field reference on a class to a shader.

Usually i would set this in the inspector of by doing something like Shader shader = Shader.Find(“OMG/TotallyNiceShader”); on the class.

What i don´t get is how the public var screenBlendShader : Shader reference in the Bloom.js file is given a value.

Basically I drop the script on my camera and the screenBlendShader is just magically set. Is there some meta data associated with the script which sets the shader reference ? Lets say I wanted to do the same with one of my own scripts. How would I do that ?

Thanks !

bump

Select the script in the Project view. You should be able to see the default assigned there.
On phone now so can’t verify. It may also get defaults from a Reset() method.

Edit; just to clarify, select the actual .js script file and look at the inspector.