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