Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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 Jogol · Oct 20, 2017 at 05:01 PM · shaderscgfragmenttransformation

GrabPass twirl shader not centering correctly

I'm trying to create a shader that I can place on a material and on for example a quad, so that when I look through it, I see a twirled version of what is behind the quad. However, it doesn't seem to center correctly as can be seen in the appended photos.Seen from afar Seen from upclose The only difference between these two pictures is that I zoomed in for the second one, which I don't want to affect the center. I want the center of the twirl to always be in the center of the quad but I guess I'm not really understanding what coordinates to use and for what (I tried using unity_ObjectToWorld[3] with similar bad results). Here is the current code:`v2f vert (appdata v) { v2f o; o.pos = UnityObjectToClipPos(v.vertex); o.uv = ComputeGrabScreenPos(o.pos); return o; }

         sampler2D _GrabTexture;
         float4 _GrabTexture_TexelSize;
         float _Factor;
         float4 _Center;
 
         half4 frag (v2f i) : SV_Target
         {
             float centerX = _GrabTexture_TexelSize.z/2;
             float centerY = _GrabTexture_TexelSize.w/2;
             half4 pixelCol = half4(0, 0, 0, 0);
             float dx = i.uv.x - centerX;
             float dy = i.uv.y - centerY;
             float p = _Factor;
             half rmax = _GrabTexture_TexelSize.z/2;
             half r = sqrt(pow(dx, 2) + pow(dy, 2));
             half z = sqrt(pow(rmax, 2) - pow(r, 2));
             half beta = atan2(dy, dx) + _Factor * (rmax-r)/2;

             float x = i.uv.x;
             float y = i.uv.y;

             if(r <= rmax) {
                 x = centerX + r * cos(beta);
                 y = centerY + r * sin(beta);
             }


             pixelCol = tex2Dproj(_GrabTexture, UNITY_PROJ_COORD(float4(x, y, i.uv.z, i.uv.w))); 
             return pixelCol;
         }`

Any help would be greatly appreciated and please let me know if you feel something is missing from the description!

twirlfar.png (60.8 kB)
twirlclose.png (286.9 kB)
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

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

77 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

Related Questions

General question about shading in unity 2 Answers

Access to svPosition in fragment shader 1 Answer

_LightMatrix0 and Directional Light 1 Answer

Is it more qualitative to calculate light direction manually or using WorldSpaceLightDir(vertex)? 1 Answer

Blending in a simple shader not working in Unity5 as it used to work in Unity4 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