|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.threed.jpct.GLSLShader
public class GLSLShader
A class for GLSL-based shaders. This isn't a full blown shader framework and
it isn't meant to be one. This is useful only when using jPCT-AE's OpenGL ES
2.0 pipeline. If you aren't using this class to write your own shaders,
jPCT-AE will fall back to its default shaders. Note: If you want to assign
additional vertex attributes to your shader, you can't do this here but in
the Mesh class.
While this class is similar to the one in desktop jPCT, it works a little
different. Especially, it's not an implementation of IRenderHook, so if you
want to set uniforms per Object3D on a shared shader, you have to write an
additional IRenderHook to do so. However, it's ensured that IRenderHook's
beforeRendering()-method will be called before the shader will be
initialized, so you can safely set your uniforms there.
jPCT-AE will look out for some uniforms/attributes in the shader to inject
it's data into.
uniform mat4 modelViewMatrix; - The model view matrix, i.e. the matrix that
makes the transformation from object into camera space
uniform mat4 modelViewProjectionMatrix; - The model view projection matrix,
i.e. the model view matrix * projection matrix
uniform mat4 textureMatrix; - The texture matrix
uniform mat4 projectionMatrix - The projection matrix
uniform vec4 additionalColor; - An object's additional color (stored in .rgb
of the uniform).
uniform vec4 ambientColor; - The world's ambient color (stored in .rgb of the
uniform).
uniform float alpha; - The alpha value of the object.
uniform float shininess; - The shininess if specular lighting is being used.
uniform bool useColors; - true, if the object contains additional vertex
colors.
uniform float fogStart; - The depth coordinate, at which the fog starts. -1.0
if there is no fog.
uniform float fogEnd; - The depth coordinate of maximum fog.
uniform vec3 fogColor; - The fog color.
uniform int lightCount; - The number of lights that light this object.
uniform vec3 lightPositions[8]; - The light positions in camera space.
uniform vec3 diffuseColors[8]; - The diffuse color of each light source.
uniform vec3 specularColors[8]; - The specular color of each light source.
uniform float attenuation[8]; - The attenuation of each light source.
uniform sampler2D textureUnit0; - The texture sampler for the first texture
layer.
uniform sampler2D textureUnit1; - The texture sampler for the second texture
layer.
uniform sampler2D textureUnit2; - The texture sampler for the third texture
layer.
uniform sampler2D textureUnit3; - The texture sampler for the forth texture
layer.
uniform int textureCount; - The number of texture layers.
uniform int blendingMode[4]; - The blending modes between these layers
(0==MODULATE, 1==ADD, 2==REPLACE, 3==BLEND).
attribute vec4 position; - The vertex positions in object space.
attribute vec3 normal; - The vertex normals in object space.
attribute vec4 color; - The additional vertex colors (if any).
attribute vec4 tangent; - The tangent vectors. The presence of this attribute
in a shader's source code will trigger the tangent vector calculation when
calling build().
attribute vec2 texture0; - The texture coordinates for the first stage.
attribute vec2 texture1; - The texture coordinates for the second stage.
attribute vec2 texture2; - The texture coordinates for the third stage.
attribute vec2 texture3; - The texture coordinates for the forth stage.
Constructor Summary | |
---|---|
GLSLShader(java.lang.String vertexShaderSource,
java.lang.String fragmentShaderSource)
Creates a new instance. |
Method Summary | |
---|---|
static void |
addReplacement(java.lang.String key,
java.lang.String shaderSrc)
With this, you can override the default shaders by making jPCT-AE use your own shader code instead. |
void |
dispose()
Disposes the shader. |
void |
finalize()
|
int |
getProgram()
Returns the id of the shader program. |
static ShaderLocator |
getShaderLocator()
Returns the shader locator or a new instance of jar-locator if none other has been set. |
boolean |
isDepthShader()
Returns if this shader is a depth shader. |
void |
setDepthShader(boolean depthShader)
Marks this shader as a depth shader. |
void |
setFloatArrayUniform(java.lang.String name,
float[] val)
Sets a new float[] uniform. |
static void |
setShaderLocator(ShaderLocator locator)
Sets a new shader locator. |
void |
setStaticFloatArrayUniform(java.lang.String name,
float[] val)
Sets a new float[] uniform. |
void |
setStaticUniform(java.lang.String name,
float val)
Sets a new float uniform. |
void |
setStaticUniform(java.lang.String name,
float[] val)
Sets a new float|vecX uniform. |
void |
setStaticUniform(java.lang.String name,
int val)
Sets a new integer uniform. |
void |
setStaticUniform(java.lang.String name,
Matrix m)
Sets a new Matrix uniform. |
void |
setStaticUniform(java.lang.String name,
Matrix[] ms)
Sets a new array of Matrix uniform. |
void |
setStaticUniform(java.lang.String name,
SimpleVector val)
Sets a new SimpleVector uniform. |
void |
setStaticUniform(java.lang.String name,
SimpleVector[] vals)
Sets a new array of SimpleVector uniform. |
void |
setUniform(java.lang.String name,
float val)
Sets a new float uniform. |
void |
setUniform(java.lang.String name,
float[] val)
Sets a new float|vecX uniform. |
void |
setUniform(java.lang.String name,
int val)
Sets a new integer uniform. |
void |
setUniform(java.lang.String name,
Matrix m)
Sets a new Matrix uniform. |
void |
setUniform(java.lang.String name,
Matrix[] vals)
Sets a new array of Matrix uniform. |
void |
setUniform(java.lang.String name,
SimpleVector val)
Sets a new SimpleVector uniform. |
void |
setUniform(java.lang.String name,
SimpleVector[] vals)
Sets a new array of SimpleVectors uniform. |
void |
setUniformCache(boolean cacheEnabled)
Sets if uniform values can be cached or not. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public GLSLShader(java.lang.String vertexShaderSource, java.lang.String fragmentShaderSource)
vertexShaderSource
- the source of the vertex shaderfragmentShaderSource
- the source of the fragment shaderMethod Detail |
---|
public static void addReplacement(java.lang.String key, java.lang.String shaderSrc)
key
- shaderSrc
- public static void setShaderLocator(ShaderLocator locator)
locator
- the new locatorpublic static ShaderLocator getShaderLocator()
public void setUniformCache(boolean cacheEnabled)
cacheEnabled
- can we cache the uniforms?public int getProgram()
public void setStaticUniform(java.lang.String name, int val)
name
- the name of the uniformval
- the valuepublic void setStaticUniform(java.lang.String name, float val)
name
- the name of the uniformval
- the valuepublic void setStaticUniform(java.lang.String name, float[] val)
name
- the name of the uniformval
- the value. Supports array-lengths from 1 to 4.public void setStaticFloatArrayUniform(java.lang.String name, float[] val)
name
- the name of the uniformval
- the value.public void setStaticUniform(java.lang.String name, SimpleVector[] vals)
name
- the name of the uniformvals
- the valuespublic void setStaticUniform(java.lang.String name, SimpleVector val)
name
- the name of the uniformval
- the valuepublic void setStaticUniform(java.lang.String name, Matrix m)
name
- the name of the uniformm
- the matrix. It won't be transposed.public void setStaticUniform(java.lang.String name, Matrix[] ms)
name
- the name of the uniformvals
- the valuespublic void setUniform(java.lang.String name, Matrix[] vals)
name
- the name of the uniformvals
- the valuespublic void setUniform(java.lang.String name, int val)
name
- the name of the uniformval
- the valuepublic void setUniform(java.lang.String name, float val)
name
- the name of the uniformval
- the valuepublic void setUniform(java.lang.String name, SimpleVector val)
name
- the name of the uniformval
- the valuepublic void setUniform(java.lang.String name, SimpleVector[] vals)
name
- the name of the uniformvals
- the valuespublic void setUniform(java.lang.String name, float[] val)
name
- the name of the uniformval
- the value. Supports array-lengths from 1 to 4.public void setFloatArrayUniform(java.lang.String name, float[] val)
name
- the name of the uniformval
- the value.public void setUniform(java.lang.String name, Matrix m)
name
- the name of the uniformm
- the matrix. It won't be transposed.public boolean isDepthShader()
public void setDepthShader(boolean depthShader)
depthShader
- true, if it's a depth shader. False otherwise.public void dispose()
public void finalize()
finalize
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |