light_d.shader
上传用户:qccn516
上传日期:2013-05-02
资源大小:3382k
文件大小:5k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. /* light shader (diffuse)
  2.  * defines: VERTEX, NV3X, TEYLOR
  3.  *
  4.  * written by Alexander Zaprjagaev
  5.  * frustum@frustum.org
  6.  * http://frustum.org
  7.  */
  8. #ifdef VERTEX
  9. /*****************************************************************************/
  10. /*                                                                           */
  11. /* simple vertex lighting                                                    */
  12. /*                                                                           */
  13. /*****************************************************************************/
  14. <vertex_local0> ilight
  15. <vertex_local1> light_color
  16. <vertex>
  17. !!ARBvp1.0
  18. ATTRIB xyz = vertex.attrib[0];
  19. ATTRIB normal = vertex.attrib[1];
  20. ATTRIB st = vertex.attrib[4];
  21. PARAM mvp[4] = { state.matrix.mvp };
  22. PARAM light = program.local[0];
  23. PARAM light_color = program.local[1];
  24. DP4 result.position.x, mvp[0], xyz;
  25. DP4 result.position.y, mvp[1], xyz;
  26. DP4 result.position.z, mvp[2], xyz;
  27. DP4 result.position.w, mvp[3], xyz;
  28. MOV result.texcoord[0], st;
  29. TEMP dir, color;
  30. SUB dir, light, xyz;
  31. DP3 dir.w, dir, dir;
  32. MAD color.w, dir.w, -light.w, 1.0;
  33. MAX color.w, color.w, 0.0;
  34. RSQ dir.w, dir.w;
  35. MUL dir, dir, dir.w;
  36. DP3 color.xyz, dir, normal;
  37. MUL color, color, color.w;
  38. MUL result.color, color, light_color;
  39. END
  40. <fragment>
  41. !!ARBtec1.0
  42. modulate texture primary
  43. END
  44. #else
  45. /*****************************************************************************/
  46. /*                                                                           */
  47. /* perpixel lighting                                                         */
  48. /*                                                                           */
  49. /*****************************************************************************/
  50. <vertex_local0> ilight
  51. <vertex_local1> light_color
  52. /*
  53.  */
  54. <vertex>
  55. !!ARBvp1.0
  56. ATTRIB xyz = vertex.attrib[0];
  57. ATTRIB normal = vertex.attrib[1];
  58. ATTRIB tangent = vertex.attrib[2];
  59. ATTRIB binormal = vertex.attrib[3];
  60. ATTRIB st = vertex.attrib[4];
  61. PARAM mvp[4] = { state.matrix.mvp };
  62. PARAM light = program.local[0];
  63. PARAM light_color = program.local[1];
  64. DP4 result.position.x, mvp[0], xyz;
  65. DP4 result.position.y, mvp[1], xyz;
  66. DP4 result.position.z, mvp[2], xyz;
  67. DP4 result.position.w, mvp[3], xyz;
  68. MOV result.texcoord[0], st;
  69. TEMP dir;
  70. SUB dir, light, xyz;
  71. DP3 result.texcoord[1].x, tangent, dir;
  72. DP3 result.texcoord[1].y, binormal, dir;
  73. DP3 result.texcoord[1].z, normal, dir;
  74. MOV result.texcoord[1].w, light.w;
  75. MOV result.color, light_color;
  76. END
  77. /*
  78.  */
  79. <fragment>
  80. #ifdef NV3X
  81. /*****************************************************************************/
  82. /*                                                                           */
  83. /* NV3X fragment program code                                                */
  84. /*                                                                           */
  85. /*****************************************************************************/
  86. !!FP1.0
  87. DP3H H0.w, f[TEX1], f[TEX1]; // H0.w - |light - xyz|
  88. MADH_SAT H5.w, H0.w, -f[TEX1].w, 1.0; // H5.w - 1.0 - |light - xyz| / (radius * radius)
  89. TEX H0, f[TEX0], TEX1, 2D; // H0 - normal
  90. MADX H0, H0, 2.0, -1.0; // expand normal
  91. TEX H1, f[TEX1], TEX2, CUBE; // H1 - light direction
  92. MADX H1, H1, 2.0, -1.0;
  93. #ifdef TEYLOR
  94. DP3X H6.x, H0, H0;
  95. DP3X H6.y, H1, H1;
  96. MADX H6, H6, -0.5, 0.5;
  97. MADX H0, H0, H6.x, H0;
  98. MADX H1, H1, H6.y, H1;
  99. #endif /* TEYLOR */
  100. DP3X H2.w, H0, H1;
  101. TEX H3, f[TEX0], TEX0, 2D; // H3 - diffuse
  102. MULX H4, H2.w, H3; // H4 - diffuse * base
  103. MULX H4, H4, H5.w; // diffuse * base * attenuation
  104. MULX o[COLH], H4, f[COL0]; // diffuse * base * attenuation * color
  105. END
  106. #else
  107. /*****************************************************************************/
  108. /*                                                                           */
  109. /* ARB fragment program code                                                 */
  110. /*                                                                           */
  111. /*****************************************************************************/
  112. !!ARBfp1.0
  113. TEMP dist, light_dir, normal, base, temp, color;
  114. DP3 dist.w, fragment.texcoord[1], fragment.texcoord[1];
  115. MAD_SAT dist.x, dist.w, -fragment.texcoord[1].w, 1.0; // attenuation
  116. TEX normal, fragment.texcoord[0], texture[1], 2D;
  117. MAD normal, normal, 2.0, -1.0; // expand normal
  118. TEX light_dir, fragment.texcoord[1], texture[2], CUBE; // light direction
  119. MAD light_dir, light_dir, 2.0, -1.0;
  120. #ifdef TEYLOR
  121. DP3 temp.x, normal, normal;
  122. DP3 temp.y, light_dir, light_dir;
  123. MAD temp, temp, -0.5, 0.5;
  124. MAD normal, normal, temp.x, normal;
  125. MAD light_dir, light_dir, temp.y, light_dir;
  126. #endif /* TEYLOR */
  127. DP3 color.w, normal, light_dir;
  128. TEX base, fragment.texcoord[0], texture[0], 2D;
  129. MUL color, color.w, base;
  130. MUL color, color, dist.x;
  131. MUL result.color, fragment.color, color;
  132. END
  133. #endif /* NV3X */
  134. #endif /* VERTEX */