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

Reflection Probes.

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