Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Geometry Sprite Shader (G)
- ; Set the geometry to process points as input, with uniforms being allocated starting at register c0
- .gsh point c0
- ; Constants
- .constf myconst(0.0, 1.0, -1.0, 3.0)
- .alias zeros myconst.xxxx
- .alias ones myconst.yyyy
- .alias nones myconst.zzzz
- .alias threes myconst.wwww
- ; Uniforms
- ;(SpriteCount, Texture Width, Texture Height, [Unused])
- .fvec spriteCount
- ;Camera Matrices
- .fvec viewMatrix[4]
- .fvec projectionMatrix[4]
- ;3 Float Vectors are used per sprite. It stores (X, Y, Width, Height) (UV Position X, UV Position Y, UV Region Width, UV Region Height) (R, G, B, A)
- .fvec spriteData[75]
- ; Inputs
- ;v0 = Top-Left
- ;v1 = Bottom-Left
- ;v2 = Top-Right
- ; Outputs
- .out outpos position
- .out outclr color
- .out outuv texcoord0
- ; Main Function
- .entry gmain
- .proc gmain
- register_setup:
- ;LOOP DATA SETUP
- ;Set r10 to 0 for looping purposes.
- mov r10, zeros
- ;r11 = spriteCount
- mov r11.x, spriteCount.x
- ;r12 = ones
- mov r12, ones
- ;CONSTANT TO SCRATCH REGISTERS SETUP
- ;r13 = threes
- mov r13, threes
- ;SPRITE DATA SETUP
- ;Load the dimensions of the texture into r14.
- mov r14, zeros
- mov r14.xy, spriteCount.yz
- loop_begin:
- ;Loop through all of the sprites that need to be drawn.
- ;Exit the loop if there are no sprites to be drawn.
- cmp r10.x, lt, lt, r11.x
- jmpc !cmp.x, loop_exit
- ;Zero out r0.
- mov r0, zeros
- ;Temporarily use r6 to store the index to the sprite data. It gets multiplied by 3 because there are 3 vectors of data per sprite.
- mul r6, r10, r13
- ;Scale to the dimensions of the sprite.
- mova a0.x, r6.x
- mov r0.xy, spriteData[a0.x].zw
- mul r2, v0, r0
- mul r3, v1, r0
- mul r4, v2, r0
- ;Translate the sprite.
- mov r0.xy, spriteData[a0.x].xy
- add r2, r2, r0
- add r3, r3, r0
- add r4, r4, r0
- ;Calculate the position of the bottom right vertex.
- mov r0.xy, spriteData[a0.x].zw
- mov r5, r3
- add r5.x, r5.x, r0.x
- ;Set the z and w components of the vertices.
- mov r2.z, zeros.x
- mov r3.z, zeros.x
- mov r4.z, zeros.x
- mov r5.z, zeros.x
- mov r2.w, ones.x
- mov r3.w, ones.x
- mov r4.w, ones.x
- mov r5.w, ones.x
- ;Load the UV data of this sprite into r15.
- mov r15, spriteData[a0.x + 1]
- ;Generate the triangles composing the sprite.
- call emit_triangles
- ;Increment the counter used to control the loop.
- add r10, r10, r12
- ;Return to the beginning of the loop.
- jmpc cmp.x, loop_begin
- loop_exit:
- ; Function termination
- end
- .end
- ; Subroutine
- ; Description: Generate the triangles composing the sprite.
- ; Inputs:
- ; r2: Top-Left Vertex Position
- ; r3: Bottom-Left Vertex Position
- ; r4: Top-Right Vertex Position
- ; r5: Bottom-Right Vertex Position
- ; r14: Texture Dimensions
- ; r15: Sprite UV Position and Size (Top-Left Origin)
- .proc emit_triangles
- ; Emit the upper left triangle.
- setemit 0
- mov r6, r2
- ;Generate the UV coordinate of the vertex.
- mov r7, zeros
- mov r7.xy, r15.xy
- mul r7, r7, r14
- call process_vertex
- emit
- setemit 1
- mov r6, r3
- ;Generate the UV coordinate of the vertex.
- mov r7, zeros
- mov r7.xy, r15.xy
- add r7.y, r7.y, r15.w
- mul r7, r7, r14
- call process_vertex
- emit
- setemit 2, prim
- mov r6, r4
- ;Generate the UV coordinate of the vertex.
- mov r7, zeros
- mov r7.xy, r15.xy
- add r7.x, r7.x, r15.z
- mul r7, r7, r14
- call process_vertex
- emit
- ; Emit the bottom right triangle.
- setemit 0
- mov r6, r4
- ;Generate the UV coordinate of the vertex.
- mov r7, zeros
- mov r7.xy, r15.xy
- add r7.x, r7.x, r15.z
- mul r7, r7, r14
- call process_vertex
- emit
- setemit 1
- mov r6, r3
- ;Generate the UV coordinate of the vertex.
- mov r7, zeros
- mov r7.xy, r15.xy
- add r7.y, r7.y, r15.w
- mul r7, r7, r14
- call process_vertex
- emit
- setemit 2, prim
- mov r6, r5
- ;Generate the UV coordinate of the vertex.
- mov r7, zeros
- mov r7.xy, r15.xy
- add r7.xy, r7.xy, r15.zw
- mul r7, r7, r14
- call process_vertex
- emit
- .end
- ; Subroutine
- ; Description: Multiply by the camera matrices and generate the final UV coordinates.
- ; Inputs:
- ; r6: Vertex Position
- ; r7: Vertex UV
- .proc process_vertex
- ; r8 = viewMatrix * r8
- dp4 r8.x, viewMatrix[0], r6
- dp4 r8.y, viewMatrix[1], r6
- dp4 r8.z, viewMatrix[2], r6
- dp4 r8.w, viewMatrix[3], r6
- ; projectionMatrix * viewMatrix * r8
- dp4 outpos.x, projectionMatrix[0], r8
- dp4 outpos.y, projectionMatrix[1], r8
- dp4 outpos.z, projectionMatrix[2], r8
- dp4 outpos.w, projectionMatrix[3], r8
- ; outclr = ones
- mov outclr, spriteData[a0.x + 2]
- ;Negate the UV coordinates Y component and invert it. (1.0f - UV.y)a
- mov r13, nones
- mul r7.y, r7.y, r13.y
- add r7.y, ones.y, r7.y
- mov r13, threes
- ;outuv = r7
- mov outuv.xy, r7.xy
- .end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement