Shader API proposal
Kevin Rushforth
kevin.rushforth at oracle.com
Fri Mar 19 13:28:39 UTC 2021
This isn't the first time that the question of allowing some sort of
application-provided shaders has come up. There is an Enhancement
request in JBS to track this, JDK-8134662 [1], but it's just a placeholder.
I don't want to discourage research in this area, but let me point out
just a few of the challenges that providing such an API would pose:
1. JavaFX already uses implicitly-generated shaders -- Both Prism (for
rendering) and Decora (for image-based filter effects) create
build-time-generated vertex and fragment shaders. Prism uses these
generated shaders to render shapes, text, and images. It passes a
generated set of uniform and varying parameters, along with the
necessary texture objects, to these shaders. It isn't clear how an
application-provided shader would interact with this. There are several
possible approaches one might take with various pros and cons. The
Decora shaders are less likely to interfere, but that's another area
where an application developer might want to use an application-provided
shader.
2. Add missing operations to JSL language -- The JSL language is only
complete enough to do what was needed to implement the Decora (image
filter effects) and 2D Prism rendering shaders. As such it is a subset
of what GLSL, HLSL, and MSL can provide. Along with this, the JSLC (JSL
Compiler) would need to implement them, and we would need a much more
robust set of tests for the compiler.
3. JSL Language specification -- right now it is an internal tool, so
the level of documentation needed is very low. If we were to productize
it, it would need a complete spec along the lines of the FXML or JavaFX
CSS spec.
I think research in this area would be interesting, as long as you look
at it as a research project, and not as a feature that is likely to
become part of JavaFX any time soon.
-- Kevin
[1] https://bugs.openjdk.java.net/browse/JDK-8134662
On 3/16/2021 6:15 PM, Jacky Guo wrote:
> This is my proposal as to how the shader API should work:
>
> In javafx.scene.paint 2 new classes would be added:
>
> - Shader
> - ShadedMaterial
>
> ShadedMaterial would contain methods relating to the material itself,
> probably including texture maps and the like.
>
> Shader would contain more low-level functions, like passing values to the
> shader or similar.
>
> I'm not sure if all the functionality should belong to one class, but in my
> mind, separating it like this will have its benefits.
>
> In addition, I haven't dabbled much with native graphics, so I will be
> needing some guidance on that end.
More information about the openjfx-discuss
mailing list