Open arkanoid87 opened 1 year ago
Yes we could probably add them. I just did not find a complete list. I do also want a nim implementation of them for the GLSL on the CPU path. But that can wait.
I've implemented just 4 (bitops like) function so far. Surely implementing them all seems a large job
I think I am facing an issue related to this. I got the error:
Error: undeclared identifier: 'step'
Reading this issue, I though about adding step
to glslFunctions
, but I continue getting the error.
Besides, I would like to know what is the appropriate way to add the CPU version. I bet it will be something like:
proc step(edge, x: float): float =
if x <= edge:
result = 0.0
else:
result = 1.0
So it looks like, I have to include the name of the function in glslFunctions
and then just define the CPU version functions somewhere else:
import chroma, shady, shady/demo, vmath
proc step(edge, x: float): float =
if x <= edge:
result = 0.0
else:
result = 1.0
proc step[T:Vec4|Vec3|Vec2](edge, x: T): T =
var len:int = if x is Vec2:
2
elif x is Vec3:
3
else:
4
for i in 0 ..< len:
if x[i] <= edge[i]:
result[i] = 0.0
else:
result[i] = 1.0
proc main(gl_FragColor: var Vec4, uv: Vec2, time: Uniform[float32]) =
if step(vec2(50.0, 80.0), uv) == vec2(0.0,0.0):
gl_FragColor = vec4(1, 1, 1, 1)
else:
gl_FragColor = vec4(0, 0, 0, 1)
# CPU test
echo step(vec2(200.0,200.0), vec2(300.0,100.0) ) == vec2(1.0,0.0)
# compile to a GPU shader:
var shader = toGLSL(main)
echo shader
run("Tutorial", shader)
Yes that is how its meant to be. More GLSL functions need to be added.
I'm finding myself editing
const glslFunctions
quite a lot, so I've added them allNot sure if this beneficial or not, but I'll share it here for your consideration
how about making it a set for performance reason?