| [ < ] | [ Up ] | [ > ] | [Top] | [Contents] | [Index] | [ ? ] |
vertex_program myGLSLVertexProgram glsl
{
source myGLSLVertexProgram.txt
}
|
GLSL supports the use of modular shaders. This means you can write GLSL external functions that can be used in multiple shaders.
vertex_program myExteranalGLSLFunction1 glsl
{
source myExternalGLSLfunction1.txt
}
vertex_program myExteranalGLSLFunction2 glsl
{
source myExternalGLSLfunction2.txt
}
vertex_program myGLSLVertexProgram1 glsl
{
source myGLSLfunction.txt
attach myExteranalGLSLFunction1 myExteranalGLSLFunction2
}
vertex_program myGLSLVertexProgram2 glsl
{
source myGLSLfunction.txt
attach myExteranalGLSLFunction1
}
|
External GLSL functions are attached to the program that needs them by using 'attach' and including the names of all external programs required on the same line seperated by spaces. This can be done for both vertex and fragment programs.
excerpt from GLSL example.frag source:
varying vec2 UV;
uniform sampler2D diffuseMap;
void main(void)
{
gl_FragColor = texture2D(diffuseMap, UV);
}
|
In material script:
fragment_program myFragmentShader glsl
{
source example.frag
}
material exampleGLSLTexturing
{
technique
{
pass
{
fragment_program_ref myFragmentShader
{
param_named diffuseMap int 0
}
texture_unit
{
texture myTexture.jpg 2d
}
}
}
}
|
An index value of 0 refers to the first texture unit in the pass, an index value of 1 refers to the second unit in the pass and so on.
Here are some examples of passing matrices to GLSL mat2, mat3, mat4 uniforms:
material exampleGLSLmatixUniforms
{
technique matrix_passing
{
pass examples
{
vertex_program_ref myVertexShader
{
// mat4 uniform
param_named OcclusionMatrix matrix4x4 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0
// or
param_named ViewMatrix float16 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0
// mat3
param_named TextRotMatrix float9 1 0 0 0 1 0 0 0 1
}
fragment_program_ref myFragmentShader
{
// mat2 uniform
param_named skewMatrix float4 0.5 0 -0.5 1.0
}
}
}
}
|
In addition to the built in attributes described in section 7.3 of the GLSL manual, Ogre supports a number of automatically bound custom vertex attributes. There are some drivers that do not behave correctly when mixing built-in vertex attributes like gl_Normal and custom vertex attributes, so for maximum compatibility you may well wish to use all custom attributes in shaders where you need at least one (e.g. for skeletal animation).
// in your GLSL #ifdef CLEVERTECHNIQUE // some clever stuff here #else // normal technique #endif #if NUM_THINGS==2 // Some specific code #else // something else #endif // in your program definition preprocessor_defines CLEVERTECHNIQUE,NUMTHINGS=2 |
| [ < ] | [ Up ] | [ > ] | [Top] | [Contents] | [Index] | [ ? ] |