How do I make the shader only work in a specific area

How do I do so the shader only works in desired area and on specific materials similar to pausing in some games:

I guess you can use a mask like in “making a flashlight”, but how do you do such a thing with a shader?

You can use a shader constant that dictates if the effect should be on or off, or the amount of effect if you want to be able to animate.

For a full screen blur when the game pauses you might want to consider (for better performance) rendering the game normally until the effect should kick in. At that point you instead switch to rending the game to a render target that you use as texture on a quad with a blur shader. You can control the behavior by sending messages to the render script.

3 Likes

In the image you posted, the blur is fullscreen, and then the UI is drawn on top, so there’s no need to mask the effect to a specific area.

In the case that you do want to mask something out, one way to do it is with UV coordinates. If you just want to not draw part of a rectangle for example (or any sprite, which are drawn on rectangular meshes). A health bar for example. If you send the shader a 0-1 value from your game, in the shader you can just say, if UV.x <= healthPercent, then draw normally, else return a transparent color.

If you’re interested, there are some nice video tutorials for ShaderForge that cover some of this stuff. It’s a fancy node-based visual system, but it uses the exact same principles as writing shader code the usual way.

2 Likes

Sorry for being unclear, this is what I really want. Could not find a good picture on google:

(combined 2 pictures, not real)

  1. Render to render target.
  2. Use target as texture on quad (full screen).
  3. Draw texture with fragment shader that only blurs past a UV coordinate threshold.
4 Likes