Class ShaderUtil

java.lang.Object
org.boxutil.util.ShaderUtil

public final class ShaderUtil extends Object
For all result texture, recommend to use storage texture for performance.

In some shader program making method:

LetterMeans
VVertex shader
TTessellation (Control and Evaluation) shader
GGeometry shader
FFragment shader
CCompute shader
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final record 
     
    static interface 
     
    static class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final byte
     
    static final byte
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    applyImageBilateralFilter(int source, boolean useRed, byte radius, float sigmaSpace, float sigmaRange, int texWidth, int texHeight, boolean bit16OutMode)
    Separated GPU bilateral filter.
    static void
    applyImageBilateralFilter(int source, boolean useRed, byte radius, float sigmaSpace, float sigmaRange, int texWidth, int texHeight, int result, boolean bit16OutMode)
    Separated GPU bilateral filter.
    static void
    applyImageBilateralFilter(int source, int sourceOffsetX, int sourceOffsetY, boolean useRed, byte radius, float sigmaSpace, float sigmaRange, int texWidth, int texHeight, int result, int resultOffsetX, int resultOffsetY, boolean bit16OutMode)
    Separated GPU bilateral filter.
    static void
    applyImageGaussianBlur(int source, boolean useRed, byte step, int texWidth, int texHeight, boolean bit16OutMode)
    Simple gaussian blur computing, only for RGBA and R texture.
    static void
    applyImageGaussianBlur(int source, boolean useRed, byte step, int texWidth, int texHeight, int result, boolean bit16OutMode)
    Simple gaussian blur computing, only for RGBA and R texture.
    static void
    applyImageGaussianBlur(int source, int sourceOffsetX, int sourceOffsetY, boolean useRed, byte step, int texWidth, int texHeight, int result, int resultOffsetX, int resultOffsetY, boolean bit16OutMode)
    Simple gaussian blur computing, only for RGBA and R texture.
    static void
    applyRadialBlur(int source, org.lwjgl.util.vector.Vector2f center, short samples, float radius, float alphaStrength, boolean isAdditiveBlend)
    Classical radial blur effect.
    static void
    applyRadialBlur(int source, org.lwjgl.util.vector.Vector2f center, short samples, float radius, float alphaStrength, int dstX, int dstY, int dstWidth, int dstHeight, boolean isAdditiveBlend)
    Classical radial blur effect.
    static void
    blitFBO(int read, int draw)
     
    static void
    blitFBO(int read, int draw, int width, int height)
     
    static void
    blitFBO(int read, int draw, int srcX1, int srcY1, int dstX1, int dstY1)
     
    static void
    blitFBO(int read, int draw, int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1)
     
    static void
    blitToScreen(int fbo)
     
    static void
    copyFromScreen(int fbo)
     
    static long
    createBindlessImage(int texture, int internalFormat)
     
    static long
    createBindlessImage(int texture, int level, boolean layered, int layer, int access, int internalFormat)
     
    static long
    createBindlessTexture(int texture)
     
    static int
    createComputeShaders(String loggerTag, String... source)
     
    static int
    createComputeShaders(String loggerTag, ShaderUtil.LinkCondition beforeLinkExc, String... source)
     
    static int
    createComputeShadersFormPath(String loggerTag, String... shadersPath)
     
    static int
    createComputeShadersFormPath(String loggerTag, ShaderUtil.LinkCondition beforeLinkExc, String... shadersPath)
     
    static int
    createShader(String loggerTag, String shader, int shaderType)
     
    static int
    createShaderProgram(String loggerTag, int[] types, String... shaders)
     
    static int
    createShaderProgram(String loggerTag, ShaderUtil.LinkCondition beforeLinkExc, int[] types, String... shaders)
     
    static int
    createShaderProgramFromPath(String loggerTag, String... shadersPath)
     
    static int
    createShaderProgramFromPath(String loggerTag, ShaderUtil.LinkCondition beforeLinkExc, String... shadersPath)
     
    static int
    createShaderVF(String loggerTag, String vert, String frag)
     
    static int
    createShaderVF(String loggerTag, ShaderUtil.LinkCondition beforeLinkExc, String vert, String frag)
     
    static int
    createShaderVFFormPath(String loggerTag, String vertPath, String fragPath)
     
    static int
    createShaderVFFormPath(String loggerTag, ShaderUtil.LinkCondition beforeLinkExc, String vertPath, String fragPath)
     
    static int
    createShaderVGF(String loggerTag, String vert, String geom, String frag)
     
    static int
    createShaderVGF(String loggerTag, ShaderUtil.LinkCondition beforeLinkExc, String vert, String geom, String frag)
     
    static int
    createShaderVGFFromPath(String loggerTag, String vertPath, String geomPath, String fragPath)
     
    static int
    createShaderVGFFromPath(String loggerTag, ShaderUtil.LinkCondition beforeLinkExc, String vertPath, String geomPath, String fragPath)
     
    static int
    createShaderVTF(String loggerTag, String vert, String tessC, String tessE, String frag)
     
    static int
    createShaderVTF(String loggerTag, ShaderUtil.LinkCondition beforeLinkExc, String vert, String tessC, String tessE, String frag)
     
    static int
    createShaderVTFFromPath(String loggerTag, String vertPath, String tessCPath, String tessEPath, String fragPath)
     
    static int
    createShaderVTFFromPath(String loggerTag, ShaderUtil.LinkCondition beforeLinkExc, String vertPath, String tessCPath, String tessEPath, String fragPath)
     
    static int
    createShaderVTGF(String loggerTag, String vert, String tessC, String tessE, String geom, String frag)
     
    static int
    createShaderVTGF(String loggerTag, ShaderUtil.LinkCondition beforeLinkExc, String vert, String tessC, String tessE, String geom, String frag)
     
    static int
    createShaderVTGFFromPath(String loggerTag, String vertPath, String tessCPath, String tessEPath, String geomPath, String fragPath)
     
    static int
    createShaderVTGFFromPath(String loggerTag, ShaderUtil.LinkCondition beforeLinkExc, String vertPath, String tessCPath, String tessEPath, String geomPath, String fragPath)
     
    static int[]
    genLegacySDF(int source, int checkChannel, int sourceOffsetX, int sourceOffsetY, int localWidth, int localHeight, int extraWidth, int extraHeight, float outsideThreshold, byte step, float resultInsidePreMultiply, float resultOutsidePreMultiply)
    CPU multi-thread parallel SDF generation method.
    static int[]
    genLegacySDF(int source, int checkChannel, int sourceOffsetX, int sourceOffsetY, int localWidth, int localHeight, int extraWidth, int extraHeight, float outsideThreshold, byte step, float resultInsidePreMultiply, float resultOutsidePreMultiply, int resultTex, int resultOffsetX, int resultOffsetY)
    CPU multi-thread parallel SDF generation method.
    static int
    genNormalMapFromRGB(int source, int sourceOffsetX, int sourceOffsetY, int srcLocalWidth, int srcLocalHeight, ShaderUtil.NormalMapGenParam param)
    GPU normal map generation from RGB texture for sprites.
    static int
    genNormalMapFromRGB(int source, int sourceOffsetX, int sourceOffsetY, int srcLocalWidth, int srcLocalHeight, ShaderUtil.NormalMapGenParam param, int resultTex, int resultOffsetX, int resultOffsetY)
    GPU normal map generation from RGB texture for sprites.
    static int
    genNormalMapFromRGB(int source, int srcLocalWidth, int srcLocalHeight, ShaderUtil.NormalMapGenParam param)
    GPU normal map generation from RGB texture for sprites.
    static int
    genNormalMapFromRGB(int source, int srcLocalWidth, int srcLocalHeight, ShaderUtil.NormalMapGenParam param, int resultTex)
    GPU normal map generation from RGB texture for sprites.
    static int[]
    genSDF(int source, int checkChannel, int localWidth, int localHeight, int extraWidth, int extraHeight, float outsideThreshold, byte step, float resultInsidePreMultiply, float resultOutsidePreMultiply)
    Fast GPU SDF generation method.
    static int[]
    genSDF(int source, int checkChannel, int localWidth, int localHeight, int extraWidth, int extraHeight, float outsideThreshold, byte step, float resultInsidePreMultiply, float resultOutsidePreMultiply, boolean bit16OutMode)
    Fast GPU SDF generation method.
    static int[]
    genSDF(int source, int checkChannel, int localWidth, int localHeight, int extraWidth, int extraHeight, float outsideThreshold, byte step, float resultInsidePreMultiply, float resultOutsidePreMultiply, int resultTex)
    Fast GPU SDF generation method.
    static int[]
    genSDF(int source, int checkChannel, int localWidth, int localHeight, int extraWidth, int extraHeight, float outsideThreshold, byte step, float resultInsidePreMultiply, float resultOutsidePreMultiply, int resultTex, boolean bit16OutMode)
    Fast GPU SDF generation method.
    static int[]
    genSDF(int source, int checkChannel, int sourceOffsetX, int sourceOffsetY, int localWidth, int localHeight, int extraWidth, int extraHeight, float outsideThreshold, byte step, float resultInsidePreMultiply, float resultOutsidePreMultiply, boolean bit16OutMode)
    Fast GPU SDF generation method.
    static int[]
    genSDF(int source, int checkChannel, int sourceOffsetX, int sourceOffsetY, int localWidth, int localHeight, int extraWidth, int extraHeight, float outsideThreshold, byte step, float resultInsidePreMultiply, float resultOutsidePreMultiply, int resultTex, int resultOffsetX, int resultOffsetY, boolean bit16OutMode)
    Fast GPU SDF generation method.
    static String
    getShaderName(int type)
     
    static int
     
    static int
     
    static int
    imageDFT(int source, boolean useRed, int texWidth, int texHeight, boolean f16OutMode)
    GPU DFT(Discrete Fourier Transform), slow but still faster more than CPU computing.
    static int
    imageDFT(int source, boolean useRed, int texWidth, int texHeight, int result, boolean f16OutMode)
    GPU DFT(Discrete Fourier Transform), slow but still faster more than CPU computing.
    static int
    imageDFT(int source, int sourceOffsetX, int sourceOffsetY, boolean useRed, int texWidth, int texHeight, boolean f16OutMode)
    GPU DFT(Discrete Fourier Transform), slow but still faster more than CPU computing.
    static int
    imageDFT(int source, int sourceOffsetX, int sourceOffsetY, boolean useRed, int texWidth, int texHeight, int result, int resultOffsetX, int resultOffsetY, boolean f16OutMode)
    GPU DFT(Discrete Fourier Transform), slow but still faster more than CPU computing.
    static int
    imageIDFT(int source, boolean useRed, int texWidth, int texHeight, boolean f16InMode, boolean f16OutMode)
    GPU IDFT(Inverse Discrete Fourier Transform), slow but still faster more than CPU computing.
    static int
    imageIDFT(int source, boolean useRed, int texWidth, int texHeight, int result, boolean f16InMode, boolean f16OutMode)
    GPU IDFT(Inverse Discrete Fourier Transform), slow but still faster more than CPU computing.
    static int
    imageIDFT(int source, int sourceOffsetX, int sourceOffsetY, boolean useRed, int texWidth, int texHeight, boolean f16InMode, boolean f16OutMode)
    GPU IDFT(Inverse Discrete Fourier Transform), slow but still faster more than CPU computing.
    static int
    imageIDFT(int source, int sourceOffsetX, int sourceOffsetY, boolean useRed, int texWidth, int texHeight, int result, int resultOffsetX, int resultOffsetY, boolean f16InMode, boolean f16OutMode)
    GPU IDFT(Inverse Discrete Fourier Transform), slow but still faster more than CPU computing.
     
    static void
     
    static void
    releaseBindlessTexture(long texture)
     

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • getShaderName

      public static String getShaderName(int type)
    • getTypeFromPath

      public static int getTypeFromPath(@NotNull String path)
    • getTypeFromFormat

      public static int getTypeFromFormat(@NotNull String format)
    • makeShaderBindingLocation

      public static ShaderUtil.LinkCondition makeShaderBindingLocation(ShaderUtil.BindingLocationStruct... bindingLocations)
    • createShaderVF

      public static int createShaderVF(@Nullable String loggerTag, @Nullable ShaderUtil.LinkCondition beforeLinkExc, String vert, String frag)
      Parameters:
      loggerTag - for locating in log when created or failed.
      beforeLinkExc - accept a int type program id, executing something after all of the glAttachShader calls but before glLinkProgram calls.
    • createShaderVF

      public static int createShaderVF(@Nullable String loggerTag, String vert, String frag)
      Parameters:
      loggerTag - for locating in log when created or failed.
    • createShaderVFFormPath

      public static int createShaderVFFormPath(@Nullable String loggerTag, @Nullable ShaderUtil.LinkCondition beforeLinkExc, String vertPath, String fragPath)
      Parameters:
      loggerTag - for locating in log when created or failed.
      beforeLinkExc - accept a int type program id, executing something after all of the glAttachShader calls but before glLinkProgram calls.
    • createShaderVFFormPath

      public static int createShaderVFFormPath(@Nullable String loggerTag, String vertPath, String fragPath)
      Parameters:
      loggerTag - for locating in log when created or failed.
    • createShaderVGF

      public static int createShaderVGF(@Nullable String loggerTag, @Nullable ShaderUtil.LinkCondition beforeLinkExc, String vert, String geom, String frag)
      Parameters:
      loggerTag - for locating in log when created or failed.
      beforeLinkExc - accept a int type program id, executing something after all of the glAttachShader calls but before glLinkProgram calls.
    • createShaderVGF

      public static int createShaderVGF(@Nullable String loggerTag, String vert, String geom, String frag)
      Parameters:
      loggerTag - for locating in log when created or failed.
    • createShaderVGFFromPath

      public static int createShaderVGFFromPath(@Nullable String loggerTag, @Nullable ShaderUtil.LinkCondition beforeLinkExc, String vertPath, String geomPath, String fragPath)
      Parameters:
      loggerTag - for locating in log when created or failed.
      beforeLinkExc - accept a int type program id, executing something after all of the glAttachShader calls but before glLinkProgram calls.
    • createShaderVGFFromPath

      public static int createShaderVGFFromPath(@Nullable String loggerTag, String vertPath, String geomPath, String fragPath)
      Parameters:
      loggerTag - for locating in log when created or failed.
    • createShaderVTF

      public static int createShaderVTF(@Nullable String loggerTag, @Nullable ShaderUtil.LinkCondition beforeLinkExc, String vert, String tessC, String tessE, String frag)
      Parameters:
      loggerTag - for locating in log when created or failed.
      beforeLinkExc - accept a int type program id, executing something after all of the glAttachShader calls but before glLinkProgram calls.
    • createShaderVTF

      public static int createShaderVTF(@Nullable String loggerTag, String vert, String tessC, String tessE, String frag)
      Parameters:
      loggerTag - for locating in log when created or failed.
    • createShaderVTFFromPath

      public static int createShaderVTFFromPath(@Nullable String loggerTag, @Nullable ShaderUtil.LinkCondition beforeLinkExc, String vertPath, String tessCPath, String tessEPath, String fragPath)
      Parameters:
      loggerTag - for locating in log when created or failed.
      beforeLinkExc - accept a int type program id, executing something after all of the glAttachShader calls but before glLinkProgram calls.
    • createShaderVTFFromPath

      public static int createShaderVTFFromPath(@Nullable String loggerTag, String vertPath, String tessCPath, String tessEPath, String fragPath)
      Parameters:
      loggerTag - for locating in log when created or failed.
    • createShaderVTGF

      public static int createShaderVTGF(@Nullable String loggerTag, @Nullable ShaderUtil.LinkCondition beforeLinkExc, String vert, String tessC, String tessE, String geom, String frag)
      Parameters:
      loggerTag - for locating in log when created or failed.
      beforeLinkExc - accept a int type program id, executing something after all of the glAttachShader calls but before glLinkProgram calls.
    • createShaderVTGF

      public static int createShaderVTGF(@Nullable String loggerTag, String vert, String tessC, String tessE, String geom, String frag)
      Parameters:
      loggerTag - for locating in log when created or failed.
    • createShaderVTGFFromPath

      public static int createShaderVTGFFromPath(@Nullable String loggerTag, @Nullable ShaderUtil.LinkCondition beforeLinkExc, String vertPath, String tessCPath, String tessEPath, String geomPath, String fragPath)
      Parameters:
      loggerTag - for locating in log when created or failed.
      beforeLinkExc - accept a int type program id, executing something after all of the glAttachShader calls but before glLinkProgram calls.
    • createShaderVTGFFromPath

      public static int createShaderVTGFFromPath(@Nullable String loggerTag, String vertPath, String tessCPath, String tessEPath, String geomPath, String fragPath)
      Parameters:
      loggerTag - for locating in log when created or failed.
    • createComputeShaders

      public static int createComputeShaders(@Nullable String loggerTag, @Nullable ShaderUtil.LinkCondition beforeLinkExc, String... source)
      Parameters:
      loggerTag - for locating in log when created or failed.
      beforeLinkExc - accept a int type program id, executing something after all of the glAttachShader calls but before glLinkProgram calls.
      source - may only have one shader source normally.
    • createComputeShaders

      public static int createComputeShaders(@Nullable String loggerTag, String... source)
      Parameters:
      loggerTag - for locating in log when created or failed.
      source - may only have one shader source normally.
    • createComputeShadersFormPath

      public static int createComputeShadersFormPath(@Nullable String loggerTag, @Nullable ShaderUtil.LinkCondition beforeLinkExc, String... shadersPath)
      Parameters:
      loggerTag - for locating in log when created or failed.
      beforeLinkExc - accept a int type program id, executing something after all of the glAttachShader calls but before glLinkProgram calls.
      shadersPath - may only have one shader source normally.
    • createComputeShadersFormPath

      public static int createComputeShadersFormPath(@Nullable String loggerTag, String... shadersPath)
      Parameters:
      loggerTag - for locating in log when created or failed.
      shadersPath - may only have one shader source normally.
    • createShader

      public static int createShader(@Nullable String loggerTag, String shader, int shaderType)
      Parameters:
      loggerTag - for locating in log when created or failed.
    • createShaderProgram

      public static int createShaderProgram(@Nullable String loggerTag, @Nullable ShaderUtil.LinkCondition beforeLinkExc, int[] types, String... shaders)
      Parameters:
      loggerTag - for locating in log when created or failed.
      beforeLinkExc - accept a int type program id, executing something after all of the glAttachShader calls but before glLinkProgram calls.
    • createShaderProgram

      public static int createShaderProgram(@Nullable String loggerTag, int[] types, String... shaders)
      Parameters:
      loggerTag - for locating in log when created or failed.
    • createShaderProgramFromPath

      public static int createShaderProgramFromPath(@Nullable String loggerTag, @Nullable ShaderUtil.LinkCondition beforeLinkExc, String... shadersPath)
      Parameters:
      loggerTag - for locating in log when created or failed.
      beforeLinkExc - accept a int type program id, executing something after all of the glAttachShader calls but before glLinkProgram calls.
      shadersPath - must be under the format:
      Shader TypeLegal Format
      Vertex*.vert *.vsh
      Tess-Control*.tesc
      Tess-Evaluation*.tese
      Geometry*.geom *.gsh
      Fragment*.frag *.fsh
      Compute*.comp *.csh
    • createShaderProgramFromPath

      public static int createShaderProgramFromPath(@Nullable String loggerTag, String... shadersPath)
      Parameters:
      loggerTag - for locating in log when created or failed.
      shadersPath - should be in the format:
      Shader TypeLegal Format
      Vertex*.vert *.vsh
      Tess-Control*.tesc
      Tess-Evaluation*.tese
      Geometry*.geom *.gsh
      Fragment*.frag *.fsh
      Compute*.comp *.csh
    • createBindlessTexture

      public static long createBindlessTexture(int texture)
    • createBindlessImage

      public static long createBindlessImage(int texture, int internalFormat)
    • createBindlessImage

      public static long createBindlessImage(int texture, int level, boolean layered, int layer, int access, int internalFormat)
    • releaseBindlessTexture

      public static void releaseBindlessTexture(long texture)
    • releaseBindlessImage

      public static void releaseBindlessImage(long image)
    • blitFBO

      public static void blitFBO(int read, int draw, int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1)
    • blitFBO

      public static void blitFBO(int read, int draw, int srcX1, int srcY1, int dstX1, int dstY1)
    • blitFBO

      public static void blitFBO(int read, int draw, int width, int height)
    • blitFBO

      public static void blitFBO(int read, int draw)
    • copyFromScreen

      public static void copyFromScreen(int fbo)
    • blitToScreen

      public static void blitToScreen(int fbo)
    • genLegacySDF

      public static int[] genLegacySDF(int source, int checkChannel, int sourceOffsetX, int sourceOffsetY, int localWidth, int localHeight, int extraWidth, int extraHeight, float outsideThreshold, byte step, float resultInsidePreMultiply, float resultOutsidePreMultiply, int resultTex, int resultOffsetX, int resultOffsetY)
      CPU multi-thread parallel SDF generation method.

      Vanilla supported.

      Parameters:
      source - must be RGBA8 texture.
      checkChannel - valid value: GL11.GL_RED, GL11.GL_GREEN, GL11.GL_BLUE, GL11.GL_ALPHA, GL11.GL_RGB; default is GL11.GL_ALPHA.
      sourceOffsetX - the source texture region left-bottom origin x-position.
      sourceOffsetY - the source texture region left-bottom origin y-position.
      extraWidth - border width for sdf texture, positive integer value required.
      extraHeight - border height for sdf texture, positive integer value required.
      outsideThreshold - when pixel check value less than or equal the value, it will be considered as outside.
      step - 8 or 9 for general usage, range from 0 to 30; also you can use CalculateUtil.getExponentPOTMin(Math.max(localWidth, localHeight)) for automatic step calculation.
      resultInsidePreMultiply - 0.01 or (1.0f / required thickness) for general usage.
      resultOutsidePreMultiply - 0.01 or (1.0f / max(extraWidth, extraHeight)) for general usage.
      resultTex - texture to store result, must be GL11.GL_INTENSITY8 texture and size must be greater than or equal to the final size.
      resultOffsetX - the result texture region left-bottom origin x-position.
      resultOffsetY - the result texture region left-bottom origin x-position.
      Returns:
      generated sdf texture with GL11.GL_INTENSITY8 POT at [0.0, 1.0], texture return 0 if failed; int[] = {texture, validWidth, validHeight, glRealWidth, glRealHeight}
    • genLegacySDF

      public static int[] genLegacySDF(int source, int checkChannel, int sourceOffsetX, int sourceOffsetY, int localWidth, int localHeight, int extraWidth, int extraHeight, float outsideThreshold, byte step, float resultInsidePreMultiply, float resultOutsidePreMultiply)
      CPU multi-thread parallel SDF generation method.

      Vanilla supported.

      Parameters:
      source - must be RGBA8 texture.
      checkChannel - valid value: GL11.GL_RED, GL11.GL_GREEN, GL11.GL_BLUE, GL11.GL_ALPHA, GL11.GL_RGB; default is GL11.GL_ALPHA.
      sourceOffsetX - the source texture region left-bottom origin x-position.
      sourceOffsetY - the source texture region left-bottom origin y-position.
      extraWidth - border width for sdf texture, positive integer value required.
      extraHeight - border height for sdf texture, positive integer value required.
      outsideThreshold - when pixel check value less than or equal the value, it will be considered as outside.
      step - 8 or 9 for general usage, range from 0 to 30; also you can use CalculateUtil.getExponentPOTMin(Math.max(localWidth, localHeight)) for automatic step calculation.
      resultInsidePreMultiply - 0.01 or (1.0f / required thickness) for general usage.
      resultOutsidePreMultiply - 0.01 or (1.0f / max(extraWidth, extraHeight)) for general usage.
      Returns:
      generated sdf texture with GL11.GL_INTENSITY8 POT at [0.0, 1.0], texture return 0 if failed; int[] = {texture, validWidth, validHeight, glRealWidth, glRealHeight}
    • genSDF

      public static int[] genSDF(int source, int checkChannel, int sourceOffsetX, int sourceOffsetY, int localWidth, int localHeight, int extraWidth, int extraHeight, float outsideThreshold, byte step, float resultInsidePreMultiply, float resultOutsidePreMultiply, int resultTex, int resultOffsetX, int resultOffsetY, boolean bit16OutMode)
      Fast GPU SDF generation method.

      OpenGL 4.3 required, compute shader supported required.

      Parameters:
      source - must be RGBA8 texture.
      checkChannel - valid value: GL11.GL_RED, GL11.GL_GREEN, GL11.GL_BLUE, GL11.GL_ALPHA, GL11.GL_RGB; default is GL11.GL_ALPHA.
      sourceOffsetX - the source texture region left-bottom origin x-position.
      sourceOffsetY - the source texture region left-bottom origin y-position.
      extraWidth - border width for sdf texture, positive integer value required.
      extraHeight - border height for sdf texture, positive integer value required.
      outsideThreshold - when pixel check value less than or equal the value, it will be considered as outside.
      step - 8 or 9 for general usage, range from 0 to 30; also you can use CalculateUtil.getExponentPOTMin(Math.max(localWidth, localHeight)) for automatic step calculation.
      resultInsidePreMultiply - 0.01 or (1.0f / required thickness) for general usage.
      resultOutsidePreMultiply - 0.01 or (1.0f / max(extraWidth, extraHeight)) for general usage.
      resultTex - texture to store result, must be R8 texture and size must be greater than or equal to the final size.
      resultOffsetX - the result texture region left-bottom origin x-position.
      resultOffsetY - the result texture region left-bottom origin x-position.
      bit16OutMode - true for R16 texture, false for R8 texture.
      Returns:
      generated sdf texture with R8/R16 NPOT at [0.0, 1.0], texture return 0 if failed; int[] = {texture, width, height}
    • genSDF

      public static int[] genSDF(int source, int checkChannel, int localWidth, int localHeight, int extraWidth, int extraHeight, float outsideThreshold, byte step, float resultInsidePreMultiply, float resultOutsidePreMultiply, int resultTex, boolean bit16OutMode)
      Fast GPU SDF generation method.

      OpenGL 4.3 required, compute shader supported required.

      Parameters:
      source - must be RGBA8 texture.
      checkChannel - valid value: GL11.GL_RED, GL11.GL_GREEN, GL11.GL_BLUE, GL11.GL_ALPHA, GL11.GL_RGB; default is GL11.GL_ALPHA.
      extraWidth - border width for sdf texture, positive integer value required.
      extraHeight - border height for sdf texture, positive integer value required.
      outsideThreshold - when pixel check value less than or equal the value, it will be considered as outside.
      step - 8 or 9 for general usage, range from 0 to 30; also you can use CalculateUtil.getExponentPOTMin(Math.max(localWidth, localHeight)) for automatic step calculation.
      resultInsidePreMultiply - 0.01 or (1.0f / required thickness) for general usage.
      resultOutsidePreMultiply - 0.01 or (1.0f / max(extraWidth, extraHeight)) for general usage.
      resultTex - texture to store result, must be R8 texture and size must be greater than or equal to the final size.
      bit16OutMode - true for R16 texture, false for R8 texture.
      Returns:
      generated sdf texture with R8/R16 NPOT at [0.0, 1.0], texture return 0 if failed; int[] = {texture, width, height}
    • genSDF

      public static int[] genSDF(int source, int checkChannel, int localWidth, int localHeight, int extraWidth, int extraHeight, float outsideThreshold, byte step, float resultInsidePreMultiply, float resultOutsidePreMultiply, int resultTex)
      Fast GPU SDF generation method.

      OpenGL 4.3 required, compute shader supported required.

      Parameters:
      source - must be RGBA8 texture.
      checkChannel - valid value: GL11.GL_RED, GL11.GL_GREEN, GL11.GL_BLUE, GL11.GL_ALPHA, GL11.GL_RGB; default is GL11.GL_ALPHA.
      extraWidth - border width for sdf texture, positive integer value required.
      extraHeight - border height for sdf texture, positive integer value required.
      outsideThreshold - when pixel check value less than or equal the value, it will be considered as outside.
      step - 8 or 9 for general usage, range from 0 to 30; also you can use CalculateUtil.getExponentPOTMin(Math.max(localWidth, localHeight)) for automatic step calculation.
      resultInsidePreMultiply - 0.01 or (1.0f / required thickness) for general usage.
      resultOutsidePreMultiply - 0.01 or (1.0f / max(extraWidth, extraHeight)) for general usage.
      resultTex - texture to store result, must be R8 texture and size must be greater than or equal to the final size.
      Returns:
      generated sdf texture with R8 NPOT at [0.0, 1.0], texture return 0 if failed; int[] = {texture, width, height}
    • genSDF

      public static int[] genSDF(int source, int checkChannel, int sourceOffsetX, int sourceOffsetY, int localWidth, int localHeight, int extraWidth, int extraHeight, float outsideThreshold, byte step, float resultInsidePreMultiply, float resultOutsidePreMultiply, boolean bit16OutMode)
      Fast GPU SDF generation method.

      OpenGL 4.3 required, compute shader supported required.

      Parameters:
      source - must be RGBA8 texture.
      sourceOffsetX - the source texture region left-bottom origin x-position.
      sourceOffsetY - the source texture region left-bottom origin y-position.
      checkChannel - valid value: GL11.GL_RED, GL11.GL_GREEN, GL11.GL_BLUE, GL11.GL_ALPHA, GL11.GL_RGB; default is GL11.GL_ALPHA.
      extraWidth - border width for sdf texture, positive integer value required.
      extraHeight - border height for sdf texture, positive integer value required.
      outsideThreshold - when pixel check value less than or equal the value, it will be considered as outside.
      step - 8 or 9 for general usage, range from 0 to 30; also you can use CalculateUtil.getExponentPOTMin(Math.max(localWidth, localHeight)) for automatic step calculation.
      resultInsidePreMultiply - 0.01 or (1.0f / required thickness) for general usage.
      resultOutsidePreMultiply - 0.01 or (1.0f / max(extraWidth, extraHeight)) for general usage.
      bit16OutMode - true for R16 texture, false for R8 texture.
      Returns:
      generated sdf texture with R8/R16 NPOT at [0.0, 1.0], texture return 0 if failed; int[] = {texture, width, height}
    • genSDF

      public static int[] genSDF(int source, int checkChannel, int localWidth, int localHeight, int extraWidth, int extraHeight, float outsideThreshold, byte step, float resultInsidePreMultiply, float resultOutsidePreMultiply, boolean bit16OutMode)
      Fast GPU SDF generation method.

      OpenGL 4.3 required, compute shader supported required.

      Parameters:
      source - must be RGBA8 texture.
      checkChannel - valid value: GL11.GL_RED, GL11.GL_GREEN, GL11.GL_BLUE, GL11.GL_ALPHA, GL11.GL_RGB; default is GL11.GL_ALPHA.
      extraWidth - border width for sdf texture, positive integer value required.
      extraHeight - border height for sdf texture, positive integer value required.
      outsideThreshold - when pixel check value less than or equal the value, it will be considered as outside.
      step - 8 or 9 for general usage, range from 0 to 30; also you can use CalculateUtil.getExponentPOTMin(Math.max(localWidth, localHeight)) for automatic step calculation.
      resultInsidePreMultiply - 0.01 or (1.0f / required thickness) for general usage.
      resultOutsidePreMultiply - 0.01 or (1.0f / max(extraWidth, extraHeight)) for general usage.
      bit16OutMode - true for R16 texture, false for R8 texture.
      Returns:
      generated sdf texture with R8/R16 NPOT at [0.0, 1.0], texture return 0 if failed; int[] = {texture, width, height}
    • genSDF

      public static int[] genSDF(int source, int checkChannel, int localWidth, int localHeight, int extraWidth, int extraHeight, float outsideThreshold, byte step, float resultInsidePreMultiply, float resultOutsidePreMultiply)
      Fast GPU SDF generation method.

      OpenGL 4.3 required, compute shader supported required.

      Parameters:
      source - must be RGBA8 texture.
      checkChannel - valid value: GL11.GL_RED, GL11.GL_GREEN, GL11.GL_BLUE, GL11.GL_ALPHA, GL11.GL_RGB; default is GL11.GL_ALPHA.
      extraWidth - border width for sdf texture, positive integer value required.
      extraHeight - border height for sdf texture, positive integer value required.
      outsideThreshold - when pixel check value less than or equal the value, it will be considered as outside.
      step - 8 or 9 for general usage, range from 0 to 30; also you can use CalculateUtil.getExponentPOTMin(Math.max(localWidth, localHeight)) for automatic step calculation.
      resultInsidePreMultiply - 0.01 or (1.0f / required thickness) for general usage.
      resultOutsidePreMultiply - 0.01 or (1.0f / max(extraWidth, extraHeight)) for general usage.
      Returns:
      generated sdf texture with R8 NPOT at [0.0, 1.0], texture return 0 if failed; int[] = {texture, width, height}
    • applyRadialBlur

      public static void applyRadialBlur(int source, @NotNull org.lwjgl.util.vector.Vector2f center, short samples, float radius, float alphaStrength, boolean isAdditiveBlend)
      Classical radial blur effect.

      Draw blur effect form source to attachment of current framebuffer, source texture size should be consistent with attachment of current framebuffer size.

      GLWrapper.Shader.valid() required.

      Parameters:
      center - center of blur effect, mapping range from 0.0 to 1.0.
      samples - blur iteration, minimum value is 1 (No any effect), general value is 32, larger is better but slower.
      radius - the blur "strength", general value is 0.1, but higher value will need more samples to get better effect.
      alphaStrength - default value is 1.0.
    • applyRadialBlur

      public static void applyRadialBlur(int source, @NotNull org.lwjgl.util.vector.Vector2f center, short samples, float radius, float alphaStrength, int dstX, int dstY, int dstWidth, int dstHeight, boolean isAdditiveBlend)
      Classical radial blur effect.

      Draw blur effect form source to attachment of current framebuffer, source texture size should be consistent with attachment of current framebuffer size.

      GLWrapper.Shader.valid() required.

      Parameters:
      center - center of blur effect, mapping range from 0.0 to 1.0.
      samples - blur iteration, minimum value is 1 (No any effect), general value is 32, larger is better but slower.
      radius - the blur "strength", general value is 0.1, but higher value will need more samples to get better effect.
      alphaStrength - default value is 1.0.
    • applyImageGaussianBlur

      public static void applyImageGaussianBlur(int source, int sourceOffsetX, int sourceOffsetY, boolean useRed, byte step, int texWidth, int texHeight, int result, int resultOffsetX, int resultOffsetY, boolean bit16OutMode)
      Simple gaussian blur computing, only for RGBA and R texture.
      Parameters:
      sourceOffsetX - the source texture region left-bottom origin x-position.
      sourceOffsetY - the source texture region left-bottom origin y-position.
      useRed - true for Red texture, false for RGBA texture.
      step - copy texture when less than 1.
      resultOffsetX - the result texture region left-bottom origin x-position.
      resultOffsetY - the result texture region left-bottom origin x-position.
      bit16OutMode - true for 16bit per channel texture, false for 8bit per channel texture.
    • applyImageGaussianBlur

      public static void applyImageGaussianBlur(int source, boolean useRed, byte step, int texWidth, int texHeight, int result, boolean bit16OutMode)
      Simple gaussian blur computing, only for RGBA and R texture.
      Parameters:
      useRed - true for Red texture, false for RGBA texture.
      step - copy texture when less than 1.
      bit16OutMode - true for 16bit per channel texture, false for 8bit per channel texture.
    • applyImageGaussianBlur

      public static void applyImageGaussianBlur(int source, boolean useRed, byte step, int texWidth, int texHeight, boolean bit16OutMode)
      Simple gaussian blur computing, only for RGBA and R texture.
      Parameters:
      useRed - true for Red texture, false for RGBA texture.
      step - copy texture when less than 1.
      bit16OutMode - true for 16bit per channel texture, false for 8bit per channel texture.
    • applyImageBilateralFilter

      public static void applyImageBilateralFilter(int source, int sourceOffsetX, int sourceOffsetY, boolean useRed, byte radius, float sigmaSpace, float sigmaRange, int texWidth, int texHeight, int result, int resultOffsetX, int resultOffsetY, boolean bit16OutMode)
      Separated GPU bilateral filter.
      Parameters:
      sourceOffsetX - the source texture region left-bottom origin x-position.
      sourceOffsetY - the source texture region left-bottom origin y-position.
      useRed - true for Red texture, false for RGBA texture.
      result - Not recommended use same result texture as source texture in separated bilateral filter, otherwise will lose some detail and edge.
      resultOffsetX - the result texture region left-bottom origin x-position.
      resultOffsetY - the result texture region left-bottom origin x-position.
      bit16OutMode - true for 16bit per channel texture, false for 8bit per channel texture.
    • applyImageBilateralFilter

      public static void applyImageBilateralFilter(int source, boolean useRed, byte radius, float sigmaSpace, float sigmaRange, int texWidth, int texHeight, int result, boolean bit16OutMode)
      Separated GPU bilateral filter.

      Not recommended use this method, it uses same result texture as source texture that will lose some detail and edge.

      Parameters:
      useRed - true for Red texture, false for RGBA texture.
      bit16OutMode - true for 16bit per channel texture, false for 8bit per channel texture.
    • applyImageBilateralFilter

      public static void applyImageBilateralFilter(int source, boolean useRed, byte radius, float sigmaSpace, float sigmaRange, int texWidth, int texHeight, boolean bit16OutMode)
      Separated GPU bilateral filter.

      Not recommended use this method, it uses same result texture as source texture that will lose some detail and edge.

      Parameters:
      useRed - true for Red texture, false for RGBA texture.
      bit16OutMode - true for 16bit per channel texture, false for 8bit per channel texture.
    • imageDFT

      public static int imageDFT(int source, int sourceOffsetX, int sourceOffsetY, boolean useRed, int texWidth, int texHeight, int result, int resultOffsetX, int resultOffsetY, boolean f16OutMode)
      GPU DFT(Discrete Fourier Transform), slow but still faster more than CPU computing.
      Parameters:
      sourceOffsetX - the source texture region left-bottom origin x-position.
      sourceOffsetY - the source texture region left-bottom origin y-position.
      useRed - true for Red texture, false for RGBA texture.
      texWidth - spatial domain texture width, NOT frequency domain texture width.
      resultOffsetX - the result texture region left-bottom origin x-position.
      resultOffsetY - the result texture region left-bottom origin x-position.
      f16OutMode - true for f16 per channel texture, false for f32 per channel texture.
      Returns:
      generated centered f16/f32 complex spectrum texture;

      R with double size(left area R for real part of complex, right area R for imaginary part of complex) for useRed;

      RGBA with double size(left area R+iG/B+iA complex, right area R+iG/B+iA complex) for not useRed;

      returns 0 if failed.

    • imageDFT

      public static int imageDFT(int source, boolean useRed, int texWidth, int texHeight, int result, boolean f16OutMode)
      GPU DFT(Discrete Fourier Transform), slow but still faster more than CPU computing.
      Parameters:
      useRed - true for Red texture, false for RGBA texture.
      texWidth - spatial domain texture width, NOT frequency domain texture width.
      f16OutMode - true for f16 per channel texture, false for f32 per channel texture.
      Returns:
      generated centered f16/f32 complex spectrum texture;

      R with double size(left area R for real part of complex, right area R for imaginary part of complex) for useRed;

      RGBA with double size(left area R+iG/B+iA complex, right area R+iG/B+iA complex) for not useRed;

      returns 0 if failed.

    • imageDFT

      public static int imageDFT(int source, int sourceOffsetX, int sourceOffsetY, boolean useRed, int texWidth, int texHeight, boolean f16OutMode)
      GPU DFT(Discrete Fourier Transform), slow but still faster more than CPU computing.
      Parameters:
      sourceOffsetX - the source texture region left-bottom origin x-position.
      sourceOffsetY - the source texture region left-bottom origin y-position.
      useRed - true for Red texture, false for RGBA texture.
      texWidth - spatial domain texture width, NOT frequency domain texture width.
      f16OutMode - true for f16 per channel texture, false for f32 per channel texture.
      Returns:
      generated centered f16/f32 complex spectrum texture;

      R with double size(left area R for real part of complex, right area R for imaginary part of complex) for useRed;

      RGBA with double size(left area R+iG/B+iA complex, right area R+iG/B+iA complex) for not useRed;

      returns 0 if failed.

    • imageDFT

      public static int imageDFT(int source, boolean useRed, int texWidth, int texHeight, boolean f16OutMode)
      GPU DFT(Discrete Fourier Transform), slow but still faster more than CPU computing.
      Parameters:
      useRed - true for Red texture, false for RGBA texture.
      texWidth - spatial domain texture width, NOT frequency domain texture width.
      f16OutMode - true for f16 per channel texture, false for f32 per channel texture.
      Returns:
      generated centered f16/f32 complex spectrum texture;

      R with double size(left area R for real part of complex, right area R for imaginary part of complex) for useRed;

      RGBA with double size(left area R+iG/B+iA complex, right area R+iG/B+iA complex) for not useRed;

      returns 0 if failed.

    • imageIDFT

      public static int imageIDFT(int source, int sourceOffsetX, int sourceOffsetY, boolean useRed, int texWidth, int texHeight, int result, int resultOffsetX, int resultOffsetY, boolean f16InMode, boolean f16OutMode)
      GPU IDFT(Inverse Discrete Fourier Transform), slow but still faster more than CPU computing.
      Parameters:
      sourceOffsetX - the source texture region left-bottom origin x-position.
      sourceOffsetY - the source texture region left-bottom origin y-position.
      useRed - true for double size Red complex, false for double size RGBA complex.
      texWidth - spatial domain texture width, NOT frequency domain texture width.
      resultOffsetX - the result texture region left-bottom origin x-position.
      resultOffsetY - the result texture region left-bottom origin x-position.
      f16InMode - true for f16 per channel texture, false for f32 per channel texture.
      f16OutMode - true for f16 per channel texture, false for 8bit per channel texture.
      Returns:
      generated 8bit/16bit per channel texture from complex spectrum, R for double size R complex, RGBA for double size RGBA complex, if failed return 0.
    • imageIDFT

      public static int imageIDFT(int source, boolean useRed, int texWidth, int texHeight, int result, boolean f16InMode, boolean f16OutMode)
      GPU IDFT(Inverse Discrete Fourier Transform), slow but still faster more than CPU computing.
      Parameters:
      useRed - true for double size Red complex, false for double size RGBA complex.
      texWidth - spatial domain texture width, NOT frequency domain texture width.
      f16InMode - true for f16 per channel texture, false for f32 per channel texture.
      f16OutMode - true for f16 per channel texture, false for 8bit per channel texture.
      Returns:
      generated 8bit/16bit per channel texture from complex spectrum, R for double size R complex, RGBA for double size RGBA complex, if failed return 0.
    • imageIDFT

      public static int imageIDFT(int source, int sourceOffsetX, int sourceOffsetY, boolean useRed, int texWidth, int texHeight, boolean f16InMode, boolean f16OutMode)
      GPU IDFT(Inverse Discrete Fourier Transform), slow but still faster more than CPU computing.
      Parameters:
      sourceOffsetX - the source texture region left-bottom origin x-position.
      sourceOffsetY - the source texture region left-bottom origin y-position.
      useRed - true for double size Red complex, false for double size RGBA complex.
      texWidth - spatial domain texture width, NOT frequency domain texture width.
      f16InMode - true for f16 per channel texture, false for f32 per channel texture.
      f16OutMode - true for f16 per channel texture, false for 8bit per channel texture.
      Returns:
      generated 8bit/16bit per channel texture from complex spectrum, R for double size R complex, RGBA for double size RGBA complex, if failed return 0.
    • imageIDFT

      public static int imageIDFT(int source, boolean useRed, int texWidth, int texHeight, boolean f16InMode, boolean f16OutMode)
      GPU IDFT(Inverse Discrete Fourier Transform), slow but still faster more than CPU computing.
      Parameters:
      useRed - true for double size Red complex, false for double size RGBA complex.
      texWidth - spatial domain texture width, NOT frequency domain texture width.
      f16InMode - true for f16 per channel texture, false for f32 per channel texture.
      f16OutMode - true for f16 per channel texture, false for 8bit per channel texture.
      Returns:
      generated 8bit/16bit per channel texture from complex spectrum, R for double size R complex, RGBA for double size RGBA complex, if failed return 0.
    • genNormalMapFromRGB

      public static int genNormalMapFromRGB(int source, int sourceOffsetX, int sourceOffsetY, int srcLocalWidth, int srcLocalHeight, ShaderUtil.NormalMapGenParam param, int resultTex, int resultOffsetX, int resultOffsetY)
      GPU normal map generation from RGB texture for sprites.

      OpenGL 4.3 required, compute shader supported required.

      Parameters:
      source - must be RGBA8 2D-texture.
      sourceOffsetX - the source texture region left-bottom origin x-position.
      sourceOffsetY - the source texture region left-bottom origin y-position.
      resultOffsetX - the result texture region left-bottom origin x-position.
      resultOffsetY - the result texture region left-bottom origin x-position.
      Returns:
      returns NPOT-texture.
    • genNormalMapFromRGB

      public static int genNormalMapFromRGB(int source, int srcLocalWidth, int srcLocalHeight, ShaderUtil.NormalMapGenParam param, int resultTex)
      GPU normal map generation from RGB texture for sprites.

      OpenGL 4.3 required, compute shader supported required.

      Parameters:
      source - must be RGBA8 2D-texture.
      Returns:
      returns NPOT-texture.
    • genNormalMapFromRGB

      public static int genNormalMapFromRGB(int source, int sourceOffsetX, int sourceOffsetY, int srcLocalWidth, int srcLocalHeight, ShaderUtil.NormalMapGenParam param)
      GPU normal map generation from RGB texture for sprites.

      OpenGL 4.3 required, compute shader supported required.

      Parameters:
      source - must be RGBA8 2D-texture.
      sourceOffsetX - the source texture region left-bottom origin x-position.
      sourceOffsetY - the source texture region left-bottom origin y-position.
      Returns:
      returns NPOT-texture.
    • genNormalMapFromRGB

      public static int genNormalMapFromRGB(int source, int srcLocalWidth, int srcLocalHeight, ShaderUtil.NormalMapGenParam param)
      GPU normal map generation from RGB texture for sprites.

      OpenGL 4.3 required, compute shader supported required.

      Parameters:
      source - must be RGBA8 2D-texture.
      Returns:
      returns NPOT-texture.