查看: 1271|回复: 1

osgvertexprogram中的问题

[复制链接]

该用户从未签到

发表于 2010-6-15 16:39:11 | 显示全部楼层 |阅读模式
osgvertexprogram中有这样一段代码。。。

  1. const char vpstr[] =
  2. "!!ARBvp1.0 # Refraction \n"
  3. " \n"
  4. "ATTRIB iPos = vertex.position; \n"
  5. "#ATTRIB iCol = vertex.color.primary; \n"
  6. "ATTRIB iNormal = vertex.normal; \n"
  7. "PARAM esEyePos = { 0, 0, 0, 1 }; \n"
  8. "PARAM const0123 = { 0, 1, 2, 3 }; \n"
  9. "PARAM fresnel = program.local[0]; \n"
  10. "PARAM refract = program.local[1]; \n"
  11. "PARAM itMV[4] = { state.matrix.modelview.invtrans }; \n"
  12. "PARAM MVP[4] = { state.matrix.mvp }; \n"
  13. "PARAM MV[4] = { state.matrix.modelview }; \n"
  14. "PARAM texmat[4] = { state.matrix.texture[0] }; \n"
  15. "TEMP esPos; # position in eye-space \n"
  16. "TEMP esNormal; # normal in eye-space \n"
  17. "TEMP tmp, IdotN, K; \n"
  18. "TEMP esE; # eye vector \n"
  19. "TEMP esI; # incident vector (=-E) \n"
  20. "TEMP esR; # first refract- then reflect-vector \n"
  21. "OUTPUT oPos = result.position; \n"
  22. "OUTPUT oColor = result.color; \n"
  23. "OUTPUT oRefractMap = result.texcoord[0]; \n"
  24. "OUTPUT oReflectMap = result.texcoord[1]; \n"
  25. " \n"
  26. "# transform vertex to clip space \n"
  27. "DP4 oPos.x, MVP[0], iPos; \n"
  28. "DP4 oPos.y, MVP[1], iPos; \n"
  29. "DP4 oPos.z, MVP[2], iPos; \n"
  30. "DP4 oPos.w, MVP[3], iPos; \n"
  31. " \n"
  32. "# Transform the normal to eye space. \n"
  33. "DP3 esNormal.x, itMV[0], iNormal; \n"
  34. "DP3 esNormal.y, itMV[1], iNormal; \n"
  35. "DP3 esNormal.z, itMV[2], iNormal; \n"
  36. " \n"
  37. "# normalize normal \n"
  38. "DP3 esNormal.w, esNormal, esNormal; \n"
  39. "RSQ esNormal.w, esNormal.w; \n"
  40. "MUL esNormal, esNormal, esNormal.w; \n"
  41. " \n"
  42. "# transform vertex position to eye space \n"
  43. "DP4 esPos.x, MV[0], iPos; \n"
  44. "DP4 esPos.y, MV[1], iPos; \n"
  45. "DP4 esPos.z, MV[2], iPos; \n"
  46. "DP4 esPos.w, MV[3], iPos; \n"
  47. " \n"
  48. "# vertex to eye vector \n"
  49. "ADD esE, -esPos, esEyePos; \n"
  50. "#MOV esE, -esPos; \n"
  51. " \n"
  52. "# normalize eye vector \n"
  53. "DP3 esE.w, esE, esE; \n"
  54. "RSQ esE.w, esE.w; \n"
  55. "MUL esE, esE, esE.w; \n"
  56. " \n"
  57. "# calculate some handy values \n"
  58. "MOV esI, -esE; \n"
  59. "DP3 IdotN, esNormal, esI; \n"
  60. " \n"
  61. "# calculate refraction vector, Renderman style \n"
  62. " \n"
  63. "# k = 1-index*index*(1-(I dot N)^2) \n"
  64. "MAD tmp, -IdotN, IdotN, const0123.y; \n"
  65. "MUL tmp, tmp, refract.y; \n"
  66. "ADD K.x, const0123.y, -tmp; \n"
  67. " \n"
  68. "# k<0, R = [0,0,0] \n"
  69. "# k>=0, R = index*I-(index*(I dot N) + sqrt(k))*N \n"
  70. "RSQ K.y, K.x; \n"
  71. "RCP K.y, K.y; # K.y = sqrt(k) \n"
  72. "MAD tmp.x, refract.x, IdotN, K.y; \n"
  73. "MUL tmp, esNormal, tmp.x; \n"
  74. "MAD esR, refract.x, esI, tmp; \n"
  75. " \n"
  76. "# transform refracted ray by cubemap transform \n"
  77. "DP3 oRefractMap.x, texmat[0], esR; \n"
  78. "DP3 oRefractMap.y, texmat[1], esR; \n"
  79. "DP3 oRefractMap.z, texmat[2], esR; \n"
  80. " \n"
  81. "# calculate reflection vector \n"
  82. "# R = 2*N*(N dot E)-E \n"
  83. "MUL tmp, esNormal, const0123.z; \n"
  84. "DP3 esR.w, esNormal, esE; \n"
  85. "MAD esR, esR.w, tmp, -esE; \n"
  86. " \n"
  87. "# transform reflected ray by cubemap transform \n"
  88. "DP3 oReflectMap.x, texmat[0], esR; \n"
  89. "DP3 oReflectMap.y, texmat[1], esR; \n"
  90. "DP3 oReflectMap.z, texmat[2], esR; \n"
  91. " \n"
  92. "# Fresnel approximation = fresnel*(1-(N dot I))^2 \n"
  93. "ADD tmp.x, const0123.y, -IdotN; \n"
  94. "MUL tmp.x, tmp.x, tmp.x; \n"
  95. "MUL oColor, tmp.x, fresnel; \n"
  96. " \n"
  97. "END \n";

复制代码


这个看起来好像是汇编代码吧。。。它是什么意思啊。。
能不能不用汇编实现。。直接用openscenegraph中的函数实现。。。
初学osg。。呵呵。。还有能不能稍微介绍下这个例子。。感觉挺有趣的。。。

该用户从未签到

发表于 2010-6-17 09:56:04 | 显示全部楼层
这是早期的着色语言代码,说白了就是汇编;相比之下现在的GLSL要简单许多了,您不妨直接学习后者。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表