Package com.github.tommyettinger.textra
Class TextureArrayShaders
java.lang.Object
com.github.tommyettinger.textra.TextureArrayShaders
Utility methods that return vertex or fragment shader source code to be used in
These shader sources can be passed to
Mostly taken from Hyperlap2D's GitHub repo. Originally licensed under Apache 2.0, like TextraTypist and libGDX.
TextureArrayPolygonSpriteBatch or TextureArrayCpuPolygonSpriteBatch. These methods all require one of
those mentioned Batches to have been created before any shader source can be obtained, since creating either Texture
Array Batch calculates the number of texture units the GPU can handle.
These shader sources can be passed to
KnownFonts.initialize(String, String, String, String, String, String, String, String)
if the only batch or batches you intend to use for Font types are Texture Array Batches. To do this more easily, make
sure you have constructed a TextureArrayPolygonSpriteBatch or TextureArrayCpuPolygonSpriteBatch in create() or later,
then call initializeTextureArrayShaders() before using any methods from KnownFonts or creating any Font.
Mostly taken from Hyperlap2D's GitHub repo. Originally licensed under Apache 2.0, like TextraTypist and libGDX.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringThe fragment shader used for any rendering with aTextureArrayPolygonSpriteBatchorTextureArrayCpuPolygonSpriteBatchwhen no distance field effect is in use (or for a STANDARD font).static StringThe vertex shader used for any rendering with aTextureArrayPolygonSpriteBatchorTextureArrayCpuPolygonSpriteBatch, regardless of distance field.static voidThis is a convenience method to initialize the shaders inKnownFontsso they work withTextureArrayPolygonSpriteBatchand/orTextureArrayCpuPolygonSpriteBatch.static voidThis is a convenience method to initialize the shaders inKnownFontsso they work withTextureArrayPolygonSpriteBatchand/orTextureArrayCpuPolygonSpriteBatch.static StringThe fragment shader used for any rendering with aTextureArrayPolygonSpriteBatchorTextureArrayCpuPolygonSpriteBatchwhenFont.DistanceFieldType.MSDFis used.static StringAn alias fordefaultArrayVertexShader(); using that method is preferred.static StringReturns eithersdfArrayFragmentShader()orsdfDerivativeArrayFragmentShader(), depending on whether derivatives are supported.static StringThe fragment shader used for any rendering with aTextureArrayPolygonSpriteBatchorTextureArrayCpuPolygonSpriteBatchwhenFont.DistanceFieldType.SDFis used.static StringAn alias fordefaultArrayVertexShader(); using that method is preferred.static StringThe fragment shader used for any rendering with aTextureArrayPolygonSpriteBatchorTextureArrayCpuPolygonSpriteBatchwhenFont.DistanceFieldType.SDFis used.static StringAn alias fordefaultArrayVertexShader(); using that method is preferred.static StringReturns eithersdfOutlineArrayFragmentShader()orsdfOutlineDerivativeArrayFragmentShader(), depending on whether derivatives are supported.static StringThe fragment shader used for any rendering with aTextureArrayPolygonSpriteBatchorTextureArrayCpuPolygonSpriteBatchwhenFont.DistanceFieldType.SDF_OUTLINEis used.static StringAn alias fordefaultArrayVertexShader(); using that method is preferred.static StringThe fragment shader used for any rendering with aTextureArrayPolygonSpriteBatchorTextureArrayCpuPolygonSpriteBatchwhenFont.DistanceFieldType.SDF_OUTLINEis used.static StringAn alias fordefaultArrayVertexShader(); using that method is preferred.
-
Method Details
-
defaultArrayVertexShader
The vertex shader used for any rendering with aTextureArrayPolygonSpriteBatchorTextureArrayCpuPolygonSpriteBatch, regardless of distance field. The other vertex shaders here are simply aliases for this method.- Returns:
- a vertex shader String that works with TextureArray batches
-
defaultArrayFragmentShader
The fragment shader used for any rendering with aTextureArrayPolygonSpriteBatchorTextureArrayCpuPolygonSpriteBatchwhen no distance field effect is in use (or for a STANDARD font).- Returns:
- a fragment shader String that works with TextureArray batches
-
sdfArrayFragmentShader
The fragment shader used for any rendering with aTextureArrayPolygonSpriteBatchorTextureArrayCpuPolygonSpriteBatchwhenFont.DistanceFieldType.SDFis used. This shader has the uniformu_smoothingand expects to be used withdefaultArrayVertexShader()as its vertex shader (but any vertex shaders here are the same).- Returns:
- a fragment shader String that works with TextureArray batches
-
sdfArrayVertexShader
An alias fordefaultArrayVertexShader(); using that method is preferred.- Returns:
- a vertex shader String that works with TextureArray batches
-
sdfDerivativeArrayFragmentShader
The fragment shader used for any rendering with aTextureArrayPolygonSpriteBatchorTextureArrayCpuPolygonSpriteBatchwhenFont.DistanceFieldType.SDFis used. This particular shader uses the dFdx() and dFdy() methods from GLSL, which are only defined in desktop OpenGL or in mobile/browser OpenGL ES when the extension "GL_OES_standard_derivatives" is available and enabled. This tends to look a little fuzzy compared tosdfArrayFragmentShader(), and isn't quite as fast. This shader has the uniformu_smoothingand expects to be used withdefaultArrayVertexShader()as its vertex shader (but any vertex shaders here are the same).- Returns:
- a fragment shader String that works with TextureArray batches
-
sdfDerivativeArrayVertexShader
An alias fordefaultArrayVertexShader(); using that method is preferred.- Returns:
- a vertex shader String that works with TextureArray batches
-
sdfAdaptiveArrayFragmentShader
Returns eithersdfArrayFragmentShader()orsdfDerivativeArrayFragmentShader(), depending on whether derivatives are supported. This shader has the uniformu_smoothingand expects to be used withdefaultArrayVertexShader()as its vertex shader (but any vertex shaders here are the same).- Returns:
- a fragment shader String for an SDF shader
-
sdfOutlineArrayFragmentShader
The fragment shader used for any rendering with aTextureArrayPolygonSpriteBatchorTextureArrayCpuPolygonSpriteBatchwhenFont.DistanceFieldType.SDF_OUTLINEis used. This shader has the uniformu_smoothingand expects to be used withdefaultArrayVertexShader()as its vertex shader (but any vertex shaders here are the same).
This draws a black outline around any text with an SDF_OUTLINE distance field, and leaves the color inside the outlined area the same. If the outline's thickness isn't suitable for your purposes, you may want to adjust the "closeness" constant in this code. You can replace the text"const float closeness = 0.0625 ;"(with multiple spaces around the value to make distinguishing it easier), using any value between 0.0 and 0.5 to change the outline thickness. Lower values lead to thicker outlines, and values closer to 0.5 should lead to thinner.- Returns:
- a fragment shader String that works with TextureArray batches
-
sdfOutlineArrayVertexShader
An alias fordefaultArrayVertexShader(); using that method is preferred.- Returns:
- a vertex shader String that works with TextureArray batches
-
sdfOutlineDerivativeArrayFragmentShader
The fragment shader used for any rendering with aTextureArrayPolygonSpriteBatchorTextureArrayCpuPolygonSpriteBatchwhenFont.DistanceFieldType.SDF_OUTLINEis used. This particular shader uses the dFdx() and dFdy() methods from GLSL, which are only defined in desktop OpenGL or in mobile/browser OpenGL ES when the extension "GL_OES_standard_derivatives" is available and enabled. This tends to look a little fuzzy compared tosdfOutlineArrayFragmentShader(), and isn't quite as fast. This shader has the uniformu_smoothingand expects to be used withdefaultArrayVertexShader()as its vertex shader (but any vertex shaders here are the same).
This draws a black outline around any text with an SDF_OUTLINE distance field, and leaves the color inside the outlined area the same. If the outline's thickness isn't suitable for your purposes, you may want to adjust the "closeness" constant in this code. You can replace the text"const float closeness = 0.0625 ;"(with multiple spaces around the value to make distinguishing it easier), using any value between 0.0 and 0.5 to change the outline thickness. Lower values lead to thicker outlines, and values closer to 0.5 should lead to thinner.- Returns:
- a fragment shader String that works with TextureArray batches
-
sdfOutlineDerivativeArrayVertexShader
An alias fordefaultArrayVertexShader(); using that method is preferred.- Returns:
- a vertex shader String that works with TextureArray batches
-
sdfOutlineAdaptiveArrayFragmentShader
Returns eithersdfOutlineArrayFragmentShader()orsdfOutlineDerivativeArrayFragmentShader(), depending on whether derivatives are supported. This shader has the uniformu_smoothingand expects to be used withdefaultArrayVertexShader()as its vertex shader (but any vertex shaders here are the same).- Returns:
- a fragment shader String for an SDF shader
-
msdfArrayFragmentShader
The fragment shader used for any rendering with aTextureArrayPolygonSpriteBatchorTextureArrayCpuPolygonSpriteBatchwhenFont.DistanceFieldType.MSDFis used. This shader has the uniformu_smoothingand expects to be used withdefaultArrayVertexShader()as its vertex shader (but any vertex shaders here are the same).- Returns:
- a fragment shader String that works with TextureArray batches
-
msdfArrayVertexShader
An alias fordefaultArrayVertexShader(); using that method is preferred.- Returns:
- a vertex shader String that works with TextureArray batches
-
initializeTextureArrayShaders
public static void initializeTextureArrayShaders()This is a convenience method to initialize the shaders inKnownFontsso they work withTextureArrayPolygonSpriteBatchand/orTextureArrayCpuPolygonSpriteBatch. This can only be called after one of those mentioned Batches has already been constructed, in create() or later. Because this callsKnownFonts.initialize(String, String, String, String, String, String, String, String), it can't be called after any methods from KnownFonts have already been called, or after any Font is created. UnlikeinitializeAdaptiveTextureArrayShaders(), this always uses the same shaders on all platforms. It doesn't ever use derivatives in shaders. -
initializeAdaptiveTextureArrayShaders
public static void initializeAdaptiveTextureArrayShaders()This is a convenience method to initialize the shaders inKnownFontsso they work withTextureArrayPolygonSpriteBatchand/orTextureArrayCpuPolygonSpriteBatch. This can only be called after one of those mentioned Batches has already been constructed, in create() or later. Because this callsKnownFonts.initialize(String, String, String, String, String, String, String, String), it can't be called after any methods from KnownFonts have already been called, or after any Font is created. This variant will adapt the SDF shaders depending on whether derivatives are available, and will use them if they are. If used heavily, the shaders that use derivatives may not perform as well as the ones that don't. They may look better (subjectively) when used, which can only be on desktop and mobile platforms right now (no web browsers).
-