示例#1
0
void Light::enterScene(Scene* scene) {
    VisualComponent::enterScene(scene);

    light = createLight();

    setEnabled(isEnabled());
    setDiffuseColour(getDiffuseColour());
    setSpecularColour(getSpecularColour());
    setAttenuation(getAttenuation());

    getSceneNode()->attachObject(light);
}
示例#2
0
bool PlatformDemoState::update(float dt)
{    
    playerController->applyInput(playerInput);

    m_scene.update(dt);
    m_meshRenderer.update();

    //update lighting
    auto& shader = m_shaderResource.get(PlatformShaderId::SpecularSmooth2D);
    //shader.setUniform("u_ambientColour", sf::Glsl::Vec4(m_scene.getAmbientColour()));
    auto lights = m_scene.getVisibleLights(m_scene.getVisibleArea());
    auto i = 0u;
    for (; i < lights.size() && i < xy::Shader::NormalMapped::MaxPointLights; ++i)
    {
        auto light = lights[i];
        if (light)
        {
            const std::string idx = std::to_string(i);
            
            auto pos = light->getWorldPosition();
            shader.setUniform("u_pointLightPositions[" + std::to_string(i) + "]", pos);
            shader.setUniform("u_pointLights[" + idx + "].intensity", light->getIntensity());
            shader.setUniform("u_pointLights[" + idx + "].diffuseColour", sf::Glsl::Vec4(light->getDiffuseColour()));
            shader.setUniform("u_pointLights[" + idx + "].specularColour", sf::Glsl::Vec4(light->getSpecularColour()));
            shader.setUniform("u_pointLights[" + idx + "].inverseRange", light->getInverseRange());
        }
    }
    //switch off inactive lights
    for (; i < xy::Shader::NormalMapped::MaxPointLights; ++i)
    {
        shader.setUniform("u_pointLights[" + std::to_string(i) + "].intensity", 0.f);
    }
    
    //update skylight
    const auto& skyLight = m_scene.getSkyLight();
    shader.setUniform("u_directionalLight.diffuseColour", sf::Glsl::Vec4(skyLight.getDiffuseColour()));
    shader.setUniform("u_directionalLight.specularColour", sf::Glsl::Vec4(skyLight.getSpecularColour()));
    shader.setUniform("u_directionalLight.intensity", skyLight.getIntensity());
    shader.setUniform("u_directionaLightDirection", skyLight.getDirection());

    return true;
}