Clarisse 5.0 SP8 SDK  5.0.5.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Classes | Public Types | Static Public Member Functions | List of all members
ShaderHelpers Class Reference

Helper class for rasterization, illumination and shading and raytracing. More...

Classes

class  FilterResolveMaterialData
 

Public Types

typedef void(* LeafRayHitNearestSceneObjectCallback )(ModuleSceneObject *scene_object, const CtxEval &eval_ctx, GeometryRaytraceCtx &raytrace_ctx)
 
typedef void(* LeafRayHitNearestLightCallback )(ModuleLight *light, const CtxEval &eval_ctx, GeometryRaytraceCtx &raytrace_ctx)
 

Static Public Member Functions

static bool filter_resolve_material_callback (const CtxEval &eval_ctx, const GeometryRaytraceCtx &raytrace_ctx, const unsigned int &ray_index, GeometryIntersection &intersection, GeometryRaytraceCtx::FilterData &data)
 
static ModuleMaterialresolve_material_switch (const CtxEval &eval_ctx, GeometryIntersection &intersection)
 
static ModuleMaterialresolve_material (const CtxEval &eval_ctx, GeometryIntersection &intersection, const DefaultMaterialConfig &default_materials)
 
static void shade (const CtxEval &eval_ctx, CtxShader &shader_ctx, GMathVec3f &color, GMathVec3f &opacity, const bool &aovs_only=false, const bool &disable_clamping=false)
 Shade the current fragment set in the shader context.
 
static void shade (GMathVec3f &color, GMathVec3f &opacity, const CtxEval &eval_ctx, CtxShader &shader_ctx, const CtxRaytrace &ray_ctx, const unsigned int &path_index, const bool &disable_clamping=false)
 Shade a path of intersections and composite them.
 
static void shade_opacity (GMathVec3f &opacity, const CtxEval &eval_ctx, CtxShader &shader_ctx, const CtxRaytrace &ray_ctx, const unsigned int &path_index, const bool &shade_transparency=true)
 Compute the composited opacity of a path of intersections.
 
static bool raytrace (GMathVec3f &color, GMathVec3f &opacity, const CtxEval &eval_ctx, CtxShader &shader_ctx, const GMathRay<> &ray, const double &tnear=gmath_epsilon, const double &tfar=gmath_infinity, const bool &disable_clamping=false)
 Raytrace the current scene with full shading/illumination evaluation.
 
static bool raytrace_opacity (GMathVec3f &opacity, const CtxEval &eval_ctx, CtxShader &ctx, const GMathRay<> &ray, const double &tnear=gmath_epsilon, const double &tfar=gmath_infinity, const bool &shade_transparency=true)
 Raytrace the current scene and compute only the resulting opacity.
 
static void raytrace (GMathVec3f *colors, GMathVec3f *opacities, const CtxEval &eval_ctx, CtxShader &shader_ctx, CtxRaytrace &ray_ctx, const bool &disable_clamping=false, const bool &use_packet=true)
 Raytrace the current scene with full shading/illumination evaluation.
 
static void raytrace_opacity (GMathVec3f *opacities, const CtxEval &eval_ctx, CtxShader &shader_ctx, CtxRaytrace &ray_ctx, const bool &shade_transparency=true, const bool &use_packet=true)
 Raytrace the current scene and compute only the resulting opacities.
 
static void clip (GMathVec3d &direction, const GMathVec3d &clip_plane_normal)
 
static double reflect (const GMathVec3d &i, const GMathVec3d &n, GMathVec3d &r)
 
static double refract (const GMathVec3d &i, const GMathVec3d &n, const double &ior, GMathVec3d &t)
 
static double refract (const GMathVec3d &i, const GMathVec3d &n, const double &eta_i, const double &eta_t, GMathVec3d &t)
 
static void reflect_and_refract (const GMathVec3d &i, const GMathVec3d &n, const double &ior, GMathVec3d &r, GMathVec3d &t, double &cos_i, double &cos_t)
 
