diff --git a/kraken/nodes/KRLight.cpp b/kraken/nodes/KRLight.cpp index 3bba735..14e1091 100755 --- a/kraken/nodes/KRLight.cpp +++ b/kraken/nodes/KRLight.cpp @@ -67,9 +67,7 @@ KRLight::KRLight(KRScene& scene, std::string name) : KRNode(scene, name) , m_flareTexture(KRTextureBinding(KRTexture::TEXTURE_USAGE_LIGHT_FLARE)) { - m_color = Vector3::One(); m_occlusionQuery = 0; - m_decayStart = 0; // Initialize shadow buffers m_cShadowBuffers = 0; @@ -93,9 +91,7 @@ tinyxml2::XMLElement* KRLight::saveXML(tinyxml2::XMLNode* parent) { tinyxml2::XMLElement* e = KRNode::saveXML(parent); m_intensity.save(e); - e->SetAttribute("color_r", m_color.x); - e->SetAttribute("color_g", m_color.y); - e->SetAttribute("color_b", m_color.z); + m_color.save(e); m_decayStart.save(e); m_flareSize.save(e); m_flareOcclusionSize.save(e); @@ -111,18 +107,8 @@ tinyxml2::XMLElement* KRLight::saveXML(tinyxml2::XMLNode* parent) void KRLight::loadXML(tinyxml2::XMLElement* e) { KRNode::loadXML(e); - float x = 1.0f, y = 1.0f, z = 1.0f; - if (e->QueryFloatAttribute("color_r", &x) != tinyxml2::XML_SUCCESS) { - x = 1.0; - } - if (e->QueryFloatAttribute("color_g", &y) != tinyxml2::XML_SUCCESS) { - y = 1.0; - } - if (e->QueryFloatAttribute("color_b", &z) != tinyxml2::XML_SUCCESS) { - z = 1.0; - } - m_color = Vector3::Create(x, y, z); + m_color.load(e); m_intensity.load(e); m_decayStart.load(e); m_flareSize.load(e); @@ -248,7 +234,7 @@ void KRLight::render(RenderInfo& ri) info.modelFormat = ModelFormat::KRENGINE_MODEL_FORMAT_TRIANGLES; KRPipeline* pParticleShader = m_pContext->getPipelineManager()->getPipeline(*ri.surface, info); - pParticleShader->setPushConstant(ShaderValue::dust_particle_color, m_color * ri.camera->settings.dust_particle_intensity * m_dust_particle_intensity * m_intensity); + pParticleShader->setPushConstant(ShaderValue::dust_particle_color, m_color.val * ri.camera->settings.dust_particle_intensity * m_dust_particle_intensity * m_intensity); pParticleShader->setPushConstant(ShaderValue::particle_origin, Matrix4::DotWDiv(Matrix4::Invert(particleModelMatrix), Vector3::Zero())); pParticleShader->bind(ri, particleModelMatrix); // TODO: Pass light index to shader @@ -300,7 +286,7 @@ void KRLight::render(RenderInfo& ri) float slice_spacing = (slice_far - slice_near) / slice_count; pFogShader->setPushConstant(ShaderValue::slice_depth_scale, Vector2::Create(slice_near, slice_spacing)); - pFogShader->setPushConstant(ShaderValue::light_color, (m_color * ri.camera->settings.volumetric_environment_intensity * m_intensity * -slice_spacing / 10.0f)); + pFogShader->setPushConstant(ShaderValue::light_color, (m_color.val * ri.camera->settings.volumetric_environment_intensity * m_intensity * -slice_spacing / 10.0f)); pFogShader->bind(ri, Matrix4()); // TODO: Pass indexes of lights to shader m_pContext->getMeshManager()->bindVBO(ri.commandBuffer, &m_pContext->getMeshManager()->KRENGINE_VBO_DATA_VOLUMETRIC_LIGHTING, 1.0f); diff --git a/kraken/nodes/KRLight.h b/kraken/nodes/KRLight.h index c46b06e..1549dea 100755 --- a/kraken/nodes/KRLight.h +++ b/kraken/nodes/KRLight.h @@ -79,10 +79,9 @@ protected: bool getShaderValue(ShaderValue value, float* output) const override; bool getShaderValue(ShaderValue value, hydra::Vector3* output) const override; + // Properties KRNODE_PROPERTY(float, m_decayStart, 0.f, "decay_start"); - hydra::Vector3 m_color; - - KRTextureBinding m_flareTexture; + KRNODE_PROPERTY(hydra::Vector3, m_color, hydra::Vector3({1.f, 1.f, 1.f}), "decay_start"); KRNODE_PROPERTY(float, m_intensity, 1.f, "intensity"); KRNODE_PROPERTY(float, m_flareSize, 0.f, "flare_size"); KRNODE_PROPERTY(float, m_flareOcclusionSize, 0.05f, "flare_occlusion_size"); @@ -91,6 +90,7 @@ protected: KRNODE_PROPERTY(float, m_dust_particle_density, 0.1f, "dust_particle_density"); KRNODE_PROPERTY(float, m_dust_particle_size, 1.f, "dust_particle_size"); KRNODE_PROPERTY(float, m_dust_particle_intensity, 1.f, "dust_particle_intensity"); + KRTextureBinding m_flareTexture; int m_occlusionQuery; // Occlusion query for attenuating occluded flares diff --git a/kraken/nodes/KRNode.h b/kraken/nodes/KRNode.h index 22d86ee..89b6d16 100755 --- a/kraken/nodes/KRNode.h +++ b/kraken/nodes/KRNode.h @@ -97,6 +97,8 @@ public: { if constexpr (std::is_same::value) { element->SetAttribute(config::name, val ? "true" : "false"); + } else if constexpr (std::is_same::value) { + kraken::setXMLAttribute(config::name, element, val, config::defaultVal); } else { element->SetAttribute(config::name, val); } @@ -112,6 +114,8 @@ public: if (element->QueryBoolAttribute(config::name, &val) != tinyxml2::XML_SUCCESS) { val = config::defaultVal; } + } else if constexpr (std::is_same::value) { + kraken::getXMLAttribute(config::name, element, config::defaultVal); } else { static_assert(false, "Typename not implemented."); } @@ -122,7 +126,7 @@ public: #define KRNODE_PROPERTY(PROP_TYPE, VAR, PROP_DEFAULT, PROP_NAME) \ struct VAR ## _config { \ - static constexpr float defaultVal = PROP_DEFAULT; \ + static constexpr PROP_TYPE defaultVal = PROP_DEFAULT; \ static constexpr const char* name = PROP_NAME; \ }; \ KRNodeProperty VAR;