- Home /
Different between tex2D and SAMPLE_TEXTURE2D (Post Processing effect)
What is the difference between tex2D() and SAMPLE_TEXTURE2D? I am trying to create a four corner pin post processing effect, and my lines come out curved with SAMPLE_TEXTURE2D, but are good and straight when I use tex2D() in an ImageEffect.
Motivation for using a custom post processing effect instead of an ImageEffect is because ImageEffects dont seem to work when using HDRP (OnRenderImage() is never called), and I want to use ShaderGraph for other parts of the app. I should also mention my shader knowledge is pretty limited so feel free to point out any newb mistakes
Here is my simple fragment shader
float4 Frag(VaryingsDefault i) : SV_Target
{
float2 uv = i.texcoord;
uv.x *= 1 / (uv.y*_URx + 1);
return SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, uv); //Compiles, but produces curved lines instead of the desired straight ones
//return tex2D(_MainTex, uv); //Doesnt compile here, but produces good straight lines
}
I built the basic Post Processing effect based on this article: https://github.com/Unity-Technologies/PostProcessing/wiki/Writing-Custom-Effects
and the specifics of the fragment shader are from this post:
https://answers.unity.com/questions/835540/4-corner-pin-distrotion-shader.html