Hi all,
Let me preface this by saying i know very little about shader programming and a quick apology.
I was looking through the DOF Shader (I think it was the one that came with the shader replacement) and i noticed that the colour of the blur part of the post processing can be altered using blur1 *= float3(1,1,1); (This line of code is in the shader and blur1 is a half3).
I would like to be able to alter this blur1 variable dynamically at runtime, so I created a:
uniform half3 _blur1; in the .shader
I’m just not sure what to change the blur1 *= float3(1,1,1); line to within the shader to accept the incoming variable and what to place in the C# script to send the float3?
Any help would be greatly received.
Many Thanks, Matt
I’m not sure if Shaderlab lets you expose half3s, but you might as well use a float4 instead. In the property block of the DOF Composite shader, add:
_blurTint ("", Color) = (1,1,1,1)
This allows the value to be saved by the Material. Then, in the CGPROGRAM, put this line in with the other uniform variables:
uniform float4 _blurTint;
Finally, instead of the hard-coded value in the fragment program:
blur1 *= _blurTint;
Because the Material is generated by a script, you’ll have to set the blur colour property from the script as well. In the DepthOfFieldEffect.js script, add a colour variable at the top:
var blurTint : Color = Color.red;
And then apply it in the GetCompositeMaterial() function, just before you return the Material every frame:
m_CompositeMaterial.SetColor("_blurTint", blurTint);
If you’ve done it right, you should see some bright red added to your image right away. You can use the same colour to multiply blur2 in the fragment shader, or repeat all the steps for a secondary tint colour.
Many thanks for that, I haven’t tried it yet but it looks perfect.
Thank you!
Matt.
Oops, I forgot that in the fragment program you’re multiplying a half3, so the line should actually be:
blur1 *= _blurTint.rgb;