本文整理汇总了C++中osl::ShadingSystem类的典型用法代码示例。如果您正苦于以下问题:C++ ShadingSystem类的具体用法?C++ ShadingSystem怎么用?C++ ShadingSystem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ShadingSystem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: thread_init
CCL_NAMESPACE_BEGIN
/* Threads */
void OSLShader::thread_init(KernelGlobals *kg, KernelGlobals *kernel_globals, OSLGlobals *osl_globals)
{
/* no osl used? */
if(!osl_globals->use) {
kg->osl = NULL;
return;
}
/* per thread kernel data init*/
kg->osl = osl_globals;
kg->osl->services->thread_init(kernel_globals, osl_globals->ts);
OSL::ShadingSystem *ss = kg->osl->ss;
OSLThreadData *tdata = new OSLThreadData();
memset(&tdata->globals, 0, sizeof(OSL::ShaderGlobals));
tdata->globals.tracedata = &tdata->tracedata;
tdata->globals.flipHandedness = false;
tdata->osl_thread_info = ss->create_thread_info();
for(int i = 0; i < SHADER_CONTEXT_NUM; i++)
tdata->context[i] = ss->get_context(tdata->osl_thread_info);
tdata->oiio_thread_info = osl_globals->ts->get_perthread_info();
kg->osl_ss = (OSLShadingSystem*)ss;
kg->osl_tdata = tdata;
}
示例2: eval_displacement
void OSLShader::eval_displacement(KernelGlobals *kg, ShaderData *sd, ShaderContext ctx)
{
/* setup shader globals from shader data */
OSLThreadData *tdata = kg->osl_tdata;
PathState state = {0};
shaderdata_to_shaderglobals(kg, sd, &state, 0, tdata);
/* execute shader */
OSL::ShadingSystem *ss = (OSL::ShadingSystem*)kg->osl_ss;
OSL::ShaderGlobals *globals = &tdata->globals;
OSL::ShadingContext *octx = tdata->context[(int)ctx];
int shader = sd->shader & SHADER_MASK;
if(kg->osl->displacement_state[shader]) {
#if OSL_LIBRARY_VERSION_CODE < 10600
ss->execute(*octx, *(kg->osl->displacement_state[shader]), *globals);
#else
ss->execute(octx, *(kg->osl->displacement_state[shader]), *globals);
#endif
}
/* get back position */
sd->P = TO_FLOAT3(globals->P);
}
示例3: thread_free
void OSLShader::thread_free(KernelGlobals *kg)
{
if(!kg->osl)
return;
OSL::ShadingSystem *ss = (OSL::ShadingSystem*)kg->osl_ss;
OSLThreadData *tdata = kg->osl_tdata;
ss->release_context(tdata->context);
ss->destroy_thread_info(tdata->osl_thread_info);
delete tdata;
kg->osl = NULL;
kg->osl_ss = NULL;
kg->osl_tdata = NULL;
}
示例4: eval_volume
void OSLShader::eval_volume(KernelGlobals *kg, ShaderData *sd, float randb, int path_flag, ShaderContext ctx)
{
/* setup shader globals from shader data */
OSLThreadData *tdata = kg->osl_tdata;
shaderdata_to_shaderglobals(kg, sd, path_flag, tdata);
/* execute shader */
OSL::ShadingSystem *ss = (OSL::ShadingSystem*)kg->osl_ss;
OSL::ShaderGlobals *globals = &tdata->globals;
OSL::ShadingContext *octx = tdata->context[(int)ctx];
int shader = sd->shader & SHADER_MASK;
if (kg->osl->volume_state[shader])
ss->execute(*octx, *(kg->osl->volume_state[shader]), *globals);
if (globals->Ci)
flatten_volume_closure_tree(sd, globals->Ci);
}
示例5: thread_free
void OSLShader::thread_free(KernelGlobals *kg)
{
if(!kg->osl)
return;
OSL::ShadingSystem *ss = (OSL::ShadingSystem*)kg->osl_ss;
OSLThreadData *tdata = kg->osl_tdata;
for(int i = 0; i < SHADER_CONTEXT_NUM; i++)
ss->release_context(tdata->context[i]);
ss->destroy_thread_info(tdata->osl_thread_info);
delete tdata;
kg->osl = NULL;
kg->osl_ss = NULL;
kg->osl_tdata = NULL;
}
示例6: eval_background
void OSLShader::eval_background(KernelGlobals *kg, ShaderData *sd, PathState *state, int path_flag)
{
/* setup shader globals from shader data */
OSLThreadData *tdata = kg->osl_tdata;
shaderdata_to_shaderglobals(kg, sd, state, path_flag, tdata);
/* execute shader for this point */
OSL::ShadingSystem *ss = (OSL::ShadingSystem*)kg->osl_ss;
OSL::ShaderGlobals *globals = &tdata->globals;
OSL::ShadingContext *octx = tdata->context;
if(kg->osl->background_state) {
ss->execute(octx, *(kg->osl->background_state), *globals);
}
/* return background color immediately */
if(globals->Ci)
flatten_background_closure_tree(sd, globals->Ci);
}
示例7: get_shadergroup_globals_info
void ShaderGroup::get_shadergroup_globals_info(OSL::ShadingSystem& shading_system)
{
m_uses_dPdtime = true;
int num_globals = 0;
if (!shading_system.getattribute(
impl->m_shader_group_ref.get(),
"num_globals_needed",
num_globals))
{
RENDERER_LOG_WARNING(
"getattribute: num_globals_needed call failed for shader group %s; "
"assuming shader group uses all globals.",
get_name());
return;
}
if (num_globals != 0)
{
OIIO::ustring* globals = 0;
if (!shading_system.getattribute(
impl->m_shader_group_ref.get(),
"globals_needed",
OIIO::TypeDesc::PTR,
&globals))
{
RENDERER_LOG_WARNING(
"getattribute: globals_needed call failed for shader group %s; "
"assuming shader group uses all globals.",
get_name());
return;
}
m_uses_dPdtime = false;
for (int i = 0; i < num_globals; ++i)
{
if (globals[i] == g_dPdtime_str)
m_uses_dPdtime = true;
}
}
}
示例8: eval_background
float3 OSLShader::eval_background(KernelGlobals *kg, ShaderData *sd, int path_flag, ShaderContext ctx)
{
/* setup shader globals from shader data */
OSLThreadData *tdata = kg->osl_tdata;
shaderdata_to_shaderglobals(kg, sd, path_flag, tdata);
/* execute shader for this point */
OSL::ShadingSystem *ss = (OSL::ShadingSystem*)kg->osl_ss;
OSL::ShaderGlobals *globals = &tdata->globals;
OSL::ShadingContext *octx = tdata->context[(int)ctx];
if (kg->osl->background_state)
ss->execute(*octx, *(kg->osl->background_state), *globals);
/* return background color immediately */
if (globals->Ci)
return flatten_background_closure_tree(globals->Ci);
return make_float3(0.0f, 0.0f, 0.0f);
}
示例9: eval_displacement
void OSLShader::eval_displacement(KernelGlobals *kg, ShaderData *sd, PathState *state)
{
/* setup shader globals from shader data */
OSLThreadData *tdata = kg->osl_tdata;
shaderdata_to_shaderglobals(kg, sd, state, 0, tdata);
/* execute shader */
OSL::ShadingSystem *ss = (OSL::ShadingSystem*)kg->osl_ss;
OSL::ShaderGlobals *globals = &tdata->globals;
OSL::ShadingContext *octx = tdata->context;
int shader = sd->shader & SHADER_MASK;
if(kg->osl->displacement_state[shader]) {
ss->execute(octx, *(kg->osl->displacement_state[shader]), *globals);
}
/* get back position */
sd->P = TO_FLOAT3(globals->P);
}
示例10:
ShadingContext::ShadingContext(
const Intersector& intersector,
Tracer& tracer,
TextureCache& texture_cache,
#ifdef WITH_OSL
OSL::ShadingSystem& shading_system,
#endif
ILightingEngine* lighting_engine,
const float transparency_threshold,
const size_t max_iterations)
: m_intersector(intersector)
, m_tracer(tracer)
, m_texture_cache(texture_cache)
, m_lighting_engine(lighting_engine)
, m_transparency_threshold(transparency_threshold)
, m_max_iterations(max_iterations)
#ifdef WITH_OSL
, m_osl_shading_system(shading_system)
, m_osl_thread_info(shading_system.create_thread_info())
, m_osl_shading_context(shading_system.get_context(m_osl_thread_info))
#endif
{
}
示例11: eval_surface
void OSLShader::eval_surface(KernelGlobals *kg, ShaderData *sd, float randb, int path_flag, ShaderContext ctx)
{
/* setup shader globals from shader data */
OSLThreadData *tdata = kg->osl_tdata;
shaderdata_to_shaderglobals(kg, sd, path_flag, tdata);
/* execute shader for this point */
OSL::ShadingSystem *ss = (OSL::ShadingSystem*)kg->osl_ss;
OSL::ShaderGlobals *globals = &tdata->globals;
OSL::ShadingContext *octx = tdata->context[(int)ctx];
int shader = sd->shader & SHADER_MASK;
if (kg->osl->surface_state[shader])
ss->execute(*octx, *(kg->osl->surface_state[shader]), *globals);
/* flatten closure tree */
sd->num_closure = 0;
sd->randb_closure = randb;
if (globals->Ci) {
bool no_glossy = (path_flag & PATH_RAY_DIFFUSE) && kernel_data.integrator.no_caustics;
flatten_surface_closure_tree(sd, no_glossy, globals->Ci);
}
}
示例12: add
bool ShaderConnection::add(OSL::ShadingSystem& shading_system)
{
if (!shading_system.ConnectShaders(
get_src_layer(),
get_src_param(),
get_dst_layer(),
get_dst_param()))
{
RENDERER_LOG_ERROR(
"error connecting shaders %s::%s -> %s::%s.",
get_src_layer(),
get_src_param(),
get_dst_layer(),
get_dst_param());
return false;
}
return true;
}
示例13: add
bool Shader::add(OSL::ShadingSystem& shading_system)
{
for (each<ShaderParamContainer> i = impl->m_params; i; ++i)
{
if (!i->add(shading_system))
return false;
}
// For some reason, OSL only supports the surface shader usage.
// So, we ignore the user shader type specified in the XML file,
// and hardcode "surface" here. TODO: research this...
//if (!shading_system.Shader(get_type(), get_shader(), get_layer()))
if (!shading_system.Shader("surface", get_shader(), get_layer()))
{
RENDERER_LOG_ERROR("error adding shader %s, %s.", get_shader(), get_layer());
return false;
}
return true;
}
示例14:
OSLShaderGroupExec::OSLShaderGroupExec(OSL::ShadingSystem& shading_system)
: m_osl_shading_system(shading_system)
, m_osl_thread_info(shading_system.create_thread_info())
, m_osl_shading_context(shading_system.get_context(m_osl_thread_info))
{
}
示例15: register_appleseed_closures
// We probably want to reuse OSL macros to declare closure params
// and register the closures. We can use them only inside the OSL namespace.
OSL_NAMESPACE_ENTER
void register_appleseed_closures(OSL::ShadingSystem& shading_system)
{
// Describe the memory layout of each closure type to the OSL runtime.
const size_t MaxParams = 32;
struct BuiltinClosures
{
const char* name;
int id;
ClosureParam params[MaxParams];
};
static const BuiltinClosures builtins[] =
{
{ "as_ashikhmin_shirley", AshikhminShirleyID, { CLOSURE_VECTOR_PARAM(AshikhminShirleyClosureParams, N),
CLOSURE_VECTOR_PARAM(AshikhminShirleyClosureParams, T),
CLOSURE_FLOAT_PARAM(AshikhminShirleyClosureParams, kd),
CLOSURE_COLOR_PARAM(AshikhminShirleyClosureParams, Cd),
CLOSURE_FLOAT_PARAM(AshikhminShirleyClosureParams, ks),
CLOSURE_COLOR_PARAM(AshikhminShirleyClosureParams, Cs),
CLOSURE_FLOAT_PARAM(AshikhminShirleyClosureParams, nu),
CLOSURE_FLOAT_PARAM(AshikhminShirleyClosureParams, nv),
CLOSURE_FINISH_PARAM(AshikhminShirleyClosureParams) } },
{ "as_microfacet_blinn", MicrofacetBlinnID, { CLOSURE_VECTOR_PARAM(MicrofacetBRDFClosureParams, N),
CLOSURE_FLOAT_PARAM(MicrofacetBRDFClosureParams, glossiness),
CLOSURE_FINISH_PARAM(MicrofacetBRDFClosureParams) } },
{ "as_microfacet_ward", MicrofacetWardID, { CLOSURE_VECTOR_PARAM(MicrofacetBRDFClosureParams, N),
CLOSURE_FLOAT_PARAM(MicrofacetBRDFClosureParams, glossiness),
CLOSURE_FINISH_PARAM(MicrofacetBRDFClosureParams) } },
{ "background", BackgroundID, { CLOSURE_FINISH_PARAM(EmptyClosureParams) } },
{ "debug", DebugID, { CLOSURE_STRING_PARAM(DebugClosureParams, tag),
CLOSURE_FINISH_PARAM(DebugClosureParams) } },
{ "diffuse", LambertID, { CLOSURE_VECTOR_PARAM(LambertClosureParams, N),
CLOSURE_FINISH_PARAM(LambertClosureParams) } },
{ "emission", EmissionID, { CLOSURE_FLOAT_PARAM(EmissionClosureParams, inner_angle),
CLOSURE_FLOAT_PARAM(EmissionClosureParams, outer_angle),
CLOSURE_FINISH_PARAM(EmissionClosureParams) } },
{ "holdout", HoldoutID, { CLOSURE_FINISH_PARAM(EmptyClosureParams) } },
{ "microfacet_beckmann", MicrofacetBeckmannID, { CLOSURE_VECTOR_PARAM(MicrofacetBRDFClosureParams, N),
CLOSURE_FLOAT_PARAM(MicrofacetBRDFClosureParams, glossiness),
CLOSURE_FINISH_PARAM(MicrofacetBRDFClosureParams) } },
{ "microfacet_ggx", MicrofacetGGXID, { CLOSURE_VECTOR_PARAM(MicrofacetBRDFClosureParams, N),
CLOSURE_FLOAT_PARAM(MicrofacetBRDFClosureParams, glossiness),
CLOSURE_FINISH_PARAM(MicrofacetBRDFClosureParams) } },
{ "reflection", ReflectionID, { CLOSURE_VECTOR_PARAM(ReflectionClosureParams, N),
CLOSURE_FINISH_PARAM(ReflectionClosureParams) } },
{ "refraction", RefractionID, { CLOSURE_VECTOR_PARAM(RefractionClosureParams, N),
CLOSURE_FLOAT_PARAM(RefractionClosureParams, from_ior),
CLOSURE_FLOAT_PARAM(RefractionClosureParams, to_ior),
CLOSURE_FINISH_PARAM(RefractionClosureParams) } },
{ "translucent", TranslucentID, { CLOSURE_VECTOR_PARAM(LambertClosureParams, N),
CLOSURE_FINISH_PARAM(LambertClosureParams) } },
{ "transparency", TransparentID, { CLOSURE_FINISH_PARAM(EmptyClosureParams) } },
{ 0, 0, {} } // mark end of the array
};
for (size_t i = 0; builtins[i].name != 0; ++i)
{
shading_system.register_closure(
builtins[i].name,
builtins[i].id,
builtins[i].params,
0,
0);
RENDERER_LOG_INFO("registered OSL closure %s.", builtins[i].name);
}
}