Teragam / JFXShader

Allows custom effect shaders in JavaFX
Apache License 2.0
33 stars 1 forks source link
effects javafx shaders

Maven Central License

JFXShader

Allows custom effect shaders in JavaFX using OpenGL (GLSL) or DirectX (HLSL).

Usage

Examples can be found in the wiki and in the samples package.

2D shader effects

A custom shader can be applied to any JavaFX node hierarchy by using setEffect:

StackPane pane = new StackPane(getOtherContent());

// Instead of using existing JavaFX effects like SepiaTone or ColorAdjust,
// we can apply our own effect with custom shaders:
MyCustomShaderEffect effect = new MyCustomShaderEffect(); 
pane.setEffect(effect.getFXEffect());
// Custom parameters can be set and used in the shader:
effect.setMyCustomParameter(2.0);

Instructions on how to implement a custom shader effect can be found in the wiki.

3D shader materials

A custom material can be applied to any Shape3D by using setMaterial:

Sphere sphere = new Sphere(100);

// Instead of being limited to PhongMaterial,
// we can apply our own material with custom shaders:
MyCustomShaderMaterial material = new MyCustomShaderMaterial();
sphere.setMaterial(material.getFXMaterial());
// Custom parameters or textures can be set and used in the shader:
material.setMyCustomParameter(3.0);
material.setMyCustomTexture(new Image("myCustomTexture.png"));

Maven

To include JFXShader in a Maven project, add the following dependency to the pom.xml:

<dependency>
    <groupId>de.teragam</groupId>
    <artifactId>jfxshader</artifactId>
    <version>1.3.1</version>
</dependency>

Requirements

Limitations

This library is bound to the restrictions of the JavaFX effects system. The following limitations apply: