19 VisRTX::Context* rtx = VisRTX_GetContext();
21 if (
type ==
"DirectionalLight" ||
type ==
"distant")
22 this->light = rtx->CreateDirectionalLight();
23 else if (
type ==
"PointLight" ||
type ==
"point" ||
type ==
"SphereLight" ||
type ==
"sphere")
24 this->light = rtx->CreateSphericalLight();
25 else if (
type ==
"SpotLight" ||
type ==
"spot")
26 this->light = rtx->CreateSpotLight();
27 else if (
type ==
"QuadLight" ||
type ==
"quad")
28 this->light = rtx->CreateQuadLight();
29 else if (
type ==
"AmbientLight" ||
type ==
"ambient")
30 this->light = rtx->CreateAmbientLight();
31 else if (
type ==
"HDRILight" ||
type ==
"hdri")
32 this->light = rtx->CreateHDRILight();
35 std::cerr <<
"Error: Unhandled light type \"" <<
type <<
"\"" << std::endl;
42 this->light->Release();
49 this->light->SetColor(
color);
58 if (this->light->GetType() == VisRTX::LightType::DIRECTIONAL)
66 float angularDiameter;
67 if (this->
Get1f({
"angularDiameter" }, &angularDiameter))
68 dirLight->SetAngularDiameter(angularDiameter);
74 else if (this->light->GetType() == VisRTX::LightType::SPHERICAL)
76 VisRTX::SphericalLight* sphereLight =
dynamic_cast<VisRTX::SphericalLight*
>(this->light);
84 sphereLight->SetRadius(
radius);
90 else if (this->light->GetType() == VisRTX::LightType::SPOT)
103 if (this->
Get1f({
"openingAngle" }, &openingAngle))
104 spot->SetOpeningAngle(openingAngle);
107 if (this->
Get1f({
"penumbraAngle" }, &penumbraAngle))
108 spot->SetPenumbraAngle(penumbraAngle);
118 else if (this->light->GetType() == VisRTX::LightType::QUAD)
120 VisRTX::QuadLight* quad =
dynamic_cast<VisRTX::QuadLight*
>(this->light);
122 VisRTX::Vec3f
position, edge1, edge2;
123 if (this->
Get3f({
"position" }, &
position) && this->
Get3f({
"edge1" }, &edge1) && this->
Get3f({
"edge2" }, &edge2))
124 quad->SetRect(
position, edge1, edge2);
126 quad->SetTwoSided(
false);
132 else if (this->light->GetType() == VisRTX::LightType::HDRI)
134 VisRTX::HDRILight* hdri =
dynamic_cast<VisRTX::HDRILight*
>(this->light);
136 Texture* texture = this->GetObject<Texture>({
"map" });
138 hdri->SetTexture(texture->texture);
145 if (this->
Get3f({
"up" }, &up))
151 VisRTX::Light* light =
nullptr;
Light(const std::string &type)
VisRTX::Vec3f Get3f(const std::vector< std::string > &ids, const VisRTX::Vec3f &defaultValue=VisRTX::Vec3f(), bool *found=nullptr) const
float Get1f(const std::vector< std::string > &ids, float defaultValue=0.0f, bool *found=nullptr) const