I’m attempting to do some manipulation of colours after all lighting calculations have been done. As a first step I’m trying to get the scene with basic lighting using a grab pass but I’m getting a different image from the grab pass than if I use the same shader with the grab pass commented out. I’m using the default surface shader created as new by Unity with the following (copy and pasted from here) added to the end:
GrabPass
{
"_BackgroundTexture"
}
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f
{
float4 grabPos : TEXCOORD0;
float4 pos : SV_POSITION;
};
v2f vert(appdata_base v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.grabPos = ComputeGrabScreenPos(o.pos);
return o;
}
sampler2D _BackgroundTexture;
half4 frag(v2f i) : SV_Target
{
half4 bgcolor = tex2Dproj(_BackgroundTexture, i.grabPos);
return bgcolor;
}
ENDCG
}
Without that snippet I get:
With it I get:
Any ideas why, or of an alternative way to get the brightness of each pixel after all lights have rendered? If it’s relevant, I currently have one directional light and one spotlight in the scene. Thanks in advance for taking the time to try and answer my (probably) silly question.