I don’t see anything wrong with that part of the code. The float3 fields themselves have a 4-byte alignment and the structure size is 48 bytes which is float4 aligned to the next struct in an array.
In case this works with one light but not multiple, this would eliminate possible misalignments of structs.
Personally I wouldn’t define a directional light this way. This is just some example code and actually not used in any shipping OptiX example as far as I can see.
The vectors v1 and v2 are possibly meant to hold the other two vectors of an ortho-normal basis with the direction as normal. That doesn’t make too much sense with a directional light source which has no anchor point, but allows to abuse this structure to implement a positional disc light and that’s where things get hacky. Don’t do that.
That said, if you don’t need parts of specific example code, just roll your own.
Now to the yellow color. You didn’t give the device code which uses the data inside the buffer.
Are you sure the yellow color comes from the light and isn’t just the “bad_color” used in some OptiX examples when an exception occurs?
I’m normally using magenta there because that doesn’t appear in real world materials that often.
Additionally to detect that an exception occurred, you should always run with an exception program which dumps exception codes when debugging your program.
An example of an exception program which dumps the exception code and how to enable that can be found here:
https://devtalk.nvidia.com/default/topic/936762/?comment=4882450
Omit the host code line which limits the printing to only one launch index to get exceptions shown for your whole launch size.
When benchmarking, undefine that code. Exception handling costs performance!
If the yellow color comes from the exception, that most often happens when changing the device code to do more recursions or using more local variables, which often exceeds the set stack size.
If the exception code is a stack overflow, simply increase the value in rtContextSetStackSize() to the smallest value which doesn’t hit that anymore.
Then you say you “would like to make a light cone along the x-axis”.
A directional light doesn’t have a cone. For that you would need to implement a positional light source with a direction and some cone angle, aka. a spot light.
You can find various implementations of spot lights on the web. Here’s one post explaining it for Cg
http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter05.html
If your renderer is a Whitted ray tracer (no global illumination) you only need to port the fragment shading part to your closest hit program.