本文整理汇总了C++中ShadingPoint::get_shading_basis方法的典型用法代码示例。如果您正苦于以下问题:C++ ShadingPoint::get_shading_basis方法的具体用法?C++ ShadingPoint::get_shading_basis怎么用?C++ ShadingPoint::get_shading_basis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShadingPoint
的用法示例。
在下文中一共展示了ShadingPoint::get_shading_basis方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
DirectLightingIntegrator::DirectLightingIntegrator(
const ShadingContext& shading_context,
const LightSampler& light_sampler,
const ShadingPoint& shading_point,
const Vector3d& outgoing,
const BSDF& bsdf,
const void* bsdf_data,
const int bsdf_sampling_modes,
const int light_sampling_modes,
const size_t bsdf_sample_count,
const size_t light_sample_count,
const bool indirect)
: m_shading_context(shading_context)
, m_light_sampler(light_sampler)
, m_shading_point(shading_point)
, m_point(shading_point.get_point())
, m_geometric_normal(shading_point.get_geometric_normal())
, m_shading_basis(shading_point.get_shading_basis())
, m_time(shading_point.get_time())
, m_outgoing(outgoing)
, m_bsdf(bsdf)
, m_bsdf_data(bsdf_data)
, m_bsdf_sampling_modes(bsdf_sampling_modes)
, m_light_sampling_modes(light_sampling_modes)
, m_bsdf_sample_count(bsdf_sample_count)
, m_light_sample_count(light_sample_count)
, m_indirect(indirect)
{
assert(is_normalized(outgoing));
}
示例2: trace_same_material
bool Intersector::trace_same_material(
const ShadingRay& ray,
const ShadingPoint& parent_shading_point,
const bool offset_origin,
ShadingPoint& shading_point) const
{
if (do_trace_same_material(ray, parent_shading_point, offset_origin, shading_point))
{
// do_trace_same_material() intersects only with triangles
// whose normal points in the same direction as the ray.
// Triangles are intersected from the inside of the object and
// shading_point.get_shading_normal() points inside the object.
// todo: we maybe need a better way to flip the shading normal here.
const Basis3d& basis = shading_point.get_shading_basis();
shading_point.set_shading_basis(
Basis3d(
-basis.get_normal(),
-basis.get_tangent_u(),
basis.get_tangent_v()));
return true;
}
return false;
}
示例3: choose_bsdf_closure_shading_basis
void OSLShaderGroupExec::choose_bsdf_closure_shading_basis(
const ShadingPoint& shading_point,
const Vector2f& s) const
{
CompositeSurfaceClosure c(
Basis3f(shading_point.get_shading_basis()),
shading_point.get_osl_shader_globals().Ci,
m_arena);
float pdfs[CompositeSurfaceClosure::MaxClosureEntries];
const size_t num_closures = c.compute_pdfs(ScatteringMode::All, pdfs);
if (num_closures == 0)
return;
const size_t index = c.choose_closure(s[1], num_closures, pdfs);
shading_point.set_shading_basis(
Basis3d(c.get_closure_shading_basis(index)));
}
示例4: execute_bump
void OSLShaderGroupExec::execute_bump(
const ShaderGroup& shader_group,
const ShadingPoint& shading_point,
const Vector2f& s) const
{
// Choose between BSSRDF and BSDF.
if (shader_group.has_subsurface() && s[0] < 0.5f)
{
do_execute(
shader_group,
shading_point,
VisibilityFlags::SubsurfaceRay);
CompositeSubsurfaceClosure c(
Basis3f(shading_point.get_shading_basis()),
shading_point.get_osl_shader_globals().Ci,
m_arena);
// Pick a shading basis from one of the BSSRDF closures.
if (c.get_closure_count() > 0)
{
const size_t index = c.choose_closure(s[1]);
shading_point.set_shading_basis(
Basis3d(c.get_closure_shading_basis(index)));
}
}
else
{
do_execute(
shader_group,
shading_point,
VisibilityFlags::CameraRay);
choose_bsdf_closure_shading_basis(shading_point, s);
}
}
示例5: 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 Vector3d& 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));
const Vector3d& geometric_normal = shading_point.get_geometric_normal();
const Basis3d& shading_basis = shading_point.get_shading_basis();
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.
Vector3d incoming;
Spectrum bsdf_value;
double bsdf_prob;
const BSDF::Mode bsdf_mode =
bsdf.sample(
sampling_context,
bsdf_data,
false, // not adjoint
true, // multiply by |cos(incoming, normal)|
geometric_normal,
shading_basis,
outgoing,
incoming,
bsdf_value,
bsdf_prob);
// Filter scattering modes.
if (!(bsdf_sampling_modes & bsdf_mode))
return;
// Discard occluded samples.
const double transmission =
shading_context.get_tracer().trace(
shading_point,
incoming,
ShadingRay::ShadowRay);
if (transmission == 0.0)
continue;
// Evaluate the environment's EDF.
InputEvaluator input_evaluator(shading_context.get_texture_cache());
Spectrum env_value;
double env_prob;
environment_edf.evaluate(
input_evaluator,
incoming,
env_value,
env_prob);
// Apply all weights, including MIS weight.
if (bsdf_mode == BSDF::Specular)
env_value *= static_cast<float>(transmission);
else
{
const double mis_weight =
mis_power2(
bsdf_sample_count * bsdf_prob,
env_sample_count * env_prob);
env_value *= static_cast<float>(transmission / bsdf_prob * mis_weight);
}
// Add the contribution of this sample to the illumination.
env_value *= bsdf_value;
radiance += env_value;
}
if (bsdf_sample_count > 1)
radiance /= static_cast<float>(bsdf_sample_count);
}
示例6: compute_ibl_environment_sampling
void compute_ibl_environment_sampling(
SamplingContext& sampling_context,
const ShadingContext& shading_context,
const EnvironmentEDF& environment_edf,
const ShadingPoint& shading_point,
const Vector3d& outgoing,
const BSDF& bsdf,
const void* bsdf_data,
const int env_sampling_modes,
const size_t bsdf_sample_count,
const size_t env_sample_count,
Spectrum& radiance)
{
assert(is_normalized(outgoing));
const Vector3d& geometric_normal = shading_point.get_geometric_normal();
const Basis3d& shading_basis = shading_point.get_shading_basis();
radiance.set(0.0f);
// todo: if we had a way to know that a BSDF is purely specular, we could
// immediately return black here since there will be no contribution from
// such a BSDF.
sampling_context.split_in_place(2, env_sample_count);
for (size_t i = 0; i < env_sample_count; ++i)
{
// Generate a uniform sample in [0,1)^2.
const Vector2d s = sampling_context.next_vector2<2>();
// Sample the environment.
InputEvaluator input_evaluator(shading_context.get_texture_cache());
Vector3d incoming;
Spectrum env_value;
double env_prob;
environment_edf.sample(
input_evaluator,
s,
incoming,
env_value,
env_prob);
// Cull samples behind the shading surface.
assert(is_normalized(incoming));
const double cos_in = dot(incoming, shading_basis.get_normal());
if (cos_in < 0.0)
continue;
// Discard occluded samples.
const double transmission =
shading_context.get_tracer().trace(
shading_point,
incoming,
ShadingRay::ShadowRay);
if (transmission == 0.0)
continue;
// Evaluate the BSDF.
Spectrum bsdf_value;
const double bsdf_prob =
bsdf.evaluate(
bsdf_data,
false, // not adjoint
true, // multiply by |cos(incoming, normal)|
geometric_normal,
shading_basis,
outgoing,
incoming,
env_sampling_modes,
bsdf_value);
if (bsdf_prob == 0.0)
continue;
// Compute MIS weight.
const double mis_weight =
mis_power2(
env_sample_count * env_prob,
bsdf_sample_count * bsdf_prob);
// Add the contribution of this sample to the illumination.
env_value *= static_cast<float>(transmission / env_prob * mis_weight);
env_value *= bsdf_value;
radiance += env_value;
}
if (env_sample_count > 1)
radiance /= static_cast<float>(env_sample_count);
}
示例7: compute_ibl_environment_sampling
void compute_ibl_environment_sampling(
SamplingContext& sampling_context,
const ShadingContext& shading_context,
const EnvironmentEDF& environment_edf,
const BSSRDF& bssrdf,
const void* bssrdf_data,
const ShadingPoint& incoming_point,
const ShadingPoint& outgoing_point,
const Dual3d& outgoing,
const size_t bssrdf_sample_count,
const size_t env_sample_count,
Spectrum& radiance)
{
assert(is_normalized(outgoing.get_value()));
const Basis3d& shading_basis = incoming_point.get_shading_basis();
radiance.set(0.0f);
sampling_context.split_in_place(2, env_sample_count);
for (size_t i = 0; i < env_sample_count; ++i)
{
// Generate a uniform sample in [0,1)^2.
const Vector2d s = sampling_context.next_vector2<2>();
// Sample the environment.
InputEvaluator input_evaluator(shading_context.get_texture_cache());
Vector3d incoming;
Spectrum env_value;
double env_prob;
environment_edf.sample(
shading_context,
input_evaluator,
s,
incoming,
env_value,
env_prob);
// Cull samples behind the shading surface.
assert(is_normalized(incoming));
const double cos_in = dot(incoming, shading_basis.get_normal());
if (cos_in <= 0.0)
continue;
// Discard occluded samples.
const double transmission =
shading_context.get_tracer().trace(
incoming_point,
incoming,
VisibilityFlags::ShadowRay);
if (transmission == 0.0)
continue;
// Evaluate the BSSRDF.
Spectrum bssrdf_value;
bssrdf.evaluate(
bssrdf_data,
outgoing_point,
outgoing.get_value(),
incoming_point,
incoming,
bssrdf_value);
// Compute MIS weight.
const double bssrdf_prob = cos_in * RcpPi;
const double mis_weight =
mis_power2(
env_sample_count * env_prob,
bssrdf_sample_count * bssrdf_prob);
// Add the contribution of this sample to the illumination.
env_value *= static_cast<float>(transmission * cos_in / env_prob * mis_weight);
env_value *= bssrdf_value;
radiance += env_value;
}
if (env_sample_count > 1)
radiance /= static_cast<float>(env_sample_count);
}
示例8: compute_ibl_bssrdf_sampling
void compute_ibl_bssrdf_sampling(
SamplingContext& sampling_context,
const ShadingContext& shading_context,
const EnvironmentEDF& environment_edf,
const BSSRDF& bssrdf,
const void* bssrdf_data,
const ShadingPoint& incoming_point,
const ShadingPoint& outgoing_point,
const Dual3d& outgoing,
const size_t bssrdf_sample_count,
const size_t env_sample_count,
Spectrum& radiance)
{
assert(is_normalized(outgoing.get_value()));
radiance.set(0.0f);
sampling_context.split_in_place(2, bssrdf_sample_count);
for (size_t i = 0; i < bssrdf_sample_count; ++i)
{
// Generate a uniform sample in [0,1)^2.
const Vector2d s = sampling_context.next_vector2<2>();
// Sample the BSSRDF (hemisphere cosine).
Vector3d incoming = sample_hemisphere_cosine(s);
const double cos_in = incoming.y;
const double bssrdf_prob = cos_in * RcpPi;
incoming = incoming_point.get_shading_basis().transform_to_parent(incoming);
if (incoming_point.get_side() == ObjectInstance::BackSide)
incoming = -incoming;
assert(is_normalized(incoming));
// Discard occluded samples.
const double transmission =
shading_context.get_tracer().trace(
incoming_point,
incoming,
VisibilityFlags::ShadowRay);
if (transmission == 0.0)
continue;
// Evaluate the BSSRDF.
Spectrum bssrdf_value;
bssrdf.evaluate(
bssrdf_data,
outgoing_point,
outgoing.get_value(),
incoming_point,
incoming,
bssrdf_value);
// Evaluate the environment's EDF.
InputEvaluator input_evaluator(shading_context.get_texture_cache());
Spectrum env_value;
double env_prob;
environment_edf.evaluate(
shading_context,
input_evaluator,
incoming,
env_value,
env_prob);
// Compute MIS weight.
const double mis_weight =
mis_power2(
bssrdf_sample_count * bssrdf_prob,
env_sample_count * env_prob);
// Add the contribution of this sample to the illumination.
env_value *= static_cast<float>(transmission * cos_in / bssrdf_prob * mis_weight);
env_value *= bssrdf_value;
radiance += env_value;
}
if (bssrdf_sample_count > 1)
radiance /= static_cast<float>(bssrdf_sample_count);
}
示例9: 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:
//.........这里部分代码省略.........
示例10: sample
size_t SubsurfaceSampler::sample(
SamplingContext& sampling_context,
const ShadingPoint& outgoing_point,
const BSSRDF& bssrdf,
const void* bssrdf_data,
SubsurfaceSample samples[],
const size_t max_sample_count)
{
assert(max_sample_count > 0);
// Sample the diffusion profile.
BSSRDFSample bssrdf_sample(sampling_context);
if (!bssrdf.sample(bssrdf_data, bssrdf_sample))
return 0;
// Reject points too far away.
// This introduces negligible bias in comparison to the other approximations.
const Vector2d& point(bssrdf_sample.get_point());
const double radius2 = square_norm(point);
const double rmax2 = bssrdf_sample.get_rmax2();
if (radius2 > rmax2)
return 0;
// Evaluate the PDF of the diffusion profile.
const double radius = sqrt(radius2);
const double bssrdf_sample_pdf =
bssrdf.evaluate_pdf(bssrdf_data, bssrdf_sample.get_channel(), radius);
// Pick a sampling basis.
sampling_context.split_in_place(1, 1);
Axis sampling_axis;
Basis3d sampling_basis;
double sampling_basis_pdf;
pick_sampling_basis(
outgoing_point.get_shading_basis(),
sampling_context.next_double2(),
sampling_axis,
sampling_basis,
sampling_basis_pdf);
// Compute height of sample point on (positive) hemisphere of radius Rmax.
assert(rmax2 >= radius2);
const double h = sqrt(rmax2 - radius2);
// Compute sphere entry and exit points.
Vector3d entry_point, exit_point;
entry_point = exit_point = outgoing_point.get_point();
entry_point += sampling_basis.transform_to_parent(Vector3d(point[0], +h, point[1]));
exit_point += sampling_basis.transform_to_parent(Vector3d(point[0], -h, point[1]));
assert(feq(norm(exit_point - entry_point), 2.0 * h, 1.0e-9));
// Build a probe ray inscribed inside the sphere of radius Rmax.
ShadingRay probe_ray(
entry_point,
-sampling_basis.get_normal(),
0.0,
2.0 * h,
outgoing_point.get_time(),
VisibilityFlags::ProbeRay,
outgoing_point.get_ray().m_depth + 1);
const Material* material = outgoing_point.get_material();
ShadingPoint shading_points[2];
size_t shading_point_index = 0;
ShadingPoint* parent_shading_point = 0;
size_t sample_count = 0;
// Trace the ray and return all intersections (or up to max_sample_count of them) found inside the sphere.
while (true)
{
// Continue tracing the ray.
shading_points[shading_point_index].clear();
if (!m_shading_context.get_intersector().trace(
probe_ray,
shading_points[shading_point_index],
parent_shading_point))
break;
// Only consider points lying on surfaces with the same material as the outgoing point.
if (shading_points[shading_point_index].get_material() == material)
{
// Execute the OSL shader if we have one. Needed for bump mapping.
#ifdef APPLESEED_WITH_OSL
if (material->has_osl_surface())
{
sampling_context.split_in_place(1, 1);
m_shading_context.execute_osl_bump(
*material->get_osl_surface(),
shading_points[shading_point_index],
sampling_context.next_double2());
}
#endif
SubsurfaceSample& sample = samples[sample_count++];
sample.m_point = shading_points[shading_point_index];
// Compute sample probability.
sample.m_probability =
bssrdf_sample_pdf
* sampling_basis_pdf
//.........这里部分代码省略.........