opengl.vsh 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. !!ARBvp1.0
  2. # part of the Irrlicht Engine Shader example.
  3. # Please note that these example shaders don't do anything really useful.
  4. # They only demonstrate that shaders can be used in Irrlicht.
  5. #input
  6. ATTRIB InPos = vertex.position;
  7. ATTRIB InColor = vertex.color;
  8. ATTRIB InNormal = vertex.normal;
  9. ATTRIB InTexCoord = vertex.texcoord;
  10. #output
  11. OUTPUT OutPos = result.position;
  12. OUTPUT OutColor = result.color;
  13. OUTPUT OutTexCoord = result.texcoord;
  14. PARAM MVP[4] = { state.matrix.mvp }; # modelViewProjection matrix.
  15. TEMP Temp;
  16. TEMP TempColor;
  17. TEMP TempNormal;
  18. TEMP TempPos;
  19. #transform position to clip space
  20. DP4 Temp.x, MVP[0], InPos;
  21. DP4 Temp.y, MVP[1], InPos;
  22. DP4 Temp.z, MVP[2], InPos;
  23. DP4 Temp.w, MVP[3], InPos;
  24. #transform normal
  25. DP3 TempNormal.x, InNormal.x, program.local[0];
  26. DP3 TempNormal.y, InNormal.y, program.local[1];
  27. DP3 TempNormal.z, InNormal.z, program.local[2];
  28. #renormalize normal
  29. DP3 TempNormal.w, TempNormal, TempNormal;
  30. RSQ TempNormal.w, TempNormal.w;
  31. MUL TempNormal, TempNormal, TempNormal.w;
  32. # calculate light vector
  33. DP4 TempPos.x, InPos, program.local[10]; # vertex into world position
  34. DP4 TempPos.y, InPos, program.local[11];
  35. DP4 TempPos.z, InPos, program.local[12];
  36. DP4 TempPos.w, InPos, program.local[13];
  37. ADD TempPos, program.local[8], -TempPos; # vtxpos - lightpos
  38. # normalize light vector
  39. DP3 TempPos.w, TempPos, TempPos;
  40. RSQ TempPos.w, TempPos.w;
  41. MUL TempPos, TempPos, TempPos.w;
  42. # calculate light color
  43. DP3 TempColor, TempNormal, TempPos; # dp3 with negative light vector
  44. LIT OutColor, TempColor; # clamp to zero if r3 < 0, r5 has diffuce component in r5.y
  45. MUL OutColor, TempColor.y, program.local[9]; # ouput diffuse color
  46. MOV OutColor.w, 1.0; # we want alpha to be always 1
  47. MOV OutTexCoord, InTexCoord; # store texture coordinate
  48. MOV OutPos, Temp;
  49. END