8
$\begingroup$

Desired result:

Desired result

Basically what I want to achieve is procedural square shape with ability to blur edges with similar effect to Gaussian blur.

I'm aware of Cycles limitations regarding blur nodes, and also I'm familiar with method to blur texture by noise. This case could be different as I want to use this shape further in my node setup.

What I have so far:

Results:

all

Node setup for the first example:

nodes

Overview and problems:

  1. This is desired result for "blur" effect. Problem with this one is if I change Color Ramp to Constant shape has still rounded corners. Also with bigger scale (Scale - 2 and Color Ramp Black position - 1) it looks like this:

    bad_blur

Sadly shapes on edges aren't tiles, after scaling (and applying) mesh they are just white stripes.

Another problem is control over size of this shape.

  1. This is just ok result. Nothing to add. Maybe only painful control.
  2. This is Box blur effect, only upside of it is that it could be achieved only by changing Color Ramp interpolation to Linear from Constant (pt. 2).

The biggest problem here is that despite I can have the shape/effect I want, control over them (and the fact that they are separated setups) is horrible. For example - scaling from really small square to big one touching edges involves changing Scale in every Mapping node and also correcting Color Ramp.

Blend file:

$\endgroup$
8
$\begingroup$

Here's an alternative solution using maths nodes to calculate distance from the square and the Gaussian distribution function.

result

The key here is for any point in the shader to calculate the closest point to the square. The square is defined by 4 boundary values - X-Min, X-Max, Y-Min, Y-Max.

To calculate the closest point that is still within the square we can simply use the Max and Min functions. ie,

closest-X = Min( Max(X, X-Min), X-Max)
closest-Y = Min( Max(Y, Y-Min), Y-Max)

To calculate the distance to this point (ie, the closest distance to the square) we can use Pythagoras

distance^2 = X^2 + Y^2

ie,

distance = sqrt(X^2 + Y^2)

For the Gaussian falloff we use the equation :

 intensity = 1 / (2^dist)

Bringing it all together produces the following material (note that I've omitted the 'sqrt' of the distance calculation - this gives a more pronounced falloff based on the square of the distance, rather than the plain distance) :

material

Adjusting the input nodes (X-Min, X-Max, Y-Min, Y-Max, Focus) will adjust the size and 'blurriness' of the square. Note that the Gaussian blur starts from the edge of the square - so the square is always maximum intensity with the falloff starting at its boundary. This means that the blur will always make it appear larger - adjust the boundary values to compensate whilst adjusting the Focus if this is not desired.

To tile multiple squares you can simply use a Mapping node and Modulo nodes to repeat the range multiple times :

material - tiled

Animating the mapping and various inputs can produce the following result :

result - animated

Blend file attached


This can be used to generate procedural tiles as shown by this sample image provided by @cgslav :

enter image description here

$\endgroup$
  • 2
    $\begingroup$ Wow! I didn't wanted this to be tiled texture but now I can't stop playing with it. Couple nodes more and I was able to create tiles with bumped mortar, check here: imgur.com/ENIJW3s Now only figure out different gradient per tile and this will be complete solution for making tiles Substance Designer style :) $\endgroup$ – cgslav Sep 5 '17 at 7:37
  • 1
    $\begingroup$ Nice - that's really effective as tiles. Adding variation per tile shouldn't be too complicated - would just need to 'Round' the coordinates to integers before feeding into a Noise texture. I'll try and update the answer with that later. $\endgroup$ – Rich Sedman Sep 5 '17 at 8:26
5
$\begingroup$

Here is a working node graph. I don't know if it mimics exactly a gaussian filter, but it looks better than the screenshots you posted.

Forgive me for the messy graph, I guess you will organize all this with groups and so on ;-).

It looks like this: enter image description here

Node setup: (you have input for U/V coordinates of the top left corner of the square, the width/height of the square, and the amount of blur)

enter image description here

"feather interval" node group: (note that with the maximum and minimum nodes, the input a and b can be in any order) (note also that I put a max node on the feather to avoid dividing by zero or negative values)

enter image description here

Basically "feather interval" is 1D function similar to a gate function (wikipedia article) with smooth corners. Than I combine 2 intervals for U and V by multiplying them.

Hope it will help you! :-)

[EDIT]

I added the divide and substract nodes just after the U/V nodes. So (u,v) is now the position of the center of the square.

enter image description here

$\endgroup$
  • $\begingroup$ It's really amazing, almost perfect! I have only one question though, is there any way to resize shape "from center", or maybe there is some constant correlation between Size and U/V values? I've "merged" U and V values to not to manipulate both of them but centering small square is pretty hard, bigger are easier to match the center, still it's just eyeballing. $\endgroup$ – cgslav Sep 4 '17 at 11:06
  • $\begingroup$ Glad it helps ;-). I'm not sure to understant why you merged U and V, you don't want to be able to place the square anywhere? $\endgroup$ – Datross Sep 5 '17 at 5:14
  • $\begingroup$ It's nice to have full control over it but my main need is to have it placed in the center of a plane/face and doing it manually isn't so precise. I was trying to calculate some kind of proportion between size value and U/V but as an artist I'm completely math resistant sadly... $\endgroup$ – cgslav Sep 5 '17 at 5:19
  • $\begingroup$ I added some nodes in the last screenshot to make u,v the position of the center. If you want to center the square, you can now just put U=V=0.5. $\endgroup$ – Datross Sep 5 '17 at 5:25
  • $\begingroup$ Basically I just shifted u and v by half of the width. There's no too complex math here ;-). $\endgroup$ – Datross Sep 5 '17 at 5:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.