2
// Copyright ļæ½ 1997 - 2001, Paul C. Gregory
4
// Contact: pgregory@aqsis.com
6
// This library is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public
8
// License as published by the Free Software Foundation; either
9
// version 2 of the License, or (at your option) any later version.
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
// General Public License for more details.
16
// You should have received a copy of the GNU General Public
17
// License along with this library; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
\brief Implements the basic shader operations.
23
\author Paul C. Gregory (pgregory@aqsis.com)
34
#include "shaderexecenv.h"
37
#include "irenderer.h"
38
#include "itexturemap.h"
39
#include "ilightsource.h"
42
START_NAMESPACE( Aqsis )
44
IqRenderer* QGetRenderContextI();
47
//----------------------------------------------------------------------
49
// Helper function to process a string inserting variable, used in printf and format.
51
static CqString SO_sprintf( const char* str, int cParams, IqShaderData** apParams, int varyingindex )
53
CqString strRes( "" );
54
CqString strTrans = str;
55
strTrans = strTrans.TranslateEscapes();
59
while ( i < strTrans.size() )
61
switch ( strTrans[ i ] )
63
case '%': // Insert variable.
66
switch ( strTrans[ i ] )
71
apParams[ ivar++ ] ->GetFloat( f, varyingindex );
73
strVal.Format( "%f", f );
81
apParams[ ivar++ ] ->GetPoint( vec, varyingindex );
83
strVal.Format( "%f,%f,%f", vec.x(), vec.y(), vec.z() );
91
apParams[ ivar++ ] ->GetColor( col, varyingindex );
93
strVal.Format( "%f,%f,%f", col.fRed(), col.fGreen(), col.fBlue() );
101
apParams[ ivar++ ] ->GetMatrix( mat, varyingindex );
103
strVal.Format( "%f,%f,%f,%f\n%f,%f,%f,%f\n%f,%f,%f,%f\n%f,%f,%f,%f",
104
mat.Element( 0, 0 ), mat.Element( 0, 1 ), mat.Element( 0, 2 ), mat.Element( 0, 3 ),
105
mat.Element( 1, 0 ), mat.Element( 1, 1 ), mat.Element( 1, 2 ), mat.Element( 1, 3 ),
106
mat.Element( 2, 0 ), mat.Element( 2, 1 ), mat.Element( 2, 2 ), mat.Element( 2, 3 ),
107
mat.Element( 3, 0 ), mat.Element( 3, 1 ), mat.Element( 3, 2 ), mat.Element( 3, 3 ) );
115
apParams[ ivar++ ] ->GetString( stra, varyingindex );
122
strRes += strTrans[ i ];
132
strRes += strTrans[ i ];
141
//----------------------------------------------------------------------
142
// init_illuminance()
143
TqBool CqShaderExecEnv::SO_init_illuminance()
146
return ( SO_advance_illuminance() );
150
//----------------------------------------------------------------------
151
// advance_illuminance()
152
TqBool CqShaderExecEnv::SO_advance_illuminance()
155
while ( m_li < m_pAttributes ->cLights() &&
156
m_pAttributes ->pLight( m_li ) ->pShader() ->fAmbient() )
160
if ( m_li < m_pAttributes ->cLights() )
167
void CqShaderExecEnv::ValidateIlluminanceCache( IqShaderData* pP, IqShaderData* pN, IqShader* pShader )
169
// If this is the first call to illuminance this time round, call all lights and setup the Cl and L caches.
170
if ( !m_IlluminanceCacheValid )
172
IqShaderData* Ns = (pN != NULL )? pN : N();
173
IqShaderData* Ps = (pP != NULL )? pP : P();
175
while ( li < m_pAttributes ->cLights() )
177
IqLightsource * lp = m_pAttributes ->pLight( li );
178
// Initialise the lightsource
179
lp->Initialise( uGridRes(), vGridRes() );
181
// Evaluate the lightsource
182
lp->Evaluate( Ps, Ns );
185
m_IlluminanceCacheValid = TqTrue;;
190
STD_SOIMPL CqShaderExecEnv::SO_radians( FLOATVAL degrees, DEFPARAMIMPL )
192
STATS_INC( SHD_so_radians );
199
BEGIN_VARYING_SECTION
201
SETFLOAT( Result, RAD( FLOAT( degrees ) ) );
205
STD_SOIMPL CqShaderExecEnv::SO_degrees( FLOATVAL radians, DEFPARAMIMPL )
207
STATS_INC( SHD_so_degrees );
214
BEGIN_VARYING_SECTION
216
SETFLOAT( Result, DEG( FLOAT( radians ) ) );
220
STD_SOIMPL CqShaderExecEnv::SO_sin( FLOATVAL a, DEFPARAMIMPL )
222
STATS_INC( SHD_so_sin );
229
BEGIN_VARYING_SECTION
231
SETFLOAT( Result, static_cast<TqFloat>( sin( FLOAT( a ) ) ) );
235
STD_SOIMPL CqShaderExecEnv::SO_asin( FLOATVAL a, DEFPARAMIMPL )
237
STATS_INC( SHD_so_asin );
244
BEGIN_VARYING_SECTION
246
SETFLOAT( Result, static_cast<TqFloat>( asin( FLOAT( a ) ) ) );
250
STD_SOIMPL CqShaderExecEnv::SO_cos( FLOATVAL a, DEFPARAMIMPL )
252
STATS_INC( SHD_so_cos );
259
BEGIN_VARYING_SECTION
261
SETFLOAT( Result, static_cast<TqFloat>( cos( FLOAT( a ) ) ) );
265
STD_SOIMPL CqShaderExecEnv::SO_acos( FLOATVAL a, DEFPARAMIMPL )
267
STATS_INC( SHD_so_acos );
274
BEGIN_VARYING_SECTION
276
SETFLOAT( Result, static_cast<TqFloat>( acos( FLOAT( a ) ) ) );
280
STD_SOIMPL CqShaderExecEnv::SO_tan( FLOATVAL a, DEFPARAMIMPL )
282
STATS_INC( SHD_so_tan );
289
BEGIN_VARYING_SECTION
291
SETFLOAT( Result, static_cast<TqFloat>( tan( FLOAT( a ) ) ) );
295
STD_SOIMPL CqShaderExecEnv::SO_atan( FLOATVAL yoverx, DEFPARAMIMPL )
297
STATS_INC( SHD_so_atan );
304
BEGIN_VARYING_SECTION
306
SETFLOAT( Result, static_cast<TqFloat>( atan( FLOAT( yoverx ) ) ) );
310
STD_SOIMPL CqShaderExecEnv::SO_atan( FLOATVAL y, FLOATVAL x, DEFPARAMIMPL )
312
STATS_INC( SHD_so_atan );
320
BEGIN_VARYING_SECTION
323
SETFLOAT( Result, static_cast<TqFloat>( atan2( FLOAT( y ), FLOAT( x ) ) ) );
327
STD_SOIMPL CqShaderExecEnv::SO_pow( FLOATVAL x, FLOATVAL y, DEFPARAMIMPL )
329
STATS_INC( SHD_so_pow );
337
BEGIN_VARYING_SECTION
340
TqFloat yy = FLOAT( y );
341
TqFloat xx = FLOAT( x );
342
if ( xx < 0.0f ) yy = FLOOR( yy );
343
SETFLOAT( Result, static_cast<TqFloat>( pow( xx, yy ) ) );
347
STD_SOIMPL CqShaderExecEnv::SO_exp( FLOATVAL x, DEFPARAMIMPL )
349
STATS_INC( SHD_so_exp );
356
BEGIN_VARYING_SECTION
358
SETFLOAT( Result, static_cast<TqFloat>( exp( FLOAT( x ) ) ) );
362
STD_SOIMPL CqShaderExecEnv::SO_sqrt( FLOATVAL x, DEFPARAMIMPL )
364
STATS_INC( SHD_so_sqrt );
371
BEGIN_VARYING_SECTION
373
SETFLOAT( Result, static_cast<TqFloat>( sqrt( FLOAT( x ) ) ) );
377
STD_SOIMPL CqShaderExecEnv::SO_log( FLOATVAL x, DEFPARAMIMPL )
379
STATS_INC( SHD_so_log );
386
BEGIN_VARYING_SECTION
388
SETFLOAT( Result, static_cast<TqFloat>( log( FLOAT( x ) ) ) );
392
STD_SOIMPL CqShaderExecEnv::SO_mod( FLOATVAL a, FLOATVAL b, DEFPARAMIMPL )
394
STATS_INC( SHD_so_mod );
402
BEGIN_VARYING_SECTION
405
TqInt n = static_cast<TqInt>( FLOAT( a ) / FLOAT( b ) );
406
TqFloat a2 = FLOAT( a ) - n * FLOAT( b );
409
SETFLOAT( Result, a2 );
413
//----------------------------------------------------------------------
415
STD_SOIMPL CqShaderExecEnv::SO_log( FLOATVAL x, FLOATVAL base, DEFPARAMIMPL )
417
STATS_INC( SHD_so_log );
425
BEGIN_VARYING_SECTION
428
SETFLOAT( Result, static_cast<TqFloat>( log( FLOAT( x ) ) / log( FLOAT( base ) ) ) );
433
STD_SOIMPL CqShaderExecEnv::SO_abs( FLOATVAL x, DEFPARAMIMPL )
435
STATS_INC( SHD_so_abs );
442
BEGIN_VARYING_SECTION
444
SETFLOAT( Result, static_cast<TqFloat>( fabs( FLOAT( x ) ) ) );
448
STD_SOIMPL CqShaderExecEnv::SO_sign( FLOATVAL x, DEFPARAMIMPL )
450
STATS_INC( SHD_so_sign );
457
BEGIN_VARYING_SECTION
459
SETFLOAT( Result, ( FLOAT( x ) < 0.0f ) ? -1.0f : 1.0f );
463
STD_SOIMPL CqShaderExecEnv::SO_min( FLOATVAL a, FLOATVAL b, DEFPARAMVARIMPL )
465
STATS_INC( SHD_so_min );
473
BEGIN_VARYING_SECTION
476
TqFloat fRes = MIN( FLOAT( a ), FLOAT( b ) );
477
while ( cParams-- > 0 )
480
apParams[ cParams ] ->GetFloat( fn, __iGrid );
481
fRes = MIN( fRes, fn );
483
SETFLOAT( Result, fRes );
487
STD_SOIMPL CqShaderExecEnv::SO_max( FLOATVAL a, FLOATVAL b, DEFPARAMVARIMPL )
489
STATS_INC( SHD_so_max );
497
BEGIN_VARYING_SECTION
500
TqFloat fRes = MAX( FLOAT( a ), FLOAT( b ) );
501
while ( cParams-- > 0 )
504
apParams[ cParams ] ->GetFloat( fn, __iGrid );
505
fRes = MAX( fRes, fn );
507
SETFLOAT( Result, fRes );
511
STD_SOIMPL CqShaderExecEnv::SO_pmin( POINTVAL a, POINTVAL b, DEFPARAMVARIMPL )
513
STATS_INC( SHD_so_pmin );
521
BEGIN_VARYING_SECTION
524
CqVector3D res = VMIN( POINT( a ), POINT( b ) );
525
while ( cParams-- > 0 )
528
apParams[ cParams ] ->GetPoint( pn, __iGrid );
529
res = VMIN( res, pn );
531
SETPOINT( Result, res );
535
STD_SOIMPL CqShaderExecEnv::SO_pmax( POINTVAL a, POINTVAL b, DEFPARAMVARIMPL )
537
STATS_INC( SHD_so_pmax );
545
BEGIN_VARYING_SECTION
548
CqVector3D res = VMAX( POINT( a ), POINT( b ) );
549
while ( cParams-- > 0 )
552
apParams[ cParams ] ->GetPoint( pn, __iGrid );
553
res = VMAX( res, pn );
555
SETPOINT( Result, res );
559
STD_SOIMPL CqShaderExecEnv::SO_cmin( COLORVAL a, COLORVAL b, DEFPARAMVARIMPL )
561
STATS_INC( SHD_so_cmin );
569
BEGIN_VARYING_SECTION
572
CqColor res = CMIN( COLOR( a ), COLOR( b ) );
573
while ( cParams-- > 0 )
576
apParams[ cParams ] ->GetColor( cn, __iGrid );
577
res = CMIN( res, cn );
579
SETCOLOR( Result, res );
583
STD_SOIMPL CqShaderExecEnv::SO_cmax( COLORVAL a, COLORVAL b, DEFPARAMVARIMPL )
585
STATS_INC( SHD_so_cmax );
593
BEGIN_VARYING_SECTION
596
CqColor res = CMAX( COLOR( a ), COLOR( b ) );
597
while ( cParams-- > 0 )
600
apParams[ cParams ] ->GetColor( cn, __iGrid );
601
res = CMAX( res, cn );
603
SETCOLOR( Result, res );
607
STD_SOIMPL CqShaderExecEnv::SO_clamp( FLOATVAL a, FLOATVAL _min, FLOATVAL _max, DEFPARAMIMPL )
609
STATS_INC( SHD_so_clamp );
618
BEGIN_VARYING_SECTION
622
SETFLOAT( Result, CLAMP( FLOAT( a ), FLOAT( _min ), FLOAT( _max ) ) );
626
STD_SOIMPL CqShaderExecEnv::SO_pclamp( POINTVAL a, POINTVAL _min, POINTVAL _max, DEFPARAMIMPL )
628
STATS_INC( SHD_so_pclamp );
637
BEGIN_VARYING_SECTION
641
SETPOINT( Result, VCLAMP( POINT( a ), POINT( _min ), POINT( _max ) ) );
645
STD_SOIMPL CqShaderExecEnv::SO_cclamp( COLORVAL a, COLORVAL _min, COLORVAL _max, DEFPARAMIMPL )
647
STATS_INC( SHD_so_cclamp );
656
BEGIN_VARYING_SECTION
660
SETCOLOR( Result, CCLAMP( COLOR( a ), COLOR( _min ), COLOR( _max ) ) );
664
STD_SOIMPL CqShaderExecEnv::SO_floor( FLOATVAL x, DEFPARAMIMPL )
666
STATS_INC( SHD_so_floor );
673
BEGIN_VARYING_SECTION
675
SETFLOAT( Result, static_cast<TqFloat>( FLOOR( FLOAT( x ) ) ) );
679
STD_SOIMPL CqShaderExecEnv::SO_ceil( FLOATVAL x, DEFPARAMIMPL )
681
STATS_INC( SHD_so_ceil );
688
BEGIN_VARYING_SECTION
690
SETFLOAT( Result, static_cast<TqFloat>( CEIL( FLOAT( x ) ) ) );
694
STD_SOIMPL CqShaderExecEnv::SO_round( FLOATVAL x, DEFPARAMIMPL )
702
BEGIN_VARYING_SECTION
704
SETFLOAT( Result, ( modf( FLOAT( x ), &v ) > 0.5f ) ? static_cast<TqFloat>( v ) + 1.0f : static_cast<TqFloat>( v ) );
708
STD_SOIMPL CqShaderExecEnv::SO_step( FLOATVAL _min, FLOATVAL value, DEFPARAMIMPL )
710
STATS_INC( SHD_so_step );
718
BEGIN_VARYING_SECTION
721
SETFLOAT( Result, ( FLOAT( value ) < FLOAT( _min ) ) ? 0.0f : 1.0f );
726
//----------------------------------------------------------------------
727
// smoothstep(_min,_max,value)
728
STD_SOIMPL CqShaderExecEnv::SO_smoothstep( FLOATVAL _min, FLOATVAL _max, FLOATVAL value, DEFPARAMIMPL )
730
STATS_INC( SHD_so_smoothstep );
739
BEGIN_VARYING_SECTION
743
if ( FLOAT( value ) < FLOAT( _min ) )
744
SETFLOAT( Result, 0.0f );
745
else if ( FLOAT( value ) >= FLOAT( _max ) )
746
SETFLOAT( Result, 1.0f );
749
TqFloat v = ( FLOAT( value ) - FLOAT( _min ) ) / ( FLOAT( _max ) - FLOAT( _min ) );
750
SETFLOAT( Result, v * v * ( 3.0f - 2.0f * v ) );
756
//----------------------------------------------------------------------
757
// spline(value, f1,f2,...,fn)
758
STD_SOIMPL CqShaderExecEnv::SO_fspline( FLOATVAL value, DEFPARAMVARIMPL )
760
STATS_INC( SHD_so_fspline );
764
CqSplineCubic spline( cParams );
768
for ( v = 0; v < cParams; v++ )
770
CHECKVARY( ( apParams[ v ] ) )
774
BEGIN_VARYING_SECTION
776
if ( FLOAT( value ) >= 1.0f )
779
apParams[ cParams - 2 ] ->GetFloat( fl, __iGrid );
780
SETFLOAT( Result, fl );
782
else if ( FLOAT( value ) <= 0.0f )
785
apParams[ 1 ] ->GetFloat( ff, __iGrid );
786
SETFLOAT( Result, ff );
791
for ( j = 0; j < cParams; j++ )
794
apParams[ j ] ->GetFloat( fn, __iGrid );
795
spline[ j ] = CqVector4D( fn, 0.0f, 0.0f, 1.0f );
798
CqVector4D res = spline.Evaluate( FLOAT( value ) );
799
SETFLOAT( Result, res.x() );
805
//----------------------------------------------------------------------
806
// spline(value, f1,f2,...,fn)
807
STD_SOIMPL CqShaderExecEnv::SO_cspline( FLOATVAL value, DEFPARAMVARIMPL )
809
STATS_INC( SHD_so_cspline );
813
CqSplineCubic spline( cParams );
817
for ( v = 0; v < cParams; v++ )
819
CHECKVARY( ( apParams[ v ] ) )
823
BEGIN_VARYING_SECTION
825
if ( FLOAT( value ) >= 1.0f )
828
apParams[ cParams - 2 ] ->GetColor( cl, __iGrid );
829
SETCOLOR( Result, cl );
831
else if ( FLOAT( value ) <= 0.0f )
834
apParams[ 1 ] ->GetColor( cf, __iGrid );
835
SETCOLOR( Result, cf );
840
for ( j = 0; j < cParams; j++ )
843
apParams[ j ] ->GetColor( cn, __iGrid );
844
spline[ j ] = CqVector4D( cn.fRed(), cn.fGreen(), cn.fBlue(), 1.0f );
847
CqVector4D res = spline.Evaluate( FLOAT( value ) );
848
SETCOLOR( Result, CqColor( res.x(), res.y(), res.z() ) );
854
//----------------------------------------------------------------------
855
// spline(value, f1,f2,...,fn)
856
STD_SOIMPL CqShaderExecEnv::SO_pspline( FLOATVAL value, DEFPARAMVARIMPL )
858
STATS_INC( SHD_so_pspline );
862
CqSplineCubic spline( cParams );
866
for ( v = 0; v < cParams; v++ )
868
CHECKVARY( ( apParams[ v ] ) )
872
BEGIN_VARYING_SECTION
874
if ( FLOAT( value ) >= 1.0f )
877
apParams[ cParams - 2 ] ->GetPoint( pl, __iGrid );
878
SETPOINT( Result, pl );
880
else if ( FLOAT( value ) <= 0.0f )
883
apParams[ 1 ] ->GetPoint( pf, __iGrid );
884
SETPOINT( Result, pf );
889
for ( j = 0; j < cParams; j++ )
892
apParams[ j ] ->GetPoint( pn, __iGrid );
896
CqVector3D res = spline.Evaluate( FLOAT( value ) );
897
SETPOINT( Result, res );
903
//----------------------------------------------------------------------
904
// spline(value, f1,f2,...,fn)
905
STD_SOIMPL CqShaderExecEnv::SO_sfspline( STRINGVAL basis, FLOATVAL value, DEFPARAMVARIMPL )
907
STATS_INC( SHD_so_sfspline );
911
CqSplineCubic spline( cParams );
915
for ( v = 0; v < cParams; v++ )
917
CHECKVARY( ( apParams[ v ] ) )
921
BEGIN_UNIFORM_SECTION
923
spline.SetmatBasis( STRING( basis ) );
926
BEGIN_VARYING_SECTION
928
if ( FLOAT( value ) >= 1.0f )
931
apParams[ cParams - 2 ] ->GetFloat( fl, __iGrid );
932
SETFLOAT( Result, fl );
934
else if ( FLOAT( value ) <= 0.0f )
937
apParams[ 1 ] ->GetFloat( ff, __iGrid );
938
SETFLOAT( Result, ff );
943
for ( j = 0; j < cParams; j++ )
946
apParams[ j ] ->GetFloat( fn, __iGrid );
947
spline[ j ] = CqVector4D( fn, 0.0f, 0.0f, 1.0f );
950
CqVector4D res = spline.Evaluate( FLOAT( value ) );
951
SETFLOAT( Result, res.x() );
957
//----------------------------------------------------------------------
958
// spline(value, f1,f2,...,fn)
959
STD_SOIMPL CqShaderExecEnv::SO_scspline( STRINGVAL basis, FLOATVAL value, DEFPARAMVARIMPL )
961
STATS_INC( SHD_so_scspline );
965
CqSplineCubic spline( cParams );
969
for ( v = 0; v < cParams; v++ )
971
CHECKVARY( ( apParams[ v ] ) )
975
BEGIN_UNIFORM_SECTION
977
spline.SetmatBasis( STRING( basis ) );
980
BEGIN_VARYING_SECTION
982
if ( FLOAT( value ) >= 1.0f )
985
apParams[ cParams - 2 ] ->GetColor( cl, __iGrid );
986
SETCOLOR( Result, cl );
988
else if ( FLOAT( value ) <= 0.0f )
991
apParams[ 1 ] ->GetColor( cf, __iGrid );
992
SETCOLOR( Result, cf );
997
for ( j = 0; j < cParams; j++ )
1000
apParams[ j ] ->GetColor( cn, __iGrid );
1001
spline[ j ] = CqVector4D( cn.fRed(), cn.fGreen(), cn.fBlue(), 1.0f );
1004
CqVector4D res = spline.Evaluate( FLOAT( value ) );
1005
SETCOLOR( Result, CqColor( res.x(), res.y(), res.z() ) );
1011
//----------------------------------------------------------------------
1012
// spline(value, f1,f2,...,fn)
1013
STD_SOIMPL CqShaderExecEnv::SO_spspline( STRINGVAL basis, FLOATVAL value, DEFPARAMVARIMPL )
1015
STATS_INC( SHD_so_spspline );
1019
CqSplineCubic spline( cParams );
1023
for ( v = 0; v < cParams; v++ )
1025
CHECKVARY( ( apParams[ v ] ) )
1029
BEGIN_UNIFORM_SECTION
1031
spline.SetmatBasis( STRING( basis ) );
1034
BEGIN_VARYING_SECTION
1036
if ( FLOAT( value ) >= 1.0f )
1039
apParams[ cParams - 2 ] ->GetPoint( pl, __iGrid );
1040
SETPOINT( Result, pl );
1042
else if ( FLOAT( value ) <= 0.0f )
1045
apParams[ 1 ] ->GetPoint( pf, __iGrid );
1046
SETPOINT( Result, pf );
1051
for ( j = 0; j < cParams; j++ )
1054
apParams[ j ] ->GetPoint( pn, __iGrid );
1058
CqVector3D res = spline.Evaluate( FLOAT( value ) );
1059
SETPOINT( Result, res );
1065
STD_SOIMPL CqShaderExecEnv::SO_fDu( FLOATVAL p, DEFPARAMIMPL )
1067
STATS_INC( SHD_so_fDu );
1069
TqFloat Deffloat = 0.0f;
1075
BEGIN_VARYING_SECTION
1076
SETFLOAT( Result, SO_DuType<TqFloat>( p, __iGrid, this, Deffloat ) );
1081
STD_SOIMPL CqShaderExecEnv::SO_fDv( FLOATVAL p, DEFPARAMIMPL )
1083
STATS_INC( SHD_so_fDv );
1085
TqFloat Deffloat = 0.0f;
1091
BEGIN_VARYING_SECTION
1092
SETFLOAT( Result, SO_DvType<TqFloat>( p, __iGrid, this, Deffloat ) );
1097
STD_SOIMPL CqShaderExecEnv::SO_fDeriv( FLOATVAL p, FLOATVAL den, DEFPARAMIMPL )
1099
STATS_INC( SHD_so_fDeriv );
1107
BEGIN_VARYING_SECTION
1108
SETFLOAT( Result, SO_DerivType<TqFloat>( p, den, __iGrid, this ) );
1113
STD_SOIMPL CqShaderExecEnv::SO_cDu( COLORVAL p, DEFPARAMIMPL )
1115
STATS_INC( SHD_so_cDu );
1117
CqColor Defcol( 0.0f, 0.0f, 0.0f );
1123
BEGIN_VARYING_SECTION
1124
SETCOLOR( Result, SO_DuType<CqColor>( p, __iGrid, this, Defcol ) );
1129
STD_SOIMPL CqShaderExecEnv::SO_cDv( COLORVAL p, DEFPARAMIMPL )
1131
STATS_INC( SHD_so_cDv );
1133
CqColor Defcol( 0.0f, 0.0f, 0.0f );
1139
BEGIN_VARYING_SECTION
1140
SETCOLOR( Result, SO_DvType<CqColor>( p, __iGrid, this, Defcol ) );
1145
STD_SOIMPL CqShaderExecEnv::SO_cDeriv( COLORVAL p, FLOATVAL den, DEFPARAMIMPL )
1147
STATS_INC( SHD_so_cDeriv );
1155
BEGIN_VARYING_SECTION
1156
SETCOLOR( Result, SO_DerivType<CqColor>( p, den, __iGrid, this ) );
1161
STD_SOIMPL CqShaderExecEnv::SO_pDu( POINTVAL p, DEFPARAMIMPL )
1163
STATS_INC( SHD_so_pDu );
1165
CqVector3D Defvec( 0.0f, 0.0f, 0.0f );
1171
BEGIN_VARYING_SECTION
1172
SETPOINT( Result, SO_DuType<CqVector3D>( p, __iGrid, this, Defvec ) );
1177
STD_SOIMPL CqShaderExecEnv::SO_pDv( POINTVAL p, DEFPARAMIMPL )
1179
STATS_INC( SHD_so_pDv );
1181
CqVector3D Defvec( 0.0f, 0.0f, 0.0f );
1187
BEGIN_VARYING_SECTION
1188
SETPOINT( Result, SO_DvType<CqVector3D>( p, __iGrid, this, Defvec ) );
1193
STD_SOIMPL CqShaderExecEnv::SO_pDeriv( POINTVAL p, FLOATVAL den, DEFPARAMIMPL )
1195
STATS_INC( SHD_so_pDeriv );
1203
BEGIN_VARYING_SECTION
1204
SETPOINT( Result, SO_DerivType<CqVector3D>( p, den, __iGrid, this ) );
1209
STD_SOIMPL CqShaderExecEnv::SO_frandom( DEFPARAMIMPL )
1211
STATS_INC( SHD_so_frandom );
1217
BEGIN_VARYING_SECTION
1218
SETFLOAT( Result, m_random.RandomFloat() );
1222
STD_SOIMPL CqShaderExecEnv::SO_crandom( DEFPARAMIMPL )
1224
STATS_INC( SHD_so_crandom );
1230
BEGIN_VARYING_SECTION
1231
SETCOLOR( Result, CqColor( m_random.RandomFloat(), m_random.RandomFloat(), m_random.RandomFloat() ) );
1235
STD_SOIMPL CqShaderExecEnv::SO_prandom( DEFPARAMIMPL )
1237
STATS_INC( SHD_so_prandom );
1243
BEGIN_VARYING_SECTION
1244
SETCOLOR( Result, CqVector3D( m_random.RandomFloat(), m_random.RandomFloat(), m_random.RandomFloat() ) );
1249
//----------------------------------------------------------------------
1251
STD_SOIMPL CqShaderExecEnv::SO_fnoise1( FLOATVAL v, DEFPARAMIMPL )
1253
STATS_INC( SHD_so_fnoise1 );
1260
BEGIN_VARYING_SECTION
1262
SETFLOAT( Result, ( m_noise.FGNoise1( FLOAT( v ) ) + 1 ) / 2.0f );
1266
//----------------------------------------------------------------------
1268
STD_SOIMPL CqShaderExecEnv::SO_fnoise2( FLOATVAL u, FLOATVAL v, DEFPARAMIMPL )
1270
STATS_INC( SHD_so_fnoise2 );
1278
BEGIN_VARYING_SECTION
1281
SETFLOAT( Result, ( m_noise.FGNoise2( FLOAT( u ), FLOAT( v ) ) + 1 ) / 2.0f );
1285
//----------------------------------------------------------------------
1287
STD_SOIMPL CqShaderExecEnv::SO_fnoise3( POINTVAL p, DEFPARAMIMPL )
1289
STATS_INC( SHD_so_fnoise3 );
1296
BEGIN_VARYING_SECTION
1298
SETFLOAT( Result, ( m_noise.FGNoise3( POINT( p ) ) + 1 ) / 2.0f );
1302
//----------------------------------------------------------------------
1304
STD_SOIMPL CqShaderExecEnv::SO_fnoise4( POINTVAL p, FLOATVAL t, DEFPARAMIMPL )
1306
// TODO: Do proper 4D noise.
1307
STATS_INC( SHD_so_fnoise4 );
1315
BEGIN_VARYING_SECTION
1318
SETFLOAT( Result, ( m_noise.FGNoise3( POINT( p ) ) + 1 ) / 2.0f );
1322
//----------------------------------------------------------------------
1324
STD_SOIMPL CqShaderExecEnv::SO_cnoise1( FLOATVAL v, DEFPARAMIMPL )
1326
STATS_INC( SHD_so_cnoise1 );
1333
BEGIN_VARYING_SECTION
1335
SETCOLOR( Result, ( m_noise.CGNoise1( FLOAT( v ) ) + 1 ) / 2.0f );
1339
//----------------------------------------------------------------------
1341
STD_SOIMPL CqShaderExecEnv::SO_cnoise2( FLOATVAL u, FLOATVAL v, DEFPARAMIMPL )
1343
STATS_INC( SHD_so_cnoise2 );
1351
BEGIN_VARYING_SECTION
1354
SETCOLOR( Result, ( m_noise.CGNoise2( FLOAT( u ), FLOAT( v ) ) + 1 ) / 2.0f );
1358
//----------------------------------------------------------------------
1360
STD_SOIMPL CqShaderExecEnv::SO_cnoise3( POINTVAL p, DEFPARAMIMPL )
1362
STATS_INC( SHD_so_cnoise3 );
1369
BEGIN_VARYING_SECTION
1371
SETCOLOR( Result, ( m_noise.CGNoise3( POINT( p ) ) + 1 ) / 2.0f );
1375
//----------------------------------------------------------------------
1377
STD_SOIMPL CqShaderExecEnv::SO_cnoise4( POINTVAL p, FLOATVAL t, DEFPARAMIMPL )
1379
// TODO: Do proper 4D noise.
1380
STATS_INC( SHD_so_cnoise4 );
1388
BEGIN_VARYING_SECTION
1391
SETCOLOR( Result, ( m_noise.CGNoise3( POINT( p ) ) + 1 ) / 2.0f );
1395
//----------------------------------------------------------------------
1397
STD_SOIMPL CqShaderExecEnv::SO_pnoise1( FLOATVAL v, DEFPARAMIMPL )
1399
STATS_INC( SHD_so_pnoise1 );
1406
BEGIN_VARYING_SECTION
1408
SETPOINT( Result, ( m_noise.PGNoise1( FLOAT( v ) ) + 1 ) / 2.0f );
1412
//----------------------------------------------------------------------
1414
STD_SOIMPL CqShaderExecEnv::SO_pnoise2( FLOATVAL u, FLOATVAL v, DEFPARAMIMPL )
1416
STATS_INC( SHD_so_pnoise2 );
1424
BEGIN_VARYING_SECTION
1427
SETPOINT( Result, ( m_noise.PGNoise2( FLOAT( u ), FLOAT( v ) ) + 1 ) / 2.0f );
1431
//----------------------------------------------------------------------
1433
STD_SOIMPL CqShaderExecEnv::SO_pnoise3( POINTVAL p, DEFPARAMIMPL )
1435
STATS_INC( SHD_so_pnoise3 );
1442
BEGIN_VARYING_SECTION
1444
SETPOINT( Result, ( m_noise.PGNoise3( POINT( p ) ) + 1 ) / 2.0f );
1448
//----------------------------------------------------------------------
1450
STD_SOIMPL CqShaderExecEnv::SO_pnoise4( POINTVAL p, FLOATVAL t, DEFPARAMIMPL )
1452
// TODO: Do proper 4D noise.
1453
STATS_INC( SHD_so_pnoise4 );
1461
BEGIN_VARYING_SECTION
1464
SETPOINT( Result, ( m_noise.PGNoise3( POINT( p ) ) + 1 ) / 2.0f );
1468
//----------------------------------------------------------------------
1469
// setcomp(c,__iGrid,v)
1470
STD_SOIMPL CqShaderExecEnv::SO_setcomp( COLORVAL p, FLOATVAL index, FLOATVAL v, DEFVOIDPARAMIMPL )
1472
STATS_INC( SHD_so_setcomp );
1480
BEGIN_VARYING_SECTION
1484
COLOR( p ) [ FLOAT( index ) ] = FLOAT( v );
1485
SETCOLOR( p, COLOR( p ) );
1489
//----------------------------------------------------------------------
1491
STD_SOIMPL CqShaderExecEnv::SO_setxcomp( POINTVAL p, FLOATVAL v, DEFVOIDPARAMIMPL )
1493
STATS_INC( SHD_so_setxcomp );
1500
BEGIN_VARYING_SECTION
1503
POINT( p ).x( FLOAT( v ) );
1504
SETPOINT( p, POINT( p ) );
1508
//----------------------------------------------------------------------
1510
STD_SOIMPL CqShaderExecEnv::SO_setycomp( POINTVAL p, FLOATVAL v, DEFVOIDPARAMIMPL )
1512
STATS_INC( SHD_so_setycomp );
1519
BEGIN_VARYING_SECTION
1522
POINT( p ).y( FLOAT( v ) );
1523
SETPOINT( p, POINT( p ) );
1527
//----------------------------------------------------------------------
1529
STD_SOIMPL CqShaderExecEnv::SO_setzcomp( POINTVAL p, FLOATVAL v, DEFVOIDPARAMIMPL )
1531
STATS_INC( SHD_so_setzcomp );
1538
BEGIN_VARYING_SECTION
1541
POINT( p ).z( FLOAT( v ) );
1542
SETPOINT( p, POINT( p ) );
1548
STD_SOIMPL CqShaderExecEnv::SO_length( VECTORVAL V, DEFPARAMIMPL )
1550
STATS_INC( SHD_so_length );
1557
BEGIN_VARYING_SECTION
1559
SETFLOAT( Result, VECTOR( V ).Magnitude() );
1563
STD_SOIMPL CqShaderExecEnv::SO_distance( POINTVAL P1, POINTVAL P2, DEFPARAMIMPL )
1565
STATS_INC( SHD_so_distance );
1573
BEGIN_VARYING_SECTION
1576
SETFLOAT( Result, ( POINT( P1 ) - POINT( P2 ) ).Magnitude() );
1581
//----------------------------------------------------------------------
1583
STD_SOIMPL CqShaderExecEnv::SO_area( POINTVAL p, DEFPARAMIMPL )
1585
STATS_INC( SHD_so_area );
1587
CqVector3D Defvec( 0.0f, 0.0f, 0.0f );
1595
BEGIN_VARYING_SECTION
1596
if ( m_pAttributes )
1599
du() ->GetFloat( fdu, __iGrid );
1600
dv() ->GetFloat( fdv, __iGrid );
1601
vecR = ( SO_DuType<CqVector3D>( p, __iGrid, this, Defvec ) * fdu ) %
1602
( SO_DvType<CqVector3D>( p, __iGrid, this, Defvec ) * fdv );
1603
SETFLOAT( Result, vecR.Magnitude() );
1610
STD_SOIMPL CqShaderExecEnv::SO_normalize( VECTORVAL V, DEFPARAMIMPL )
1612
STATS_INC( SHD_so_normalize );
1619
BEGIN_VARYING_SECTION
1622
SETVECTOR( Result, VECTOR( V ) );
1627
//----------------------------------------------------------------------
1629
STD_SOIMPL CqShaderExecEnv::SO_faceforward( NORMALVAL N, VECTORVAL I, DEFPARAMIMPL )
1631
STATS_INC( SHD_so_faceforward );
1639
BEGIN_VARYING_SECTION
1643
Ng() ->GetNormal( Nref, __iGrid );
1644
TqFloat s = ( ( ( -VECTOR( I ) ) * Nref ) < 0.0f ) ? -1.0f : 1.0f;
1645
SETNORMAL( Result, NORMAL( N ) * s );
1650
//----------------------------------------------------------------------
1651
// faceforward(N,I,Nref)
1652
STD_SOIMPL CqShaderExecEnv::SO_faceforward2( NORMALVAL N, VECTORVAL I, NORMALVAL Nref, DEFPARAMIMPL )
1654
STATS_INC( SHD_so_faceforward2 );
1663
BEGIN_VARYING_SECTION
1667
TqFloat s = ( ( ( -VECTOR( I ) ) * NORMAL( Nref ) ) < 0.0f ) ? -1.0f : 1.0f;
1668
SETNORMAL( Result, NORMAL( N ) * s );
1673
//----------------------------------------------------------------------
1675
STD_SOIMPL CqShaderExecEnv::SO_reflect( VECTORVAL I, NORMALVAL N, DEFPARAMIMPL )
1677
STATS_INC( SHD_so_reflect );
1685
BEGIN_VARYING_SECTION
1688
TqFloat idn = 2.0f * ( VECTOR( I ) * NORMAL( N ) );
1689
CqVector3D res = VECTOR( I ) - ( idn * NORMAL( N ) );
1690
SETVECTOR( Result, res );
1695
//----------------------------------------------------------------------
1697
STD_SOIMPL CqShaderExecEnv::SO_refract( VECTORVAL I, NORMALVAL N, FLOATVAL eta, DEFPARAMIMPL )
1699
STATS_INC( SHD_so_refract );
1708
BEGIN_VARYING_SECTION
1712
TqFloat IdotN = VECTOR( I ) * NORMAL( N );
1713
TqFloat feta = FLOAT( eta );
1714
TqFloat k = 1 - feta * feta * ( 1 - IdotN * IdotN );
1715
SETVECTOR( Result, ( k < 0.0f ) ? CqVector3D( 0, 0, 0 ) : CqVector3D( feta * VECTOR( I ) - ( feta * IdotN + sqrt( k ) ) * NORMAL( N ) ) );
1720
//----------------------------------------------------------------------
1721
// fresnel(I,N,eta,Kr,Kt)
1722
#define SQR(A) ((A)*(A))
1723
STD_SOIMPL CqShaderExecEnv::SO_fresnel( VECTORVAL I, NORMALVAL N, FLOATVAL eta, FLOATVAL Kr, FLOATVAL Kt, DEFVOIDPARAMIMPL )
1725
STATS_INC( SHD_so_fresnel );
1735
BEGIN_VARYING_SECTION
1741
TqFloat cos_theta = -VECTOR( I ) * NORMAL( N );
1742
TqFloat fuvA = SQR( 1.0f / FLOAT( eta ) ) - ( 1.0f - SQR( cos_theta ) );
1743
TqFloat fuvB = fabs( fuvA );
1744
TqFloat fu2 = ( fuvA + fuvB ) / 2;
1745
TqFloat fv2 = ( -fuvA + fuvB ) / 2;
1746
TqFloat fv2sqrt = ( fv2 == 0.0f ) ? 0.0f : sqrt( fabs( fv2 ) );
1747
TqFloat fu2sqrt = ( fu2 == 0.0f ) ? 0.0f : sqrt( fabs( fu2 ) );
1748
TqFloat fperp2 = ( SQR( cos_theta - fu2sqrt ) + fv2 ) / ( SQR( cos_theta + fu2sqrt ) + fv2 );
1749
TqFloat feta = FLOAT( eta );
1750
TqFloat fpara2 = ( SQR( SQR( 1.0f / feta ) * cos_theta - fu2sqrt ) + SQR( -fv2sqrt ) ) /
1751
( SQR( SQR( 1.0f / feta ) * cos_theta + fu2sqrt ) + SQR( fv2sqrt ) );
1753
TqFloat __Kr = 0.5f * ( fperp2 + fpara2 );
1754
SETFLOAT( Kr, __Kr );
1755
SETFLOAT( Kt, 1.0f - __Kr );
1759
//----------------------------------------------------------------------
1760
// fresnel(I,N,eta,Kr,Kt,R,T)
1761
STD_SOIMPL CqShaderExecEnv::SO_fresnel( VECTORVAL I, NORMALVAL N, FLOATVAL eta, FLOATVAL Kr, FLOATVAL Kt, VECTORVAL R, VECTORVAL T, DEFVOIDPARAMIMPL )
1763
STATS_INC( SHD_so_fresnel );
1775
BEGIN_VARYING_SECTION
1783
TqFloat cos_theta = -VECTOR( I ) * NORMAL( N );
1784
TqFloat fuvA = SQR( 1.0f / FLOAT( eta ) ) - ( 1.0f - SQR( cos_theta ) );
1785
TqFloat fuvB = fabs( fuvA );
1786
TqFloat fu2 = ( fuvA + fuvB ) / 2;
1787
TqFloat fv2 = ( -fuvA + fuvB ) / 2;
1788
TqFloat feta = FLOAT( eta );
1789
TqFloat fv2sqrt = ( fv2 == 0.0f ) ? 0.0f : sqrt( fabs( fv2 ) );
1790
TqFloat fu2sqrt = ( fu2 == 0.0f ) ? 0.0f : sqrt( fabs( fu2 ) );
1791
TqFloat fperp2 = ( SQR( cos_theta - fu2sqrt ) + fv2 ) / ( SQR( cos_theta + fu2sqrt ) + fv2 );
1792
TqFloat fpara2 = ( SQR( SQR( 1.0f / feta ) * cos_theta - fu2sqrt ) + SQR( -fv2sqrt ) ) /
1793
( SQR( SQR( 1.0f / feta ) * cos_theta + fu2sqrt ) + SQR( fv2sqrt ) );
1794
TqFloat __Kr = 0.5f * ( fperp2 + fpara2 );
1795
SETFLOAT( Kr, __Kr );
1796
SETFLOAT( Kt, 1.0f - __Kr );
1799
SO_reflect( I, N, R );
1800
SO_refract( I, N, eta, T );
1804
//----------------------------------------------------------------------
1806
STD_SOIMPL CqShaderExecEnv::SO_transform( STRINGVAL fromspace, STRINGVAL tospace, POINTVAL p, DEFPARAMIMPL )
1808
STATS_INC( SHD_so_transform );
1812
assert( pShader != 0 );
1817
if ( NULL != QGetRenderContextI() )
1819
BEGIN_UNIFORM_SECTION
1820
GETSTRING( fromspace );
1821
GETSTRING( tospace );
1822
const CqMatrix& mat = QGetRenderContextI() ->matSpaceToSpace( STRING( fromspace ).c_str(), STRING( tospace ).c_str(), pShader->matCurrent(), matObjectToWorld(), QGetRenderContextI()->Time() );
1825
BEGIN_VARYING_SECTION
1827
SETPOINT( Result, mat * POINT( p ) );
1832
BEGIN_VARYING_SECTION
1834
SETPOINT( Result, POINT( p ) );
1840
//----------------------------------------------------------------------
1842
STD_SOIMPL CqShaderExecEnv::SO_transform( STRINGVAL tospace, POINTVAL p, DEFPARAMIMPL )
1844
STATS_INC( SHD_so_transform );
1848
assert( pShader != 0 );
1853
if ( NULL != QGetRenderContextI() )
1855
BEGIN_UNIFORM_SECTION
1856
GETSTRING( tospace );
1857
const CqMatrix& mat = QGetRenderContextI() ->matSpaceToSpace( "current", STRING( tospace ).c_str(), pShader->matCurrent(), matObjectToWorld(), QGetRenderContextI()->Time() );
1860
BEGIN_VARYING_SECTION
1862
SETPOINT( Result, mat * POINT( p ) );
1867
BEGIN_VARYING_SECTION
1869
SETPOINT( Result, POINT( p ) );
1875
//----------------------------------------------------------------------
1877
STD_SOIMPL CqShaderExecEnv::SO_transformm( MATRIXVAL tospace, POINTVAL p, DEFPARAMIMPL )
1879
STATS_INC( SHD_so_transform );
1883
assert( pShader != 0 );
1888
BEGIN_VARYING_SECTION
1889
GETMATRIX( tospace );
1891
SETPOINT( Result, MATRIX( tospace ) * POINT( p ) );
1896
//----------------------------------------------------------------------
1897
// vtransform(s,s,P)
1898
STD_SOIMPL CqShaderExecEnv::SO_vtransform( STRINGVAL fromspace, STRINGVAL tospace, VECTORVAL p, DEFPARAMIMPL )
1900
STATS_INC( SHD_so_vtransform );
1904
assert( pShader != 0 );
1909
if ( NULL != QGetRenderContextI() )
1911
BEGIN_UNIFORM_SECTION
1912
GETSTRING( fromspace );
1913
GETSTRING( tospace );
1914
const CqMatrix& mat = QGetRenderContextI() ->matVSpaceToSpace( STRING( fromspace ).c_str(), STRING( tospace ).c_str(), pShader->matCurrent(), matObjectToWorld(), QGetRenderContextI()->Time() );
1917
BEGIN_VARYING_SECTION
1919
SETVECTOR( Result, mat * VECTOR( p ) );
1924
BEGIN_VARYING_SECTION
1926
SETVECTOR( Result, VECTOR( p ) );
1932
//----------------------------------------------------------------------
1934
STD_SOIMPL CqShaderExecEnv::SO_vtransform( STRINGVAL tospace, VECTORVAL p, DEFPARAMIMPL )
1936
STATS_INC( SHD_so_vtransform );
1940
assert( pShader != 0 );
1945
if ( NULL != QGetRenderContextI() )
1947
BEGIN_UNIFORM_SECTION
1948
GETSTRING( tospace );
1949
const CqMatrix& mat = QGetRenderContextI() ->matVSpaceToSpace( "current", STRING( tospace ).c_str(), pShader->matCurrent(), matObjectToWorld(), QGetRenderContextI()->Time() );
1952
BEGIN_VARYING_SECTION
1954
SETVECTOR( Result, mat * VECTOR( p ) );
1959
BEGIN_VARYING_SECTION
1961
SETVECTOR( Result, VECTOR( p ) );
1967
//----------------------------------------------------------------------
1969
STD_SOIMPL CqShaderExecEnv::SO_vtransformm( MATRIXVAL tospace, VECTORVAL p, DEFPARAMIMPL )
1971
STATS_INC( SHD_so_vtransform );
1975
assert( pShader != 0 );
1980
BEGIN_VARYING_SECTION
1981
GETMATRIX( tospace );
1983
SETVECTOR( Result, MATRIX( tospace ) * VECTOR( p ) );
1988
//----------------------------------------------------------------------
1989
// ntransform(s,s,P)
1990
STD_SOIMPL CqShaderExecEnv::SO_ntransform( STRINGVAL fromspace, STRINGVAL tospace, NORMALVAL p, DEFPARAMIMPL )
1992
STATS_INC( SHD_so_ntransform );
1996
assert( pShader != 0 );
2001
if ( NULL != QGetRenderContextI() )
2003
BEGIN_UNIFORM_SECTION
2004
GETSTRING( fromspace );
2005
GETSTRING( tospace );
2006
const CqMatrix& mat = QGetRenderContextI() ->matNSpaceToSpace( STRING( fromspace ).c_str(), STRING( tospace ).c_str(), pShader->matCurrent(), matObjectToWorld(), QGetRenderContextI()->Time() );
2007
BEGIN_UNIFORM_SECTION
2009
BEGIN_VARYING_SECTION
2011
SETNORMAL( Result, mat * NORMAL( p ) );
2016
BEGIN_VARYING_SECTION
2018
SETNORMAL( Result, NORMAL( p ) );
2024
//----------------------------------------------------------------------
2026
STD_SOIMPL CqShaderExecEnv::SO_ntransform( STRINGVAL tospace, NORMALVAL p, DEFPARAMIMPL )
2028
STATS_INC( SHD_so_ntransform );
2032
assert( pShader != 0 );
2037
if ( NULL != QGetRenderContextI() )
2039
BEGIN_UNIFORM_SECTION
2040
GETSTRING( tospace );
2041
const CqMatrix& mat = QGetRenderContextI() ->matNSpaceToSpace( "current", STRING( tospace ).c_str(), pShader->matCurrent(), matObjectToWorld(), QGetRenderContextI()->Time() );
2042
BEGIN_UNIFORM_SECTION
2044
BEGIN_VARYING_SECTION
2046
SETNORMAL( Result, mat * NORMAL( p ) );
2051
BEGIN_VARYING_SECTION
2053
SETNORMAL( Result, NORMAL( p ) );
2059
//----------------------------------------------------------------------
2061
STD_SOIMPL CqShaderExecEnv::SO_ntransformm( MATRIXVAL tospace, NORMALVAL p, DEFPARAMIMPL )
2063
STATS_INC( SHD_so_ntransform );
2067
assert( pShader != 0 );
2072
BEGIN_VARYING_SECTION
2073
GETMATRIX( tospace );
2075
SETNORMAL( Result, MATRIX( tospace ) * NORMAL( p ) );
2080
//----------------------------------------------------------------------
2082
STD_SOIMPL CqShaderExecEnv::SO_depth( POINTVAL p, DEFPARAMIMPL )
2084
STATS_INC( SHD_so_depth );
2088
if ( NULL == QGetRenderContextI() )
2094
BEGIN_VARYING_SECTION
2096
TqFloat d = POINT( p ).z();
2097
d = ( d - QGetRenderContextI() ->GetFloatOption( "System", "Clipping" ) [ 0 ] ) /
2098
( QGetRenderContextI() ->GetFloatOption( "System", "Clipping" ) [ 1 ] - QGetRenderContextI() ->GetFloatOption( "System", "Clipping" ) [ 0 ] );
2099
SETFLOAT( Result, d );
2104
//----------------------------------------------------------------------
2105
// calculatenormal(P)
2106
STD_SOIMPL CqShaderExecEnv::SO_calculatenormal( POINTVAL p, DEFPARAMIMPL )
2108
STATS_INC( SHD_so_calculatenormal );
2110
CqVector3D Defvec( 0.0f, 0.0f, 0.0f );
2113
// Find out if the orientation is inverted.
2114
TqBool CSO = pTransform()->GetHandedness(QGetRenderContextI()->Time());
2117
TqBool O = pAttributes() ->GetIntegerAttribute( "System", "Orientation" ) [ 0 ] != 0;
2119
if ( O != CSO ) neg = -1;
2124
BEGIN_VARYING_SECTION
2125
//CqVector3D dPdu = SO_DuType<CqVector3D>( p, __iGrid, this, Defvec );
2126
//CqVector3D dPdv = SO_DvType<CqVector3D>( p, __iGrid, this, Defvec );
2127
//CqVector3D N = dPdu % dPdv;
2129
CqVector3D Ret, Ret2;
2130
TqInt uRes = uGridRes();
2131
TqInt GridX = __iGrid % ( uRes + 1 );
2136
p->GetValue( v1, __iGrid + 1 );
2137
p->GetValue( v2, __iGrid );
2142
p->GetValue( v1, __iGrid );
2143
p->GetValue( v2, __iGrid - 1 );
2146
TqInt vRes = vGridRes();
2147
TqInt GridY = ( __iGrid / ( uRes + 1 ) );
2151
p->GetValue( v1, __iGrid + uRes + 1 );
2152
p->GetValue( v2, __iGrid );
2157
p->GetValue( v1, __iGrid );
2158
p->GetValue( v2, __iGrid - ( uRes + 1 ) );
2162
CqVector3D N = Ret % Ret2;
2165
SETNORMAL( Result, N );
2169
STD_SOIMPL CqShaderExecEnv::SO_cmix( COLORVAL color0, COLORVAL color1, FLOATVAL value, DEFPARAMIMPL )
2171
STATS_INC( SHD_so_cmix );
2180
BEGIN_VARYING_SECTION
2184
CqColor c( ( 1.0f - FLOAT( value ) ) * COLOR( color0 ) + FLOAT( value ) * COLOR( color1 ) );
2185
SETCOLOR( Result, c );
2189
STD_SOIMPL CqShaderExecEnv::SO_fmix( FLOATVAL f0, FLOATVAL f1, FLOATVAL value, DEFPARAMIMPL )
2191
STATS_INC( SHD_so_fmix );
2199
BEGIN_VARYING_SECTION
2203
TqFloat f( ( 1.0f - FLOAT( value ) ) * FLOAT( f0 ) + FLOAT( value ) * FLOAT( f1 ) );
2204
SETFLOAT( Result, f );
2208
STD_SOIMPL CqShaderExecEnv::SO_pmix( POINTVAL p0, POINTVAL p1, FLOATVAL value, DEFPARAMIMPL )
2210
STATS_INC( SHD_so_pmix );
2218
BEGIN_VARYING_SECTION
2222
CqVector3D p( ( 1.0f - FLOAT( value ) ) * POINT( p0 ) + FLOAT( value ) * POINT( p1 ) );
2223
SETPOINT( Result, p );
2227
STD_SOIMPL CqShaderExecEnv::SO_vmix( VECTORVAL v0, VECTORVAL v1, FLOATVAL value, DEFPARAMIMPL )
2229
STATS_INC( SHD_so_vmix );
2237
BEGIN_VARYING_SECTION
2241
CqVector3D v( ( 1.0f - FLOAT( value ) ) * VECTOR( v0 ) + FLOAT( value ) * VECTOR( v1 ) );
2242
SETVECTOR( Result, v );
2246
STD_SOIMPL CqShaderExecEnv::SO_nmix( NORMALVAL n0, NORMALVAL n1, FLOATVAL value, DEFPARAMIMPL )
2254
BEGIN_VARYING_SECTION
2258
CqVector3D n( ( 1.0f - FLOAT( value ) ) * NORMAL( n0 ) + FLOAT( value ) * NORMAL( n1 ) );
2259
SETNORMAL( Result, n );
2264
//----------------------------------------------------------------------
2266
STD_SOIMPL CqShaderExecEnv::SO_ftexture1( STRINGVAL name, FLOATVAL channel, DEFPARAMVARIMPL )
2268
STATS_INC( SHD_so_ftexture1 );
2270
TqFloat Deffloat = 0.0f;
2273
if ( NULL == QGetRenderContextI() )
2278
TqFloat fill = 0.0f;
2279
if ( paramMap.find( "fill" ) != paramMap.end() )
2280
paramMap[ "fill" ] ->GetFloat( fill );
2282
BEGIN_UNIFORM_SECTION
2284
GETFLOAT( channel );
2285
IqTextureMap* pTMap = QGetRenderContextI() ->GetTextureMap( STRING( name ) );
2286
TqFloat fdu = 0.0f, fdv = 0.0f;
2287
if ( m_pAttributes )
2289
du() ->GetFloat( fdu );
2290
dv() ->GetFloat( fdv );
2295
__fVarying = TqTrue;
2296
if ( pTMap != 0 && pTMap->IsValid() )
2298
std::valarray<TqFloat> val;
2299
pTMap->PrepareSampleOptions( paramMap );
2301
BEGIN_VARYING_SECTION
2302
TqFloat swidth = 0.0f, twidth = 0.0f;
2303
if ( fdu != 0.0f && fdv != 0.0f )
2305
TqFloat dsdu = SO_DuType<TqFloat>( s(), __iGrid, this, Deffloat );
2306
swidth = fabs( dsdu * fdu );
2307
TqFloat dtdu = SO_DuType<TqFloat>( t(), __iGrid, this, Deffloat );
2308
twidth = fabs( dtdu * fdu );
2310
TqFloat dsdv = SO_DvType<TqFloat>( s(), __iGrid, this, Deffloat );
2311
swidth += fabs( dsdv * fdv );
2312
TqFloat dtdv = SO_DvType<TqFloat>( t(), __iGrid, this, Deffloat );
2313
twidth += fabs( dtdv * fdv );
2317
swidth = 1.0 / pTMap->XRes();
2318
twidth = 1.0 / pTMap->YRes();
2321
// Sample the texture.
2323
s() ->GetFloat( fs, __iGrid );
2324
t() ->GetFloat( ft, __iGrid );
2325
pTMap->SampleMap( fs, ft, swidth, twidth, val );
2327
// Grab the appropriate channel.
2328
TqFloat fchan = FLOAT( channel );
2329
if ( fchan >= val.size() )
2330
SETFLOAT( Result, fill );
2332
SETFLOAT( Result, val[ static_cast<unsigned int>( fchan ) ] );
2337
BEGIN_VARYING_SECTION
2338
SETFLOAT( Result, 0.0f );
2343
//----------------------------------------------------------------------
2345
STD_SOIMPL CqShaderExecEnv::SO_ftexture2( STRINGVAL name, FLOATVAL channel, FLOATVAL s, FLOATVAL t, DEFPARAMVARIMPL )
2347
STATS_INC( SHD_so_ftexture2 );
2349
TqFloat Deffloat = 0.0f;
2352
if ( NULL == QGetRenderContextI() )
2357
TqFloat fill = 0.0f;
2358
if ( paramMap.find( "fill" ) != paramMap.end() )
2359
paramMap[ "fill" ] ->GetFloat( fill );
2361
BEGIN_UNIFORM_SECTION
2363
GETFLOAT( channel );
2364
IqTextureMap* pTMap = QGetRenderContextI() ->GetTextureMap( STRING( name ) );
2365
TqFloat fdu = 0.0f, fdv = 0.0f;
2366
if ( m_pAttributes )
2368
du() ->GetFloat( fdu );
2369
dv() ->GetFloat( fdv );
2374
__fVarying = TqTrue;
2375
if ( pTMap != 0 && pTMap->IsValid() )
2377
std::valarray<TqFloat> val;
2378
pTMap->PrepareSampleOptions( paramMap );
2380
BEGIN_VARYING_SECTION
2381
TqFloat swidth = 0.0f, twidth = 0.0f;
2382
if ( fdu != 0.0f && fdv != 0.0f )
2384
TqFloat dsdu = SO_DuType<TqFloat>( s, __iGrid, this, Deffloat );
2385
swidth = fabs( dsdu * fdu );
2386
TqFloat dtdu = SO_DuType<TqFloat>( t, __iGrid, this, Deffloat );
2387
twidth = fabs( dtdu * fdu );
2389
TqFloat dsdv = SO_DvType<TqFloat>( s, __iGrid, this, Deffloat );
2390
swidth += fabs( dsdv * fdv );
2391
TqFloat dtdv = SO_DvType<TqFloat>( t, __iGrid, this, Deffloat );
2392
twidth += fabs( dtdv * fdv );
2396
swidth = 1.0 / pTMap->XRes();
2397
twidth = 1.0 / pTMap->YRes();
2400
// Sample the texture.
2403
pTMap->SampleMap( FLOAT( s ), FLOAT( t ), swidth, twidth, val );
2405
// Grab the appropriate channel.
2406
TqFloat fchan = FLOAT( channel );
2407
if ( fchan >= val.size() )
2408
SETFLOAT( Result, fill );
2410
SETFLOAT( Result, val[ static_cast<unsigned int>( fchan ) ] );
2415
BEGIN_VARYING_SECTION
2416
SETFLOAT( Result, 0.0f ); // Default, completely lit
2421
//----------------------------------------------------------------------
2422
// texture(S,F,F,F,F,F,F,F,F)
2423
STD_SOIMPL CqShaderExecEnv::SO_ftexture3( STRINGVAL name, FLOATVAL channel, FLOATVAL s1, FLOATVAL t1, FLOATVAL s2, FLOATVAL t2, FLOATVAL s3, FLOATVAL t3, FLOATVAL s4, FLOATVAL t4, DEFPARAMVARIMPL )
2425
STATS_INC( SHD_so_ftexture3 );
2429
if ( NULL == QGetRenderContextI() )
2434
TqFloat fill = 0.0f;
2435
if ( paramMap.find( "fill" ) != paramMap.end() )
2436
paramMap[ "fill" ] ->GetFloat( fill );
2438
BEGIN_UNIFORM_SECTION
2440
GETFLOAT( channel );
2441
IqTextureMap* pTMap = QGetRenderContextI() ->GetTextureMap( STRING( name ) );
2445
__fVarying = TqTrue;
2446
if ( pTMap != 0 && pTMap->IsValid() )
2448
std::valarray<TqFloat> val;
2449
pTMap->PrepareSampleOptions( paramMap );
2451
BEGIN_VARYING_SECTION
2453
// Sample the texture.
2462
pTMap->SampleMap( FLOAT( s1 ), FLOAT( t1 ), FLOAT( s2 ), FLOAT( t2 ), FLOAT( s3 ), FLOAT( t3 ), FLOAT( s4 ), FLOAT( t4 ), val );
2464
// Grab the appropriate channel.
2465
TqFloat fchan = FLOAT( channel );
2466
if ( fchan >= val.size() )
2467
SETFLOAT( Result, fill );
2469
SETFLOAT( Result, val[ static_cast<unsigned int>( fchan ) ] );
2474
BEGIN_VARYING_SECTION
2475
SETFLOAT( Result, 0.0f ); // Default, completely lit
2480
//----------------------------------------------------------------------
2482
STD_SOIMPL CqShaderExecEnv::SO_ctexture1( STRINGVAL name, FLOATVAL channel, DEFPARAMVARIMPL )
2484
STATS_INC( SHD_so_ctexture1 );
2486
TqFloat Deffloat = 0.0f;
2489
if ( NULL == QGetRenderContextI() )
2494
TqFloat fill = 0.0f;
2495
if ( paramMap.find( "fill" ) != paramMap.end() )
2496
paramMap[ "fill" ] ->GetFloat( fill );
2498
BEGIN_UNIFORM_SECTION
2500
GETFLOAT( channel );
2501
IqTextureMap* pTMap = QGetRenderContextI() ->GetTextureMap( STRING( name ) );
2502
TqFloat fdu = 0.0f, fdv = 0.0f;
2503
if ( m_pAttributes )
2505
du() ->GetFloat( fdu );
2506
dv() ->GetFloat( fdv );
2511
__fVarying = TqTrue;
2512
if ( pTMap != 0 && pTMap->IsValid() )
2514
std::valarray<TqFloat> val;
2515
pTMap->PrepareSampleOptions( paramMap );
2517
BEGIN_VARYING_SECTION
2518
TqFloat swidth = 0.0f, twidth = 0.0f;
2519
if ( fdu != 0.0f && fdv != 0.0f )
2521
TqFloat dsdu = SO_DuType<TqFloat>( s(), __iGrid, this, Deffloat );
2522
swidth = fabs( dsdu * fdu );
2523
TqFloat dsdv = SO_DvType<TqFloat>( s(), __iGrid, this, Deffloat );
2524
swidth += fabs( dsdv * fdv );
2526
TqFloat dtdu = SO_DuType<TqFloat>( t(), __iGrid, this, Deffloat );
2527
twidth = fabs( dtdu * fdu );
2528
TqFloat dtdv = SO_DvType<TqFloat>( t(), __iGrid, this, Deffloat );
2529
twidth += fabs( dtdv * fdv );
2533
swidth = 1.0 / pTMap->XRes();
2534
twidth = 1.0 / pTMap->YRes();
2537
// Sample the texture.
2539
s() ->GetFloat( fs, __iGrid );
2540
t() ->GetFloat( ft, __iGrid );
2541
pTMap->SampleMap( fs, ft, swidth, twidth, val );
2543
// Grab the appropriate channel.
2544
TqFloat fchan = FLOAT( channel );
2545
if ( fchan + 2 >= val.size() )
2546
SETCOLOR( Result, CqColor( fill, fill, fill ) );
2548
SETCOLOR( Result, CqColor( val[ static_cast<unsigned int>( fchan ) ], val[ static_cast<unsigned int>( fchan ) + 1 ], val[ static_cast<unsigned int>( fchan ) + 2 ] ) );
2553
BEGIN_VARYING_SECTION
2554
SETCOLOR( Result, CqColor( 0, 0, 0 ) ); // Default, no color
2559
//----------------------------------------------------------------------
2561
STD_SOIMPL CqShaderExecEnv::SO_ctexture2( STRINGVAL name, FLOATVAL channel, FLOATVAL s, FLOATVAL t, DEFPARAMVARIMPL )
2563
STATS_INC( SHD_so_ctexture2 );
2565
TqFloat Deffloat = 0.0f;
2568
if ( NULL == QGetRenderContextI() )
2573
TqFloat fill = 0.0f;
2574
if ( paramMap.find( "fill" ) != paramMap.end() )
2575
paramMap[ "fill" ] ->GetFloat( fill );
2577
BEGIN_UNIFORM_SECTION
2579
GETFLOAT( channel );
2580
IqTextureMap* pTMap = QGetRenderContextI() ->GetTextureMap( STRING( name ) );
2581
TqFloat fdu = 0.0f, fdv = 0.0f;
2582
if ( m_pAttributes )
2584
du() ->GetFloat( fdu );
2585
dv() ->GetFloat( fdv );
2590
__fVarying = TqTrue;
2591
if ( pTMap != 0 && pTMap->IsValid() )
2593
std::valarray<TqFloat> val;
2594
pTMap->PrepareSampleOptions( paramMap );
2596
BEGIN_VARYING_SECTION
2597
TqFloat swidth = 0.0f, twidth = 0.0f;
2598
if ( fdu != 0.0f && fdv != 0.0f )
2600
TqFloat dsdu = SO_DuType<TqFloat>( s, __iGrid, this, Deffloat );
2601
swidth = fabs( dsdu * fdu );
2602
TqFloat dsdv = SO_DvType<TqFloat>( s, __iGrid, this, Deffloat );
2603
swidth += fabs( dsdv * fdv );
2605
TqFloat dtdu = SO_DuType<TqFloat>( t, __iGrid, this, Deffloat );
2606
twidth = fabs( dtdu * fdu );
2607
TqFloat dtdv = SO_DvType<TqFloat>( t, __iGrid, this, Deffloat );
2608
twidth += fabs( dtdv * fdv );
2612
swidth = 1.0 / pTMap->XRes();
2613
twidth = 1.0 / pTMap->YRes();
2616
// Sample the texture.
2619
pTMap->SampleMap( FLOAT( s ), FLOAT( t ), swidth, twidth, val );
2621
// Grab the appropriate channel.
2622
TqFloat fchan = FLOAT( channel );
2623
if ( fchan + 2 >= val.size() )
2624
SETCOLOR( Result, CqColor( fill, fill, fill ) );
2626
SETCOLOR( Result, CqColor( val[ static_cast<unsigned int>( fchan ) ], val[ static_cast<unsigned int>( fchan ) + 1 ], val[ static_cast<unsigned int>( fchan ) + 2 ] ) );
2631
BEGIN_VARYING_SECTION
2632
SETCOLOR( Result, CqColor( 0, 0, 0 ) ); // Default, completely lit
2637
//----------------------------------------------------------------------
2638
// texture(S,F,F,F,F,F,F,F,F)
2639
STD_SOIMPL CqShaderExecEnv::SO_ctexture3( STRINGVAL name, FLOATVAL channel, FLOATVAL s1, FLOATVAL t1, FLOATVAL s2, FLOATVAL t2, FLOATVAL s3, FLOATVAL t3, FLOATVAL s4, FLOATVAL t4, DEFPARAMVARIMPL )
2641
STATS_INC( SHD_so_ctexture3 );
2645
if ( NULL == QGetRenderContextI() )
2650
TqFloat fill = 0.0f;
2651
if ( paramMap.find( "fill" ) != paramMap.end() )
2652
paramMap[ "fill" ] ->GetFloat( fill );
2654
BEGIN_UNIFORM_SECTION
2656
GETFLOAT( channel );
2657
IqTextureMap* pTMap = QGetRenderContextI() ->GetTextureMap( STRING( name ) );
2661
__fVarying = TqTrue;
2662
if ( pTMap != 0 && pTMap->IsValid() )
2664
std::valarray<TqFloat> val;
2665
pTMap->PrepareSampleOptions( paramMap );
2667
BEGIN_VARYING_SECTION
2668
// Sample the texture.
2677
pTMap->SampleMap( FLOAT( s1 ), FLOAT( t1 ), FLOAT( s2 ), FLOAT( t2 ), FLOAT( s3 ), FLOAT( t3 ), FLOAT( s4 ), FLOAT( t4 ), val );
2679
// Grab the appropriate channel.
2680
TqFloat fchan = FLOAT( channel );
2681
if ( fchan + 2 >= val.size() )
2682
SETCOLOR( Result, CqColor( fill, fill, fill ) );
2684
SETCOLOR( Result, CqColor( val[ static_cast<unsigned int>( fchan ) ], val[ static_cast<unsigned int>( fchan ) + 1 ], val[ static_cast<unsigned int>( fchan ) + 2 ] ) );
2689
BEGIN_VARYING_SECTION
2690
SETCOLOR( Result, CqColor( 0, 0, 0 ) ); // Default, completely lit
2696
//----------------------------------------------------------------------
2698
STD_SOIMPL CqShaderExecEnv::SO_fenvironment2( STRINGVAL name, FLOATVAL channel, VECTORVAL R, DEFPARAMVARIMPL )
2700
STATS_INC( SHD_so_fenvironment2 );
2702
CqVector3D Defvec( 0.0f, 0.0f, 0.0f );
2705
if ( NULL == QGetRenderContextI() )
2710
TqFloat fill = 0.0f;
2711
if ( paramMap.find( "fill" ) != paramMap.end() )
2712
paramMap[ "fill" ] ->GetFloat( fill );
2714
BEGIN_UNIFORM_SECTION
2716
GETFLOAT( channel );
2717
IqTextureMap* pTMap = QGetRenderContextI() ->GetEnvironmentMap( STRING( name ) );
2719
// Try with LatLong map file
2722
pTMap = QGetRenderContextI() ->GetLatLongMap( STRING( name ) );
2724
TqFloat fdu = 0.0f, fdv = 0.0f;
2725
if ( m_pAttributes )
2727
du() ->GetFloat( fdu );
2728
dv() ->GetFloat( fdv );
2732
__fVarying = TqTrue;
2733
if ( pTMap != 0 && pTMap->IsValid() )
2735
pTMap->PrepareSampleOptions( paramMap );
2736
std::valarray<TqFloat> val;
2738
BEGIN_VARYING_SECTION
2739
CqVector3D swidth = 0.0f, twidth = 0.0f;
2742
CqVector3D dRdu = SO_DuType<CqVector3D>( R, __iGrid, this, Defvec );
2743
swidth = dRdu * fdu;
2747
CqVector3D dRdv = SO_DvType<CqVector3D>( R, __iGrid, this, Defvec );
2748
twidth = dRdv * fdv;
2752
swidth = CqVector3D( 1.0 / pTMap->XRes() );
2753
twidth = CqVector3D( 1.0 / pTMap->YRes() );
2756
// Sample the texture.
2758
pTMap->SampleMap( VECTOR( R ), swidth, twidth, val );
2760
// Grab the appropriate channel.
2761
TqFloat fchan = FLOAT( channel );
2762
if ( fchan >= val.size() )
2763
SETFLOAT( Result, fill );
2765
SETFLOAT( Result, val[ static_cast<unsigned int>( fchan ) ] );
2770
BEGIN_VARYING_SECTION
2771
SETFLOAT( Result, 0.0f ); // Default, completely lit
2776
//----------------------------------------------------------------------
2777
// environment(S,P,P,P,P)
2778
STD_SOIMPL CqShaderExecEnv::SO_fenvironment3( STRINGVAL name, FLOATVAL channel, VECTORVAL R1, VECTORVAL R2, VECTORVAL R3, VECTORVAL R4, DEFPARAMVARIMPL )
2780
STATS_INC( SHD_so_fenvironment3 );
2784
if ( NULL == QGetRenderContextI() )
2789
TqFloat fill = 0.0f;
2790
if ( paramMap.find( "fill" ) != paramMap.end() )
2791
paramMap[ "fill" ] ->GetFloat( fill );
2793
BEGIN_UNIFORM_SECTION
2795
GETFLOAT( channel );
2796
IqTextureMap* pTMap = QGetRenderContextI() ->GetEnvironmentMap( STRING( name ) );
2797
// Try with LatLong map file
2800
pTMap = QGetRenderContextI() ->GetLatLongMap( STRING( name ) );
2804
__fVarying = TqTrue;
2805
if ( pTMap != 0 && pTMap->IsValid() )
2807
std::valarray<TqFloat> val;
2808
pTMap->PrepareSampleOptions( paramMap );
2810
BEGIN_VARYING_SECTION
2811
// Sample the texture.
2816
pTMap->SampleMap( VECTOR( R1 ), VECTOR( R2 ), VECTOR( R3 ), VECTOR( R4 ), val );
2818
// Grab the appropriate channel.
2819
TqFloat fchan = FLOAT( channel );
2820
if ( fchan >= val.size() )
2821
SETFLOAT( Result, fill );
2823
SETFLOAT( Result, val[ static_cast<unsigned int>( fchan ) ] );
2828
BEGIN_VARYING_SECTION
2829
SETFLOAT( Result, 0.0f ); // Default, completely lit
2835
//----------------------------------------------------------------------
2837
STD_SOIMPL CqShaderExecEnv::SO_cenvironment2( STRINGVAL name, FLOATVAL channel, VECTORVAL R, DEFPARAMVARIMPL )
2839
STATS_INC( SHD_so_cenvironment2 );
2841
CqVector3D Defvec( 0.0f, 0.0f, 0.0f );
2844
if ( NULL == QGetRenderContextI() )
2849
TqFloat fill = 0.0f;
2850
if ( paramMap.find( "fill" ) != paramMap.end() )
2851
paramMap[ "fill" ] ->GetFloat( fill );
2853
BEGIN_UNIFORM_SECTION
2855
GETFLOAT( channel );
2856
IqTextureMap* pTMap = QGetRenderContextI() ->GetEnvironmentMap( STRING( name ) );
2857
// Try with LatLong map file
2860
pTMap = QGetRenderContextI() ->GetLatLongMap( STRING( name ) );
2862
TqFloat fdu = 0.0f, fdv = 0.0f;
2863
if ( m_pAttributes )
2865
du() ->GetFloat( fdu );
2866
dv() ->GetFloat( fdv );
2870
__fVarying = TqTrue;
2871
if ( pTMap != 0 && pTMap->IsValid() )
2873
std::valarray<TqFloat> val;
2874
pTMap->PrepareSampleOptions( paramMap );
2876
BEGIN_VARYING_SECTION
2877
CqVector3D swidth = 0.0f, twidth = 0.0f;
2880
CqVector3D dRdu = SO_DuType<CqVector3D>( R, __iGrid, this, Defvec );
2881
swidth = dRdu * fdu;
2885
CqVector3D dRdv = SO_DvType<CqVector3D>( R, __iGrid, this, Defvec );
2886
twidth = dRdv * fdv;
2890
swidth = CqVector3D( 1.0 / pTMap->XRes() );
2891
twidth = CqVector3D( 1.0 / pTMap->YRes() );
2894
// Sample the texture.
2896
pTMap->SampleMap( VECTOR( R ), swidth, twidth, val );
2899
// Grab the appropriate channel.
2900
TqFloat fchan = FLOAT( channel );
2901
if ( fchan + 2 >= val.size() )
2902
SETCOLOR( Result, CqColor( fill, fill, fill ) );
2904
SETCOLOR( Result, CqColor( val[ static_cast<unsigned int>( fchan ) ], val[ static_cast<unsigned int>( fchan ) + 1 ], val[ static_cast<unsigned int>( fchan ) + 2 ] ) );
2909
BEGIN_VARYING_SECTION
2910
SETCOLOR( Result, CqColor( 0.0f, 0.0f, 0.0f ) ); // Default, completely lit
2915
//----------------------------------------------------------------------
2916
// environment(S,P,P,P,P)
2917
STD_SOIMPL CqShaderExecEnv::SO_cenvironment3( STRINGVAL name, FLOATVAL channel, VECTORVAL R1, VECTORVAL R2, VECTORVAL R3, VECTORVAL R4, DEFPARAMVARIMPL )
2919
STATS_INC( SHD_so_cenvironment3 );
2923
if ( NULL == QGetRenderContextI() )
2928
TqFloat fill = 0.0f;
2929
if ( paramMap.find( "fill" ) != paramMap.end() )
2930
paramMap[ "fill" ] ->GetFloat( fill );
2932
BEGIN_UNIFORM_SECTION
2934
GETFLOAT( channel );
2935
IqTextureMap* pTMap = QGetRenderContextI() ->GetEnvironmentMap( STRING( name ) );
2936
// Try with LatLong map file
2939
pTMap = QGetRenderContextI() ->GetLatLongMap( STRING( name ) );
2941
BEGIN_UNIFORM_SECTION
2943
__fVarying = TqTrue;
2944
if ( pTMap != 0 && pTMap->IsValid() )
2946
std::valarray<TqFloat> val;
2947
pTMap->PrepareSampleOptions( paramMap );
2949
BEGIN_VARYING_SECTION
2950
// Sample the texture.
2955
pTMap->SampleMap( VECTOR( R1 ), VECTOR( R2 ), VECTOR( R3 ), VECTOR( R4 ), val );
2957
// Grab the appropriate channel.
2958
TqFloat fchan = FLOAT( channel );
2959
if ( fchan + 2 >= val.size() )
2960
SETCOLOR( Result, CqColor( fill, fill, fill ) );
2962
SETCOLOR( Result, CqColor( val[ static_cast<unsigned int>( fchan ) ], val[ static_cast<unsigned int>( fchan ) + 1 ], val[ static_cast<unsigned int>( fchan ) + 2 ] ) );
2967
BEGIN_VARYING_SECTION
2968
SETCOLOR( Result, CqColor( 0.0f, 0.0f, 0.0f ) ); // Default, completely lit
2973
//----------------------------------------------------------------------
2975
STD_SOIMPL CqShaderExecEnv::SO_bump1( STRINGVAL name, FLOATVAL channel, DEFPARAMVARIMPL )
2979
__fVarying = TqTrue;
2981
BEGIN_VARYING_SECTION
2982
SETPOINT( Result, CqVector3D( 0, 0, 0 ) );
2986
//----------------------------------------------------------------------
2988
STD_SOIMPL CqShaderExecEnv::SO_bump2( STRINGVAL name, FLOATVAL channel, FLOATVAL s, FLOATVAL t, DEFPARAMVARIMPL )
2992
__fVarying = TqTrue;
2994
BEGIN_VARYING_SECTION
2995
SETPOINT( Result, CqVector3D( 0, 0, 0 ) );
2999
//----------------------------------------------------------------------
3000
// bump(S,F,F,F,F,F,F,F,F)
3001
STD_SOIMPL CqShaderExecEnv::SO_bump3( STRINGVAL name, FLOATVAL channel, FLOATVAL s1, FLOATVAL t1, FLOATVAL s2, FLOATVAL t2, FLOATVAL s3, FLOATVAL t3, FLOATVAL s4, FLOATVAL t4, DEFPARAMVARIMPL )
3005
__fVarying = TqTrue;
3007
BEGIN_VARYING_SECTION
3008
SETPOINT( Result, CqVector3D( 0, 0, 0 ) );
3012
//----------------------------------------------------------------------
3014
STD_SOIMPL CqShaderExecEnv::SO_shadow( STRINGVAL name, FLOATVAL channel, POINTVAL P, DEFPARAMVARIMPL )
3016
STATS_INC( SHD_so_shadow );
3020
if ( NULL == QGetRenderContextI() )
3025
BEGIN_UNIFORM_SECTION
3027
GETFLOAT( channel );
3028
IqTextureMap* pMap = QGetRenderContextI() ->GetShadowMap( STRING( name ) );
3031
__fVarying = TqTrue;
3032
if ( pMap != 0 && pMap->IsValid() )
3034
std::valarray<TqFloat> fv;
3035
pMap->PrepareSampleOptions( paramMap );
3037
BEGIN_VARYING_SECTION
3038
CqVector3D swidth = 0.0f, twidth = 0.0f, nullv = 0.0f;
3040
swidth = SO_DerivType<CqVector3D>( P, NULL, __iGrid, this );
3041
twidth = SO_DerivType<CqVector3D>( P, NULL, __iGrid, this );
3045
pMap->SampleMap( POINT( P ), swidth, twidth, fv, 0 );
3046
pMap->PrepareSampleOptions( paramMap );
3047
SETFLOAT( Result, fv[ 0 ] );
3052
BEGIN_VARYING_SECTION
3053
SETFLOAT( Result, 0.0f ); // Default, completely lit
3058
//----------------------------------------------------------------------
3059
// shadow(S,P,P,P,P)
3061
STD_SOIMPL CqShaderExecEnv::SO_shadow1( STRINGVAL name, FLOATVAL channel, POINTVAL P1, POINTVAL P2, POINTVAL P3, POINTVAL P4, DEFPARAMVARIMPL )
3063
STATS_INC( SHD_so_shadow1 );
3067
if ( NULL == QGetRenderContextI() )
3072
BEGIN_UNIFORM_SECTION
3074
GETFLOAT( channel );
3075
IqTextureMap* pMap = QGetRenderContextI() ->GetShadowMap( STRING( name ) );
3078
__fVarying = TqTrue;
3079
if ( pMap != 0 && pMap->IsValid() )
3081
std::valarray<TqFloat> fv;
3082
pMap->PrepareSampleOptions( paramMap );
3084
BEGIN_VARYING_SECTION
3089
pMap->SampleMap( POINT( P1 ), POINT( P2 ), POINT( P3 ), POINT( P4 ), fv, 0 );
3090
SETFLOAT( Result, fv[ 0 ] );
3095
BEGIN_VARYING_SECTION
3096
SETFLOAT( Result, 0.0f ); // Default, completely lit
3102
//----------------------------------------------------------------------
3105
STD_SOIMPL CqShaderExecEnv::SO_ambient( DEFPARAMIMPL )
3107
STATS_INC( SHD_so_ambient );
3111
// Use the lightsource stack on the current surface
3112
if ( m_pAttributes != 0 )
3114
// If this is the first call to illuminance this time round, call all lights and setup the Cl and L caches.
3115
if ( !m_IlluminanceCacheValid )
3117
ValidateIlluminanceCache( NULL, NULL, pShader );
3120
Result->SetColor( gColBlack );
3122
for ( TqUint light_index = 0; light_index < m_pAttributes ->cLights(); light_index++ )
3124
__fVarying = TqTrue;
3126
IqLightsource* lp = m_pAttributes ->pLight( light_index );
3127
if ( lp->pShader() ->fAmbient() )
3129
BEGIN_VARYING_SECTION
3130
// Now Combine the color of all ambient lightsources.
3133
if ( NULL != lp->Cl() )
3134
lp->Cl() ->GetColor( colCl, __iGrid );
3135
SETCOLOR( Result, COLOR( Result ) + colCl );
3144
//----------------------------------------------------------------------
3146
STD_SOIMPL CqShaderExecEnv::SO_diffuse( NORMALVAL N, DEFPARAMIMPL )
3148
STATS_INC( SHD_so_diffuse );
3152
// If the illuminance cache is already OK, then we don't need to bother filling in the illuminance parameters.
3153
if ( !m_IlluminanceCacheValid )
3155
ValidateIlluminanceCache( NULL, N, pShader );
3158
IqShaderData* pDefAngle = pShader->CreateTemporaryStorage( type_float, class_uniform );
3159
if ( NULL == pDefAngle ) return ;
3161
pDefAngle->SetFloat( PIO2 );
3163
Result->SetColor( gColBlack );
3165
__fVarying = TqTrue;
3166
IqShaderData* __nondiffuse = NULL;
3167
__nondiffuse = pShader->CreateTemporaryStorage( type_float, class_varying );
3169
// SO_init_illuminance returns TRUE if there are any non ambient ligthsources available.
3170
if ( SO_init_illuminance() )
3172
IqShader * pLightsource = 0;
3175
// Get the "__nondiffuse" setting from the current lightsource, if specified.
3176
TqFloat __nondiffuse_val;
3177
if ( m_li < m_pAttributes ->cLights() )
3178
pLightsource = m_pAttributes ->pLight( m_li ) ->pShader();
3181
pLightsource->GetValue( "__nondiffuse", __nondiffuse );
3182
/// \note: This is OK here, outside the BEGIN_VARYING_SECTION as, varying in terms of lightsources
3184
if( NULL != __nondiffuse )
3186
__nondiffuse->GetFloat( __nondiffuse_val, 0 );
3187
if( __nondiffuse_val != 0.0f )
3192
// SO_illuminance sets the current state to whether the lightsource illuminates the points or not.
3193
SO_illuminance( NULL, NULL, N, pDefAngle, NULL );
3198
BEGIN_VARYING_SECTION
3200
// Get the light vector and color from the lightsource.
3202
L() ->GetVector( Ln, __iGrid );
3205
// Combine the light color into the result
3209
Cl() ->GetColor( colCl, __iGrid );
3210
SETCOLOR( Result, COLOR( Result ) + colCl * ( Ln * NORMAL( N ) ) );
3214
// SO_advance_illuminance returns TRUE if there are any more non ambient lightsources.
3216
while ( SO_advance_illuminance() );
3218
pShader->DeleteTemporaryStorage( __nondiffuse );
3219
pShader->DeleteTemporaryStorage( pDefAngle );
3223
//----------------------------------------------------------------------
3224
// specular(N,V,roughness)
3225
STD_SOIMPL CqShaderExecEnv::SO_specular( NORMALVAL N, VECTORVAL V, FLOATVAL roughness, DEFPARAMIMPL )
3227
STATS_INC( SHD_so_specular );
3231
// If the illuminance cache is already OK, then we don't need to bother filling in the illuminance parameters.
3232
if ( !m_IlluminanceCacheValid )
3234
ValidateIlluminanceCache( NULL, N, pShader );
3237
IqShaderData* pDefAngle = pShader->CreateTemporaryStorage( type_float, class_uniform );
3238
if ( NULL == pDefAngle ) return ;
3240
pDefAngle->SetFloat( PIO2 );
3242
Result->SetColor( gColBlack );
3243
__fVarying = TqTrue;
3245
IqShaderData* __nonspecular = NULL;
3246
__nonspecular = pShader->CreateTemporaryStorage( type_float, class_varying );
3248
// SO_init_illuminance returns TRUE if there are any non ambient ligthsources available.
3249
if ( SO_init_illuminance() )
3251
IqShader * pLightsource = 0;
3254
// Get the "__nonspecular" setting from the current lightsource, if specified.
3255
TqFloat __nonspecular_val;
3256
if ( m_li < m_pAttributes ->cLights() )
3257
pLightsource = m_pAttributes ->pLight( m_li ) ->pShader();
3260
pLightsource->GetValue( "__nonspecular", __nonspecular );
3261
/// \note: This is OK here, outside the BEGIN_VARYING_SECTION as, varying in terms of lightsources
3263
if( NULL != __nonspecular )
3265
__nonspecular->GetFloat( __nonspecular_val, 0 );
3266
if( __nonspecular_val != 0.0f )
3271
// SO_illuminance sets the current state to whether the lightsource illuminates the points or not.
3272
SO_illuminance( NULL, NULL, N, pDefAngle, NULL );
3276
BEGIN_VARYING_SECTION
3279
// Get the ligth vector and color from the lightsource
3281
L() ->GetVector( Ln, __iGrid );
3283
CqVector3D H = Ln + VECTOR( V );
3286
// Combine the color into the result.
3287
/// \note The (roughness/8) term emulates the BMRT behaviour for prmanspecular.
3290
GETFLOAT( roughness );
3292
Cl() ->GetColor( colCl, __iGrid );
3293
SETCOLOR( Result, COLOR( Result ) + colCl * pow( MAX( 0.0f, NORMAL( N ) * H ), 1.0f / ( FLOAT( roughness ) / 8.0f ) ) );
3297
// SO_advance_illuminance returns TRUE if there are any more non ambient lightsources.
3299
while ( SO_advance_illuminance() );
3301
pShader->DeleteTemporaryStorage( __nonspecular );
3302
pShader->DeleteTemporaryStorage( pDefAngle );
3306
//----------------------------------------------------------------------
3308
STD_SOIMPL CqShaderExecEnv::SO_phong( NORMALVAL N, VECTORVAL V, FLOATVAL size, DEFPARAMIMPL )
3310
STATS_INC( SHD_so_phong );
3314
IqShaderData * pnV = pShader ->CreateTemporaryStorage( type_vector, class_varying );
3315
IqShaderData* pnN = pShader ->CreateTemporaryStorage( type_normal, class_varying );
3316
IqShaderData* pR = pShader ->CreateTemporaryStorage( type_vector, class_varying );
3318
/// note: Not happy about this, the shader should take care of this at construction time,
3319
/// but at the moment, it can't guarantee the validity of the m_u/vGridRes data members.
3320
pnV->Initialise( uGridRes(), vGridRes() );
3321
pnN->Initialise( uGridRes(), vGridRes() );
3322
pR->Initialise( uGridRes(), vGridRes() );
3324
SO_normalize( V, pnV );
3325
SO_normalize( N, pnN );
3327
__fVarying = TqTrue;
3328
BEGIN_VARYING_SECTION
3330
pnV->GetVector( vecnV, __iGrid );
3331
pnV->SetVector( -vecnV, __iGrid );
3334
SO_reflect( pnV, pnN, pR );
3336
pShader->DeleteTemporaryStorage( pnV );
3337
pShader->DeleteTemporaryStorage( pnN );
3339
// If the illuminance cache is already OK, then we don't need to bother filling in the illuminance parameters.
3340
if ( !m_IlluminanceCacheValid )
3342
ValidateIlluminanceCache( NULL, N, pShader );
3345
IqShaderData* pDefAngle = pShader->CreateTemporaryStorage( type_float, class_uniform );
3346
if ( NULL == pDefAngle ) return ;
3348
pDefAngle->SetFloat( PIO2 );
3350
// Initialise the return value
3351
Result->SetColor( gColBlack );
3353
// SO_init_illuminance returns TRUE if there are any non ambient ligthsources available.
3354
if ( SO_init_illuminance() )
3358
// SO_illuminance sets the current state to whether the lightsource illuminates the points or not.
3359
SO_illuminance( NULL, NULL, N, pDefAngle, NULL );
3364
BEGIN_VARYING_SECTION
3366
// Get the light vector and color from the loght source.
3368
L() ->GetVector( Ln, __iGrid );
3371
// Now combine the color into the result.
3374
pR->GetVector( vecR, __iGrid );
3377
Cl() ->GetColor( colCl, __iGrid );
3378
SETCOLOR( Result, COLOR( Result ) + colCl * pow( MAX( 0.0f, vecR * Ln ), FLOAT( size ) ) );
3383
// SO_advance_illuminance returns TRUE if there are any more non ambient lightsources.
3385
while ( SO_advance_illuminance() );
3387
pShader->DeleteTemporaryStorage( pDefAngle );
3388
pShader->DeleteTemporaryStorage( pR );
3392
//----------------------------------------------------------------------
3394
STD_SOIMPL CqShaderExecEnv::SO_trace( POINTVAL P, VECTORVAL R, DEFPARAMIMPL )
3396
STATS_INC( SHD_so_trace );
3404
BEGIN_VARYING_SECTION
3405
SETCOLOR( Result, CqColor( 0, 0, 0 ) );
3410
//----------------------------------------------------------------------
3411
// illuminance(P,nsamples)
3412
STD_SOIMPL CqShaderExecEnv::SO_illuminance( STRINGVAL Category, POINTVAL P, VECTORVAL Axis, FLOATVAL Angle, DEFVOIDPARAMIMPL )
3414
STATS_INC( SHD_so_illuminance );
3418
BEGIN_UNIFORM_SECTION
3420
if ( NULL != Category ) Category->GetString( cat );
3423
__fVarying = TqTrue;
3425
// Fill in the lightsource information, and transfer the results to the shader variables,
3426
if ( m_pAttributes != 0 )
3428
IqLightsource * lp = m_pAttributes ->pLight( m_li );
3430
if ( NULL != Axis ) CHECKVARY( Axis )
3431
if ( NULL != Angle ) CHECKVARY( Angle )
3433
TqBool exec = TqTrue;
3438
TqBool exclude = TqFalse;
3439
CqString lightcategories;
3443
if( cat.find( "-" ) == 0 )
3446
catname = cat.substr( 1, cat.size() );
3453
IqShaderData* pcats = lp->pShader()->FindArgument("__category");
3456
pcats->GetString( lightcategories );
3459
// While no matching category has been found...
3460
TqInt tokenpos = 0, tokenend;
3463
tokenend = lightcategories.find(',', tokenpos);
3464
CqString token = lightcategories.substr( tokenpos, tokenend );
3465
if( catname.compare( token ) == 0 )
3473
if( tokenend == std::string::npos )
3476
tokenpos = tokenend+1;
3483
BEGIN_VARYING_SECTION
3486
lp->L() ->GetVector( Ln, __iGrid );
3489
// Store them locally on the surface.
3490
L() ->SetVector( Ln, __iGrid );
3492
lp->Cl() ->GetColor( colCl, __iGrid );
3493
Cl() ->SetColor( colCl, __iGrid );
3495
// Check if its within the cone.
3497
CqVector3D vecAxis( 0, 1, 0 );
3498
if ( NULL != Axis ) Axis->GetVector( vecAxis, __iGrid );
3499
TqFloat fAngle = PI;
3500
if ( NULL != Angle ) Angle->GetFloat( fAngle, __iGrid );
3502
TqFloat cosangle = Ln * vecAxis;
3503
cosangle = CLAMP( cosangle, -1, 1 );
3504
if ( acos( cosangle ) > fAngle )
3505
m_CurrentState.SetValue( __iGrid, TqFalse );
3507
m_CurrentState.SetValue( __iGrid, TqTrue );
3514
STD_SOIMPL CqShaderExecEnv::SO_illuminance( STRINGVAL Category, POINTVAL P, DEFVOIDPARAMIMPL )
3516
STATS_INC( SHD_so_illuminance );
3518
SO_illuminance( Category, P, NULL, NULL );
3522
//----------------------------------------------------------------------
3524
STD_SOIMPL CqShaderExecEnv::SO_illuminate( POINTVAL P, VECTORVAL Axis, FLOATVAL Angle, DEFVOIDPARAMIMPL )
3526
STATS_INC( SHD_so_illuminate );
3530
TqBool res = TqTrue;
3531
if ( m_Illuminate > 0 ) res = TqFalse;
3533
__fVarying = TqTrue;
3536
BEGIN_VARYING_SECTION
3537
// Get the point being lit and set the ligth vector.
3540
Ps() ->GetPoint( vecPs, __iGrid );
3541
L() ->SetVector( vecPs - POINT( P ), __iGrid );
3543
// Check if its within the cone.
3545
L() ->GetVector( Ln, __iGrid );
3548
CqVector3D vecAxis( 0.0f, 1.0f, 0.0f );
3549
if ( NULL != Axis ) Axis->GetVector( vecAxis, __iGrid );
3550
TqFloat fAngle = PI;
3551
if ( NULL != Angle ) Angle->GetFloat( fAngle, __iGrid );
3552
TqFloat cosangle = Ln * vecAxis;
3553
cosangle = CLAMP( cosangle, -1, 1 );
3554
if ( acos( cosangle ) > fAngle )
3556
// Make sure we set the light color to zero in the areas that won't be lit.
3557
Cl() ->SetColor( CqColor( 0, 0, 0 ), __iGrid );
3558
m_CurrentState.SetValue( __iGrid, TqFalse );
3561
m_CurrentState.SetValue( __iGrid, TqTrue );
3569
STD_SOIMPL CqShaderExecEnv::SO_illuminate( POINTVAL P, DEFVOIDPARAMIMPL )
3571
STATS_INC( SHD_so_illuminate );
3573
SO_illuminate( P, NULL, NULL, pShader );
3577
//----------------------------------------------------------------------
3579
STD_SOIMPL CqShaderExecEnv::SO_solar( VECTORVAL Axis, FLOATVAL Angle, DEFVOIDPARAMIMPL )
3581
// TODO: Check light cone, and exclude points outside.
3582
STATS_INC( SHD_so_solar );
3586
TqBool res = TqTrue;
3587
if ( m_Illuminate > 0 ) res = TqFalse;
3589
__fVarying = TqTrue;
3590
BEGIN_VARYING_SECTION
3593
CqVector3D vecAxis( 0.0f, 1.0f, 0.0f );
3594
if ( NULL != Axis ) Axis->GetVector( vecAxis, __iGrid );
3595
L() ->SetVector( vecAxis, __iGrid );
3596
m_CurrentState.SetValue( __iGrid, TqTrue );
3604
STD_SOIMPL CqShaderExecEnv::SO_solar( DEFVOIDPARAMIMPL )
3606
STATS_INC( SHD_so_solar );
3608
SO_solar( NULL, NULL, pShader );
3612
//----------------------------------------------------------------------
3615
STD_SOIMPL CqShaderExecEnv::SO_printf( STRINGVAL str, DEFVOIDPARAMVARIMPL )
3617
STATS_INC( SHD_so_printf );
3621
if ( NULL == QGetRenderContextI() )
3626
for ( ii = 0; ii < cParams; ii++ )
3628
CHECKVARY( apParams[ ii ] );
3631
BEGIN_VARYING_SECTION
3633
CqString strA = SO_sprintf( STRING( str ).c_str(), cParams, apParams, __iGrid );
3634
QGetRenderContextI() ->PrintString( strA.c_str() );
3639
//----------------------------------------------------------------------
3642
STD_SOIMPL CqShaderExecEnv::SO_format( STRINGVAL str, DEFPARAMVARIMPL )
3644
STATS_INC( SHD_so_format );
3650
for ( ii = 0; ii < cParams; ii++ )
3652
CHECKVARY( apParams[ ii ] );
3654
CHECKVARY( Result );
3656
BEGIN_VARYING_SECTION
3658
CqString strA = SO_sprintf( STRING( str ).c_str(), cParams, apParams, __iGrid );
3659
SETSTRING( Result, strA );
3664
//----------------------------------------------------------------------
3667
STD_SOIMPL CqShaderExecEnv::SO_concat( STRINGVAL stra, STRINGVAL strb, DEFPARAMVARIMPL )
3669
STATS_INC( SHD_so_concat );
3676
for ( ii = 0; ii < cParams; ii++ )
3678
CHECKVARY( apParams[ ii ] );
3680
CHECKVARY( Result );
3682
BEGIN_VARYING_SECTION
3684
CqString strRes = STRING( stra );
3686
strRes += STRING( strb );
3687
for ( ii = 0; ii < cParams; ii++ )
3690
apParams[ ii ] ->GetString( sn, __iGrid );
3693
SETSTRING( Result, strRes );
3698
//----------------------------------------------------------------------
3700
STD_SOIMPL CqShaderExecEnv::SO_fcellnoise1( FLOATVAL v, DEFPARAMIMPL )
3702
STATS_INC( SHD_so_fcellnoise1 );
3709
BEGIN_VARYING_SECTION
3711
SETFLOAT( Result, m_cellnoise.FCellNoise1( FLOAT( v ) ) );
3715
STD_SOIMPL CqShaderExecEnv::SO_ccellnoise1( FLOATVAL v, DEFPARAMIMPL )
3717
STATS_INC( SHD_so_ccellnoise1 );
3724
BEGIN_VARYING_SECTION
3726
SETCOLOR( Result, CqColor( m_cellnoise.PCellNoise1( FLOAT( v ) ) ) );
3730
STD_SOIMPL CqShaderExecEnv::SO_pcellnoise1( FLOATVAL v, DEFPARAMIMPL )
3732
STATS_INC( SHD_so_pcellnoise1 );
3739
BEGIN_VARYING_SECTION
3741
SETPOINT( Result, m_cellnoise.PCellNoise1( FLOAT( v ) ) );
3745
//----------------------------------------------------------------------
3747
STD_SOIMPL CqShaderExecEnv::SO_fcellnoise2( FLOATVAL u, FLOATVAL v, DEFPARAMIMPL )
3749
STATS_INC( SHD_so_fcellnoise2 );
3757
BEGIN_VARYING_SECTION
3760
SETFLOAT( Result, m_cellnoise.FCellNoise2( FLOAT( u ), FLOAT( v ) ) );
3763
STD_SOIMPL CqShaderExecEnv::SO_ccellnoise2( FLOATVAL u, FLOATVAL v, DEFPARAMIMPL )
3765
STATS_INC( SHD_so_ccellnoise2 );
3773
BEGIN_VARYING_SECTION
3776
SETCOLOR( Result, CqColor( m_cellnoise.PCellNoise2( FLOAT( u ), FLOAT( v ) ) ) );
3779
STD_SOIMPL CqShaderExecEnv::SO_pcellnoise2( FLOATVAL u, FLOATVAL v, DEFPARAMIMPL )
3781
STATS_INC( SHD_so_pcellnoise3 );
3789
BEGIN_VARYING_SECTION
3792
SETPOINT( Result, m_cellnoise.PCellNoise2( FLOAT( u ), FLOAT( v ) ) );
3796
//----------------------------------------------------------------------
3798
STD_SOIMPL CqShaderExecEnv::SO_fcellnoise3( POINTVAL p, DEFPARAMIMPL )
3800
STATS_INC( SHD_so_fcellnoise3 );
3807
BEGIN_VARYING_SECTION
3809
SETFLOAT( Result, m_cellnoise.FCellNoise3( POINT( p ) ) );
3812
STD_SOIMPL CqShaderExecEnv::SO_ccellnoise3( POINTVAL p, DEFPARAMIMPL )
3814
STATS_INC( SHD_so_ccellnoise3 );
3821
BEGIN_VARYING_SECTION
3823
SETCOLOR( Result, CqColor( m_cellnoise.PCellNoise3( POINT( p ) ) ) );
3826
STD_SOIMPL CqShaderExecEnv::SO_pcellnoise3( POINTVAL p, DEFPARAMIMPL )
3828
STATS_INC( SHD_so_pcellnoise2 );
3835
BEGIN_VARYING_SECTION
3837
SETPOINT( Result, m_cellnoise.PCellNoise3( POINT( p ) ) );
3841
//----------------------------------------------------------------------
3843
STD_SOIMPL CqShaderExecEnv::SO_fcellnoise4( POINTVAL p, FLOATVAL v, DEFPARAMIMPL )
3845
STATS_INC( SHD_so_fcellnoise4 );
3853
BEGIN_VARYING_SECTION
3856
SETFLOAT( Result, m_cellnoise.FCellNoise4( POINT( p ), FLOAT( v ) ) );
3859
STD_SOIMPL CqShaderExecEnv::SO_ccellnoise4( POINTVAL p, FLOATVAL v, DEFPARAMIMPL )
3861
STATS_INC( SHD_so_ccellnoise4 );
3869
BEGIN_VARYING_SECTION
3872
SETCOLOR( Result, CqColor( m_cellnoise.PCellNoise4( POINT( p ), FLOAT( v ) ) ) );
3875
STD_SOIMPL CqShaderExecEnv::SO_pcellnoise4( POINTVAL p, FLOATVAL v, DEFPARAMIMPL )
3877
STATS_INC( SHD_so_pcellnoise2 );
3885
BEGIN_VARYING_SECTION
3888
SETPOINT( Result, m_cellnoise.PCellNoise4( POINT( p ), FLOAT( v ) ) );
3894
//----------------------------------------------------------------------
3898
STD_SOIMPL CqShaderExecEnv::SO_atmosphere( STRINGVAL name, IqShaderData* pV, DEFPARAMIMPL )
3900
STATS_INC( SHD_so_atmosphere );
3904
IqShader * pAtmosphere = NULL;
3906
if ( NULL != m_pAttributes && NULL != m_pAttributes ->pshadAtmosphere(QGetRenderContextI()->Time()) )
3907
pAtmosphere = m_pAttributes ->pshadAtmosphere(QGetRenderContextI()->Time());
3909
BEGIN_UNIFORM_SECTION
3912
Result->SetValue( pAtmosphere->GetValue( STRING( name ).c_str(), pV ) ? 1.0f : 0.0f, 0 );
3914
Result->SetValue( 0.0f, 0 );
3919
//----------------------------------------------------------------------
3923
STD_SOIMPL CqShaderExecEnv::SO_displacement( STRINGVAL name, IqShaderData* pV, DEFPARAMIMPL )
3925
STATS_INC( SHD_so_displacement );
3929
IqShader * pDisplacement = NULL;
3931
if ( NULL != m_pAttributes && NULL != m_pAttributes ->pshadDisplacement(QGetRenderContextI()->Time()) )
3932
pDisplacement = m_pAttributes ->pshadDisplacement(QGetRenderContextI()->Time());
3934
BEGIN_UNIFORM_SECTION
3936
if ( pDisplacement )
3937
Result->SetValue( pDisplacement->GetValue( STRING( name ).c_str(), pV ) ? 1.0f : 0.0f, 0 );
3939
Result->SetValue( 0.0f, 0 );
3944
//----------------------------------------------------------------------
3948
STD_SOIMPL CqShaderExecEnv::SO_lightsource( STRINGVAL name, IqShaderData* pV, DEFPARAMIMPL )
3950
STATS_INC( SHD_so_lightsource );
3954
// This should only be called within an Illuminance construct, so m_li should be valid.
3955
IqShader * pLightsource = 0;
3957
BEGIN_UNIFORM_SECTION
3959
if ( m_li < m_pAttributes ->cLights() )
3960
pLightsource = m_pAttributes ->pLight( m_li ) ->pShader();
3962
Result->SetValue( pLightsource->GetValue( STRING( name ).c_str(), pV ) ? 1.0f : 0.0f, 0 );
3964
Result->SetValue( 0.0f, 0 );
3969
//----------------------------------------------------------------------
3973
STD_SOIMPL CqShaderExecEnv::SO_surface( STRINGVAL name, IqShaderData* pV, DEFPARAMIMPL )
3975
STATS_INC( SHD_so_surface );
3979
IqShader * pSurface = NULL;
3981
if ( NULL != m_pAttributes && NULL != m_pAttributes ->pshadSurface(QGetRenderContextI()->Time()) )
3982
pSurface = m_pAttributes ->pshadSurface(QGetRenderContextI()->Time());
3984
BEGIN_UNIFORM_SECTION
3987
Result->SetValue( pSurface->GetValue( STRING( name ).c_str(), pV ) ? 1.0f : 0.0f, 0 );
3989
Result->SetValue( 0.0f, 0 );
3994
//----------------------------------------------------------------------
3998
STD_SOIMPL CqShaderExecEnv::SO_attribute( STRINGVAL name, IqShaderData* pV, DEFPARAMIMPL )
4000
STATS_INC( SHD_so_attribute );
4004
//Find out if it is a specific attribute request
4005
BEGIN_UNIFORM_SECTION
4009
if ( STRING( name ).compare( "ShadingRate" ) == 0 )
4011
if ( pV->Type() == type_float )
4013
pV->SetFloat( m_pAttributes ->GetFloatAttribute( "System", "ShadingRate" ) [ 0 ] );
4017
else if ( STRING( name ).compare( "Sides" ) == 0 )
4019
if ( pV->Type() == type_float )
4021
pV->SetFloat( m_pAttributes ->GetIntegerAttribute( "System", "Sides" ) [ 0 ] );
4025
else if ( STRING( name ).compare( "Matte" ) == 0 )
4027
if ( pV->Type() == type_float )
4029
pV->SetFloat( m_pAttributes ->GetIntegerAttribute( "System", "Matte" ) [ 0 ] );
4035
int iColon = STRING( name ).find_first_of( ':' );
4038
CqString strParam = STRING( name ).substr( iColon + 1, STRING( name ).size() - iColon - 1 );
4039
STRING( name ) = STRING( name ).substr( 0, iColon );
4040
//const CqParameter* pParam = m_pAttributes ->pParameter( STRING( name ).c_str(), strParam.c_str() );
4043
if ( NULL != pAttributes() ->GetFloatAttribute( STRING( name ).c_str(), strParam.c_str() ) )
4044
pV->SetFloat( pAttributes() ->GetFloatAttribute( STRING( name ).c_str(), strParam.c_str() ) [ 0 ] );
4045
else if ( NULL != pAttributes() ->GetIntegerAttribute( STRING( name ).c_str(), strParam.c_str() ) )
4046
pV->SetFloat( pAttributes() ->GetIntegerAttribute( STRING( name ).c_str(), strParam.c_str() ) [ 0 ] );
4047
else if ( NULL != pAttributes() ->GetStringAttribute( STRING( name ).c_str(), strParam.c_str() ) )
4048
pV->SetString( pAttributes() ->GetStringAttribute( STRING( name ).c_str(), strParam.c_str() ) [ 0 ] );
4049
else if ( NULL != pAttributes() ->GetPointAttribute( STRING( name ).c_str(), strParam.c_str() ) )
4050
pV->SetPoint( pAttributes() ->GetPointAttribute( STRING( name ).c_str(), strParam.c_str() ) [ 0 ] );
4051
else if ( NULL != pAttributes() ->GetVectorAttribute( STRING( name ).c_str(), strParam.c_str() ) )
4052
pV->SetVector( pAttributes() ->GetVectorAttribute( STRING( name ).c_str(), strParam.c_str() ) [ 0 ] );
4053
else if ( NULL != pAttributes() ->GetNormalAttribute( STRING( name ).c_str(), strParam.c_str() ) )
4054
pV->SetNormal( pAttributes() ->GetNormalAttribute( STRING( name ).c_str(), strParam.c_str() ) [ 0 ] );
4055
else if ( NULL != pAttributes() ->GetColorAttribute( STRING( name ).c_str(), strParam.c_str() ) )
4056
pV->SetColor( pAttributes() ->GetColorAttribute( STRING( name ).c_str(), strParam.c_str() ) [ 0 ] );
4057
else if ( NULL != pAttributes() ->GetMatrixAttribute( STRING( name ).c_str(), strParam.c_str() ) )
4058
pV->SetMatrix( pAttributes() ->GetMatrixAttribute( STRING( name ).c_str(), strParam.c_str() ) [ 0 ] );
4063
Result->SetValue( Ret, 0 );
4068
//----------------------------------------------------------------------
4072
STD_SOIMPL CqShaderExecEnv::SO_option( STRINGVAL name, IqShaderData* pV, DEFPARAMIMPL )
4074
STATS_INC( SHD_so_option );
4078
if ( NULL == QGetRenderContextI() )
4081
BEGIN_UNIFORM_SECTION
4082
//Find out if it is a specific option request
4086
if ( STRING( name ).compare( "Format" ) == 0 )
4088
if ( pV->Type() == type_float &&
4089
pV->ArrayLength() > 0 )
4091
if ( pV->ArrayLength() >= 3 )
4093
pV->ArrayEntry( 0 ) ->SetFloat( static_cast<TqFloat>( QGetRenderContextI() ->GetIntegerOption( "System", "Resolution" ) [ 0 ] ) );
4094
pV->ArrayEntry( 1 ) ->SetFloat( static_cast<TqFloat>( QGetRenderContextI() ->GetIntegerOption( "System", "Resolution" ) [ 1 ] ) );
4095
pV->ArrayEntry( 2 ) ->SetFloat( static_cast<TqFloat>( QGetRenderContextI() ->GetFloatOption( "System", "PixelAspectRatio" ) [ 2 ] ) );
4100
else if ( STRING( name ).compare( "CropWindow" ) == 0 )
4102
if ( pV->Type() == type_float &&
4103
pV->ArrayLength() > 0 )
4105
if ( pV->ArrayLength() >= 4 )
4107
pV->ArrayEntry( 0 ) ->SetFloat( static_cast<TqFloat>( QGetRenderContextI() ->GetFloatOption( "System", "CropWindow" ) [ 0 ] ) );
4108
pV->ArrayEntry( 1 ) ->SetFloat( static_cast<TqFloat>( QGetRenderContextI() ->GetFloatOption( "System", "CropWindow" ) [ 1 ] ) );
4109
pV->ArrayEntry( 2 ) ->SetFloat( static_cast<TqFloat>( QGetRenderContextI() ->GetFloatOption( "System", "CropWindow" ) [ 2 ] ) );
4110
pV->ArrayEntry( 3 ) ->SetFloat( static_cast<TqFloat>( QGetRenderContextI() ->GetFloatOption( "System", "CropWindow" ) [ 3 ] ) );
4115
else if ( STRING( name ).compare( "FrameAspectRatio" ) == 0 )
4117
if ( pV->Type() == type_float )
4119
pV->SetFloat( static_cast<TqFloat>( QGetRenderContextI() ->GetFloatOption( "System", "FrameAspectRatio" ) [ 0 ] ) );
4123
else if ( STRING( name ).compare( "DepthOfField" ) == 0 )
4125
if ( pV->Type() == type_float &&
4126
pV->ArrayLength() > 0 )
4128
if ( pV->ArrayLength() >= 3 )
4130
pV->ArrayEntry( 0 ) ->SetFloat( static_cast<TqFloat>( QGetRenderContextI() ->GetFloatOption( "System", "DepthOfField" ) [ 0 ] ) );
4131
pV->ArrayEntry( 1 ) ->SetFloat( static_cast<TqFloat>( QGetRenderContextI() ->GetFloatOption( "System", "DepthOfField" ) [ 1 ] ) );
4132
pV->ArrayEntry( 2 ) ->SetFloat( static_cast<TqFloat>( QGetRenderContextI() ->GetFloatOption( "System", "DepthOfField" ) [ 2 ] ) );
4137
else if ( STRING( name ).compare( "Shutter" ) == 0 )
4139
if ( pV->Type() == type_float &&
4140
pV->ArrayLength() > 0 )
4142
if ( pV->ArrayLength() >= 2 )
4144
pV->ArrayEntry( 0 ) ->SetFloat( static_cast<TqFloat>( QGetRenderContextI() ->GetFloatOption( "System", "Shutter" ) [ 0 ] ) );
4145
pV->ArrayEntry( 1 ) ->SetFloat( static_cast<TqFloat>( QGetRenderContextI() ->GetFloatOption( "System", "Shutter" ) [ 1 ] ) );
4150
else if ( STRING( name ).compare( "Clipping" ) == 0 )
4152
if ( pV->Type() == type_float &&
4153
pV->ArrayLength() > 0 )
4155
if ( pV->ArrayLength() >= 2 )
4157
pV->ArrayEntry( 0 ) ->SetFloat( static_cast<TqFloat>( QGetRenderContextI() ->GetFloatOption( "System", "Clipping" ) [ 0 ] ) );
4158
pV->ArrayEntry( 1 ) ->SetFloat( static_cast<TqFloat>( QGetRenderContextI() ->GetFloatOption( "System", "Clipping" ) [ 1 ] ) );
4165
CqString strName = STRING( name ).c_str();
4166
int iColon = strName.find_first_of( ':' );
4169
CqString strParam = strName.substr( iColon + 1, strName.size() - iColon - 1 );
4170
strName = strName.substr( 0, iColon );
4171
//const CqParameter* pParam = m_pAttributes ->pParameter( strName.c_str(), strParam.c_str() );
4175
if ( NULL != QGetRenderContextI() ->GetStringOption( strName.c_str(), strParam.c_str() ) )
4176
pV->SetString( QGetRenderContextI() ->GetStringOption( strName.c_str(), strParam.c_str() ) [ 0 ] );
4177
else if ( NULL != QGetRenderContextI() ->GetIntegerOption( strName.c_str(), strParam.c_str() ) )
4178
pV->SetFloat( QGetRenderContextI() ->GetIntegerOption( strName.c_str(), strParam.c_str() ) [ 0 ] );
4180
else if ( NULL != QGetRenderContextI() ->GetPointOption( strName.c_str(), strParam.c_str() ) )
4181
pV->SetPoint( QGetRenderContextI() ->GetPointOption( strName.c_str(), strParam.c_str() ) [ 0 ] );
4183
else if ( NULL != QGetRenderContextI() ->GetColorOption( strName.c_str(), strParam.c_str() ) )
4184
pV->SetColor( QGetRenderContextI() ->GetColorOption( strName.c_str(), strParam.c_str() ) [ 0 ] );
4185
else if ( NULL != QGetRenderContextI() ->GetFloatOption( strName.c_str(), strParam.c_str() ) )
4186
pV->SetFloat( QGetRenderContextI() ->GetFloatOption( strName.c_str(), strParam.c_str() ) [ 0 ] );
4187
/* did not deal with Vector, Normal and Matrix yet */
4193
Result->SetValue( Ret, 0 );
4198
//----------------------------------------------------------------------
4202
STD_SOIMPL CqShaderExecEnv::SO_rendererinfo( STRINGVAL name, IqShaderData* pV, DEFPARAMIMPL )
4204
STATS_INC( SHD_so_rendererinfo );
4208
BEGIN_UNIFORM_SECTION
4212
if ( STRING( name ).compare( "renderer" ) == 0 )
4214
if ( pV->Type() == type_string )
4216
pV->SetString( STRNAME );
4220
else if ( STRING( name ).compare( "version" ) == 0 )
4222
if ( pV->Type() == type_float &&
4223
pV->ArrayLength() > 0 )
4225
if ( pV->ArrayLength() >= 4 )
4227
pV->ArrayEntry( 0 ) ->SetFloat( static_cast<TqFloat>( VERMAJOR ) );
4228
pV->ArrayEntry( 1 ) ->SetFloat( static_cast<TqFloat>( VERMINOR ) );
4229
pV->ArrayEntry( 2 ) ->SetFloat( static_cast<TqFloat>( BUILD ) );
4230
pV->ArrayEntry( 3 ) ->SetFloat( 0.0f );
4235
else if ( STRING( name ).compare( "versionstring" ) == 0 )
4237
if ( pV->Type() == type_string )
4239
#if defined(AQSIS_SYSTEM_WIN32) || defined(AQSIS_SYSTEM_MACOSX)
4240
pV->SetString( VERSION_STR );
4241
#else // AQSIS_SYSTEM_WIN32
4242
pV->SetString( VERSION );
4243
#endif // !AQSIS_SYSTEM_WIN32
4247
Result->SetValue( Ret, 0 );
4252
//----------------------------------------------------------------------
4255
STD_SOIMPL CqShaderExecEnv::SO_incident( STRINGVAL name, IqShaderData* pV, DEFPARAMIMPL )
4257
STATS_INC( SHD_so_incident );
4261
BEGIN_UNIFORM_SECTION
4262
Result->SetValue( 0.0f, 0 );
4267
//----------------------------------------------------------------------
4270
STD_SOIMPL CqShaderExecEnv::SO_opposite( STRINGVAL name, IqShaderData* pV, DEFPARAMIMPL )
4272
STATS_INC( SHD_so_opposite );
4276
BEGIN_UNIFORM_SECTION
4277
Result->SetValue( 0.0f, 0 );
4282
//----------------------------------------------------------------------
4283
// ctransform(s,s,c)
4284
STD_SOIMPL CqShaderExecEnv::SO_ctransform( STRINGVAL fromspace, STRINGVAL tospace, COLORVAL c, DEFPARAMIMPL )
4286
STATS_INC( SHD_so_ctransform );
4293
BEGIN_UNIFORM_SECTION
4294
CqString strfromspace( "rgb" );
4295
if ( NULL != fromspace ) fromspace->GetString( strfromspace );
4296
GETSTRING( tospace );
4299
BEGIN_VARYING_SECTION
4301
CqColor res( COLOR( c ) );
4302
if ( strfromspace.compare( "hsv" ) == 0 ) res = COLOR( c ).hsvtorgb();
4303
else if ( strfromspace.compare( "hsl" ) == 0 ) res = COLOR( c ).hsltorgb();
4304
else if ( strfromspace.compare( "XYZ" ) == 0 ) res = COLOR( c ).XYZtorgb();
4305
else if ( strfromspace.compare( "xyY" ) == 0 ) res = COLOR( c ).xyYtorgb();
4306
else if ( strfromspace.compare( "YIQ" ) == 0 ) res = COLOR( c ).YIQtorgb();
4308
if ( STRING( tospace ).compare( "hsv" ) == 0 ) res = COLOR( c ).rgbtohsv();
4309
else if ( STRING( tospace ).compare( "hsl" ) == 0 ) res = COLOR( c ).rgbtohsl();
4310
else if ( STRING( tospace ).compare( "XYZ" ) == 0 ) res = COLOR( c ).rgbtoXYZ();
4311
else if ( STRING( tospace ).compare( "xyY" ) == 0 ) res = COLOR( c ).rgbtoxyY();
4312
else if ( STRING( tospace ).compare( "YIQ" ) == 0 ) res = COLOR( c ).rgbtoYIQ();
4314
SETCOLOR( Result, res );
4319
//----------------------------------------------------------------------
4321
STD_SOIMPL CqShaderExecEnv::SO_ctransform( STRINGVAL tospace, COLORVAL c, DEFPARAMIMPL )
4323
STATS_INC( SHD_so_ctransform );
4325
assert( pShader != 0 );
4326
SO_ctransform( NULL, tospace, c, Result, pShader );
4330
//----------------------------------------------------------------------
4332
STD_SOIMPL CqShaderExecEnv::SO_ptlined( POINTVAL P0, POINTVAL P1, POINTVAL Q, DEFPARAMIMPL )
4334
STATS_INC( SHD_so_ptlined );
4343
BEGIN_VARYING_SECTION
4347
CqVector3D kDiff = POINT( Q ) - POINT( P0 );
4348
CqVector3D vecDir = POINT( P1 ) - POINT( P0 );
4349
TqFloat fT = kDiff * vecDir;
4355
TqFloat fSqrLen = vecDir.Magnitude2();
4356
if ( fT >= fSqrLen )
4364
kDiff -= fT * vecDir;
4367
SETFLOAT( Result, kDiff.Magnitude() );
4372
STD_SOIMPL CqShaderExecEnv::SO_inversesqrt( FLOATVAL x, DEFPARAMIMPL )
4374
STATS_INC( SHD_so_inversesqrt );
4381
BEGIN_VARYING_SECTION
4383
SETFLOAT( Result, 1.0f / static_cast<TqFloat>( sqrt( FLOAT( x ) ) ) );
4387
STD_SOIMPL CqShaderExecEnv::SO_match( STRINGVAL a, STRINGVAL b, DEFPARAMIMPL )
4389
// TODO: Do this properly.
4390
STATS_INC( SHD_so_match );
4394
BEGIN_UNIFORM_SECTION
4398
if ( STRING( a ).size() == 0 ) r = 0.0f;
4399
else if ( STRING( b ).size() == 0 ) r = 0.0f;
4402
// MJO> Only check the occurrence of string b in string a
4403
// It doesn't support the regular expression yet
4404
r = ( float ) ( strstr( STRING( b ).c_str(), STRING( a ).c_str() ) != 0 );
4407
SETFLOAT( Result, r );
4412
//----------------------------------------------------------------------
4414
STD_SOIMPL CqShaderExecEnv::SO_fpnoise1( FLOATVAL v, FLOATVAL period, DEFPARAMIMPL )
4416
STATS_INC( SHD_so_fpnoise1 );
4424
BEGIN_VARYING_SECTION
4427
SETFLOAT( Result, ( m_noise.FGNoise1( fmod( FLOAT( v ), FLOAT( period ) ) ) + 1 ) / 2.0f );
4431
//----------------------------------------------------------------------
4432
// pnoise(u,v,uperiod,vperiod)
4433
STD_SOIMPL CqShaderExecEnv::SO_fpnoise2( FLOATVAL u, FLOATVAL v, FLOATVAL uperiod, FLOATVAL vperiod, DEFPARAMIMPL )
4435
STATS_INC( SHD_so_fpnoise2 );
4440
CHECKVARY( uperiod )
4442
CHECKVARY( vperiod )
4445
BEGIN_VARYING_SECTION
4448
GETFLOAT( uperiod );
4449
GETFLOAT( vperiod );
4450
SETFLOAT( Result, ( m_noise.FGNoise2( fmod( FLOAT( u ), FLOAT( uperiod ) ),
4451
fmod( FLOAT( v ), FLOAT( vperiod ) ) ) + 1 ) / 2.0f );
4455
//----------------------------------------------------------------------
4456
// pnoise(p,pperiod)
4457
STD_SOIMPL CqShaderExecEnv::SO_fpnoise3( POINTVAL p, POINTVAL pperiod, DEFPARAMIMPL )
4459
STATS_INC( SHD_so_fnoise3 );
4464
CHECKVARY( pperiod )
4467
BEGIN_VARYING_SECTION
4469
GETPOINT( pperiod );
4470
SETFLOAT( Result, ( m_noise.FGNoise3( CqVector3D( fmod( POINT( p ).x(), POINT( pperiod ).x() ),
4471
fmod( POINT( p ).y(), POINT( pperiod ).y() ),
4472
fmod( POINT( p ).z(), POINT( pperiod ).z() ) ) ) + 1 ) / 2.0f );
4476
//----------------------------------------------------------------------
4477
// pnoise(p,t,pperiod,tperiod)
4478
STD_SOIMPL CqShaderExecEnv::SO_fpnoise4( POINTVAL p, FLOATVAL t, POINTVAL pperiod, FLOATVAL tperiod, DEFPARAMIMPL )
4480
STATS_INC( SHD_so_fnoise4 );
4485
CHECKVARY( pperiod )
4487
CHECKVARY( tperiod )
4490
BEGIN_VARYING_SECTION
4493
GETPOINT( pperiod );
4494
GETFLOAT( tperiod );
4495
SETFLOAT( Result, ( m_noise.FGNoise3( CqVector3D( fmod( POINT( p ).x(), POINT( pperiod ).x() ),
4496
fmod( POINT( p ).y(), POINT( pperiod ).y() ),
4497
fmod( POINT( p ).z(), POINT( pperiod ).z() ) ) ) + 1 ) / 2.0f );
4501
//----------------------------------------------------------------------
4503
STD_SOIMPL CqShaderExecEnv::SO_cpnoise1( FLOATVAL v, FLOATVAL period, DEFPARAMIMPL )
4505
STATS_INC( SHD_so_cpnoise1 );
4513
BEGIN_VARYING_SECTION
4516
SETCOLOR( Result, ( m_noise.CGNoise1( fmod( FLOAT( v ), FLOAT( period ) ) ) + 1 ) / 2.0f );
4520
//----------------------------------------------------------------------
4521
// pnoise(u,v,uperiod,vperiod)
4522
STD_SOIMPL CqShaderExecEnv::SO_cpnoise2( FLOATVAL u, FLOATVAL v, FLOATVAL uperiod, FLOATVAL vperiod, DEFPARAMIMPL )
4524
STATS_INC( SHD_so_cpnoise2 );
4529
CHECKVARY( uperiod )
4531
CHECKVARY( vperiod )
4534
BEGIN_VARYING_SECTION
4537
GETFLOAT( uperiod );
4538
GETFLOAT( vperiod );
4539
SETCOLOR( Result, ( m_noise.CGNoise2( fmod( FLOAT( u ), FLOAT( uperiod ) ),
4540
fmod( FLOAT( v ), FLOAT( vperiod ) ) ) + 1 ) / 2.0f );
4544
//----------------------------------------------------------------------
4545
// pnoise(p,pperiod)
4546
STD_SOIMPL CqShaderExecEnv::SO_cpnoise3( POINTVAL p, POINTVAL pperiod, DEFPARAMIMPL )
4548
STATS_INC( SHD_so_cpnoise3 );
4553
CHECKVARY( pperiod )
4556
BEGIN_VARYING_SECTION
4558
GETPOINT( pperiod );
4559
SETCOLOR( Result, ( m_noise.CGNoise3( CqVector3D( fmod( POINT( p ).x(), POINT( pperiod ).x() ),
4560
fmod( POINT( p ).y(), POINT( pperiod ).y() ),
4561
fmod( POINT( p ).z(), POINT( pperiod ).z() ) ) ) + 1 ) / 2.0f );
4565
//----------------------------------------------------------------------
4566
// pnoise(p,t,pperiod,tperiod)
4567
STD_SOIMPL CqShaderExecEnv::SO_cpnoise4( POINTVAL p, FLOATVAL t, POINTVAL pperiod, FLOATVAL tperiod, DEFPARAMIMPL )
4569
STATS_INC( SHD_so_cpnoise4 );
4574
CHECKVARY( pperiod )
4576
CHECKVARY( tperiod )
4579
BEGIN_VARYING_SECTION
4582
GETPOINT( pperiod );
4583
GETFLOAT( tperiod );
4584
SETCOLOR( Result, ( m_noise.CGNoise3( CqVector3D( fmod( POINT( p ).x(), POINT( pperiod ).x() ),
4585
fmod( POINT( p ).y(), POINT( pperiod ).y() ),
4586
fmod( POINT( p ).z(), POINT( pperiod ).z() ) ) ) + 1 ) / 2.0f );
4590
//----------------------------------------------------------------------
4592
STD_SOIMPL CqShaderExecEnv::SO_ppnoise1( FLOATVAL v, FLOATVAL period, DEFPARAMIMPL )
4594
STATS_INC( SHD_so_ppnoise1 );
4602
BEGIN_VARYING_SECTION
4605
SETPOINT( Result, ( m_noise.PGNoise1( fmod( FLOAT( v ), FLOAT( period ) ) ) + 1 ) / 2.0f );
4609
//----------------------------------------------------------------------
4610
// pnoise(u,v,uperiod,vperiod)
4611
STD_SOIMPL CqShaderExecEnv::SO_ppnoise2( FLOATVAL u, FLOATVAL v, FLOATVAL uperiod, FLOATVAL vperiod, DEFPARAMIMPL )
4613
STATS_INC( SHD_so_ppnoise2 );
4618
CHECKVARY( uperiod )
4620
CHECKVARY( vperiod )
4623
BEGIN_VARYING_SECTION
4626
GETFLOAT( uperiod );
4627
GETFLOAT( vperiod );
4628
SETPOINT( Result, ( m_noise.PGNoise2( fmod( FLOAT( u ), FLOAT( uperiod ) ),
4629
fmod( FLOAT( v ), FLOAT( vperiod ) ) ) + 1 ) / 2.0f );
4633
//----------------------------------------------------------------------
4634
// pnoise(p,pperiod)
4635
STD_SOIMPL CqShaderExecEnv::SO_ppnoise3( POINTVAL p, POINTVAL pperiod, DEFPARAMIMPL )
4637
STATS_INC( SHD_so_ppnoise3 );
4642
CHECKVARY( pperiod )
4645
BEGIN_VARYING_SECTION
4647
GETPOINT( pperiod );
4648
SETPOINT( Result, ( m_noise.PGNoise3( CqVector3D( fmod( POINT( p ).x(), POINT( pperiod ).x() ),
4649
fmod( POINT( p ).y(), POINT( pperiod ).y() ),
4650
fmod( POINT( p ).z(), POINT( pperiod ).z() ) ) ) + 1 ) / 2.0f );
4654
//----------------------------------------------------------------------
4655
// pnoise(p,t,pperiod,tperiod)
4656
STD_SOIMPL CqShaderExecEnv::SO_ppnoise4( POINTVAL p, FLOATVAL t, POINTVAL pperiod, FLOATVAL tperiod, DEFPARAMIMPL )
4658
STATS_INC( SHD_so_ppnoise4 );
4663
CHECKVARY( pperiod )
4665
CHECKVARY( tperiod )
4668
BEGIN_VARYING_SECTION
4671
GETPOINT( pperiod );
4672
GETFLOAT( tperiod );
4673
SETPOINT( Result, ( m_noise.PGNoise3( CqVector3D( fmod( POINT( p ).x(), POINT( pperiod ).x() ),
4674
fmod( POINT( p ).y(), POINT( pperiod ).y() ),
4675
fmod( POINT( p ).z(), POINT( pperiod ).z() ) ) ) + 1 ) / 2.0f );
4680
//----------------------------------------------------------------------
4681
// rotate(Q,angle,P0,P1)
4682
STD_SOIMPL CqShaderExecEnv::SO_rotate( VECTORVAL Q, FLOATVAL angle, POINTVAL P0, POINTVAL P1, DEFPARAMIMPL )
4684
STATS_INC( SHD_so_rotate );
4694
BEGIN_VARYING_SECTION
4699
CqMatrix matR( FLOAT( angle ), POINT( P1 ) - POINT( P0 ) );
4701
CqVector3D Res( VECTOR( Q ) );
4704
SETPOINT( Result, Res );
4708
//----------------------------------------------------------------------
4709
// filterstep(edge,s1)
4710
STD_SOIMPL CqShaderExecEnv::SO_filterstep( FLOATVAL edge, FLOATVAL s1, DEFPARAMVARIMPL )
4712
STATS_INC( SHD_so_filterstep );
4714
TqFloat Deffloat = 0.0f;
4723
BEGIN_UNIFORM_SECTION
4725
du() ->GetFloat( fdu );
4726
dv() ->GetFloat( fdv );
4729
BEGIN_VARYING_SECTION
4732
TqFloat dsdu = SO_DuType<TqFloat>( s1, __iGrid, this, Deffloat );
4733
TqFloat dsdv = SO_DvType<TqFloat>( s1, __iGrid, this, Deffloat );
4735
TqFloat uwidth = fabs( dsdu * fdu );
4736
TqFloat vwidth = fabs( dsdv * fdv );
4738
TqFloat w = uwidth + vwidth;
4741
SETFLOAT( Result, CLAMP( ( FLOAT( s1 ) + w / 2.0f - FLOAT( edge ) ) / w, 0, 1 ) );
4743
// TqFloat res = RiCatmullRomFilter( FLOAT( s1 ) - FLOAT( edge ), 0, w, 0);
4744
// SETFLOAT( Result, res );
4746
// std::cout << res << std::endl;
4747
// TqFloat res = 1.0f - CLAMP( ( FLOAT( s1 ) + w / 2.0f - FLOAT( edge ) ) / w, 0, 1 );
4749
// std::cout << "Aqsis angle/dangle: " << FLOAT(s1) << ", edge: " << FLOAT(edge) << ", dsdu: " << dsdu << ", dsdv: " << dsdv << ", w: " << w << ", res: " << res << std::endl;
4753
//----------------------------------------------------------------------
4754
// filterstep(edge,s1,s2)
4755
STD_SOIMPL CqShaderExecEnv::SO_filterstep2( FLOATVAL edge, FLOATVAL s1, FLOATVAL s2, DEFPARAMVARIMPL )
4757
STATS_INC( SHD_so_filterstep2 );
4768
BEGIN_VARYING_SECTION
4772
TqFloat w = FLOAT( s2 ) - FLOAT( s1 );
4774
SETFLOAT( Result, CLAMP( ( FLOAT( s1 ) + w / 2.0f - FLOAT( edge ) ) / w, 0, 1 ) );
4778
//----------------------------------------------------------------------
4779
// specularbrdf(L,N,V,rough)
4780
STD_SOIMPL CqShaderExecEnv::SO_specularbrdf( VECTORVAL L, NORMALVAL N, VECTORVAL V, FLOATVAL rough, DEFPARAMIMPL )
4782
STATS_INC( SHD_so_specularbrdf );
4792
BEGIN_VARYING_SECTION
4797
CqVector3D H = VECTOR( L ) + VECTOR( V );
4799
/// \note The (roughness/8) term emulates the BMRT behaviour for prmanspecular.
4803
Cl() ->GetColor( colCl, __iGrid );
4804
SETCOLOR( Result, colCl * pow( MAX( 0.0f, NORMAL( N ) * H ), 1.0f / ( FLOAT( rough ) / 8.0f ) ) );
4809
//----------------------------------------------------------------------
4811
STD_SOIMPL CqShaderExecEnv::SO_determinant( MATRIXVAL M, DEFPARAMIMPL )
4813
STATS_INC( SHD_so_determinant );
4820
BEGIN_VARYING_SECTION
4822
SETFLOAT( Result, MATRIX( M ).Determinant() );
4827
//----------------------------------------------------------------------
4829
STD_SOIMPL CqShaderExecEnv::SO_mtranslate( MATRIXVAL M, VECTORVAL V, DEFPARAMIMPL )
4831
STATS_INC( SHD_so_mtranslate );
4839
BEGIN_VARYING_SECTION
4842
MATRIX( M ).Translate( VECTOR( V ) );
4843
SETMATRIX( Result, MATRIX( M ) );
4847
//----------------------------------------------------------------------
4849
STD_SOIMPL CqShaderExecEnv::SO_mrotate( MATRIXVAL M, FLOATVAL angle, VECTORVAL axis, DEFPARAMIMPL )
4851
STATS_INC( SHD_so_mrotate );
4860
BEGIN_VARYING_SECTION
4864
MATRIX( M ).Rotate( FLOAT( angle ), VECTOR( axis ) );
4865
SETMATRIX( Result, MATRIX( M ) );
4869
//----------------------------------------------------------------------
4871
STD_SOIMPL CqShaderExecEnv::SO_mscale( MATRIXVAL M, POINTVAL S, DEFPARAMIMPL )
4873
STATS_INC( SHD_so_mscale );
4881
BEGIN_VARYING_SECTION
4884
MATRIX( M ).Scale( POINT( S ).x(), POINT( S ).y(), POINT( S ).z() );
4885
SETMATRIX( Result, MATRIX( M ) );
4890
//----------------------------------------------------------------------
4892
STD_SOIMPL CqShaderExecEnv::SO_setmcomp( MATRIXVAL M, FLOATVAL r, FLOATVAL c, FLOATVAL v, DEFVOIDPARAMIMPL )
4894
STATS_INC( SHD_so_setmcomp );
4903
BEGIN_VARYING_SECTION
4908
MATRIX( M ) [ static_cast<TqInt>( FLOAT( r ) ) ][ static_cast<TqInt>( FLOAT( c ) ) ] = FLOAT( v );
4909
MATRIX( M ).SetfIdentity( TqFalse );
4910
M->SetValue( MATRIX( M ), __iGrid );
4915
//----------------------------------------------------------------------
4916
// spline(value, f1,f2,...,fn)
4917
STD_SOIMPL CqShaderExecEnv::SO_fsplinea( FLOATVAL value, FLOATARRAYVAL a, DEFPARAMIMPL )
4919
STATS_INC( SHD_so_fsplinea );
4923
assert( a->ArrayLength() > 0 );
4924
assert( a->Type() == type_float );
4926
TqInt cParams = a->ArrayLength();
4927
CqSplineCubic spline( cParams );
4933
BEGIN_VARYING_SECTION
4937
if ( FLOAT( value ) >= 1.0f )
4939
a->ArrayEntry( cParams - 2 ) ->GetFloat( fTemp, __iGrid );
4940
Result->SetFloat( fTemp, __iGrid );
4942
else if ( FLOAT( value ) <= 0.0f )
4944
a->ArrayEntry( 1 ) ->GetFloat( fTemp, __iGrid );
4945
Result->SetFloat( fTemp, __iGrid );
4950
for ( j = 0; j < cParams; j++ )
4952
a->ArrayEntry( j ) ->GetFloat( fTemp, __iGrid );
4953
spline[ j ] = CqVector4D( fTemp, 0.0f, 0.0f, 1.0f );
4956
CqVector4D res = spline.Evaluate( FLOAT( value ) );
4957
SETFLOAT( Result, res.x() );
4963
//----------------------------------------------------------------------
4964
// spline(value, f1,f2,...,fn)
4965
STD_SOIMPL CqShaderExecEnv::SO_csplinea( FLOATVAL value, COLORARRAYVAL a, DEFPARAMIMPL )
4967
STATS_INC( SHD_so_csplinea );
4971
assert( a->ArrayLength() > 0 );
4972
assert( a->Type() == type_color );
4974
TqInt cParams = a->ArrayLength();
4975
CqSplineCubic spline( cParams );
4982
BEGIN_VARYING_SECTION
4986
if ( FLOAT( value ) >= 1.0f )
4988
a->ArrayEntry( cParams - 2 ) ->GetColor( colTemp, __iGrid );
4989
Result->SetColor( colTemp, __iGrid );
4991
else if ( FLOAT( value ) <= 0.0f )
4993
a->ArrayEntry( 1 ) ->GetColor( colTemp, __iGrid );
4994
Result->SetColor( colTemp, __iGrid );
4999
for ( j = 0; j < cParams; j++ )
5001
a->ArrayEntry( j ) ->GetColor( colTemp, __iGrid );
5002
spline[ j ] = CqVector4D( colTemp.fRed(), colTemp.fGreen(), colTemp.fBlue(), 1.0f );
5005
CqVector4D res = spline.Evaluate( FLOAT( value ) );
5006
SETCOLOR( Result, CqColor( res.x(), res.y(), res.z() ) );
5012
//----------------------------------------------------------------------
5013
// spline(value, f1,f2,...,fn)
5014
STD_SOIMPL CqShaderExecEnv::SO_psplinea( FLOATVAL value, POINTARRAYVAL a, DEFPARAMIMPL )
5016
STATS_INC( SHD_so_psplinea );
5020
assert( a->ArrayLength() > 0 );
5021
assert( a->Type() == type_point );
5023
TqInt cParams = a->ArrayLength();
5024
CqSplineCubic spline( cParams );
5031
BEGIN_VARYING_SECTION
5035
if ( FLOAT( value ) >= 1.0f )
5037
a->ArrayEntry( cParams - 2 ) ->GetPoint( vecTemp, __iGrid );
5038
Result->SetPoint( vecTemp, __iGrid );
5040
else if ( FLOAT( value ) <= 0.0f )
5042
a->ArrayEntry( 1 ) ->GetPoint( vecTemp, __iGrid );
5043
Result->SetPoint( vecTemp, __iGrid );
5048
for ( j = 0; j < cParams; j++ )
5050
a->ArrayEntry( j ) ->GetPoint( vecTemp, __iGrid );
5051
spline[ j ] = vecTemp;
5054
CqVector3D res = spline.Evaluate( FLOAT( value ) );
5055
SETPOINT( Result, res );
5061
//----------------------------------------------------------------------
5062
// spline(value, f1,f2,...,fn)
5063
STD_SOIMPL CqShaderExecEnv::SO_sfsplinea( STRINGVAL basis, FLOATVAL value, FLOATARRAYVAL a, DEFPARAMIMPL )
5065
STATS_INC( SHD_so_sfsplinea );
5069
assert( a->ArrayLength() > 0 );
5070
assert( a->Type() == type_float );
5072
TqInt cParams = a->ArrayLength();
5073
CqSplineCubic spline( cParams );
5079
BEGIN_UNIFORM_SECTION
5081
spline.SetmatBasis( STRING( basis ) );
5084
BEGIN_VARYING_SECTION
5088
if ( FLOAT( value ) >= 1.0f )
5090
a->ArrayEntry( cParams - 2 ) ->GetFloat( fTemp, __iGrid );
5091
Result->SetFloat( fTemp, __iGrid );
5093
else if ( FLOAT( value ) <= 0.0f )
5095
a->ArrayEntry( 1 ) ->GetFloat( fTemp, __iGrid );
5096
Result->SetFloat( fTemp, __iGrid );
5101
for ( j = 0; j < cParams; j++ )
5103
a->ArrayEntry( j ) ->GetFloat( fTemp, __iGrid );
5104
spline[ j ] = CqVector4D( fTemp, 0.0f, 0.0f, 1.0f );
5107
CqVector4D res = spline.Evaluate( FLOAT( value ) );
5108
SETFLOAT( Result, res.x() );
5114
//----------------------------------------------------------------------
5115
// spline(value, f1,f2,...,fn)
5116
STD_SOIMPL CqShaderExecEnv::SO_scsplinea( STRINGVAL basis, FLOATVAL value, COLORARRAYVAL a, DEFPARAMIMPL )
5118
STATS_INC( SHD_so_scsplinea );
5122
assert( a->ArrayLength() > 0 );
5123
assert( a->Type() == type_color );
5125
TqInt cParams = a->ArrayLength();
5126
CqSplineCubic spline( cParams );
5133
BEGIN_UNIFORM_SECTION
5135
spline.SetmatBasis( STRING( basis ) );
5138
BEGIN_VARYING_SECTION
5142
if ( FLOAT( value ) >= 1.0f )
5144
a->ArrayEntry( cParams - 2 ) ->GetColor( colTemp, __iGrid );
5145
Result->SetColor( colTemp, __iGrid );
5147
else if ( FLOAT( value ) <= 0.0f )
5149
a->ArrayEntry( 1 ) ->GetColor( colTemp, __iGrid );
5150
Result->SetColor( colTemp, __iGrid );
5155
for ( j = 0; j < cParams; j++ )
5157
a->ArrayEntry( j ) ->GetColor( colTemp, __iGrid );
5158
spline[ j ] = CqVector4D( colTemp.fRed(), colTemp.fGreen(), colTemp.fBlue(), 1.0f );
5161
CqVector4D res = spline.Evaluate( FLOAT( value ) );
5162
SETCOLOR( Result, CqColor( res.x(), res.y(), res.z() ) );
5168
//----------------------------------------------------------------------
5169
// spline(value, f1,f2,...,fn)
5170
STD_SOIMPL CqShaderExecEnv::SO_spsplinea( STRINGVAL basis, FLOATVAL value, POINTARRAYVAL a, DEFPARAMIMPL )
5172
STATS_INC( SHD_so_spsplinea );
5176
assert( a->ArrayLength() > 0 );
5177
assert( a->Type() == type_point );
5179
TqInt cParams = a->ArrayLength();
5180
CqSplineCubic spline( cParams );
5187
BEGIN_UNIFORM_SECTION
5189
spline.SetmatBasis( STRING( basis ) );
5192
BEGIN_VARYING_SECTION
5196
if ( FLOAT( value ) >= 1.0f )
5198
a->ArrayEntry( cParams - 2 ) ->GetPoint( vecTemp, __iGrid );
5199
Result->SetPoint( vecTemp, __iGrid );
5201
else if ( FLOAT( value ) <= 0.0f )
5203
a->ArrayEntry( 1 ) ->GetPoint( vecTemp, __iGrid );
5204
Result->SetPoint( vecTemp, __iGrid );
5209
for ( j = 0; j < cParams; j++ )
5211
a->ArrayEntry( j ) ->GetPoint( vecTemp, __iGrid );
5212
spline[ j ] = vecTemp;
5215
CqVector3D res = spline.Evaluate( FLOAT( value ) );
5216
SETPOINT( Result, res );
5222
//----------------------------------------------------------------------
5224
STD_SOIMPL CqShaderExecEnv::SO_shadername( DEFPARAMIMPL )
5226
STATS_INC( SHD_so_shadername );
5232
BEGIN_VARYING_SECTION
5233
SETSTRING( Result, pShader->strName() );
5238
//----------------------------------------------------------------------
5240
STD_SOIMPL CqShaderExecEnv::SO_shadername2( STRINGVAL shader, DEFPARAMIMPL )
5242
STATS_INC( SHD_so_shadername2 );
5246
CqString strName( "" );
5248
IqShader* pSurface = 0;
5249
IqShader* pDisplacement = 0;
5250
IqShader* pAtmosphere = 0;
5253
pSurface = m_pAttributes ->pshadSurface(QGetRenderContextI()->Time());
5254
pDisplacement = m_pAttributes ->pshadDisplacement(QGetRenderContextI()->Time());
5255
pAtmosphere = m_pAttributes ->pshadAtmosphere(QGetRenderContextI()->Time());
5260
BEGIN_VARYING_SECTION
5262
GETSTRING( shader );
5263
if ( STRING( shader ).compare( "surface" ) == 0 && pSurface != 0 ) strName = pSurface->strName();
5264
else if ( STRING( shader ).compare( "displacement" ) == 0 && pDisplacement != 0 ) strName = pDisplacement->strName();
5265
else if ( STRING( shader ).compare( "atmosphere" ) == 0 && pAtmosphere != 0 ) strName = pAtmosphere->strName();
5266
SETSTRING( Result, strName );
5271
//----------------------------------------------------------------------
5273
// support resolution, type, channels, projectionmatrix(*) and viewingmatrix(*)
5274
// User has to provide an array of TqFloat (2) for resolution
5275
// an string for type
5276
// an integer for channels
5277
// an array of floats (16) for both projectionmatrix and viewingmatrix
5278
// (*) the name must be a shadow map
5281
STD_SOIMPL CqShaderExecEnv::SO_textureinfo( STRINGVAL name, STRINGVAL dataname, IqShaderData* pV, DEFPARAMIMPL )
5283
STATS_INC( SHD_so_textureinfo );
5287
if ( NULL == QGetRenderContextI() )
5291
IqTextureMap* pMap = NULL;
5292
IqTextureMap *pSMap = NULL;
5293
IqTextureMap *pLMap = NULL;
5294
IqTextureMap *pEMap = NULL;
5295
IqTextureMap *pTMap = NULL;
5297
BEGIN_UNIFORM_SECTION
5299
GETSTRING( dataname );
5301
if ( !pMap && strstr( STRING( name ).c_str(), ".tif" ) )
5303
pTMap = QGetRenderContextI() ->GetTextureMap( STRING( name ) );
5304
if ( pTMap && ( pTMap->Type() == MapType_Texture ) )
5308
else if ( pTMap ) delete pTMap;
5312
pSMap = QGetRenderContextI() ->GetShadowMap( STRING( name ) );
5313
if ( pSMap && ( pSMap->Type() == MapType_Shadow ) )
5317
else if ( pSMap ) delete pSMap;
5322
pEMap = QGetRenderContextI() ->GetEnvironmentMap( STRING( name ) );
5323
if ( pEMap && ( pEMap->Type() == MapType_Environment ) )
5327
else if ( pEMap ) delete pEMap;
5332
pTMap = QGetRenderContextI() ->GetTextureMap( STRING( name ) );
5333
if ( pTMap && ( pTMap->Type() == MapType_Texture ) )
5337
else if ( pTMap ) delete pTMap;
5341
if ( pMap == 0 ) return ;
5343
if ( STRING( dataname ).compare( "resolution" ) == 0 )
5345
if ( pV->Type() == type_float &&
5346
pV->ArrayLength() > 0 )
5349
if ( pV->ArrayLength() == 2 )
5351
pV->ArrayEntry( 0 ) ->SetFloat( static_cast<TqFloat>( pMap->XRes() ) );
5352
pV->ArrayEntry( 1 ) ->SetFloat( static_cast<TqFloat>( pMap->YRes() ) );
5358
if ( STRING( dataname ).compare( "type" ) == 0 )
5360
if ( pV->Type() == type_string )
5362
if ( pMap->Type() == MapType_Texture )
5364
pV->SetString( "texture" );
5368
if ( pMap->Type() == MapType_Bump )
5370
pV->SetString( "bump" );
5375
if ( pMap->Type() == MapType_Shadow )
5377
pV->SetString( "shadow" );
5381
if ( pMap->Type() == MapType_Environment )
5383
pV->SetString( "environment" );
5387
if ( pMap->Type() == MapType_LatLong )
5389
// both latlong/cube respond the same way according to BMRT
5390
// It makes sense since both use environment() shader fct.
5391
pV->SetString( "environment" );
5400
if ( STRING( dataname ).compare( "channels" ) == 0 )
5402
if ( pV->Type() == type_float )
5404
pV->SetFloat( static_cast<TqFloat>( pMap->SamplesPerPixel() ) );
5410
if ( STRING( dataname ).compare( "viewingmatrix" ) == 0 )
5412
if ( ( ( pV->Type() == type_float ) && ( pV->ArrayLength() == 16 ) ) ||
5413
( pV->Type() == type_matrix ) )
5415
if ( pSMap ) // && pSMap->Type() == MapType_Shadow)
5418
CqMatrix m = pSMap->GetMatrix( 0 ); /* WorldToCamera */
5419
if ( pV->ArrayLength() == 16 )
5422
pV->ArrayEntry( 0 ) ->SetFloat( static_cast<TqFloat>( m[ 0 ][ 0 ] ) );
5423
pV->ArrayEntry( 1 ) ->SetFloat( static_cast<TqFloat>( m[ 0 ][ 1 ] ) );
5424
pV->ArrayEntry( 2 ) ->SetFloat( static_cast<TqFloat>( m[ 0 ][ 2 ] ) );
5425
pV->ArrayEntry( 3 ) ->SetFloat( static_cast<TqFloat>( m[ 0 ][ 3 ] ) );
5426
pV->ArrayEntry( 4 ) ->SetFloat( static_cast<TqFloat>( m[ 1 ][ 0 ] ) );
5427
pV->ArrayEntry( 5 ) ->SetFloat( static_cast<TqFloat>( m[ 1 ][ 1 ] ) );
5428
pV->ArrayEntry( 6 ) ->SetFloat( static_cast<TqFloat>( m[ 1 ][ 2 ] ) );
5429
pV->ArrayEntry( 7 ) ->SetFloat( static_cast<TqFloat>( m[ 1 ][ 3 ] ) );
5430
pV->ArrayEntry( 8 ) ->SetFloat( static_cast<TqFloat>( m[ 2 ][ 0 ] ) );
5431
pV->ArrayEntry( 9 ) ->SetFloat( static_cast<TqFloat>( m[ 2 ][ 1 ] ) );
5432
pV->ArrayEntry( 10 ) ->SetFloat( static_cast<TqFloat>( m[ 2 ][ 2 ] ) );
5433
pV->ArrayEntry( 11 ) ->SetFloat( static_cast<TqFloat>( m[ 2 ][ 3 ] ) );
5434
pV->ArrayEntry( 12 ) ->SetFloat( static_cast<TqFloat>( m[ 3 ][ 0 ] ) );
5435
pV->ArrayEntry( 13 ) ->SetFloat( static_cast<TqFloat>( m[ 3 ][ 1 ] ) );
5436
pV->ArrayEntry( 14 ) ->SetFloat( static_cast<TqFloat>( m[ 3 ][ 2 ] ) );
5437
pV->ArrayEntry( 15 ) ->SetFloat( static_cast<TqFloat>( m[ 3 ][ 3 ] ) );
5442
pV->SetMatrix( m, 0 );
5451
if ( STRING( dataname ).compare( "projectionmatrix" ) == 0 )
5453
if ( ( ( pV->Type() == type_float ) && ( pV->ArrayLength() == 16 ) ) ||
5454
( pV->Type() == type_matrix ) )
5456
if ( pSMap ) // && pSMap->Type() == MapType_Shadow)
5459
CqMatrix m = pSMap->GetMatrix( 1 ); /* WorldToScreen */
5461
if ( pV->ArrayLength() == 16 )
5463
pV->ArrayEntry( 0 ) ->SetFloat( static_cast<TqFloat>( m[ 0 ][ 0 ] ) );
5464
pV->ArrayEntry( 1 ) ->SetFloat( static_cast<TqFloat>( m[ 0 ][ 1 ] ) );
5465
pV->ArrayEntry( 2 ) ->SetFloat( static_cast<TqFloat>( m[ 0 ][ 2 ] ) );
5466
pV->ArrayEntry( 3 ) ->SetFloat( static_cast<TqFloat>( m[ 0 ][ 3 ] ) );
5467
pV->ArrayEntry( 4 ) ->SetFloat( static_cast<TqFloat>( m[ 1 ][ 0 ] ) );
5468
pV->ArrayEntry( 5 ) ->SetFloat( static_cast<TqFloat>( m[ 1 ][ 1 ] ) );
5469
pV->ArrayEntry( 6 ) ->SetFloat( static_cast<TqFloat>( m[ 1 ][ 2 ] ) );
5470
pV->ArrayEntry( 7 ) ->SetFloat( static_cast<TqFloat>( m[ 1 ][ 3 ] ) );
5471
pV->ArrayEntry( 8 ) ->SetFloat( static_cast<TqFloat>( m[ 2 ][ 0 ] ) );
5472
pV->ArrayEntry( 9 ) ->SetFloat( static_cast<TqFloat>( m[ 2 ][ 1 ] ) );
5473
pV->ArrayEntry( 10 ) ->SetFloat( static_cast<TqFloat>( m[ 2 ][ 2 ] ) );
5474
pV->ArrayEntry( 11 ) ->SetFloat( static_cast<TqFloat>( m[ 2 ][ 3 ] ) );
5475
pV->ArrayEntry( 12 ) ->SetFloat( static_cast<TqFloat>( m[ 3 ][ 0 ] ) );
5476
pV->ArrayEntry( 13 ) ->SetFloat( static_cast<TqFloat>( m[ 3 ][ 1 ] ) );
5477
pV->ArrayEntry( 14 ) ->SetFloat( static_cast<TqFloat>( m[ 3 ][ 2 ] ) );
5478
pV->ArrayEntry( 15 ) ->SetFloat( static_cast<TqFloat>( m[ 3 ][ 3 ] ) );
5484
pV->SetMatrix( m, 0 );
5495
SETFLOAT( Result, Ret );
5499
// SIGGRAPH 2002; Larry G. Bake functions
5501
const int batchsize = 10240; // elements to buffer before writing
5502
// Make sure we're thread-safe on those file writes
5506
// A "BakingChannel" is the buffer for a single baking output file.
5507
// We buffer up samples until "batchsize" has been accepted, then
5508
// write them all at once. This keeps us from constantly accessing
5509
// the disk. Note that we are careful to use a mutex to keep
5510
// simultaneous multithreaded writes from clobbering each other.
5513
BakingChannel ( void ) : buffered( 0 ), data( NULL ), filename( NULL )
5515
BakingChannel ( const char *_filename, int _elsize )
5517
init ( _filename, _elsize );
5519
// Initialize - allocate memory, etc.
5520
void init ( const char *_filename, int _elsize )
5522
elsize = _elsize + 2;
5524
data = new float [ elsize * batchsize ];
5525
filename = strdup ( _filename );
5527
// Destructor: write buffered output, close file, deallocate
5534
// Add one more data item
5535
void moredata ( float s, float t, float *newdata )
5537
if ( buffered >= batchsize )
5539
float *f = data + elsize * buffered;
5542
for ( int j = 2; j < elsize; ++j )
5543
f[ j ] = newdata[ j - 2 ];
5547
int elsize; // element size (e.g., 3 for colors)
5548
int buffered; // how many elements are currently buffered
5549
float *data; // pointer to the allocated buffer (new'ed)
5550
char *filename; // pointer to filename (strdup'ed)
5551
// Write any buffered data to the file
5552
void writedata ( void )
5555
if ( buffered > 0 && filename != NULL )
5557
FILE * file = fopen ( filename, "a" );
5559
for ( int i = 0; i < buffered; ++i, f += elsize )
5561
for ( int j = 0; j < elsize; ++j )
5562
fprintf ( file, "%g ", f[ j ] );
5563
fprintf ( file, "\n" );
5572
typedef std::map<std::string, BakingChannel> BakingData;
5575
extern "C" BakingData *bake_init()
5577
BakingData * bd = new BakingData;
5581
extern "C" void bake_done( BakingData *bd )
5583
delete bd; // Will destroy bd, and in turn all its BakingChannel's
5585
// Workhorse routine -- look up the channel name, add a new BakingChannel
5586
// if it doesn't exist, add one point's data to the channel.
5587
extern "C" void bake ( BakingData *bd, const std::string &name,
5588
float s, float t, int elsize, float *data )
5590
BakingData::iterator found = bd->find ( name );
5592
if ( found == bd->end() )
5594
// This named map doesn't yet exist
5595
( *bd ) [ name ] = BakingChannel();
5596
found = bd->find ( name );
5597
BakingChannel &bc = ( found->second );
5598
bc.init ( name.c_str(), elsize );
5599
bc.moredata ( s, t, data );
5603
BakingChannel &bc = ( found->second );
5604
bc.moredata ( s, t, data );
5608
extern "C" int bake_f( BakingData *bd, char *name, float s, float t, float f )
5610
float * bakedata = ( float * ) & f;
5612
bake ( bd, name, s, t, 1, bakedata );
5615
// for baking a triple -- just call bake with appropriate args
5616
extern "C" int bake_3( BakingData *bd, char *name, float s, float t, float *bakedata )
5618
bake ( bd, name, s, t, 3, bakedata );
5624
STD_SOIMPL CqShaderExecEnv::SO_bake_f( STRINGVAL name, FLOATVAL s, FLOATVAL t, FLOATVAL f, DEFVOIDPARAMVARIMPL )
5626
STATS_INC( SHD_so_bake );
5634
BEGIN_UNIFORM_SECTION
5636
BakingData *bd = bake_init( /*STRING( name).c_str() */ );
5639
BEGIN_VARYING_SECTION
5643
bake_f( bd, ( char * ) STRING( name ).c_str(), FLOAT( s ), FLOAT( t ), FLOAT( f ) );
5646
BEGIN_UNIFORM_SECTION
5651
STD_SOIMPL CqShaderExecEnv::SO_bake_3c( STRINGVAL name, FLOATVAL s, FLOATVAL t, COLORVAL f, DEFVOIDPARAMVARIMPL )
5653
STATS_INC( SHD_so_bake );
5661
BEGIN_UNIFORM_SECTION
5665
BakingData *bd = bake_init( /*(char *) STRING( name ).c_str()*/ );
5667
BEGIN_VARYING_SECTION
5671
COLOR( f ).GetColorRGB( &rgb[ 0 ], &rgb[ 1 ], &rgb[ 2 ] );
5672
bake_3( bd, ( char * ) STRING( name ).c_str(), FLOAT( s ), FLOAT( t ), rgb );
5674
BEGIN_UNIFORM_SECTION
5679
STD_SOIMPL CqShaderExecEnv::SO_bake_3n( STRINGVAL name, FLOATVAL s, FLOATVAL t, NORMALVAL f, DEFVOIDPARAMVARIMPL )
5681
STATS_INC( SHD_so_bake );
5689
BEGIN_UNIFORM_SECTION
5691
BakingData *bd = bake_init( /*(char *) STRING( name ).c_str() */ );
5694
BEGIN_VARYING_SECTION
5699
rgb[ 0 ] = VECTOR( f ) [ 0 ];
5700
rgb[ 1 ] = VECTOR( f ) [ 1 ];
5701
rgb[ 2 ] = VECTOR( f ) [ 2 ];
5702
bake_3( bd, ( char * ) STRING( name ).c_str(), FLOAT( s ), FLOAT( t ), rgb );
5705
BEGIN_UNIFORM_SECTION
5710
STD_SOIMPL CqShaderExecEnv::SO_bake_3p( STRINGVAL name, FLOATVAL s, FLOATVAL t, POINTVAL f, DEFVOIDPARAMVARIMPL )
5712
STATS_INC( SHD_so_bake );
5720
BEGIN_UNIFORM_SECTION
5722
BakingData *bd = bake_init( /*(char *) STRING( name ).c_str() */ );
5725
BEGIN_VARYING_SECTION
5730
rgb[ 0 ] = VECTOR( f ) [ 0 ];
5731
rgb[ 1 ] = VECTOR( f ) [ 1 ];
5732
rgb[ 2 ] = VECTOR( f ) [ 2 ];
5733
bake_3( bd, ( char * ) STRING( name ).c_str(), FLOAT( s ), FLOAT( t ), rgb );
5736
BEGIN_UNIFORM_SECTION
5741
STD_SOIMPL CqShaderExecEnv::SO_bake_3v( STRINGVAL name, FLOATVAL s, FLOATVAL t, VECTORVAL f, DEFVOIDPARAMVARIMPL )
5743
STATS_INC( SHD_so_bake );
5750
BEGIN_UNIFORM_SECTION
5752
BakingData *bd = bake_init( /*(char *) STRING( name ).c_str() */ );
5755
BEGIN_VARYING_SECTION
5760
rgb[ 0 ] = VECTOR( f ) [ 0 ];
5761
rgb[ 1 ] = VECTOR( f ) [ 1 ];
5762
rgb[ 2 ] = VECTOR( f ) [ 2 ];
5763
bake_3( bd, ( char * ) STRING( name ).c_str(), FLOAT( s ), FLOAT( t ), rgb );
5766
BEGIN_UNIFORM_SECTION
5772
// We manually decalr th
5773
STD_SOIMPL CqShaderExecEnv::SO_external( DSOMethod method, void *initData, DEFPARAMVARIMPL )
5775
STATS_INC( SHD_so_external );
5779
CHECKVARY( Result );
5781
for ( p = 0;p < cParams;p++ )
5783
CHECKVARY( apParams[ p ] );
5786
int dso_argc = cParams + 1; // dso_argv[0] is used for the return value
5787
void **dso_argv = new void * [ dso_argc ] ;
5789
// create storage for the returned value
5790
switch ( Result->Type() )
5794
dso_argv[ 0 ] = ( void* ) new TqFloat; break;
5801
dso_argv[ 0 ] = ( void* ) new TqFloat[ 3 ]; break;
5803
dso_argv[ 0 ] = ( void* ) new STRING_DESC;
5804
( ( STRING_DESC* ) dso_argv[ 0 ] ) ->s = NULL;
5805
( ( STRING_DESC* ) dso_argv[ 0 ] ) ->bufflen = 0;
5808
case type_sixteentuple:
5809
dso_argv[ 0 ] = ( void* ) new TqFloat[ 16 ];
5816
// Allocate space for the arguments
5817
for ( p = 1;p <= cParams;p++ )
5820
switch ( apParams[ p - 1 ] ->Type() )
5823
dso_argv[ p ] = ( void* ) new TqFloat; break;
5826
case type_triple: // This seems reasonable
5830
dso_argv[ p ] = ( void* ) new TqFloat[ 3 ]; break;
5832
dso_argv[ p ] = ( void* ) new STRING_DESC;
5833
( ( STRING_DESC* ) dso_argv[ p ] ) ->s = NULL;
5834
( ( STRING_DESC* ) dso_argv[ p ] ) ->bufflen = 0;
5837
case type_sixteentuple:
5838
dso_argv[ 0 ] = ( void* ) new TqFloat[ 16 ];
5847
BEGIN_VARYING_SECTION
5849
// Convert the arguments to the required format for the DSO
5850
for ( p = 1;p <= cParams;p++ )
5853
switch ( apParams[ p - 1 ] ->Type() )
5856
apParams[ p - 1 ] ->GetFloat( *( ( float* ) dso_argv[ p ] ), __iGrid );
5862
apParams[ p - 1 ] ->GetPoint( v, __iGrid );
5863
( ( float* ) dso_argv[ p ] ) [ 0 ] = v[ 0 ];
5864
( ( float* ) dso_argv[ p ] ) [ 1 ] = v[ 1 ];
5865
( ( float* ) dso_argv[ p ] ) [ 2 ] = v[ 2 ];
5868
case type_triple: // This seems reasonable
5872
apParams[ p - 1 ] ->GetVector( v, __iGrid );
5873
( ( float* ) dso_argv[ p ] ) [ 0 ] = v[ 0 ];
5874
( ( float* ) dso_argv[ p ] ) [ 1 ] = v[ 1 ];
5875
( ( float* ) dso_argv[ p ] ) [ 2 ] = v[ 2 ];
5881
apParams[ p - 1 ] ->GetNormal( v, __iGrid );
5882
( ( float* ) dso_argv[ p ] ) [ 0 ] = v[ 0 ];
5883
( ( float* ) dso_argv[ p ] ) [ 1 ] = v[ 1 ];
5884
( ( float* ) dso_argv[ p ] ) [ 2 ] = v[ 2 ];
5890
apParams[ p - 1 ] ->GetColor( c, __iGrid );
5891
( ( float* ) dso_argv[ p ] ) [ 0 ] = c[ 0 ];
5892
( ( float* ) dso_argv[ p ] ) [ 1 ] = c[ 1 ];
5893
( ( float* ) dso_argv[ p ] ) [ 2 ] = c[ 2 ];
5899
apParams[ p - 1 ] ->GetString( s, __iGrid );
5900
char *ps = new char[ s.size() + 1 ];
5901
strncpy ( ps, s.c_str(), s.size() + 1 );
5902
( ( STRING_DESC* ) dso_argv[ p ] ) ->s = ps;
5903
( ( STRING_DESC* ) dso_argv[ p ] ) ->bufflen = s.size() + 1;
5907
case type_sixteentuple:
5911
apParams[ p - 1 ] ->GetMatrix( m, __iGrid );
5912
for ( r = 0; r < 4; r++ )
5913
for ( c = 0; c < 4; c++ )
5914
( ( TqFloat* ) dso_argv[ p ] ) [ ( r * 4 ) + c ] = m[ r ][ c ];
5923
// Atlast, we call the shadeop method, looks rather dull after all this effort.
5924
method( initData, dso_argc, dso_argv );
5926
// Pass the returned value back to aqsis
5927
switch ( Result->Type() )
5932
TqFloat val = *( ( float* ) ( dso_argv[ 0 ] ) );
5933
Result->SetFloat( val, __iGrid );
5940
v[ 0 ] = ( ( float* ) dso_argv[ 0 ] ) [ 0 ];
5941
v[ 1 ] = ( ( float* ) dso_argv[ 0 ] ) [ 1 ];
5942
v[ 2 ] = ( ( float* ) dso_argv[ 0 ] ) [ 2 ];
5943
Result->SetPoint( v, __iGrid );
5946
case type_triple: // This seems reasonable
5950
v[ 0 ] = ( ( float* ) dso_argv[ 0 ] ) [ 0 ];
5951
v[ 1 ] = ( ( float* ) dso_argv[ 0 ] ) [ 1 ];
5952
v[ 2 ] = ( ( float* ) dso_argv[ 0 ] ) [ 2 ];
5953
Result->SetVector( v, __iGrid );
5959
v[ 0 ] = ( ( float* ) dso_argv[ 0 ] ) [ 0 ];
5960
v[ 1 ] = ( ( float* ) dso_argv[ 0 ] ) [ 1 ];
5961
v[ 2 ] = ( ( float* ) dso_argv[ 0 ] ) [ 2 ];
5962
Result->SetNormal( v, __iGrid );
5968
c[ 0 ] = ( ( float* ) dso_argv[ 0 ] ) [ 0 ];
5969
c[ 1 ] = ( ( float* ) dso_argv[ 0 ] ) [ 1 ];
5970
c[ 2 ] = ( ( float* ) dso_argv[ 0 ] ) [ 2 ];
5971
Result->SetColor( c, __iGrid );
5976
CqString s( ( ( STRING_DESC* ) dso_argv[ 0 ] ) ->s );
5977
Result->SetString( s, __iGrid );
5981
case type_sixteentuple:
5983
CqMatrix m( ( float* ) dso_argv[ 0 ] );
5984
Result->SetMatrix( m, __iGrid );
5989
std::cout << "Unsupported type" << std::endl;
5994
// Set the values that were altered by the Shadeop
5995
for ( p = 1;p <= cParams;p++ )
5997
switch ( apParams[ p - 1 ] ->Type() )
6001
TqFloat val = *( ( float* ) dso_argv[ p ] ) ;
6002
apParams[ p - 1 ] ->SetFloat( val, __iGrid );
6009
v[ 0 ] = ( ( float* ) dso_argv[ p ] ) [ 0 ];
6010
v[ 1 ] = ( ( float* ) dso_argv[ p ] ) [ 1 ];
6011
v[ 2 ] = ( ( float* ) dso_argv[ p ] ) [ 2 ];
6012
apParams[ p - 1 ] ->SetPoint( v, __iGrid );
6015
case type_triple: // This seems reasonable
6019
v[ 0 ] = ( ( float* ) dso_argv[ p ] ) [ 0 ];
6020
v[ 1 ] = ( ( float* ) dso_argv[ p ] ) [ 1 ];
6021
v[ 2 ] = ( ( float* ) dso_argv[ p ] ) [ 2 ];
6022
apParams[ p - 1 ] ->SetVector( v, __iGrid );
6028
v[ 0 ] = ( ( float* ) dso_argv[ p ] ) [ 0 ];
6029
v[ 1 ] = ( ( float* ) dso_argv[ p ] ) [ 1 ];
6030
v[ 2 ] = ( ( float* ) dso_argv[ p ] ) [ 2 ];
6031
apParams[ p - 1 ] ->SetNormal( v, __iGrid );
6037
c[ 0 ] = ( ( float* ) dso_argv[ p ] ) [ 0 ];
6038
c[ 1 ] = ( ( float* ) dso_argv[ p ] ) [ 1 ];
6039
c[ 2 ] = ( ( float* ) dso_argv[ p ] ) [ 2 ];
6040
apParams[ p - 1 ] ->SetColor( c, __iGrid );
6045
CqString s( ( ( STRING_DESC* ) dso_argv[ p ] ) ->s );
6046
apParams[ p - 1 ] ->SetString( s, __iGrid );
6050
case type_sixteentuple:
6052
CqMatrix m( ( float* ) dso_argv[ p ] );
6053
apParams[ p - 1 ] ->SetMatrix( m, __iGrid );
6064
// Free up the storage allocated for the return type
6065
switch ( Result->Type() )
6069
delete ( float* ) dso_argv[ 0 ]; break;
6071
case type_triple: // This seems reasonable
6076
delete[] ( float* ) dso_argv[ 0 ]; break;
6077
case type_string: // Need to look into these
6078
delete ( STRING_DESC* ) dso_argv[ 0 ]; break;
6080
case type_sixteentuple:
6081
delete[] ( float* ) dso_argv[ 0 ]; break;
6087
// Free up the storage allocated for the args
6088
for ( p = 1;p <= cParams;p++ )
6090
switch ( apParams[ p - 1 ] ->Type() )
6093
delete ( float* ) dso_argv[ p ]; break;
6100
delete[] ( float* ) dso_argv[ p ]; break;
6102
delete ( STRING_DESC* ) dso_argv[ p ]; break;
6104
case type_sixteentuple:
6105
delete[] ( float* ) dso_argv[ p ]; break;
6115
//----------------------------------------------------------------------
6116
// occlusion(occlmap,P,N,samples)
6117
STD_SOIMPL CqShaderExecEnv::SO_occlusion( STRINGVAL occlmap, FLOATVAL channel, POINTVAL P, NORMALVAL N, FLOATVAL samples, DEFPARAMVARIMPL )
6119
STATS_INC( SHD_so_occlusion );
6123
if ( NULL == QGetRenderContextI() )
6128
BEGIN_UNIFORM_SECTION
6129
GETSTRING( occlmap );
6131
GETFLOAT( samples );
6132
IqTextureMap* pMap = QGetRenderContextI() ->GetShadowMap( STRING( occlmap ) );
6135
CqVector3D L(0,0,-1);
6137
__fVarying = TqTrue;
6138
if ( pMap != 0 && pMap->IsValid() )
6140
std::valarray<TqFloat> fv;
6141
pMap->PrepareSampleOptions( paramMap );
6143
BEGIN_VARYING_SECTION
6144
// Storage for the final combined occlusion value.
6145
TqFloat occlsum = 0.0f;
6146
TqFloat dotsum = 0.0f;
6148
CqVector3D swidth = 0.0f, twidth = 0.0f;
6150
swidth = SO_DerivType<CqVector3D>( P, NULL, __iGrid, this );
6151
twidth = SO_DerivType<CqVector3D>( P, NULL, __iGrid, this );
6155
TqInt i = pMap->NumPages() - 1;
6156
for( ; i >= 0; i-- )
6158
// Check if the lightsource is behind the sample.
6159
CqVector3D Nl = pMap->GetMatrix(2, i) * NORMAL( N );
6160
TqFloat cosangle = Nl * L;
6161
if( cosangle < 0.0f )
6165
pMap->SampleMap( POINT( P ), swidth, twidth, fv, i );
6166
occlsum += cosangle * fv[0];
6170
SETFLOAT( Result, occlsum);
6175
BEGIN_VARYING_SECTION
6176
SETFLOAT( Result, 0.0f ); // Default, completely lit
6182
END_NAMESPACE( Aqsis )
6183
//---------------------------------------------------------------------