Skip to content

Instantly share code, notes, and snippets.

@barcharcraz
Last active January 2, 2016 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barcharcraz/8278622 to your computer and use it in GitHub Desktop.
Save barcharcraz/8278622 to your computer and use it in GitHub Desktop.
type TVert = tuple
pos: vec3
norm: vec3
uv: vec2
type TMVP = tuple
model: mat4x4
view: mat4x4
proj:mat4x4
type TVSOut = tuple
uv: vec2
#this would come from some other library
#would need to be able to do image related things
#with it
type TImage
shader standard:
using pervert input: TVert
using uniform mvp: TMVP
using texture tex: TImage
vc to ps vsout: vec2
vsproc(): vec4 =
vsout = input.uv
result = mvp.proj * mvp.view * mvp.model * input.pos
psproc(): vec4 =
result = sample(tex, vsout.uv)
#the generated code would have something like:
proc drawStandard(input: seq[TVert], mvp: TMVP, tex: TImage) = ...
#we could have seperate stages as well maybe something liek
vertex shader standardvs:
using pervert input: TVert
using uniform mvp: TMVP
using vertex output: TVert.pos
vsproc(): TVert =
result.pos = mvp.proj * mvp.view * mvp.model * input.pos
result.norm = input.norm
result.uv = input.uv
pixel shader standardps:
using texture tex: TImage
psproc(input: TVert): vec4 =
result = sample(tex, input.uv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment