This discussion is archived
5 Replies Latest reply: Jan 8, 2013 10:58 AM by 916161 RSS

HowTo combine shadow and original graphic

916161 Newbie
Currently Being Moderated
Hi,

the JavaDoc for Shadow states:

"This effect is primarily used along with its default black color for purposes of combining it with the original to create a shadow. It can also be used with a light color and combined with an original to create a glow effect."
http://docs.oracle.com/javafx/2/api/javafx/scene/effect/Shadow.html

... indicating that I can somehow combine/blend the result of the effect with the input. If that's the case, is there an example somewhere how I can do that?

Regards

Toni

Edited by: monacotoni on 08.01.2013 06:42
  • 1. Re: HowTo combine shadow and original graphic
    916161 Newbie
    Currently Being Moderated
    What I can do is combine effect and original like this:


    public void draw(GraphicsContext graphicsContext, double x, double y, double width, double height) {

    WritableImage image = new WritableImage((int) width, (int) height);
    SnapshotParameters snapshotParameters = new SnapshotParameters();
    snapshotParameters.setFill(Color.TRANSPARENT);
    graphicsContext.getCanvas().snapshot(snapshotParameters, image);
    graphicsContext.applyEffect(effect);
    graphicsContext.drawImage(image, 0,0, width, height);
    }

    But that's not very performant and doesn't work well with animations, so I'm looking for a better way to do it. I was hoping to reuse the strategy used to create DropShadow. If someone has a hint how that can be done, let me know...
  • 2. Re: HowTo combine shadow and original graphic
    twasyl Newbie
    Currently Being Moderated
    Hi there,

    Look at my article here: http://thierrywasyl.wordpress.com/2012/05/02/tweetwallfx-part-1/
    I used the inputProperty for an effect to "chain effects" especially the DropShadow with the Reflection.
    More info here: http://docs.oracle.com/javafx/2/visual_effects/jfxpub-visual_effects.htm

    Enjoy!
  • 3. Re: HowTo combine shadow and original graphic
    916161 Newbie
    Currently Being Moderated
    You refer to chaining of effects. That's not what I want. With a chain, the next effect will be applied to the result of the previous. The original is "lost".

    For example if you apply the JavaFX Shadow Effect on a red Circle, you'll get a black Circular Shadow Shape as a result.

    The JavaDoc seems to indicate that DropShadow does that internally and renders this resulting black circular shape. But it also knows how to render the original graphics, and it renders the red circle (the original graphic) on top of it. So the result is a red circle with a Shadow.

    I don't see how I could do that with chaining...

    I can mimic this Behaviour by storing a snapshot, then apply the effect and render the stored snapshot on top of it. But I guess that's far from optimal.
  • 4. Re: HowTo combine shadow and original graphic
    894410 Newbie
    Currently Being Moderated
    Can you explain in more detail what you are trying to achieve. Some pictures might help. I am not understanding what you are trying to achieve.
  • 5. Re: HowTo combine shadow and original graphic
    916161 Newbie
    Currently Being Moderated
    Hi Jasper,

    thanks for your reply. What I'm looking for is an explanation of what the JavaDoc of javafx.scene.effect.Shadow states:

    "This effect is primarily used along with its default black color for purposes of *combining it with the original to create a shadow*. It can also be used with a light color and combined with an original to create a glow effect. The DropShadow effect is a utility effect which automatically combines this Shadow effect with an original graphic for ease of adding a shadow to an existing scene graph Node with a single effect."

    Basically I want to know if "is primarily used" means that you -the JavaFX team- use it like that, or that we -the users of the API- can also use it like that. In case everyone can use it like that, an example of how I can do that (combine the effect with an original like DropShadow does it) would be helpful. As described above I found a way to do it (make a snapshot of the node and render that after applying the effect), but I hope that this JavaDoc indicates there's a better way.

    What I finally would like to achieve is create a pseudo 3-D Shadow for a 2-D orthogonal TileEngine. Here's a link how it would look like with a DropShadow:

    https://www.youtube.com/watch?v=uBsb9evptDw

    Obviously that is not what I want. So after reading the JavaDoc I assumed there might be a way to create my own Pseudo3DShadow using a similar approach to DropShadow. That's why I asked for clarification and an example.

    I hope my question is easier to understand with this explanation. If not, please let me know, and I'll try to clarify.

    Thanks

    Toni

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points