Class PostProcessShader

java.lang.Object
org.xjge.graphics.PostProcessShader

public abstract class PostProcessShader
extends java.lang.Object
These objects are used to apply post-processing effects to the framebuffer texture of a viewport. They achieve this by changing which shader program the framebuffer object will use during its rendering cycle.

NOTE: When defining shaders for post processing effects take care to make sure that the vertex layout is organized correctly (this consists of a vec3 at location 0, and a vec2 at location 2). It's also worth mentioning that framebuffers write to texture objects so any shader program that wishes to apply post-processing effects should contain (at minimum) the following code;

 //Vertex Shader
 #version 330 core
 
 layout (location = 0) in vec3 aPosition;
 layout (location = 2) in vec2 aTexCoords;
 
 uniform mat4 uProjection;
 
 out vec2 ioTexCoords;
 
 void main() {
     ioTexCoords = aTexCoords;
     gl_Position = uProjection * vec4(aPosition, 1);
 }
 
 
 //Fragment Shader
 #version 330 core
 
 in vec2 ioTexCoords;
 
 uniform sampler2D uTexture;
 
 float sharpen(float pixArray) {
     float normal  = (fract(pixArray) - 0.5) * 2.0;
     float normal2 = normal * normal;
 
     return floor(pixArray) + normal * pow(normal2, 2.0) / 2.0 + 0.5;
 }
 
 void main() {
     vec2 vRes = textureSize(uTexture, 0);
 
     vec3 sceneColor = texture(uTexture, vec2(
         sharpen(ioTexCoords.x * vRes.x) / vRes.x,
           sharpen(ioTexCoords.y * vRes.y) / vRes.y
     )).rgb;
 
     sceneColor.r = 0;
     
     gl_FragColor = vec4(sceneColor, 1);
 }
 
Since:
2.1.9
  • Field Summary

    Fields
    Modifier and Type Field Description
    GLProgram glProgram  
  • Constructor Summary

    Constructors
    Constructor Description
    PostProcessShader​(GLProgram glProgram)
    Creates a new object that can be used to reroute the render cycle of a viewport object and apply post-processing effects to its framebuffer texture.
  • Method Summary

    Modifier and Type Method Description
    abstract void render​(int viewTexHandle, int bloomTexHandle, org.joml.Matrix4f projMatrix, Graphics g)
    Acts like any other render method does within the engine with the exception that it runs

    Methods inherited from class java.lang.Object

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

    • glProgram

      public final GLProgram glProgram
  • Constructor Details

    • PostProcessShader

      public PostProcessShader​(GLProgram glProgram)
      Creates a new object that can be used to reroute the render cycle of a viewport object and apply post-processing effects to its framebuffer texture.
      Parameters:
      glProgram - the shader program that will be used to render the framebuffer texture
  • Method Details

    • render

      public abstract void render​(int viewTexHandle, int bloomTexHandle, org.joml.Matrix4f projMatrix, Graphics g)
      Acts like any other render method does within the engine with the exception that it runs
      Parameters:
      viewTexHandle - the handle of the framebuffer texture containing color information
      bloomTexHandle - the handle of another framebuffer texture generated by the engine when bloom effects are enabled
      projMatrix - A temporary projection matrix used by the engine. You'll want to pass this to your custom post-process shader during the vertex stage.
      g - the graphics object used by the viewport