Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by mylies43 · Nov 20, 2015 at 07:17 AM · c#unity 5mousepositionblur

How to change blur based on mouse X position?

Im trying to figure out how to change the blur level on my menu screen as I move from side of the screen to the other. The idea is to have two sections of blur. And when the mouse is on the left most side the right side is max blurry while the left is not at all, and vice versa for the other side. Im not sure how to go around doing this so help is highly appreciated.

The code in question.

 {

     [Range(0, 2)]
     public int downsample = 1;

     public enum BlurType {
         StandardGauss = 0,
         SgxGauss = 1,
     }

     [Range(0.0f, 10.0f)]
     public float blurSize = 3.0f;

     [Range(1, 4)]
     public int blurIterations = 2;

     public BlurType blurType= BlurType.StandardGauss;

     public Shader blurShader = null;
     private Material blurMaterial = null;


     public override bool CheckResources () {
         CheckSupport (false);

         blurMaterial = CheckShaderAndCreateMaterial (blurShader, blurMaterial);

         if (!isSupported)
             ReportAutoDisable ();
         return isSupported;
     }

     public void OnDisable () {
         if (blurMaterial)
             DestroyImmediate (blurMaterial);
     }

     public void OnRenderImage (RenderTexture source, RenderTexture destination) {
         if (CheckResources() == false) {
             Graphics.Blit (source, destination);
             return;
         }

         float widthMod = 1.0f / (1.0f * (1<<downsample));

         blurMaterial.SetVector ("_Parameter", new Vector4 (blurSize * widthMod, -blurSize * widthMod, 0.0f, 0.0f));
         source.filterMode = FilterMode.Bilinear;

         int rtW = source.width >> downsample;
         int rtH = source.height >> downsample;

         // downsample
         RenderTexture rt = RenderTexture.GetTemporary (rtW, rtH, 0, source.format);

         rt.filterMode = FilterMode.Bilinear;
         Graphics.Blit (source, rt, blurMaterial, 0);

         var passOffs= blurType == BlurType.StandardGauss ? 0 : 2;

         for(int i = 0; i < blurIterations; i++) {
             float iterationOffs = (i*1.0f);
             blurMaterial.SetVector ("_Parameter", new Vector4 (blurSize * widthMod + iterationOffs, -blurSize * widthMod - iterationOffs, 0.0f, 0.0f));

             // vertical blur
             RenderTexture rt2 = RenderTexture.GetTemporary (rtW, rtH, 0, source.format);
             rt2.filterMode = FilterMode.Bilinear;
             Graphics.Blit (rt, rt2, blurMaterial, 1 + passOffs);
             RenderTexture.ReleaseTemporary (rt);
             rt = rt2;

             // horizontal blur
             rt2 = RenderTexture.GetTemporary (rtW, rtH, 0, source.format);
             rt2.filterMode = FilterMode.Bilinear;
             Graphics.Blit (rt, rt2, blurMaterial, 2 + passOffs);
             RenderTexture.ReleaseTemporary (rt);
             rt = rt2;
         }

         Graphics.Blit (rt, destination);

         RenderTexture.ReleaseTemporary (rt);
     }
 }

}

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Bullet to Mouse Position? 1 Answer

The location of the object by points 0 Answers

How to add a " Achievement unlocked " text and a collectible after completing all objectives 0 Answers

playing multiple sound on gameobject 1 Answer

How to interrupt wait coroutine in a loop? 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