I am looking to blur a node output in shader graph, so that I can use it as the mask for a Lerp. Something like the following illustrates my goal. I could try and preprocess the blur in an image application, However in my case, I am trying to stay procedural on this. However, I can’t find any blur related nodes. I understand that a real time blur can be expensive, but I am just curious if such a node exists in shader graph?
Yes it would be possible but expensive in a node as it’d have to process multiple offset samples.
However if it’s just a texture sample you want to blur you can use Sample Texture 2D LOD to get lower mip levels (although you’ll get better results by blurring in your image app).
In this case, it is just the binary output of a branch node (the star was for illustration purposes only). I am taking the output of a dot product and using it to create a vertex displacement transition. The transition is just really hard, due to the black and white nature of the result, so I am trying to figure out how to soften the edges between the black and white pixels. But mostly, I am just trying to learn what nodes are available.
A dot product gives a range of values from -1 to 1, so you might be able to remap the values to get something more gradual and use in a lerp? This is also going to be simpler and more efficient so would generally be a better approach. What are you using as the input for the dot product?
I was using the dot product range (-1 to 1) and comparing it to a solid value, such as zero, then branching to create a solid mask (if greater than 0 draw white, if less draw black), with a goal of blurring the result. However, I was able to cobble together something that works using smoothstep instead.
However, I may also be experiencing a bug. I am using the normal vector (world) and a second vector to represent a lighting direction and getting the dot product, but when I do that I get a black result in the dot product preview regardless of vector value (see below)
Have you been able to fix this issue? I want to do the same. I’m looking to create a shader that blurs my sprite, possibly using the Sample Texture 2D LOD to lower the mip levels. But I really have no idea where to start or where to search for some examples.
You could sample lower mipmap level using Sample Texture 2D LOD, and then create a Custom Function node with a single pass blur implementation. This will save quite a lot of computation I think.
Start from manual on how to create a Custom Function node, it’s explained there, then implement a blur.
Hello, I know this is late but this is for anyone looking for a shader graph method to blur a given sampled texture as I couldn’t find any other resource on this matter.
What is happening is you have a blur scale float value (In my case I’m using 1.0005) offsetting 4 unique UV’s offsets X and Y values by that blur scale value, leaving one UV’s offsets at 0, 0, then adding all the samples and dividing by 5 (the total amount of samples).
From what I can tell this isn’t very resource intensive and can be scaled up with additional sampling, and I’m sure this can be further improved.
In this case I’m blurring two textures so ignore the bottom right corner unless you also want to blur multiple samples.
Edit: Day 2, Indeed I already found a better way to do this, looks better and is more efficient.
Same concept as before, just using a noise map to scramble the base textures UV. This blur is different as it has a noisy look to it. In this instance there are two sampled textures, one for an inner blur and one for an outer blur where you can control both the scale and opacity of the UV noise scramble.
The values I am using:
Tanline Blur Scale Inner = 500000
Tanline Blur Amount Inner = 0.995
Tanline Blur Scale Outer = 2000
Tanline Blur Amount Outer = 0.995
sometimes i am looking for a blur node and i end here and answers don’t really suit me. gaussianBlur.unitypackage (3.4 KB)
here a subgraph with gaussian blur to help others.
void GaussianBlur_float(UnityTexture2D Texture, float2 UV, float Blur, UnitySamplerState Sampler,
float2 Texture_TexelSize, out float3 Out_RGB,
out float Out_Alpha)
{
float4 col = float4(0.0, 0.0, 0.0, 0.0);
float kernelSum = 0.0;
int upper = ((Blur - 1) / 2);
int lower = -upper;
for (int x = lower; x <= upper; ++x)
{
for (int y = lower; y <= upper; ++y)
{
kernelSum++;
float2 offset = float2(Texture_TexelSize.x * x, Texture_TexelSize.y * y);
col += Texture.Sample(Sampler, UV + offset);
}
}
col /= kernelSum;
Out_RGB = float3(col.r, col.g, col.b);
Out_Alpha = col.a;
}
Note that sample texture 2D is a mandatory step because it’s the only moment where the shader can see pixels around the actual pixel to do his math.
There is no “blur node” usable after even if we see a 2D “preview”.
It should be possible to render to a temporary render texture to pass a result to another shader but it’s beyond my knowledge.
BUT, if you need to blur just ONE time on a texture, use photoshop,
or create a editor script to blur at import process,
or runtime script (beware of performance).