static double fresnel_dielectric (const double &cos_i, const double &cos_t, const double &eta_i, const double &eta_t)
 
static double fresnel_dielectric (const double &cos_i, const double &cos_t, const double &ior)
 
static double fresnel_dielectric (const GMathVec3d &wi, const GMathVec3d &normal, const double &ior)
 
static double fresnel_conductor (const double &cos_i, const double &eta, const double &k)
 
static float luminance (const GMathVec3f &rgb)
 
static float luminance (const GMathVec4f &rgba)
 
static double luminance (const GMathVec3d &rgb)
 
static double luminance (const GMathVec4d &rgba)
 
static double compute_reflection_ray (const CtxEval &eval_ctx, const CtxShader &ctx, GMathRay<> &r_ray)
 Compute the reflection ray using fragment information from the input CtxShader.
 
static double compute_refraction_ray (const CtxEval &eval_ctx, const CtxShader &ctx, const double &ior, GMathRay<> &t_ray)
 Compute the refraction ray using fragment information from the input CtxShader.
 
static void compute_reflection_and_refraction_rays (const CtxEval &eval_ctx, const CtxShader &ctx, const double &ior, GMathRay<> &r_ray, GMathRay<> &t_ray, double &cos_i, double &cos_t)
 Compute both reflection and refraction rays using fragment information from the input CtxShader.
 
static bool create_shader_ctx (const CtxEval &eval_ctx, CtxShader &ctx, const ModuleLayerScene &layer)
 Creates a minimal valid shader context. Once you are done using the ctx, you MUST call a cleanup_shader_ctx otherwise, you will get memory leaks. Assume the camera is of class CameraPerspective.
 
static bool create_shader_ctx (const CtxEval &eval_ctx, CtxShader &ctx, const ModuleRenderScene &render_scene)
 Creates a minimal valid shader context. Once you are done using the ctx, you MUST call a cleanup_shader_ctx otherwise, you will get memory leaks. Assume the camera is of class CameraPerspective.
 
static void cleanup_shader_ctx (CtxShader &ctx)
 Cleanup a valid shader context.
 
static bool raycast (GeometryIntersection &intersection, GMathRay<> &ray, const CtxEval &eval_ctx, CtxShader &ctx, const double &x, const double &y, const unsigned int &width, const unsigned int &height, float alpha_threshold=0, const CoreVector< ModuleSceneItem * > *items=0, bool exclude=true, bool filter_unpickable=false, bool raycast_light=false)
 Cast a ray for the specified pixel and return the intersection if any.
 
static void compute_bump_normal (GMathVec3d &normal, const CtxEval &eval_ctx, CtxShader &ctx, const ModuleTexture &texture, const bool &smoothed=true, const double &factor=1.0, const bool &use_texture_space=true)
 Compute bump normal from a texture.
 
static void compute_normal_from_map (GMathVec3d &normal, const CtxEval &eval_ctx, CtxShader &ctx, const ModuleTexture &texture, const bool &smoothed=true, const double &factor=1.0, const bool &use_tangent_space=true)
 Compute normal from a normal map texture.
 
static bool ray_hit (const CtxEval &eval_ctx, CtxShader &shader_ctx, const GMathRay<> &ray, const double &tnear=gmath_epsilon, const double &tfar=gmath_infinity)
 Cast a ray and test if it hits something.
 
static void ray_hit (const CtxEval &eval_ctx, CtxShader &shader_ctx, CtxRaytrace &ray_ctx, const bool &use_packet=true)
 Cast rays and test if they hit something.
 
static void ray_hit_nearest (const CtxEval &eval_ctx, CtxShader &shader_ctx, CtxRaytrace &ray_ctx, const bool &use_packet=true)
 Cast rays and and search for the nearest intersection.
 
static void decimate_points (OfObjectFactory &factory, CoreVector< GMathVec3d > &points, const double &decimate_value, ModuleTexture *decimate_texture=0, const unsigned int &decimate_seed=0)
 
