Torque3D Documentation / _generateds / shaderFeatureHLSL.h

shaderFeatureHLSL.h

Engine/source/shaderGen/HLSL/shaderFeatureHLSL.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_HLSL_SHADERFEATUREHLSL_H_
 24#define _SHADERGEN_HLSL_SHADERFEATUREHLSL_H_
 25
 26#ifndef _SHADERFEATURE_H_
 27#include "shaderGen/shaderFeature.h"
 28#endif
 29
 30struct LangElement;
 31struct MaterialFeatureData;
 32struct RenderPassData;
 33
 34
 35class ShaderFeatureHLSL : public ShaderFeature
 36{
 37public:
 38   ShaderFeatureHLSL();
 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   Var* getInWorldNormal(Vector<ShaderComponent*>& componentList);
143
144   // ShaderFeature
145   Var* getVertTexCoord( const String &name );
146   LangElement* setupTexSpaceMat(  Vector<ShaderComponent*> &componentList, Var **texSpaceMat );
147   LangElement* assignColor( LangElement *elem, Material::BlendOp blend, LangElement *lerpElem = NULL, ShaderFeature::OutputTarget outputTarget = ShaderFeature::DefaultTarget );
148   LangElement* expandNormalMap( LangElement *sampleNormalOp, LangElement *normalDecl, LangElement *normalVar, const MaterialFeatureData &fd );
149};
150
151
152class NamedFeatureHLSL : public ShaderFeatureHLSL
153{
154protected:
155   String mName;
156
157public:
158   NamedFeatureHLSL( const String &name )
159      : mName( name )
160   {}
161
162   virtual String getName() { return mName; }
163};
164
165class RenderTargetZeroHLSL : public ShaderFeatureHLSL
166{
167protected:
168   ShaderFeature::OutputTarget mOutputTargetMask;
169   String mFeatureName;
170
171public:
172   RenderTargetZeroHLSL( const ShaderFeature::OutputTarget target )
173      : mOutputTargetMask( target )
174   {
175      char buffer[256];
176      dSprintf(buffer, sizeof(buffer), "Render Target Output = 0.0, output mask %04b", mOutputTargetMask);
177      mFeatureName = buffer;
178   }
179
180   virtual String getName() { return mFeatureName; }
181
182   virtual void processPix( Vector<ShaderComponent*> &componentList, 
183      const MaterialFeatureData &fd );
184   
185   virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const { return mOutputTargetMask; }
186};
187
188
189/// Vertex position
190class VertPositionHLSL : public ShaderFeatureHLSL
191{
192public:
193   virtual void processVert( Vector<ShaderComponent*> &componentList,
194                             const MaterialFeatureData &fd );
195
196   virtual void processPix( Vector<ShaderComponent*> &componentList,
197                            const MaterialFeatureData &fd);
198                             
199   virtual String getName()
200   {
201      return "Vert Position";
202   }
203
204   virtual void determineFeature(   Material *material,
205                                    const GFXVertexFormat *vertexFormat,
206                                    U32 stageNum,
207                                    const FeatureType &type,
208                                    const FeatureSet &features,
209                                    MaterialFeatureData *outFeatureData );
210
211};
212
213
214/// Vertex lighting based on the normal and the light 
215/// direction passed through the vertex color.
216class RTLightingFeatHLSL : public ShaderFeatureHLSL
217{
218protected:
219
220   ShaderIncludeDependency mDep;
221
222public:
223
224   RTLightingFeatHLSL();
225
226   virtual void processVert( Vector<ShaderComponent*> &componentList,
227                             const MaterialFeatureData &fd );
228
229   virtual void processPix( Vector<ShaderComponent*> &componentList, 
230                            const MaterialFeatureData &fd );
231
232   virtual Material::BlendOp getBlendOp(){ return Material::None; }
233   
234   virtual Resources getResources( const MaterialFeatureData &fd );
235
236   virtual String getName()
237   {
238      return "RT Lighting";
239   }
240};
241
242
243/// Base texture
244class DiffuseMapFeatHLSL : public ShaderFeatureHLSL
245{
246protected:
247
248   ShaderIncludeDependency mTorqueDep;
249
250public:
251   DiffuseMapFeatHLSL();
252   virtual void processVert( Vector<ShaderComponent*> &componentList,
253                             const MaterialFeatureData &fd );
254
255   virtual void processPix( Vector<ShaderComponent*> &componentList, 
256                            const MaterialFeatureData &fd );
257
258   virtual U32 getOutputTargets(const MaterialFeatureData &fd) const;
259
260   virtual Material::BlendOp getBlendOp(){ return Material::LerpAlpha; }
261
262   virtual Resources getResources( const MaterialFeatureData &fd );
263
264   // Sets textures and texture flags for current pass
265   virtual void setTexData( Material::StageData &stageDat,
266                            const MaterialFeatureData &fd,
267                            RenderPassData &passData,
268                            U32 &texIndex );
269                            
270   virtual String getName()
271   {
272      return "Base Texture";
273   }
274};
275
276
277/// Overlay texture
278class OverlayTexFeatHLSL : public ShaderFeatureHLSL
279{
280public:
281   virtual void processVert( Vector<ShaderComponent*> &componentList,
282                             const MaterialFeatureData &fd );
283
284   virtual void processPix( Vector<ShaderComponent*> &componentList, 
285                            const MaterialFeatureData &fd );
286
287   virtual Material::BlendOp getBlendOp(){ return Material::LerpAlpha; }
288
289   virtual Resources getResources( const MaterialFeatureData &fd );
290
291   // Sets textures and texture flags for current pass
292   virtual void setTexData( Material::StageData &stageDat,
293                            const MaterialFeatureData &fd,
294                            RenderPassData &passData,
295                            U32 &texIndex );
296
297   virtual String getName()
298   {
299      return "Overlay Texture";
300   }
301};
302
303
304/// Diffuse color
305class DiffuseFeatureHLSL : public ShaderFeatureHLSL
306{
307public:   
308   virtual void processPix(   Vector<ShaderComponent*> &componentList, 
309                              const MaterialFeatureData &fd );
310
311   virtual Material::BlendOp getBlendOp(){ return Material::None; }
312
313   virtual U32 getOutputTargets(const MaterialFeatureData &fd) const;
314   virtual String getName()
315   {
316      return "Diffuse Color";
317   }
318};
319
320/// Diffuse vertex color
321class DiffuseVertColorFeatureHLSL : public ShaderFeatureHLSL
322{
323public:   
324
325   virtual void processVert(  Vector< ShaderComponent*>& componentList,
326                              const MaterialFeatureData& fd );
327   virtual void processPix(   Vector< ShaderComponent*>&componentList, 
328                              const MaterialFeatureData& fd );
329
330   virtual Material::BlendOp getBlendOp(){ return Material::None; }
331
332   virtual String getName()
333   {
334      return "Diffuse Vertex Color";
335   }
336};
337
338/// Lightmap
339class LightmapFeatHLSL : public ShaderFeatureHLSL
340{
341public:
342   virtual void processVert(  Vector<ShaderComponent*> &componentList,
343                              const MaterialFeatureData &fd );
344
345   virtual void processPix(   Vector<ShaderComponent*> &componentList, 
346                              const MaterialFeatureData &fd );
347
348   virtual Material::BlendOp getBlendOp(){ return Material::LerpAlpha; }
349
350   virtual Resources getResources( const MaterialFeatureData &fd );
351
352   // Sets textures and texture flags for current pass
353   virtual void setTexData( Material::StageData &stageDat,
354                            const MaterialFeatureData &fd,
355                            RenderPassData &passData,
356                            U32 &texIndex );
357                            
358   virtual String getName()
359   {
360      return "Lightmap";
361   }
362
363   virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const;
364};
365
366
367/// Tonemap
368class TonemapFeatHLSL : public ShaderFeatureHLSL
369{
370public:
371   virtual void processVert(  Vector<ShaderComponent*> &componentList,
372                              const MaterialFeatureData &fd );
373
374   virtual void processPix(   Vector<ShaderComponent*> &componentList, 
375                              const MaterialFeatureData &fd );
376
377   virtual Material::BlendOp getBlendOp(){ return Material::LerpAlpha; }
378
379   virtual Resources getResources( const MaterialFeatureData &fd );
380
381   // Sets textures and texture flags for current pass
382   virtual void setTexData( Material::StageData &stageDat,
383                            const MaterialFeatureData &fd,
384                            RenderPassData &passData,
385                            U32 &texIndex );
386                            
387   virtual String getName()
388   {
389      return "Tonemap";
390   }
391
392   virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const;
393};
394
395
396/// Baked lighting stored on the vertex color
397class VertLitHLSL : public ShaderFeatureHLSL
398{
399public:
400   virtual void processVert( Vector<ShaderComponent*> &componentList,
401                             const MaterialFeatureData &fd );
402
403   virtual void processPix( Vector<ShaderComponent*> &componentList, 
404                            const MaterialFeatureData &fd );
405
406   virtual Material::BlendOp getBlendOp(){ return Material::None; }
407   
408   virtual String getName()
409   {
410      return "Vert Lit";
411   }
412
413   virtual U32 getOutputTargets( const MaterialFeatureData &fd ) const;
414};
415
416
417/// Detail map
418class DetailFeatHLSL : public ShaderFeatureHLSL
419{
420public:
421   virtual void processVert( Vector<ShaderComponent*> &componentList,
422                             const MaterialFeatureData &fd );
423
424   virtual void processPix( Vector<ShaderComponent*> &componentList, 
425                            const MaterialFeatureData &fd );
426
427   virtual Resources getResources( const MaterialFeatureData &fd );
428
429   virtual Material::BlendOp getBlendOp(){ return Material::Mul; }
430
431   // Sets textures and texture flags for current pass
432   virtual void setTexData( Material::StageData &stageDat,
433                            const MaterialFeatureData &fd,
434                            RenderPassData &passData,
435                            U32 &texIndex );
436
437   virtual String getName()
438   {
439      return "Detail";
440   }
441};
442
443
444/// Reflect Cubemap
445class ReflectCubeFeatHLSL : public ShaderFeatureHLSL
446{
447public:
448   virtual void processVert( Vector<ShaderComponent*> &componentList,
449                             const MaterialFeatureData &fd );
450
451   virtual void processPix( Vector<ShaderComponent*> &componentList, 
452                            const MaterialFeatureData &fd );
453
454   virtual Resources getResources( const MaterialFeatureData &fd );
455
456   // Sets textures and texture flags for current pass
457   virtual void setTexData( Material::StageData &stageDat,
458                            const MaterialFeatureData &fd,
459                            RenderPassData &passData,
460                            U32 &texIndex );
461
462   virtual String getName()
463   {
464      return "Reflect Cube";
465   }
466};
467
468
469/// Fog
470class FogFeatHLSL : public ShaderFeatureHLSL
471{
472protected:
473
474   ShaderIncludeDependency mFogDep;
475
476public:
477   FogFeatHLSL();
478
479   virtual void processVert( Vector<ShaderComponent*> &componentList,
480                             const MaterialFeatureData &fd );
481
482   virtual void processPix( Vector<ShaderComponent*> &componentList, 
483                            const MaterialFeatureData &fd );
484
485   virtual Resources getResources( const MaterialFeatureData &fd );
486
487   virtual Material::BlendOp getBlendOp() { return Material::LerpAlpha; }
488
489   virtual String getName()
490   {
491      return "Fog";
492   }
493};
494
495
496/// Tex Anim
497class TexAnimHLSL : public ShaderFeatureHLSL
498{
499public:
500   virtual Material::BlendOp getBlendOp() { return Material::None; }
501
502   virtual String getName()
503   {
504      return "Texture Animation";
505   }
506};
507
508
509/// Visibility
510class VisibilityFeatHLSL : public ShaderFeatureHLSL
511{
512protected:
513
514   ShaderIncludeDependency mTorqueDep;
515
516public:
517
518   VisibilityFeatHLSL();
519
520   virtual void processVert( Vector<ShaderComponent*> &componentList,
521                             const MaterialFeatureData &fd );
522
523   virtual void processPix( Vector<ShaderComponent*> &componentList, 
524                            const MaterialFeatureData &fd );
525
526   virtual Resources getResources( const MaterialFeatureData &fd );
527
528   virtual Material::BlendOp getBlendOp() { return Material::None; }
529
530   virtual String getName()
531   {
532      return "Visibility";
533   }
534};
535
536
537///
538class AlphaTestHLSL : public ShaderFeatureHLSL
539{
540public:
541   virtual void processPix(   Vector<ShaderComponent*> &componentList, 
542                              const MaterialFeatureData &fd );
543
544   virtual Material::BlendOp getBlendOp() { return Material::None; }
545
546   virtual String getName()
547   {
548      return "Alpha Test";
549   }
550};
551
552
553/// Special feature used to mask out the RGB color for
554/// non-glow passes of glow materials.
555/// @see RenderGlowMgr
556class GlowMaskHLSL : public ShaderFeatureHLSL
557{
558public:
559   virtual void processPix(   Vector<ShaderComponent*> &componentList, 
560                              const MaterialFeatureData &fd );
561
562   virtual Material::BlendOp getBlendOp() { return Material::None; }
563
564   virtual String getName()
565   {
566      return "Glow Mask";
567   }
568};
569
570/// This should be the final feature on most pixel shaders which
571/// encodes the color for the current HDR target format.
572/// @see HDRPostFx
573/// @see LightManager
574/// @see torque.hlsl
575class HDROutHLSL : public ShaderFeatureHLSL
576{
577protected:
578
579   ShaderIncludeDependency mTorqueDep;
580
581public:
582
583   HDROutHLSL();
584
585   virtual void processPix(   Vector<ShaderComponent*> &componentList, 
586                              const MaterialFeatureData &fd );
587
588   virtual Material::BlendOp getBlendOp() { return Material::None; }
589
590   virtual String getName() { return "HDR Output"; }
591};
592
593///
594class FoliageFeatureHLSL : public ShaderFeatureHLSL
595{
596protected:
597
598   ShaderIncludeDependency mDep;
599
600public:
601
602   FoliageFeatureHLSL();
603
604   virtual void processVert( Vector<ShaderComponent*> &componentList,
605                             const MaterialFeatureData &fd );
606
607   virtual void processPix( Vector<ShaderComponent*> &componentList,
608                           const MaterialFeatureData &fd );   
609
610   virtual String getName()
611   {
612      return "Foliage Feature";
613   }
614
615   virtual void determineFeature( Material *material, 
616                                  const GFXVertexFormat *vertexFormat,
617                                  U32 stageNum,
618                                  const FeatureType &type,
619                                  const FeatureSet &features,
620                                  MaterialFeatureData *outFeatureData );
621
622   virtual ShaderFeatureConstHandles* createConstHandles( GFXShader *shader, SimObject *userObject );   
623};
624
625class ParticleNormalFeatureHLSL : public ShaderFeatureHLSL
626{
627public:
628
629   virtual void processVert( Vector<ShaderComponent*> &componentList,
630      const MaterialFeatureData &fd );
631
632   virtual String getName()
633   {
634      return "Particle Normal Generation Feature";
635   }
636
637};
638
639
640/// Special feature for unpacking imposter verts.
641/// @see RenderImposterMgr
642class ImposterVertFeatureHLSL : public ShaderFeatureHLSL
643{
644protected:
645
646   ShaderIncludeDependency mDep;
647
648public:
649
650   ImposterVertFeatureHLSL();
651
652   virtual void processVert(  Vector<ShaderComponent*> &componentList,
653                              const MaterialFeatureData &fd );
654
655   virtual void processPix(  Vector<ShaderComponent*> &componentList,
656                             const MaterialFeatureData &fd );
657
658   virtual String getName() { return "Imposter Vert"; }
659
660   virtual void determineFeature( Material *material, 
661                                  const GFXVertexFormat *vertexFormat,
662                                  U32 stageNum,
663                                  const FeatureType &type,
664                                  const FeatureSet &features,
665                                  MaterialFeatureData *outFeatureData );
666};
667
668/// Hardware Skinning
669class HardwareSkinningFeatureHLSL : public ShaderFeatureHLSL
670{
671protected:
672
673public:
674
675   virtual void processVert(  Vector<ShaderComponent*> &componentList,
676                              const MaterialFeatureData &fd );
677
678   virtual String getName() { return "Hardware Skinning"; }
679};
680
681/// Reflection Probes
682class ReflectionProbeFeatHLSL : public ShaderFeatureHLSL
683{
684protected:
685   ShaderIncludeDependency mDep;
686
687public:
688   ReflectionProbeFeatHLSL();
689
690   virtual void processVert(Vector<ShaderComponent*>& componentList,
691      const MaterialFeatureData& fd);
692
693   virtual void processPix(Vector<ShaderComponent*> &componentList,
694      const MaterialFeatureData &fd);
695
696   virtual Resources getResources(const MaterialFeatureData &fd);
697
698   // Sets textures and texture flags for current pass
699   virtual void setTexData(Material::StageData &stageDat,
700      const MaterialFeatureData &fd,
701      RenderPassData &passData,
702      U32 &texIndex);
703
704   virtual String getName()
705   {
706      return "Reflection Probes";
707   }
708};
709
710#endif // _SHADERGEN_HLSL_SHADERFEATUREHLSL_H_
711