Re: How can I store global variables one by one in an array?


Larry Gritz
 

First of all, in OSL, if you simply call "P", you will be calling a set of shading points P, I think.

I think that's the point of confusion.  P is one point, it is not a "set of points."

The programming model (how you think of the shader operating) is that you are shading one point at a time. That's all that is exposed.

Whether the system is actually shading one or multiple points at the same time (and if they are synchronized in any meaningful way) depends on the implementation and which "back end" you may be using. The ordinary CPU based back end that almost all OSL renderers use REALLY IS just shading one point at a time (though multiple threads may be shading different points simultaneously, which are not necessarily the same material or shader). The "CPU batched shading" that Intel has ~95% complete shades up to 8 or 16 points of the same material simultaneously (depending on the kind of CPU you have). The Cuda-based GPU back end may shade LOTS of points, but even in that case, it's not ALL the points that will be shaded, and groups of points in parallel don't necessarily know about and are not necessarily synchronized with other groups of points in the same overall kernel launch.

So in short, OSL just doesn't present this kind of interface, and most renderers currently in operation do not work underneath in a way that would be well matched to accessing all points simultaneously at the same point of execution of the shader.


On Mar 2, 2022, at 3:38 AM, トマトフライ <tomatofry.illust@...> wrote:

I replied to the email that was sent to me, but I'm not sure if it was for sending only.
I'm not sure if you received it, so I'll send it to this thread as well.
 
I'm sorry for the confusing question.
I will explain based on the reply you gave me.
 
First of all, in OSL, if you simply call "P", you will be calling a set of shading points P, I think.
This means that you don't know how many shading points there are in the scene, and you can't read the numerical values of the coordinates of each shading point.
What I want to do is to take one arbitrary coordinate from the set of shading points (like a normal point type) and store that coordinate in an array. Then I want to use the length of P as the conditional expression in the for statement, and in that I want to take an element from the array and compare it to the other P to create a map.
 
 
Since what I want to do is declare a variable, so to speak, I can't show any code in OSL that would change this.
If I were to express it in C instead
 
int P_length = sizeof(P.x) / sizeof(P.x[0]);
 
float P_xval =P.x[103];
 
and so on.
 
 
 
Or, if I can access the coordinates of every single point in the set of P, I may be able to omit this kind of code.
Maybe it exists as a member of the structure P.
 
 
Is it possible to program like this in OSL?
And do such variables exist?
That's what I want to ask.
 
 
And one more thing, I am sorry to repeat this question.
It seems that the global variables contain elements like members in c language.
Is there a site or a way to view all of them? I would appreciate it if you could help me.
Thank you.

--
Larry Gritz




Join osl-dev@lists.aswf.io to automatically receive all group messages.