Guest User

Untitled

a guest
Jan 18th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. // ---------------------- Vertex Shader for line primitives -------------------------
  2.  
  3. // --- Input Constants ---
  4. // vc0, vc1, vc2, vc3 - 4x4 model matrix
  5. // vc4, vc5, vc6, vc7 - 4x4 view matrix
  6. // vc8.x - Scalar for LineThickness
  7.  
  8. // --- Input Attributes ---
  9. // va0 - 3d vector of vertex position
  10. // va1 - 3d vector of line direction
  11. // va2.x - Dash size
  12.  
  13. // --- Usage ---
  14. // Each line is represented by 4 vertices - two at the start point, and two at the end point.
  15. // This shader will move these vertices apart, so as to form a rectangle,
  16. // so index buffers should be populated as if these 4 vertices form a quad.
  17.  
  18. // ----------------------------------------------------------------------------------
  19.  
  20. // Transform vertex by model matrix
  21. m44 vt5 va0 vc0
  22.  
  23. // Copy model matrix to temporary registers, where we are allowed to manipulate it
  24. mov vt0 vc0
  25. mov vt1 vc1
  26. mov vt2 vc2
  27. mov vt3 vc3
  28.  
  29. // Remove translation - we don't want to translate a vector that holds direction (not position)
  30. sub vt0.w vt0.w vt0.w
  31. sub vt1.w vt1.w vt1.w
  32. sub vt2.w vt2.w vt2.w
  33.  
  34. // Transform line direction by the model matrix - save in vt4
  35. m44 vt4 va1 vt0
  36.  
  37. // Line direction is now in 2d screen space, take its right orthagonal and put it in vt2.xy
  38. mov vt2 vt4 // Copy to prevent shader validation error
  39. mov vt2.x vt4.y // Transpose X & Y
  40. mov vt2.y vt4.x // Transpose X & Y
  41. neg vt2.y vt2.y // y = -y
  42.  
  43. // Normalize the direction down to 1 pixel, then multiply it by LineThickness
  44. mul vt0.xy vt2.xy vt2.xy // Square offset
  45. add vt0.z vt0.x vt0.y // Sum of squares
  46. sqt vt0.z vt0.z // Square root - save in vt0.z
  47. //div vt2.xy vt2.xy vt0.z // Normalize offset
  48. //mul vt2.xy vt2.xy vc8.x // Multiply by LineThickness
  49.  
  50. // Shift the screen space vertex by the 2d direction
  51. add vt5.xy vt5.xy vt2.xy // Add offset to transformed vertex position
  52.  
  53. // Set up dash size
  54. div vt0.z vt0.z va2.x // Change dash size to length relative
  55. mov v0 vt0.z // Copy the vertex distance on line to the fragment shader
  56. //mov v0.x va2.x // Copy the vertex distance on line to the fragment shader
  57.  
  58. // Transform by view matrix
  59. m44 vt5 vt5 vc4 // Transform by view
  60. mov op vt5 // Return vertex position
Add Comment
Please, Sign In to add comment