Beispiel #1
0
void EpicShader::SetupShaderLighting(const Light* light) const
{
    if (!light) {
        SetShaderUniform("lightingType", static_cast<int>(Light::LightType::GLOBAL));
    } else {
        // Get the light's properties
        const LightProperties* lightProperty = static_cast<const LightProperties*>(light->GetPropertiesRaw());

        // Select proper lighting subroutine based on the light's type.
        switch(light->GetLightType()) {
            case Light::LightType::POINT:
                SetShaderUniform("lightingType", static_cast<int>(Light::LightType::POINT));
                SetShaderUniform("pointLight.light_color", lightProperty->light_color);
                SetShaderUniform("pointLight.point_position", lightProperty->point_position);
                SetShaderUniform("pointLight.light_radius", lightProperty->light_radius);
                break;
            case Light::LightType::DIRECTIONAL:
                SetShaderUniform("lightingType", static_cast<int>(Light::LightType::DIRECTIONAL));
                SetShaderUniform(light->GetName() + ".light_color", lightProperty->light_color);
                SetShaderUniform(light->GetName() + ".forward_direction", light->GetForwardDirection());
                SetShaderUniform(light->GetName() + ".point_position", lightProperty->point_position);
                break;
            case Light::LightType::HEMISPHERE:
                SetShaderUniform("lightingType", static_cast<int>(Light::LightType::HEMISPHERE));
                SetShaderUniform(light->GetName() + ".sky_color", lightProperty->sky_color);
                SetShaderUniform(light->GetName() + ".ground_color", lightProperty->ground_color);
                break;
            default:
                std::cerr << "WARNING: Light type is not supported. Defaulting to global light. Your output may look wrong. -- Ignoring: " << static_cast<int>(light->GetLightType()) << std::endl;
                SetShaderUniform("lightingType", static_cast<int>(Light::LightType::GLOBAL));
                break;
	}
        light->SetupShaderUniforms(this);
    }
    UpdateAttenuationUniforms(light);
}
void BlinnPhongShader::SetupShaderLighting(const Light* light) const
{
    if (!light) {
#ifndef DISABLE_OPENGL_SUBROUTINES
        SetShaderSubroutine("inputLightSubroutine", "globalLightSubroutine", lightingShaderStage);
#else
        SetShaderUniform("lightingType", static_cast<int>(Light::LightType::GLOBAL));
#endif
    } else {
        // Select proper lighting subroutine based on the light's type.
        switch(light->GetLightType()) {
        case Light::LightType::POINT:
#ifndef DISABLE_OPENGL_SUBROUTINES
            SetShaderSubroutine("inputLightSubroutine", "pointLightSubroutine", lightingShaderStage);
#else
            SetShaderUniform("lightingType", static_cast<int>(Light::LightType::POINT));
#endif
            break;
        default:
            std::cerr << "WARNING: Light type is not supported. Defaulting to global light. Your output may look wrong. -- Ignoring: " << static_cast<int>(light->GetLightType()) << std::endl;
#ifndef DISABLE_OPENGL_SUBROUTINES
            SetShaderSubroutine("inputLightSubroutine", "globalLightSubroutine", lightingShaderStage);
#else
            SetShaderUniform("lightingType", static_cast<int>(Light::LightType::GLOBAL));
#endif
            break;
        }

        // Get the light's properties and pass it into the shader.
        const LightProperties* lightProperty = light->GetPropertiesRaw();
        SetShaderUniform("genericLight.diffuseColor", lightProperty->diffuseColor);
        SetShaderUniform("genericLight.specularColor", lightProperty->specularColor);
        light->SetupShaderUniforms(this);
    }
    UpdateAttenuationUniforms(light);
}