static void merge_fragments (float &cm, float &am, const float &c1, const float &a1, const float &c2, const float &a2)
 
static void merge_fragments (GMathVec3f &cm, GMathVec3f &am, const GMathVec3f &c1, const GMathVec3f &a1, const GMathVec3f &c2, const GMathVec3f &a2)
 
static void merge_fragments (GMathVec3f &c1, GMathVec3f &a1, const GMathVec3f &c2, const GMathVec3f &a2)
 
static bool evaluate_support_material (const GeometryPointCloud &point_cloud, const ModuleMaterial &material, CoreBasicArray< GMathVec3f > &colors, CoreBasicArray< GMathVec3f > &opacities, ModuleLayer3d *layer=nullptr, AppProgressBar *progress_bar=nullptr)
 
static bool evaluate_support_texture (const GeometryPointCloud &point_cloud, const ModuleTexture &texture, CoreBasicArray< GMathVec4f > &colors, ModuleLayer3d *layer=nullptr, AppProgressBar *progress_bar=nullptr)
 
static bool evaluate_vertices_texture (ModuleGeometry &geometry, const CoreBasicArray< unsigned int > &vertex_indices, const ModuleTexture &texture, CoreBasicArray< GMathVec4f > &colors, ModuleLayer3d *layer=nullptr, AppProgressBar *progress_bar=nullptr)
 
static void gas_leaf_ray_hit_nearest (const CtxEval &eval_ctx, CtxShader &shader_ctx, GeometryRaytraceCtx &raytrace_ctx, LeafRayHitNearestSceneObjectCallback leaf_callback, const GMathMatrix4x4d &m, const GMathMatrix4x4d &inv_m, const unsigned int &leaf_index, ModuleSceneObject *leaf_module, GeometryOverride *leaf_override=0)
 
static void gas_leaf_ray_hit_nearest_motion (const CtxEval &eval_ctx, CtxShader &shader_ctx, GeometryRaytraceCtx &raytrace_ctx, LeafRayHitNearestSceneObjectCallback leaf_callback, const CoreBasicArray< GMathMatrix4x4d > &matrices, const unsigned int &leaf_index, ModuleSceneObject *leaf_module, GeometryOverride *leaf_override=0)
 
static void gas_leaf_ray_hit_nearest (const CtxEval &eval_ctx, CtxShader &shader_ctx, GeometryRaytraceCtx &raytrace_ctx, LeafRayHitNearestLightCallback leaf_callback, const GMathMatrix4x4d &m, const GMathMatrix4x4d &inv_m, const unsigned int &leaf_index, ModuleLight *leaf_module)
 
static void gas_leaf_ray_hit_nearest_motion (const CtxEval &eval_ctx, CtxShader &shader_ctx, GeometryRaytraceCtx &raytrace_ctx, LeafRayHitNearestLightCallback leaf_callback, const CoreBasicArray< GMathMatrix4x4d > &matrices, const unsigned int &leaf_index, ModuleLight *leaf_module)
 

Detailed Description

Helper class for rasterization, illumination and shading and raytracing.

Useful shading static method collection.

Member Function Documentation

void ShaderHelpers::cleanup_shader_ctx ( CtxShader ctx)
static

Cleanup a valid shader context.

Parameters
ctxshader context to cleanup
void ShaderHelpers::compute_bump_normal ( GMathVec3d &  normal,
const CtxEval eval_ctx,
CtxShader ctx,
const ModuleTexture texture,
const bool &  smoothed = true,
const double &  factor = 1.0,
const bool &  use_texture_space = true 
)
static

Compute bump normal from a texture.

Parameters
ctxvalid shader context
texturetexture that gets evaluated (3 times) at the surrounding of the wpos of the CtxShader
factorbump factor
void ShaderHelpers::compute_normal_from_map ( GMathVec3d &  normal,
const CtxEval eval_ctx,
CtxShader ctx,
const ModuleTexture texture,
const bool &  smoothed = true,
const double &  factor = 1.0,
const bool &  use_tangent_space = true 
)
static

