One way to make a transparent hole in a plane with graded transparency is to uv-map a solid, monochrome image with graded alpha (I assume).

But can I do this with nodes? I've used the Error Function to do this.

Basically transparency is 0.5 * (1 - erf((r-r0)/fuzzy)) where r is the distance from the center of the plane, r0 is the radius of 50% transparency, and fuzzy is about 0.25 * r0. It would be nice if everything would scale, so if I scaled the plane the hole would naturally scale with it.

note: if erf(x) is not available, it can be replaced with x.clip(-1, 1) like this:

enter image description here

I'm not sure how to begin to explain to nodes how to get the plane coordinates, and the erf() function.

Can this be done easily with nodes?

The image below is fake - I did it with matplotlib as an example of a plane with a fuzzy transparency as described above.

enter image description here

This is all I have so far, not sure how to even start to obtain u and v of the plane separately so I can even star to calculate r = sqrt(u**2 + v**2). Using Separate XYZ or Separate RGB seems to give absolute X, Y, Z coordinates, and I just want coordinates within the plane itself.

enter image description here


You can use an OSL script to generate the exact result that you want.

shader circlefade(
point Vector = P,
float size = 0.5,
output float Fac = 0.0 )
    float r = distance(Vector, (0.5,0.5));
    float fuzzy = 0.25 * size;
    Fac = 0.5 * (1-erf((r-size)/fuzzy));

osl sample

  • $\begingroup$ Excellent - thank you! The script node is exactly what i need, never dared to try it but now it seems easy! Reminder to self, don't forget to click the OpenShadingLanguage checkbox in the Render menu: i.stack.imgur.com/q9JJv.png $\endgroup$ – uhoh Nov 21 '16 at 12:40
  • 1
    $\begingroup$ I didn't look if erf was in OSL, easy to add. You will want to use a different size depending if you connect to generated, uv ... or nothing. my sample The osl language is very close to C. $\endgroup$ – sambler Nov 21 '16 at 12:41
  • $\begingroup$ I was surprised to find erf() there too, but yippeee!! I'm normally allergic to curly brackets, but I can make an exception for OSL. Thanks again! $\endgroup$ – uhoh Nov 21 '16 at 12:49

Use the Texture Coordinate node instead of Geometry. The Texture Coordinate provides 'Generated' output that varies from 0 to 1 in each dimension over the whole mesh or Object output that gives zero at the centre of the object.

For a "hole" in the centre of your plane you could use the Object Texture Coordinates and determine the distance from the origin using "distance = sqrt(x^2+y^2+z^2) like this :

enter image description here

Use the result to feed into the Mix factor as in your existing example. To make it variable you can add a Multiply node set to "Clamp" and/or other nodes (add, subtract, Max,Min, etc. - depending on the effect you require) just before the Mix node and adjust this to change the properties of the "hole".

  • $\begingroup$ OK I'm getting there - thanks! I'll post the final solution when I get it. Since the values are 0 to 1, have to subtract 0.5 from each before squaring to get it centered. Looks like can ignore z for a simple plane, but will come in handy for more complex shapes. Looks like I'm out of luck for the erf() function though. I'll try to fudge it with arctan() somehow. I wish I could open one of those math boxes and just type a script or something. (I'm not a C programmer :( though). I'll ask separately. Thanks! $\endgroup$ – uhoh Nov 21 '16 at 10:46
  • 1
    $\begingroup$ Glad to help :-) You can use Object coords instead of Generated as that's centred around the centre - but is dependent on scale rather than Generated which is always 0-1. Yeah - it would be really good to be able to enter a script - nice idea - it would be much easier than stringing together multiple nodes! $\endgroup$ – Rich Sedman Nov 21 '16 at 10:53
  • $\begingroup$ I have dabbled with OSL a bit but try and avoid it in Answers as it's not always available (Linux, for example, doesn't include it in Blender in the standard distro) and it's not as understandable to non-coders. I prefer a node based solution whenever possible. $\endgroup$ – Rich Sedman Nov 21 '16 at 12:07
  • $\begingroup$ Actually, the other answer works so nicely, I really have to accept it and clean up. Thank you very much for your help and comments - you've shown me how to get the coordinates and that's something I'll use frequently in the future. $\endgroup$ – uhoh Nov 21 '16 at 12:37

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.