5#ifndef EXAMPLES_RAY_SAMPLING_SIMPLE_SHAPES_H
6#define EXAMPLES_RAY_SAMPLING_SIMPLE_SHAPES_H
10#include <nv/index/iscene_group.h>
11#include <nv/index/icylinder.h>
12#include <nv/index/icone.h>
13#include <nv/index/isphere.h>
14#include <nv/index/iellipsoid.h>
15#include <nv/index/iplane.h>
17#include <nv/index/imaterial.h>
18#include <nv/index/ilight.h>
23"NV_IDX_XAC_VERSION_1_0 \n"
25"class Surface_sample_program \n"
27" NV_IDX_SURFACE_SAMPLE_PROGRAM \n"
32" NV_IDX_DEVICE_INLINE_MEMBER void initialize() \n"
44" NV_IDX_DEVICE_INLINE_MEMBER int execute( \n"
45" const Sample_info_self& sample_info, \n"
46" Sample_output& sample_output) \n"
48" const uint light_id = state.self.get_light_id(); \n"
49" const uint material_id = state.self.get_material_id(); \n"
51" const float3 ray_direction = normalize(sample_info.ray_direction); \n"
52" float4 color = nv::index::xaclib::phong_shading( \n"
53" state.scene, material_id, light_id, \n"
55" sample_info.sample_normal, true); \n"
58" const float screen_gamma = 0.6f; \n"
59" color = nv::index::xaclib::gamma_correct(color, screen_gamma); \n"
60" sample_output.set_color(color); \n"
61" return NV_IDX_PROG_OK; \n"
66" // The user program used for picking. \n"
67" NV_IDX_DEVICE_INLINE_MEMBER int inquire( \n"
68" const Sample_info_self& sample_info, \n"
69" Query_results& query_results) \n"
71" // sample_info.ray_t is automatically written \n"
72" // color is automatically written \n"
74" // we could invalidate current sample to skip/ignore it \n"
75" //query_results.invalidate_sample(); \n"
77" // write some attribute value of current sample \n"
79" sample_info.scene_position.x; \n"
80" query_results.write_value<float>(0u /*user_value_idx*/, v); \n"
83" if (counter & 1) { \n"
84" // write every other counter as user value \n"
85" query_results.write_value<int>(1u /*user_value_idx*/, counter); \n"
88" const float3 normal = sample_info.sample_normal; \n"
89" query_results.write_value<float3>(2u /*user_value_idx*/, normal); \n"
91" return NV_IDX_PROG_OK; \n"
93" // we can stop sampling: \n"
94" //return NV_IDX_PROG_TERMINATE_PROGRAM_INSTANCE; \n"
104 const char*
name()
const {
return "Simple Shapes"; }
108 return "0 0 0 1500 1500 1500";
113 return nv::index::app::get_bbox_from_string<mi::Float32,3>(
get_roi_string());
117 nv::index::app::IApplication_layer* app_layer,
119 const mi::math::Bbox< mi::Float32, 3>& roi_bbox,
120 const mi::neuraylib::Tag& session_tag,
121 std::map<std::string, std::string>& opt_map,
122 mi::neuraylib::IDice_transaction* dice_transaction)
const
125 mi::base::Handle<const nv::index::ISession> session(
126 dice_transaction->access<
const nv::index::ISession>(session_tag));
130 mi::base::Handle<nv::index::IScene> scene(
131 dice_transaction->edit<nv::index::IScene>(session->get_scene()));
135 const int user_prg = nv::index::app::get_sint32(opt_map[
"user_program_mode"]);
138 mi::base::Handle<nv::index::ISurface_sample_program> surface_sample_program(
139 scene->create_attribute<nv::index::ISurface_sample_program>());
143 if (program_src.empty()) {
153 surface_sample_program->set_program_source(program_src.c_str());
155 const mi::neuraylib::Tag surface_program_tag =
156 dice_transaction->store_for_reference_counting(surface_sample_program.get());
158 scene->append(surface_program_tag, dice_transaction);
164 mi::base::Handle<nv::index::IDirectional_light> light_global(
165 scene->create_attribute<nv::index::IDirectional_light>());
167 light_global->set_direction(mi::math::Vector<mi::Float32, 3>(0.5f, 0.f, 1.f));
168 const mi::neuraylib::Tag light_global_tag = dice_transaction->store_for_reference_counting(light_global.get());
170 scene->append(light_global_tag, dice_transaction);
173 mi::base::Handle<nv::index::IPhong_gl> phong_global(scene->create_attribute<nv::index::IPhong_gl>());
175 phong_global->set_ambient(mi::math::Color(0.1f, 0.15f, 0.1f, 1.0f));
176 phong_global->set_diffuse(mi::math::Color(0.95f, 0.3f, 0.3f, 1.0f));
177 phong_global->set_specular(mi::math::Color(0.4f, 0.4f, 0.5f, 1.0f));
178 phong_global->set_shininess(100);
179 const mi::neuraylib::Tag phong_global_tag = dice_transaction->store_for_reference_counting(phong_global.get());
181 scene->append(phong_global_tag, dice_transaction);
186 mi::base::Handle<nv::index::IPhong_gl> phong_0(scene->create_attribute<nv::index::IPhong_gl>());
188 phong_0->set_ambient(mi::math::Color(0.f, 0.3f, 0.0f, 1.0f));
189 phong_0->set_diffuse(mi::math::Color(0.f, 0.1f, 0.0f, 1.0f));
190 phong_0->set_specular(mi::math::Color(0.2f, 0.2f, 0.2f, 1.0f));
191 phong_0->set_shininess(10);
192 const mi::neuraylib::Tag phong_0_tag = dice_transaction->store_for_reference_counting(phong_0.get());
194 scene->append(phong_0_tag, dice_transaction);
196 mi::base::Handle<nv::index::IPlane> plane_1(scene->create_shape<nv::index::IPlane>());
198 plane_1->set_point(mi::math::Vector<mi::Float32, 3>(10.f, 10.f, 400.f));
199 plane_1->set_normal(mi::math::Vector<mi::Float32, 3>(0.f, 0.f, 1.f));
200 plane_1->set_up(mi::math::Vector<mi::Float32, 3>(0.f, 1.f, 0.f));
201 plane_1->set_extent(mi::math::Vector<mi::Float32, 2>(580.f, 300.f));
202 const mi::neuraylib::Tag plane_1_tag = dice_transaction->store_for_reference_counting(
203 plane_1.get(), mi::neuraylib:
:NULL_TAG,
"plane_1");
205 scene->append(plane_1_tag, dice_transaction);
207 mi::base::Handle<nv::index::IPhong_gl> phong_1(scene->create_attribute<nv::index::IPhong_gl>());
209 phong_1->set_ambient(mi::math::Color(0.f, 0.1f, 0.4f, 1.0f));
210 phong_1->set_diffuse(mi::math::Color(0.f, 0.3f, 0.6f, 1.0f));
211 phong_1->set_specular(mi::math::Color(0.4f, 0.4f, 0.5f, 1.0f));
212 phong_1->set_shininess(10);
213 const mi::neuraylib::Tag phong_1_tag = dice_transaction->store_for_reference_counting(phong_1.get());
215 scene->append(phong_1_tag, dice_transaction);
217 mi::base::Handle<nv::index::ISphere> sphere_1(scene->create_shape<nv::index::ISphere>());
219 sphere_1->set_center(mi::math::Vector<mi::Float32, 3>(300.f, 250.f, 500.f));
220 sphere_1->set_radius(250);
221 const mi::neuraylib::Tag sphere_1_tag = dice_transaction->store_for_reference_counting(
222 sphere_1.get(), mi::neuraylib:
:NULL_TAG,
"sphere_1");
224 scene->append(sphere_1_tag, dice_transaction);
226 mi::base::Handle<nv::index::IPhong_gl> phong_2(scene->create_attribute<nv::index::IPhong_gl>());
228 phong_2->set_ambient(mi::math::Color(0.15f, 0.1f, 0.1f, 1.0f));
229 phong_2->set_diffuse(mi::math::Color(0.75f, 0.1f, 0.1f, 1.0f));
230 phong_2->set_specular(mi::math::Color(0.5f, 0.4f, 0.4f, 1.0f));
231 phong_2->set_shininess(50);
232 const mi::neuraylib::Tag phong_2_tag = dice_transaction->store_for_reference_counting(phong_2.get());
234 scene->append(phong_2_tag, dice_transaction);
236 mi::base::Handle<nv::index::ICone> cone_1(scene->create_shape<nv::index::ICone>());
238 const mi::math::Vector<mi::Float32, 3> cone_1_center(280.f, 230.f, 100.f);
239 cone_1->set_center(cone_1_center);
240 cone_1->set_tip(cone_1_center + mi::math::Vector<mi::Float32, 3>(20.f, 80.f, 20.f));
241 cone_1->set_radius(50);
242 cone_1->set_capped(
true);
243 const mi::neuraylib::Tag cone_1_tag = dice_transaction->store_for_reference_counting(
244 cone_1.get(), mi::neuraylib:
:NULL_TAG,
"cone_1");
246 scene->append(cone_1_tag, dice_transaction);
248 mi::base::Handle<nv::index::IPhong_gl> phong_3(scene->create_attribute<nv::index::IPhong_gl>());
250 phong_3->set_ambient(mi::math::Color(0.1f, 0.15f, 0.1f, 1.0f));
251 phong_3->set_diffuse(mi::math::Color(0.5f, 0.55f, 0.5f, 1.0f));
252 phong_3->set_specular(mi::math::Color(0.4f, 0.4f, 0.5f, 1.0f));
253 phong_3->set_shininess(80);
254 const mi::neuraylib::Tag phong_3_tag = dice_transaction->store_for_reference_counting(phong_3.get());
256 scene->append(phong_3_tag, dice_transaction);
258 mi::base::Handle<nv::index::ICylinder> cylinder_1(scene->create_shape<nv::index::ICylinder>());
260 const mi::math::Vector<mi::Float32, 3> cylinder_1_bottom(280.f, 200.f, 200.f);
261 cylinder_1->set_bottom(cylinder_1_bottom);
262 cylinder_1->set_top(cylinder_1_bottom + mi::math::Vector<mi::Float32, 3>(0.f, 120.f, -60.f));
263 cylinder_1->set_radius(40);
264 cylinder_1->set_capped(
true);
265 const mi::neuraylib::Tag cylinder_1_tag = dice_transaction->store_for_reference_counting(
266 cylinder_1.get(), mi::neuraylib:
:NULL_TAG,
"cylinder_1");
268 scene->append(cylinder_1_tag, dice_transaction);
275 const mi::neuraylib::Tag& camera_tag,
276 mi::neuraylib::IDice_transaction* transaction)
const
281 mi::base::Handle<nv::index::IPerspective_camera> cam(
282 transaction->edit<nv::index::IPerspective_camera>(camera_tag));
286 const mi::math::Vector<mi::Float32, 3> from(254.f, 254.f, 550.f);
287 const mi::math::Vector<mi::Float32, 3> to (255.f, 255.f, -255.f);
288 const mi::math::Vector<mi::Float32, 3> up (0.f, 1.f, 0.f);
289 mi::math::Vector<mi::Float32, 3> viewdir = to - from;
292 cam->set(from, viewdir, up);
293 cam->set_aperture(0.033f);
294 cam->set_aspect(1.f);
295 cam->set_focal(0.03f);
296 cam->set_clip_min(1.f);
297 cam->set_clip_max(5000.f);
const char * get_roi_string() const
void setup_camera(const mi::neuraylib::Tag &camera_tag, mi::neuraylib::IDice_transaction *transaction) const
const mi::math::Bbox< mi::Float32, 3 > get_roi_box() const
const char * name() const
bool create_scene(nv::index::app::IApplication_layer *app_layer, Scene_info &scene_info, const mi::math::Bbox< mi::Float32, 3 > &roi_bbox, const mi::neuraylib::Tag &session_tag, std::map< std::string, std::string > &opt_map, mi::neuraylib::IDice_transaction *dice_transaction) const
static const char * program_end
static const char * inquire_program
static const char * color_program
static const char * program_begin
Scene setup interface for ray sampling example.
#define check_success(expr)
std::string rtc_program_source