Procedural square shape in Cycles (with similar effect to Gaussian blur) 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:



Node setup for the first example:



Overview and problems:


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:




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.


This is just ok result. Nothing to add. Maybe only painful control.
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:
Here's an alternative solution using maths nodes to calculate distance from the square and the Gaussian distribution function.



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) :



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 :



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



Blend file attached 



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