Compute normal from a normal map texture.

Parameters
ctxvalid shader context
texturetexture that gets evaluated
factornormal map factor
void ShaderHelpers::compute_reflection_and_refraction_rays ( const CtxEval eval_ctx,
const CtxShader ctx,
const double &  ior,
GMathRay<> &  r_ray,
GMathRay<> &  t_ray,
double &  cos_i,
double &  cos_t 
)
static

Compute both reflection and refraction rays using fragment information from the input CtxShader.

Parameters
eval_ctxvalid evaluation context
ctxvalid shader context
iorindex of refraction of the surface
r_rayreflected ray
t_raytransmitted ray
cos_ithe cosine of the angle between the incident/reflected ray and the normal
cos_tthe cosine of the angle between the transmitted ray and the normal
double ShaderHelpers::compute_reflection_ray ( const CtxEval eval_ctx,
const CtxShader ctx,
GMathRay<> &  r_ray 
)
static

Compute the reflection ray using fragment information from the input CtxShader.

Parameters
eval_ctxvalid evaluation context
ctxvalid shader context
r_rayreflected ray
Returns
the cosine of the angle between the incident/reflected rays and the normal
double ShaderHelpers::compute_refraction_ray ( const CtxEval eval_ctx,
const CtxShader ctx,
const double &  ior,
GMathRay<> &  t_ray 
)
static

Compute the refraction ray using fragment information from the input CtxShader.

Parameters
eval_ctxvalid evaluation context
ctxvalid shader context
iorindex of refraction of the surface
t_raytransmitted ray
Returns
the cosine of the angle between the transmitted ray and the normal
bool ShaderHelpers::create_shader_ctx ( const CtxEval eval_ctx,
CtxShader ctx,
const ModuleLayerScene layer 
)
static

Creates a minimal valid shader context. Once you are done using the ctx, you MUST call a cleanup_shader_ctx otherwise, you will get memory leaks. Assume the camera is of class CameraPerspective.

Parameters
ctxresulting valid shader context
layer3D layer the shader context is supposed to be used for render
Returns
false if the creation failed (imcomplete layer such as no camera...)
bool ShaderHelpers::create_shader_ctx ( const CtxEval eval_ctx,
CtxShader ctx,
const ModuleRenderScene render_scene 
)
static

Creates a minimal valid shader context. Once you are done using the ctx, you MUST call a cleanup_shader_ctx otherwise, you will get memory leaks. Assume the camera is of class CameraPerspective.

Parameters
ctxresulting valid shader context
render_scenethe scene the shader context is supposed to be used for render
Returns
false if the creation failed (imcomplete scene such as no camera...)
bool ShaderHelpers::evaluate_support_material ( const GeometryPointCloud point_cloud,
const ModuleMaterial material,
CoreBasicArray< GMathVec3f > &  colors,
CoreBasicArray< GMathVec3f > &  opacities,
ModuleLayer3d layer = nullptr,
AppProgressBar progress_bar = nullptr 
)
static

Evaluate the material color for each points of the point cloud, using the point cloud support geometry.

Parameters
[in]point_cloudThe point cloud to evaluate.
[in]materialThe material to evaluate on the point cloud support primitives.
[out]colorsEvaluated material colors, one for each point.
[out]opacitiesEvaluated material opacities, one for each point.
[in]layerOptional layer, if NULL rays will be set along the surface normal and raytracing will be disabled.
[in]progress_barOptional progress bar.Created if not specified.
Returns
True on success. False if point_count has no support geometry, or if colors or opacities size don't match point count.
bool ShaderHelpers::evaluate_support_texture ( const GeometryPointCloud point_cloud,
const ModuleTexture texture,
CoreBasicArray< GMathVec4f > &  colors,
ModuleLayer3d layer = nullptr,
AppProgressBar progress_bar = nullptr 
)
static

