本文整理汇总了C++中ShadingContext类的典型用法代码示例。如果您正苦于以下问题:C++ ShadingContext类的具体用法?C++ ShadingContext怎么用?C++ ShadingContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ShadingContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: osl_regex_impl
OSL_SHADEOP int
osl_regex_impl (void *sg_, const char *subject_, void *results, int nresults,
const char *pattern, int fullmatch)
{
ShaderGlobals *sg = (ShaderGlobals *)sg_;
ShadingContext *ctx = sg->context;
const std::string &subject (ustring::from_unique(subject_).string());
match_results<std::string::const_iterator> mresults;
const regex ®ex (ctx->find_regex (USTR(pattern)));
if (nresults > 0) {
std::string::const_iterator start = subject.begin();
int res = fullmatch ? regex_match (subject, mresults, regex)
: regex_search (subject, mresults, regex);
int *m = (int *)results;
for (int r = 0; r < nresults; ++r) {
if (r/2 < (int)mresults.size()) {
if ((r & 1) == 0)
m[r] = mresults[r/2].first - start;
else
m[r] = mresults[r/2].second - start;
} else {
m[r] = USTR(pattern).length();
}
}
return res;
} else {
return fullmatch ? regex_match (subject, regex)
: regex_search (subject, regex);
}
}
示例2: texturesys
bool
RendererServices::environment (ustring filename, TextureHandle *texture_handle,
TexturePerthread *texture_thread_info,
TextureOpt &options, ShaderGlobals *sg,
const Vec3 &R, const Vec3 &dRdx, const Vec3 &dRdy,
int nchannels, float *result,
float *dresultds, float *dresultdt)
{
ShadingContext *context = sg->context;
if (! texture_thread_info)
texture_thread_info = context->texture_thread_info();
bool status;
if (texture_handle)
status = texturesys()->environment (texture_handle, texture_thread_info,
options, R, dRdx, dRdy,
nchannels, result, dresultds, dresultdt);
else
status = texturesys()->environment (filename, options, R, dRdx, dRdy,
nchannels, result, dresultds, dresultdt);
if (!status) {
std::string err = texturesys()->geterror();
if (err.size() && sg) {
sg->context->error ("[RendererServices::environment] %s", err);
}
}
return status;
}
示例3: osl_luminance_dfdv
OSL_SHADEOP void osl_luminance_dfdv (void *sg, void *out, void *c)
{
ShadingContext *ctx = (ShadingContext *)((ShaderGlobals *)sg)->context;
((float *)out)[0] = ctx->shadingsys().luminance (((const Color3 *)c)[0]);
((float *)out)[1] = ctx->shadingsys().luminance (((const Color3 *)c)[1]);
((float *)out)[2] = ctx->shadingsys().luminance (((const Color3 *)c)[2]);
}
示例4: evaluate_inputs
void DisneyLayeredBRDF::evaluate_inputs(
const ShadingContext& shading_context,
InputEvaluator& input_evaluator,
const ShadingPoint& shading_point,
const size_t offset) const
{
char* ptr = reinterpret_cast<char*>(input_evaluator.data());
DisneyBRDFInputValues* values = reinterpret_cast<DisneyBRDFInputValues*>(ptr + offset);
memset(values, 0, sizeof(DisneyBRDFInputValues));
Color3d base_color(0.0);
for (size_t i = 0, e = m_parent->get_layer_count(); i < e; ++i)
{
const DisneyMaterialLayer& layer =
m_parent->get_layer(i, shading_context.get_thread_index());
layer.evaluate_expressions(
shading_point,
shading_context.get_oiio_texture_system(),
base_color,
*values);
}
// Colors in SeExpr are always in the sRGB color space.
base_color = srgb_to_linear_rgb(base_color);
values->m_base_color = Color3f(base_color);
values->precompute_tint_color();
}
示例5: osl_prepend_color_from
OSL_SHADEOP void
osl_prepend_color_from (void *sg, void *c_, const char *from)
{
ShadingContext *ctx (((ShaderGlobals *)sg)->context);
Color3 &c (*(Color3*)c_);
c = ctx->shadingsys().to_rgb (USTR(from), c[0], c[1], c[2]);
}
示例6: osl_wavelength_color_vf
OSL_SHADEOP void osl_wavelength_color_vf (void *sg, void *out, float lambda)
{
ShadingContext *ctx = (ShadingContext *)((ShaderGlobals *)sg)->context;
Color3 rgb = ctx->shadingsys().XYZ_to_RGB (wavelength_color_XYZ (lambda));
// constrain_rgb (rgb);
rgb *= 1.0/2.52; // Empirical scale from lg to make all comps <= 1
// norm_rgb (rgb);
clamp_zero (rgb);
*(Color3 *)out = rgb;
}
示例7: shade_environment
void ShadingEngine::shade_environment(
SamplingContext& sampling_context,
const ShadingContext& shading_context,
const ShadingPoint& shading_point,
ShadingResult& shading_result) const
{
// Retrieve the environment shader of the scene.
const EnvironmentShader* environment_shader =
shading_point.get_scene().get_environment()->get_environment_shader();
if (environment_shader)
{
// There is an environment shader: execute it.
InputEvaluator input_evaluator(shading_context.get_texture_cache());
const ShadingRay& ray = shading_point.get_ray();
const Vector3d direction = normalize(ray.m_dir);
environment_shader->evaluate(
input_evaluator,
direction,
shading_result);
// Set environment shader AOV.
shading_result.set_entity_aov(*environment_shader);
}
else
{
// No environment shader: shade as transparent black.
shading_result.set_main_to_transparent_black_linear_rgba();
shading_result.set_aovs_to_transparent_black_linear_rgba();
}
}
示例8: do_compute_lighting
void do_compute_lighting(
SamplingContext& sampling_context,
const ShadingContext& shading_context,
const ShadingPoint& shading_point,
Spectrum& radiance, // output radiance, in W.sr^-1.m^-2
SpectrumStack& aovs)
{
PathVisitor path_visitor(
m_params,
m_light_sampler,
sampling_context,
shading_context,
shading_point.get_scene(),
radiance,
aovs);
PathTracer<PathVisitor, false> path_tracer( // false = not adjoint
path_visitor,
m_params.m_rr_min_path_length,
m_params.m_max_path_length,
shading_context.get_max_iterations());
const size_t path_length =
path_tracer.trace(
sampling_context,
shading_context,
shading_point);
// Update statistics.
++m_path_count;
m_path_length.insert(path_length);
}
示例9: compute_emitted_radiance
void PathVertex::compute_emitted_radiance(
const ShadingContext& shading_context,
TextureCache& texture_cache,
Spectrum& radiance) const
{
assert(m_edf);
// No radiance if we're too close to the light.
if (m_shading_point->get_distance() < m_edf->get_light_near_start())
{
radiance.set(0.0f);
return;
}
if (const ShaderGroup* sg = get_material()->get_render_data().m_shader_group)
shading_context.execute_osl_emission(*sg, *m_shading_point);
// Evaluate the EDF inputs.
InputEvaluator input_evaluator(texture_cache);
m_edf->evaluate_inputs(input_evaluator, *m_shading_point);
// Compute the emitted radiance.
m_edf->evaluate(
input_evaluator.data(),
Vector3f(m_shading_point->get_geometric_normal()),
Basis3f(m_shading_point->get_shading_basis()),
Vector3f(m_outgoing.get_value()),
radiance);
}
示例10: ShadingContext
ShadingContext *ShadingApi
::context(Gotham::AttributeMap &attr,
const boost::shared_ptr<MaterialList> &materials,
const boost::shared_ptr<TextureList> &textures)
{
ShadingContext *result = 0;
result = new ShadingContext();
// give the materials to the ShadingContext
result->setMaterials(materials);
// give the textures to the ShadingContext
result->setTextures(textures);
return result;
} // end context()
示例11: evaluate_osl_background
void evaluate_osl_background(
const ShadingContext& shading_context,
const Vector3f& local_outgoing,
Spectrum& value) const
{
if (m_shader_group)
shading_context.execute_osl_background(*m_shader_group, local_outgoing, value);
else value.set(0.0f);
}
示例12: add_back_lighting
void add_back_lighting(
const InputValues& values,
SamplingContext& sampling_context,
const PixelContext& pixel_context,
const ShadingContext& shading_context,
const ShadingPoint& shading_point,
Spectrum& radiance,
SpectrumStack& aovs) const
{
const Vector3d& p = shading_point.get_point();
const Vector3d& n = shading_point.get_original_shading_normal();
const Vector3d& d = shading_point.get_ray().m_dir;
// Construct a ray perpendicular to the other side of the surface.
ShadingRay back_ray(shading_point.get_ray());
back_ray.m_tmax *= norm(d);
back_ray.m_dir = dot(d, n) > 0.0 ? -n : n;
back_ray.m_org = p - back_ray.m_tmax * back_ray.m_dir;
ShadingPoint back_shading_point(shading_point);
back_shading_point.set_ray(back_ray);
Spectrum back_radiance(0.0f);
SpectrumStack back_aovs(aovs.size(), 0.0f);
// Compute back lighting.
for (size_t i = 0; i < m_back_lighting_samples; ++i)
{
shading_context.get_lighting_engine()->compute_lighting(
sampling_context,
pixel_context,
shading_context,
back_shading_point,
back_radiance,
back_aovs);
}
// Apply translucency factor.
back_radiance *= values.m_translucency;
back_aovs *= values.m_translucency;
// Divide by the number of samples.
const float rcp_sample_count = 1.0f / static_cast<float>(m_back_lighting_samples);
back_radiance *= rcp_sample_count;
back_aovs *= rcp_sample_count;
// Add back lighting contribution.
radiance += back_radiance;
aovs += back_aovs;
}
示例13: apply_aerial_perspective
void apply_aerial_perspective(
const InputValues& values,
const ShadingContext& shading_context,
const PixelContext& pixel_context,
const ShadingPoint& shading_point,
ShadingResult& shading_result) const
{
Spectrum sky_color;
if (m_aerial_persp_mode == AerialPerspSkyColor)
sky_color = values.m_aerial_persp_sky_color;
else
{
// Retrieve the environment shader of the scene.
const Scene& scene = shading_point.get_scene();
const EnvironmentShader* environment_shader =
scene.get_environment()->get_environment_shader();
if (environment_shader)
{
// Execute the environment shader to obtain the sky color in the direction of the ray.
InputEvaluator input_evaluator(shading_context.get_texture_cache());
const ShadingRay& ray = shading_point.get_ray();
const Vector3d direction = normalize(ray.m_dir);
ShadingResult sky;
environment_shader->evaluate(
shading_context,
pixel_context,
input_evaluator,
direction,
sky);
sky_color = sky.m_main.m_color;
}
else sky_color.set(0.0f);
}
// Compute the blend factor.
const double d = shading_point.get_distance() * m_aerial_persp_rcp_distance;
const double k = m_aerial_persp_intensity * exp(d);
const double blend = min(k, 1.0);
// Blend the shading result and the sky color.
sky_color *= static_cast<float>(blend);
shading_result.m_main.m_color *= static_cast<float>(1.0 - blend);
shading_result.m_main.m_color += sky_color;
}
示例14: compute_ibl_bsdf_sampling
void compute_ibl_bsdf_sampling(
SamplingContext& sampling_context,
const ShadingContext& shading_context,
const EnvironmentEDF& environment_edf,
const ShadingPoint& shading_point,
const Dual3d& outgoing,
const BSDF& bsdf,
const void* bsdf_data,
const int bsdf_sampling_modes,
const size_t bsdf_sample_count,
const size_t env_sample_count,
Spectrum& radiance)
{
assert(is_normalized(outgoing.get_value()));
radiance.set(0.0f);
for (size_t i = 0; i < bsdf_sample_count; ++i)
{
// Sample the BSDF.
// todo: rendering will be incorrect if the BSDF value returned by the sample() method
// includes the contribution of a specular component since these are explicitly rejected
// afterward. We need a mechanism to indicate that we want the contribution of some of
// the components only.
BSDFSample sample(shading_point, outgoing);
bsdf.sample(
sampling_context,
bsdf_data,
false, // not adjoint
true, // multiply by |cos(incoming, normal)|
sample);
// Filter scattering modes.
if (!(bsdf_sampling_modes & sample.m_mode))
continue;
// Discard occluded samples.
const float transmission =
shading_context.get_tracer().trace(
shading_point,
Vector3d(sample.m_incoming.get_value()),
VisibilityFlags::ShadowRay);
if (transmission == 0.0f)
continue;
// Evaluate the environment's EDF.
InputEvaluator input_evaluator(shading_context.get_texture_cache());
Spectrum env_value;
float env_prob;
environment_edf.evaluate(
shading_context,
input_evaluator,
sample.m_incoming.get_value(),
env_value,
env_prob);
// Apply all weights, including MIS weight.
if (sample.m_mode == ScatteringMode::Specular)
env_value *= transmission;
else
{
const float mis_weight =
mis_power2(
bsdf_sample_count * sample.m_probability,
env_sample_count * env_prob);
env_value *= transmission / sample.m_probability * mis_weight;
}
// Add the contribution of this sample to the illumination.
env_value *= sample.m_value;
radiance += env_value;
}
if (bsdf_sample_count > 1)
radiance /= static_cast<float>(bsdf_sample_count);
}
示例15: evaluate
void DiagnosticSurfaceShader::evaluate(
SamplingContext& sampling_context,
const PixelContext& pixel_context,
const ShadingContext& shading_context,
const ShadingPoint& shading_point,
ShadingResult& shading_result) const
{
switch (m_shading_mode)
{
case Color:
{
shading_result.set_main_to_opaque_pink_linear_rgba();
const Material* material = shading_point.get_material();
if (material)
{
const Material::RenderData& material_data = material->get_render_data();
#ifdef APPLESEED_WITH_OSL
// Execute the OSL shader if there is one.
if (material_data.m_shader_group)
{
shading_context.execute_osl_shading(
*material_data.m_shader_group,
shading_point);
}
#endif
if (material_data.m_bsdf)
{
InputEvaluator input_evaluator(shading_context.get_texture_cache());
material_data.m_bsdf->evaluate_inputs(
shading_context,
input_evaluator,
shading_point);
const Vector3d direction = -normalize(shading_point.get_ray().m_dir);
material_data.m_bsdf->evaluate(
input_evaluator.data(),
false,
false,
shading_point.get_geometric_normal(),
shading_point.get_shading_basis(),
direction,
direction,
ScatteringMode::All,
shading_result.m_main.m_color);
shading_result.m_color_space = ColorSpaceSpectral;
}
}
}
break;
case Coverage:
shading_result.set_main_to_linear_rgb(Color3f(1.0f));
break;
case Barycentric:
shading_result.set_main_to_linear_rgb(
vector2_to_color(shading_point.get_bary()));
break;
case UV:
shading_result.set_main_to_linear_rgb(
uvs_to_color(shading_point.get_uv(0)));
break;
case Tangent:
case Bitangent:
case ShadingNormal:
{
#ifdef APPLESEED_WITH_OSL
const Material* material = shading_point.get_material();
if (material)
{
const Material::RenderData& material_data = material->get_render_data();
// Execute the OSL shader if there is one.
if (material_data.m_shader_group)
{
sampling_context.split_in_place(2, 1);
shading_context.execute_osl_bump(
*material_data.m_shader_group,
shading_point,
sampling_context.next_vector2<2>());
}
}
#endif
const Vector3d v =
m_shading_mode == ShadingNormal ? shading_point.get_shading_basis().get_normal() :
m_shading_mode == Tangent ? shading_point.get_shading_basis().get_tangent_u() :
shading_point.get_shading_basis().get_tangent_v();
shading_result.set_main_to_linear_rgb(vector3_to_color(v));
}
break;
case GeometricNormal:
//.........这里部分代码省略.........