terrFeatureGLSL.cpp 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "terrain/glsl/terrFeatureGLSL.h"
  24. #include "terrain/terrFeatureTypes.h"
  25. #include "materials/materialFeatureTypes.h"
  26. #include "materials/materialFeatureData.h"
  27. #include "materials/processedMaterial.h"
  28. #include "gfx/gfxDevice.h"
  29. #include "shaderGen/langElement.h"
  30. #include "shaderGen/shaderOp.h"
  31. #include "shaderGen/featureMgr.h"
  32. #include "shaderGen/shaderGen.h"
  33. #include "core/module.h"
  34. namespace
  35. {
  36. void register_glsl_shader_features_for_terrain(GFXAdapterType type)
  37. {
  38. if(type != OpenGL)
  39. return;
  40. FEATUREMGR->registerFeature( MFT_TerrainBaseMap, new TerrainBaseMapFeatGLSL );
  41. FEATUREMGR->registerFeature( MFT_TerrainParallaxMap, new NamedFeatureGLSL( "Terrain Parallax Texture" ) );
  42. FEATUREMGR->registerFeature( MFT_TerrainDetailMap, new TerrainDetailMapFeatGLSL );
  43. FEATUREMGR->registerFeature( MFT_TerrainNormalMap, new TerrainNormalMapFeatGLSL );
  44. FEATUREMGR->registerFeature( MFT_TerrainMacroMap, new TerrainMacroMapFeatGLSL );
  45. FEATUREMGR->registerFeature( MFT_TerrainLightMap, new TerrainLightMapFeatGLSL );
  46. FEATUREMGR->registerFeature( MFT_TerrainSideProject, new NamedFeatureGLSL( "Terrain Side Projection" ) );
  47. FEATUREMGR->registerFeature( MFT_TerrainAdditive, new TerrainAdditiveFeatGLSL );
  48. FEATUREMGR->registerFeature( MFT_DeferredTerrainBaseMap, new TerrainBaseMapFeatGLSL );
  49. FEATUREMGR->registerFeature( MFT_DeferredTerrainMacroMap, new TerrainMacroMapFeatGLSL );
  50. FEATUREMGR->registerFeature( MFT_DeferredTerrainDetailMap, new TerrainDetailMapFeatGLSL );
  51. FEATUREMGR->registerFeature( MFT_DeferredTerrainBlankInfoMap, new TerrainBlankInfoMapFeatGLSL );
  52. }
  53. };
  54. MODULE_BEGIN( TerrainFeatGLSL )
  55. MODULE_INIT_AFTER( ShaderGen )
  56. MODULE_INIT
  57. {
  58. SHADERGEN->getFeatureInitSignal().notify(&register_glsl_shader_features_for_terrain);
  59. }
  60. MODULE_END;
  61. TerrainFeatGLSL::TerrainFeatGLSL()
  62. : mTorqueDep(ShaderGen::smCommonShaderPath + String("/gl/torque.glsl" ))
  63. {
  64. addDependency( &mTorqueDep );
  65. }
  66. Var* TerrainFeatGLSL::_getUniformVar( const char *name, const char *type, ConstantSortPosition csp )
  67. {
  68. Var *theVar = (Var*)LangElement::find( name );
  69. if ( !theVar )
  70. {
  71. theVar = new Var;
  72. theVar->setType( type );
  73. theVar->setName( name );
  74. theVar->uniform = true;
  75. theVar->constSortPos = csp;
  76. }
  77. return theVar;
  78. }
  79. Var* TerrainFeatGLSL::_getInDetailCoord( Vector<ShaderComponent*> &componentList )
  80. {
  81. String name( String::ToString( "detCoord%d", getProcessIndex() ) );
  82. Var *inDet = (Var*)LangElement::find( name );
  83. if ( !inDet )
  84. {
  85. ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
  86. inDet = connectComp->getElement( RT_TEXCOORD );
  87. inDet->setName( name );
  88. inDet->setStructName( "IN" );
  89. inDet->setType( "vec4" );
  90. }
  91. return inDet;
  92. }
  93. Var* TerrainFeatGLSL::_getInMacroCoord( Vector<ShaderComponent*> &componentList )
  94. {
  95. String name( String::ToString( "macroCoord%d", getProcessIndex() ) );
  96. Var *inDet = (Var*)LangElement::find( name );
  97. if ( !inDet )
  98. {
  99. ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
  100. inDet = connectComp->getElement( RT_TEXCOORD );
  101. inDet->setName( name );
  102. inDet->setStructName( "IN" );
  103. inDet->setType( "vec4" );
  104. }
  105. return inDet;
  106. }
  107. Var* TerrainFeatGLSL::_getNormalMapTex()
  108. {
  109. String name( String::ToString( "normalMap%d", getProcessIndex() ) );
  110. Var *normalMap = (Var*)LangElement::find( name );
  111. if ( !normalMap )
  112. {
  113. normalMap = new Var;
  114. normalMap->setType( "sampler2D" );
  115. normalMap->setName( name );
  116. normalMap->uniform = true;
  117. normalMap->sampler = true;
  118. normalMap->constNum = Var::getTexUnitNum();
  119. }
  120. return normalMap;
  121. }
  122. Var* TerrainFeatGLSL::_getDetailIdStrengthParallax()
  123. {
  124. String name( String::ToString( "detailIdStrengthParallax%d", getProcessIndex() ) );
  125. Var *detailInfo = (Var*)LangElement::find( name );
  126. if ( !detailInfo )
  127. {
  128. detailInfo = new Var;
  129. detailInfo->setType( "vec3" );
  130. detailInfo->setName( name );
  131. detailInfo->uniform = true;
  132. detailInfo->constSortPos = cspPotentialPrimitive;
  133. }
  134. return detailInfo;
  135. }
  136. Var* TerrainFeatGLSL::_getMacroIdStrengthParallax()
  137. {
  138. String name( String::ToString( "macroIdStrengthParallax%d", getProcessIndex() ) );
  139. Var *detailInfo = (Var*)LangElement::find( name );
  140. if ( !detailInfo )
  141. {
  142. detailInfo = new Var;
  143. detailInfo->setType( "vec3" );
  144. detailInfo->setName( name );
  145. detailInfo->uniform = true;
  146. detailInfo->constSortPos = cspPotentialPrimitive;
  147. }
  148. return detailInfo;
  149. }
  150. void TerrainBaseMapFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
  151. const MaterialFeatureData &fd )
  152. {
  153. MultiLine *meta = new MultiLine;
  154. output = meta;
  155. // Generate the incoming texture var.
  156. Var *inTex;
  157. {
  158. Var *inPos = (Var*)LangElement::find( "inPosition" );
  159. if ( !inPos )
  160. inPos = (Var*)LangElement::find( "position" );
  161. inTex = new Var( "texCoord", "vec3" );
  162. Var *oneOverTerrainSize = _getUniformVar( "oneOverTerrainSize", "float", cspPass );
  163. // NOTE: The y coord here should be negative to have
  164. // the texture maps not end up flipped which also caused
  165. // normal and parallax mapping to be incorrect.
  166. //
  167. // This mistake early in development means that the layer
  168. // id bilinear blend depends on it being that way.
  169. //
  170. // So instead i fixed this by flipping the base and detail
  171. // coord y scale to compensate when rendering.
  172. //
  173. meta->addStatement( new GenOp( " @ = @.xyz * float3( @, @, -@ );\r\n",
  174. new DecOp( inTex ), inPos, oneOverTerrainSize, oneOverTerrainSize, oneOverTerrainSize ) );
  175. }
  176. ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
  177. // Pass the texture coord to the pixel shader.
  178. Var *outTex = connectComp->getElement( RT_TEXCOORD );
  179. outTex->setName( "outTexCoord" );
  180. outTex->setStructName( "OUT" );
  181. outTex->setType( "vec3" );
  182. meta->addStatement( new GenOp( " @.xy = @.xy;\r\n", outTex, inTex ) );
  183. // If this shader has a side projected layer then we
  184. // pass the dot product between the +Y and the normal
  185. // thru outTexCoord.z for use in blending the textures.
  186. if ( fd.features.hasFeature( MFT_TerrainSideProject ) )
  187. {
  188. Var *inNormal = (Var*)LangElement::find( "normal" );
  189. meta->addStatement(
  190. new GenOp( " @.z = pow( abs( dot( normalize( float3( @.x, @.y, 0 ) ), float3( 0, 1, 0 ) ) ), 10.0 );\r\n",
  191. outTex, inNormal, inNormal ) );
  192. }
  193. else
  194. meta->addStatement( new GenOp( " @.z = 0;\r\n", outTex ) );
  195. // HACK: This is sort of lazy... we generate the tanget
  196. // vector here so that we're sure it exists in the parallax
  197. // and normal features which will expect "T" to exist.
  198. //
  199. // If this shader doesn't use it the shader compiler will
  200. // optimize away this code.
  201. //
  202. Var *inTangentZ = getVertTexCoord( "tcTangentZ" );
  203. Var *inTanget = new Var( "T", "vec3" );
  204. Var *squareSize = _getUniformVar( "squareSize", "float", cspPass );
  205. meta->addStatement( new GenOp( " @ = normalize( float3( @, 0, @ ) );\r\n",
  206. new DecOp( inTanget ), squareSize, inTangentZ ) );
  207. }
  208. void TerrainBaseMapFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
  209. const MaterialFeatureData &fd )
  210. {
  211. // grab connector texcoord register
  212. Var *texCoord = getInTexCoord( "texCoord", "vec3", componentList );
  213. // create texture var
  214. Var *diffuseMap = new Var;
  215. diffuseMap->setType( "sampler2D" );
  216. diffuseMap->setName( "baseTexMap" );
  217. diffuseMap->uniform = true;
  218. diffuseMap->sampler = true;
  219. diffuseMap->constNum = Var::getTexUnitNum(); // used as texture unit num here
  220. MultiLine *meta = new MultiLine;
  221. Var *baseColor = new Var;
  222. baseColor->setType( "vec4" );
  223. baseColor->setName( "baseColor" );
  224. meta->addStatement( new GenOp( " @ = tex2D( @, @.xy );\r\n", new DecOp( baseColor ), diffuseMap, texCoord ) );
  225. ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;
  226. if(fd.features.hasFeature(MFT_isDeferred))
  227. {
  228. target= ShaderFeature::RenderTarget1;
  229. }
  230. meta->addStatement( new GenOp( " @;\r\n", assignColor( baseColor, Material::Mul,NULL,target ) ) );
  231. output = meta;
  232. }
  233. ShaderFeature::Resources TerrainBaseMapFeatGLSL::getResources( const MaterialFeatureData &fd )
  234. {
  235. Resources res;
  236. res.numTexReg = 1;
  237. res.numTex = 1;
  238. return res;
  239. }
  240. U32 TerrainBaseMapFeatGLSL::getOutputTargets( const MaterialFeatureData &fd ) const
  241. {
  242. return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget;
  243. }
  244. TerrainDetailMapFeatGLSL::TerrainDetailMapFeatGLSL()
  245. : mTorqueDep(ShaderGen::smCommonShaderPath + String("/gl/torque.glsl" )),
  246. mTerrainDep(ShaderGen::smCommonShaderPath + String("/terrain/terrain.glsl" ))
  247. {
  248. addDependency( &mTorqueDep );
  249. addDependency( &mTerrainDep );
  250. }
  251. void TerrainDetailMapFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
  252. const MaterialFeatureData &fd )
  253. {
  254. const S32 detailIndex = getProcessIndex();
  255. // Grab incoming texture coords... the base map feature
  256. // made sure this was created.
  257. Var *inTex = (Var*)LangElement::find( "texCoord" );
  258. AssertFatal( inTex, "The texture coord is missing!" );
  259. // Grab the input position.
  260. Var *inPos = (Var*)LangElement::find( "inPosition" );
  261. if ( !inPos )
  262. inPos = (Var*)LangElement::find( "position" );
  263. // Get the object space eye position.
  264. Var *eyePos = _getUniformVar( "eyePos", "vec3", cspPotentialPrimitive );
  265. MultiLine *meta = new MultiLine;
  266. // If we have parallax mapping then make sure we've sent
  267. // the negative view vector to the pixel shader.
  268. if ( fd.features.hasFeature( MFT_TerrainParallaxMap ) &&
  269. !LangElement::find( "outNegViewTS" ) )
  270. {
  271. // Get the object to tangent transform which
  272. // will consume 3 output registers.
  273. Var *objToTangentSpace = getOutObjToTangentSpace( componentList, meta, fd );
  274. // Now use a single output register to send the negative
  275. // view vector in tangent space to the pixel shader.
  276. ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
  277. Var *outNegViewTS = connectComp->getElement( RT_TEXCOORD );
  278. outNegViewTS->setName( "outNegViewTS" );
  279. outNegViewTS->setStructName( "OUT" );
  280. outNegViewTS->setType( "vec3" );
  281. meta->addStatement( new GenOp( " @ = tMul( @, float3( @ - @.xyz ) );\r\n",
  282. outNegViewTS, objToTangentSpace, eyePos, inPos ) );
  283. }
  284. // Get the distance from the eye to this vertex.
  285. Var *dist = (Var*)LangElement::find( "dist" );
  286. if ( !dist )
  287. {
  288. dist = new Var;
  289. dist->setType( "float" );
  290. dist->setName( "dist" );
  291. meta->addStatement( new GenOp( " @ = distance( @.xyz, @ );\r\n",
  292. new DecOp( dist ), inPos, eyePos ) );
  293. }
  294. // grab connector texcoord register
  295. ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
  296. Var *outTex = connectComp->getElement( RT_TEXCOORD );
  297. outTex->setName( String::ToString( "detCoord%d", detailIndex ) );
  298. outTex->setStructName( "OUT" );
  299. outTex->setType( "vec4" );
  300. // Get the detail scale and fade info.
  301. Var *detScaleAndFade = new Var;
  302. detScaleAndFade->setType( "vec4" );
  303. detScaleAndFade->setName( String::ToString( "detailScaleAndFade%d", detailIndex ) );
  304. detScaleAndFade->uniform = true;
  305. detScaleAndFade->constSortPos = cspPotentialPrimitive;
  306. // Setup the detail coord.
  307. //
  308. // NOTE: You see here we scale the texture coord by 'xyx'
  309. // to generate the detail coord. This y is here because
  310. // its scale is flipped to correct for the non negative y
  311. // in texCoord.
  312. //
  313. // See TerrainBaseMapFeatGLSL::processVert().
  314. //
  315. meta->addStatement( new GenOp( " @.xyz = @ * @.xyx;\r\n", outTex, inTex, detScaleAndFade ) );
  316. // And sneak the detail fade thru the w detailCoord.
  317. meta->addStatement( new GenOp( " @.w = clamp( ( @.z - @ ) * @.w, 0.0, 1.0 );\r\n",
  318. outTex, detScaleAndFade, dist, detScaleAndFade ) );
  319. output = meta;
  320. }
  321. void TerrainDetailMapFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
  322. const MaterialFeatureData &fd )
  323. {
  324. const S32 detailIndex = getProcessIndex();
  325. Var *inTex = getVertTexCoord( "texCoord" );
  326. MultiLine *meta = new MultiLine;
  327. // We need the negative tangent space view vector
  328. // as in parallax mapping we step towards the camera.
  329. Var *negViewTS = (Var*)LangElement::find( "negViewTS" );
  330. if ( !negViewTS &&
  331. fd.features.hasFeature( MFT_TerrainParallaxMap ) )
  332. {
  333. Var *inNegViewTS = (Var*)LangElement::find( "outNegViewTS" );
  334. if ( !inNegViewTS )
  335. {
  336. ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
  337. inNegViewTS = connectComp->getElement( RT_TEXCOORD );
  338. inNegViewTS->setName( "outNegViewTS" );
  339. inNegViewTS->setStructName( "IN" );
  340. inNegViewTS->setType( "vec3" );
  341. }
  342. negViewTS = new Var( "negViewTS", "vec3" );
  343. meta->addStatement( new GenOp( " @ = normalize( @ );\r\n", new DecOp( negViewTS ), inNegViewTS ) );
  344. }
  345. // Get the layer samples.
  346. Var *layerSample = (Var*)LangElement::find( "layerSample" );
  347. if ( !layerSample )
  348. {
  349. layerSample = new Var;
  350. layerSample->setType( "vec4" );
  351. layerSample->setName( "layerSample" );
  352. // Get the layer texture var
  353. Var *layerTex = new Var;
  354. layerTex->setType( "sampler2D" );
  355. layerTex->setName( "layerTex" );
  356. layerTex->uniform = true;
  357. layerTex->sampler = true;
  358. layerTex->constNum = Var::getTexUnitNum();
  359. // Read the layer texture to get the samples.
  360. meta->addStatement( new GenOp( " @ = round( tex2D( @, @.xy ) * 255.0f );\r\n",
  361. new DecOp( layerSample ), layerTex, inTex ) );
  362. }
  363. Var *layerSize = (Var*)LangElement::find( "layerSize" );
  364. if ( !layerSize )
  365. {
  366. layerSize = new Var;
  367. layerSize->setType( "float" );
  368. layerSize->setName( "layerSize" );
  369. layerSize->uniform = true;
  370. layerSize->constSortPos = cspPass;
  371. }
  372. // Grab the incoming detail coord.
  373. Var *inDet = _getInDetailCoord( componentList );
  374. // Get the detail id.
  375. Var *detailInfo = _getDetailIdStrengthParallax();
  376. // Create the detail blend var.
  377. Var *detailBlend = new Var;
  378. detailBlend->setType( "float" );
  379. detailBlend->setName( String::ToString( "detailBlend%d", detailIndex ) );
  380. // Calculate the blend for this detail texture.
  381. meta->addStatement( new GenOp( " @ = calcBlend( @.x, @.xy, @, @ );\r\n",
  382. new DecOp( detailBlend ), detailInfo, inTex, layerSize, layerSample ) );
  383. // New terrain
  384. Var *lerpBlend = (Var*)LangElement::find("lerpBlend");
  385. if (!lerpBlend)
  386. {
  387. lerpBlend = new Var;
  388. lerpBlend->setType("float");
  389. lerpBlend->setName("lerpBlend");
  390. lerpBlend->uniform = true;
  391. lerpBlend->constSortPos = cspPrimitive;
  392. }
  393. Var *blendDepth = (Var*)LangElement::find(String::ToString("blendDepth%d", detailIndex));
  394. if (!blendDepth)
  395. {
  396. blendDepth = new Var;
  397. blendDepth->setType("float");
  398. blendDepth->setName(String::ToString("blendDepth%d", detailIndex));
  399. blendDepth->uniform = true;
  400. blendDepth->constSortPos = cspPrimitive;
  401. }
  402. ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;
  403. if(fd.features.hasFeature( MFT_DeferredTerrainDetailMap ))
  404. target= ShaderFeature::RenderTarget1;
  405. Var *outColor = (Var*)LangElement::find( getOutputTargetVarName(target) );
  406. if (!outColor)
  407. {
  408. // create color var
  409. outColor = new Var;
  410. outColor->setType("float4");
  411. outColor->setName("col");
  412. outColor->setStructName("OUT");
  413. meta->addStatement(new GenOp(" @;\r\n", outColor));
  414. }
  415. Var *detailColor = (Var*)LangElement::find("detailColor");
  416. if (!detailColor)
  417. {
  418. detailColor = new Var;
  419. detailColor->setType("float4");
  420. detailColor->setName("detailColor");
  421. meta->addStatement(new GenOp(" @;\r\n", new DecOp(detailColor)));
  422. }
  423. // Get the detail texture.
  424. Var *detailMap = new Var;
  425. detailMap->setType("sampler2D");
  426. detailMap->setName(String::ToString("detailMap%d", detailIndex));
  427. detailMap->uniform = true;
  428. detailMap->sampler = true;
  429. detailMap->constNum = Var::getTexUnitNum(); // used as texture unit num here
  430. // Get the normal map texture.
  431. Var *normalMap = _getNormalMapTex();
  432. // Issue happens somewhere here -----
  433. // Sample the normal map.
  434. //
  435. // We take two normal samples and lerp between them for
  436. // side projection layers... else a single sample.
  437. LangElement *texOp;
  438. // Note that we're doing the standard greyscale detail
  439. // map technique here which can darken and lighten the
  440. // diffuse texture.
  441. //
  442. // We take two color samples and lerp between them for
  443. // side projection layers... else a single sample.
  444. //
  445. if (fd.features.hasFeature(MFT_TerrainSideProject, detailIndex))
  446. {
  447. meta->addStatement(new GenOp(" @ = ( lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z ) * 2.0 ) - 1.0;\r\n",
  448. detailColor, detailMap, inDet, detailMap, inDet, inTex));
  449. texOp = new GenOp("lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z )",
  450. normalMap, inDet, normalMap, inDet, inTex);
  451. }
  452. else
  453. {
  454. meta->addStatement(new GenOp(" @ = ( tex2D( @, @.xy ) * 2.0 ) - 1.0;\r\n",
  455. detailColor, detailMap, inDet));
  456. texOp = new GenOp("tex2D(@, @.xy)", normalMap, inDet);
  457. }
  458. // New terrain
  459. // Get a var and accumulate the blend amount.
  460. Var *blendTotal = (Var*)LangElement::find( "blendTotal" );
  461. if ( !blendTotal )
  462. {
  463. blendTotal = new Var;
  464. blendTotal->setName( "blendTotal" );
  465. blendTotal->setType( "float" );
  466. meta->addStatement( new GenOp( " @ = 0;\r\n", new DecOp( blendTotal ) ) );
  467. }
  468. // Add to the blend total.
  469. meta->addStatement(new GenOp(" @ = max( @, @ );\r\n", blendTotal, blendTotal, detailBlend));
  470. // If we had a parallax feature... then factor in the parallax
  471. // amount so that it fades out with the layer blending.
  472. if ( fd.features.hasFeature( MFT_TerrainParallaxMap, detailIndex ) )
  473. {
  474. // Call the library function to do the rest.
  475. if (fd.features.hasFeature(MFT_IsBC3nm, detailIndex))
  476. {
  477. meta->addStatement(new GenOp(" @.xy += parallaxOffsetDxtnm( @, @.xy, @, @.z * @ );\r\n",
  478. inDet, normalMap, inDet, negViewTS, detailInfo, detailBlend));
  479. }
  480. else
  481. {
  482. meta->addStatement(new GenOp(" @.xy += parallaxOffset( @, @.xy, @, @.z * @ );\r\n",
  483. inDet, normalMap, inDet, negViewTS, detailInfo, detailBlend));
  484. }
  485. }
  486. // If we're using SM 3.0 then take advantage of
  487. // dynamic branching to skip layers per-pixel.
  488. if ( GFX->getPixelShaderVersion() >= 3.0f )
  489. meta->addStatement( new GenOp( " if ( @ > 0.0f )\r\n", detailBlend ) );
  490. meta->addStatement( new GenOp( " {\r\n" ) );
  491. // Note that we're doing the standard greyscale detail
  492. // map technique here which can darken and lighten the
  493. // diffuse texture.
  494. //
  495. // We take two color samples and lerp between them for
  496. // side projection layers... else a single sample.
  497. //
  498. if ( fd.features.hasFeature( MFT_TerrainSideProject, detailIndex ) )
  499. {
  500. meta->addStatement( new GenOp( " @ = ( lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z ) * 2.0 ) - 1.0;\r\n",
  501. detailColor, detailMap, inDet, detailMap, inDet, inTex ) );
  502. }
  503. else
  504. {
  505. meta->addStatement( new GenOp( " @ = ( tex2D( @, @.xy ) * 2.0 ) - 1.0;\r\n",
  506. detailColor, detailMap, inDet ) );
  507. }
  508. meta->addStatement( new GenOp( " @ *= @.y * @.w;\r\n",
  509. detailColor, detailInfo, inDet ) );
  510. meta->addStatement(new GenOp(" @.rgb = toGamma(@.rgb);\r\n", outColor, outColor));
  511. meta->addStatement(new GenOp(" @ += @ * @;\r\n",
  512. outColor, detailColor, detailBlend));
  513. meta->addStatement(new GenOp(" @.rgb = toLinear(clamp(@.rgb, 0, 1));\r\n", outColor, outColor));
  514. meta->addStatement( new GenOp( " }\r\n" ) );
  515. output = meta;
  516. }
  517. ShaderFeature::Resources TerrainDetailMapFeatGLSL::getResources( const MaterialFeatureData &fd )
  518. {
  519. Resources res;
  520. if ( getProcessIndex() == 0 )
  521. {
  522. // If this is the first detail pass then we
  523. // samples from the layer tex.
  524. res.numTex += 1;
  525. // If this material also does parallax then it
  526. // will generate the negative view vector and the
  527. // worldToTanget transform.
  528. if ( fd.features.hasFeature( MFT_TerrainParallaxMap ) )
  529. res.numTexReg += 4;
  530. }
  531. // sample from the detail texture for diffuse coloring.
  532. res.numTex += 1;
  533. // If we have parallax for this layer then we'll also
  534. // be sampling the normal map for the parallax heightmap.
  535. if ( fd.features.hasFeature( MFT_TerrainParallaxMap, getProcessIndex() ) )
  536. res.numTex += 1;
  537. // Finally we always send the detail texture
  538. // coord to the pixel shader.
  539. res.numTexReg += 1;
  540. return res;
  541. }
  542. U32 TerrainDetailMapFeatGLSL::getOutputTargets( const MaterialFeatureData &fd ) const
  543. {
  544. return fd.features[MFT_DeferredTerrainDetailMap] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget;
  545. }
  546. TerrainMacroMapFeatGLSL::TerrainMacroMapFeatGLSL()
  547. : mTorqueDep(ShaderGen::smCommonShaderPath + String("/gl/torque.glsl" )),
  548. mTerrainDep(ShaderGen::smCommonShaderPath + String("/terrain/terrain.glsl" ))
  549. {
  550. addDependency( &mTorqueDep );
  551. addDependency( &mTerrainDep );
  552. }
  553. void TerrainMacroMapFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
  554. const MaterialFeatureData &fd )
  555. {
  556. const S32 detailIndex = getProcessIndex();
  557. // Grab incoming texture coords... the base map feature
  558. // made sure this was created.
  559. Var *inTex = (Var*)LangElement::find( "texCoord" );
  560. AssertFatal( inTex, "The texture coord is missing!" );
  561. // Grab the input position.
  562. Var *inPos = (Var*)LangElement::find( "inPosition" );
  563. if ( !inPos )
  564. inPos = (Var*)LangElement::find( "position" );
  565. // Get the object space eye position.
  566. Var *eyePos = _getUniformVar( "eyePos", "vec3", cspPotentialPrimitive );
  567. MultiLine *meta = new MultiLine;
  568. // Get the distance from the eye to this vertex.
  569. Var *dist = (Var*)LangElement::find( "macroDist" );
  570. if ( !dist )
  571. {
  572. dist = new Var;
  573. dist->setType( "float" );
  574. dist->setName( "macroDist" );
  575. meta->addStatement( new GenOp( " @ = distance( @.xyz, @ );\r\n",
  576. new DecOp( dist ), inPos, eyePos ) );
  577. }
  578. // grab connector texcoord register
  579. ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
  580. Var *outTex = connectComp->getElement( RT_TEXCOORD );
  581. outTex->setName( String::ToString( "macroCoord%d", detailIndex ) );
  582. outTex->setStructName( "OUT" );
  583. outTex->setType( "vec4" );
  584. // Get the detail scale and fade info.
  585. Var *detScaleAndFade = new Var;
  586. detScaleAndFade->setType( "vec4" );
  587. detScaleAndFade->setName( String::ToString( "macroScaleAndFade%d", detailIndex ) );
  588. detScaleAndFade->uniform = true;
  589. detScaleAndFade->constSortPos = cspPotentialPrimitive;
  590. // Setup the detail coord.
  591. meta->addStatement( new GenOp( " @.xyz = @ * @.xyx;\r\n", outTex, inTex, detScaleAndFade ) );
  592. // And sneak the detail fade thru the w detailCoord.
  593. meta->addStatement( new GenOp( " @.w = clamp( ( @.z - @ ) * @.w, 0.0, 1.0 );\r\n",
  594. outTex, detScaleAndFade, dist, detScaleAndFade ) );
  595. output = meta;
  596. }
  597. void TerrainMacroMapFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
  598. const MaterialFeatureData &fd )
  599. {
  600. const S32 detailIndex = getProcessIndex();
  601. Var *inTex = getVertTexCoord( "texCoord" );
  602. MultiLine *meta = new MultiLine;
  603. // We need the negative tangent space view vector
  604. // as in parallax mapping we step towards the camera.
  605. Var *negViewTS = (Var*)LangElement::find( "negViewTS" );
  606. if ( !negViewTS &&
  607. fd.features.hasFeature( MFT_TerrainParallaxMap ) )
  608. {
  609. Var *inNegViewTS = (Var*)LangElement::find( "outNegViewTS" );
  610. if ( !inNegViewTS )
  611. {
  612. ShaderConnector *connectComp = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
  613. inNegViewTS = connectComp->getElement( RT_TEXCOORD );
  614. inNegViewTS->setName( "outNegViewTS" );
  615. inNegViewTS->setStructName( "IN" );
  616. inNegViewTS->setType( "vec3" );
  617. }
  618. negViewTS = new Var( "negViewTS", "vec3" );
  619. meta->addStatement( new GenOp( " @ = normalize( @ );\r\n", new DecOp( negViewTS ), inNegViewTS ) );
  620. }
  621. // Get the layer samples.
  622. Var *layerSample = (Var*)LangElement::find( "layerSample" );
  623. if ( !layerSample )
  624. {
  625. layerSample = new Var;
  626. layerSample->setType( "vec4" );
  627. layerSample->setName( "layerSample" );
  628. // Get the layer texture var
  629. Var *layerTex = new Var;
  630. layerTex->setType( "sampler2D" );
  631. layerTex->setName( "macrolayerTex" );
  632. layerTex->uniform = true;
  633. layerTex->sampler = true;
  634. layerTex->constNum = Var::getTexUnitNum();
  635. // Read the layer texture to get the samples.
  636. meta->addStatement( new GenOp( " @ = round( tex2D( @, @.xy ) * 255.0f );\r\n",
  637. new DecOp( layerSample ), layerTex, inTex ) );
  638. }
  639. Var *layerSize = (Var*)LangElement::find( "layerSize" );
  640. if ( !layerSize )
  641. {
  642. layerSize = new Var;
  643. layerSize->setType( "float" );
  644. layerSize->setName( "layerSize" );
  645. layerSize->uniform = true;
  646. layerSize->constSortPos = cspPass;
  647. }
  648. // Grab the incoming detail coord.
  649. Var *inDet = _getInMacroCoord( componentList );
  650. // Get the detail id.
  651. Var *detailInfo = _getMacroIdStrengthParallax();
  652. // Create the detail blend var.
  653. Var *detailBlend = new Var;
  654. detailBlend->setType( "float" );
  655. detailBlend->setName( String::ToString( "macroBlend%d", detailIndex ) );
  656. // Calculate the blend for this detail texture.
  657. meta->addStatement( new GenOp( " @ = calcBlend( @.x, @.xy, @, @ );\r\n",
  658. new DecOp( detailBlend ), detailInfo, inTex, layerSize, layerSample ) );
  659. // Get a var and accumulate the blend amount.
  660. Var *blendTotal = (Var*)LangElement::find( "blendTotal" );
  661. if ( !blendTotal )
  662. {
  663. blendTotal = new Var;
  664. //blendTotal->setName( "blendTotal" );
  665. blendTotal->setName( "blendTotal" );
  666. blendTotal->setType( "float" );
  667. meta->addStatement( new GenOp( " @ = 0;\r\n", new DecOp( blendTotal ) ) );
  668. }
  669. // Add to the blend total.
  670. meta->addStatement(new GenOp(" @ = max( @, @ );\r\n", blendTotal, blendTotal, detailBlend));
  671. Var *detailColor = (Var*)LangElement::find( "macroColor" );
  672. if ( !detailColor )
  673. {
  674. detailColor = new Var;
  675. detailColor->setType( "vec4" );
  676. detailColor->setName( "macroColor" );
  677. meta->addStatement( new GenOp( " @;\r\n", new DecOp( detailColor ) ) );
  678. }
  679. // Get the detail texture.
  680. Var *detailMap = new Var;
  681. detailMap->setType( "sampler2D" );
  682. detailMap->setName( String::ToString( "macroMap%d", detailIndex ) );
  683. detailMap->uniform = true;
  684. detailMap->sampler = true;
  685. detailMap->constNum = Var::getTexUnitNum(); // used as texture unit num here
  686. // If we're using SM 3.0 then take advantage of
  687. // dynamic branching to skip layers per-pixel.
  688. if ( GFX->getPixelShaderVersion() >= 3.0f )
  689. meta->addStatement( new GenOp( " if ( @ > 0.0f )\r\n", detailBlend ) );
  690. meta->addStatement( new GenOp( " {\r\n" ) );
  691. // Note that we're doing the standard greyscale detail
  692. // map technique here which can darken and lighten the
  693. // diffuse texture.
  694. //
  695. // We take two color samples and lerp between them for
  696. // side projection layers... else a single sample.
  697. //
  698. if ( fd.features.hasFeature( MFT_TerrainSideProject, detailIndex ) )
  699. {
  700. meta->addStatement( new GenOp( " @ = ( lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z ) * 2.0 ) - 1.0;\r\n",
  701. detailColor, detailMap, inDet, detailMap, inDet, inTex ) );
  702. }
  703. else
  704. {
  705. meta->addStatement( new GenOp( " @ = ( tex2D( @, @.xy ) * 2.0 ) - 1.0;\r\n",
  706. detailColor, detailMap, inDet ) );
  707. }
  708. meta->addStatement( new GenOp( " @ *= @.y * @.w;\r\n",
  709. detailColor, detailInfo, inDet ) );
  710. ShaderFeature::OutputTarget target = ShaderFeature::DefaultTarget;
  711. if(fd.features.hasFeature(MFT_DeferredTerrainMacroMap))
  712. target= ShaderFeature::RenderTarget1;
  713. Var *outColor = (Var*)LangElement::find( getOutputTargetVarName(target) );
  714. meta->addStatement(new GenOp(" @.rgb = toGamma(@.rgb);\r\n", outColor, outColor));
  715. meta->addStatement(new GenOp(" @ += @ * @;\r\n",
  716. outColor, detailColor, detailBlend));
  717. meta->addStatement(new GenOp(" @.rgb = toLinear(clamp(@.rgb, 0, 1));\r\n", outColor, outColor));
  718. meta->addStatement( new GenOp( " }\r\n" ) );
  719. output = meta;
  720. }
  721. ShaderFeature::Resources TerrainMacroMapFeatGLSL::getResources( const MaterialFeatureData &fd )
  722. {
  723. Resources res;
  724. if ( getProcessIndex() == 0 )
  725. {
  726. // If this is the first detail pass then we
  727. // samples from the layer tex.
  728. res.numTex += 1;
  729. }
  730. res.numTex += 1;
  731. // Finally we always send the detail texture
  732. // coord to the pixel shader.
  733. res.numTexReg += 1;
  734. return res;
  735. }
  736. U32 TerrainMacroMapFeatGLSL::getOutputTargets( const MaterialFeatureData &fd ) const
  737. {
  738. return fd.features[MFT_DeferredTerrainMacroMap] ? ShaderFeature::RenderTarget1 : ShaderFeature::DefaultTarget;
  739. }
  740. void TerrainNormalMapFeatGLSL::processVert( Vector<ShaderComponent*> &componentList,
  741. const MaterialFeatureData &fd )
  742. {
  743. // We only need to process normals during the deferred.
  744. if ( !fd.features.hasFeature( MFT_DeferredConditioner ) )
  745. return;
  746. MultiLine *meta = new MultiLine;
  747. // Make sure the world to tangent transform
  748. // is created and available for the pixel shader.
  749. getOutViewToTangent( componentList, meta, fd );
  750. output = meta;
  751. }
  752. void TerrainNormalMapFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
  753. const MaterialFeatureData &fd )
  754. {
  755. // We only need to process normals during the deferred.
  756. if (!fd.features.hasFeature(MFT_DeferredConditioner))
  757. return;
  758. MultiLine *meta = new MultiLine;
  759. Var *viewToTangent = getInViewToTangent( componentList );
  760. // This var is read from GBufferConditionerGLSL and
  761. // used in the deferred output.
  762. Var *gbNormal = (Var*)LangElement::find( "gbNormal" );
  763. if ( !gbNormal )
  764. {
  765. gbNormal = new Var;
  766. gbNormal->setName( "gbNormal" );
  767. gbNormal->setType( "vec3" );
  768. meta->addStatement( new GenOp( " @ = tGetMatrix3Row(@, 2);\r\n", new DecOp( gbNormal ), viewToTangent ) );
  769. }
  770. const S32 normalIndex = getProcessIndex();
  771. Var *detailBlend = (Var*)LangElement::find( String::ToString( "detailBlend%d", normalIndex ) );
  772. AssertFatal( detailBlend, "The detail blend is missing!" );
  773. // If we're using SM 3.0 then take advantage of
  774. // dynamic branching to skip layers per-pixel.
  775. if ( GFX->getPixelShaderVersion() >= 3.0f )
  776. meta->addStatement( new GenOp( " if ( @ > 0.0f )\r\n", detailBlend ) );
  777. meta->addStatement( new GenOp( " {\r\n" ) );
  778. // Get the normal map texture.
  779. Var *normalMap = _getNormalMapTex();
  780. /// Get the texture coord.
  781. Var *inDet = _getInDetailCoord( componentList );
  782. Var *inTex = getVertTexCoord( "texCoord" );
  783. // Sample the normal map.
  784. //
  785. // We take two normal samples and lerp between them for
  786. // side projection layers... else a single sample.
  787. LangElement *texOp;
  788. if ( fd.features.hasFeature( MFT_TerrainSideProject, normalIndex ) )
  789. {
  790. texOp = new GenOp( "lerp( tex2D( @, @.yz ), tex2D( @, @.xz ), @.z )",
  791. normalMap, inDet, normalMap, inDet, inTex );
  792. }
  793. else
  794. texOp = new GenOp( "tex2D(@, @.xy)", normalMap, inDet );
  795. // create bump normal
  796. Var *bumpNorm = new Var;
  797. bumpNorm->setName( "bumpNormal" );
  798. bumpNorm->setType( "vec4" );
  799. LangElement *bumpNormDecl = new DecOp( bumpNorm );
  800. meta->addStatement( expandNormalMap( texOp, bumpNormDecl, bumpNorm, fd ) );
  801. // Normalize is done later...
  802. // Note: The reverse mul order is intentional. Affine matrix.
  803. meta->addStatement( new GenOp( " @ = lerp( @, tMul( @.xyz, @ ), min( @, @.w ) );\r\n",
  804. gbNormal, gbNormal, bumpNorm, viewToTangent, detailBlend, inDet ) );
  805. // End the conditional block.
  806. meta->addStatement( new GenOp( " }\r\n" ) );
  807. // If this is the last normal map then we
  808. // can test to see the total blend value
  809. // to see if we should clip the result.
  810. //if ( fd.features.getNextFeatureIndex( MFT_TerrainNormalMap, normalIndex ) == -1 )
  811. //meta->addStatement( new GenOp( " clip( @ - 0.0001f );\r\n", blendTotal ) );
  812. output = meta;
  813. }
  814. ShaderFeature::Resources TerrainNormalMapFeatGLSL::getResources( const MaterialFeatureData &fd )
  815. {
  816. Resources res;
  817. // We only need to process normals during the deferred.
  818. if ( fd.features.hasFeature( MFT_DeferredConditioner ) )
  819. {
  820. // If this is the first normal map and there
  821. // are no parallax features then we will
  822. // generate the worldToTanget transform.
  823. if ( !fd.features.hasFeature( MFT_TerrainParallaxMap ) &&
  824. ( getProcessIndex() == 0 || !fd.features.hasFeature( MFT_TerrainNormalMap, getProcessIndex() - 1 ) ) )
  825. res.numTexReg = 3;
  826. res.numTex = 1;
  827. }
  828. return res;
  829. }
  830. void TerrainLightMapFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
  831. const MaterialFeatureData &fd )
  832. {
  833. // grab connector texcoord register
  834. Var *inTex = (Var*)LangElement::find( "texCoord" );
  835. if ( !inTex )
  836. return;
  837. // Get the lightmap texture.
  838. Var *lightMap = new Var;
  839. lightMap->setType( "sampler2D" );
  840. lightMap->setName( "lightMapTex" );
  841. lightMap->uniform = true;
  842. lightMap->sampler = true;
  843. lightMap->constNum = Var::getTexUnitNum();
  844. MultiLine *meta = new MultiLine;
  845. // Find or create the lightMask value which is read by
  846. // RTLighting to mask out the lights.
  847. //
  848. // The first light is always the sunlight so we apply
  849. // the shadow mask to only the first channel.
  850. //
  851. Var *lightMask = (Var*)LangElement::find( "lightMask" );
  852. if ( !lightMask )
  853. {
  854. lightMask = new Var( "lightMask", "vec4" );
  855. meta->addStatement( new GenOp( " @ = vec4(1);\r\n", new DecOp( lightMask ) ) );
  856. }
  857. meta->addStatement( new GenOp( " @[0] = tex2D( @, @.xy ).r;\r\n", lightMask, lightMap, inTex ) );
  858. output = meta;
  859. }
  860. ShaderFeature::Resources TerrainLightMapFeatGLSL::getResources( const MaterialFeatureData &fd )
  861. {
  862. Resources res;
  863. res.numTex = 1;
  864. return res;
  865. }
  866. void TerrainAdditiveFeatGLSL::processPix( Vector<ShaderComponent*> &componentList,
  867. const MaterialFeatureData &fd )
  868. {
  869. Var *color = NULL;
  870. Var *normal = NULL;
  871. if (fd.features[MFT_DeferredTerrainDetailMap])
  872. {
  873. color = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::RenderTarget1) );
  874. normal = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::DefaultTarget) );
  875. }
  876. else
  877. color = (Var*) LangElement::find( getOutputTargetVarName(ShaderFeature::DefaultTarget) );
  878. Var *blendTotal = (Var*)LangElement::find( "blendTotal" );
  879. if ( !color || !blendTotal )
  880. return;
  881. MultiLine *meta = new MultiLine;
  882. meta->addStatement( new GenOp( " clip( @ - 0.0001 );\r\n", blendTotal ) );
  883. meta->addStatement( new GenOp( " @.a = @;\r\n", color, blendTotal ) );
  884. if (normal)
  885. meta->addStatement(new GenOp(" @.a = @;\r\n", normal, blendTotal));
  886. output = meta;
  887. }
  888. //standard matInfo map contains data of the form .r = bitflags, .g = (will contain AO),
  889. //.b = specular strength, a= spec power.
  890. //here, it's merely a cutout for now, so that lightmapping (target3) doesn't get mangled.
  891. //we'll most likely revisit that later. possibly several ways...
  892. U32 TerrainBlankInfoMapFeatGLSL::getOutputTargets(const MaterialFeatureData &fd) const
  893. {
  894. return fd.features[MFT_isDeferred] ? ShaderFeature::RenderTarget2 : ShaderFeature::RenderTarget1;
  895. }
  896. void TerrainBlankInfoMapFeatGLSL::processPix(Vector<ShaderComponent*> &componentList,
  897. const MaterialFeatureData &fd)
  898. {
  899. // search for material var
  900. Var *material;
  901. OutputTarget targ = RenderTarget1;
  902. if (fd.features[MFT_isDeferred])
  903. {
  904. targ = RenderTarget2;
  905. }
  906. material = (Var*)LangElement::find(getOutputTargetVarName(targ));
  907. MultiLine * meta = new MultiLine;
  908. if (!material)
  909. {
  910. // create color var
  911. material = new Var;
  912. material->setType("vec4");
  913. material->setName(getOutputTargetVarName(targ));
  914. material->setStructName("OUT");
  915. }
  916. meta->addStatement(new GenOp(" @ = float4(0.0,0.0,0.0,0.0001);\r\n", material));
  917. output = meta;
  918. }