Normal OpenGL Shader:

uniform mat4 MatrixTransform;

attribute vec4 pos;
attribute vec4 col;
attribute vec2 tex;

varying vec4 diffuseColor;
varying vec2 diffuseTexCoord;
void main( )
{
gl_Position = MatrixTransform * pos;
diffuseTexCoord = tex;
diffuseColor = col;
}

##!fragment!##

uniform sampler2D Texture;

varying vec4 diffuseColor;
varying vec2 diffuseTexCoord;
void main( )
{
gl_FragColor = texture2D(Texture, diffuseTexCoord) * diffuseColor;
}

Introducing Techniques:

  • The shader will be split in 5 parts:
    • Vertex Globals section (uniforms, global attributes, global varyings)
      • This section is added to all sources that are compiled (which will be optimized by OpenGL then, removing unneeded stuff, etc.)
    • Fragment Globals section (uniforms, global varyings)
      • This section is added to all sources that are compiled (which will be optimized by OpenGL then, removing unneeded stuff, etc.)
    • The vertexshader section
      • This section is again split by each vertex shader included in the shader
    • The fragmentshader section
      • This section is again split by each vertex shader included in the shader
    • The Techniques section
      • This section is split by each technique which is a pair of vertex and fragment shader

Example File:

vertexglobal
{
uniform mat4 MatrixTransform;

attribute vec4 pos;
attribute vec2 tex;

varying vec2 diffuseTexCoord;
}

vertexshaders
{
shader “Texture”
{
void main( )
{
gl_Position = MatrixTransform * pos;
diffuseTexCoord = tex;
}
}

shader “Texture Color”
{
attribute vec4 col;
varying vec4 diffuseColor;

void main( )
{
gl_Position = MatrixTransform * pos;
diffuseTexCoord = tex;
diffuseColor = col;
}
}
}

fragmentglobal
{
uniform sampler2D Texture;
varying vec2 diffuseTexCoord;
}

fragmentshaders
{
shader “Texture”
{
void main( )
{
gl_FragColor = texture2D(Texture, diffuseTexCoord);
}
}

shader “Texture Color”
{
varying vec4 diffuseColor;

void main( )
{
gl_FragColor = texture2D(Texture, diffuseTexCoord) * diffuseColor;
}
}
}

techniques
{
technique “Texture”
{
vertex “Texture”
fragment “Texture”
}

technique “Texture Color”
{
vertex “Texture Color”
fragment “Texture Color”
}
}

Last edited Aug 14, 2012 at 8:13 PM by AstrorEnales, version 1

Comments

No comments yet.