3

is it possible to create custom effects for JavaFX, based on a Pixle Shader? I found this article but what is Decora? I cannot find anything about it.

THX

1
  • 1
    I think the best way is to try and find out. I know the JavaFX source contains shaders, so my guess would be that this article is not obsolete. I think Decora is either some library or app that the author used as inspiration. Mar 3, 2018 at 10:34

3 Answers 3

5

Currently no - in the abstract base class Effect.java, there are abstract package-private methods like, copy(), sync(), update() etc.

The Decora project is discussed here: http://labonnesoupe.org/static/code/ . I asked about opening JSL, to make some kind of public API in the developer OpenJFX thread perhaps 6 months ago, and was told, "no, there are no plans to open this api to the public".

As you may be aware, OpenJFX are considering new committers, which works, I believe on the premise that you sign an Oracle contributor agreement, and are voted in by lazy consensus. Perhaps this will shunt this much needed area into life.

In my own 2D game, I use Guassian Blurs, and Blooms, to highlight spell strikes, and I believe Decora was used in developing these Effects. However, they are pitifully slow. Taking my FPS from around 250 down to around 30 on a 10 series NVidia card. I would love to see improvements here.

I emailed Chris Campbell (author of Labonnesoupe) asking about his work on JavaFX shaders, but he emailed me back to say it was over 8 years ago, and he's not up on the latest. A search of web reveals that all reference to Decora is now ancient.

1

Theoretically it is possible to create you custom effect in JavaFx however using way u probably won't like. Abstract class javafx.scene.effect.Effect has internal methods inside, that is right. But based on the fact that internal means "package private" we can do the following. In your project create a new package called "javafx.scene.effect" the same as Effect class is in, and inside this newly created package just create your custom effect class that extends javafx.scene.effect.Effect and that's it you have your custom JavaFx effect.
Custom Effect class example:

package javafx.scene.effect;

import com.sun.javafx.geom.BaseBounds;
import com.sun.javafx.geom.Rectangle;
import com.sun.javafx.geom.transform.BaseTransform;
import com.sun.javafx.scene.BoundsAccessor;
import com.sun.scenario.effect.FilterContext;
import com.sun.scenario.effect.ImageData;

import javafx.scene.Node;

public class MyEffect extends javafx.scene.effect.Effect
{
    public MyEffect()
    {
        
    }

    @Override
    com.sun.scenario.effect.Effect impl_createImpl()
    {
        return new com.sun.scenario.effect.Effect()
        {
            
            @Override
            public boolean reducesOpaquePixels()
            {
                // TODO Auto-generated method stub
                return false;
            }
            
            @Override
            public BaseBounds getBounds(BaseTransform transform, com.sun.scenario.effect.Effect defaultInput)
            {
                // TODO Auto-generated method stub
                return null;
            }
            
            @Override
            public AccelType getAccelType(FilterContext fctx)
            {
                // TODO Auto-generated method stub
                return null;
            }
            
            @Override
            public ImageData filter(FilterContext fctx, BaseTransform transform, Rectangle outputClip, Object renderHelper, com.sun.scenario.effect.Effect defaultInput)
            {
                // TODO Auto-generated method stub
                return null;
            }
        };
    }

    @Override
    void impl_update()
    {
        // TODO Auto-generated method stub

    }

    @Override
    public BaseBounds impl_getBounds(BaseBounds bounds, BaseTransform tx, Node node, BoundsAccessor boundsAccessor)
    {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    boolean impl_checkChainContains(javafx.scene.effect.Effect e)
    {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public javafx.scene.effect.Effect impl_copy()
    {
        // TODO Auto-generated method stub
        return null;
    }
}

However I have literally no idea what those inhered methods in from javafx.scene.effect.Effect supposed to do so you need to figure it out :) Also, keep in mind that internal/private things are private for some reason (even though I also do not see that reason in this case)!
Aditional:
What I currently know is that JavaFx Effects are only some sort of "masks" or "providers" for Effects from `com.sun.scenario.effect` and there are many com.sun.scenario.effect children classes that have no direct JavaFx version/implementation so you should be theoretically able to add these ones into JavaFx by your self using my solution! But again there is a question if this is a good idea because I think `com.sun.scenario.effect` is something that regular JavaFx programer supposed to not even know about. But I will let you to decide!
0

Use libgdx. Its free and Works on Web HTML 5 webgl ,ios,android,all desktop and with full shader support

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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