Evaluate the texture color for each points of the point cloud, using the point cloud support geometry.

Parameters
[in]point_cloudThe point cloud to evaluate.
[in]textureThe texture to evaluate on the point cloud support primitives.
[out]colorsEvaluated texture colors, one for each point.
[in]layerOptional layer, if NULL rays will be set along the surface normal and raytracing will be disabled.
[in]progress_barOptional progress bar. Created if not specified.
Returns
True on success. False if point_count has no support geometry, or if colors size doesn't match point count.
bool ShaderHelpers::evaluate_vertices_texture ( ModuleGeometry geometry,
const CoreBasicArray< unsigned int > &  vertex_indices,
const ModuleTexture texture,
CoreBasicArray< GMathVec4f > &  colors,
ModuleLayer3d layer = nullptr,
AppProgressBar progress_bar = nullptr 
)
static

Evaluate the texture color for vertices of a geometry.

Parameters
[in]geometryThe geometry to evaluate.
[in]vertex_indicesThe indices of the vertices to evaluate.
[in]textureThe texture to evaluate on the point cloud support primitives.
[out]colorsEvaluated texture colors, one for each point.
[in]layerOptional layer, if NULL rays will be set along the surface normal and raytracing will be disabled.
[in]progress_barOptional progress bar. Created if not specified.
Returns
True on success. False if colors size doesn't match vertex count.
bool ShaderHelpers::ray_hit ( const CtxEval eval_ctx,
CtxShader shader_ctx,
const GMathRay<> &  ray,
const double &  tnear = gmath_epsilon,
const double &  tfar = gmath_infinity 
)
static

Cast a ray and test if it hits something.

Parameters
eval_ctxvalid evaluation context
shader_ctxvalid shader context
tnearnear clip value
tfarfar clip value
Returns
true if the ray hit something, else false
void ShaderHelpers::ray_hit ( const CtxEval eval_ctx,
CtxShader shader_ctx,
CtxRaytrace ray_ctx,
const bool &  use_packet = true 
)
static

Cast rays and test if they hit something.

Parameters
eval_ctxvalid evaluation context
shader_ctxvalid shader context
ray_ctxraytracing context to use
void ShaderHelpers::ray_hit_nearest ( const CtxEval eval_ctx,
CtxShader shader_ctx,
CtxRaytrace ray_ctx,
const bool &  use_packet = true 
)
static

Cast rays and and search for the nearest intersection.

Parameters
eval_ctxvalid evaluation context
shader_ctxvalid shader context
ray_ctxraytracing context to use
bool ShaderHelpers::raycast ( GeometryIntersection intersection,
GMathRay<> &  ray,
const CtxEval eval_ctx,
CtxShader shader_ctx,
const double &  x,
const double &  y,
const unsigned int &  width,
const unsigned int &  height,
float  alpha_threshold = 0,
const CoreVector< ModuleSceneItem * > *  items = 0,
bool  exclude = true,
bool  filter_unpickable = false,
bool  raycast_light = false 
)
static

Cast a ray for the specified pixel and return the intersection if any.

Parameters
intersectionresulting intersection on the hit object
rayresulting cast ray
ctxvalid shader context
xx coordinate of the pixel to raycast from (in pixel space)
yy coordinate of the pixel to raycast from (in pixel space)
widthwidth of the film plane
heightheight of the film plane
alpha_thresholdoptional value under which an object is considered transparent therefore ignored
itemsoptional array of modules to care about
excludeoptional argument to specify whether items provided are the ones to ignore or to consider
filter_unpickablecare about 'display_pickable' attribute
Returns
true if an object has been hit, else false
bool ShaderHelpers::raytrace ( GMathVec3f &  color,
GMathVec3f &  opacity,
const CtxEval eval_ctx,
CtxShader ctx,
const GMathRay<> &  ray,
const double &  tnear = gmath_epsilon,
const double &  tfar = gmath_infinity,
const bool &  disable_clamping = false 
)
static

