YOUR ACCOUNT

Login or Register to post new topics or replies
VinnieF
Vinnie

Posts: 5
I'm working on implementing Photoshop Layer Styles in my MIT licensed project:

https://github.com/vinniefalco/LayerEf...d/graphics

After a lot of study and searching I figured out that the distance transform plays a key role in implementing almost all the styles. You can see clear evidence of the distance transform by turning on the "Stroke" layer style, setting the fill type to Gradient, and choosing "Shape Burst" for the style.

If you set the Outer Glow style to the "Precise" technique it also shows direct evidence of a canonical distance transform.

But what is the algorithm used for the "Soft" technique? It does not look like a distance transform. At least, not directly. There seems to be some sort of blur. But its not a blur because I try blurring the mask using similar settings, and doing a difference calculation on the outer glow versus my blurred mask and there are some small pixel differences at various radii.

Can someone please point me in a direction for implementing the "Soft" technique of Photoshop's Outer Glow filter?

Thanks

  Details E-Mail
Ghislaine
Ghislaine

Posts: 3142
Filters: 270
Hi Vinnie !

I can't help you but can say "Welcome in our community" ! smile:)
  Details E-Mail
CorvusCroax
CorvusCroax

Posts: 1227
Filters: 18
Hi Vinnie,

Welcome to FF! Having a simple outerglow and inner glow FF node exactly like photoshop's is something some of us have been agitating for for some time. (especially in 'precise' mode. The stock answer is that FF's architecture is sample-based, not pixel based.

I'd guess the closest you can get is to:

Use percentile to 'offset' the shape. Then use gaussian blur. The 'offset' and the blur distance are then plugged into the same control: "Distance"
  Details E-Mail
VinnieF
Vinnie

Posts: 5
Hi, and thanks for the warm welcome.

To be clear, I'm looking to understand the algorithm that Photoshop uses, not to come up with some approximation. I think that before attempting an approximation using available tools (if they are limited, as you said that Filter Forge is sample based), it is beneficial to understand exactly what is being approximated.

So what exactly is Photoshop doing for "Softer?" I can confirm with 100% certainty that for "Precise" it is a simple anti-aliased distance transform, I can reproduce it in my demo application.

I can also confirm that the "Softer" and "Precise" distance transforms are the basis of almost all the Layer Style effects. Drop shadow is Outer Glow in "Softer" mode (with an offset and optional knockout). Stroke with Gradient/Shape Burst is a "Precise" distance transform. Inner Glow is your choice "Softer" or "Precise" distance transform. Inner Shadow is the "Softer" distance transform. I did all my tests using difference calculations on channels and they are exactly the same.

My intuition tells me that the Bevel and Emboss style uses the "Softer" distance transform for calculating the height map in "Smooth" mode, and the "Precise" distance transform for the two "Chisel" options.

Summary:

The distance transform is a useful operation for producing a variety of layer effects. Photoshop seems to use two forms of the distance transform: "Precise", which creates the traditional definition of the distance transform, and "Smooth" which produces a similar effect but is not the same.

A deeper understanding of the "Smooth" distance transform would be useful in reproducing similar effects.
  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1750
Filters: 39
Hi Vinnie,

Nice work you started there smile:-) I myself worked on similar stuff in Graphics32 (graphics library for Delphi). Yep the precise mode is based on euclidean distance transforms. The soft mode seems to be based on blurring of the alpha mask. Here is what they give you:

Quote

Smooth Blurs the edges of a matte slightly and is useful for all types of mattes, whether their edges are soft or hard. It does not preserve detailed features at larger sizes.

Chisel Hard Uses a distance measurement technique and is primarily useful on hard-edged mattes from anti-aliased shapes such as type. It preserves detailed features better than the Smooth technique.

Chisel Soft Uses a modified distance measurement technique and, although not as accurate as Chisel Hard, is more useful on a larger range of mattes. It preserves features better than the Smooth technique.

Softer Applies a blur and is useful on all types of mattes, whether their edges are soft or hard. At larger sizes, Softer does not preserve detailed features.

Precise Uses a distance measurement technique to create a glow and is primarily useful on hard-edged mattes from anti-aliased shapes such as type. It preserves features better than the Softer technique.


(Mid page: http://help.adobe.com/en_US/photoshop...89ba.html)

Try blurring the distance transformed mask, or blur the mask before distance transform for the "mixed modes". The blurring technique used is probably a 3 pass box blur approx. of a gaussian blur
  Details E-Mail
VinnieF
Vinnie

Posts: 5
Thanks! That quote fr om the manual is quite informative. You suggested a 3 pass box blur. Repeated application of a box blur results in a gaussian kernel (central lim it theorem). I did a quick test of box blur versus drop shadow here's the result.

Can box blur be made exceptionally fast? I would think so since the weights are equal and the kernel is separable. You suggest a 3 pass box blur. How do I handle the case of size = 1? Would that be just one box blur? What about size 2? two box blurs? Size 6? Three 2-pixel box blurs?

Give the size parameter, range [0,250] what formula do you suggest for the number of passes and the size of each pass?

  Details E-Mail
VinnieF
Vinnie

Posts: 5
Here's a comparison of Box Blur and Drop Shadow for size = 1. As you can see, there are some slight differences in the values. Drop Shadow at size = 1 is definitely not using a Box Blur with radius = 1 on the mask.

  Details E-Mail
Sphinx.
Filter Optimizer

Posts: 1750
Filters: 39
I don't think you have a 1:1 relation btwn radius and size, that would not make sense. Size is probably half of radius and then black point compensated, i.e. move the black point to 50% (or 127).

Try creating a setup where you can inspect the difference gradually as you tweak the blur radius.
  Details E-Mail
VinnieF
Vinnie

Posts: 5
Anyone heard of the "Gaussian Distance Transform" ??
  Details E-Mail

Join Our Community!

Filter Forge has a thriving, vibrant, knowledgeable user community. Feel free to join us and have fun!

33,712 Registered Users
+19 new in 30 days!

153,533 Posts
+31 new in 30 days!

15,348 Topics
+73 new in year!

Create an Account

Online Users Last minute:

33 unregistered users.