Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ---------------------- Vertex Shader for line primitives -------------------------
- // --- Input Constants ---
- // vc0, vc1, vc2, vc3 - 4x4 model matrix
- // vc4, vc5, vc6, vc7 - 4x4 view matrix
- // vc8.x - Scalar for LineThickness
- // --- Input Attributes ---
- // va0 - 3d vector of vertex position
- // va1 - 3d vector of line direction
- // va2.x - Dash size
- // --- Usage ---
- // Each line is represented by 4 vertices - two at the start point, and two at the end point.
- // This shader will move these vertices apart, so as to form a rectangle,
- // so index buffers should be populated as if these 4 vertices form a quad.
- // ----------------------------------------------------------------------------------
- // Transform vertex by model matrix
- m44 vt5 va0 vc0
- // Copy model matrix to temporary registers, where we are allowed to manipulate it
- mov vt0 vc0
- mov vt1 vc1
- mov vt2 vc2
- mov vt3 vc3
- // Remove translation - we don't want to translate a vector that holds direction (not position)
- sub vt0.w vt0.w vt0.w
- sub vt1.w vt1.w vt1.w
- sub vt2.w vt2.w vt2.w
- // Transform line direction by the model matrix - save in vt4
- m44 vt4 va1 vt0
- // Line direction is now in 2d screen space, take its right orthagonal and put it in vt2.xy
- mov vt2 vt4 // Copy to prevent shader validation error
- mov vt2.x vt4.y // Transpose X & Y
- mov vt2.y vt4.x // Transpose X & Y
- neg vt2.y vt2.y // y = -y
- // Normalize the direction down to 1 pixel, then multiply it by LineThickness
- mul vt0.xy vt2.xy vt2.xy // Square offset
- add vt0.z vt0.x vt0.y // Sum of squares
- sqt vt0.z vt0.z // Square root - save in vt0.z
- //div vt2.xy vt2.xy vt0.z // Normalize offset
- //mul vt2.xy vt2.xy vc8.x // Multiply by LineThickness
- // Shift the screen space vertex by the 2d direction
- add vt5.xy vt5.xy vt2.xy // Add offset to transformed vertex position
- // Set up dash size
- div vt0.z vt0.z va2.x // Change dash size to length relative
- mov v0 vt0.z // Copy the vertex distance on line to the fragment shader
- //mov v0.x va2.x // Copy the vertex distance on line to the fragment shader
- // Transform by view matrix
- m44 vt5 vt5 vc4 // Transform by view
- mov op vt5 // Return vertex position
Add Comment
Please, Sign In to add comment