This example shows how a renderer can call the code generated by the "native" backend for compiled materials to evaluate sub-expressions of multiple materials on the CPU.
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include "example_shared.h"
#include "texture_support_native.h"
struct Options {
std::string outputfile;
unsigned res_x, res_y;
bool use_class_compilation;
bool use_custom_tex_runtime;
bool enable_derivatives;
std::string material_name;
Options()
: outputfile("example_native.png")
, res_x(700)
, res_y(520)
, use_class_compilation(false)
, use_custom_tex_runtime(false)
, enable_derivatives(false)
{}
};
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f
);
void create_material_instance(
const char* material_name,
const char* instance_name)
{
std::string module_name, material_simple_name;
if (!mi::examples::mdl::parse_cmd_argument_material_name(
material_name, module_name, material_simple_name, true))
exit_failure();
mdl_impexp_api->
load_module(transaction, module_name.c_str(), context);
if (!print_messages(context))
exit_failure("Loading module '%s' failed.", module_name.c_str());
if (!module)
exit_failure("Failed to access the loaded module.");
std::string material_db_name
= std::string(module_db_name->get_c_str()) + "::" + material_simple_name;
material_db_name = mi::examples::mdl::add_missing_material_signature(
module.get(), material_db_name);
if (material_db_name.empty())
exit_failure("Failed to find the material %s in the module %s.",
material_simple_name.c_str(), module_name.c_str());
if (!material_definition)
exit_failure("Accessing definition '%s' failed.", material_db_name.c_str());
material_definition->create_function_call(0, &result));
if (result != 0)
exit_failure("Instantiating '%s' failed.", material_db_name.c_str());
transaction->
store(material_instance.get(), instance_name);
}
void compile_material_instance(
const char* instance_name,
const char* compiled_material_name,
bool class_compilation)
{
context->
set_option(
"target_type", standard_material_type.get());
material_instance->create_compiled_material(flags, context));
check_success(print_messages(context));
transaction->
store(compiled_material.get(), compiled_material_name);
}
const char* compiled_material_name,
const char* path,
const char* fname,
bool use_custom_tex_runtime,
bool enable_derivatives)
{
check_success(be_native->set_option("num_texture_spaces", "1") == 0);
if (use_custom_tex_runtime)
check_success(be_native->set_option("use_builtin_resource_handler", "off") == 0);
if (enable_derivatives)
check_success(be_native->set_option("texture_runtime_with_derivs", "on") == 0);
be_native->translate_material_expression(
transaction, compiled_material.get(), path, fname, context));
check_success(print_messages(context));
check_success(code_native);
code_native->retain();
return code_native.get();
}
{
{ 0.0f, 0.0f, 1.0f },
{ 0.0f, 0.0f, 1.0f },
{ 0.0f, 0.0f, 0.0f },
0.0f,
texture_coords,
texture_tangent_u,
texture_tangent_v,
nullptr,
nullptr,
&identity[0],
&identity[0],
0,
1.0f
};
union
{
int int_val;
float float_val;
double double_val;
} execute_result = { 0 };
float rel_x = float(x) / float(width);
float rel_y = float(y) / float(height);
mdl_state.
position.x = 2.0f * rel_x - 1;
mdl_state.
position.y = 2.0f * rel_y - 1;
texture_coords[0].x = rel_x;
texture_coords[0].y = rel_y;
check_success(
code_native->
execute(0, mdl_state, tex_handler,
nullptr, &execute_result) == 0);
execute_result.float3_val.x = powf(execute_result.float3_val.x, 1.f / 2.2f);
execute_result.float3_val.y = powf(execute_result.float3_val.y, 1.f / 2.2f);
execute_result.float3_val.z = powf(execute_result.float3_val.z, 1.f / 2.2f);
data[y * width + x] = execute_result.float3_val;
}
}
canvas->retain();
return canvas.get();
}
{
float step_x = 1.f / width;
float step_y = 1.f / height;
{
{ 0.0f, 0.0f, 0.0f },
{ step_x, 0.0f, 0.0f },
{ 0.0f, step_y, 0.0f }
} };
{ 0.0f, 0.0f, 1.0f },
{ 0.0f, 0.0f, 1.0f },
{
{ 0.0f, 0.0f, 0.0f },
{ 2 * step_x, 0.0f, 0.0f },
{ 0.0f, 2 * step_y, 0.0f }
},
0.0f,
texture_coords,
texture_tangent_u,
texture_tangent_v,
nullptr,
nullptr,
&identity[0],
&identity[0],
0,
1.0f
};
union
{
int int_val;
float float_val;
double double_val;
} execute_result = { 0 };
float rel_x = x * step_x;
float rel_y = y * step_y;
mdl_state.
position.val.x = 2.0f * rel_x - 1;
mdl_state.
position.val.y = 2.0f * rel_y - 1;
texture_coords[0].val.x = rel_x;
texture_coords[0].val.y = rel_y;
check_success(code_native->
execute(
0,
nullptr,
&execute_result) == 0);
execute_result.float3_val.x = powf(execute_result.float3_val.x, 1.f / 2.2f);
execute_result.float3_val.y = powf(execute_result.float3_val.y, 1.f / 2.2f);
execute_result.float3_val.z = powf(execute_result.float3_val.z, 1.f / 2.2f);
data[y * width + x] = execute_result.float3_val;
}
}
canvas->retain();
return canvas.get();
}
bool prepare_textures(
std::vector<Texture>& textures,
{
{
char const *image_type = image->get_type(0, 0);
if (image->is_uvtile() || image->is_animated()) {
std::cerr << "The example does not support uvtile and/or animated textures!" << std::endl;
return false;
}
if (texture->get_effective_gamma(0, 0) != 1.0f) {
image_api->
convert(canvas.get(),
"Color"));
gamma_canvas->set_gamma(texture->get_effective_gamma(0, 0));
canvas = gamma_canvas;
}
else if (strcmp(image_type, "Color") != 0 && strcmp(image_type, "Float32<4>") != 0) {
canvas = image_api->
convert(canvas.get(),
"Color");
}
textures.push_back(Texture(canvas));
}
return true;
}
void usage(char const *prog_name)
{
std::cout
<< "Usage: " << prog_name << " [options] [<material_name>]\n"
<< "Options:\n"
<< " --res <x> <y> resolution (default: 700x520)\n"
<< " --cc use class compilation\n"
<< " --cr use custom texture runtime\n"
<< " -d enable use of derivatives\n"
<< " (not supported in combination with --cr by this example)\n"
<< " -o <outputfile> image file to write result to\n"
<< " (default: example_native.png)\n"
<< " -p|--mdl_path <path> mdl search path, can occur multiple times\n"
<< std::endl;
exit_failure();
}
int MAIN_UTF8(int argc, char *argv[])
{
Options options;
mi::examples::mdl::Configure_options configure_options;
configure_options.add_example_search_path = false;
for (int i = 1; i < argc; ++i) {
char const *opt = argv[i];
if (opt[0] == '-') {
if (strcmp(opt, "-o") == 0 && i < argc - 1) {
options.outputfile = argv[++i];
} else if (strcmp(opt, "--res") == 0 && i < argc - 2) {
options.res_x = std::max(atoi(argv[++i]), 1);
options.res_y = std::max(atoi(argv[++i]), 1);
} else if (strcmp(opt, "--cc") == 0) {
options.use_class_compilation = true;
} else if (strcmp(opt, "--cr") == 0) {
options.use_custom_tex_runtime = true;
} else if (strcmp(opt, "-d") == 0) {
options.enable_derivatives = true;
} else if ((strcmp(opt, "--mdl_path") == 0 || strcmp(opt, "-p") == 0)
&& i < argc - 1) {
configure_options.additional_mdl_paths.push_back(argv[++i]);
} else {
std::cout << "Unknown option: \"" << opt << "\"" << std::endl;
usage(argv[0]);
}
} else
options.material_name = opt;
}
if (options.material_name.empty()) {
configure_options.add_example_search_path = true;
options.material_name = "::nvidia::sdk_examples::tutorials::example_execution1";
}
if (!neuray.is_valid_interface())
exit_failure("Failed to load the SDK.");
if (!mi::examples::mdl::configure(neuray.get(), configure_options))
exit_failure("Failed to initialize the SDK.");
if (ret != 0)
exit_failure("Failed to initialize the SDK. Result code: %d", ret);
{
{
std::string instance_name = "material instance";
create_material_instance(
mdl_factory.get(),
transaction.get(),
mdl_impexp_api.get(),
context.get(),
options.material_name.c_str(),
instance_name.c_str());
std::string instance_compilation_name
= std::string("instance compilation of ") + instance_name;
std::string compilation_name
= std::string("compilation of ") + instance_name;
compile_material_instance(
mdl_factory.get(),
transaction.get(),
context.get(),
instance_name.c_str(),
compilation_name.c_str(),
options.use_class_compilation);
generate_native(
transaction.get(),
mdl_backend_api.get(),
context.get(),
compilation_name.c_str(),
"surface.scattering.tint",
"tint",
options.use_custom_tex_runtime,
options.enable_derivatives));
std::vector<Texture> textures;
if (options.use_custom_tex_runtime) {
check_success(prepare_textures(
textures, transaction.get(), image_api.get(), target_code.get()));
}
if (options.enable_derivatives) {
Texture_handler_deriv tex_handler;
Texture_handler_deriv *tex_handler_ptr = nullptr;
if (options.use_custom_tex_runtime) {
tex_handler.
vtable = &tex_deriv_vtable;
tex_handler.textures = textures.data();
tex_handler_ptr = &tex_handler;
}
canvas = bake_expression_native_with_derivs(
image_api.get(), target_code.get(), tex_handler_ptr,
options.res_x, options.res_y);
} else {
Texture_handler tex_handler;
Texture_handler *tex_handler_ptr = nullptr;
if (options.use_custom_tex_runtime) {
tex_handler.vtable = &tex_vtable;
tex_handler.textures = textures.data();
tex_handler_ptr = &tex_handler;
}
canvas = bake_expression_native(
image_api.get(), target_code.get(), tex_handler_ptr,
options.res_x, options.res_y);
}
}
}
if (neuray->shutdown() != 0)
exit_failure("Failed to shutdown the SDK.");
neuray = nullptr;
if (!mi::examples::mdl::unload())
exit_failure("Failed to unload the SDK.");
exit_success();
}
COMMANDLINE_TO_UTF8
Handle class template for interfaces, automatizing the lifetime control via reference counting.
Definition: handle.h:113
NxM-dimensional matrix class template of fixed dimensions.
Definition: matrix.h:367
Abstract interface for a canvas represented by a rectangular array of tiles.
Definition: icanvas.h:89
This interface represents a compiled material.
Definition: icompiled_material.h:97
This interface is used to interact with the distributed database.
Definition: idatabase.h:289
This interface represents a function definition.
Definition: ifunction_definition.h:44
This interface provides various utilities related to canvases and buffers.
Definition: iimage_api.h:72
virtual ICanvas * create_canvas(const char *pixel_type, Uint32 width, Uint32 height, Uint32 layers=1, bool is_cubemap=false, Float32 gamma=0.0f) const =0
Creates a canvas with given pixel type, resolution, and layers.
virtual ITile * convert(const ITile *tile, const char *pixel_type) const =0
Converts a tile to a different pixel type.
virtual void adjust_gamma(ITile *tile, Float32 old_gamma, Float32 new_gamma) const =0
Sets the gamma value of a tile and adjusts the pixel data accordingly.
This interface represents a pixel image file.
Definition: iimage.h:66
This interface represents a material instance.
Definition: imaterial_instance.h:34
@ CLASS_COMPILATION
Selects class compilation instead of instance compilation.
Definition: imaterial_instance.h:41
@ DEFAULT_OPTIONS
Default compilation options (e.g., instance compilation).
Definition: imaterial_instance.h:40
This interface can be used to obtain the MDL backends.
Definition: imdl_backend_api.h:56
@ MB_NATIVE
Generate native code.
Definition: imdl_backend_api.h:64
virtual IMdl_backend * get_backend(Mdl_backend_kind kind)=0
Returns an MDL backend generator.
The execution context can be used to query status information like error and warning messages concern...
Definition: imdl_execution_context.h:131
virtual Sint32 set_option(const char *name, const char *value)=0
Sets a string option.
Factory for various MDL interfaces and functions.
Definition: imdl_factory.h:53
virtual IMdl_execution_context * create_execution_context()=0
Creates an execution context.
virtual IType_factory * create_type_factory(ITransaction *transaction)=0
Returns an MDL type factory for the given transaction.
virtual const IString * get_db_module_name(const char *mdl_name)=0
Returns the DB name for the MDL name of a module (or file path for MDLE modules).
API component for MDL related import and export operations.
Definition: imdl_impexp_api.h:43
virtual Sint32 export_canvas(const char *filename, const ICanvas *canvas, const IMap *export_options=0) const =0
Exports a canvas to a file on disk.
virtual Sint32 load_module(ITransaction *transaction, const char *argument, IMdl_execution_context *context=0)=0
Loads an MDL module from disk (or a builtin module) into the database.
This interface represents an MDL module.
Definition: imodule.h:634
Represents target code of an MDL backend.
Definition: imdl_backend.h:783
Textures add image processing options to images.
Definition: itexture.h:68
A transaction provides a consistent view on the database.
Definition: itransaction.h:82
virtual const base::IInterface * access(const char *name)=0
Retrieves an element from the database.
virtual Sint32 commit()=0
Commits the transaction.
virtual Sint32 store(base::IInterface *db_element, const char *name, Uint8 privacy=LOCAL_SCOPE)=0
Stores the element db_element in the database under the name name and with the privacy level privacy.
@ SID_MATERIAL
The "::material" struct type.
Definition: itype.h:484
Interface * get() const
Access to the interface. Returns 0 for an invalid interface.
Definition: handle.h:294
unsigned int Uint32
32-bit unsigned integer.
Definition: types.h:49
Uint64 Size
Unsigned integral type that is large enough to hold the size of all types.
Definition: types.h:112
signed int Sint32
32-bit signed integer.
Definition: types.h:46
virtual Sint32 execute(Size index, const Shading_state_material &state, Texture_handler_base *tex_handler, const ITarget_argument_block *cap_args, void *result) const =0
Run this code on the native CPU with the given captured arguments block.
virtual const char * get_texture(Size index) const =0
Returns the name of a texture resource used by the target code.
tct_traits<true>::tct_derivable_float3 tct_deriv_float3
A float3 with derivatives.
Definition: target_code_types.h:132
virtual Size get_texture_count() const =0
Returns the number of texture resources used by the target code.
Storage class for a NxM-dimensional matrix class template of fixed dimensions.
Definition: matrix.h:90
Generic storage class template for math vector representations storing DIM elements of type T.
Definition: vector.h:135
The MDL material state structure inside the MDL SDK is a representation of the renderer state as defi...
Definition: target_code_types.h:210
traits::tct_derivable_float3 position
The result of state::position().
Definition: target_code_types.h:225
The texture handler structure that is passed to the texturing functions.
Definition: target_code_types.h:712
The texture handler structure that is passed to the texturing functions with derivative support.
Definition: target_code_types.h:721
Texture_handler_deriv_vtable const * vtable
In vtable-mode, the vtable field is used to call the texturing functions.
Definition: target_code_types.h:724
#ifndef TEXTURE_SUPPORT_H
#define TEXTURE_SUPPORT_H
#include "example_shared.h"
#define USE_SMOOTHERSTEP_FILTER
struct Texture
{
: canvas(c)
, ncomp(4)
{
check_success(strcmp(canvas->get_type(), "Color") == 0);
size.x = canvas->get_resolution_x();
size.y = canvas->get_resolution_y();
size.z = canvas->get_layers_size();
data =
static_cast<const mi::Float32*
> (tile->get_data());
}
};
struct Texture_handler : Texture_handler_base {
size_t num_textures;
Texture const *textures;
};
struct Texture_handler_deriv : Texture_handler_deriv_base {
size_t num_textures;
Texture const *textures;
};
{
res[0] = v.x;
res[1] = v.y;
res[2] = v.z;
res[3] = v.w;
}
static inline void store_result4(float res[4], const float v)
{
res[0] = res[1] = res[2] = res[3] = v;
}
static inline void store_result4(
float res[4], const float v0, const float v1, const float v2, const float v3)
{
res[0] = v0;
res[1] = v1;
res[2] = v2;
res[3] = v3;
}
{
res[0] = v.x;
res[1] = v.y;
res[2] = v.z;
}
static inline void store_result3(float res[3], const float v)
{
res[0] = res[1] = res[2] = v;
}
static inline void store_result3(float res[3], const float v0, const float v1, const float v2)
{
res[0] = v0;
res[1] = v1;
res[2] = v2;
}
}
}
}
}
{
texi = (int) std::min(std::max(texil, 0ll), (texsizel - 1ll));
else {
const bool alternate = (a != 0);
if (alternate)
texi = -texi;
if (s != a)
}
}
else texi = (int) texil;
texi += crop_offset;
}
void tex_lookup2D(
Texture const &tex,
{
f2u_rz(u2f_rn(tex.size.x-1) * crop_u[0]),
f2u_rz(u2f_rn(tex.size.y-1) * crop_v[0]));
std::max(f2u_rz(u2f_rn(tex.size.x) * crop_w), 1u),
std::max(f2u_rz(u2f_rn(tex.size.y) * crop_h), 1u));
const float U = uv[0] * crop_texres.x - 0.5f;
const float V = uv[1] * crop_texres.y - 0.5f;
const mi::Uint32 U0 = texremap(crop_texres.x, wrap_u, crop_offset[0], U);
const mi::Uint32 U1 = texremap(crop_texres.x, wrap_u, crop_offset[0], U+1.0f);
const mi::Uint32 V0 = texremap(crop_texres.y, wrap_v, crop_offset[1], V);
const mi::Uint32 V1 = texremap(crop_texres.y, wrap_v, crop_offset[1], V+1.0f);
const mi::Uint32 i00 = (tex.size.x * V0 + U0) * tex.ncomp;
const mi::Uint32 i01 = (tex.size.x * V0 + U1) * tex.ncomp;
const mi::Uint32 i10 = (tex.size.x * V1 + U0) * tex.ncomp;
const mi::Uint32 i11 = (tex.size.x * V1 + U1) * tex.ncomp;
#ifdef USE_SMOOTHERSTEP_FILTER
ufrac *= ufrac*ufrac*(ufrac*(ufrac*6.0f - 15.0f) + 10.0f);
vfrac *= vfrac*vfrac*(vfrac*(vfrac*6.0f - 15.0f) + 10.0f);
#endif
mi::Float32_4(tex.data[i00 + 0], tex.data[i00 + 1], tex.data[i00 + 2], tex.data[i00 + 3]),
mi::Float32_4(tex.data[i01 + 0], tex.data[i01 + 1], tex.data[i01 + 2], tex.data[i01 + 3]),
ufrac);
mi::Float32_4(tex.data[i10 + 0], tex.data[i10 + 1], tex.data[i10 + 2], tex.data[i10 + 3]),
mi::Float32_4(tex.data[i11 + 0], tex.data[i11 + 1], tex.data[i11 + 2], tex.data[i11 + 3]),
ufrac);
}
void tex_lookup_float4_2d(
{
Texture_handler const *self = static_cast<Texture_handler const *>(self_base);
if (texture_idx == 0 || texture_idx - 1 >= self->num_textures) {
store_result4(result, 0.0f);
return;
}
Texture const &tex = self->textures[texture_idx - 1];
tex_lookup2D(result, tex, coord, wrap_u, wrap_v, crop_u, crop_v, frame);
}
void tex_lookup_deriv_float4_2d(
{
Texture_handler const *self = static_cast<Texture_handler const *>(self_base);
if (texture_idx == 0 || texture_idx - 1 >= self->num_textures) {
store_result4(result, 0.0f);
return;
}
Texture const &tex = self->textures[texture_idx - 1];
tex_lookup2D(result, tex, uv, wrap_u, wrap_v, crop_u, crop_v, frame);
}
void tex_lookup_float3_2d(
{
Texture_handler const *self = static_cast<Texture_handler const *>(self_base);
if (texture_idx == 0 || texture_idx - 1 >= self->num_textures) {
store_result3(result, 0.0f);
return;
}
tex_lookup_float4_2d(c, self, texture_idx, coord, wrap_u, wrap_v, crop_u, crop_v, frame);
result[0] = c[0];
result[1] = c[1];
result[2] = c[2];
}
void tex_lookup_deriv_float3_2d(
{
Texture_handler const *self = static_cast<Texture_handler const *>(self_base);
if (texture_idx == 0 || texture_idx - 1 >= self->num_textures) {
store_result3(result, 0.0f);
return;
}
tex_lookup_float4_2d(c, self, texture_idx, uv, wrap_u, wrap_v, crop_u, crop_v, frame);
result[0] = c[0];
result[1] = c[1];
result[2] = c[2];
}
void tex_texel_float4_2d(
float frame)
{
Texture_handler const *self = static_cast<Texture_handler const *>(self_base);
if (texture_idx == 0 || texture_idx - 1 >= self->num_textures) {
store_result3(result, 0.0f);
return;
}
Texture const &tex = self->textures[texture_idx - 1];
const mi::Uint32 idx = (tex.size.x * coord[1] + coord[0]) * tex.ncomp;
store_result4(result,
mi::Float32_4(tex.data[idx + 0], tex.data[idx + 1], tex.data[idx + 2], tex.data[idx + 3]));
}
void tex_lookup_float4_3d(
{
result[0] = 0.0f;
result[1] = 0.0f;
result[2] = 0.0f;
result[3] = 1.0f;
}
void tex_lookup_float3_3d(
{
result[0] = 0.0f;
result[1] = 0.0f;
result[2] = 0.0f;
}
void tex_texel_float4_3d(
float frame)
{
result[0] = 0.0f;
result[1] = 0.0f;
result[2] = 0.0f;
result[3] = 1.0f;
}
void tex_lookup_float4_cube(
{
result[0] = 0.0f;
result[1] = 0.0f;
result[2] = 0.0f;
result[3] = 1.0f;
}
void tex_lookup_float3_cube(
{
result[0] = 0.0f;
result[1] = 0.0f;
result[2] = 0.0f;
}
void tex_resolution_2d(
float frame)
{
Texture_handler const *self = static_cast<Texture_handler const *>(self_base);
if (texture_idx == 0 || texture_idx - 1 >= self->num_textures) {
result[0] = 0;
result[1] = 0;
return;
}
Texture const &tex = self->textures[texture_idx - 1];
result[0] = tex.size.x;
result[1] = tex.size.y;
}
void tex_resolution_3d(
float frame)
{
result[0] = 0;
result[1] = 0;
result[2] = 0;
}
bool tex_texture_isvalid(
{
Texture_handler const *self = static_cast<Texture_handler const *>(self_base);
return texture_idx != 0 && texture_idx - 1 < self->num_textures;
}
void tex_frame(
{
result[0] = 0;
result[1] = 0;
}
const Texture_handler_base *self,
{
return 0.0f;
}
const Texture_handler_base *self,
{
return 0.0f;
}
bool df_light_profile_isvalid(
const Texture_handler_base *self,
{
return false;
}
const Texture_handler_base *self,
const float theta_phi[2])
{
return 0.0f;
}
void df_light_profile_sample(
const Texture_handler_base *self,
const float xi[3])
{
result[0] = 0.0f;
result[1] = 0.0f;
result[2] = 0.0f;
}
const Texture_handler_base *self,
const float theta_phi[2])
{
return 0.0f;
}
bool df_bsdf_measurement_isvalid(
const Texture_handler_base *self,
{
return false;
}
void df_bsdf_measurement_resolution(
const Texture_handler_base *self,
{
result[0] = 0;
result[1] = 0;
result[2] = 0;
}
void df_bsdf_measurement_evaluate(
const Texture_handler_base *self,
{
result[0] = 0.0f;
result[1] = 0.0f;
result[2] = 0.0f;
}
void df_bsdf_measurement_sample(
const Texture_handler_base *self,
{
result[0] = 0.0f;
result[1] = 0.0f;
result[2] = 0.0f;
}
const Texture_handler_base *self,
{
return 0.0f;
}
void df_bsdf_measurement_albedos(
const Texture_handler_base *self,
{
result[0] = 0.0f;
result[1] = 0.0f;
result[2] = 0.0f;
result[3] = 0.0f;
}
#ifndef TEX_SUPPORT_NO_DUMMY_ADAPTNORMAL
void adapt_normal(
float result[3],
Texture_handler_base const *self_base,
float const normal[3])
{
result[0] = normal[0];
result[1] = normal[1];
result[2] = normal[2];
}
#endif
#ifndef TEX_SUPPORT_NO_DUMMY_SCENEDATA
bool scene_data_isvalid(
Texture_handler_base const *self_base,
unsigned scene_data_id)
{
return false;
}
void scene_data_lookup_float4(
float result[4],
Texture_handler_base const *self_base,
unsigned scene_data_id,
float const default_value[4],
bool uniform_lookup)
{
result[0] = default_value[0];
result[1] = default_value[1];
result[2] = default_value[2];
result[3] = default_value[3];
}
void scene_data_lookup_float3(
float result[3],
Texture_handler_base const *self_base,
unsigned scene_data_id,
float const default_value[3],
bool uniform_lookup)
{
result[0] = default_value[0];
result[1] = default_value[1];
result[2] = default_value[2];
}
void scene_data_lookup_color(
float result[3],
Texture_handler_base const *self_base,
unsigned scene_data_id,
float const default_value[3],
bool uniform_lookup)
{
result[0] = default_value[0];
result[1] = default_value[1];
result[2] = default_value[2];
}
void scene_data_lookup_float2(
float result[2],
Texture_handler_base const *self_base,
unsigned scene_data_id,
float const default_value[2],
bool uniform_lookup)
{
result[0] = default_value[0];
result[1] = default_value[1];
}
float scene_data_lookup_float(
Texture_handler_base const *self_base,
unsigned scene_data_id,
float const default_value,
bool uniform_lookup)
{
return default_value;
}
void scene_data_lookup_int4(
int result[4],
Texture_handler_base const *self_base,
unsigned scene_data_id,
int const default_value[4],
bool uniform_lookup)
{
result[0] = default_value[0];
result[1] = default_value[1];
result[2] = default_value[2];
result[3] = default_value[3];
}
void scene_data_lookup_int3(
int result[3],
Texture_handler_base const *self_base,
unsigned scene_data_id,
int const default_value[3],
bool uniform_lookup)
{
result[0] = default_value[0];
result[1] = default_value[1];
result[2] = default_value[2];
}
void scene_data_lookup_int2(
int result[2],
Texture_handler_base const *self_base,
unsigned scene_data_id,
int const default_value[2],
bool uniform_lookup)
{
result[0] = default_value[0];
result[1] = default_value[1];
}
int scene_data_lookup_int(
Texture_handler_base const *self_base,
unsigned scene_data_id,
int default_value,
bool uniform_lookup)
{
return default_value;
}
void scene_data_lookup_float4x4(
float result[16],
Texture_handler_base const *self_base,
unsigned scene_data_id,
float const default_value[16],
bool uniform_lookup)
{
for (int i = 0; i < 16; ++i)
result[i] = default_value[i];
}
void scene_data_lookup_deriv_float4(
Texture_handler_base const *self_base,
unsigned scene_data_id,
bool uniform_lookup)
{
*result = *default_value;
}
void scene_data_lookup_deriv_float3(
Texture_handler_base const *self_base,
unsigned scene_data_id,
bool uniform_lookup)
{
*result = *default_value;
}
void scene_data_lookup_deriv_color(
Texture_handler_base const *self_base,
unsigned scene_data_id,
bool uniform_lookup)
{
*result = *default_value;
}
void scene_data_lookup_deriv_float2(
Texture_handler_base const *self_base,
unsigned scene_data_id,
bool uniform_lookup)
{
*result = *default_value;
}
void scene_data_lookup_deriv_float(
Texture_handler_base const *self_base,
unsigned scene_data_id,
bool uniform_lookup)
{
*result = *default_value;
}
#endif
tex_lookup_float4_2d,
tex_lookup_float3_2d,
tex_texel_float4_2d,
tex_lookup_float4_3d,
tex_lookup_float3_3d,
tex_texel_float4_3d,
tex_lookup_float4_cube,
tex_lookup_float3_cube,
tex_resolution_2d,
tex_resolution_3d,
tex_texture_isvalid,
tex_frame,
df_light_profile_power,
df_light_profile_maximum,
df_light_profile_isvalid,
df_light_profile_evaluate,
df_light_profile_sample,
df_light_profile_pdf,
df_bsdf_measurement_isvalid,
df_bsdf_measurement_resolution,
df_bsdf_measurement_evaluate,
df_bsdf_measurement_sample,
df_bsdf_measurement_pdf,
df_bsdf_measurement_albedos,
adapt_normal,
scene_data_isvalid,
scene_data_lookup_float,
scene_data_lookup_float2,
scene_data_lookup_float3,
scene_data_lookup_float4,
scene_data_lookup_int,
scene_data_lookup_int2,
scene_data_lookup_int3,
scene_data_lookup_int4,
scene_data_lookup_color,
scene_data_lookup_float4x4,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr
};
tex_lookup_deriv_float4_2d,
tex_lookup_deriv_float3_2d,
tex_texel_float4_2d,
tex_lookup_float4_3d,
tex_lookup_float3_3d,
tex_texel_float4_3d,
tex_lookup_float4_cube,
tex_lookup_float3_cube,
tex_resolution_2d,
tex_resolution_3d,
tex_texture_isvalid,
tex_frame,
df_light_profile_power,
df_light_profile_maximum,
df_light_profile_isvalid,
df_light_profile_evaluate,
df_light_profile_sample,
df_light_profile_pdf,
df_bsdf_measurement_isvalid,
df_bsdf_measurement_resolution,
df_bsdf_measurement_evaluate,
df_bsdf_measurement_sample,
df_bsdf_measurement_pdf,
df_bsdf_measurement_albedos,
adapt_normal,
scene_data_isvalid,
scene_data_lookup_float,
scene_data_lookup_float2,
scene_data_lookup_float3,
scene_data_lookup_float4,
scene_data_lookup_int,
scene_data_lookup_int2,
scene_data_lookup_int3,
scene_data_lookup_int4,
scene_data_lookup_color,
scene_data_lookup_float4x4,
scene_data_lookup_deriv_float,
scene_data_lookup_deriv_float2,
scene_data_lookup_deriv_float3,
scene_data_lookup_deriv_float4,
scene_data_lookup_deriv_color,
};
#endif
Fixed-size math vector class template with generic operations.
Definition: vector.h:286
long long Sint64
64-bit signed integer.
Definition: types.h:61
unsigned long long Uint64
64-bit unsigned integer.
Definition: types.h:62
float Float32
32-bit float.
Definition: types.h:51
bool sign_bit(Sint8 s)
Returns true if s<0 and false if s>= 0.
Definition: function.h:790
Bbox<T, DIM> lerp(const Bbox<T, DIM> &bbox1, const Bbox<T, DIM> &bbox2, T t)
Returns the linear interpolation between bbox1 and bbox2, i.e., it returns (1-t) * bbox1 + t * bbox2.
Definition: bbox.h:672
Color floor(const Color &c)
Returns a color with the elementwise largest integral value that is not greater than the element in c...
Definition: color.h:603
tct_traits<true>::tct_derivable_float2 tct_deriv_float2
A float2 with derivatives.
Definition: target_code_types.h:129
Mbsdf_part
MBSDFs can consist of two parts, which can be selected using this enumeration.
Definition: target_code_types.h:328
tct_deriv< float[4]> tct_deriv_arr_float_4
A float[4] with derivatives (needed to avoid problems with wrong alignment).
Definition: target_code_types.h:144
tct_traits<true>::tct_derivable_float tct_deriv_float
A float with derivatives.
Definition: target_code_types.h:126
Tex_wrap_mode
The texture wrap modes as defined by tex::wrap_mode in the MDL specification.
Definition: target_code_types.h:309
struct Shading_state_material_impl<true> Shading_state_material_with_derivs
The MDL material state structure with derivatives for the texture coordinates.
Definition: target_code_types.h:303
tct_deriv< float[2]> tct_deriv_arr_float_2
A float[2] with derivatives (needed to avoid problems with wrong alignment).
Definition: target_code_types.h:138
tct_deriv< float[3]> tct_deriv_arr_float_3
A float[3] with derivatives (needed to avoid problems with wrong alignment).
Definition: target_code_types.h:141
@ TEX_WRAP_CLIP
tex::wrap_clip: makes the texture lookup return zero for texture coordinates outside of the range
Definition: target_code_types.h:323
@ TEX_WRAP_MIRRORED_REPEAT
tex::wrap_mirrored_repeat: like wrap_repeat but takes one minus the fractional part every other inter...
Definition: target_code_types.h:319
@ TEX_WRAP_CLAMP
tex::wrap_clamp: clamps the lookup coordinate to the range
Definition: target_code_types.h:311
The runtime for bitmap texture access for the generated target code can optionally be implemented in ...
Definition: target_code_types.h:344
A template struct with derivatives.
Definition: target_code_types.h:97