Beispiel #1
0
bool ShaderGroup::create_optimized_osl_shader_group(
    OSL::ShadingSystem& shading_system,
    IAbortSwitch*       abort_switch)
{
    if (is_valid())
        return true;

    RENDERER_LOG_DEBUG("setting up shader group %s...", get_name());

    try
    {
        OSL::ShaderGroupRef shader_group_ref = shading_system.ShaderGroupBegin(get_name());

        if (shader_group_ref.get() == 0)
        {
            RENDERER_LOG_ERROR("failed to setup shader group %s: ShaderGroupBegin() call failed.", get_name());
            return false;
        }

        for (each<ShaderContainer> i = impl->m_shaders; i; ++i)
        {
            if (is_aborted(abort_switch))
            {
                shading_system.ShaderGroupEnd();
                return true;
            }

            if (!i->add(shading_system))
                return false;
        }

        for (each<ShaderConnectionContainer> i = impl->m_connections; i; ++i)
        {
            if (is_aborted(abort_switch))
            {
                shading_system.ShaderGroupEnd();
                return true;
            }

            if (!i->add(shading_system))
                return false;
        }

        if (!shading_system.ShaderGroupEnd())
        {
            RENDERER_LOG_ERROR("failed to setup shader group %s: ShaderGroupEnd() call failed.", get_name());
            return false;
        }

        impl->m_shader_group_ref = shader_group_ref;

        get_shadergroup_closures_info(shading_system);
        report_has_closure("emission", m_has_emission);
        report_has_closure("transparent", m_has_transparency);
        report_has_closure("subsurface", m_has_subsurface);
        report_has_closure("holdout", m_has_holdout);
        report_has_closure("debug", m_has_debug);

        get_shadergroup_globals_info(shading_system);
        report_uses_global("dPdtime", m_uses_dPdtime);

        return true;
    }
    catch (const exception& e)
    {
        RENDERER_LOG_ERROR("failed to setup shader group %s: %s.", get_name(), e.what());
        return false;
    }
}
Beispiel #2
0
bool ShaderGroup::create_optimized_osl_shader_group(
    OSLShadingSystem&       shading_system,
    const ShaderCompiler*   shader_compiler,
    IAbortSwitch*           abort_switch)
{
    if (is_valid())
        return true;

    RENDERER_LOG_DEBUG("setting up shader group \"%s\"...", get_path().c_str());

    if (!compile_source_shaders(shader_compiler))
        return false;

    try
    {
        OSL::ShaderGroupRef shader_group_ref = shading_system.ShaderGroupBegin(get_name());

        if (shader_group_ref.get() == nullptr)
        {
            RENDERER_LOG_ERROR("failed to setup shader group \"%s\": ShaderGroupBegin() call failed.", get_path().c_str());
            return false;
        }

        for (Shader& shader : impl->m_shaders)
        {
            if (is_aborted(abort_switch))
            {
                shading_system.ShaderGroupEnd();
                return true;
            }

            if (!shader.add(shading_system))
                return false;
        }

        for (ShaderConnection& connection : impl->m_connections)
        {
            if (is_aborted(abort_switch))
            {
                shading_system.ShaderGroupEnd();
                return true;
            }

            if (!connection.add(shading_system))
                return false;
        }

        if (!shading_system.ShaderGroupEnd())
        {
            RENDERER_LOG_ERROR("failed to setup shader group \"%s\": ShaderGroupEnd() call failed.", get_path().c_str());
            return false;
        }

        impl->m_shader_group_ref = shader_group_ref;

        get_shadergroup_closures_info(shading_system);
        report_has_closure("bsdf", HasBSDFs);
        report_has_closure(g_emission_str.c_str(), HasEmission);
        report_has_closure(g_transparent_str.c_str(), HasTransparency);
        report_has_closure(g_subsurface_str.c_str(), HasSubsurface);
        report_has_closure(g_debug_str.c_str(), HasDebug);

        report_has_closure("NPR", HasNPR);
        report_has_closure(g_matte_str.c_str(), HasMatte);

        get_shadergroup_globals_info(shading_system);
        report_uses_global("dPdtime", UsesdPdTime);

        return true;
    }
    catch (const exception& e)
    {
        RENDERER_LOG_ERROR("failed to setup shader group \"%s\": %s.", get_path().c_str(), e.what());
        return false;
    }
}