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