Torque3D Documentation / _generateds / shaderFeatureGLSL.h

shaderFeatureGLSL.h

Engine/source/shaderGen/GLSL/shaderFeatureGLSL.h

More...

Classes:

class

Detail map.

class

Diffuse color.

class

Base texture.

class

Diffuse vertex color.

class
class

Special feature used to mask out the RGB color for non-glow passes of glow materials.

class

Hardware Skinning.

class

This should be the final feature on most pixel shaders which encodes the color for the current HDR target format.

class

Special feature for unpacking imposter verts.

class
class

Overlay texture.

class

Reflect Cubemap.

class

Vertex lighting based on the normal and the light direction passed through the vertex color.

class

Tex Anim.

class
class

Baked lighting stored on the vertex color.

class

Vertex position.

class

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23#ifndef _SHADERGEN_GLSL_SHADERFEATUREGLSL_H_
 24#define _SHADERGEN_GLSL_SHADERFEATUREGLSL_H_
 25
 26#ifndef _SHADERFEATURE_H_
 27   #include "shaderGen/shaderFeature.h"
 28#endif
 29
 30struct LangElement;
 31struct MaterialFeatureData;
 32struct RenderPassData;
 33
 34
 35class ShaderFeatureGLSL : public ShaderFeature
 36{
 37public:
 38   ShaderFeatureGLSL();
 39
 40   ///
 41   Var* getOutTexCoord( const char *name,
 42                        const char *type,
 43                        bool mapsToSampler,
 44                        bool useTexAnim,
 45                        MultiLine *meta,
 46                        Vector<ShaderComponent*> &componentList );
 47
 48   /// Returns an input texture coord by name adding it
 49   /// to the input connector if it doesn't exist.
 50   static Var* getInTexCoord( const char *name,
 51                              const char *type,
 52                              bool mapsToSampler,
 53                              Vector<ShaderComponent*> &componentList );
 54
 55   static Var* getInColor( const char *name,
 56                           const char *type,
 57                           Vector<ShaderComponent*> &componentList );
 58
 59   ///
 60   static Var* addOutVpos( MultiLine *meta,
 61                           Vector<ShaderComponent*> &componentList );
 62
 63   /// Returns the VPOS input register for the pixel shader.
 64   static Var* getInVpos(  MultiLine *meta,
 65                           Vector<ShaderComponent*> &componentList );
 66
 67   /// Returns the "objToTangentSpace" transform or creates one if this
 68   /// is the first feature to need it.
 69   Var* getOutObjToTangentSpace( Vector<ShaderComponent*> &componentList,
 70                                 MultiLine *meta,
 71                                 const MaterialFeatureData &fd );
 72
 73   /// Returns the existing output "outWorldToTangent" transform or 
 74   /// creates one if this is the first feature to need it.
 75   Var* getOutWorldToTangent( Vector<ShaderComponent*> &componentList,
 76                              MultiLine *meta,
 77                              const MaterialFeatureData &fd );
 78
 79   /// Returns the input "worldToTanget" space transform 
 80   /// adding it to the input connector if it doesn't exist.
 81   static Var* getInWorldToTangent( Vector<ShaderComponent*> &componentList );
 82   
 83   /// Returns the existing output "outViewToTangent" transform or 
 84   /// creates one if this is the first feature to need it.
 85   Var* getOutViewToTangent( Vector<ShaderComponent*> &componentList,
 86      MultiLine *meta,
 87      const MaterialFeatureData &fd );
 88
 89   /// Returns the input "viewToTangent" space transform 
 90   /// adding it to the input connector if it doesn't exist.
 91   static Var* getInViewToTangent( Vector<ShaderComponent*> &componentList );
 92   
 93   /// Calculates the world space position in the vertex shader and 
 94   /// assigns it to the passed language element.  It does not pass 
 95   /// it across the connector to the pixel shader.
 96   /// @see addOutWsPosition
 97   void getWsPosition(  Vector<ShaderComponent*> &componentList,                
 98                      bool useInstancing,
 99                      MultiLine *meta,
100                      LangElement *wsPosition );
101   
102   /// Adds the "wsPosition" to the input connector if it doesn't exist.
103   Var* addOutWsPosition(  Vector<ShaderComponent*> &componentList,             
104                         bool useInstancing,
105                         MultiLine *meta );
106   
107   /// Returns the input world space position from the connector.
108   static Var* getInWsPosition( Vector<ShaderComponent*> &componentList );
109   
110   /// Returns the world space view vector from the wsPosition.
111   static Var* getWsView( Var *wsPosition, MultiLine *meta );
112   
113   /// Returns the input normal map texture.
114   static Var* getNormalMapTex();
115   
116   ///
117   Var* addOutDetailTexCoord( Vector<ShaderComponent*> &componentList, 
118                             MultiLine *meta,
119                             bool useTexAnim );
120
121   ///
122   Var* getObjTrans( Vector<ShaderComponent*> &componentList,                                       
123                    bool useInstancing,
124                    MultiLine *meta );
125   
126   ///
127   Var* getModelView( Vector<ShaderComponent*> &componentList,                                       
128                     bool useInstancing,
129                     MultiLine *meta );
130   
131   ///
132   Var* getWorldView( Vector<ShaderComponent*> &componentList,                
133                     bool useInstancing,
134                     MultiLine *meta );
135   
136   ///
137   Var* getInvWorldView( Vector<ShaderComponent*> &componentList,                                       
138                        bool useInstancing,
139                        MultiLine *meta );
140      
141   // ShaderFeature
142   Var* getVertTexCoord( const String &name );
143   LangElement* setupTexSpaceMat(  Vector<ShaderComponent*> &componentList, Var **texSpaceMat );
144   LangElement* assignColor( LangElement *elem, Material::BlendOp blend, LangElement *lerpElem = NULL, ShaderFeature::OutputTarget outputTarget = ShaderFeature::DefaultTarget );
145   LangElement* expandNormalMap( LangElement *sampleNormalOp, LangElement *normalDecl, LangElement *normalVar, const MaterialFeatureData &fd );
146};
147
148
149class NamedFeatureGLSL : public ShaderFeatureGLSL
150{
151protected:
152   String mName;
153
154public:
155   NamedFeatureGLSL( const String &name )
156      : mName( name )
157   {}
158
159   virtual String getName() { return mName; }
160};
161
162class RenderTargetZeroGLSL : public ShaderFeatureGLSL
163{
164protected:
165   ShaderFeature::OutputTarget mOutputTargetMask;
166   String mFeatureName;
167   
168public:
169   RenderTargetZeroGLSL( const ShaderFeature::OutputTarget target )
170   : mOutputTargetMask( target )
171   {
172      char buffer[256];
173      dSprintf(buffer, sizeof(buffer), "Render Target Output = 0.0, output mask %04b", mOutputTargetMask);
174      mFeatureName = buffer;
175   }
176   
177   virtual String getName() { return mFeatureName; }
178   
179   virtual void processPix( Vector<ShaderComponent*> &componentList, 
180                           const MaterialFeatureData &fd );
181   
182   virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const { return mOutputTargetMask; }
183};
184
185
186/// Vertex position
187class VertPositionGLSL : public ShaderFeatureGLSL
188{
189public:
190   virtual void processVert( Vector<ShaderComponent*> &componentList,
191                             const MaterialFeatureData &fd );
192                             
193   virtual String getName()
194   {
195      return "Vert Position";
196   }
197
198   virtual void determineFeature(   Material *material,
199                                    const GFXVertexFormat *vertexFormat,
200                                    U32 stageNum,
201                                    const FeatureType &type,
202                                    const FeatureSet &features,
203                                    MaterialFeatureData *outFeatureData );
204
205};
206
207
208/// Vertex lighting based on the normal and the light 
209/// direction passed through the vertex color.
210class RTLightingFeatGLSL : public ShaderFeatureGLSL
211{
212protected:
213
214   ShaderIncludeDependency mDep;
215
216public:
217
218   RTLightingFeatGLSL();
219
220   virtual void processVert( Vector<ShaderComponent*> &componentList,
221                             const MaterialFeatureData &fd );
222
223   virtual void processPix( Vector<ShaderComponent*> &componentList, 
224                            const MaterialFeatureData &fd );
225
226   virtual Material::BlendOp getBlendOp(){ return Material::None; }
227   
228   virtual Resources getResources( const MaterialFeatureData &fd );
229
230   virtual String getName()
231   {
232      return "RT Lighting";
233   }
234};
235
236
237/// Base texture
238class DiffuseMapFeatGLSL : public ShaderFeatureGLSL
239{
240
241protected:
242
243   ShaderIncludeDependency mTorqueDep;
244public:
245   DiffuseMapFeatGLSL();
246   virtual void processVert( Vector<ShaderComponent*> &componentList,
247                             const MaterialFeatureData &fd );
248
249   virtual void processPix( Vector<ShaderComponent*> &componentList, 
250                            const MaterialFeatureData &fd );
251
252   virtual U32 getOutputTargets(const MaterialFeatureData &fd) const;
253
254   virtual Material::BlendOp getBlendOp(){ return Material::LerpAlpha; }
255
256   virtual Resources getResources( const MaterialFeatureData &fd );
257
258   // Sets textures and texture flags for current pass
259   virtual void setTexData( Material::StageData &stageDat,
260                            const MaterialFeatureData &fd,
261                            RenderPassData &passData,
262                            U32 &texIndex );
263                            
264   virtual String getName()
265   {
266      return "Base Texture";
267   }
268};
269
270
271/// Overlay texture
272class OverlayTexFeatGLSL : public ShaderFeatureGLSL
273{
274public:
275   virtual void processVert( Vector<ShaderComponent*> &componentList,
276                             const MaterialFeatureData &fd );
277
278   virtual void processPix( Vector<ShaderComponent*> &componentList, 
279                            const MaterialFeatureData &fd );
280
281   virtual Material::BlendOp getBlendOp(){ return Material::LerpAlpha; }
282
283   virtual Resources getResources( const MaterialFeatureData &fd );
284
285   // Sets textures and texture flags for current pass
286   virtual void setTexData( Material::StageData &stageDat,
287                            const MaterialFeatureData &fd,
288                            RenderPassData &passData,
289                            U32 &texIndex );
290
291   virtual String getName()
292   {
293      return "Overlay Texture";
294   }
295};
296
297
298/// Diffuse color
299class DiffuseFeatureGLSL : public ShaderFeatureGLSL
300{
301public:   
302   virtual void processPix(   Vector<ShaderComponent*> &componentList, 
303                              const MaterialFeatureData &fd );
304
305   virtual Material::BlendOp getBlendOp(){ return Material::None; }
306
307   virtual U32 getOutputTargets(const MaterialFeatureData &fd) const;
308
309   virtual String getName()
310   {
311      return "Diffuse Color";
312   }
313};
314
315/// Diffuse vertex color
316class DiffuseVertColorFeatureGLSL : public ShaderFeatureGLSL
317{
318public:   
319
320   virtual void processVert(  Vector< ShaderComponent*>& componentList,
321                              const MaterialFeatureData& fd );
322   virtual void processPix(   Vector< ShaderComponent*>&componentList, 
323                              const MaterialFeatureData& fd );
324
325   virtual Material::BlendOp getBlendOp(){ return Material::None; }
326
327   virtual String getName()
328   {
329      return "Diffuse Vertex Color";
330   }
331};
332
333/// Lightmap
334class LightmapFeatGLSL : public ShaderFeatureGLSL
335{
336public:
337   virtual void processVert(  Vector<ShaderComponent*> &componentList,
338                              const MaterialFeatureData &fd );
339
340   virtual void processPix(   Vector<ShaderComponent*> &componentList, 
341                              const MaterialFeatureData &fd );
342
343   virtual Material::BlendOp getBlendOp(){ return Material::LerpAlpha; }
344
345   virtual Resources getResources( const MaterialFeatureData &fd );
346
347   // Sets textures and texture flags for current pass
348   virtual void setTexData( Material::StageData &stageDat,
349                            const MaterialFeatureData &fd,
350                            RenderPassData &passData,
351                            U32 &texIndex );
352                            
353   virtual String getName()
354   {
355      return "Lightmap";
356   }
357   
358   virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const;
359};
360
361
362/// Tonemap
363class TonemapFeatGLSL : public ShaderFeatureGLSL
364{
365public:
366   virtual void processVert(  Vector<ShaderComponent*> &componentList,
367                              const MaterialFeatureData &fd );
368
369   virtual void processPix(   Vector<ShaderComponent*> &componentList, 
370                              const MaterialFeatureData &fd );
371
372   virtual Material::BlendOp getBlendOp(){ return Material::LerpAlpha; }
373
374   virtual Resources getResources( const MaterialFeatureData &fd );
375
376   // Sets textures and texture flags for current pass
377   virtual void setTexData( Material::StageData &stageDat,
378                            const MaterialFeatureData &fd,
379                            RenderPassData &passData,
380                            U32 &texIndex );
381                            
382   virtual String getName()
383   {
384      return "Tonemap";
385   }
386   
387   virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const;
388};
389
390
391/// Baked lighting stored on the vertex color
392class VertLitGLSL : public ShaderFeatureGLSL
393{
394public:
395   virtual void processVert( Vector<ShaderComponent*> &componentList,
396                             const MaterialFeatureData &fd );
397
398   virtual void processPix( Vector<ShaderComponent*> &componentList, 
399                            const MaterialFeatureData &fd );
400
401   virtual Material::BlendOp getBlendOp(){ return Material::None; }
402   
403   virtual String getName()
404   {
405      return "Vert Lit";
406   }
407   
408   virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const;
409};
410
411
412/// Detail map
413class DetailFeatGLSL : public ShaderFeatureGLSL
414{
415public:
416   virtual void processVert( Vector<ShaderComponent*> &componentList,
417                             const MaterialFeatureData &fd );
418
419   virtual void processPix( Vector<ShaderComponent*> &componentList, 
420                            const MaterialFeatureData &fd );
421
422   virtual Resources getResources( const MaterialFeatureData &fd );
423
424   virtual Material::BlendOp getBlendOp(){ return Material::Mul; }
425
426   // Sets textures and texture flags for current pass
427   virtual void setTexData( Material::StageData &stageDat,
428                            const MaterialFeatureData &fd,
429                            RenderPassData &passData,
430                            U32 &texIndex );
431
432   virtual String getName()
433   {
434      return "Detail";
435   }
436};
437
438
439/// Reflect Cubemap
440class ReflectCubeFeatGLSL : public ShaderFeatureGLSL
441{
442public:
443   virtual void processVert( Vector<ShaderComponent*> &componentList,
444                             const MaterialFeatureData &fd );
445
446   virtual void processPix( Vector<ShaderComponent*> &componentList, 
447                            const MaterialFeatureData &fd );
448
449   virtual Resources getResources( const MaterialFeatureData &fd );
450
451   // Sets textures and texture flags for current pass
452   virtual void setTexData( Material::StageData &stageDat,
453                            const MaterialFeatureData &fd,
454                            RenderPassData &passData,
455                            U32 &texIndex );
456
457   virtual String getName()
458   {
459      return "Reflect Cube";
460   }
461};
462
463
464/// Fog
465class FogFeatGLSL : public ShaderFeatureGLSL
466{
467protected:
468
469   ShaderIncludeDependency mFogDep;
470
471public:
472   FogFeatGLSL();
473
474   virtual void processVert( Vector<ShaderComponent*> &componentList,
475                             const MaterialFeatureData &fd );
476
477   virtual void processPix( Vector<ShaderComponent*> &componentList, 
478                            const MaterialFeatureData &fd );
479
480   virtual Resources getResources( const MaterialFeatureData &fd );
481
482   virtual Material::BlendOp getBlendOp() { return Material::LerpAlpha; }
483
484   virtual String getName()
485   {
486      return "Fog";
487   }
488};
489
490
491/// Tex Anim
492class TexAnimGLSL : public ShaderFeatureGLSL
493{
494public:
495   virtual Material::BlendOp getBlendOp() { return Material::None; }
496
497   virtual String getName()
498   {
499      return "Texture Animation";
500   }
501};
502
503
504/// Visibility
505class VisibilityFeatGLSL : public ShaderFeatureGLSL
506{
507protected:
508
509   ShaderIncludeDependency mTorqueDep;
510
511public:
512
513   VisibilityFeatGLSL();
514
515   virtual void processVert( Vector<ShaderComponent*> &componentList,
516                             const MaterialFeatureData &fd );
517
518   virtual void processPix( Vector<ShaderComponent*> &componentList, 
519                            const MaterialFeatureData &fd );
520
521   virtual Resources getResources( const MaterialFeatureData &fd );
522
523   virtual Material::BlendOp getBlendOp() { return Material::None; }
524
525   virtual String getName()
526   {
527      return "Visibility";
528   }
529};
530
531
532///
533class AlphaTestGLSL : public ShaderFeatureGLSL
534{
535public:
536   virtual void processPix(   Vector<ShaderComponent*> &componentList, 
537                              const MaterialFeatureData &fd );
538
539   virtual Material::BlendOp getBlendOp() { return Material::None; }
540
541   virtual String getName()
542   {
543      return "Alpha Test";
544   }
545};
546
547
548/// Special feature used to mask out the RGB color for
549/// non-glow passes of glow materials.
550/// @see RenderGlowMgr
551class GlowMaskGLSL : public ShaderFeatureGLSL
552{
553public:
554   virtual void processPix(   Vector<ShaderComponent*> &componentList, 
555                              const MaterialFeatureData &fd );
556
557   virtual Material::BlendOp getBlendOp() { return Material::None; }
558
559   virtual String getName()
560   {
561      return "Glow Mask";
562   }
563};
564
565/// This should be the final feature on most pixel shaders which
566/// encodes the color for the current HDR target format.
567/// @see HDRPostFx
568/// @see LightManager
569/// @see torque.glsl
570class HDROutGLSL : public ShaderFeatureGLSL
571{
572protected:
573   
574   ShaderIncludeDependency mTorqueDep;
575   
576public:
577   
578   HDROutGLSL();
579   
580   virtual void processPix(   Vector<ShaderComponent*> &componentList, 
581                           const MaterialFeatureData &fd );
582   
583   virtual Material::BlendOp getBlendOp() { return Material::None; }
584   
585   virtual String getName() { return "HDR Output"; }
586};
587
588///
589class FoliageFeatureGLSL : public ShaderFeatureGLSL
590{
591protected:
592   
593   ShaderIncludeDependency mDep;
594   
595public:
596   
597   FoliageFeatureGLSL();
598   
599   virtual void processVert( Vector<ShaderComponent*> &componentList,
600                            const MaterialFeatureData &fd );
601
602   virtual void processPix( Vector<ShaderComponent*> &componentList,
603                           const MaterialFeatureData &fd );   
604   
605   virtual String getName()
606   {
607      return "Foliage Feature";
608   }
609   
610   virtual void determineFeature( Material *material, 
611                                 const GFXVertexFormat *vertexFormat,
612                                 U32 stageNum,
613                                 const FeatureType &type,
614                                 const FeatureSet &features,
615                                 MaterialFeatureData *outFeatureData );
616
617   virtual ShaderFeatureConstHandles* createConstHandles( GFXShader *shader, SimObject *userObject );   
618};
619
620class ParticleNormalFeatureGLSL : public ShaderFeatureGLSL
621{
622public:
623   
624   virtual void processVert( Vector<ShaderComponent*> &componentList,
625                            const MaterialFeatureData &fd );
626   
627   virtual String getName()
628   {
629      return "Particle Normal Generation Feature";
630   }
631   
632};
633
634
635/// Special feature for unpacking imposter verts.
636/// @see RenderImposterMgr
637class ImposterVertFeatureGLSL : public ShaderFeatureGLSL
638{
639protected:
640   
641   ShaderIncludeDependency mDep;
642   
643public:
644
645   ImposterVertFeatureGLSL();
646
647   virtual void processVert(  Vector<ShaderComponent*> &componentList,
648                            const MaterialFeatureData &fd );
649
650   virtual void processPix(  Vector<ShaderComponent*> &componentList,
651                           const MaterialFeatureData &fd );
652   
653   virtual String getName() { return "Imposter Vert"; }
654   
655   virtual void determineFeature( Material *material, 
656                                 const GFXVertexFormat *vertexFormat,
657                                 U32 stageNum,
658                                 const FeatureType &type,
659                                 const FeatureSet &features,
660                                 MaterialFeatureData *outFeatureData );
661};
662
663/// Hardware Skinning
664class HardwareSkinningFeatureGLSL : public ShaderFeatureGLSL
665{
666protected:
667
668public:
669
670   virtual void processVert(Vector<ShaderComponent*> &componentList,
671      const MaterialFeatureData &fd);
672
673   virtual String getName() { return "Hardware Skinning"; }
674};
675
676#endif // _SHADERGEN_GLSL_SHADERFEATUREGLSL_H_
677