|
osgvertexprogram中有这样一段代码。。。
- const char vpstr[] =
- "!!ARBvp1.0 # Refraction \n"
- " \n"
- "ATTRIB iPos = vertex.position; \n"
- "#ATTRIB iCol = vertex.color.primary; \n"
- "ATTRIB iNormal = vertex.normal; \n"
- "PARAM esEyePos = { 0, 0, 0, 1 }; \n"
- "PARAM const0123 = { 0, 1, 2, 3 }; \n"
- "PARAM fresnel = program.local[0]; \n"
- "PARAM refract = program.local[1]; \n"
- "PARAM itMV[4] = { state.matrix.modelview.invtrans }; \n"
- "PARAM MVP[4] = { state.matrix.mvp }; \n"
- "PARAM MV[4] = { state.matrix.modelview }; \n"
- "PARAM texmat[4] = { state.matrix.texture[0] }; \n"
- "TEMP esPos; # position in eye-space \n"
- "TEMP esNormal; # normal in eye-space \n"
- "TEMP tmp, IdotN, K; \n"
- "TEMP esE; # eye vector \n"
- "TEMP esI; # incident vector (=-E) \n"
- "TEMP esR; # first refract- then reflect-vector \n"
- "OUTPUT oPos = result.position; \n"
- "OUTPUT oColor = result.color; \n"
- "OUTPUT oRefractMap = result.texcoord[0]; \n"
- "OUTPUT oReflectMap = result.texcoord[1]; \n"
- " \n"
- "# transform vertex to clip space \n"
- "DP4 oPos.x, MVP[0], iPos; \n"
- "DP4 oPos.y, MVP[1], iPos; \n"
- "DP4 oPos.z, MVP[2], iPos; \n"
- "DP4 oPos.w, MVP[3], iPos; \n"
- " \n"
- "# Transform the normal to eye space. \n"
- "DP3 esNormal.x, itMV[0], iNormal; \n"
- "DP3 esNormal.y, itMV[1], iNormal; \n"
- "DP3 esNormal.z, itMV[2], iNormal; \n"
- " \n"
- "# normalize normal \n"
- "DP3 esNormal.w, esNormal, esNormal; \n"
- "RSQ esNormal.w, esNormal.w; \n"
- "MUL esNormal, esNormal, esNormal.w; \n"
- " \n"
- "# transform vertex position to eye space \n"
- "DP4 esPos.x, MV[0], iPos; \n"
- "DP4 esPos.y, MV[1], iPos; \n"
- "DP4 esPos.z, MV[2], iPos; \n"
- "DP4 esPos.w, MV[3], iPos; \n"
- " \n"
- "# vertex to eye vector \n"
- "ADD esE, -esPos, esEyePos; \n"
- "#MOV esE, -esPos; \n"
- " \n"
- "# normalize eye vector \n"
- "DP3 esE.w, esE, esE; \n"
- "RSQ esE.w, esE.w; \n"
- "MUL esE, esE, esE.w; \n"
- " \n"
- "# calculate some handy values \n"
- "MOV esI, -esE; \n"
- "DP3 IdotN, esNormal, esI; \n"
- " \n"
- "# calculate refraction vector, Renderman style \n"
- " \n"
- "# k = 1-index*index*(1-(I dot N)^2) \n"
- "MAD tmp, -IdotN, IdotN, const0123.y; \n"
- "MUL tmp, tmp, refract.y; \n"
- "ADD K.x, const0123.y, -tmp; \n"
- " \n"
- "# k<0, R = [0,0,0] \n"
- "# k>=0, R = index*I-(index*(I dot N) + sqrt(k))*N \n"
- "RSQ K.y, K.x; \n"
- "RCP K.y, K.y; # K.y = sqrt(k) \n"
- "MAD tmp.x, refract.x, IdotN, K.y; \n"
- "MUL tmp, esNormal, tmp.x; \n"
- "MAD esR, refract.x, esI, tmp; \n"
- " \n"
- "# transform refracted ray by cubemap transform \n"
- "DP3 oRefractMap.x, texmat[0], esR; \n"
- "DP3 oRefractMap.y, texmat[1], esR; \n"
- "DP3 oRefractMap.z, texmat[2], esR; \n"
- " \n"
- "# calculate reflection vector \n"
- "# R = 2*N*(N dot E)-E \n"
- "MUL tmp, esNormal, const0123.z; \n"
- "DP3 esR.w, esNormal, esE; \n"
- "MAD esR, esR.w, tmp, -esE; \n"
- " \n"
- "# transform reflected ray by cubemap transform \n"
- "DP3 oReflectMap.x, texmat[0], esR; \n"
- "DP3 oReflectMap.y, texmat[1], esR; \n"
- "DP3 oReflectMap.z, texmat[2], esR; \n"
- " \n"
- "# Fresnel approximation = fresnel*(1-(N dot I))^2 \n"
- "ADD tmp.x, const0123.y, -IdotN; \n"
- "MUL tmp.x, tmp.x, tmp.x; \n"
- "MUL oColor, tmp.x, fresnel; \n"
- " \n"
- "END \n";
复制代码
这个看起来好像是汇编代码吧。。。它是什么意思啊。。
能不能不用汇编实现。。直接用openscenegraph中的函数实现。。。
初学osg。。呵呵。。还有能不能稍微介绍下这个例子。。感觉挺有趣的。。。 |
|