This type of extensions create textures at render time. This class is defined in mx_textureextension.h
class CtextureExtension : public CbaseExtension { public: virtual bool getRGB( Crgb& rgb, real u, real v, const IntersectionInfo* intersectionInfo = 0 ) = 0; };
The actual work of this extension is done in getRGB. This is the speed critical routine. Make every effort to optimize this function. Do not allocate memory in it. Avoid any OS and/or SDK function calls in this critical routine. Most of the memory can be pre-allocated in initializeForRendering. If you want to access the global scene pointer, store it in initializeForRendering and use it later. This can save a huge amount of time.
getRGB
virtual bool getRGB( Crgb& rgb, real u, real v, const IntersectionInfo* intersectionInfo = 0 ) = 0;
Calculate and return the color at the given texture coordinates u and v.
Arguments
Crgb& rgb
: output, calculated color, float values.
real u, v
: input, texture coordinates at which the color must be calculated.
const IntersectionInfo* intersectionInfo
: input, pointer to a structure with intersection information. Always check != NULL. Class IntersectionInfo is defined as follows:
class IntersectionInfo { public: Cvector barycentric; Cpoint* intersectionGlobals; Cpoint* normalGlobals; };
Where:
Cvector barycentric
are the barycentric coordinates of the triangle (when dealing with actual meshes) or the natural parametric coordinates (if dealing with a procedural geometry object )
Cpoint* intersectionGlobals
: point of intersection in global coordinates.
Cpoint* normalGlobals
: normal at the point of intersection in global coordinates.
Returns
true
if successful, false
otherwise;
#include <math.h> #include "extensionmanager.h" #include "textureextension.h" class CproceduralChecker : public CtextureExtension { DECLARE_EXTENSION_METHODS( "Checker", CproceduralChecker, 1 ) unsigned int uRepeat, vRepeat; Cmaxwell* pMaxwellLocal; public: CproceduralChecker() { getExtensionData()->createUInt( "repeatU", 10, 1, 10000 ); getExtensionData()->createUInt( "repeatV", 10, 1, 10000 ); } ~CproceduralChecker() { } bool initializeForRendering( Cmaxwell* pMaxwell ) { pMaxwellLocal = pMaxwell; getExtensionData()->getUInt( "repeatU", uRepeat ); getExtensionData()->getUInt( "repeatV", vRepeat ); return true; } bool getRGB( Crgb& rgb, real u, real v, const IntersectionInfo* intersectionInfo ) { int pu = ( ( int )( uRepeat * fabs( u ) ) ) % 2; int pv = ( ( int )( vRepeat * fabs( v ) ) ) % 2; rgb.r *= pu ^ pv; rgb.g *= pu ^ pv; rgb.b *= pu ^ pv; return true; } };