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 /
This question was closed Oct 24, 2016 at 01:09 AM by fdkio for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by fdkio · Oct 23, 2016 at 06:34 PM · shadershadersblur

Shaders : Blur only part of the screen

I wish to blur only part of the screen (let's say half of it). From what I've found online I need to create a texture 'mask' that will make the shader only "work" on that mask. However, I have no idea of how to create that texture 'mask'. Looking at the inspector with the MobileBlur shader selected I can see there are two fields under "Default Maps" but changing them doesn't produce any results.

I was wondering where (and how) on the shader code can I create that texture 'mask'. Or maybe if you know some example/tutorial that could shed some light on this subject of texture masks that would be much appreciated. Thanks in advance!

Edit: After a while I encountered this tutorial series:
Unity Tutorial: A Practical Intro to Shaders - Part 1
which even though it did not touch the subject of texture masks, it allowed to understand shaders enough to get the problem solved. Still, if anyone can explain the texture maps part it would still be appreciated.

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

  • Sort: 
avatar image
1
Best Answer

Answer by fdkio · Oct 24, 2016 at 05:23 AM

I found the correct solution finally! Here it is for those having the same problem:
Basically you create the texture you desire to apply your shader on. For me it was a circular gradient. White is where the shader will be apllied, black is where it isn't. On the texture don't forget to tick the box "Alpha from Grayscale".
Then on the shader you add the mask on your properties tab. The beggining should look something like this:

 Shader "Hidden/FastBlurCircular" {
     Properties {
         _MainTex ("Base (RGB)", 2D) = "white" {}
         _Mask ("Blur Mask", 2D) = "white" {}
         _Bloom ("Bloom (RGB)", 2D) = "black" {}
         
     }
     
     CGINCLUDE
 
         #include "UnityCG.cginc"
 
         sampler2D _MainTex;
         sampler2D _Mask;
         sampler2D _Bloom;

Then, after doing the desired calculations you will end up with a certain color for the pixel. Simply lerp that color with the original one using the alpha from the texture mask like so:

 //Some calculations that give you 'color'
 
 half4 originalColor = tex2D(_MainTex, uv) ;
 half4 maskColor = tex2D(_Mask, uv);
 
 return lerp(originalColor,color,maskColor.a);

I hope this helps someone with the same issue!

Comment
Add comment · Show 1 · 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
avatar image jeanf_le · Jul 18, 2017 at 09:51 AM 1
Share

Hey, thx for the tip. Could you share the whole shader code? that would be very useful.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Blurry smooth edges of a mesh 0 Answers

How to have a gradient blur in objects? 0 Answers

viewDir changes with o.Normal 1 Answer

How to set shader vertex normals to face up 1 Answer

shader Transparency 1 Answer


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