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

游戏引擎

开发平台:

Visual C++

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