• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by alex_e_m · Dec 15, 2017 at 05:31 PM · shadersnoobpost-process-effect

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;
         }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by alex_e_m · Dec 18, 2017 at 07:39 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

81 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Legacy edge detection image effect + post processing not working 1 Answer

Why doesn't this shader work when using it with as a custom effect on the post processing stack 1 Answer

Curved Screen Post Processing Effect 1 Answer

Strange shadow/texture issue on Save Scene 0 Answers

vertex displacement shader and ssao 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges