BRL-CAD
sh_osl.cpp
Go to the documentation of this file.
1 
2 /* S H _ O S L . C
3  * BRL-CAD
4  *
5  * Copyright (c) 2004-2014 United States Government as represented by
6  * the U.S. Army Research Laboratory.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this file; see the file named COPYING for more
19  * information.
20  */
21 /** @file liboptical/sh_osl.c
22  *
23  * This shader is an interface for OSL shading system. More information
24  * when more features are implemented.
25  *
26  */
27 
28 #include "common.h"
29 
30 #include <stdlib.h>
31 #include <stddef.h>
32 #include <stdio.h>
33 #include <math.h>
34 #include <string.h>
35 
36 #include "./liboslrend.h"
37 
38 #include "vmath.h"
39 #include "raytrace.h"
40 #include "optical.h"
41 #include "light.h"
42 
43 #define OSL_MAGIC 0x1837 /* make this a unique number for each shader */
44 #define CK_OSL_SP(_p) BU_CKMAG(_p, OSL_MAGIC, "osl_specific")
45 
46 /* Oslrenderer system */
47 OSLRenderer *oslr = NULL;
48 
49 /* Every time a thread reaches osl_render for the first time,
50  we save the address of their own buffers, which is an ugly way to
51  identify them */
52 std::vector<struct resource *> visited_addrs;
53 /* Holds information about the context necessary to correctly execute a
54  shader */
55 std::vector<void *> thread_infos;
56 
57 /* Save default a_hit */
58 int (*default_a_hit)(struct application *, struct partition *, struct seg *);
59 /* Save default a_miss */
60 int (*default_a_miss)(struct application *);
61 
62 /*
63  * The shader specific structure contains all variables which are unique
64  * to any particular use of the shader.
65  */
66 struct osl_specific {
67  uint32_t magic; /* magic # for memory validity check */
68  ShadingAttribStateRef shader_ref; /* Reference to this shader in OSLRender system */
69 };
70 
71 /* The default values for the variables in the shader specific structure */
72 static const
73 struct osl_specific osl_defaults = {
74  OSL_MAGIC,
75 };
76 
77 #define SHDR_NULL ((struct osl_specific *)0)
78 #define SHDR_O(m) bu_offsetof(struct osl_specific, m)
79 
80 /* description of how to parse/print the arguments to the shader */
82  {"", 0, (char *)0, 0, BU_STRUCTPARSE_FUNC_NULL, NULL, NULL }
83 };
84 
85 extern "C" {
86 
87  HIDDEN int osl_setup(register struct region *rp, struct bu_vls *matparm,
88  void **dpp, const struct mfuncs *mfp,
89  struct rt_i *rtip);
90 
91  HIDDEN int osl_render(struct application *ap, const struct partition *pp,
92  struct shadework *swp, void *dp);
93  HIDDEN void osl_print(register struct region *rp, void *dp);
94  HIDDEN void osl_free(void *cp);
95 
96 }
97 
98 /* The "mfuncs" structure defines the external interface to the shader.
99  * Note that more than one shader "name" can be associated with a given
100  * shader by defining more than one mfuncs struct in this array.
101  * See sh_phong.c for an example of building more than one shader "name"
102  * from a set of source functions. There you will find that "glass" "mirror"
103  * and "plastic" are all names for the same shader with different default
104  * values for the parameters.
105  */
106 struct mfuncs osl_mfuncs[] = {
107  {MF_MAGIC, "osl", 0, MFI_NORMAL|MFI_HIT|MFI_UV, 0, osl_setup, osl_render, osl_print, osl_free },
108  {0, (char *)0, 0, 0, 0, 0, 0, 0, 0 }
109 };
110 
111 int
112 osl_parse_edge(char *edge, ShaderEdge &sh_edge)
113 {
114  /* Split string around # */
115  const char *item;
116 
117  ShaderParam sh_param1, sh_param2;
118 
119  /* Name of the first shader */
120  if ((item = strtok(edge, "#")) == NULL) {
121  fprintf(stderr, "[Error] Expecting the first shader name, found NULL.\n");
122  return -1;
123  }
124  sh_param1.layername = item;
125 
126  /* Parameter of the first shader */
127  if ((item = strtok(NULL, "#")) == NULL) {
128  fprintf(stderr, "[Error] Expecting the parameter of the first shader, found NULL.\n");
129  return -1;
130  }
131  sh_param1.paramname = item;
132 
133  /* Name of the first shader */
134  if ((item = strtok(NULL, "#")) == NULL) {
135  fprintf(stderr, "[Error] Expecting the second shader name, found NULL.\n");
136  return -1;
137  }
138  sh_param2.layername = item;
139 
140  /* Name of the first shader */
141  if ((item = strtok(NULL, "#")) == NULL) {
142  fprintf(stderr, "[Error] Expecting the parameter of the second shader, found NULL.\n");
143  return -1;
144  }
145  sh_param2.paramname = item;
146 
147  sh_edge = std::make_pair(sh_param1, sh_param2);
148 }
149 
150 int
151 osl_parse_shader(char *shadername, ShaderInfo &sh_info)
152 {
153 
154  /* Split string around # */
155  const char *item;
156  item = strtok(shadername, "#");
157  /* We are going to look for shader in ../shaders/ */
158  sh_info.shadername = "../shaders/" + std::string(item);
159 
160  /* Check for parameters */
161  while ((item = strtok(NULL, "#")) != NULL) {
162 
163  /* Setting layer name, in case we're doing a shader group */
164  if (BU_STR_EQUAL(item, "layername")) {
165 
166  /* Get the name of the layer being set */
167  item = strtok(NULL, "#");
168  if (item == NULL) {
169  fprintf(stderr, "[Error] Missing layer name\n");
170  return -1;
171  }
172  sh_info.layername = std::string(item);
173  }
174  else {
175  /* Name of the parameter */
176  std::string param_name = item;
177 
178  /* Get the type of parameter being set */
179  item = strtok(NULL, "#");
180  if (item == NULL) {
181  fprintf(stderr, "[Error] Missing parameter type\n");
182  return -1;
183  }
184  else if (BU_STR_EQUAL(item, "int")) {
185  item = strtok(NULL, "#");
186  if (item == NULL) {
187  fprintf(stderr, "[Error] Missing float value\n");
188  return -1;
189  }
190  int value = atoi(item);
191  sh_info.iparam.push_back(std::make_pair(param_name, value));
192  }
193  else if (BU_STR_EQUAL(item, "float")) {
194  item = strtok(NULL, "#");
195  if (item == NULL) {
196  fprintf(stderr, "[Error] Missing float value\n");
197  return -1;
198  }
199  float value = atof(item);
200  sh_info.fparam.push_back(std::make_pair(param_name, value));
201  }
202  else if (BU_STR_EQUAL(item, "color")) {
203  Color3 color_value;
204  for (int i=0; i<3; i++) {
205  item = strtok(NULL, "#");
206  if (item == NULL) {
207  fprintf(stderr, "[Error] Missing %d-th component of color value\n", i);
208  return -1;
209  }
210  color_value[i] = atof(item);
211  }
212  sh_info.cparam.push_back(std::make_pair(param_name, color_value));
213  }
214  else if (BU_STR_EQUAL(item, "normal") || BU_STR_EQUAL(item, "point") || BU_STR_EQUAL(item, "vector")) {
215 
216  TypeDesc type;
217  std::string type_name(item);
218  if (BU_STR_EQUAL(item, "normal")) type = TypeDesc::TypeNormal;
219  else if (BU_STR_EQUAL(item, "point")) type = TypeDesc::TypePoint;
220  else if (BU_STR_EQUAL(item, "vector")) type = TypeDesc::TypeVector;
221 
222  Vec3 vec_value;
223  for (int i=0; i<3; i++) {
224  item = strtok(NULL, "#");
225  if (item == NULL) {
226  fprintf(stderr, "[Error] Missing %d-th component of %s value\n", i, type_name.c_str());
227  return -1;
228  }
229  vec_value[i] = atof(item);
230  }
231  ShaderInfo::TypeVec type_vec(type, vec_value);
232  sh_info.vparam.push_back(std::make_pair(param_name, type_vec));
233  }
234  else if (BU_STR_EQUAL(item, "matrix")) {
235  fprintf(stderr, "matrix\n");
236  Matrix44 mat_value;
237  for (int i=0; i<4; i++)
238  for (int j=0; j<4; j++) {
239  item = strtok(NULL, "#");
240  if (item == NULL) {
241  fprintf(stderr, "[Error] Missing %d-th component of matrix value\n", i*4 + j);
242  return -1;
243  }
244  mat_value[i][j] = atof(item);
245  fprintf(stderr, "%.2lf ", mat_value[i][j]);
246  }
247  fprintf(stderr, "\n");
248  sh_info.mparam.push_back(std::make_pair(param_name, mat_value));
249  }
250  else if (BU_STR_EQUAL(item, "string")) {
251  item = strtok(NULL, "#");
252  if (item == NULL) {
253  fprintf(stderr, "[Error] Missing string\n");
254  return -1;
255  }
256  std::string string_value = item;
257  sh_info.sparam.push_back(std::make_pair(param_name, string_value));
258  }
259  else {
260  /* FIXME: add support to TypePoint, TypeVector, TypeNormal parameters */
261  fprintf(stderr, "[Error] Unknown parameter type\n");
262  return -1;
263  }
264  }
265  }
266 }
267 
268 /**
269  * This function parses the input shaders
270  * Example:
271  * shadername=color#Cin#point#0.0#0.0#1.0
272  * shadername=glass
273  * shadername=checker#K#float#4.0
274  * join=color#Cout#shader#Cin1
275  * join=glass#Cout#shader#Cin1
276  **/
277 int
278 osl_parse(const struct bu_vls *in_vls, ShaderGroupInfo &group_info)
279 {
280  struct bu_vls vls = BU_VLS_INIT_ZERO;
281  register char *cp;
282  char *name;
283  char *value;
284  int retval;
285 
286  BU_CK_VLS(in_vls);
287 
288  /* Duplicate the input string. This algorithm is destructive. */
289  bu_vls_vlscat(&vls, in_vls);
290  cp = bu_vls_addr(&vls);
291 
292  while (*cp) {
293  /* NAME = VALUE white-space-separator */
294 
295  /* skip any leading whitespace */
296  while (*cp != '\0' && isspace(*cp))
297  cp++;
298 
299  /* Find equal sign */
300  name = cp;
301  while (*cp != '\0' && *cp != '=')
302  cp++;
303 
304  if (*cp == '\0') {
305  if (name == cp) break;
306 
307  /* end of string in middle of arg */
308  bu_log("bu_structparse: input keyword '%s' is not followed by '=' in '%s'\nInput must be in keyword=value format.\n",
309  name, bu_vls_addr(in_vls));
310  bu_vls_free(&vls);
311  return -2;
312  }
313 
314  *cp++ = '\0';
315 
316  /* Find end of value. */
317  if (*cp == '"') {
318  /* strings are double-quote (") delimited skip leading " &
319  * find terminating " while skipping escaped quotes (\")
320  */
321  for (value = ++cp; *cp != '\0'; ++cp)
322  if (*cp == '"' &&
323  (cp == value || *(cp-1) != '\\'))
324  break;
325 
326  if (*cp != '"') {
327  bu_log("bu_structparse: keyword '%s'=\" without closing \"\n",
328  name);
329  bu_vls_free(&vls);
330  return -3;
331  }
332  } else {
333  /* non-strings are white-space delimited */
334  value = cp;
335  while (*cp != '\0' && !isspace(*cp))
336  cp++;
337  }
338 
339  if (*cp != '\0')
340  *cp++ = '\0';
341 
342  if (BU_STR_EQUAL(name, "shadername")) {
343  ShaderInfo sh_info;
344  osl_parse_shader(value, sh_info);
345  group_info.shader_layers.push_back(sh_info);
346  }
347  else if (BU_STR_EQUAL(name, "join")) {
348  ShaderEdge sh_edge;
349  osl_parse_edge(value, sh_edge);
350  group_info.shader_edges.push_back(sh_edge);
351  }
352  }
353  bu_vls_free(&vls);
354  return 0;
355 }
356 
357 /*
358  * This routine is called (at prep time)
359  * once for each region which uses this shader.
360  * Any shader-specific initialization should be done here.
361  *
362  * Returns:
363  * 1 success
364  * 0 success, but delete region
365  * -1 failure
366  */
367 
368 extern "C" {
369 
370 HIDDEN int osl_setup(register struct region *rp, struct bu_vls *matparm,
371  void **dpp, const struct mfuncs *mfp,
372  struct rt_i *rtip)
373 {
374  register struct osl_specific *osl_sp;
375 
376  /* check the arguments */
377  RT_CHECK_RTI(rtip);
378  BU_CK_VLS(matparm);
379  RT_CK_REGION(rp);
380 
381  if (rdebug&RDEBUG_SHADE)
382  bu_log("osl_setup(%s)\n", rp->reg_name);
383 
384  /* Get memory for the shader parameters and shader-specific data */
385  BU_GET(osl_sp, struct osl_specific);
386  *dpp = (char *)osl_sp;
387 
388  /* -----------------------------------
389  * Initialize the osl specific values
390  * -----------------------------------
391  */
392 
393  osl_sp->magic = OSL_MAGIC;
394 
395  /* Parse the user's arguments to fill osl specifics */
396  ShaderGroupInfo group_info;
397  if (osl_parse(matparm, group_info) < 0) {
398  return -1;
399  }
400 
401  /* -----------------------------------
402  * Initialize osl render system
403  * -----------------------------------
404  */
405  /* If OSL system was not initialized yet, do it */
406  if (oslr == NULL) {
407  oslr = new OSLRenderer();
408  }
409  /* Add this shader to OSL system */
410  osl_sp->shader_ref = oslr->AddShader(group_info);
411 
412  if (rdebug&RDEBUG_SHADE) {
413  bu_struct_print(" Parameters:", osl_print_tab, (char *)osl_sp);
414  }
415 
416  return 1;
417 }
418 
419 HIDDEN void osl_print(register struct region *rp, void *dp)
420 {
421  bu_struct_print(rp->reg_name, osl_print_tab, (char *)dp);
422 }
423 
424 
425 HIDDEN void osl_free(void *cp)
426 {
427  register struct osl_specific *osl_sp =
428  (struct osl_specific *)cp;
429  BU_PUT(cp, struct osl_specific);
430 }
431 
432 /*
433  * Callback function to be called whenever a refraction ray hits an object
434  */
435 int
436 osl_refraction_hit(struct application *ap, struct partition *PartHeadp, struct seg *finished_segs)
437 {
438 
439  /* iterating over partitions, this will keep track of the current
440  * partition we're working on.
441  */
442  struct partition *pp;
443 
444  /* will serve as a pointer for the entry and exit hitpoints */
445  struct hit *hitp;
446 
447  /* will serve as a pointer to the solid primitive we hit */
448  struct soltab *stp;
449 
450  /* will contain surface curvature information at the entry */
451  struct curvature cur;
452 
453  /* will contain our hit point coordinate */
454  point_t pt;
455 
456  /* will contain normal vector where ray enters geometry */
457  vect_t inormal;
458 
459  /* will contain normal vector where ray exits geometry */
460  vect_t onormal;
461 
462  struct shadework sw;
463 
464  /* iterate over each partition until we get back to the head.
465  * each partition corresponds to a specific homogeneous region of
466  * material.
467  */
468  for (pp=PartHeadp->pt_forw; pp != PartHeadp; pp = pp->pt_forw) {
469 
470  register const struct mfuncs *mfp;
471  register const struct region *rp;
472 
473  memset((char *)&sw, 0, sizeof(sw));
474  sw.sw_transmit = sw.sw_reflect = 0.0;
475  sw.sw_refrac_index = 1.0;
476  sw.sw_extinction = 0;
477  sw.sw_xmitonly = 0; /* want full data */
478  sw.sw_inputs = 0; /* no fields filled yet */
479  sw.sw_segs = finished_segs;
480  VSETALL(sw.sw_color, 1);
481  VSETALL(sw.sw_basecolor, 1);
482 
483  rp = pp->pt_regionp;
484  mfp = (struct mfuncs *)pp->pt_regionp->reg_mfuncs;
485 
486  /* Determine the hit point */
487  sw.sw_hit = *(pp->pt_outhit); /* struct copy */
488  VJOIN1(sw.sw_hit.hit_point, ap->a_ray.r_pt, sw.sw_hit.hit_dist, ap->a_ray.r_dir);
489 
490  /* Determine the normal point */
491  stp = pp->pt_outseg->seg_stp;
492  RT_HIT_NORMAL(sw.sw_hit.hit_normal, &(sw.sw_hit), stp, &(ap->a_ray), pp->pt_outflip);
493 
494  /* Invoke the actual shader (may be a tree of them) */
495  if (mfp && mfp->mf_render)
496  (void)mfp->mf_render(ap, pp, &sw, rp->reg_udata);
497 
498  VMOVE(ap->a_color, sw.sw_color);
499  }
500  return 1;
501 }
502 
503 
504 /*
505  * This is called (from viewshade() in shade.c) once for each hit point
506  * to be shaded. The purpose here is to fill in values in the shadework
507  * structure.
508  */
509 HIDDEN int osl_render(struct application *ap, const struct partition *pp,
510  struct shadework *swp, void *dp)
511 /* defined in ../h/shadework.h */
512 /* ptr to the shader-specific struct */
513 {
514  register struct osl_specific *osl_sp =
515  (struct osl_specific *)dp;
516 
517  void * thread_info;
518 
519  int nsamples; /* Number of samples */
520 
521  /* check the validity of the arguments we got */
522  RT_AP_CHECK(ap);
523  RT_CHECK_PT(pp);
524  CK_OSL_SP(osl_sp);
525 
526  if (rdebug&RDEBUG_SHADE)
527  bu_struct_print("osl_render Parameters:", osl_print_tab,
528  (char *)osl_sp);
529 
531 
532  /* Check if it is the first time this thread is calling this function */
533  bool visited = false;
534  for (size_t i = 0; i < visited_addrs.size(); i++) {
535  if (ap->a_resource == visited_addrs[i]) {
536  visited = true;
537  thread_info = thread_infos[i];
538  break;
539  }
540  }
541  if (!visited) {
542  visited_addrs.push_back(ap->a_resource);
543  /* Get thread specific information from OSLRender system */
544  thread_info = oslr->CreateThreadInfo();
545  thread_infos.push_back(thread_info);
546  }
547 
548  if (ap->a_level == 0) {
549  default_a_hit = ap->a_hit; /* save the default hit callback (colorview @ rt) */
550  default_a_miss = ap->a_miss;
551  }
553 
554  Color3 acc_color(0.0f);
555 
556  /* -----------------------------------
557  * Fill in all necessary information for the OSL renderer
558  * -----------------------------------
559  */
560  RenderInfo info;
561  /* Set hit point */
562  VMOVE(info.P, swp->sw_hit.hit_point);
563 
564  /* Set normal at the point */
565  VMOVE(info.N, swp->sw_hit.hit_normal);
566 
567  /* Set incidence ray direction */
568  VMOVE(info.I, ap->a_ray.r_dir);
569 
570  /* U-V mapping stuff */
571  info.u = swp->sw_uv.uv_u;
572  info.v = swp->sw_uv.uv_v;
573  VSETALL(info.dPdu, 0.0f);
574  VSETALL(info.dPdv, 0.0f);
575 
576  /* x and y pixel coordinates */
577  info.screen_x = ap->a_x;
578  info.screen_y = ap->a_y;
579 
580  info.depth = ap->a_level;
581  info.surfacearea = 1.0f;
582 
583  info.shader_ref = osl_sp->shader_ref;
584 
585  /* We assume that the only information that will be written is thread_info,
586  so that oslr->QueryColor is thread safe */
587  info.thread_info = thread_info;
588 
589 
590 // Ray-tracing (local illumination)
591 
592  /* We only perform reflection if application decides to */
593  info.doreflection = 0;
594  info.out_ray_type = 0;
595 
596  Color3 weight = oslr->QueryColor(&info);
597 
598  /* Fire another ray */
599  if ((info.out_ray_type & RAY_REFLECT) || (info.out_ray_type & RAY_TRANSMIT)) {
600 
601  struct application new_ap;
602  RT_APPLICATION_INIT(&new_ap);
603 
604  new_ap = *ap; /* struct copy */
605  new_ap.a_onehit = 1;
606  new_ap.a_hit = default_a_hit;
607  new_ap.a_level = info.depth + 1;
608  new_ap.a_flag = 0;
609 
610  VMOVE(new_ap.a_ray.r_dir, info.out_ray.dir);
611  VMOVE(new_ap.a_ray.r_pt, info.out_ray.origin);
612 
613  /* This next ray represents refraction */
614  if (info.out_ray_type & RAY_TRANSMIT) {
615 
616  /* Displace the hit point a little bit in the direction
617  of the next ray */
618  Vec3 tmp;
619  VSCALE(tmp, info.out_ray.dir, 1e-4);
620  VADD2(new_ap.a_ray.r_pt, new_ap.a_ray.r_pt, tmp);
621 
622  new_ap.a_onehit = 1;
623  new_ap.a_refrac_index = 1.5;
624  new_ap.a_flag = 2; /* mark as refraction */
625  new_ap.a_hit = osl_refraction_hit;
626  }
627 
628  (void)rt_shootray(&new_ap);
629 
630  Color3 rec;
631  VMOVE(rec, new_ap.a_color);
632 
633  Color3 res = rec*weight;
634 
635  VMOVE(swp->sw_color, res);
636  }
637  else {
638  /* Final color */
639  VMOVE(swp->sw_color, weight);
640  }
641 
642  return 1;
643 }
644 }
645 
646 /*
647  * Local Variables:
648  * mode: C++
649  * tab-width: 8
650  * indent-tabs-mode: t
651  * c-file-style: "stroustrup"
652  * End:
653  * ex: shiftwidth=4 tabstop=8
654  */
HIDDEN int osl_render(struct application *ap, const struct partition *pp, struct shadework *swp, void *dp)
Definition: sh_osl.cpp:509
struct xray a_ray
Actual ray to be shot.
Definition: raytrace.h:1583
OSLRenderer * oslr
Definition: sh_osl.cpp:47
point_t dir
Definition: liboslrend.h:47
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
struct region * pt_regionp
ptr to containing region
Definition: raytrace.h:580
struct hit * pt_outhit
OUT hit ptr.
Definition: raytrace.h:579
#define MF_MAGIC
Definition: magic.h:205
void * thread_info
Definition: liboslrend.h:62
struct soltab * seg_stp
pointer back to soltab
Definition: raytrace.h:372
Definition: clone.c:90
int a_flag
application-specific flag
Definition: raytrace.h:1626
#define VSETALL(a, s)
Definition: color.c:54
std::string paramname
Definition: liboslrend.h:106
void bu_semaphore_acquire(unsigned int i)
Definition: semaphore.c:180
Definition: raytrace.h:368
Definition: raytrace.h:248
std::vector< std::pair< std::string, TypeVec > > vparam
Definition: liboslrend.h:99
ShadingAttribStateRef shader_ref
Definition: sh_osl.cpp:68
Header file for the BRL-CAD common definitions.
std::string layername
Definition: liboslrend.h:95
std::pair< TypeDesc, Vec3 > TypeVec
Definition: liboslrend.h:92
struct seg * pt_outseg
OUT seg pointer.
Definition: raytrace.h:578
const char * reg_name
Identifying string.
Definition: raytrace.h:539
fastf_t surfacearea
Definition: liboslrend.h:71
struct resource * a_resource
dynamic memory resources
Definition: raytrace.h:1591
char pt_outflip
flip outhit->hit_normal
Definition: raytrace.h:582
int a_onehit
flag to stop on first hit
Definition: raytrace.h:1586
#define RT_CK_REGION(_p)
Definition: raytrace.h:559
int(* a_hit)(struct application *, struct partition *, struct seg *)
called when shot hits model
Definition: raytrace.h:1584
int(* default_a_miss)(struct application *)
Definition: sh_osl.cpp:60
#define HIDDEN
Definition: common.h:86
std::vector< std::pair< std::string, Matrix44 > > mparam
Definition: liboslrend.h:101
Color3 QueryColor(RenderInfo *info) const
Definition: liboslrend.cpp:97
int out_ray_type
Definition: liboslrend.h:79
HIDDEN void osl_print(register struct region *rp, void *dp)
Definition: sh_osl.cpp:419
void bu_struct_print(const char *title, const struct bu_structparse *parsetab, const char *base)
Definition: parse.c:1221
point_t N
Definition: liboslrend.h:66
ShadingAttribStateRef AddShader(ShaderGroupInfo &group_info)
Definition: liboslrend.cpp:47
#define RT_AP_CHECK(_ap)
Definition: raytrace.h:1685
fastf_t screen_x
Definition: liboslrend.h:63
void bu_vls_free(struct bu_vls *vp)
Definition: vls.c:248
fastf_t a_color[3]
application-specific color
Definition: raytrace.h:1620
std::vector< ShaderEdge > shader_edges
Definition: liboslrend.h:114
int osl_parse_edge(char *edge, ShaderEdge &sh_edge)
Definition: sh_osl.cpp:112
point_t P
Definition: liboslrend.h:65
#define BU_CK_VLS(_vp)
Definition: vls.h:69
void * memset(void *s, int c, size_t n)
void * CreateThreadInfo()
Definition: liboslrend.cpp:162
ShadingAttribStateRef shader_ref
Definition: liboslrend.h:72
#define RT_CHECK_RTI(_p)
Definition: raytrace.h:1832
std::vector< ShaderInfo > shader_layers
Definition: liboslrend.h:113
int osl_parse_shader(char *shadername, ShaderInfo &sh_info)
Definition: sh_osl.cpp:151
int a_x
Screen X of ray, if applicable.
Definition: raytrace.h:1596
char * strtok(char *s, const char *delim)
#define BU_GET(_ptr, _type)
Definition: malloc.h:201
std::vector< std::pair< std::string, float > > fparam
Definition: liboslrend.h:97
int osl_refraction_hit(struct application *ap, struct partition *PartHeadp, struct seg *finished_segs)
Definition: sh_osl.cpp:436
std::vector< struct resource * > visited_addrs
Definition: sh_osl.cpp:52
int a_level
recursion level (for printing)
Definition: raytrace.h:1595
#define BU_PUT(_ptr, _type)
Definition: malloc.h:215
point_t I
Definition: liboslrend.h:67
struct bu_structparse osl_print_tab[]
Definition: sh_osl.cpp:81
char * bu_vls_addr(const struct bu_vls *vp)
Definition: vls.c:111
std::pair< ShaderParam, ShaderParam > ShaderEdge
Definition: liboslrend.h:109
std::string shadername
Definition: liboslrend.h:94
#define BU_STRUCTPARSE_FUNC_NULL
Definition: parse.h:153
void bu_semaphore_release(unsigned int i)
Definition: semaphore.c:218
vect_t r_dir
Direction of ray (UNIT Length)
Definition: raytrace.h:219
fastf_t u
Definition: liboslrend.h:68
fastf_t v
Definition: liboslrend.h:68
HIDDEN void osl_free(void *cp)
Definition: sh_osl.cpp:425
fastf_t screen_y
Definition: liboslrend.h:64
point_t r_pt
Point at which ray starts.
Definition: raytrace.h:218
#define RDEBUG_SHADE
Definition: optical.h:130
#define BU_SEM_SYSCALL
Definition: parallel.h:178
HIDDEN int osl_setup(register struct region *rp, struct bu_vls *matparm, void **dpp, const struct mfuncs *mfp, struct rt_i *rtip)
Definition: sh_osl.cpp:370
std::vector< std::pair< std::string, int > > iparam
Definition: liboslrend.h:96
int a_y
Screen Y of ray, if applicable.
Definition: raytrace.h:1597
point_t dPdv
Definition: liboslrend.h:69
point_t dPdu
Definition: liboslrend.h:69
int osl_parse(const struct bu_vls *in_vls, ShaderGroupInfo &group_info)
Definition: sh_osl.cpp:278
int rt_shootray(struct application *ap)
int(* a_miss)(struct application *)
called when shot misses
Definition: raytrace.h:1585
void * reg_udata
User appl. data for material.
Definition: raytrace.h:548
#define BU_VLS_INIT_ZERO
Definition: vls.h:84
int(* default_a_hit)(struct application *, struct partition *, struct seg *)
Definition: sh_osl.cpp:58
#define RT_HIT_NORMAL(_normal, _hitp, _stp, _unused, _flipflag)
Definition: raytrace.h:273
std::vector< void * > thread_infos
Definition: sh_osl.cpp:55
#define CK_OSL_SP(_p)
Definition: sh_osl.cpp:44
std::vector< std::pair< std::string, std::string > > sparam
Definition: liboslrend.h:100
uint32_t magic
Definition: sh_osl.cpp:67
void bu_vls_vlscat(struct bu_vls *dest, const struct bu_vls *src)
Definition: vls.c:415
std::string layername
Definition: liboslrend.h:105
struct partition * pt_forw
forwards link
Definition: raytrace.h:574
#define RT_CHECK_PT(_p)
compat
Definition: raytrace.h:588
#define RT_APPLICATION_INIT(_p)
Definition: raytrace.h:1676
Ray out_ray
Definition: liboslrend.h:80
fastf_t a_refrac_index
current index of refraction
Definition: raytrace.h:1624
Definition: vls.h:56
#define OSL_MAGIC
Definition: sh_osl.cpp:43
Header file for the BRL-CAD Optical Library, LIBOPTICAL.
void * reg_mfuncs
User appl. funcs for material.
Definition: raytrace.h:547
int rdebug
Definition: init.c:39
point_t origin
Definition: liboslrend.h:48
int doreflection
Definition: liboslrend.h:78
struct mfuncs osl_mfuncs[]
Definition: sh_osl.cpp:106
#define BU_STR_EQUAL(s1, s2)
Definition: str.h:126
std::vector< std::pair< std::string, Color3 > > cparam
Definition: liboslrend.h:98