com.threed.jpct
Class GLSLShadowInjector

java.lang.Object
  extended by com.threed.jpct.GLSLShadowInjector

public class GLSLShadowInjector
extends java.lang.Object

This class offers static methods to inject shadow mapping code into exiting shaders. It's tailored to work with the default shaders that come with jPCT-AE, but you can use it on your own shaders as well, if you follow some basic rules. The easiest way to do that, is to base your shaders on the default shaders and keep the names of the uniforms and variables.
While you can do shadow mapping on your own in jPCT-AE, it's advised to rely on the ShadowHelper class in the util package if possible.
If you have an object that should receive shadows and that uses a custom shader based on the default shaders, you have two options:

  1. Do nothing. jPCT-AE will try to inject the shadow mapping code into your shader at runtime by doing some magic.
  2. Trigger the injection by yourself. You can do this by calling the injectShadowCode() method.


Field Summary
static int NORMAL_SHADOWS
          Shadow mode for normal, blocky shadows with no filtering
static int NORMAL_SHADOWS_WITH_EDGE_SMOOTHING
          Shadow mode for normal, blocky shadows which fade out at the edges of the shadow map.
static int PCF_FILTERED_SHADOWS
          Shadow mode for filtered shadows, which are less blocky but slower.
static int PCF_FILTERED_SHADOWS_WITH_EDGE_SMOOTHING
          Shadow mode for filtered shadows + edge smoothing.
 
Constructor Summary
GLSLShadowInjector()
           
 
Method Summary
static int getShadowMode()
          Returns the engine's current shadow mode.
static GLSLShader injectShadowCode(GLSLShader sourceShader)
          Tries to inject shadow mapping code into a GLSLShader.
static void setShadowMode(int mode)
          Sets the shadow mode.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NORMAL_SHADOWS

public static final int NORMAL_SHADOWS
Shadow mode for normal, blocky shadows with no filtering

See Also:
Constant Field Values

NORMAL_SHADOWS_WITH_EDGE_SMOOTHING

public static final int NORMAL_SHADOWS_WITH_EDGE_SMOOTHING
Shadow mode for normal, blocky shadows which fade out at the edges of the shadow map.

See Also:
Constant Field Values

PCF_FILTERED_SHADOWS

public static final int PCF_FILTERED_SHADOWS
Shadow mode for filtered shadows, which are less blocky but slower.

See Also:
Constant Field Values

PCF_FILTERED_SHADOWS_WITH_EDGE_SMOOTHING

public static final int PCF_FILTERED_SHADOWS_WITH_EDGE_SMOOTHING
Shadow mode for filtered shadows + edge smoothing.

See Also:
Constant Field Values
Constructor Detail

GLSLShadowInjector

public GLSLShadowInjector()
Method Detail

setShadowMode

public static void setShadowMode(int mode)
Sets the shadow mode. Because jPCT-AE modifies shaders at runtime, this setting is global for the whole engine. You'll find a method of the same name in the ShadowHelper class. If you are using the ShadowHelper anyway, use that one and ignore this here.

Parameters:
mode - the mode.

getShadowMode

public static int getShadowMode()
Returns the engine's current shadow mode.

Returns:
the mode.

injectShadowCode

public static GLSLShader injectShadowCode(GLSLShader sourceShader)
Tries to inject shadow mapping code into a GLSLShader. If this succeeds, a new GLSLShader instance will be returned. If it fails, a messsage will be logged and the old instance will be returned.

Parameters:
sourceShader - the source shader
Returns:
either a new instance or the old one in case of a problem