Raytrace the current scene with full shading/illumination evaluation.

Parameters
colorresulting raytraced color (r,g,b)
opacityresulting opacity of the color
ctxvalid shader context
tnearnear clip value
tfarfar clip value
disable_clampingwhen true, the color clamping that is configured in the shader context is ignored
void ShaderHelpers::raytrace ( GMathVec3f *  colors,
GMathVec3f *  opacities,
const CtxEval eval_ctx,
CtxShader shader_ctx,
CtxRaytrace ray_ctx,
const bool &  disable_clamping = false,
const bool &  use_packet = true 
)
static

Raytrace the current scene with full shading/illumination evaluation.

Parameters
colorsresulting raytraced colors (r,g,b)
opacityresulting opacities of each color
eval_ctxvalid evaluation context
shader_ctxvalid shader context
ray_ctxraytracing context to use
disable_clampingwhen true, the color clamping that is configured in the shader context is ignored
use_packetwhen true, packet tracing is enabled
bool ShaderHelpers::raytrace_opacity ( GMathVec3f &  opacity,
const CtxEval eval_ctx,
CtxShader ctx,
const GMathRay<> &  ray,
const double &  tnear = gmath_epsilon,
const double &  tfar = gmath_infinity,
const bool &  shade_transparency = true 
)
static

Raytrace the current scene and compute only the resulting opacity.

Parameters
opacityresulting opaciy
ctxvalid shader context
tnearnear clip value
tfarfar clip value
shade_transparencywhen true, the material of objects is evaluated in order to know their opacity
void ShaderHelpers::raytrace_opacity ( GMathVec3f *  opacities,
const CtxEval eval_ctx,
CtxShader shader_ctx,
CtxRaytrace ray_ctx,
const bool &  shade_transparency = true,
const bool &  use_packet = true 
)
static

Raytrace the current scene and compute only the resulting opacities.

Parameters
opacityresulting opacities of each ray
eval_ctxvalid evaluation context
shader_ctxvalid shader context
ray_ctxraytracing context to use
sample_incincrement to apply to the sample index at each ray
shade_transparencywhen true, the material of objects is evaluated in order to know their opacity
use_packetwhen true, packet tracing is enabled
void ShaderHelpers::shade ( const CtxEval eval_ctx,
CtxShader shader_ctx,
GMathVec3f &  color,
GMathVec3f &  opacity,
const bool &  aovs_only = false,
const bool &  disable_clamping = false 
)
static

Shade the current fragment set in the shader context.

Parameters
eval_ctxa valid evaluation context
shader_ctxa valid shader context
outputmaterial evaluation output
aovs_onlywhen true, only the aovs are computed
disable_clampingwhen true, the color clamping that is configured in the shader context is ignored
void ShaderHelpers::shade ( GMathVec3f &  color,
GMathVec3f &  opacity,
const CtxEval eval_ctx,
CtxShader shader_ctx,
const CtxRaytrace ray_ctx,
const unsigned int &  path_index,
const bool &  disable_clamping = false 
)
static

Shade a path of intersections and composite them.

Parameters
colorresulting composited color (r,g,b)
opacityresulting composited opacity
eval_ctxa valid evaluation context
shader_ctxa valid shader context
ray_ctxthe raytracing context containing the path of intersection to shade
path_indexthe index of the path in the raytracing context to shade
disable_clampingwhen true, the color clamping that is configured in the shader context is ignored
void ShaderHelpers::shade_opacity ( GMathVec3f &  opacity,
const CtxEval eval_ctx,
CtxShader shader_ctx,
const CtxRaytrace ray_ctx,
const unsigned int &  path_index,
const bool &  shade_transparency = true 
)
static

Compute the composited opacity of a path of intersections.

Parameters
opacityresulting composited opacity
eval_ctxa valid evaluation context
ctxa valid shader context
datathe raytrace data containing the result of a raytracing
path_indexthe index of the path in the raytrace data to shade