Skip to content

Instantly share code, notes, and snippets.

@smealum
Last active August 29, 2015 14:11
Show Gist options
  • Save smealum/b7b1195924e35e94ba41 to your computer and use it in GitHub Desktop.
Save smealum/b7b1195924e35e94ba41 to your computer and use it in GitHub Desktop.
custom geoshader
; make sure you update aemstro_as for this (12/13/14)
; setup constants
.const c20, 1.0, 0.0, 0.5, 1.0
.const c21, 0.25, 0.0, 0.5, 1.0
.const c22, 0.0, 0.0, -0.5, 1.0
.const c23, 0.5, 0.0, -0.5, 1.0
.const c24, 0.0, 0.5, -0.5, 1.0
.const c25, 0.5, 0.5, -0.5, 1.0
.const c26, 1.0, 0.0, -0.5, 1.0
.const c27, 1.0, 0.5, -0.5, 1.0
.const c30, 0.02, 0.02, 0.0, 0.0
.const c31, 1.0, 0.00, 0.0, 1.0
; setup outmap
.out o0, result.position
.out o1, result.color
.out o2, result.texcoord0
.out o3, result.texcoord1
; setup uniform map (required to use SHDR_GetUniformRegister)
.uniform c0, c3, projection ; c0-c3 = projection matrix
.uniform c4, c7, modelview ; c4-c7 = modelview matrix
.uniform c8, c8, lightDirection ; c8 = light direction vector
.uniform c9, c9, lightAmbient ; c9 = light ambient color
; setup vsh and gsh
.vsh main, endmain
.gsh main_gsh, endmain_gsh
; code
main:
mov r1, v0 (0x6)
mov r1, c20 (0x3)
; tempreg = mdlvMtx * in.pos
dp4 r0, c4, r1 (0x0)
dp4 r0, c5, r1 (0x1)
dp4 r0, c6, r1 (0x2)
mov r0, c20 (0x3)
; result.pos = projMtx * tempreg
dp4 o0, c0, r0 (0x0)
dp4 o0, c1, r0 (0x1)
dp4 o0, c2, r0 (0x2)
dp4 o0, c3, r0 (0x3)
; result.texcoord = in.texcoord
mov o2, v1 (0x5)
mov o3, c20 (0x7)
;mov o4, c20 (0x7)
; result.color = EXPERIMENTS !
mov r0, c20 (0x7) ; r0 = color (black by default)
;mov r1, c20 (0x8) ; r1 = (0.5, 0.5)
;mov r2, c20 (0x4) ; r2 = (0.0, 1.0)
;mov r1, c20 (0x7) ; r1 = (0.0, 0.0)
;mov r2, c20 (0x7) ; r2 = (0.0, 0.0)
;cmp r1, 7, 7, r2 (0x5)
;ifc end_if, else, 0b1100
; mov r0, c20 (0x5)
;else:
; mov r0, c20 (0x5)
;end_if:
;ifu end_if, else, b3
; mov r0, c20 (0x5)
;else:
; mov r0, c20 (0x5)
;end_if:
loop end_loop, i0
add r0, c21, r0 (0x9)
end_loop:
mov r0, v2 (0x6)
mov o1, r0 (0x5)
flush
endmain:
draw_line:
; r12 = p1-p0
add r12, r11, r10 (0xc)
; r13 = norm(p1-p0)
dp4 r13, r12, r12 (0x5)
rsq r13, r13 (0x5)
mul r13, r13, r12 (0x5)
mul r13, c30, r13 (0x5)
; r14 = rot90(norm(p1-p0))
mov r14, r13 (0xe)
mov r14, r14 (0xf)
setemit vtx0, false, true
mov r3, r14 (0xd)
add o0, r3, v0 (0x5)
mov o1, r2 (0x5)
mov o2, c20 (0x5)
mov o3, c20 (0x5)
mov o4, c20 (0x5)
emit
setemit vtx1, false, true
mov r3, r14 (0x5)
add o0, r3, v0 (0x5)
mov o1, r2 (0x5)
mov o2, c20 (0x5)
mov o3, c20 (0x5)
mov o4, c20 (0x5)
emit
setemit vtx2, true, false
mov r3, r12 (0x5)
add r3, r14, r3 (0xd)
add o0, r3, v0 (0x5)
mov o1, r2 (0x5)
mov o2, c20 (0x5)
mov o3, c20 (0x5)
mov o4, c20 (0x5)
emit
setemit vtx0, true, true
mov r3, r12 (0x5)
add r3, r3, r14 (0x5)
add o0, r3, v0 (0x5)
mov o1, r2 (0x5)
mov o2, c20 (0x5)
mov o3, c20 (0x5)
emit
end_draw_line:
main_gsh:
; color
mov r2, c31 (0x5)
; r10 = p0, r11 = p1
mov r10, v0 (0x5)
mov r11, v4 (0x5)
call draw_line, end_draw_line
; r10 = p0, r11 = p1
mov r10, v4 (0x5)
mov r11, v8 (0x5)
call draw_line, end_draw_line
flush
endmain_gsh:
; operand descriptors
.opdesc x___, xyzw, xyzw ; 0x0
.opdesc _y__, xyzw, xyzw ; 0x1
.opdesc __z_, xyzw, xyzw ; 0x2
.opdesc ___w, xyzw, xyzw ; 0x3
.opdesc xyzw, zzzy, xyzw ; 0x4
.opdesc xyzw, xyzw, xyzw ; 0x5
.opdesc xyz_, xyzw, xyzw ; 0x6
.opdesc xyzw, yyyw, xyzw ; 0x7
.opdesc xyzw, yzzz, xyzw ; 0x8
.opdesc xyz_, xxxx, xyzw ; 0x9
.opdesc __zw, yyyy, xyzw ; 0xa
.opdesc xyzw, wwww, xyzw ; 0xb
.opdesc xyzw, xyzw, -xyzw ; 0xc
.opdesc xyzw, -xyzw, xyzw ; 0xd
.opdesc xyzw, yxzw, xyzw ; 0xe
.opdesc _y__, -xyzw, xyzw ; 0xf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment