Shaders.cpp 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  1. //-------------------------------------------------------------------------------
  2. /**
  3. * This program is distributed under the terms of the GNU Lesser General
  4. * Public License (LGPL).
  5. *
  6. * ASSIMP Viewer Utility
  7. *
  8. */
  9. //-------------------------------------------------------------------------------
  10. #include "stdafx.h"
  11. #include "assimp_view.h"
  12. namespace AssimpView {
  13. std::string g_szNormalsShader = std::string(
  14. //-------------------------------------------------------------------------------\n"
  15. /**\n"
  16. * This program is distributed under the terms of the GNU Lesser General\n
  17. * Public License (LGPL). \n
  18. *\n
  19. * ASSIMP Viewer Utility\n
  20. *\n"
  21. */
  22. //-------------------------------------------------------------------------------\n"
  23. // World * View * Projection matrix\n"
  24. // NOTE: Assume that the material uses a WorldViewProjection matrix\n"
  25. "float4x4 WorldViewProjection : WORLDVIEWPROJECTION;\n"
  26. "float4 OUTPUT_COLOR;\n"
  27. // ----------------------------------------------------------------------------\n"
  28. // Vertex shader input structure\n"
  29. // ----------------------------------------------------------------------------\n"
  30. "struct VS_INPUT\n"
  31. "{\n"
  32. "// Position\n"
  33. "float3 Position : POSITION;\n"
  34. "};\n"
  35. // ----------------------------------------------------------------------------\n"
  36. // Vertex shader output structure\n"
  37. // ----------------------------------------------------------------------------\n"
  38. "struct VS_OUTPUT\n"
  39. "{\n"
  40. "// Position\n"
  41. "float4 Position : POSITION;\n"
  42. "};\n"
  43. // ----------------------------------------------------------------------------\n"
  44. // Vertex shader\n"
  45. // ----------------------------------------------------------------------------\n"
  46. "VS_OUTPUT RenderNormalsVS(VS_INPUT IN)\n"
  47. "{\n"
  48. "// Initialize the output structure with zero\n"
  49. "VS_OUTPUT Out = (VS_OUTPUT)0;\n"
  50. "// Multiply with the WorldViewProjection matrix\n"
  51. "Out.Position = mul(float4(IN.Position,1.0f),WorldViewProjection);\n"
  52. "return Out;\n"
  53. "}\n"
  54. // ----------------------------------------------------------------------------\n"
  55. // Pixel shader\n"
  56. // ----------------------------------------------------------------------------\n"
  57. "float4 RenderNormalsPS() : COLOR\n"
  58. "{\n"
  59. "return OUTPUT_COLOR;\n"
  60. "}\n"
  61. // ----------------------------------------------------------------------------\n"
  62. // Technique for the normal rendering effect (ps_2_0)\n"
  63. // ----------------------------------------------------------------------------\n"
  64. "technique RenderNormals\n"
  65. "{\n"
  66. "pass p0\n"
  67. "{\n"
  68. "CullMode=none;\n"
  69. "PixelShader = compile ps_2_0 RenderNormalsPS();\n"
  70. "VertexShader = compile vs_2_0 RenderNormalsVS();\n"
  71. "}\n"
  72. "};\n"
  73. );
  74. std::string g_szSkyboxShader = std::string(
  75. //-------------------------------------------------------------------------------\n"
  76. /**\n"
  77. * This program is distributed under the terms of the GNU Lesser General\n
  78. * Public License (LGPL). \n
  79. *\n
  80. * ASSIMP Viewer Utility\n
  81. *\n"
  82. */
  83. //-------------------------------------------------------------------------------\n"
  84. // ----------------------------------------------------------------------------\n"
  85. // Sampler and texture for the skybox\n"
  86. // ----------------------------------------------------------------------------\n"
  87. "textureCUBE lw_tex_envmap;\n"
  88. "samplerCUBE EnvironmentMapSampler = sampler_state\n"
  89. "{\n"
  90. "Texture = (lw_tex_envmap);\n"
  91. "AddressU = CLAMP;\n"
  92. "AddressV = CLAMP;\n"
  93. "AddressW = CLAMP;\n"
  94. "MAGFILTER = linear;\n"
  95. "MINFILTER = linear;\n"
  96. "};\n"
  97. // World * View * Projection matrix\n"
  98. // NOTE: Assume that the material uses a WorldViewProjection matrix\n"
  99. "float4x4 WorldViewProjection : WORLDVIEWPROJECTION;\n"
  100. // ----------------------------------------------------------------------------\n"
  101. // Vertex shader input structure\n"
  102. // ----------------------------------------------------------------------------\n"
  103. "struct VS_INPUT\n"
  104. "{\n"
  105. // Position\n"
  106. "float3 Position : POSITION;\n"
  107. // 3D-Texture coordinate\n"
  108. "float3 Texture0 : TEXCOORD0;\n"
  109. "};\n"
  110. // ----------------------------------------------------------------------------\n"
  111. // Vertex shader output structure\n"
  112. // ----------------------------------------------------------------------------\n"
  113. "struct VS_OUTPUT\n"
  114. "{\n"
  115. // Position\n"
  116. "float4 Position : POSITION;\n"
  117. // 3D-Texture coordinate\n"
  118. "float3 Texture0 : TEXCOORD0;\n"
  119. "};\n"
  120. // ----------------------------------------------------------------------------\n"
  121. // Vertex shader\n"
  122. // ----------------------------------------------------------------------------\n"
  123. "VS_OUTPUT RenderSkyBoxVS(VS_INPUT IN)\n"
  124. "{\n"
  125. // Initialize the output structure with zero\n"
  126. "VS_OUTPUT Out = (VS_OUTPUT)0;\n"
  127. // Multiply with the WorldViewProjection matrix\n"
  128. "Out.Position = mul(float4(IN.Position,1.0f),WorldViewProjection);\n"
  129. // Set z to w to ensure z becomes 1.0 after the division through\n"
  130. // w occurs\n"
  131. "Out.Position.z = Out.Position.w;\n"
  132. // Simply pass through texture coordinates\n"
  133. "Out.Texture0 = IN.Texture0;\n"
  134. "return Out;\n"
  135. "}\n"
  136. // ----------------------------------------------------------------------------\n"
  137. // Pixel shader\n"
  138. // ----------------------------------------------------------------------------\n"
  139. "float4 RenderSkyBoxPS(float3 Texture0 : TEXCOORD0) : COLOR\n"
  140. "{\n"
  141. // Lookup the skybox texture\n"
  142. "return texCUBE(EnvironmentMapSampler,Texture0) ;\n"
  143. "}\n"
  144. // ----------------------------------------------------------------------------\n"
  145. // Technique for the skybox shader (ps_2_0)\n"
  146. // ----------------------------------------------------------------------------\n"
  147. "technique RenderSkyBox\n"
  148. "{\n"
  149. "pass p0\n"
  150. "{\n"
  151. "ZWriteEnable = FALSE;\n"
  152. "FogEnable = FALSE;\n"
  153. "CullMode = NONE;\n"
  154. "PixelShader = compile ps_2_0 RenderSkyBoxPS();\n"
  155. "VertexShader = compile vs_2_0 RenderSkyBoxVS();\n"
  156. "}\n"
  157. "};\n"
  158. "texture TEXTURE_2D;\n"
  159. "sampler TEXTURE_SAMPLER = sampler_state\n"
  160. "{\n"
  161. "Texture = (TEXTURE_2D);\n"
  162. "};\n"
  163. // ----------------------------------------------------------------------------\n"
  164. "struct VS_OUTPUT2\n"
  165. "{\n"
  166. "// Position\n"
  167. "float4 _Position : POSITION;\n"
  168. "// Texture coordinate\n"
  169. "float2 _TexCoord0 : TEXCOORD0;\n"
  170. "};\n"
  171. // ----------------------------------------------------------------------------\n"
  172. "VS_OUTPUT2 RenderImageVS(float4 INPosition : POSITION,\n"
  173. "float2 INTexCoord0 : TEXCOORD0 )\n"
  174. "{\n"
  175. // Initialize the output structure with zero\n"
  176. "VS_OUTPUT2 Out = (VS_OUTPUT2)0;\n"
  177. "Out._Position.xy = INPosition.xy;\n"
  178. "Out._Position.z = Out._Position.w = 1.0f;\n"
  179. "Out._TexCoord0 = INTexCoord0;\n"
  180. "return Out;\n"
  181. "}\n"
  182. // ----------------------------------------------------------------------------\n"
  183. "float4 RenderImagePS(float2 IN : TEXCOORD0) : COLOR\n"
  184. "{\n"
  185. "return tex2D(TEXTURE_SAMPLER,IN);\n"
  186. "}\n"
  187. // ----------------------------------------------------------------------------\n"
  188. // Technique for the background image shader (ps_2_0)\n"
  189. // ----------------------------------------------------------------------------\n"
  190. "technique RenderImage2D\n"
  191. "{\n"
  192. "pass p0\n"
  193. "{\n"
  194. "ZWriteEnable = FALSE;\n"
  195. "FogEnable = FALSE;\n"
  196. "CullMode = NONE;\n"
  197. "PixelShader = compile ps_2_0 RenderImagePS();\n"
  198. "VertexShader = compile vs_2_0 RenderImageVS();\n"
  199. "}\n"
  200. "};\n"
  201. );
  202. std::string g_szDefaultShader = std::string(
  203. //-------------------------------------------------------------------------------\n"
  204. /**\n"
  205. * This program is distributed under the terms of the GNU Lesser General\n
  206. * Public License (LGPL). \n
  207. *\n
  208. * ASSIMP Viewer Utility\n
  209. *\n"
  210. */
  211. //-------------------------------------------------------------------------------\n"
  212. // World * View * Projection matrix\n"
  213. // NOTE: Assume that the material uses a WorldViewProjection matrix\n"
  214. "float4x4 WorldViewProjection : WORLDVIEWPROJECTION;\n"
  215. "float4x4 World : WORLD;\n"
  216. "float4x3 WorldInverseTranspose : WORLDINVERSETRANSPOSE;\n"
  217. // light colors\n"
  218. "float3 afLightColor[5];\n"
  219. // light direction \n"
  220. "float3 afLightDir[5];\n"
  221. // position of the camera in worldspace\n"
  222. "float3 vCameraPos : CAMERAPOSITION;\n"
  223. // ----------------------------------------------------------------------------\n"
  224. // Vertex shader input structure\n"
  225. // ----------------------------------------------------------------------------\n"
  226. "struct VS_INPUT\n"
  227. "{\n"
  228. "// Position\n"
  229. "float3 Position : POSITION;\n"
  230. "float3 Normal : NORMAL;\n"
  231. "};\n"
  232. // ----------------------------------------------------------------------------\n"
  233. // Vertex shader output structure\n"
  234. // ----------------------------------------------------------------------------\n"
  235. "struct VS_OUTPUT\n"
  236. "{\n"
  237. // Position\n"
  238. "float4 Position : POSITION;\n"
  239. "float3 ViewDir : TEXCOORD0;\n"
  240. "float3 Normal : TEXCOORD1;\n"
  241. "};\n"
  242. // ----------------------------------------------------------------------------\n"
  243. // Vertex shader\n"
  244. // ----------------------------------------------------------------------------\n"
  245. "VS_OUTPUT DefaultVShader(VS_INPUT IN)\n"
  246. "{\n"
  247. // Initialize the output structure with zero\n"
  248. "VS_OUTPUT Out = (VS_OUTPUT)0;\n"
  249. // Multiply with the WorldViewProjection matrix\n"
  250. "Out.Position = mul(float4(IN.Position,1.0f),WorldViewProjection);\n"
  251. "float3 WorldPos = mul(float4(IN.Position,1.0f),World);\n"
  252. "Out.ViewDir = vCameraPos - WorldPos;\n"
  253. "Out.Normal = mul(IN.Normal,WorldInverseTranspose);\n"
  254. "return Out;\n"
  255. "}\n"
  256. // ----------------------------------------------------------------------------\n"
  257. // Pixel shader\n"
  258. // ----------------------------------------------------------------------------\n"
  259. "float4 DefaultPShaderSpecular_D1(VS_OUTPUT IN) : COLOR\n"
  260. "{\n"
  261. "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
  262. "float3 Normal = normalize(IN.Normal);\n"
  263. "float3 ViewDir = normalize(IN.ViewDir);\n"
  264. "{\n"
  265. "float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
  266. "float3 Reflect = reflect (Normal,afLightDir[0]);\n"
  267. "float fHalfLambert = L1*L1;\n"
  268. "OUT.rgb += afLightColor[0] * (fHalfLambert +\n"
  269. "saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,ViewDir),9));\n"
  270. "}\n"
  271. "return OUT;\n"
  272. "}\n"
  273. // ----------------------------------------------------------------------------\n"
  274. "float4 DefaultPShaderSpecular_D2(VS_OUTPUT IN) : COLOR\n"
  275. "{\n"
  276. "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
  277. "float3 Normal = normalize(IN.Normal);\n"
  278. "float3 ViewDir = normalize(IN.ViewDir);\n"
  279. "{\n"
  280. "float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
  281. "float3 Reflect = reflect (ViewDir,Normal);\n"
  282. "float fHalfLambert = L1*L1;\n"
  283. "OUT.rgb += afLightColor[0] * (fHalfLambert +\n"
  284. "saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,afLightDir[0]),9));\n"
  285. "}\n"
  286. "{\n"
  287. "float L1 = dot(Normal,afLightDir[1]) * 0.5f + 0.5f;\n"
  288. "float3 Reflect = reflect (ViewDir,Normal);\n"
  289. "float fHalfLambert = L1*L1;\n"
  290. "OUT.rgb += afLightColor[1] * (fHalfLambert +\n"
  291. "saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,afLightDir[1]),9));\n"
  292. "}\n"
  293. "return OUT;\n"
  294. "}\n"
  295. // ----------------------------------------------------------------------------\n"
  296. "float4 DefaultPShaderSpecular_PS20_D1(VS_OUTPUT IN) : COLOR\n"
  297. "{\n"
  298. "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
  299. "float3 Normal = normalize(IN.Normal);\n"
  300. "float3 ViewDir = normalize(IN.ViewDir);\n"
  301. "{\n"
  302. "float L1 = dot(Normal,afLightDir[0]);\n"
  303. "float3 Reflect = reflect (Normal,afLightDir[0]);\n"
  304. "OUT.rgb += afLightColor[0] * ((L1) +\n"
  305. "pow(dot(Reflect,ViewDir),9));\n"
  306. "}\n"
  307. "return OUT;\n"
  308. "}\n"
  309. // ----------------------------------------------------------------------------\n"
  310. "float4 DefaultPShaderSpecular_PS20_D2(VS_OUTPUT IN) : COLOR\n"
  311. "{\n"
  312. "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
  313. "float3 Normal = normalize(IN.Normal);\n"
  314. "float3 ViewDir = normalize(IN.ViewDir);\n"
  315. "{\n"
  316. "float L1 = dot(Normal,afLightDir[0]);\n"
  317. "float3 Reflect = reflect (Normal,afLightDir[0]);\n"
  318. "OUT.rgb += afLightColor[0] * ((L1) +\n"
  319. "pow(dot(Reflect,ViewDir),9));\n"
  320. "}\n"
  321. "{\n"
  322. "float L1 = dot(Normal,afLightDir[1]);\n"
  323. "float3 Reflect = reflect (Normal,afLightDir[1]);\n"
  324. "OUT.rgb += afLightColor[1] * ((L1) +\n"
  325. "pow(dot(Reflect,ViewDir),9));\n"
  326. "}\n"
  327. "return OUT;\n"
  328. "}\n"
  329. // ----------------------------------------------------------------------------\n"
  330. // Technique for the default effect\n"
  331. // ----------------------------------------------------------------------------\n"
  332. "technique DefaultFXSpecular_D1\n"
  333. "{\n"
  334. "pass p0\n"
  335. "{\n"
  336. "CullMode=none;\n"
  337. "PixelShader = compile ps_3_0 DefaultPShaderSpecular_D1();\n"
  338. "VertexShader = compile vs_3_0 DefaultVShader();\n"
  339. "}\n"
  340. "};\n"
  341. "technique DefaultFXSpecular_D2\n"
  342. "{\n"
  343. "pass p0\n"
  344. "{\n"
  345. "CullMode=none;\n"
  346. "PixelShader = compile ps_3_0 DefaultPShaderSpecular_D2();\n"
  347. "VertexShader = compile vs_3_0 DefaultVShader();\n"
  348. "}\n"
  349. "};\n"
  350. // ----------------------------------------------------------------------------\n"
  351. // Technique for the default effect (ps_2_0)\n"
  352. // ----------------------------------------------------------------------------\n"
  353. "technique DefaultFXSpecular_PS20_D1\n"
  354. "{\n"
  355. "pass p0\n"
  356. "{\n"
  357. "CullMode=none;\n"
  358. "PixelShader = compile ps_2_0 DefaultPShaderSpecular_PS20_D1();\n"
  359. "VertexShader = compile vs_2_0 DefaultVShader();\n"
  360. "}\n"
  361. "};\n"
  362. "technique DefaultFXSpecular_PS20_D2\n"
  363. "{\n"
  364. "pass p0\n"
  365. "{\n"
  366. "CullMode=none;\n"
  367. "PixelShader = compile ps_2_0 DefaultPShaderSpecular_PS20_D2();\n"
  368. "VertexShader = compile vs_2_0 DefaultVShader();\n"
  369. "}\n"
  370. "};\n"
  371. );
  372. std::string g_szMaterialShader = std::string(
  373. //-------------------------------------------------------------------------------\n"
  374. /**\n"
  375. * This program is distributed under the terms of the GNU Lesser General\n
  376. * Public License (LGPL). \n
  377. *\n
  378. * ASSIMP Viewer Utility\n
  379. *\n"
  380. */
  381. //-------------------------------------------------------------------------------\n"
  382. // World * View * Projection matrix\n"
  383. // NOTE: Assume that the material uses a WorldViewProjection matrix\n"
  384. "float4x4 WorldViewProjection : WORLDVIEWPROJECTION;\n"
  385. "float4x4 World : WORLD;\n"
  386. "float4x3 WorldInverseTranspose : WORLDINVERSETRANSPOSE;\n"
  387. "#ifndef AV_DISABLESSS\n"
  388. "float4x3 ViewProj;\n"
  389. "float4x3 InvViewProj;\n"
  390. "#endif\n"
  391. // light colors (diffuse and specular)\n"
  392. "float4 afLightColor[5];\n"
  393. "float4 afLightColorAmbient[5];\n"
  394. // light direction \n"
  395. "float3 afLightDir[5];\n"
  396. // position of the camera in worldspace\n"
  397. "float3 vCameraPos : CAMERAPOSITION;\n"
  398. "#ifdef AV_DIFFUSE_TEXTURE\n"
  399. "texture DIFFUSE_TEXTURE;\n"
  400. "sampler DIFFUSE_SAMPLER\n"
  401. "{\n"
  402. "Texture = <DIFFUSE_TEXTURE>;\n"
  403. "MinFilter=LINEAR;\n"
  404. "MagFilter=LINEAR;\n"
  405. "MipFilter=LINEAR;\n"
  406. "};\n"
  407. "#endif // AV_DIFFUSE_TEXTUR\n"
  408. "#ifdef AV_SPECULAR_TEXTURE\n"
  409. "texture SPECULAR_TEXTURE;\n"
  410. "sampler SPECULAR_SAMPLER\n"
  411. "{\n"
  412. "Texture = <SPECULAR_TEXTURE>;\n"
  413. "MinFilter=LINEAR;\n"
  414. "MagFilter=LINEAR;\n"
  415. "MipFilter=LINEAR;\n"
  416. "};\n"
  417. "#endif // AV_SPECULAR_TEXTUR\n"
  418. "#ifdef AV_AMBIENT_TEXTURE\n"
  419. "texture AMBIENT_TEXTURE;\n"
  420. "sampler AMBIENT_SAMPLER\n"
  421. "{\n"
  422. "Texture = <AMBIENT_TEXTURE>;\n"
  423. "MinFilter=LINEAR;\n"
  424. "MagFilter=LINEAR;\n"
  425. "MipFilter=LINEAR;\n"
  426. "};\n"
  427. "#endif // AV_AMBIENT_TEXTUR\n"
  428. "#ifdef AV_OPACITY_TEXTURE\n"
  429. "texture OPACITY_TEXTURE;\n"
  430. "sampler OPACITY_SAMPLER\n"
  431. "{\n"
  432. "Texture = <OPACITY_TEXTURE>;\n"
  433. "MinFilter=LINEAR;\n"
  434. "MagFilter=LINEAR;\n"
  435. "MipFilter=LINEAR;\n"
  436. "};\n"
  437. "#endif // AV_OPACITY_TEXTURE\n"
  438. "#ifdef AV_EMISSIVE_TEXTURE\n"
  439. "texture EMISSIVE_TEXTURE;\n"
  440. "sampler EMISSIVE_SAMPLER\n"
  441. "{\n"
  442. "Texture = <EMISSIVE_TEXTURE>;\n"
  443. "MinFilter=LINEAR;\n"
  444. "MagFilter=LINEAR;\n"
  445. "MipFilter=LINEAR;\n"
  446. "};\n"
  447. "#endif // AV_EMISSIVE_TEXTUR\n"
  448. "#ifdef AV_NORMAL_TEXTURE\n"
  449. "texture NORMAL_TEXTURE;\n"
  450. "sampler NORMAL_SAMPLER\n"
  451. "{\n"
  452. "Texture = <NORMAL_TEXTURE>;\n"
  453. "MinFilter=LINEAR;\n"
  454. "MagFilter=LINEAR;\n"
  455. "MipFilter=LINEAR;\n"
  456. "};\n"
  457. "#endif // AV_NORMAL_TEXTURE\n"
  458. "#ifdef AV_SKYBOX_LOOKUP\n"
  459. "textureCUBE lw_tex_envmap;\n"
  460. "samplerCUBE EnvironmentMapSampler = sampler_state\n"
  461. "{\n"
  462. "Texture = (lw_tex_envmap);\n"
  463. "AddressU = CLAMP;\n"
  464. "AddressV = CLAMP;\n"
  465. "AddressW = CLAMP;\n"
  466. "MAGFILTER = linear;\n"
  467. "MINFILTER = linear;\n"
  468. "};\n"
  469. "#endif // AV_SKYBOX_LOOKUP\n"
  470. "float4 DIFFUSE_COLOR;\n"
  471. "float4 SPECULAR_COLOR;\n"
  472. "float4 AMBIENT_COLOR;\n"
  473. "float4 EMISSIVE_COLOR;\n"
  474. "#ifdef AV_SPECULAR_COMPONENT\n"
  475. "float SPECULARITY;\n"
  476. "#endif\n"
  477. "#ifdef AV_OPACITY\n"
  478. "float TRANSPARENCY;\n"
  479. "#endif\n"
  480. // ----------------------------------------------------------------------------\n"
  481. // Vertex shader input structure\n"
  482. // ----------------------------------------------------------------------------\n"
  483. "struct VS_INPUT\n"
  484. "{\n"
  485. // Position\n"
  486. "float3 Position : POSITION;\n"
  487. "float3 Normal : NORMAL;\n"
  488. // NOTE: Tangents and bitangents are passed to the shader
  489. // in every case, even if not required. This saves a few lines
  490. // of code ...
  491. "float3 Tangent : TEXCOORD0;\n"
  492. "float3 Bitangent : TEXCOORD1;\n"
  493. "float2 TexCoord0 : TEXCOORD2;\n"
  494. "};\n"
  495. // ----------------------------------------------------------------------------\n"
  496. // Vertex shader output structure\n"
  497. // ----------------------------------------------------------------------------\n"
  498. "struct VS_OUTPUT\n"
  499. "{\n"
  500. // Position\n"
  501. "float4 Position : POSITION;\n"
  502. "float3 ViewDir : TEXCOORD0;\n"
  503. "#ifndef AV_NORMAL_TEXTURE\n"
  504. "float3 Normal : TEXCOORD1;\n"
  505. "#endif\n"
  506. "float2 TexCoord0 : TEXCOORD2;\n"
  507. "#ifdef AV_NORMAL_TEXTURE\n"
  508. "float3 Light0 : TEXCOORD3;\n"
  509. "float3 Light1 : TEXCOORD4;\n"
  510. "#endif\n"
  511. "};\n"
  512. // ----------------------------------------------------------------------------\n"
  513. // Selective SuperSampling in screenspace for reflection lookups\n"
  514. // ----------------------------------------------------------------------------\n"
  515. "#ifndef AV_SKYBOX_LOOKUP\n"
  516. "#define AV_DISABLESSS\n"
  517. "#endif\n"
  518. "#ifndef AV_DISABLESSS\n"
  519. "float3 GetSSSCubeMap(float3 Reflect)\n"
  520. "{\n"
  521. // compute the reflection vector in screen space\n"
  522. "float3 ScreenReflect = mul(Reflect,ViewProj);\n"
  523. // compute the gradients of the reflection vector\n"
  524. "float3 fDX = ddx(ScreenReflect);\n"
  525. "float3 fDY = ddy(ScreenReflect);\n"
  526. // take the center step and calculate gradients for it\n"
  527. "float3 fColor = texCUBE(EnvironmentMapSampler,Reflect).rgb;\n"
  528. // Take 10 samples around the center step \n"
  529. "fColor += texCUBEgrad(EnvironmentMapSampler,mul( ScreenReflect + (0.4f * 2.0 / 3.5) * fDX + (0.4f * 2.0 / 3.5) * fDY, InvViewProj),fDX,fDY).rgb;\n"
  530. "fColor += texCUBEgrad(EnvironmentMapSampler,mul( ScreenReflect + (0.4f * 3.0 / 3.5) * fDX + (0.4f *-1.0 / 3.5) * fDY, InvViewProj),fDX,fDY).rgb;\n"
  531. "fColor += texCUBEgrad(EnvironmentMapSampler,mul( ScreenReflect + (0.4f * 1.0 / 3.5) * fDX + (0.4f *-3.0 / 3.5) * fDY, InvViewProj),fDX,fDY).rgb;\n"
  532. "fColor += texCUBEgrad(EnvironmentMapSampler,mul( ScreenReflect + (0.4f *-2.0 / 3.5) * fDX + (0.4f *-2.0 / 3.5) * fDY, InvViewProj),fDX,fDY).rgb;\n"
  533. "fColor += texCUBEgrad(EnvironmentMapSampler,mul( ScreenReflect + (0.4f *-3.0 / 3.5) * fDX + (0.4f * 1.0 / 3.5) * fDY, InvViewProj),fDX,fDY).rgb;\n"
  534. "fColor += texCUBEgrad(EnvironmentMapSampler,mul( ScreenReflect + (0.4f *-1.0 / 3.5) * fDX + (0.4f * 3.0 / 3.5) * fDY, InvViewProj),fDX,fDY).rgb;\n"
  535. "fColor /= 7;\n"
  536. "return fColor;\n"
  537. "}\n"
  538. "#else\n"
  539. "#define GetSSSCubeMap(_refl) (texCUBElod(EnvironmentMapSampler,float4(_refl,0.0f)).rgb) \n"
  540. "#endif\n"
  541. // bugfix: if normal mapping is active we have the reflection
  542. // vector in tangent, not in world space. Would need the inverse
  543. // of the TSM matrix in the pixel shader (or world space tangent mapping)
  544. // Simply disable realtime reflection for normal mapping.
  545. "#ifdef AV_NORMAL_TEXTURE\n"
  546. "#undef GetSSSCubeMap\n"
  547. "#define GetSSSCubeMap(_refl) (float3(1.0f,1.0f,1.0f))\n"
  548. "#endif\n"
  549. // ----------------------------------------------------------------------------\n"
  550. // Vertex shader\n"
  551. // ----------------------------------------------------------------------------\n"
  552. "VS_OUTPUT MaterialVShader_D1(VS_INPUT IN)\n"
  553. "{\n"
  554. // Initialize the output structure with zero\n"
  555. "VS_OUTPUT Out = (VS_OUTPUT)0;\n"
  556. // Multiply with the WorldViewProjection matrix\n"
  557. "Out.Position = mul(float4(IN.Position,1.0f),WorldViewProjection);\n"
  558. "float3 WorldPos = mul(float4(IN.Position,1.0f),World);\n"
  559. "Out.TexCoord0 = IN.TexCoord0;\n"
  560. "#ifndef AV_NORMAL_TEXTURE\n"
  561. "Out.ViewDir = vCameraPos - WorldPos;\n"
  562. "Out.Normal = mul(IN.Normal,WorldInverseTranspose);\n"
  563. "#endif\n"
  564. "#ifdef AV_NORMAL_TEXTURE\n"
  565. "float3x3 TBNMatrix = float3x3(IN.Tangent, IN.Bitangent, IN.Normal);\n"
  566. "float3x3 WTTS = mul(TBNMatrix, (float3x3)WorldInverseTranspose);\n"
  567. "Out.Light0 = normalize(mul(WTTS, afLightDir[0] ));\n"
  568. "Out.ViewDir = normalize(mul(WTTS, (vCameraPos - WorldPos)));\n"
  569. "#endif\n"
  570. "return Out;\n"
  571. "}\n"
  572. "// ----------------------------------------------------------------------------\n"
  573. "VS_OUTPUT MaterialVShader_D2(VS_INPUT IN)\n"
  574. "{\n"
  575. // Initialize the output structure with zero\n"
  576. "VS_OUTPUT Out = (VS_OUTPUT)0;\n"
  577. // Multiply with the WorldViewProjection matrix\n"
  578. "Out.Position = mul(float4(IN.Position,1.0f),WorldViewProjection);\n"
  579. "float3 WorldPos = mul(float4(IN.Position,1.0f),World);\n"
  580. "Out.TexCoord0 = IN.TexCoord0;\n"
  581. "#ifndef AV_NORMAL_TEXTURE\n"
  582. "Out.ViewDir = vCameraPos - WorldPos;\n"
  583. "Out.Normal = mul(IN.Normal,WorldInverseTranspose);\n"
  584. "#endif\n"
  585. "#ifdef AV_NORMAL_TEXTURE\n"
  586. "float3x3 TBNMatrix = float3x3(IN.Tangent, IN.Bitangent, IN.Normal);\n"
  587. "float3x3 WTTS = mul(TBNMatrix, (float3x3)WorldInverseTranspose);\n"
  588. "Out.Light0 = normalize(mul(WTTS, afLightDir[0] ));\n"
  589. "Out.Light1 = normalize(mul(WTTS, afLightDir[1] ));\n"
  590. "Out.ViewDir = normalize(mul(WTTS, (vCameraPos - WorldPos)));\n"
  591. "#endif\n"
  592. "return Out;\n"
  593. "}\n"
  594. // ----------------------------------------------------------------------------\n"
  595. // Pixel shader\n"
  596. // ----------------------------------------------------------------------------\n"
  597. "float4 MaterialPShaderSpecular_D1(VS_OUTPUT IN) : COLOR\n"
  598. "{\n"
  599. "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
  600. "#ifdef AV_NORMAL_TEXTURE\n"
  601. "float3 IN_Light0 = normalize(IN.Light0);\n"
  602. "float3 Normal = normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0).rgb - 1.0f);\n"
  603. "#else\n"
  604. "float3 Normal = normalize(IN.Normal);\n"
  605. "#endif \n"
  606. "float3 ViewDir = normalize(IN.ViewDir);\n"
  607. "#ifdef AV_SPECULAR_COMPONENT\n"
  608. "float3 Reflect = -normalize(reflect (ViewDir,Normal));\n"
  609. "#endif // !AV_SPECULAR_COMPONENT\n"
  610. "{\n"
  611. "#ifdef AV_NORMAL_TEXTURE\n"
  612. "float L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;\n"
  613. "#define AV_LIGHT_0 IN_Light0\n"
  614. // would need to convert the reflection vector into world space ....
  615. // simply let it ...
  616. "#else\n"
  617. "float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
  618. "#define AV_LIGHT_0 afLightDir[0]\n"
  619. "#endif\n"
  620. "float fHalfLambert = L1*L1;\n"
  621. "#ifdef AV_DIFFUSE_TEXTURE\n"
  622. "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * fHalfLambert +\n"
  623. "#else\n"
  624. "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * fHalfLambert +\n"
  625. "#endif // !AV_DIFFUSE_TEXTURE\n"
  626. "#ifdef AV_SPECULAR_COMPONENT\n"
  627. "#ifndef AV_SKYBOX_LOOKUP\n"
  628. "#ifdef AV_SPECULAR_TEXTURE\n"
  629. "SPECULAR_COLOR.rgb * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
  630. "#else\n"
  631. "SPECULAR_COLOR.rgb * afLightColor[0].rgb * (saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
  632. "#endif // !AV_SPECULAR_TEXTURE\n"
  633. "#else\n"
  634. "#ifdef AV_SPECULAR_TEXTURE\n"
  635. "SPECULAR_COLOR.rgb * afLightColor[0].rgb * GetSSSCubeMap(Reflect) * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
  636. "#else\n"
  637. "SPECULAR_COLOR.rgb * afLightColor[0].rgb * GetSSSCubeMap(Reflect) * (saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
  638. "#endif // !AV_SPECULAR_TEXTURE\n"
  639. "#endif // !AV_SKYBOX_LOOKUP\n"
  640. "#endif // !AV_SPECULAR_COMPONENT\n"
  641. "#ifdef AV_AMBIENT_TEXTURE\n"
  642. "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +\n"
  643. "#else\n"
  644. "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb + \n"
  645. "#endif // !AV_AMBIENT_TEXTURE\n"
  646. "#ifdef AV_EMISSIVE_TEXTURE\n"
  647. "EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
  648. "#else \n"
  649. "EMISSIVE_COLOR.rgb;\n"
  650. "#endif // !AV_EMISSIVE_TEXTURE\n"
  651. "}\n"
  652. "#ifdef AV_OPACITY\n"
  653. "OUT.a = TRANSPARENCY;\n"
  654. "#endif\n"
  655. "#ifdef AV_OPACITY_TEXTURE\n"
  656. "OUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;\n"
  657. "#endif\n"
  658. "return OUT;\n"
  659. "#undef AV_LIGHT_0\n"
  660. "}\n"
  661. // ----------------------------------------------------------------------------\n"
  662. "float4 MaterialPShaderSpecular_D2(VS_OUTPUT IN) : COLOR\n"
  663. "{\n"
  664. "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
  665. "#ifdef AV_NORMAL_TEXTURE\n"
  666. "float3 IN_Light0 = normalize(IN.Light0);\n"
  667. "float3 IN_Light1 = normalize(IN.Light1);\n"
  668. "float3 Normal = normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0).rgb - 1.0f);\n"
  669. "#else\n"
  670. "float3 Normal = normalize(IN.Normal);\n"
  671. "#endif \n"
  672. "float3 ViewDir = normalize(IN.ViewDir);\n"
  673. "#ifdef AV_SPECULAR_COMPONENT\n"
  674. "float3 Reflect = -normalize(reflect (ViewDir,Normal));\n"
  675. "#endif // !AV_SPECULAR_COMPONENT\n"
  676. "{\n"
  677. "#ifdef AV_NORMAL_TEXTURE\n"
  678. "float L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;\n"
  679. "#define AV_LIGHT_0 IN_Light0\n"
  680. "#else\n"
  681. "float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
  682. "#define AV_LIGHT_0 afLightDir[0]\n"
  683. "#endif\n"
  684. "float fHalfLambert = L1*L1;\n"
  685. "#ifdef AV_DIFFUSE_TEXTURE\n"
  686. "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * fHalfLambert +\n"
  687. "#else\n"
  688. "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * fHalfLambert +\n"
  689. "#endif // !AV_DIFFUSE_TEXTURE\n"
  690. "#ifdef AV_SPECULAR_COMPONENT\n"
  691. "#ifndef AV_SKYBOX_LOOKUP\n"
  692. "#ifdef AV_SPECULAR_TEXTURE\n"
  693. "SPECULAR_COLOR.rgb * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
  694. "#else\n"
  695. "SPECULAR_COLOR.rgb * afLightColor[0].rgb * (saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
  696. "#endif // !AV_SPECULAR_TEXTURE\n"
  697. "#else\n"
  698. "#ifdef AV_SPECULAR_TEXTURE\n"
  699. "SPECULAR_COLOR.rgb * afLightColor[0].rgb * GetSSSCubeMap(Reflect) * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
  700. "#else\n"
  701. "SPECULAR_COLOR.rgb * afLightColor[0].rgb * GetSSSCubeMap(Reflect) * (saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
  702. "#endif // !AV_SPECULAR_TEXTURE\n"
  703. "#endif // !AV_SKYBOX_LOOKUP\n"
  704. "#endif // !AV_SPECULAR_COMPONENT\n"
  705. "#ifdef AV_AMBIENT_TEXTURE\n"
  706. "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb + \n"
  707. "#else\n"
  708. "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb + \n"
  709. "#endif // !AV_AMBIENT_TEXTURE\n"
  710. "#ifdef AV_EMISSIVE_TEXTURE\n"
  711. "EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
  712. "#else \n"
  713. "EMISSIVE_COLOR.rgb;\n"
  714. "#endif // !AV_EMISSIVE_TEXTURE\n"
  715. "}\n"
  716. "{\n"
  717. "#ifdef AV_NORMAL_TEXTURE\n"
  718. "float L1 = dot(Normal,IN_Light1) * 0.5f + 0.5f;\n"
  719. "#define AV_LIGHT_1 IN_Light1\n"
  720. "#else\n"
  721. "float L1 = dot(Normal,afLightDir[1]) * 0.5f + 0.5f;\n"
  722. "#define AV_LIGHT_1 afLightDir[1]\n"
  723. "#endif\n"
  724. "float fHalfLambert = L1*L1;\n"
  725. "#ifdef AV_DIFFUSE_TEXTURE\n"
  726. "OUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * fHalfLambert +\n"
  727. "#else\n"
  728. "OUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * fHalfLambert +\n"
  729. "#endif // !AV_DIFFUSE_TEXTURE\n"
  730. "#ifdef AV_SPECULAR_COMPONENT\n"
  731. "#ifndef AV_SKYBOX_LOOKUP\n"
  732. "#ifdef AV_SPECULAR_TEXTURE\n"
  733. "SPECULAR_COLOR.rgb * afLightColor[1].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,AV_LIGHT_1),SPECULARITY)) + \n"
  734. "#else\n"
  735. "SPECULAR_COLOR.rgb * afLightColor[1].rgb * (saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,AV_LIGHT_1),SPECULARITY)) + \n"
  736. "#endif // !AV_SPECULAR_TEXTURE\n"
  737. "#else\n"
  738. "#ifdef AV_SPECULAR_TEXTURE\n"
  739. "SPECULAR_COLOR.rgb * afLightColor[1].rgb * GetSSSCubeMap(Reflect) * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,AV_LIGHT_1),SPECULARITY)) + \n"
  740. "#else\n"
  741. "SPECULAR_COLOR.rgb * afLightColor[1].rgb * GetSSSCubeMap(Reflect) * (saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,AV_LIGHT_1),SPECULARITY)) + \n"
  742. "#endif // !AV_SPECULAR_TEXTURE\n"
  743. "#endif // !AV_SKYBOX_LOOKUP\n"
  744. "#endif // !AV_SPECULAR_COMPONENT\n"
  745. "#ifdef AV_AMBIENT_TEXTURE\n"
  746. "AMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb + \n"
  747. "#else\n"
  748. "AMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb + \n"
  749. "#endif // !AV_AMBIENT_TEXTURE\n"
  750. "#ifdef AV_EMISSIVE_TEXTURE\n"
  751. "EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
  752. "#else \n"
  753. "EMISSIVE_COLOR.rgb;\n"
  754. "#endif // !AV_EMISSIVE_TEXTURE\n"
  755. "}\n"
  756. "#ifdef AV_OPACITY\n"
  757. "OUT.a = TRANSPARENCY;\n"
  758. "#endif\n"
  759. "#ifdef AV_OPACITY_TEXTURE\n"
  760. "OUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;\n"
  761. "#endif\n"
  762. "return OUT;\n"
  763. "#undef AV_LIGHT_0\n"
  764. "#undef AV_LIGHT_1\n"
  765. "}\n"
  766. // ----------------------------------------------------------------------------\n"
  767. "float4 MaterialPShaderSpecular_PS20_D1(VS_OUTPUT IN) : COLOR\n"
  768. "{\n"
  769. "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
  770. "#ifdef AV_NORMAL_TEXTURE\n"
  771. "float3 IN_Light0 = normalize(IN.Light0);\n"
  772. "float3 Normal = normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0).rgb - 1.0f);\n"
  773. "#else\n"
  774. "float3 Normal = normalize(IN.Normal);\n"
  775. "#endif \n"
  776. "float3 ViewDir = normalize(IN.ViewDir);\n"
  777. "{\n"
  778. "#ifdef AV_NORMAL_TEXTURE\n"
  779. "float L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;\n"
  780. "float3 Reflect = reflect (Normal,IN_Light0);\n"
  781. "#else\n"
  782. "float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
  783. "float3 Reflect = reflect (Normal,afLightDir[0]);\n"
  784. "#endif\n"
  785. "#ifdef AV_DIFFUSE_TEXTURE\n"
  786. "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * L1 +\n"
  787. "#else\n"
  788. "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * L1 +\n"
  789. "#endif // !AV_DIFFUSE_TEXTURE\n"
  790. "#ifdef AV_SPECULAR_COMPONENT\n"
  791. "#ifdef AV_SPECULAR_TEXTURE\n"
  792. "SPECULAR_COLOR.rgb * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
  793. "#else\n"
  794. "SPECULAR_COLOR.rgb * afLightColor[0].rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
  795. "#endif // !AV_SPECULAR_TEXTURE\n"
  796. "#endif // !AV_SPECULAR_COMPONENT\n"
  797. "#ifdef AV_AMBIENT_TEXTURE\n"
  798. "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +\n"
  799. "#else\n"
  800. "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb +\n"
  801. "#endif // !AV_AMBIENT_TEXTURE\n"
  802. "#ifdef AV_EMISSIVE_TEXTURE\n"
  803. "EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
  804. "#else \n"
  805. "EMISSIVE_COLOR.rgb;\n"
  806. "#endif // !AV_EMISSIVE_TEXTURE\n"
  807. "}\n"
  808. "#ifdef AV_OPACITY\n"
  809. "OUT.a = TRANSPARENCY;\n"
  810. "#endif\n"
  811. "#ifdef AV_OPACITY_TEXTURE\n"
  812. "OUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;\n"
  813. "#endif\n"
  814. "return OUT;\n"
  815. "}\n"
  816. // ----------------------------------------------------------------------------\n"
  817. "float4 MaterialPShaderSpecular_PS20_D2(VS_OUTPUT IN) : COLOR\n"
  818. "{\n"
  819. "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
  820. "#ifdef AV_NORMAL_TEXTURE\n"
  821. "float3 IN_Light0 = normalize(IN.Light0);\n"
  822. "float3 IN_Light1 = normalize(IN.Light1);\n"
  823. "float3 Normal = normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0) - 1.0f);\n"
  824. "#else\n"
  825. "float3 Normal = normalize(IN.Normal);\n"
  826. "#endif \n"
  827. "float3 ViewDir = normalize(IN.ViewDir);\n"
  828. "{\n"
  829. "#ifdef AV_NORMAL_TEXTURE\n"
  830. "float L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;\n"
  831. "float3 Reflect = reflect (Normal,IN_Light0);\n"
  832. "#else\n"
  833. "float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
  834. "float3 Reflect = reflect (Normal,afLightDir[0]);\n"
  835. "#endif\n"
  836. "#ifdef AV_DIFFUSE_TEXTURE\n"
  837. "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * L1 +\n"
  838. "#else\n"
  839. "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * L1 +\n"
  840. "#endif // !AV_DIFFUSE_TEXTURE\n"
  841. "#ifdef AV_SPECULAR_COMPONENT\n"
  842. "#ifdef AV_SPECULAR_TEXTURE\n"
  843. "SPECULAR_COLOR.rgb * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
  844. "#else\n"
  845. "SPECULAR_COLOR.rgb * afLightColor[0].rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
  846. "#endif // !AV_SPECULAR_TEXTURE\n"
  847. "#endif // !AV_SPECULAR_COMPONENT\n"
  848. "#ifdef AV_AMBIENT_TEXTURE\n"
  849. "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +\n"
  850. "#else\n"
  851. "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb +\n"
  852. "#endif // !AV_AMBIENT_TEXTURE\n"
  853. "#ifdef AV_EMISSIVE_TEXTURE\n"
  854. "EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
  855. "#else \n"
  856. "EMISSIVE_COLOR.rgb;\n"
  857. "#endif // !AV_EMISSIVE_TEXTURE\n"
  858. "}\n"
  859. "{\n"
  860. "#ifdef AV_NORMAL_TEXTURE\n"
  861. "float L1 = dot(Normal,IN_Light1) * 0.5f + 0.5f;\n"
  862. "float3 Reflect = reflect (Normal,IN_Light1);\n"
  863. "#else\n"
  864. "float L1 = dot(Normal,afLightDir[1]) * 0.5f + 0.5f;\n"
  865. "float3 Reflect = reflect (Normal,afLightDir[1]);\n"
  866. "#endif\n"
  867. "#ifdef AV_DIFFUSE_TEXTURE\n"
  868. "OUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * L1 +\n"
  869. "#else\n"
  870. "OUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * L1 +\n"
  871. "#endif // !AV_DIFFUSE_TEXTURE\n"
  872. "#ifdef AV_SPECULAR_COMPONENT\n"
  873. "#ifdef AV_SPECULAR_TEXTURE\n"
  874. "SPECULAR_COLOR.rgb * afLightColor[1].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
  875. "#else\n"
  876. "SPECULAR_COLOR.rgb * afLightColor[1].rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
  877. "#endif // !AV_SPECULAR_TEXTURE\n"
  878. "#endif // !AV_SPECULAR_COMPONENT\n"
  879. "#ifdef AV_AMBIENT_TEXTURE\n"
  880. "AMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +\n"
  881. "#else\n"
  882. "AMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb + \n"
  883. "#endif // !AV_AMBIENT_TEXTURE\n"
  884. "#ifdef AV_EMISSIVE_TEXTURE\n"
  885. "EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
  886. "#else \n"
  887. "EMISSIVE_COLOR.rgb;\n"
  888. "#endif // !AV_EMISSIVE_TEXTURE\n"
  889. "}\n"
  890. "#ifdef AV_OPACITY\n"
  891. "OUT.a = TRANSPARENCY;\n"
  892. "#endif\n"
  893. "#ifdef AV_OPACITY_TEXTURE\n"
  894. "OUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;\n"
  895. "#endif\n"
  896. "return OUT;\n"
  897. "}\n"
  898. // ----------------------------------------------------------------------------\n"
  899. // Technique for the material effect\n"
  900. // ----------------------------------------------------------------------------\n"
  901. "technique MaterialFXSpecular_D1\n"
  902. "{\n"
  903. "pass p0\n"
  904. "{\n"
  905. "CullMode=none;\n"
  906. "#ifdef AV_OPACITY_TEXTURE\n"
  907. "AlphaBlendEnable=TRUE;"
  908. "SrcBlend = srcalpha;\n"
  909. "DestBlend = invsrcalpha;\n"
  910. "#else\n"
  911. "#ifdef AV_OPACITY\n"
  912. "AlphaBlendEnable=TRUE;"
  913. "SrcBlend = srcalpha;\n"
  914. "DestBlend = invsrcalpha;\n"
  915. "#endif \n"
  916. "#endif\n"
  917. "PixelShader = compile ps_3_0 MaterialPShaderSpecular_D1();\n"
  918. "VertexShader = compile vs_3_0 MaterialVShader_D1();\n"
  919. "}\n"
  920. "};\n"
  921. "technique MaterialFXSpecular_D2\n"
  922. "{\n"
  923. "pass p0\n"
  924. "{\n"
  925. "CullMode=none;\n"
  926. "#ifdef AV_OPACITY_TEXTURE\n"
  927. "AlphaBlendEnable=TRUE;"
  928. "SrcBlend = srcalpha;\n"
  929. "DestBlend = invsrcalpha;\n"
  930. "#else\n"
  931. "#ifdef AV_OPACITY\n"
  932. "AlphaBlendEnable=TRUE;"
  933. "SrcBlend = srcalpha;\n"
  934. "DestBlend = invsrcalpha;\n"
  935. "#endif \n"
  936. "#endif\n"
  937. "PixelShader = compile ps_3_0 MaterialPShaderSpecular_D2();\n"
  938. "VertexShader = compile vs_3_0 MaterialVShader_D2();\n"
  939. "}\n"
  940. "};\n"
  941. // ----------------------------------------------------------------------------\n"
  942. // Technique for the material effect (ps_2_0)\n"
  943. // ----------------------------------------------------------------------------\n"
  944. "technique MaterialFXSpecular_PS20_D1\n"
  945. "{\n"
  946. "pass p0\n"
  947. "{\n"
  948. "CullMode=none;\n"
  949. "#ifdef AV_OPACITY_TEXTURE\n"
  950. "AlphaBlendEnable=TRUE;"
  951. "SrcBlend = srcalpha;\n"
  952. "DestBlend = invsrcalpha;\n"
  953. "#else\n"
  954. "#ifdef AV_OPACITY\n"
  955. "AlphaBlendEnable=TRUE;"
  956. "SrcBlend = srcalpha;\n"
  957. "DestBlend = invsrcalpha;\n"
  958. "#endif \n"
  959. "#endif\n"
  960. "PixelShader = compile ps_2_0 MaterialPShaderSpecular_PS20_D1();\n"
  961. "VertexShader = compile vs_2_0 MaterialVShader_D1();\n"
  962. "}\n"
  963. "};\n"
  964. "technique MaterialFXSpecular_PS20_D2\n"
  965. "{\n"
  966. "pass p0\n"
  967. "{\n"
  968. "CullMode=none;\n"
  969. "#ifdef AV_OPACITY_TEXTURE\n"
  970. "AlphaBlendEnable=TRUE;"
  971. "SrcBlend = srcalpha;\n"
  972. "DestBlend = invsrcalpha;\n"
  973. "#else\n"
  974. "#ifdef AV_OPACITY\n"
  975. "AlphaBlendEnable=TRUE;"
  976. "SrcBlend = srcalpha;\n"
  977. "DestBlend = invsrcalpha;\n"
  978. "#endif \n"
  979. "#endif\n"
  980. "PixelShader = compile ps_2_0 MaterialPShaderSpecular_PS20_D2();\n"
  981. "VertexShader = compile vs_2_0 MaterialVShader_D2();\n"
  982. "}\n"
  983. "};\n"
  984. );
  985. std::string g_szPassThroughShader = std::string(
  986. //-------------------------------------------------------------------------------\n"
  987. /**\n"
  988. * This program is distributed under the terms of the GNU Lesser General\n
  989. * Public License (LGPL). \n
  990. *\n
  991. * ASSIMP Viewer Utility\n
  992. *\n"
  993. */
  994. //-------------------------------------------------------------------------------\n"
  995. "texture TEXTURE_2D;\n"
  996. "sampler TEXTURE_SAMPLER = sampler_state\n"
  997. "{\n"
  998. "Texture = (TEXTURE_2D);\n"
  999. "};\n"
  1000. // ----------------------------------------------------------------------------\n"
  1001. "struct VS_OUTPUT\n"
  1002. "{\n"
  1003. "// Position\n"
  1004. "float4 _Position : POSITION;\n"
  1005. "// Texture coordinate\n"
  1006. "float2 _TexCoord0 : TEXCOORD0;\n"
  1007. "};\n"
  1008. // ----------------------------------------------------------------------------\n"
  1009. "VS_OUTPUT DefaultVShader(float4 INPosition : POSITION,\n"
  1010. "float2 INTexCoord0 : TEXCOORD0 )\n"
  1011. "{\n"
  1012. "// Initialize the output structure with zero\n"
  1013. "VS_OUTPUT Out = (VS_OUTPUT)0;\n"
  1014. "Out._Position = INPosition;\n"
  1015. "Out._TexCoord0 = INTexCoord0;\n"
  1016. "return Out;\n"
  1017. "}\n"
  1018. // ----------------------------------------------------------------------------\n"
  1019. "float4 PassThrough_PS(float2 IN : TEXCOORD0) : COLOR\n"
  1020. "{\n"
  1021. "return tex2D(TEXTURE_SAMPLER,IN);\n"
  1022. "}\n"
  1023. // ----------------------------------------------------------------------------\n"
  1024. // Simple pass-through technique\n"
  1025. // ----------------------------------------------------------------------------\n"
  1026. "technique PassThrough\n"
  1027. "{\n"
  1028. "pass p0\n"
  1029. "{\n"
  1030. "FillMode=Solid;\n"
  1031. "ZEnable = FALSE;\n"
  1032. "CullMode = none;\n"
  1033. "AlphaBlendEnable = TRUE;\n"
  1034. "SrcBlend =srcalpha;\n"
  1035. "DestBlend =invsrcalpha;\n"
  1036. "PixelShader = compile ps_2_0 PassThrough_PS();\n"
  1037. "VertexShader = compile vs_2_0 DefaultVShader();\n"
  1038. "}\n"
  1039. "};\n"
  1040. );
  1041. };