debugVizFeatureHLSL.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #include "shaderGen/HLSL/debugVizFeatureHLSL.h"
  2. #include "shaderGen/shaderGen.h"
  3. #include "shaderGen/langElement.h"
  4. #include "shaderGen/shaderOp.h"
  5. #include "shaderGen/shaderGenVars.h"
  6. #include "gfx/gfxDevice.h"
  7. #include "materials/matInstance.h"
  8. #include "materials/processedMaterial.h"
  9. #include "materials/materialFeatureTypes.h"
  10. #include "core/util/autoPtr.h"
  11. //****************************************************************************
  12. // HDR Output
  13. //****************************************************************************
  14. DebugVizHLSL::DebugVizHLSL()
  15. : mTorqueDep(ShaderGen::smCommonShaderPath + String("/torque.hlsl"))
  16. {
  17. addDependency(&mTorqueDep);
  18. }
  19. void DebugVizHLSL::processPix(Vector<ShaderComponent*>& componentList,
  20. const MaterialFeatureData& fd)
  21. {
  22. MultiLine* meta = new MultiLine;
  23. Var* surface = (Var*)LangElement::find("surface");
  24. Var* color = (Var*)LangElement::find(getOutputTargetVarName(ShaderFeature::DefaultTarget));
  25. if (!surface)
  26. return;
  27. //0 == display both forward and deferred viz, 1 = display forward only viz, 2 = display deferred only viz
  28. S32 vizDisplayMode = Con::getIntVariable("$Viz_DisplayMode", 0);
  29. S32 surfaceVizMode = Con::getIntVariable("$Viz_SurfacePropertiesModeVar", -1);
  30. if (surfaceVizMode != -1 && vizDisplayMode == 0 || vizDisplayMode == 1)
  31. {
  32. if (color)
  33. {
  34. Var* specularColor = (Var*)LangElement::find("specularColor");
  35. switch (surfaceVizMode)
  36. {
  37. case 0:
  38. meta->addStatement(new GenOp(" @.rgb = @.baseColor.rgb;\r\n", color, surface));
  39. break;
  40. case 1:
  41. meta->addStatement(new GenOp(" @.rgb = @.N.rgb;\r\n", color, surface));
  42. break;
  43. case 2:
  44. meta->addStatement(new GenOp(" @.rgb = @.ao.rrr;\r\n", color, surface));
  45. break;
  46. case 3:
  47. meta->addStatement(new GenOp(" @.rgb = @.roughness.rrr;\r\n", color, surface));
  48. break;
  49. case 4:
  50. meta->addStatement(new GenOp(" @.rgb = @.metalness.rrr;\r\n", color, surface));
  51. break;
  52. case 5:
  53. meta->addStatement(new GenOp(" @.rgb = @.depth.rrr;\r\n", color, surface));
  54. break;
  55. case 6:
  56. meta->addStatement(new GenOp(" @.rgb = @.albedo.rgb;\r\n", color, surface));
  57. break;
  58. case 7:
  59. if (!specularColor)
  60. {
  61. specularColor = new Var("specularColor", "float3");
  62. specularColor->uniform = false;
  63. }
  64. meta->addStatement(new GenOp(" @ = @.baseColor.rgb * @.ao;\r\n", specularColor, surface, surface));
  65. meta->addStatement(new GenOp(" @.rgb = @.rgb;\r\n", color, specularColor));
  66. break;
  67. case 8:
  68. meta->addStatement(new GenOp(" @.rgb = @.matFlag.rrr;\r\n", color, surface));
  69. break;
  70. case 9:
  71. meta->addStatement(new GenOp(" @.rgb = @.P.xyz;\r\n", color, surface));
  72. break;
  73. case 10:
  74. meta->addStatement(new GenOp(" @.rgb = @.R.xyz;\r\n", color, surface));
  75. break;
  76. case 11:
  77. meta->addStatement(new GenOp(" @.rgb = @.F.rgb;\r\n", color, surface));
  78. break;
  79. case 12: //TODO
  80. /*Var * ssaoMaskTex = (Var*)LangElement::find("ssaoMaskTex");
  81. if (!ssaoMaskTex)
  82. {
  83. break;
  84. }
  85. meta->addStatement(new GenOp(" @.rgb = @.N;\r\n", color, surface));*/
  86. meta->addStatement(new GenOp(" @.rgb = float3(0,0,0);\r\n", color));
  87. break;
  88. case 13: //TODO
  89. meta->addStatement(new GenOp(" @.rgb = float3(0,0,0);\r\n", color));
  90. break;
  91. case 14: //TODO
  92. meta->addStatement(new GenOp(" @.rgb = float3(0,0,0);\r\n", color));
  93. break;
  94. };
  95. }
  96. output = meta;
  97. return;
  98. }
  99. //if not that, try the probe viz
  100. Var* ibl = (Var*)LangElement::find("ibl");
  101. if (ibl && color)
  102. {
  103. const char* showAtten = Con::getVariable("$Probes::showAttenuation", "0");
  104. const char* showContrib = Con::getVariable("$Probes::showProbeContrib", "0");
  105. const char* showSpec = Con::getVariable("$Probes::showSpecularCubemaps", "0");
  106. const char* showDiff = Con::getVariable("$Probes::showDiffuseCubemaps", "0");
  107. if (showAtten == "0" && showContrib == "0" && showSpec == "0" && showDiff == "0")
  108. return;
  109. if (fd.features[MFT_LightMap] || fd.features[MFT_ToneMap] || fd.features[MFT_VertLit])
  110. return;
  111. ShaderConnector* connectComp = dynamic_cast<ShaderConnector*>(componentList[C_CONNECTOR]);
  112. MultiLine* meta = new MultiLine;
  113. // Now the wsPosition and wsView.
  114. Var* worldToTangent = getInWorldToTangent(componentList);
  115. Var* wsNormal = getInWorldNormal(componentList);
  116. Var* wsPosition = getInWsPosition(componentList);
  117. Var* wsView = getWsView(wsPosition, meta);
  118. //Reflection Probe WIP
  119. U32 MAX_FORWARD_PROBES = 4;
  120. Var* numProbes = (Var*)LangElement::find("inNumProbes");
  121. Var* cubeMips = (Var*)LangElement::find("cubeMips");
  122. Var* skylightCubemapIdx = (Var*)LangElement::find("inSkylightCubemapIdx");
  123. Var* inProbePosArray = (Var*)LangElement::find("inProbePosArray");
  124. Var* inRefPosArray = (Var*)LangElement::find("inRefPosArray");
  125. Var* refScaleArray = (Var*)LangElement::find("inRefScaleArray");
  126. Var* probeConfigData = (Var*)LangElement::find("inProbeConfigDataArray");
  127. Var* worldToObjArray = (Var*)LangElement::find("inWorldToObjArray");
  128. Var* BRDFTexture = (Var*)LangElement::find("BRDFTexture");
  129. Var* BRDFTextureTex = (Var*)LangElement::find("texture_BRDFTexture");
  130. Var* specularCubemapAR = (Var*)LangElement::find("SpecularCubemapAR");
  131. Var* specularCubemapARTex = (Var*)LangElement::find("texture_SpecularCubemapAR");
  132. Var* irradianceCubemapAR = (Var*)LangElement::find("IrradianceCubemapAR");
  133. Var* irradianceCubemapARTex = (Var*)LangElement::find("texture_IrradianceCubemapAR");
  134. Var* matinfo = (Var*)LangElement::find("ORMConfig");
  135. Var* metalness = (Var*)LangElement::find("metalness");
  136. Var* roughness = (Var*)LangElement::find("roughness");
  137. Var* wsEyePos = (Var*)LangElement::find("eyePosWorld");
  138. Var* ibl = (Var*)LangElement::find("ibl");
  139. //Reflection vec
  140. Var* showAttenVar = new Var("showAttenVar", "int");
  141. char buf[64];
  142. dSprintf(buf, sizeof(buf), " @ = %s;\r\n", showAtten);
  143. meta->addStatement(new GenOp(buf, new DecOp(showAttenVar)));
  144. Var* showContribVar = new Var("showContribVar", "int");
  145. dSprintf(buf, sizeof(buf), " @ = %s;\r\n", showContrib);
  146. meta->addStatement(new GenOp(buf, new DecOp(showContribVar)));
  147. Var* showSpecVar = new Var("showSpecVar", "int");
  148. dSprintf(buf, sizeof(buf), " @ = %s;\r\n", showSpec);
  149. meta->addStatement(new GenOp(buf, new DecOp(showSpecVar)));
  150. Var* showDiffVar = new Var("showDiffVar", "int");
  151. dSprintf(buf, sizeof(buf), " @ = %s;\r\n", showDiff);
  152. meta->addStatement(new GenOp(buf, new DecOp(showDiffVar)));
  153. String computeForwardProbes = String(" @ = debugVizForwardProbes(@,@,@,@,@,@,@,@,\r\n\t\t");
  154. computeForwardProbes += String("@,TORQUE_SAMPLER2D_MAKEARG(@),\r\n\t\t");
  155. computeForwardProbes += String("TORQUE_SAMPLERCUBEARRAY_MAKEARG(@),TORQUE_SAMPLERCUBEARRAY_MAKEARG(@), @, @, @, @).rgb; \r\n");
  156. meta->addStatement(new GenOp(computeForwardProbes.c_str(), ibl, surface, cubeMips, numProbes, worldToObjArray, probeConfigData, inProbePosArray, refScaleArray, inRefPosArray,
  157. skylightCubemapIdx, BRDFTexture,
  158. irradianceCubemapAR, specularCubemapAR,
  159. showAttenVar, showContribVar, showSpecVar, showDiffVar));
  160. meta->addStatement(new GenOp(" @.rgb = @.rgb;\r\n", color, ibl));
  161. output = meta;
  162. return;
  163. }
  164. }