RenderKit / ospray

An Open, Scalable, Portable, Ray Tracing Based Rendering Engine for High-Fidelity Visualization
http://ospray.org
Apache License 2.0
1.01k stars 182 forks source link

Converting IES file to intensityDistribution parameter #582

Open ArchlineXP opened 8 months ago

ArchlineXP commented 8 months ago

Hi,

We are stuck with converting the IES files to intensityDistribution parameter. Can someone please send me an example how to do it? We checked the https://www.ospray.org/documentation.html#photometric-lights document and found some information in Table 24, but couldn't figure out the conversion number.

johguenther commented 8 months ago

OSPRay Studio can load EULUMDAT files (alternative file format to IES, there are many converter tools) and pass the data as intensityDistribution to OSPRay, see https://github.com/ospray/ospray_studio/blob/master/sg/scene/lights/Photometric.cpp. Maybe this helps?

BruceCherniak commented 8 months ago

If IES is the necessary file format, there is a simple header-only IES file loader https://github.com/fknfilewalker/tinyies that will parse the file into an intensity array, and then the code that @johguenther mentions above can help to create the OSPRay intensityDistribution array. Ultimately, that array gets sent to OSPRay here https://github.com/ospray/ospray_studio/blob/master/sg/scene/lights/Light.cpp#L75 createChildData("intensityDistribution", lamp.lid)

ArchlineXP commented 7 months ago

Thanks for the answers, it helped a lot. We have another question about the converter:

We implemented your suggestions, but the results are incorrect. There are 5 lights in this scene, they all share the same .ldt data.

['A' image] https://ieslibrary.com/browse#ies-0017df4b5e5cfef10c72a89afaadf02b ['B' image] https://ieslibrary.com/browse#ies-006ea39eb1924d82436026bb68fff5f5 ['C' image] https://ieslibrary.com/browse#ies-021e7275e2d15cf3347d0299a955eb0f

Code:

phy_light = ospNewLight("spot");
CALVector3 pos = from; // float[3]
ospSetParam(phy_light, "position", OSP_VEC3F, pos);

CALVector3 t_ = To; // float[3]
t_.normalize();
ospSetParam(phy_light, "direction", OSP_VEC3F, t_);

OSPIntensityQuantity INTq = OSPIntensityQuantity::OSP_INTENSITY_QUANTITY_SCALE;
ospSetInt(phy_light, "intensityQuantity", INTq);
//ospSetParam(phy_light, "intensityQuantity", OSP_UINT, &INTq);
//ospSetParam(phy_light, "intensityQuantity", OSP_UCHAR, &INTq);

//  CALVector3 c0(0, 0, 1);
//  ospSetParam(phy_light, "c0", OSP_VEC3F, c0);
OSPData data_;

ospray::sg::Eulumdat lamp(R"(C:\......................\A.ldt)");
lamp.load();
float *pmData = new float[lamp.lid.size()];
for( int x = 0; x < lamp.lid.size(); x++)
    pmData[x] = lamp.lid[x];

data_ = ospNewSharedData1D(pmData, OSP_FLOAT, lamp.lid.size());

ospSetObject(phy_light, "intensityDistribution", data_);
ospCommit(phy_light);

I attached 3 pictures of the result. What can you suggest to make the final result of the IES lights good?

A

B

C

johguenther commented 7 months ago

The IES data you use is 2D, but passed as 1D, thus what you see is the different slices/planes compressed within the illumination cone (showing as stripes).

Try changing to

data_ = ospNewSharedData2D(lamp.lid.data(), OSP_FLOAT, lamp.Ng, lamp.totalMc)

No need to copy the data into pmData, but then lamp needs to be kept alive to share the data with OSPRay (alternatively use ospCopyData2D to let OSPRay keep the data).