r/GraphicsProgramming • u/eitanski • Nov 14 '20
How to implement math in a CUDA based ray tracer?
I just learnt a bit of CUDA and some of it's basics, and now I'm on the look for tools to handle all the mathematic operations. I know the math needed, but I don't want to implement everything by myself. I looked up the cuda math library and cublas but I still couldn't find any functions to do all the operations. Things like dot products, cross products, integrals and so on.
How can I use CUDA for these operations without doing everything from scratch?
Take in mind I'm a beginner in CG and programming as a whole.
Thanks Ahead!
2
u/wchang22 Nov 14 '20
This header helper_math.h has most of the simple graphics math operations (dot, cross, normalize, etc) you would find in shading languages like GLSL.
1
u/leseiden Nov 14 '20
I haven't tried it, but the eigen documentation suggests that it can be used with cuda but may not be feature complete.
It's a decent general purpose linear algebra library.
1
u/guerrerost Nov 15 '20
I also agree with others that if you don't have much experience with CG programming you may have a hard time figuring out how to implement a ray tracer on the GPU since you will also have to consider how you will share memory, optimal block sizes, kernel implementations, etc.
However if you decide to stick to it, I recommend the glm library for math operations (I recently worked on a CUDA path tracer myself and found it helpful).
1
u/Plazmatic Nov 18 '20
glm https://github.com/g-truc/glm supports CUDA and has way more facilities than cuda_math.h
0
7
Nov 14 '20
[removed] — view removed comment
2
u/PoTe2 Nov 15 '20
(I'm op's partner in his project)our main goal for this project was to learn a new technology, which is why we went for raytracing on Cuda. we don't really care about performance as we just want to learn the basics of the algorithm and the style of work that's used when working on the GPU (CUDA)I think we will just write the functions ourselves in the end and sacrifice some performance. that being said we'll probably also try to get cuBLAS to work just for the heck of using an actual industry-standard API. In any case, thanks for the reply!
edit - fixed a weird copy paste
4
u/ShillingAintEZ Nov 14 '20
If you don't know how to implement a dot product you might want to back off of cuda and start with something as simple as possible.