You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1414 lines
44 KiB

  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2012, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. #include "stdafx.h"
  35. #include "assimp_view.h"
  36. namespace AssimpView
  37. {
  38. // ------------------------------------------------------------------------------------------------
  39. std::string g_szNormalsShader = std::string(
  40. // World * View * Projection matrix\n"
  41. // NOTE: Assume that the material uses a WorldViewProjection matrix\n"
  42. "float4x4 WorldViewProjection : WORLDVIEWPROJECTION;\n"
  43. "float4 OUTPUT_COLOR;\n"
  44. // Vertex shader input structure
  45. "struct VS_INPUT\n"
  46. "{\n"
  47. "// Position\n"
  48. "float3 Position : POSITION;\n"
  49. "};\n"
  50. // Vertex shader output structure for pixel shader usage
  51. "struct VS_OUTPUT\n"
  52. "{\n"
  53. "float4 Position : POSITION;\n"
  54. "};\n"
  55. // Vertex shader output structure for FixedFunction usage
  56. "struct VS_OUTPUT_FF\n"
  57. "{\n"
  58. "float4 Position : POSITION;\n"
  59. "float4 Color : COLOR;\n"
  60. "};\n"
  61. // Vertex shader for rendering normals using pixel shader
  62. "VS_OUTPUT RenderNormalsVS(VS_INPUT IN)\n"
  63. "{\n"
  64. "// Initialize the output structure with zero\n"
  65. "VS_OUTPUT Out = (VS_OUTPUT)0;\n"
  66. "// Multiply with the WorldViewProjection matrix\n"
  67. "Out.Position = mul(float4(IN.Position,1.0f),WorldViewProjection);\n"
  68. "return Out;\n"
  69. "}\n"
  70. // Vertex shader for rendering normals using fixed function pipeline
  71. "VS_OUTPUT_FF RenderNormalsVS_FF(VS_INPUT IN)\n"
  72. "{\n"
  73. "VS_OUTPUT_FF Out;\n"
  74. "Out.Position = mul(float4(IN.Position,1.0f),WorldViewProjection);\n"
  75. "Out.Color = OUTPUT_COLOR;\n"
  76. "return Out;\n"
  77. "}\n"
  78. // Pixel shader
  79. "float4 RenderNormalsPS() : COLOR\n"
  80. "{\n"
  81. "return OUTPUT_COLOR;\n"
  82. "}\n"
  83. // Technique for the normal rendering effect (ps_2_0)
  84. "technique RenderNormals\n"
  85. "{\n"
  86. "pass p0\n"
  87. "{\n"
  88. "CullMode=none;\n"
  89. "PixelShader = compile ps_2_0 RenderNormalsPS();\n"
  90. "VertexShader = compile vs_2_0 RenderNormalsVS();\n"
  91. "}\n"
  92. "};\n"
  93. // Technique for the normal rendering effect (fixed function)
  94. "technique RenderNormals_FF\n"
  95. "{\n"
  96. "pass p0\n"
  97. "{\n"
  98. "CullMode=none;\n"
  99. "VertexShader = compile vs_2_0 RenderNormalsVS_FF();\n"
  100. "ColorOp[0] = SelectArg1;\n"
  101. "ColorArg0[0] = Diffuse;\n"
  102. "AlphaOp[0] = SelectArg1;\n"
  103. "AlphaArg0[0] = Diffuse;\n"
  104. "}\n"
  105. "};\n"
  106. );
  107. // ------------------------------------------------------------------------------------------------
  108. std::string g_szSkyboxShader = std::string(
  109. // Sampler and texture for the skybox
  110. "textureCUBE lw_tex_envmap;\n"
  111. "samplerCUBE EnvironmentMapSampler = sampler_state\n"
  112. "{\n"
  113. "Texture = (lw_tex_envmap);\n"
  114. "AddressU = CLAMP;\n"
  115. "AddressV = CLAMP;\n"
  116. "AddressW = CLAMP;\n"
  117. "MAGFILTER = linear;\n"
  118. "MINFILTER = linear;\n"
  119. "};\n"
  120. // World * View * Projection matrix\n"
  121. // NOTE: Assume that the material uses a WorldViewProjection matrix\n"
  122. "float4x4 WorldViewProjection : WORLDVIEWPROJECTION;\n"
  123. // Vertex shader input structure
  124. "struct VS_INPUT\n"
  125. "{\n"
  126. "float3 Position : POSITION;\n"
  127. "float3 Texture0 : TEXCOORD0;\n"
  128. "};\n"
  129. // Vertex shader output structure
  130. "struct VS_OUTPUT\n"
  131. "{\n"
  132. "float4 Position : POSITION;\n"
  133. "float3 Texture0 : TEXCOORD0;\n"
  134. "};\n"
  135. // Vertex shader
  136. "VS_OUTPUT RenderSkyBoxVS(VS_INPUT IN)\n"
  137. "{\n"
  138. "VS_OUTPUT Out;\n"
  139. // Multiply with the WorldViewProjection matrix
  140. "Out.Position = mul(float4(IN.Position,1.0f),WorldViewProjection);\n"
  141. // Set z to w to ensure z becomes 1.0 after the division through w occurs
  142. "Out.Position.z = Out.Position.w;\n"
  143. // Simply pass through texture coordinates
  144. "Out.Texture0 = IN.Texture0;\n"
  145. "return Out;\n"
  146. "}\n"
  147. // Pixel shader
  148. "float4 RenderSkyBoxPS(float3 Texture0 : TEXCOORD0) : COLOR\n"
  149. "{\n"
  150. // Lookup the skybox texture
  151. "return texCUBE(EnvironmentMapSampler,Texture0) ;\n"
  152. "}\n"
  153. // Technique for the skybox shader (ps_2_0)
  154. "technique RenderSkyBox\n"
  155. "{\n"
  156. "pass p0\n"
  157. "{\n"
  158. "ZWriteEnable = FALSE;\n"
  159. "FogEnable = FALSE;\n"
  160. "CullMode = NONE;\n"
  161. "PixelShader = compile ps_2_0 RenderSkyBoxPS();\n"
  162. "VertexShader = compile vs_2_0 RenderSkyBoxVS();\n"
  163. "}\n"
  164. "};\n"
  165. // -------------- same for static background image -----------------
  166. "texture TEXTURE_2D;\n"
  167. "sampler TEXTURE_SAMPLER = sampler_state\n"
  168. "{\n"
  169. "Texture = (TEXTURE_2D);\n"
  170. "};\n"
  171. "struct VS_OUTPUT2\n"
  172. "{\n"
  173. "float4 Position : POSITION;\n"
  174. "float2 TexCoord0 : TEXCOORD0;\n"
  175. "};\n"
  176. "VS_OUTPUT2 RenderImageVS(float4 INPosition : POSITION, float2 INTexCoord0 : TEXCOORD0 )\n"
  177. "{\n"
  178. "VS_OUTPUT2 Out;\n"
  179. "Out.Position.xy = INPosition.xy;\n"
  180. "Out.Position.z = Out.Position.w = 1.0f;\n"
  181. "Out.TexCoord0 = INTexCoord0;\n"
  182. "return Out;\n"
  183. "}\n"
  184. "float4 RenderImagePS(float2 IN : TEXCOORD0) : COLOR\n"
  185. "{\n"
  186. "return tex2D(TEXTURE_SAMPLER,IN);\n"
  187. "}\n"
  188. // Technique for the background image shader (ps_2_0)
  189. "technique RenderImage2D\n"
  190. "{\n"
  191. "pass p0\n"
  192. "{\n"
  193. "ZWriteEnable = FALSE;\n"
  194. "FogEnable = FALSE;\n"
  195. "CullMode = NONE;\n"
  196. "PixelShader = compile ps_2_0 RenderImagePS();\n"
  197. "VertexShader = compile vs_2_0 RenderImageVS();\n"
  198. "}\n"
  199. "};\n"
  200. );
  201. std::string g_szDefaultShader = std::string(
  202. // World * View * Projection matrix
  203. // NOTE: Assume that the material uses a WorldViewProjection matrix
  204. "float4x4 WorldViewProjection : WORLDVIEWPROJECTION;\n"
  205. "float4x4 World : WORLD;\n"
  206. "float4x3 WorldInverseTranspose : WORLDINVERSETRANSPOSE;\n"
  207. // light colors
  208. "float3 afLightColor[5];\n"
  209. // light direction
  210. "float3 afLightDir[5];\n"
  211. // position of the camera in worldspace\n"
  212. "float3 vCameraPos : CAMERAPOSITION;\n"
  213. // Bone matrices
  214. // "#ifdef AV_SKINNING \n"
  215. "float4x3 gBoneMatrix[60]; \n"
  216. // "#endif // AV_SKINNING \n"
  217. // Vertex shader input structure
  218. "struct VS_INPUT\n"
  219. "{\n"
  220. "float3 Position : POSITION;\n"
  221. "float3 Normal : NORMAL;\n"
  222. // "#ifdef AV_SKINNING \n"
  223. "float4 BlendIndices : BLENDINDICES;\n"
  224. "float4 BlendWeights : BLENDWEIGHT;\n"
  225. // "#endif // AV_SKINNING \n"
  226. "};\n"
  227. // Vertex shader output structure for pixel shader usage
  228. "struct VS_OUTPUT\n"
  229. "{\n"
  230. "float4 Position : POSITION;\n"
  231. "float3 ViewDir : TEXCOORD0;\n"
  232. "float3 Normal : TEXCOORD1;\n"
  233. "};\n"
  234. // Vertex shader output structure for fixed function
  235. "struct VS_OUTPUT_FF\n"
  236. "{\n"
  237. "float4 Position : POSITION;\n"
  238. "float4 Color : COLOR;\n"
  239. "};\n"
  240. // Vertex shader for pixel shader usage
  241. "VS_OUTPUT DefaultVShader(VS_INPUT IN)\n"
  242. "{\n"
  243. "VS_OUTPUT Out;\n"
  244. // "#ifdef AV_SKINNING \n"
  245. "float4 weights = IN.BlendWeights; \n"
  246. "weights.w = 1.0f - dot( weights.xyz, float3( 1, 1, 1)); \n"
  247. "float4 localPos = float4( IN.Position, 1.0f); \n"
  248. "float3 objPos = mul( localPos, gBoneMatrix[IN.BlendIndices.x]) * weights.x; \n"
  249. "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.y]) * weights.y; \n"
  250. "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.z]) * weights.z; \n"
  251. "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.w]) * weights.w; \n"
  252. // "#else \n"
  253. // "float3 objPos = IN.Position; \n"
  254. // "#endif // AV_SKINNING \n"
  255. // Multiply with the WorldViewProjection matrix
  256. "Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection);\n"
  257. "float3 WorldPos = mul( float4( objPos, 1.0f), World);\n"
  258. "Out.ViewDir = vCameraPos - WorldPos;\n"
  259. "Out.Normal = mul(IN.Normal,WorldInverseTranspose);\n"
  260. "return Out;\n"
  261. "}\n"
  262. // Vertex shader for fixed function pipeline
  263. "VS_OUTPUT_FF DefaultVShader_FF(VS_INPUT IN)\n"
  264. "{\n"
  265. "VS_OUTPUT_FF Out;\n"
  266. // "#ifdef AV_SKINNING \n"
  267. "float4 weights = IN.BlendWeights; \n"
  268. "weights.w = 1.0f - dot( weights.xyz, float3( 1, 1, 1)); \n"
  269. "float4 localPos = float4( IN.Position, 1.0f); \n"
  270. "float3 objPos = mul( localPos, gBoneMatrix[IN.BlendIndices.x]) * weights.x; \n"
  271. "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.y]) * weights.y; \n"
  272. "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.z]) * weights.z; \n"
  273. "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.w]) * weights.w; \n"
  274. // "#else \n"
  275. // "float3 objPos = IN.Position; \n"
  276. // "#endif // AV_SKINNING \n"
  277. // Multiply with the WorldViewProjection matrix
  278. "Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection);\n"
  279. "float3 worldNormal = normalize( mul( IN.Normal, (float3x3) WorldInverseTranspose)); \n"
  280. // per-vertex lighting. We simply assume light colors of unused lights to be black
  281. "Out.Color = float4( 0.2f, 0.2f, 0.2f, 1.0f); \n"
  282. "for( int a = 0; a < 2; a++)\n"
  283. " Out.Color.rgb += saturate( dot( afLightDir[a], worldNormal)) * afLightColor[a].rgb; \n"
  284. "return Out;\n"
  285. "}\n"
  286. // Pixel shader for one light
  287. "float4 DefaultPShaderSpecular_D1(VS_OUTPUT IN) : COLOR\n"
  288. "{\n"
  289. "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
  290. "float3 Normal = normalize(IN.Normal);\n"
  291. "float3 ViewDir = normalize(IN.ViewDir);\n"
  292. "{\n"
  293. "float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
  294. "float3 Reflect = reflect (Normal,afLightDir[0]);\n"
  295. "float fHalfLambert = L1*L1;\n"
  296. "OUT.rgb += afLightColor[0] * (fHalfLambert +\n"
  297. "saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,ViewDir),9));\n"
  298. "}\n"
  299. "return OUT;\n"
  300. "}\n"
  301. // Pixel shader for two lights
  302. "float4 DefaultPShaderSpecular_D2(VS_OUTPUT IN) : COLOR\n"
  303. "{\n"
  304. "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
  305. "float3 Normal = normalize(IN.Normal);\n"
  306. "float3 ViewDir = normalize(IN.ViewDir);\n"
  307. "{\n"
  308. "float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
  309. "float3 Reflect = reflect (ViewDir,Normal);\n"
  310. "float fHalfLambert = L1*L1;\n"
  311. "OUT.rgb += afLightColor[0] * (fHalfLambert +\n"
  312. "saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,afLightDir[0]),9));\n"
  313. "}\n"
  314. "{\n"
  315. "float L1 = dot(Normal,afLightDir[1]) * 0.5f + 0.5f;\n"
  316. "float3 Reflect = reflect (ViewDir,Normal);\n"
  317. "float fHalfLambert = L1*L1;\n"
  318. "OUT.rgb += afLightColor[1] * (fHalfLambert +\n"
  319. "saturate(fHalfLambert * 4.0f) * pow(dot(Reflect,afLightDir[1]),9));\n"
  320. "}\n"
  321. "return OUT;\n"
  322. "}\n"
  323. // ----------------------------------------------------------------------------
  324. "float4 DefaultPShaderSpecular_PS20_D1(VS_OUTPUT IN) : COLOR\n"
  325. "{\n"
  326. "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
  327. "float3 Normal = normalize(IN.Normal);\n"
  328. "float3 ViewDir = normalize(IN.ViewDir);\n"
  329. "{\n"
  330. "float L1 = dot(Normal,afLightDir[0]);\n"
  331. "float3 Reflect = reflect (Normal,afLightDir[0]);\n"
  332. "OUT.rgb += afLightColor[0] * ((L1) +\n"
  333. "pow(dot(Reflect,ViewDir),9));\n"
  334. "}\n"
  335. "return OUT;\n"
  336. "}\n"
  337. // ----------------------------------------------------------------------------
  338. "float4 DefaultPShaderSpecular_PS20_D2(VS_OUTPUT IN) : COLOR\n"
  339. "{\n"
  340. "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
  341. "float3 Normal = normalize(IN.Normal);\n"
  342. "float3 ViewDir = normalize(IN.ViewDir);\n"
  343. "{\n"
  344. "float L1 = dot(Normal,afLightDir[0]);\n"
  345. "float3 Reflect = reflect (Normal,afLightDir[0]);\n"
  346. "OUT.rgb += afLightColor[0] * ((L1) +\n"
  347. "pow(dot(Reflect,ViewDir),9));\n"
  348. "}\n"
  349. "{\n"
  350. "float L1 = dot(Normal,afLightDir[1]);\n"
  351. "float3 Reflect = reflect (Normal,afLightDir[1]);\n"
  352. "OUT.rgb += afLightColor[1] * ((L1) +\n"
  353. "pow(dot(Reflect,ViewDir),9));\n"
  354. "}\n"
  355. "return OUT;\n"
  356. "}\n"
  357. // Technique for the default effect
  358. "technique DefaultFXSpecular_D1\n"
  359. "{\n"
  360. "pass p0\n"
  361. "{\n"
  362. "CullMode=none;\n"
  363. "PixelShader = compile ps_3_0 DefaultPShaderSpecular_D1();\n"
  364. "VertexShader = compile vs_3_0 DefaultVShader();\n"
  365. "}\n"
  366. "};\n"
  367. "technique DefaultFXSpecular_D2\n"
  368. "{\n"
  369. "pass p0\n"
  370. "{\n"
  371. "CullMode=none;\n"
  372. "PixelShader = compile ps_3_0 DefaultPShaderSpecular_D2();\n"
  373. "VertexShader = compile vs_3_0 DefaultVShader();\n"
  374. "}\n"
  375. "};\n"
  376. // Technique for the default effect (ps_2_0)
  377. "technique DefaultFXSpecular_PS20_D1\n"
  378. "{\n"
  379. "pass p0\n"
  380. "{\n"
  381. "CullMode=none;\n"
  382. "PixelShader = compile ps_2_0 DefaultPShaderSpecular_PS20_D1();\n"
  383. "VertexShader = compile vs_2_0 DefaultVShader();\n"
  384. "}\n"
  385. "};\n"
  386. "technique DefaultFXSpecular_PS20_D2\n"
  387. "{\n"
  388. "pass p0\n"
  389. "{\n"
  390. "CullMode=none;\n"
  391. "PixelShader = compile ps_2_0 DefaultPShaderSpecular_PS20_D2();\n"
  392. "VertexShader = compile vs_2_0 DefaultVShader();\n"
  393. "}\n"
  394. "};\n"
  395. // Technique for the default effect using the fixed function pixel pipeline
  396. "technique DefaultFXSpecular_FF\n"
  397. "{\n"
  398. "pass p0\n"
  399. "{\n"
  400. "CullMode=none;\n"
  401. "VertexShader = compile vs_2_0 DefaultVShader_FF();\n"
  402. "ColorOp[0] = SelectArg1;\n"
  403. "ColorArg0[0] = Diffuse;\n"
  404. "AlphaOp[0] = SelectArg1;\n"
  405. "AlphaArg0[0] = Diffuse;\n"
  406. "}\n"
  407. "};\n"
  408. );
  409. std::string g_szMaterialShader = std::string(
  410. // World * View * Projection matrix
  411. // NOTE: Assume that the material uses a WorldViewProjection matrix
  412. "float4x4 WorldViewProjection : WORLDVIEWPROJECTION;\n"
  413. "float4x4 World : WORLD;\n"
  414. "float4x3 WorldInverseTranspose : WORLDINVERSETRANSPOSE;\n"
  415. "#ifndef AV_DISABLESSS\n"
  416. "float4x3 ViewProj;\n"
  417. "float4x3 InvViewProj;\n"
  418. "#endif\n"
  419. "float4 DIFFUSE_COLOR;\n"
  420. "float4 SPECULAR_COLOR;\n"
  421. "float4 AMBIENT_COLOR;\n"
  422. "float4 EMISSIVE_COLOR;\n"
  423. "#ifdef AV_SPECULAR_COMPONENT\n"
  424. "float SPECULARITY;\n"
  425. "float SPECULAR_STRENGTH;\n"
  426. "#endif\n"
  427. "#ifdef AV_OPACITY\n"
  428. "float TRANSPARENCY;\n"
  429. "#endif\n"
  430. // light colors (diffuse and specular)
  431. "float4 afLightColor[5];\n"
  432. "float4 afLightColorAmbient[5];\n"
  433. // light direction
  434. "float3 afLightDir[5];\n"
  435. // position of the camera in worldspace
  436. "float3 vCameraPos : CAMERAPOSITION;\n"
  437. // Bone matrices
  438. "#ifdef AV_SKINNING \n"
  439. "float4x3 gBoneMatrix[60]; \n"
  440. "#endif // AV_SKINNING \n"
  441. "#ifdef AV_DIFFUSE_TEXTURE\n"
  442. "texture DIFFUSE_TEXTURE;\n"
  443. "sampler DIFFUSE_SAMPLER\n"
  444. "{\n"
  445. "Texture = <DIFFUSE_TEXTURE>;\n"
  446. "#ifdef AV_WRAPU\n"
  447. "AddressU = WRAP;\n"
  448. "#endif\n"
  449. "#ifdef AV_MIRRORU\n"
  450. "AddressU = MIRROR;\n"
  451. "#endif\n"
  452. "#ifdef AV_CLAMPU\n"
  453. "AddressU = CLAMP;\n"
  454. "#endif\n"
  455. "#ifdef AV_WRAPV\n"
  456. "AddressV = WRAP;\n"
  457. "#endif\n"
  458. "#ifdef AV_MIRRORV\n"
  459. "AddressV = MIRROR;\n"
  460. "#endif\n"
  461. "#ifdef AV_CLAMPV\n"
  462. "AddressV = CLAMP;\n"
  463. "#endif\n"
  464. "};\n"
  465. "#endif // AV_DIFFUSE_TEXTUR\n"
  466. "#ifdef AV_DIFFUSE_TEXTURE2\n"
  467. "texture DIFFUSE_TEXTURE2;\n"
  468. "sampler DIFFUSE_SAMPLER2\n"
  469. "{\n"
  470. "Texture = <DIFFUSE_TEXTURE2>;\n"
  471. "};\n"
  472. "#endif // AV_DIFFUSE_TEXTUR2\n"
  473. "#ifdef AV_SPECULAR_TEXTURE\n"
  474. "texture SPECULAR_TEXTURE;\n"
  475. "sampler SPECULAR_SAMPLER\n"
  476. "{\n"
  477. "Texture = <SPECULAR_TEXTURE>;\n"
  478. "};\n"
  479. "#endif // AV_SPECULAR_TEXTUR\n"
  480. "#ifdef AV_AMBIENT_TEXTURE\n"
  481. "texture AMBIENT_TEXTURE;\n"
  482. "sampler AMBIENT_SAMPLER\n"
  483. "{\n"
  484. "Texture = <AMBIENT_TEXTURE>;\n"
  485. "};\n"
  486. "#endif // AV_AMBIENT_TEXTUR\n"
  487. "#ifdef AV_LIGHTMAP_TEXTURE\n"
  488. "texture LIGHTMAP_TEXTURE;\n"
  489. "sampler LIGHTMAP_SAMPLER\n"
  490. "{\n"
  491. "Texture = <LIGHTMAP_TEXTURE>;\n"
  492. "};\n"
  493. "#endif // AV_LIGHTMAP_TEXTURE\n"
  494. "#ifdef AV_OPACITY_TEXTURE\n"
  495. "texture OPACITY_TEXTURE;\n"
  496. "sampler OPACITY_SAMPLER\n"
  497. "{\n"
  498. "Texture = <OPACITY_TEXTURE>;\n"
  499. "};\n"
  500. "#endif // AV_OPACITY_TEXTURE\n"
  501. "#ifdef AV_EMISSIVE_TEXTURE\n"
  502. "texture EMISSIVE_TEXTURE;\n"
  503. "sampler EMISSIVE_SAMPLER\n"
  504. "{\n"
  505. "Texture = <EMISSIVE_TEXTURE>;\n"
  506. "};\n"
  507. "#endif // AV_EMISSIVE_TEXTUR\n"
  508. "#ifdef AV_NORMAL_TEXTURE\n"
  509. "texture NORMAL_TEXTURE;\n"
  510. "sampler NORMAL_SAMPLER\n"
  511. "{\n"
  512. "Texture = <NORMAL_TEXTURE>;\n"
  513. "};\n"
  514. "#endif // AV_NORMAL_TEXTURE\n"
  515. "#ifdef AV_SKYBOX_LOOKUP\n"
  516. "textureCUBE lw_tex_envmap;\n"
  517. "samplerCUBE EnvironmentMapSampler = sampler_state\n"
  518. "{\n"
  519. "Texture = (lw_tex_envmap);\n"
  520. "AddressU = CLAMP;\n"
  521. "AddressV = CLAMP;\n"
  522. "AddressW = CLAMP;\n"
  523. "MAGFILTER = linear;\n"
  524. "MINFILTER = linear;\n"
  525. "};\n"
  526. "#endif // AV_SKYBOX_LOOKUP\n"
  527. // Vertex shader input structure
  528. "struct VS_INPUT\n"
  529. "{\n"
  530. "float3 Position : POSITION;\n"
  531. "float3 Normal : NORMAL;\n"
  532. "float4 Color : COLOR0;\n"
  533. "float3 Tangent : TANGENT;\n"
  534. "float3 Bitangent : BINORMAL;\n"
  535. "float2 TexCoord0 : TEXCOORD0;\n"
  536. "#ifdef AV_TWO_UV \n"
  537. "float2 TexCoord1 : TEXCOORD1;\n"
  538. "#endif \n"
  539. "#ifdef AV_SKINNING \n"
  540. "float4 BlendIndices : BLENDINDICES;\n"
  541. "float4 BlendWeights : BLENDWEIGHT;\n"
  542. "#endif // AV_SKINNING \n"
  543. "};\n"
  544. // Vertex shader output structure for pixel shader usage
  545. "struct VS_OUTPUT\n"
  546. "{\n"
  547. "float4 Position : POSITION;\n"
  548. "float3 ViewDir : TEXCOORD0;\n"
  549. "float4 Color : COLOR0;\n"
  550. "#ifndef AV_NORMAL_TEXTURE\n"
  551. "float3 Normal : TEXCOORD1;\n"
  552. "#endif\n"
  553. "float2 TexCoord0 : TEXCOORD2;\n"
  554. "#ifdef AV_TWO_UV \n"
  555. "float2 TexCoord1 : TEXCOORD3;\n"
  556. "#endif \n"
  557. "#ifdef AV_NORMAL_TEXTURE\n"
  558. "float3 Light0 : TEXCOORD3;\n"
  559. "float3 Light1 : TEXCOORD4;\n"
  560. "#endif\n"
  561. "};\n"
  562. // Vertex shader output structure for fixed function pixel pipeline
  563. "struct VS_OUTPUT_FF\n"
  564. "{\n"
  565. "float4 Position : POSITION;\n"
  566. "float4 DiffuseColor : COLOR0;\n"
  567. "float4 SpecularColor : COLOR1;\n"
  568. "float2 TexCoord0 : TEXCOORD0;\n"
  569. "};\n"
  570. // Selective SuperSampling in screenspace for reflection lookups
  571. "#define GetSSSCubeMap(_refl) (texCUBElod(EnvironmentMapSampler,float4(_refl,0.0f)).rgb) \n"
  572. // Vertex shader for pixel shader usage and one light
  573. "VS_OUTPUT MaterialVShader_D1(VS_INPUT IN)\n"
  574. "{\n"
  575. "VS_OUTPUT Out = (VS_OUTPUT)0;\n"
  576. "#ifdef AV_SKINNING \n"
  577. "float4 weights = IN.BlendWeights; \n"
  578. "weights.w = 1.0f - dot( weights.xyz, float3( 1, 1, 1)); \n"
  579. "float4 localPos = float4( IN.Position, 1.0f); \n"
  580. "float3 objPos = mul( localPos, gBoneMatrix[IN.BlendIndices.x]) * weights.x; \n"
  581. "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.y]) * weights.y; \n"
  582. "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.z]) * weights.z; \n"
  583. "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.w]) * weights.w; \n"
  584. "#else \n"
  585. "float3 objPos = IN.Position; \n"
  586. "#endif // AV_SKINNING \n"
  587. // Multiply with the WorldViewProjection matrix
  588. "Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection);\n"
  589. "float3 WorldPos = mul( float4( objPos, 1.0f), World);\n"
  590. "Out.TexCoord0 = IN.TexCoord0;\n"
  591. "#ifdef AV_TWO_UV \n"
  592. "Out.TexCoord1 = IN.TexCoord1;\n"
  593. "#endif\n"
  594. "Out.Color = IN.Color;\n"
  595. "#ifndef AV_NORMAL_TEXTURE\n"
  596. "Out.ViewDir = vCameraPos - WorldPos;\n"
  597. "Out.Normal = mul(IN.Normal,WorldInverseTranspose);\n"
  598. "#endif\n"
  599. "#ifdef AV_NORMAL_TEXTURE\n"
  600. "float3x3 TBNMatrix = float3x3(IN.Tangent, IN.Bitangent, IN.Normal);\n"
  601. "float3x3 WTTS = mul(TBNMatrix, (float3x3)WorldInverseTranspose);\n"
  602. "Out.Light0 = normalize(mul(WTTS, afLightDir[0] ));\n"
  603. "Out.ViewDir = normalize(mul(WTTS, (vCameraPos - WorldPos)));\n"
  604. "#endif\n"
  605. "return Out;\n"
  606. "}\n"
  607. // Vertex shader for pixel shader usage and two lights
  608. "VS_OUTPUT MaterialVShader_D2(VS_INPUT IN)\n"
  609. "{\n"
  610. "VS_OUTPUT Out = (VS_OUTPUT)0;\n"
  611. "#ifdef AV_SKINNING \n"
  612. "float4 weights = IN.BlendWeights; \n"
  613. "weights.w = 1.0f - dot( weights.xyz, float3( 1, 1, 1)); \n"
  614. "float4 localPos = float4( IN.Position, 1.0f); \n"
  615. "float3 objPos = mul( localPos, gBoneMatrix[IN.BlendIndices.x]) * weights.x; \n"
  616. "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.y]) * weights.y; \n"
  617. "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.z]) * weights.z; \n"
  618. "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.w]) * weights.w; \n"
  619. "#else \n"
  620. "float3 objPos = IN.Position; \n"
  621. "#endif // AV_SKINNING \n"
  622. // Multiply with the WorldViewProjection matrix
  623. "Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection);\n"
  624. "float3 WorldPos = mul( float4( objPos, 1.0f), World);\n"
  625. "Out.TexCoord0 = IN.TexCoord0;\n"
  626. "#ifdef AV_TWO_UV \n"
  627. "Out.TexCoord1 = IN.TexCoord1;\n"
  628. "#endif\n"
  629. "Out.Color = IN.Color;\n"
  630. "#ifndef AV_NORMAL_TEXTURE\n"
  631. "Out.ViewDir = vCameraPos - WorldPos;\n"
  632. "Out.Normal = mul(IN.Normal,WorldInverseTranspose);\n"
  633. "#endif\n"
  634. "#ifdef AV_NORMAL_TEXTURE\n"
  635. "float3x3 TBNMatrix = float3x3(IN.Tangent, IN.Bitangent, IN.Normal);\n"
  636. "float3x3 WTTS = mul(TBNMatrix, (float3x3)WorldInverseTranspose);\n"
  637. "Out.Light0 = normalize(mul(WTTS, afLightDir[0] ));\n"
  638. "Out.Light1 = normalize(mul(WTTS, afLightDir[1] ));\n"
  639. "Out.ViewDir = normalize(mul(WTTS, (vCameraPos - WorldPos)));\n"
  640. "#endif\n"
  641. "return Out;\n"
  642. "}\n"
  643. // Vertex shader for zero to five lights using the fixed function pixel pipeline
  644. "VS_OUTPUT_FF MaterialVShader_FF(VS_INPUT IN)\n"
  645. "{\n"
  646. "VS_OUTPUT_FF Out = (VS_OUTPUT_FF)0;\n"
  647. "#ifdef AV_SKINNING \n"
  648. "float4 weights = IN.BlendWeights; \n"
  649. "weights.w = 1.0f - dot( weights.xyz, float3( 1, 1, 1)); \n"
  650. "float4 localPos = float4( IN.Position, 1.0f); \n"
  651. "float3 objPos = mul( localPos, gBoneMatrix[IN.BlendIndices.x]) * weights.x; \n"
  652. "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.y]) * weights.y; \n"
  653. "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.z]) * weights.z; \n"
  654. "objPos += mul( localPos, gBoneMatrix[IN.BlendIndices.w]) * weights.w; \n"
  655. "#else \n"
  656. "float3 objPos = IN.Position; \n"
  657. "#endif // AV_SKINNING \n"
  658. // Multiply with the WorldViewProjection matrix
  659. "Out.Position = mul( float4( objPos, 1.0f), WorldViewProjection);\n"
  660. "float3 worldPos = mul( float4( objPos, 1.0f), World);\n"
  661. "float3 worldNormal = normalize( mul( IN.Normal, (float3x3) WorldInverseTranspose)); \n"
  662. "Out.TexCoord0 = IN.TexCoord0;\n"
  663. // calculate per-vertex diffuse lighting including ambient part
  664. "float4 diffuseColor = float4( 0.0f, 0.0f, 0.0f, 1.0f); \n"
  665. "for( int a = 0; a < 2; a++) \n"
  666. " diffuseColor.rgb += saturate( dot( afLightDir[a], worldNormal)) * afLightColor[a].rgb; \n"
  667. // factor in material properties and a bit of ambient lighting
  668. "Out.DiffuseColor = diffuseColor * DIFFUSE_COLOR + float4( 0.2f, 0.2f, 0.2f, 1.0f) * AMBIENT_COLOR; ; \n"
  669. // and specular including emissive part
  670. "float4 specularColor = float4( 0.0f, 0.0f, 0.0f, 1.0f); \n"
  671. "#ifdef AV_SPECULAR_COMPONENT\n"
  672. "float3 viewDir = normalize( worldPos - vCameraPos); \n"
  673. "for( int a = 0; a < 2; a++) \n"
  674. "{ \n"
  675. " float3 reflDir = reflect( afLightDir[a], worldNormal); \n"
  676. " float specIntensity = pow( saturate( dot( reflDir, viewDir)), SPECULARITY) * SPECULAR_STRENGTH; \n"
  677. " specularColor.rgb += afLightColor[a] * specIntensity; \n"
  678. "} \n"
  679. "#endif // AV_SPECULAR_COMPONENT\n"
  680. // factor in material properties and the emissive part
  681. "Out.SpecularColor = specularColor * SPECULAR_COLOR + EMISSIVE_COLOR; \n"
  682. "return Out;\n"
  683. "}\n"
  684. // Pixel shader - one light
  685. "float4 MaterialPShaderSpecular_D1(VS_OUTPUT IN) : COLOR\n"
  686. "{\n"
  687. "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
  688. "#ifdef AV_NORMAL_TEXTURE\n"
  689. "float3 IN_Light0 = normalize(IN.Light0);\n"
  690. "float3 Normal = normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0).rgb - 1.0f);\n"
  691. "#else\n"
  692. "float3 Normal = normalize(IN.Normal);\n"
  693. "#endif \n"
  694. "float3 ViewDir = normalize(IN.ViewDir);\n"
  695. "#ifdef AV_SPECULAR_COMPONENT\n"
  696. "float3 Reflect = normalize(reflect (-ViewDir,Normal));\n"
  697. "#endif // !AV_SPECULAR_COMPONENT\n"
  698. "{\n"
  699. "#ifdef AV_NORMAL_TEXTURE\n"
  700. "float L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;\n"
  701. "#define AV_LIGHT_0 IN_Light0\n"
  702. // would need to convert the reflection vector into world space ....
  703. // simply let it ...
  704. "#else\n"
  705. "float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
  706. "#define AV_LIGHT_0 afLightDir[0]\n"
  707. "#endif\n"
  708. "#ifdef AV_DIFFUSE_TEXTURE2\n"
  709. "float fHalfLambert = 1.f;\n"
  710. "#else\n"
  711. "float fHalfLambert = L1*L1;\n"
  712. "#endif \n"
  713. "#ifdef AV_DIFFUSE_TEXTURE\n"
  714. "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * fHalfLambert * IN.Color.rgb +\n"
  715. "#else\n"
  716. "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * fHalfLambert * IN.Color.rgb +\n"
  717. "#endif // !AV_DIFFUSE_TEXTURE\n"
  718. "#ifdef AV_SPECULAR_COMPONENT\n"
  719. "#ifndef AV_SKYBOX_LOOKUP\n"
  720. "#ifdef AV_SPECULAR_TEXTURE\n"
  721. "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
  722. "#else\n"
  723. "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
  724. "#endif // !AV_SPECULAR_TEXTURE\n"
  725. "#else\n"
  726. "#ifdef AV_SPECULAR_TEXTURE\n"
  727. "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * GetSSSCubeMap(Reflect) * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
  728. "#else\n"
  729. "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * GetSSSCubeMap(Reflect) * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
  730. "#endif // !AV_SPECULAR_TEXTURE\n"
  731. "#endif // !AV_SKYBOX_LOOKUP\n"
  732. "#endif // !AV_SPECULAR_COMPONENT\n"
  733. "#ifdef AV_AMBIENT_TEXTURE\n"
  734. "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +\n"
  735. "#else\n"
  736. "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb + \n"
  737. "#endif // !AV_AMBIENT_TEXTURE\n"
  738. "#ifdef AV_EMISSIVE_TEXTURE\n"
  739. "EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
  740. "#else \n"
  741. "EMISSIVE_COLOR.rgb;\n"
  742. "#endif // !AV_EMISSIVE_TEXTURE\n"
  743. "}\n"
  744. "#ifdef AV_OPACITY\n"
  745. "OUT.a = TRANSPARENCY;\n"
  746. "#endif\n"
  747. "#ifdef AV_LIGHTMAP_TEXTURE\n"
  748. "OUT.rgb *= tex2D(LIGHTMAP_SAMPLER,AV_LIGHTMAP_TEXTURE_UV_COORD).rgb*LM_STRENGTH;\n"
  749. "#endif\n"
  750. "#ifdef AV_OPACITY_TEXTURE\n"
  751. "OUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;\n"
  752. "#endif\n"
  753. "return OUT;\n"
  754. "#undef AV_LIGHT_0\n"
  755. "}\n"
  756. // Pixel shader - two lights
  757. "float4 MaterialPShaderSpecular_D2(VS_OUTPUT IN) : COLOR\n"
  758. "{\n"
  759. "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
  760. "#ifdef AV_NORMAL_TEXTURE\n"
  761. "float3 IN_Light0 = normalize(IN.Light0);\n"
  762. "float3 IN_Light1 = normalize(IN.Light1);\n"
  763. "float3 Normal = normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0).rgb - 1.0f);\n"
  764. "#else\n"
  765. "float3 Normal = normalize(IN.Normal);\n"
  766. "#endif \n"
  767. "float3 ViewDir = normalize(IN.ViewDir);\n"
  768. "#ifdef AV_SPECULAR_COMPONENT\n"
  769. "float3 Reflect = -normalize(reflect (ViewDir,Normal));\n"
  770. "#endif // !AV_SPECULAR_COMPONENT\n"
  771. "{\n"
  772. "#ifdef AV_NORMAL_TEXTURE\n"
  773. "float L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;\n"
  774. "#define AV_LIGHT_0 IN_Light0\n"
  775. "#else\n"
  776. "float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
  777. "#define AV_LIGHT_0 afLightDir[0]\n"
  778. "#endif\n"
  779. "float fHalfLambert = L1*L1;\n"
  780. "#ifdef AV_DIFFUSE_TEXTURE\n"
  781. "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * fHalfLambert * IN.Color.rgb +\n"
  782. "#else\n"
  783. "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * fHalfLambert * IN.Color.rgb +\n"
  784. "#endif // !AV_DIFFUSE_TEXTURE\n"
  785. "#ifdef AV_SPECULAR_COMPONENT\n"
  786. "#ifndef AV_SKYBOX_LOOKUP\n"
  787. "#ifdef AV_SPECULAR_TEXTURE\n"
  788. "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
  789. "#else\n"
  790. "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
  791. "#endif // !AV_SPECULAR_TEXTURE\n"
  792. "#else\n"
  793. "#ifdef AV_SPECULAR_TEXTURE\n"
  794. "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * GetSSSCubeMap(Reflect) * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
  795. "#else\n"
  796. "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * GetSSSCubeMap(Reflect) * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_0),SPECULARITY)) + \n"
  797. "#endif // !AV_SPECULAR_TEXTURE\n"
  798. "#endif // !AV_SKYBOX_LOOKUP\n"
  799. "#endif // !AV_SPECULAR_COMPONENT\n"
  800. "#ifdef AV_AMBIENT_TEXTURE\n"
  801. "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb + \n"
  802. "#else\n"
  803. "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb + \n"
  804. "#endif // !AV_AMBIENT_TEXTURE\n"
  805. "#ifdef AV_EMISSIVE_TEXTURE\n"
  806. "EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
  807. "#else \n"
  808. "EMISSIVE_COLOR.rgb;\n"
  809. "#endif // !AV_EMISSIVE_TEXTURE\n"
  810. "}\n"
  811. "{\n"
  812. "#ifdef AV_NORMAL_TEXTURE\n"
  813. "float L1 = dot(Normal,IN_Light1) * 0.5f + 0.5f;\n"
  814. "#define AV_LIGHT_1 IN_Light1\n"
  815. "#else\n"
  816. "float L1 = dot(Normal,afLightDir[1]) * 0.5f + 0.5f;\n"
  817. "#define AV_LIGHT_1 afLightDir[1]\n"
  818. "#endif\n"
  819. "float fHalfLambert = L1*L1;\n"
  820. "#ifdef AV_DIFFUSE_TEXTURE\n"
  821. "OUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * fHalfLambert * IN.Color.rgb +\n"
  822. "#else\n"
  823. "OUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * fHalfLambert * IN.Color.rgb +\n"
  824. "#endif // !AV_DIFFUSE_TEXTURE\n"
  825. "#ifdef AV_SPECULAR_COMPONENT\n"
  826. "#ifndef AV_SKYBOX_LOOKUP\n"
  827. "#ifdef AV_SPECULAR_TEXTURE\n"
  828. "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_1),SPECULARITY)) + \n"
  829. "#else\n"
  830. "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_1),SPECULARITY)) + \n"
  831. "#endif // !AV_SPECULAR_TEXTURE\n"
  832. "#else\n"
  833. "#ifdef AV_SPECULAR_TEXTURE\n"
  834. "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * GetSSSCubeMap(Reflect) * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_1),SPECULARITY)) + \n"
  835. "#else\n"
  836. "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * GetSSSCubeMap(Reflect) * (saturate(fHalfLambert * 2.0f) * pow(dot(Reflect,AV_LIGHT_1),SPECULARITY)) + \n"
  837. "#endif // !AV_SPECULAR_TEXTURE\n"
  838. "#endif // !AV_SKYBOX_LOOKUP\n"
  839. "#endif // !AV_SPECULAR_COMPONENT\n"
  840. "#ifdef AV_AMBIENT_TEXTURE\n"
  841. "AMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb + \n"
  842. "#else\n"
  843. "AMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb + \n"
  844. "#endif // !AV_AMBIENT_TEXTURE\n"
  845. "#ifdef AV_EMISSIVE_TEXTURE\n"
  846. "EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
  847. "#else \n"
  848. "EMISSIVE_COLOR.rgb;\n"
  849. "#endif // !AV_EMISSIVE_TEXTURE\n"
  850. "}\n"
  851. "#ifdef AV_OPACITY\n"
  852. "OUT.a = TRANSPARENCY;\n"
  853. "#endif\n"
  854. "#ifdef AV_LIGHTMAP_TEXTURE\n"
  855. "OUT.rgb *= tex2D(LIGHTMAP_SAMPLER,AV_LIGHTMAP_TEXTURE_UV_COORD).rgb*LM_STRENGTH;\n"
  856. "#endif\n"
  857. "#ifdef AV_OPACITY_TEXTURE\n"
  858. "OUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;\n"
  859. "#endif\n"
  860. "return OUT;\n"
  861. "#undef AV_LIGHT_0\n"
  862. "#undef AV_LIGHT_1\n"
  863. "}\n"
  864. // Same pixel shader again, one light
  865. "float4 MaterialPShaderSpecular_PS20_D1(VS_OUTPUT IN) : COLOR\n"
  866. "{\n"
  867. "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
  868. "#ifdef AV_NORMAL_TEXTURE\n"
  869. "float3 IN_Light0 = normalize(IN.Light0);\n"
  870. "float3 Normal = normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0).rgb - 1.0f);\n"
  871. "#else\n"
  872. "float3 Normal = normalize(IN.Normal);\n"
  873. "#endif \n"
  874. "float3 ViewDir = normalize(IN.ViewDir);\n"
  875. "{\n"
  876. "#ifdef AV_NORMAL_TEXTURE\n"
  877. "float L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;\n"
  878. "float3 Reflect = reflect (Normal,IN_Light0);\n"
  879. "#else\n"
  880. "float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
  881. "float3 Reflect = reflect (Normal,afLightDir[0]);\n"
  882. "#endif\n"
  883. "#ifdef AV_DIFFUSE_TEXTURE\n"
  884. "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * L1 +\n"
  885. "#else\n"
  886. "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * L1 +\n"
  887. "#endif // !AV_DIFFUSE_TEXTURE\n"
  888. "#ifdef AV_SPECULAR_COMPONENT\n"
  889. "#ifdef AV_SPECULAR_TEXTURE\n"
  890. "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
  891. "#else\n"
  892. "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
  893. "#endif // !AV_SPECULAR_TEXTURE\n"
  894. "#endif // !AV_SPECULAR_COMPONENT\n"
  895. "#ifdef AV_AMBIENT_TEXTURE\n"
  896. "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +\n"
  897. "#else\n"
  898. "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb +\n"
  899. "#endif // !AV_AMBIENT_TEXTURE\n"
  900. "#ifdef AV_EMISSIVE_TEXTURE\n"
  901. "EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
  902. "#else \n"
  903. "EMISSIVE_COLOR.rgb;\n"
  904. "#endif // !AV_EMISSIVE_TEXTURE\n"
  905. "}\n"
  906. "#ifdef AV_OPACITY\n"
  907. "OUT.a = TRANSPARENCY;\n"
  908. "#endif\n"
  909. "#ifdef AV_OPACITY_TEXTURE\n"
  910. "OUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;\n"
  911. "#endif\n"
  912. "return OUT;\n"
  913. "}\n"
  914. // Same pixel shader again, two lights
  915. "float4 MaterialPShaderSpecular_PS20_D2(VS_OUTPUT IN) : COLOR\n"
  916. "{\n"
  917. "float4 OUT = float4(0.0f,0.0f,0.0f,1.0f);\n"
  918. "#ifdef AV_NORMAL_TEXTURE\n"
  919. "float3 IN_Light0 = normalize(IN.Light0);\n"
  920. "float3 IN_Light1 = normalize(IN.Light1);\n"
  921. "float3 Normal = normalize(2.0f * tex2D(NORMAL_SAMPLER, IN.TexCoord0) - 1.0f);\n"
  922. "#else\n"
  923. "float3 Normal = normalize(IN.Normal);\n"
  924. "#endif \n"
  925. "float3 ViewDir = normalize(IN.ViewDir);\n"
  926. "{\n"
  927. "#ifdef AV_NORMAL_TEXTURE\n"
  928. "float L1 = dot(Normal,IN_Light0) * 0.5f + 0.5f;\n"
  929. "float3 Reflect = reflect (Normal,IN_Light0);\n"
  930. "#else\n"
  931. "float L1 = dot(Normal,afLightDir[0]) * 0.5f + 0.5f;\n"
  932. "float3 Reflect = reflect (Normal,afLightDir[0]);\n"
  933. "#endif\n"
  934. "#ifdef AV_DIFFUSE_TEXTURE\n"
  935. "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * L1 +\n"
  936. "#else\n"
  937. "OUT.rgb += afLightColor[0].rgb * DIFFUSE_COLOR.rgb * L1 +\n"
  938. "#endif // !AV_DIFFUSE_TEXTURE\n"
  939. "#ifdef AV_SPECULAR_COMPONENT\n"
  940. "#ifdef AV_SPECULAR_TEXTURE\n"
  941. "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
  942. "#else\n"
  943. "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[0].rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
  944. "#endif // !AV_SPECULAR_TEXTURE\n"
  945. "#endif // !AV_SPECULAR_COMPONENT\n"
  946. "#ifdef AV_AMBIENT_TEXTURE\n"
  947. "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +\n"
  948. "#else\n"
  949. "AMBIENT_COLOR.rgb * afLightColorAmbient[0].rgb +\n"
  950. "#endif // !AV_AMBIENT_TEXTURE\n"
  951. "#ifdef AV_EMISSIVE_TEXTURE\n"
  952. "EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
  953. "#else \n"
  954. "EMISSIVE_COLOR.rgb;\n"
  955. "#endif // !AV_EMISSIVE_TEXTURE\n"
  956. "}\n"
  957. "{\n"
  958. "#ifdef AV_NORMAL_TEXTURE\n"
  959. "float L1 = dot(Normal,IN_Light1) * 0.5f + 0.5f;\n"
  960. "float3 Reflect = reflect (Normal,IN_Light1);\n"
  961. "#else\n"
  962. "float L1 = dot(Normal,afLightDir[1]) * 0.5f + 0.5f;\n"
  963. "float3 Reflect = reflect (Normal,afLightDir[1]);\n"
  964. "#endif\n"
  965. "#ifdef AV_DIFFUSE_TEXTURE\n"
  966. "OUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * tex2D(DIFFUSE_SAMPLER,IN.TexCoord0).rgb * L1 +\n"
  967. "#else\n"
  968. "OUT.rgb += afLightColor[1].rgb * DIFFUSE_COLOR.rgb * L1 +\n"
  969. "#endif // !AV_DIFFUSE_TEXTURE\n"
  970. "#ifdef AV_SPECULAR_COMPONENT\n"
  971. "#ifdef AV_SPECULAR_TEXTURE\n"
  972. "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * tex2D(SPECULAR_SAMPLER,IN.TexCoord0).rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
  973. "#else\n"
  974. "SPECULAR_COLOR.rgb * SPECULAR_STRENGTH * afLightColor[1].rgb * (saturate(L1 * 4.0f) * pow(dot(Reflect,ViewDir),SPECULARITY)) + \n"
  975. "#endif // !AV_SPECULAR_TEXTURE\n"
  976. "#endif // !AV_SPECULAR_COMPONENT\n"
  977. "#ifdef AV_AMBIENT_TEXTURE\n"
  978. "AMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb * tex2D(AMBIENT_SAMPLER,IN.TexCoord0).rgb +\n"
  979. "#else\n"
  980. "AMBIENT_COLOR.rgb * afLightColorAmbient[1].rgb + \n"
  981. "#endif // !AV_AMBIENT_TEXTURE\n"
  982. "#ifdef AV_EMISSIVE_TEXTURE\n"
  983. "EMISSIVE_COLOR.rgb * tex2D(EMISSIVE_SAMPLER,IN.TexCoord0).rgb;\n"
  984. "#else \n"
  985. "EMISSIVE_COLOR.rgb;\n"
  986. "#endif // !AV_EMISSIVE_TEXTURE\n"
  987. "}\n"
  988. "#ifdef AV_OPACITY\n"
  989. "OUT.a = TRANSPARENCY;\n"
  990. "#endif\n"
  991. "#ifdef AV_OPACITY_TEXTURE\n"
  992. "OUT.a *= tex2D(OPACITY_SAMPLER,IN.TexCoord0). AV_OPACITY_TEXTURE_REGISTER_MASK;\n"
  993. "#endif\n"
  994. "return OUT;\n"
  995. "}\n"
  996. // Technique for the material effect
  997. "technique MaterialFXSpecular_D1\n"
  998. "{\n"
  999. "pass p0\n"
  1000. "{\n"
  1001. "#ifdef AV_OPACITY_TEXTURE\n"
  1002. "AlphaBlendEnable=TRUE;"
  1003. "SrcBlend = srcalpha;\n"
  1004. "DestBlend = invsrcalpha;\n"
  1005. "#else\n"
  1006. "#ifdef AV_OPACITY\n"
  1007. "AlphaBlendEnable=TRUE;"
  1008. "SrcBlend = srcalpha;\n"
  1009. "DestBlend = invsrcalpha;\n"
  1010. "#endif \n"
  1011. "#endif\n"
  1012. "PixelShader = compile ps_3_0 MaterialPShaderSpecular_D1();\n"
  1013. "VertexShader = compile vs_3_0 MaterialVShader_D1();\n"
  1014. "}\n"
  1015. "};\n"
  1016. "technique MaterialFXSpecular_D2\n"
  1017. "{\n"
  1018. "pass p0\n"
  1019. "{\n"
  1020. "#ifdef AV_OPACITY_TEXTURE\n"
  1021. "AlphaBlendEnable=TRUE;"
  1022. "SrcBlend = srcalpha;\n"
  1023. "DestBlend = invsrcalpha;\n"
  1024. "#else\n"
  1025. "#ifdef AV_OPACITY\n"
  1026. "AlphaBlendEnable=TRUE;"
  1027. "SrcBlend = srcalpha;\n"
  1028. "DestBlend = invsrcalpha;\n"
  1029. "#endif \n"
  1030. "#endif\n"
  1031. "PixelShader = compile ps_3_0 MaterialPShaderSpecular_D2();\n"
  1032. "VertexShader = compile vs_3_0 MaterialVShader_D2();\n"
  1033. "}\n"
  1034. "};\n"
  1035. // Technique for the material effect (ps_2_0)
  1036. "technique MaterialFXSpecular_PS20_D1\n"
  1037. "{\n"
  1038. "pass p0\n"
  1039. "{\n"
  1040. "#ifdef AV_OPACITY_TEXTURE\n"
  1041. "AlphaBlendEnable=TRUE;"
  1042. "SrcBlend = srcalpha;\n"
  1043. "DestBlend = invsrcalpha;\n"
  1044. "#else\n"
  1045. "#ifdef AV_OPACITY\n"
  1046. "AlphaBlendEnable=TRUE;"
  1047. "SrcBlend = srcalpha;\n"
  1048. "DestBlend = invsrcalpha;\n"
  1049. "#endif \n"
  1050. "#endif\n"
  1051. "PixelShader = compile ps_2_0 MaterialPShaderSpecular_PS20_D1();\n"
  1052. "VertexShader = compile vs_2_0 MaterialVShader_D1();\n"
  1053. "}\n"
  1054. "};\n"
  1055. "technique MaterialFXSpecular_PS20_D2\n"
  1056. "{\n"
  1057. "pass p0\n"
  1058. "{\n"
  1059. "//CullMode=none;\n"
  1060. "#ifdef AV_OPACITY_TEXTURE\n"
  1061. "AlphaBlendEnable=TRUE;"
  1062. "SrcBlend = srcalpha;\n"
  1063. "DestBlend = invsrcalpha;\n"
  1064. "#else\n"
  1065. "#ifdef AV_OPACITY\n"
  1066. "AlphaBlendEnable=TRUE;"
  1067. "SrcBlend = srcalpha;\n"
  1068. "DestBlend = invsrcalpha;\n"
  1069. "#endif \n"
  1070. "#endif\n"
  1071. "PixelShader = compile ps_2_0 MaterialPShaderSpecular_PS20_D2();\n"
  1072. "VertexShader = compile vs_2_0 MaterialVShader_D2();\n"
  1073. "}\n"
  1074. "};\n"
  1075. // Technique for the material effect using fixed function pixel pipeline
  1076. "technique MaterialFX_FF\n"
  1077. "{\n"
  1078. "pass p0\n"
  1079. "{\n"
  1080. "//CullMode=none;\n"
  1081. "SpecularEnable = true; \n"
  1082. "VertexShader = compile vs_2_0 MaterialVShader_FF();\n"
  1083. "ColorOp[0] = Modulate;\n"
  1084. "ColorArg0[0] = Texture;\n"
  1085. "ColorArg1[0] = Diffuse;\n"
  1086. "AlphaOp[0] = Modulate;\n"
  1087. "AlphaArg0[0] = Texture;\n"
  1088. "AlphaArg1[0] = Diffuse;\n"
  1089. "}\n"
  1090. "};\n"
  1091. );
  1092. std::string g_szPassThroughShader = std::string(
  1093. "texture TEXTURE_2D;\n"
  1094. "sampler TEXTURE_SAMPLER = sampler_state\n"
  1095. "{\n"
  1096. "Texture = (TEXTURE_2D);\n"
  1097. "MinFilter = POINT;\n"
  1098. "MagFilter = POINT;\n"
  1099. "};\n"
  1100. // Vertex Shader output for pixel shader usage
  1101. "struct VS_OUTPUT\n"
  1102. "{\n"
  1103. "float4 Position : POSITION;\n"
  1104. "float2 TexCoord0 : TEXCOORD0;\n"
  1105. "};\n"
  1106. // vertex shader for pixel shader usage
  1107. "VS_OUTPUT DefaultVShader(float4 INPosition : POSITION, float2 INTexCoord0 : TEXCOORD0 )\n"
  1108. "{\n"
  1109. "VS_OUTPUT Out;\n"
  1110. "Out.Position = INPosition;\n"
  1111. "Out.TexCoord0 = INTexCoord0;\n"
  1112. "return Out;\n"
  1113. "}\n"
  1114. // simply lookup a texture
  1115. "float4 PassThrough_PS(float2 IN : TEXCOORD0) : COLOR\n"
  1116. "{\n"
  1117. " return tex2D(TEXTURE_SAMPLER,IN);\n"
  1118. "}\n"
  1119. // visualize the alpha channel (in black) -> use a
  1120. "float4 PassThroughAlphaA_PS(float2 IN : TEXCOORD0) : COLOR\n"
  1121. "{\n"
  1122. " return float4(0.0f,0.0f,0.0f,tex2D(TEXTURE_SAMPLER,IN).a);\n"
  1123. "}\n"
  1124. // visualize the alpha channel (in black) -> use r
  1125. "float4 PassThroughAlphaR_PS(float2 IN : TEXCOORD0) : COLOR\n"
  1126. "{\n"
  1127. " return float4(0.0f,0.0f,0.0f,tex2D(TEXTURE_SAMPLER,IN).r);\n"
  1128. "}\n"
  1129. // Simple pass-through technique
  1130. "technique PassThrough\n"
  1131. "{\n"
  1132. "pass p0\n"
  1133. "{\n"
  1134. "FillMode=Solid;\n"
  1135. "ZEnable = FALSE;\n"
  1136. "CullMode = none;\n"
  1137. "AlphaBlendEnable = TRUE;\n"
  1138. "SrcBlend =srcalpha;\n"
  1139. "DestBlend =invsrcalpha;\n"
  1140. "PixelShader = compile ps_2_0 PassThrough_PS();\n"
  1141. "VertexShader = compile vs_2_0 DefaultVShader();\n"
  1142. "}\n"
  1143. "};\n"
  1144. // Pass-through technique which visualizes the texture's alpha channel
  1145. "technique PassThroughAlphaFromA\n"
  1146. "{\n"
  1147. "pass p0\n"
  1148. "{\n"
  1149. "FillMode=Solid;\n"
  1150. "ZEnable = FALSE;\n"
  1151. "CullMode = none;\n"
  1152. "AlphaBlendEnable = TRUE;\n"
  1153. "SrcBlend =srcalpha;\n"
  1154. "DestBlend =invsrcalpha;\n"
  1155. "PixelShader = compile ps_2_0 PassThroughAlphaA_PS();\n"
  1156. "VertexShader = compile vs_2_0 DefaultVShader();\n"
  1157. "}\n"
  1158. "};\n"
  1159. // Pass-through technique which visualizes the texture's red channel
  1160. "technique PassThroughAlphaFromR\n"
  1161. "{\n"
  1162. "pass p0\n"
  1163. "{\n"
  1164. "FillMode=Solid;\n"
  1165. "ZEnable = FALSE;\n"
  1166. "CullMode = none;\n"
  1167. "AlphaBlendEnable = TRUE;\n"
  1168. "SrcBlend =srcalpha;\n"
  1169. "DestBlend =invsrcalpha;\n"
  1170. "PixelShader = compile ps_2_0 PassThroughAlphaR_PS();\n"
  1171. "VertexShader = compile vs_2_0 DefaultVShader();\n"
  1172. "}\n"
  1173. "};\n"
  1174. // technique for fixed function pixel pipeline
  1175. "technique PassThrough_FF\n"
  1176. "{\n"
  1177. "pass p0\n"
  1178. "{\n"
  1179. "ZEnable = FALSE;\n"
  1180. "CullMode = none;\n"
  1181. "AlphaBlendEnable = TRUE;\n"
  1182. "SrcBlend =srcalpha;\n"
  1183. "DestBlend =invsrcalpha;\n"
  1184. "VertexShader = compile vs_2_0 DefaultVShader();\n"
  1185. "ColorOp[0] = SelectArg1;\n"
  1186. "ColorArg0[0] = Texture;\n"
  1187. "AlphaOp[0] = SelectArg1;\n"
  1188. "AlphaArg0[0] = Texture;\n"
  1189. "}\n"
  1190. "};\n"
  1191. );
  1192. std::string g_szCheckerBackgroundShader = std::string(
  1193. // the two colors used to draw the checker pattern
  1194. "float3 COLOR_ONE = float3(0.4f,0.4f,0.4f);\n"
  1195. "float3 COLOR_TWO = float3(0.6f,0.6f,0.6f);\n"
  1196. // size of a square in both x and y direction
  1197. "float SQUARE_SIZE = 10.0f;\n"
  1198. // vertex shader output structure
  1199. "struct VS_OUTPUT\n"
  1200. "{\n"
  1201. "float4 Position : POSITION;\n"
  1202. "};\n"
  1203. // vertex shader
  1204. "VS_OUTPUT DefaultVShader(float4 INPosition : POSITION, float2 INTexCoord0 : TEXCOORD0 )\n"
  1205. "{\n"
  1206. "VS_OUTPUT Out;\n"
  1207. "Out.Position = INPosition;\n"
  1208. "return Out;\n"
  1209. "}\n"
  1210. // pixel shader
  1211. "float4 MakePattern_PS(float2 IN : VPOS) : COLOR\n"
  1212. "{\n"
  1213. "float2 fDiv = IN / SQUARE_SIZE;\n"
  1214. "float3 fColor = COLOR_ONE;\n"
  1215. "if (0 == round(fmod(round(fDiv.x),2)))\n"
  1216. "{\n"
  1217. " if (0 == round(fmod(round(fDiv.y),2))) fColor = COLOR_TWO;\n"
  1218. "}\n"
  1219. "else if (0 != round(fmod(round(fDiv.y),2)))fColor = COLOR_TWO;\n"
  1220. "return float4(fColor,1.0f);"
  1221. "}\n"
  1222. // technique to generate a pattern
  1223. "technique MakePattern\n"
  1224. "{\n"
  1225. "pass p0\n"
  1226. "{\n"
  1227. "FillMode=Solid;\n"
  1228. "ZEnable = FALSE;\n"
  1229. "CullMode = none;\n"
  1230. "PixelShader = compile ps_3_0 MakePattern_PS();\n"
  1231. "VertexShader = compile vs_3_0 DefaultVShader();\n"
  1232. "}\n"
  1233. "};\n"
  1234. );
  1235. };