Teragam / JFXShader

Allows custom effect shaders in JavaFX

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.0</version>
</dependency>

Requirements

  • Java 11 or higher
  • JavaFX version 18 or higher

Limitations

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

  • Only fragment/pixel shaders are supported. The vertex shaders of 2D effects cannot be overwritten.
  • The fragment/pixel shaders only support one active render target (output texture).
  • It is not possible to use OpenGL shaders on Windows.
  • For DirectX, only ps_3_0 shaders are supported.
  • JavaFX requires DirectX shaders to be compiled with the fxc compiler. The following command can be used to compile HLSL shaders: fxc.exe /nologo /T ps_3_0 /Fo .\shader.obj .\shader.hlsl
  • On some systems (i.e. VMs), it is necessary to enable the GPU usage by setting the prism.forceGPU system property to true.
  • Due to dirty region optimizations, JavaFX may apply the shader effect only to the dirty region of the node. This can lead to artifacts. To disable dirty region optimizations, set the prism.dirtyopts system property to false.

About

Allows custom effect shaders in JavaFX

License:Apache License 2.0


Languages

Language:Java 89.9%Language:C++ 4.9%Language:HLSL 2.6%Language:GLSL 2.3%Language:Makefile 0.4%