eg:
Code: Select all
#version 100
precision highp float;
precision highp int;
void FFP_Add(in vec3 vIn0, in vec3 vIn1, out vec3 vOut)
{
vOut = vIn0 + vIn1;
}
void FFP_Assign(in vec4 vIn, out vec4 vOut)
{
vOut = vIn;
}
void FFP_Lerp(in vec4 vIn0, in vec4 vIn1, in float T, out vec4 vOut)
{
vOut = mix(vIn0, vIn1, T);
}
void FFP_Modulate(in vec4 vIn0, in vec4 vIn1, out vec4 vOut)
{
vOut = vIn0 * vIn1;
}
void FFP_SampleTexture(in sampler2D s, in vec2 f, out vec4 t)
{
t = texture2D(s, f);
}
uniform sampler2D gTextureSampler0;
uniform vec4 gFogColor0;
varying vec4 oColor_0;
varying vec4 oColor_1;
varying vec2 oTexcoord2_0;
varying float oTexcoord1_1;
void main() {
vec4 outputColor;
vec4 texel_0;
vec4 source1;
vec4 source2;
FFP_Assign(oColor_0, outputColor);
FFP_SampleTexture(gTextureSampler0, oTexcoord2_0, texel_0);
FFP_Assign(texel_0, source1);
FFP_Assign(oColor_0, source2);
FFP_Modulate(source1, source2, outputColor);
FFP_Add(outputColor.xyz, oColor_1.xyz, outputCol
Code: Select all
namespace OgreBites
{
/** This class demonstrates basic usage of the RTShader system.
It sub class the material manager listener class and when a target scheme callback
is invoked with the shader generator scheme it tries to create an equivalent shader
based technique based on the default technique of the given material.
*/
class ShaderGeneratorTechniqueResolverListener: public Ogre::MaterialManager::Listener
{
public:
ShaderGeneratorTechniqueResolverListener(Ogre::RTShader::ShaderGenerator* pShaderGenerator)
{
mShaderGenerator = pShaderGenerator;
}
/** This is the hook point where shader based technique will be created.
It will be called whenever the material manager won't find appropriate technique
that satisfy the target scheme name. If the scheme name is out target RT Shader System
scheme name we will try to create shader generated technique for it.
*/
virtual Ogre::Technique* handleSchemeNotFound(unsigned short schemeIndex, const Ogre::String& schemeName, Ogre::Material* originalMaterial, unsigned short lodIndex, const Ogre::Renderable* rend)
{
Ogre::Technique* generatedTech = NULL;
// Case this is the default shader generator scheme.
if (schemeName == Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME)
{
bool techniqueCreated;
// Create shader generated technique for this material.
techniqueCreated = mShaderGenerator->createShaderBasedTechnique ( originalMaterial->getName (), Ogre::MaterialManager::DEFAULT_SCHEME_NAME, schemeName );
// Case technique registration succeeded.
if (techniqueCreated)
{
// Force creating the shaders for the generated technique.
mShaderGenerator->validateMaterial ( schemeName, originalMaterial->getName () );
// Grab the generated technique.
Ogre::Material::TechniqueIterator itTech = originalMaterial->getTechniqueIterator ();
while (itTech.hasMoreElements ())
{
Ogre::Technique* curTech = itTech.getNext ();
if (curTech->getSchemeName () == schemeName)
{
generatedTech = curTech;
LogTool::logString ( "\n\n" );
LogTool::logString ( "ShaderGenerator..." );
LogTool::logString ( "scheme name:", schemeName );
LogTool::logString ( "material name:", originalMaterial->getName () );
LogTool::logString ( "vertex shader\n", generatedTech->getPass ( 0 )->getVertexProgram ()->getSource () );
LogTool::logString ( "vertex-fragment Dividing line----------------------------" );
LogTool::logString ( "fragment shader\n", generatedTech->getPass ( 0 )->getFragmentProgram ()->getSource () );
LogTool::logString ( "\n\n" );
break;
}
}
}
}
return generatedTech;
}
protected:
Ogre::RTShader::ShaderGenerator* mShaderGenerator; // The shader generator instance.
};
}