libctru/examples/graphics/gpu/geoshader/source/gshader.pica

92 lines
1.6 KiB
Plaintext
Raw Normal View History

2015-07-22 19:41:59 +02:00
; Example PICA200 geometry shader
; Uniforms
.fvec projection[4]
; Constants
.constf myconst(0.0, 1.0, -1.0, 0.5)
.alias zeros myconst.xxxx ; Vector full of zeros
.alias ones myconst.yyyy ; Vector full of ones
.alias half myconst.wwww
; Outputs - this time the type *is* used
.out outpos position
.out outclr color
; Inputs: we will receive the following inputs:
; v0-v1: position/color of the first vertex
; v2-v3: position/color of the second vertex
; v4-v5: position/color of the third vertex
.proc main
; Calculate the midpoints of the vertices
mov r4, v0
add r4, v2, r4
mul r4, half, r4
mov r5, v2
add r5, v4, r5
mul r5, half, r5
mov r6, v4
add r6, v0, r6
mul r6, half, r6
; Emit the first triangle
mov r0, v0
mov r1, r4
mov r2, r6
call emit_triangle
; Emit the second triangle
mov r0, r4
mov r1, v2
mov r2, r5
call emit_triangle
; Emit the third triangle
mov r0, r6
mov r1, r5
mov r2, v4
call emit_triangle
; We're finished
end
.end
.proc emit_triangle
; Emit the first vertex
setemit 0
mov r8, r0
mov r9, v1
call process_vertex
emit
; Emit the second vertex
setemit 1
mov r8, r1
mov r9, v3
call process_vertex
emit
; Emit the third vertex and finish the primitive
setemit 2, prim
mov r8, r2
mov r9, v5
call process_vertex
emit
.end
; Subroutine
; Inputs:
; r8: vertex position
; r9: vertex color
.proc process_vertex
; outpos = projectionMatrix * r8
dp4 outpos.x, projection[0], r8
dp4 outpos.y, projection[1], r8
dp4 outpos.z, projection[2], r8
dp4 outpos.w, projection[3], r8
; outclr = r9
mov outclr, r9
.end