I have this (part of the) Shader file:
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _HighLumiTex;
float4 _HighLumiTex_ST;
v2f vert (appdata v)
{ [untouched from default] }
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
fixed4 highLumi = tex2D(_HighLumiTex, i.uv);
return col + highLumi;
}
And this (part of the) script:
public Shader highLumiShader; // Working bloom shader
public Shader blurShader; // Working gaussian blur shader
public Shader compoShader;
private Material highLumiMat;
private Material blurMat;
private Material compoMat;
private void Awake()
{
highLumiMat = new Material(highLumiShader);
blurMat = new Material(blurShader);
}
private void OnRenderImage(RenderTexture source, RenderTexture destination)
{
RenderTexture highLumiTex =
RenderTexture.GetTemporary(source.width,
source.height, 0, source.format);
RenderTexture blurTex =
RenderTexture.GetTemporary(source.width,
source.height, 0, source.format);
Graphics.Blit(source, highLumiTex, highLumiMat);
Graphics.Blit(highLumiTex, blurTex, blurMat);
compoMat.SetTexture("_HighLumiTex", blurTex); // This is the line that is giving an error.
Graphics.Blit(source, destination, compoMat);
RenderTexture.ReleaseTemporary(blurTex);
RenderTexture.ReleaseTemporary(highLumiTex);
}
I don't see why compoMat.SetTexture("_HighLumiTex", blurTex) wouldn't work, seeing as _HighLumiTex does exist in the compoShader file. Why would it be "object reference is not set to an instance of an object"?
I've tried changing the order, and the declaration in the other shaders but it seems like the only issue is the "SetTexture" line.