5#ifndef NIRT_I_Q3_LEVEL_SHADER_HPP_INCLUDED
6#define NIRT_I_Q3_LEVEL_SHADER_HPP_INCLUDED
8#include <nirtcpp/core/engine/irrArray.hpp>
9#include <nirtcpp/core/engine/fast_atof.hpp>
10#include <nirtcpp/core/engine/IFileSystem.hpp>
11#include <nirtcpp/core/engine/IVideoDriver.hpp>
12#include <nirtcpp/core/engine/coreutil.hpp>
15namespace nirt::scene::quake3
23 E_Q3_MESH_GEOMETRY = 0,
39 defaultModulate ( video::EMFN_MODULATE_4X ),
41 patchTesselation ( 8 ),
43 startTime ( 0 ), endTime ( 0 ),
44 mergeShaderBuffer ( 1 ),
45 cleanUnResolvedMeshes ( 1 ),
56 std::copy_n(
"scripts\x0", 8, scriptDir);
67 s32 mergeShaderBuffer;
68 s32 cleanUnResolvedMeshes;
84 const char * in =
string.data() + pos;
86 for (
u16 i = 0; i != listSize; ++i )
88 if (
string.size() < pos)
90 u32 len = (
u32) strlen ( list[i] );
91 if (
string.size() < pos+len)
93 if ( in [len] != 0 && in [len] !=
' ' )
95 if ( strncmp ( in, list[i], len ) )
106 const char * in =
string.data() + pos;
118 v.
X = getAsFloat (
string, pos );
119 v.Z = getAsFloat (
string, pos );
120 v.Y = getAsFloat (
string, pos );
129inline void getAsStringList ( tStringList &list,
s32 max,
const core::stringc &
string,
u32 &startPos )
137 endPos =
string.findNext (
' ', startPos );
141 endPos =
string.size();
144 list.push_back (
string.subString ( startPos, endPos - startPos ) );
145 startPos = endPos + 1;
147 if ( list.size() >= (
u32) max )
176 if ( cull.size() == 0 )
180 static const c8 * funclist[] = {
"none",
"disable",
"twosided" };
183 switch ( isEqual ( cull, pos, funclist, 3 ) )
200 if (
string.size() == 0 )
203 static const c8 * funclist[] = {
"lequal",
"equal" };
206 switch ( isEqual (
string, pos, funclist, 2 ) )
229inline static void getBlendFunc (
const core::stringc &
string, SBlendFunc &blendfunc )
231 if (
string.size() == 0 )
235 static const c8 * funclist[] =
240 "gl_one_minus_dst_color",
242 "gl_one_minus_src_color",
244 "gl_one_minus_src_alpha",
246 "gl_one_minus_dst_alpha",
258 s32 srcFact = isEqual (
string, pos, funclist, 16 );
264 s32 dstFact = isEqual (
string, pos, funclist, 16 );
275 blendfunc.isTransparent = 1;
286 blendfunc.isTransparent = 0;
293 blendfunc.isTransparent = 1;
304 blendfunc.param0 = 1.f/255.f;
305 blendfunc.isTransparent = 1;
313 blendfunc.isTransparent = 1;
320 blendfunc.isTransparent = 1;
326 blendfunc.param0 = 1.f/255.f;
327 blendfunc.isTransparent = 1;
333 blendfunc.param0 = 0.5f;
334 blendfunc.isTransparent = 1;
340 blendfunc.param0 = 1.f / 255.f;
341 blendfunc.isTransparent = 1;
356 blendfunc.isTransparent = 1;
366 static u32 RandomSeed = 0x69666966;
367 RandomSeed = (RandomSeed * 3631 + 1);
369 f32 value = ( (
f32) (RandomSeed & 0x7FFF ) * (1.0f / (
f32)(0x7FFF >> 1) ) ) - 1.f;
374enum eQ3ModifierFunction
384 SCROLL = FUNCTION2 + 1,
385 SCALE = FUNCTION2 + 2,
386 ROTATE = FUNCTION2 + 3,
387 STRETCH = FUNCTION2 + 4,
388 TURBULENCE = FUNCTION2 + 5,
389 WAVE = FUNCTION2 + 6,
391 IDENTITY = FUNCTION2 + 7,
392 VERTEX = FUNCTION2 + 8,
393 TEXTURE = FUNCTION2 + 9,
394 LIGHTMAP = FUNCTION2 + 10,
395 ENVIRONMENT = FUNCTION2 + 11,
396 DOLLAR_LIGHTMAP = FUNCTION2 + 12,
397 BULGE = FUNCTION2 + 13,
398 AUTOSPRITE = FUNCTION2 + 14,
399 AUTOSPRITE2 = FUNCTION2 + 15,
400 TRANSFORM = FUNCTION2 + 16,
401 EXACTVERTEX = FUNCTION2 + 17,
402 CONSTANT = FUNCTION2 + 18,
403 LIGHTINGSPECULAR = FUNCTION2 + 19,
404 MOVE = FUNCTION2 + 20,
405 NORMAL = FUNCTION2 + 21,
406 IDENTITYLIGHTING = FUNCTION2 + 22,
408 WAVE_MODIFIER_FUNCTION = 0x30,
409 SINUS = WAVE_MODIFIER_FUNCTION + 1,
410 COSINUS = WAVE_MODIFIER_FUNCTION + 2,
411 SQUARE = WAVE_MODIFIER_FUNCTION + 3,
412 TRIANGLE = WAVE_MODIFIER_FUNCTION + 4,
413 SAWTOOTH = WAVE_MODIFIER_FUNCTION + 5,
414 SAWTOOTH_INVERSE = WAVE_MODIFIER_FUNCTION + 6,
415 NOISE = WAVE_MODIFIER_FUNCTION + 7,
424 masterfunc0 ( UNKNOWN ), masterfunc1( UNKNOWN ), func ( SINUS ),
425 tcgen( TEXTURE ), rgbgen ( IDENTITY ), alphagen ( UNKNOWN ),
426 base ( 0 ), amp ( 1 ), phase ( 0 ), frequency ( 1 ),
428 x ( 0 ), y ( 0 ), z( 0 ), count( 0 )
433 eQ3ModifierFunction masterfunc0;
435 eQ3ModifierFunction masterfunc1;
437 eQ3ModifierFunction func;
439 eQ3ModifierFunction tcgen;
440 eQ3ModifierFunction rgbgen;
441 eQ3ModifierFunction alphagen;
477 f32 evaluate (
f32 dt )
const
480 f32 x = core::fract( (dt + phase ) * frequency );
492 y = x < 0.5f ? 1.f : -1.f;
495 y = x < 0.5f ? ( 4.f * x ) - 1.f : ( -4.f * x ) + 3.f;
500 case SAWTOOTH_INVERSE:
510 return base + ( y * amp );
519 sinf ( lat ) * sinf ( lng ),
524inline void getModifierFunc ( SModifierFunction& fill,
const core::stringc &
string,
u32 &pos )
526 if (
string.size() == 0 )
529 static const c8 * funclist[] =
531 "sin",
"cos",
"square",
532 "triangle",
"sawtooth",
"inversesawtooth",
"noise"
535 fill.func = (eQ3ModifierFunction) isEqual (
string,pos, funclist,7 );
536 fill.func = fill.func == UNKNOWN ? SINUS : (eQ3ModifierFunction) ((
u32) fill.func + WAVE_MODIFIER_FUNCTION + 1);
538 fill.base = getAsFloat (
string, pos );
539 fill.amp = getAsFloat (
string, pos );
540 fill.phase = getAsFloat (
string, pos );
541 fill.frequency = getAsFloat (
string, pos );
552 SVariable (
const c8 * n,
const c8 *c = 0 ) : name ( n ), content (c) {}
569 bool operator == (
const SVariable &other )
const
571 return 0 == strcmp ( name.data(), other.name.data() );
574 bool operator < (
const SVariable &other )
const
576 return 0 > strcmp ( name.data(), other.name.data() );
584 SVarGroup () { Variable.setAllocStrategy ( core::ALLOC_STRATEGY_SAFE ); }
590 u32 isDefined (
const c8 * name,
const c8 * content = 0 )
const
592 for (
u32 i = 0; i != Variable.size (); ++i )
594 if ( 0 == strcmp ( Variable[i].name.data(), name ) &&
595 ( 0 == content || strstr ( Variable[i].content.data(), content ) )
609 s32 index = Variable.linear_search ( search );
611 return irrEmptyStringc;
613 return Variable [ index ].content;
617 void set (
const c8 * name,
const c8 * content = 0 )
619 u32 index = isDefined ( name, 0 );
622 Variable.push_back (
SVariable ( name, content ) );
626 Variable [ index ].content = content;
640 VariableGroup.setAllocStrategy ( core::ALLOC_STRATEGY_SAFE );
655 : ID ( 0 ), VarGroup ( 0 ) {}
658 bool operator == (
const IShader &other )
const
660 return 0 == strcmp ( name.data(), other.name.data() );
664 bool operator < (
const IShader &other )
const
666 return strcmp ( name.data(), other.name.data() ) < 0;
670 u32 getGroupSize ()
const
674 return VarGroup->VariableGroup.size ();
679 if ( 0 == VarGroup || stage >= VarGroup->VariableGroup.size () )
682 return &VarGroup->VariableGroup [ stage ];
710 for (
s32 i = 0; i < stack - 1; ++i )
717 for (
u32 g = 0; g != group->Variable.size(); ++g )
720 for (
s32 i = 0; i < stack; ++i )
723 buf += group->Variable[g].name;
725 buf += group->Variable[g].content;
733 for (
s32 i = 0; i < stack - 1; ++i )
749 const u32 size = shader->VarGroup->VariableGroup.size ();
750 for (
u32 i = 0; i != size; ++i )
752 const SVarGroup * group = &shader->VarGroup->VariableGroup[ i ];
753 dumpVarGroup ( dest, group,
core::clamp( (
int)i, 0, 2 ) );
760 dest.append (
"{\n" );
762 dest.append (
"}\n" );
772inline void getTextures(tTexArray &textures,
774 const io::IFileSystem *fileSystem,
775 video::IVideoDriver* driver)
777 static const char *
const extension[] =
788 tStringList stringList;
789 getAsStringList(stringList, -1, name, startPos);
794 for (
u32 i = 0; i!= stringList.size (); ++i )
796 video::ITexture* texture = 0;
797 for (
u32 g = 0; g != 7; ++g)
801 if ( loadFile ==
"$whiteimage" )
803 texture = driver->getTexture(
"$whiteimage" );
807 u32 image[4] = { 0xFFFFFFFF, 0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF };
809 texture = driver->addTexture(
"$whiteimage", w );
815 if ( loadFile ==
"$redimage" )
817 texture = driver->getTexture(
"$redimage" );
821 u32 image[4] = { 0xFFFF0000, 0xFFFF0000,0xFFFF0000,0xFFFF0000 };
823 texture = driver->addTexture(
"$redimage", w );
828 if ( loadFile ==
"$blueimage" )
830 texture = driver->getTexture(
"$blueimage" );
834 u32 image[4] = { 0xFF0000FF, 0xFF0000FF,0xFF0000FF,0xFF0000FF };
836 texture = driver->addTexture(
"$blueimage", w );
841 if ( loadFile ==
"$checkerimage" )
843 texture = driver->getTexture(
"$checkerimage" );
847 u32 image[4] = { 0xFFFFFFFF, 0xFF000000,0xFF000000,0xFFFFFFFF };
849 texture = driver->addTexture(
"$checkerimage", w );
854 if ( loadFile ==
"$lightmap" )
860 loadFile.append ( extension[g] );
863 texture = driver->findTexture( loadFile );
867 if ( fileSystem->existFile ( loadFile ) )
869 texture = driver->getTexture( loadFile );
876 textures.push_back(texture);
Base class of most objects of the Nirtcpp Engine.
Definition IReferenceCounted.hpp:46
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.hpp:22
T X
X coordinate of the vector.
Definition vector3d.hpp:450
Manages various Quake3 Shader Styles.
Definition IQ3Shader.hpp:882
A Parsed Shader Holding Variables ordered in Groups.
Definition IQ3Shader.hpp:652
Definition IQ3Shader.hpp:362
Definition IQ3Shader.hpp:35
A blend function for a q3 shader.
Definition IQ3Shader.hpp:156
Definition IQ3Shader.hpp:421
holding a group a variable
Definition IQ3Shader.hpp:636
Definition IQ3Shader.hpp:582
Definition IQ3Shader.hpp:546
dimension2d< u32 > dimension2du
using type alias for an unsigned integer dimension.
Definition dimension2d.hpp:212
const char * fast_atof_move(const char *in, f32 &result)
Provides a fast function for converting a string into a float.
Definition fast_atof.hpp:317
string< c8 > stringc
using type alias for character strings
Definition irrString.hpp:1457
const f32 PI
Constant for PI.
Definition irrMath.hpp:54
io::path & cutFilenameExtension(io::path &dest, const io::path &source)
cut the filename extension from a source file path and store it in a dest file path
Definition coreutil.hpp:48
vector3d< f32 > vector3df
using type alias for a f32 3d vector.
Definition vector3d.hpp:487
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition irrMath.hpp:164
core::string< fschar_t > path
Type used for all file system related strings.
Definition path.hpp:17
E_MATERIAL_FLAG
Material flags.
Definition EMaterialFlags.hpp:15
@ EMF_BILINEAR_FILTER
Is bilinear filtering enabled? Default: true.
Definition EMaterialFlags.hpp:43
E_MODULATE_FUNC
MaterialTypeParam: e.g. DirectX: D3DTOP_MODULATE, D3DTOP_MODULATE2X, D3DTOP_MODULATE4X.
Definition SMaterial.hpp:56
E_BLEND_FACTOR
Definition SMaterial.hpp:25
@ EBF_ZERO
src & dest (0, 0, 0, 0)
Definition SMaterial.hpp:26
@ EBF_SRC_COLOR
dest (srcR, srcG, srcB, srcA)
Definition SMaterial.hpp:30
@ EBF_DST_COLOR
src (destR, destG, destB, destA)
Definition SMaterial.hpp:28
@ EBF_SRC_ALPHA
src & dest (srcA, srcA, srcA, srcA)
Definition SMaterial.hpp:32
@ EBF_ONE_MINUS_SRC_ALPHA
src & dest (1-srcA, 1-srcA, 1-srcA, 1-srcA)
Definition SMaterial.hpp:33
@ EBF_ONE
src & dest (1, 1, 1, 1)
Definition SMaterial.hpp:27
f32 pack_textureBlendFunc(const E_BLEND_FACTOR srcFact, const E_BLEND_FACTOR dstFact, const E_MODULATE_FUNC modulate=EMFN_MODULATE_1X, const u32 alphaSource=EAS_TEXTURE)
Pack srcFact, dstFact, Modulate and alpha source to MaterialTypeParam or BlendFactor.
Definition SMaterial.hpp:119
@ ECF_A8R8G8B8
Definition SColor.hpp:38
@ ECFN_EQUAL
Exact equality.
Definition SMaterial.hpp:70
@ ECFN_LESSEQUAL
<= test, default for e.g. depth test
Definition SMaterial.hpp:68
E_MATERIAL_TYPE
Abstracted and easy to use fixed function/programmable pipeline material modes.
Definition EMaterialTypes.hpp:15
@ EMT_TRANSPARENT_ALPHA_CHANNEL
Makes the material transparent based on the texture alpha channel.
Definition EMaterialTypes.hpp:101
@ EMT_SOLID
Standard solid material.
Definition EMaterialTypes.hpp:19
@ EMT_LIGHTMAP_M4
Material type with standard lightmap technique.
Definition EMaterialTypes.hpp:49
@ EMT_ONETEXTURE_BLEND
BlendFunc = source * sourceFactor + dest * destFactor ( E_BLEND_FUNC )
Definition EMaterialTypes.hpp:193
@ EMT_TRANSPARENT_ADD_COLOR
A transparent material.
Definition EMaterialTypes.hpp:88
unsigned short u16
16 bit unsigned variable.
Definition irrTypes.hpp:46
signed int s32
32 bit signed variable.
Definition irrTypes.hpp:72
unsigned char u8
8 bit unsigned variable.
Definition irrTypes.hpp:24
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.hpp:64
char c8
8 bit character variable.
Definition irrTypes.hpp:37
float f32
32 bit floating point variable.
Definition irrTypes.hpp:110
signed short s16
16 bit signed variable.
Definition irrTypes.hpp:54