22 VisRTX::Context* rtx = VisRTX_GetContext();
24 if (type ==
"DirectionalLight" || type ==
"distant")
25 this->light = rtx->CreateDirectionalLight();
26 else if (type ==
"PointLight" || type ==
"point" || type ==
"SphereLight" || type ==
"sphere")
27 this->light = rtx->CreateSphericalLight();
28 else if (type ==
"SpotLight" || type ==
"spot")
29 this->light = rtx->CreateSpotLight();
30 else if (type ==
"QuadLight" || type ==
"quad")
31 this->light = rtx->CreateQuadLight();
32 else if (type ==
"AmbientLight" || type ==
"ambient")
33 this->light = rtx->CreateAmbientLight();
34 else if (type ==
"HDRILight" || type ==
"hdri")
35 this->light = rtx->CreateHDRILight();
38 vtkLogF(ERROR,
"VisRTX Error: Unhandled light type \"%s\"", type.c_str());
45 this->light->Release();
50 switch(this->light->GetType())
52 case VisRTX::LightType::AMBIENT:
54 case VisRTX::LightType::DIRECTIONAL:
56 case VisRTX::LightType::SPHERICAL:
58 case VisRTX::LightType::SPOT:
60 case VisRTX::LightType::QUAD:
62 case VisRTX::LightType::HDRI:
72 if (this->
GetVec3f({
"color" }, &color))
73 this->light->SetColor(color);
76 if (this->
GetFloat({
"intensity" }, &intensity))
77 this->light->SetIntensity(intensity);
82 if (this->light->GetType() == VisRTX::LightType::DIRECTIONAL)
84 VisRTX::DirectionalLight* dirLight =
dynamic_cast<VisRTX::DirectionalLight*
>(this->light);
86 VisRTX::Vec3f direction;
87 if (this->
GetVec3f({
"direction" }, &direction))
88 dirLight->SetDirection(direction);
90 float angularDiameter;
91 if (this->
GetFloat({
"angularDiameter" }, &angularDiameter))
92 dirLight->SetAngularDiameter(angularDiameter);
98 else if (this->light->GetType() == VisRTX::LightType::SPHERICAL)
100 VisRTX::SphericalLight* sphereLight =
dynamic_cast<VisRTX::SphericalLight*
>(this->light);
102 VisRTX::Vec3f position;
103 if (this->
GetVec3f({
"position" }, &position))
104 sphereLight->SetPosition(position);
107 if (this->
GetFloat({
"radius" }, &radius))
108 sphereLight->SetRadius(radius);
114 else if (this->light->GetType() == VisRTX::LightType::SPOT)
116 VisRTX::SpotLight* spot =
dynamic_cast<VisRTX::SpotLight*
>(this->light);
118 VisRTX::Vec3f position;
119 if (this->
GetVec3f({
"position" }, &position))
120 spot->SetPosition(position);
122 VisRTX::Vec3f direction;
123 if (this->
GetVec3f({
"direction" }, &direction))
124 spot->SetDirection(direction);
127 if (this->
GetFloat({
"openingAngle" }, &openingAngle))
128 spot->SetOpeningAngle(openingAngle);
131 if (this->
GetFloat({
"penumbraAngle" }, &penumbraAngle))
132 spot->SetPenumbraAngle(penumbraAngle);
135 if (this->
GetFloat({
"radius" }, &radius))
136 spot->SetRadius(radius);
142 else if (this->light->GetType() == VisRTX::LightType::QUAD)
144 VisRTX::QuadLight* quad =
dynamic_cast<VisRTX::QuadLight*
>(this->light);
146 VisRTX::Vec3f position, edge1, edge2;
147 if (this->
GetVec3f({
"position" }, &position) && this->
GetVec3f({
"edge1" }, &edge1) && this->
GetVec3f({
"edge2" }, &edge2))
148 quad->SetRect(position, edge1, edge2);
150 quad->SetTwoSided(
false);
156 else if (this->light->GetType() == VisRTX::LightType::HDRI)
158 VisRTX::HDRILight* hdri =
dynamic_cast<VisRTX::HDRILight*
>(this->light);
160 Texture* texture = this->GetObject<Texture>({
"map" });
162 hdri->SetTexture(texture->texture);
164 VisRTX::Vec3f direction;
165 if (this->
GetVec3f({
"dir",
"direction" }, &direction))
166 hdri->SetDirection(direction);
175 VisRTX::Light* light =
nullptr;
Light(const std::string &type)
float GetFloat(const std::vector< std::string > &ids, float defaultValue=0.0f, bool *found=nullptr) const
VisRTX::Vec3f GetVec3f(const std::vector< std::string > &ids, const VisRTX::Vec3f &defaultValue=VisRTX::Vec3f(), bool *found=nullptr) const
#define vtkLogF(verbosity_name,...)
Add to log given the verbosity level.