tex2D(s,t,ddx,ddy) not working in fullscreen

Hi, i’m trying to make full screen custom post effect. with script added to main cam, with one line: blit(src,dst,mat) in void OnRenderImage(src,dst). I wrote the shader with _MainTex so it’ll work in “Blit”.
I done it(many times) all correctlly like in tuts. if i assign this shader to any object (with texture) it works well, but the problem is when i assign that shader(in material) to script (blit(,mat)) it ignores the ddx,ddy part,it works like tex2D(tex,uv). WHY? how can I fix it?

here is the fragment code.
**
fixed3 frag(vout v):sv_target

		{
			fixed3 c;
			float2 cddx=float2(
				pow(abs(0.5-v.uv.x),1.6)*_xy,
				-pow(abs(0.5-v.uv.y),1.6)*_xy);
			float2 cddy=float2(
				-pow(abs(0.5-v.uv.x),1.6)*_xy,
				pow(abs(0.5-v.uv.y),1.6)*_xy);
			c=tex2D(_MainTex,v.uv,cddx,cddy);
			return c*0.5;
		}

Hi. I found an answer. tex2D(sampler2D,uv,ddx,ddy) and tex2Dgrad(…) methods use mipmaps. when i tried to pass “screen” texture to the shader in blit(src,dst,mat) I noticed that src has no mipmaps, only the original texture. so, I thought that I’ll simply add mipmaps with src.GenerateMips() and it’ll work. but there is a catch: if i try to do that the editor throws me exceptions that the rendertexture is created, that generating mips is unsuported in created rendertexture and other stuff… finally i found the recipy:


  • one time
  1. create another temp renderTexture
  2. turn off auto generate mipmaps
  3. useMips=true
  • every frame (OnRenderImage(…))
  1. blit src to temp
  2. generate mipmaps in temp
  3. blit(temp,dst,mat)

it generates mipmaps on new render texture and passes it to the shader without any errors.

one last thing, if someone knows how to specify mipmap count that i want to generate, tell me please.

I hope it’ll be helpful to newbies in shaders like me.