Access variables between cu files

Hello together,

I’m pretty sure this question has been answered before but I think I miss the keyword to find the answer.

I have a ray generation program in a file and inside a variable seed:

RT_PROGRAM void function() {
// ...
unsigned int seed = ...;

Now, all I want is to use this seed in another in a closest hit / any hit progam (read only):

RT_PROGRAM void closest_hit() {
// ...
// use seed from
// ...

How do I do that? Thank you in advance!

The random number seed should be per ray, which means it needs to be part of your per ray payload structure.
(That seed is not read only because it changes every time you draw a new random number.)

Example code for that OptiX API here:
Initialization in the raygeneration program:
Access inside the closest hit program (e.g. for explicit light sampling):

Very similar for the OptiX 7.x API, shown in these ported examples:

(BTW, if you need global read-only variables, with the old OptiX API these would normally be stored in variables at the Context scope which is accessible in all program domains. In the OptiX 7.x API that would be inside the constant launch parameter structure.)

That solved all problems, thank you!

1 Like