YafaRay Core  v3.2.0-ALPHA-10-g60452c5
basicnodes.cc
Go to the documentation of this file.
1 
2 #include <textures/basicnodes.h>
3 #include <textures/layernode.h>
4 #include <core_api/object3d.h>
5 #include <core_api/camera.h>
6 #include <iomanip>
7 
9 
10 textureMapper_t::textureMapper_t(const texture_t *texture): tex(texture), bumpStr(0.02), doScalar(true)
11 {
12  map_x=1; map_y=2, map_z=3;
13 }
14 
16 {
17  if(tex->discrete())
18  {
19  int u, v, w;
20  tex->resolution(u, v, w);
21  dU = 1.f/(float)u;
22  dV = 1.f/(float)v;
23  if(tex->isThreeD()) dW = 1.f/(float)w;
24  else dW = 0.f;
25  }
26  else
27  {
28  float step = 0.0002f;
29  dU = dV = dW = step;
30  }
31 
32  pDU = point3d_t(dU, 0, 0);
33  pDV = point3d_t(0, dV, 0);
34  pDW = point3d_t(0, 0, dW);
35 
36  bumpStr /= scale.length();
37 
38  if (!tex->isNormalmap())
39  bumpStr /= 100.0f;
40 }
41 
42 // Map the texture to a cylinder
43 inline point3d_t tubemap(const point3d_t &p)
44 {
45  point3d_t res;
46  res.y = p.z;
47  float d = p.x*p.x + p.y*p.y;
48  if (d>0) {
49  res.z = 1.0/fSqrt(d);
50  res.x = -atan2(p.x, p.y) * M_1_PI;
51  }
52  else res.x = res.z = 0;
53  return res;
54 }
55 
56 // Map the texture to a sphere
57 inline point3d_t spheremap(const point3d_t &p)
58 {
59  point3d_t res(0.f);
60  float d = p.x*p.x + p.y*p.y + p.z*p.z;
61  if (d>0) {
62  res.z = fSqrt(d);
63  if ((p.x!=0) && (p.y!=0)) res.x = -atan2(p.x, p.y) * M_1_PI;
64  res.y = 1.0f - 2.0f*(fAcos(p.z/res.z) * M_1_PI);
65  }
66  return res;
67 }
68 
69 // Map the texture to a cube
70 inline point3d_t cubemap(const point3d_t &p, const vector3d_t &n)
71 {
72  const int ma[3][3] = { {1, 2, 0}, {0, 2, 1}, {0, 1, 2} };
73  // int axis = std::fabs(n.x) > std::fabs(n.y) ? (std::fabs(n.x) > std::fabs(n.z) ? 0 : 2) : (std::fabs(n.y) > std::fabs(n.z) ? 1 : 2);
74  // no functionality changes, just more readable code
75 
76  int axis;
77 
78  if (std::fabs(n.z) >= std::fabs(n.x) && std::fabs(n.z) >= std::fabs(n.y)) {
79  axis= 2;
80  }
81  else if (std::fabs(n.y) >= std::fabs(n.x) && std::fabs(n.y) >= std::fabs(n.z)) {
82  axis= 1;
83  }
84  else {
85  axis= 0;
86  }
87 
88  return point3d_t(p[ma[axis][0]], p[ma[axis][1]], p[ma[axis][2]]);
89 }
90 
91 // Map the texture to a plane but it should not be used by now as it does nothing, it's just for completeness sake
92 inline point3d_t flatmap(const point3d_t &p)
93 {
94  return p;
95 }
96 
98 {
99  point3d_t texpt(p);
100  // Texture coordinates standardized, if needed, to -1..1
101  switch(tex_coords)
102  {
103  case TXC_UV: texpt = point3d_t(2.0f*texpt.x-1.0f, 2.0f*texpt.y-1.0f, texpt.z); break;
104  default: break;
105  }
106  // Texture axis mapping
107  float texmap[4] = {0, texpt.x, texpt.y, texpt.z};
108  texpt.x=texmap[map_x];
109  texpt.y=texmap[map_y];
110  texpt.z=texmap[map_z];
111  // Texture coordinates mapping
112  switch(tex_maptype)
113  {
114  case TXP_TUBE: texpt = tubemap(texpt); break;
115  case TXP_SPHERE:texpt = spheremap(texpt); break;
116  case TXP_CUBE: texpt = cubemap(texpt, N); break;
117  case TXP_PLAIN: // texpt = flatmap(texpt); break;
118  default: break;
119  }
120  // Texture scale and offset
121  texpt = mult(texpt,scale) + offset;
122 
123  return texpt;
124 }
125 
127 {
128  return point3d_t(sp.U, sp.V, 0.f);
129 }
130 
131 void textureMapper_t::getCoords(point3d_t &texpt, vector3d_t &Ng, const surfacePoint_t &sp, const renderState_t &state) const
132 {
133  switch(tex_coords)
134  {
135  case TXC_UV: texpt = eval_uv(sp); Ng = sp.Ng; break;
136  case TXC_ORCO: texpt = sp.orcoP; Ng = sp.orcoNg; break;
137  case TXC_TRAN: texpt = mtx * sp.P; Ng = mtx * sp.Ng; break; // apply 4x4 matrix of object for mapping also to true surface normals
138  case TXC_WIN: texpt = state.cam->screenproject(sp.P); Ng = sp.Ng; break;
139  case TXC_NOR: {
140  vector3d_t camx, camy, camz;
141  state.cam->getAxis(camx,camy,camz);
142  texpt = point3d_t(sp.N*camx, -sp.N*camy, 0); Ng = sp.Ng;
143  break;
144  }
145  case TXC_STICK: // Not implemented yet use GLOB
146  case TXC_STRESS:// Not implemented yet use GLOB
147  case TXC_TAN: // Not implemented yet use GLOB
148  case TXC_REFL: // Not implemented yet use GLOB
149  case TXC_GLOB: // GLOB mapped as default
150  default: texpt = sp.P; Ng = sp.Ng;
151  break;
152  }
153 }
154 
155 
156 void textureMapper_t::eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp)const
157 {
158  point3d_t texpt(0.f);
159  vector3d_t Ng(0.f);
160  mipMapParams_t * mipMapParams = nullptr;
161 
163  {
164  spDifferentials_t spDiff(sp, *(sp.ray));
165 
166  getCoords(texpt, Ng, sp, state);
167 
168  point3d_t texptorig=texpt;
169 
170  texpt = doMapping(texptorig, Ng);
171 
172  if(tex_coords == TXC_UV && sp.hasUV)
173  {
174  float dUdx = 0.f, dVdx = 0.f;
175  float dUdy = 0.f, dVdy = 0.f;
176  spDiff.getUVdifferentials(dUdx, dVdx, dUdy, dVdy);
177 
178  point3d_t texpt_diffx = 1.0e+2f * (doMapping(texptorig + 1.0e-2f * point3d_t(dUdx, dVdx, 0.f), Ng) - texpt);
179  point3d_t texpt_diffy = 1.0e+2f * (doMapping(texptorig + 1.0e-2f * point3d_t(dUdy, dVdy, 0.f), Ng) - texpt);
180 
181  mipMapParams = new mipMapParams_t(texpt_diffx.x, texpt_diffx.y, texpt_diffy.x, texpt_diffy.y);
182  }
183  }
184  else
185  {
186  getCoords(texpt, Ng, sp, state);
187  texpt = doMapping(texpt, Ng);
188  }
189 
190  stack[this->ID] = nodeResult_t(tex->getColor(texpt, mipMapParams), (doScalar) ? tex->getFloat(texpt, mipMapParams) : 0.f );
191 
192  if(mipMapParams)
193  {
194  delete mipMapParams;
195  mipMapParams = nullptr;
196  }
197 }
198 
199 // Basically you shouldn't call this anyway, but for the sake of consistency, redirect:
200 void textureMapper_t::eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp, const vector3d_t &wo, const vector3d_t &wi)const
201 {
202  eval(stack, state, sp);
203 }
204 
205 // Normal perturbation
206 
208 {
209  point3d_t texpt(0.f);
210  vector3d_t Ng(0.f);
211  float du = 0.0f, dv = 0.0f;
212 
213  getCoords(texpt, Ng, sp, state);
214 
215  if (tex->discrete() && sp.hasUV && tex_coords == TXC_UV)
216  {
217  texpt = doMapping(texpt, Ng);
218  colorA_t color(0.f);
219  vector3d_t norm(0.f);
220 
221  if (tex->isNormalmap())
222  {
223  // Get color from normal map texture
224  color = tex->getRawColor(texpt);
225 
226  // Assign normal map RGB colors to vector norm
227  norm.x = color.getR();
228  norm.y = color.getG();
229  norm.z = color.getB();
230  norm = (2.f * norm) - 1.f;
231 
232  // Convert norm into shading space
233  du = norm * sp.dSdU;
234  dv = norm * sp.dSdV;
235  }
236  else
237  {
238  point3d_t i0 = (texpt - pDU);
239  point3d_t i1 = (texpt + pDU);
240  point3d_t j0 = (texpt - pDV);
241  point3d_t j1 = (texpt + pDV);
242  float dfdu = (tex->getFloat(i0) - tex->getFloat(i1)) / dU;
243  float dfdv = (tex->getFloat(j0) - tex->getFloat(j1)) / dV;
244 
245  // now we got the derivative in UV-space, but need it in shading space:
246  vector3d_t vecU = sp.dSdU;
247  vector3d_t vecV = sp.dSdV;
248  vecU.z = dfdu;
249  vecV.z = dfdv;
250  // now we have two vectors NU/NV/df; Solve plane equation to get 1/0/df and 0/1/df (i.e. dNUdf and dNVdf)
251  norm = vecU ^ vecV;
252  }
253 
254  norm.normalize();
255 
256  if(std::fabs(norm.z) > 1e-30f)
257  {
258  float NF = 1.0/norm.z * bumpStr; // normalizes z to 1, why?
259  du = norm.x * NF;
260  dv = norm.y * NF;
261  }
262  else du = dv = 0.f;
263  }
264  else
265  {
266  if (tex->isNormalmap())
267  {
268  texpt = doMapping(texpt, Ng);
269  colorA_t color(0.f);
270  vector3d_t norm(0.f);
271 
272  // Get color from normal map texture
273  color = tex->getRawColor(texpt);
274 
275  // Assign normal map RGB colors to vector norm
276  norm.x = color.getR();
277  norm.y = color.getG();
278  norm.z = color.getB();
279  norm = (2.f * norm) - 1.f;
280 
281  // Convert norm into shading space
282  du = norm * sp.dSdU;
283  dv = norm * sp.dSdV;
284 
285  norm.normalize();
286 
287  if(std::fabs(norm.z) > 1e-30f)
288  {
289  float NF = 1.0/norm.z * bumpStr; // normalizes z to 1, why?
290  du = norm.x * NF;
291  dv = norm.y * NF;
292  }
293  else du = dv = 0.f;
294  }
295  else
296  {
297  // no uv coords -> procedurals usually, this mapping only depends on NU/NV which is fairly arbitrary
298  // weird things may happen when objects are rotated, i.e. incorrect bump change
299  point3d_t i0 = doMapping(texpt - dU * sp.NU, Ng);
300  point3d_t i1 = doMapping(texpt + dU * sp.NU, Ng);
301  point3d_t j0 = doMapping(texpt - dV * sp.NV, Ng);
302  point3d_t j1 = doMapping(texpt + dV * sp.NV, Ng);
303 
304  du = (tex->getFloat(i0) - tex->getFloat(i1)) / dU;
305  dv = (tex->getFloat(j0) - tex->getFloat(j1)) / dV;
306  du *= bumpStr;
307  dv *= bumpStr;
308 
309  if(tex_coords != TXC_UV)
310  {
311  du = -du;
312  dv = -dv;
313  }
314  }
315  }
316 
317  stack[this->ID] = nodeResult_t(colorA_t(du, dv, 0.f, 0.f), 0.f );
318 }
319 
321 {
322  const texture_t *tex=0;
323  const std::string *texname=0, *option=0;
324  TEX_COORDS tc = TXC_GLOB;
325  TEX_PROJ maptype = TXP_PLAIN;
326  float bumpStr = 1.f;
327  bool scalar=true;
328  int map[3] = { 1, 2, 3 };
329  point3d_t offset(0.f), scale(1.f);
330  matrix4x4_t mtx(1);
331  if( !params.getParam("texture", texname) )
332  {
333  Y_ERROR << "TextureMapper: No texture given for texture mapper!" << yendl;
334  return nullptr;
335  }
336  tex = render.getTexture(*texname);
337  if(!tex)
338  {
339  Y_ERROR << "TextureMapper: texture '" << texname << "' does not exist!" << yendl;
340  return nullptr;
341  }
342  textureMapper_t *tm = new textureMapper_t(tex);
343  if(params.getParam("texco", option) )
344  {
345  if(*option == "uv") tc = TXC_UV;
346  else if(*option == "global") tc = TXC_GLOB;
347  else if(*option == "orco") tc = TXC_ORCO;
348  else if(*option == "transformed") tc = TXC_TRAN;
349  else if(*option == "window") tc = TXC_WIN;
350  else if(*option == "normal") tc = TXC_NOR;
351  else if(*option == "reflect") tc = TXC_REFL;
352  else if(*option == "stick") tc = TXC_STICK;
353  else if(*option == "stress") tc = TXC_STRESS;
354  else if(*option == "tangent") tc = TXC_TAN;
355  }
356  if(params.getParam("mapping", option) && tex->discrete())
357  {
358  if(*option == "plain") maptype = TXP_PLAIN;
359  else if(*option == "cube") maptype = TXP_CUBE;
360  else if(*option == "tube") maptype = TXP_TUBE;
361  else if(*option == "sphere") maptype = TXP_SPHERE;
362  }
363  params.getMatrix("transform", mtx);
364  params.getParam("scale", scale);
365  params.getParam("offset", offset);
366  params.getParam("do_scalar", scalar);
367  params.getParam("bump_strength", bumpStr);
368  params.getParam("proj_x", map[0]);
369  params.getParam("proj_y", map[1]);
370  params.getParam("proj_z", map[2]);
371  for(int i=0; i<3; ++i) map[i] = std::min(3, std::max(0, map[i]));
372  tm->tex_coords = tc;
373  tm->tex_maptype = maptype;
374  tm->map_x = map[0];
375  tm->map_y = map[1];
376  tm->map_z = map[2];
377  tm->scale = vector3d_t(scale);
378  tm->offset = vector3d_t(2*offset); // Offset need to be doubled due to -1..1 texture standardized wich results in a 2 wide width/height
379  tm->doScalar = scalar;
380  tm->bumpStr = bumpStr;
381  tm->mtx = mtx;
382  tm->setup();
383  return tm;
384 }
385 
386 /* ==========================================
387 / The most simple node you could imagine...
388 / ========================================== */
389 
390 void valueNode_t::eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp)const
391 {
392  stack[this->ID] = nodeResult_t(color, value);
393 }
394 
395 void valueNode_t::eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp, const vector3d_t &wo, const vector3d_t &wi)const
396 {
397  stack[this->ID] = nodeResult_t(color, value);
398 }
399 
401 {
402  color_t col(1.f);
403  float alpha=1.f;
404  float val=1.f;
405  params.getParam("color", col);
406  params.getParam("alpha", alpha);
407  params.getParam("scalar", val);
408  return new valueNode_t(colorA_t(col, alpha), val);
409 }
410 
411 /* ==========================================
412 / A simple mix node, could be used to derive other math nodes
413 / ========================================== */
414 
415 mixNode_t::mixNode_t(): cfactor(0.f), input1(0), input2(0), factor(0)
416 {}
417 
418 mixNode_t::mixNode_t(float val): cfactor(val), input1(0), input2(0), factor(0)
419 {}
420 
421 void mixNode_t::eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp)const
422 {
423  float f2 = (factor) ? factor->getScalar(stack) : cfactor;
424  float f1 = 1.f - f2, fin1, fin2;
425  colorA_t cin1, cin2;
426  if(input1)
427  {
428  cin1 = input1->getColor(stack);
429  fin1 = input1->getScalar(stack);
430  }
431  else
432  {
433  cin1 = col1;
434  fin1 = val1;
435  }
436  if(input2)
437  {
438  cin2 = input2->getColor(stack);
439  fin2 = input2->getScalar(stack);
440  }
441  else
442  {
443  cin2 = col2;
444  fin2 = val2;
445  }
446 
447  colorA_t color = f1 * cin1 + f2 * cin2;
448  float scalar = f1 * fin1 + f2 * fin2;
449  stack[this->ID] = nodeResult_t(color, scalar);
450 }
451 
452 void mixNode_t::eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp, const vector3d_t &wo, const vector3d_t &wi)const
453 {
454  eval(stack, state, sp);
455 }
456 
457 bool mixNode_t::configInputs(const paraMap_t &params, const nodeFinder_t &find)
458 {
459  const std::string *name=0;
460  if( params.getParam("input1", name) )
461  {
462  input1 = find(*name);
463  if(!input1)
464  {
465  Y_ERROR << "MixNode: Couldn't get input1 " << *name << yendl;
466  return false;
467  }
468  }
469  else if(!params.getParam("color1", col1))
470  {
471  Y_ERROR << "MixNode: Color1 not set" << yendl;
472  return false;
473  }
474 
475  if( params.getParam("input2", name) )
476  {
477  input2 = find(*name);
478  if(!input2)
479  {
480  Y_ERROR << "MixNode: Couldn't get input2 " << *name << yendl;
481  return false;
482  }
483  }
484  else if(!params.getParam("color2", col2))
485  {
486  Y_ERROR << "MixNode: Color2 not set" << yendl;
487  return false;
488  }
489 
490  if( params.getParam("factor", name) )
491  {
492  factor = find(*name);
493  if(!factor)
494  {
495  Y_ERROR << "MixNode: Couldn't get factor " << *name << yendl;
496  return false;
497  }
498  }
499  else if(!params.getParam("value", cfactor))
500  {
501  Y_ERROR << "MixNode: Value not set" << yendl;
502  return false;
503  }
504 
505  return true;
506 }
507 
508 bool mixNode_t::getDependencies(std::vector<const shaderNode_t*> &dep) const
509 {
510  if(input1) dep.push_back(input1);
511  if(input2) dep.push_back(input2);
512  if(factor) dep.push_back(factor);
513  return !dep.empty();
514 }
515 
516 class addNode_t: public mixNode_t
517 {
518  public:
519  virtual void eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp)const
520  {
521  float f2, fin1, fin2;
522  colorA_t cin1, cin2;
523  getInputs(stack, cin1, cin2, fin1, fin2, f2);
524 
525  cin1 += f2 * cin2;
526  fin1 += f2 * fin2;
527  stack[this->ID] = nodeResult_t(cin1, fin1);
528  }
529 };
530 
531 class multNode_t: public mixNode_t
532 {
533  public:
534  virtual void eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp)const
535  {
536  float f1, f2, fin1, fin2;
537  colorA_t cin1, cin2;
538  getInputs(stack, cin1, cin2, fin1, fin2, f2);
539  f1 = 1.f - f2;
540 
541  cin1 *= colorA_t(f1) + f2 * cin2;
542  fin2 *= f1 + f2 * fin2;
543  stack[this->ID] = nodeResult_t(cin1, fin1);
544  }
545 };
546 
547 class subNode_t: public mixNode_t
548 {
549  public:
550  virtual void eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp)const
551  {
552  float f2, fin1, fin2;
553  colorA_t cin1, cin2;
554  getInputs(stack, cin1, cin2, fin1, fin2, f2);
555 
556  cin1 -= f2 * cin2;
557  fin1 -= f2 * fin2;
558  stack[this->ID] = nodeResult_t(cin1, fin1);
559  }
560 };
561 
562 class screenNode_t: public mixNode_t
563 {
564  public:
565  virtual void eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp)const
566  {
567  float f1, f2, fin1, fin2;
568  colorA_t cin1, cin2;
569  getInputs(stack, cin1, cin2, fin1, fin2, f2);
570  f1 = 1.f - f2;
571 
572  colorA_t color = colorA_t(1.f) - (colorA_t(f1) + f2 * (1.f - cin2)) * (1.f - cin1);
573  float scalar = 1.0 - (f1 + f2*(1.f - fin2)) * (1.f - fin1);
574  stack[this->ID] = nodeResult_t(color, scalar);
575  }
576 };
577 
578 class diffNode_t: public mixNode_t
579 {
580  public:
581  virtual void eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp)const
582  {
583  float f1, f2, fin1, fin2;
584  colorA_t cin1, cin2;
585  getInputs(stack, cin1, cin2, fin1, fin2, f2);
586  f1 = 1.f - f2;
587 
588  cin1.R = f1*cin1.R + f2*std::fabs(cin1.R - cin2.R);
589  cin1.G = f1*cin1.G + f2*std::fabs(cin1.G - cin2.G);
590  cin1.B = f1*cin1.B + f2*std::fabs(cin1.B - cin2.B);
591  cin1.A = f1*cin1.A + f2*std::fabs(cin1.A - cin2.A);
592  fin1 = f1*fin1 + f2*std::fabs(fin1 - fin2);
593  stack[this->ID] = nodeResult_t(cin1, fin1);
594  }
595 };
596 
597 class darkNode_t: public mixNode_t
598 {
599  public:
600  virtual void eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp)const
601  {
602  float f2, fin1, fin2;
603  colorA_t cin1, cin2;
604  getInputs(stack, cin1, cin2, fin1, fin2, f2);
605 
606  cin2 *= f2;
607  if(cin2.R < cin1.R) cin1.R = cin2.R;
608  if(cin2.G < cin1.G) cin1.G = cin2.G;
609  if(cin2.B < cin1.B) cin1.B = cin2.B;
610  if(cin2.A < cin1.A) cin1.A = cin2.A;
611  fin2 *= f2;
612  if(fin2 < fin1) fin1 = fin2;
613  stack[this->ID] = nodeResult_t(cin1, fin1);
614  }
615 };
616 
617 class lightNode_t: public mixNode_t
618 {
619  public:
620  virtual void eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp)const
621  {
622  float f2, fin1, fin2;
623  colorA_t cin1, cin2;
624  getInputs(stack, cin1, cin2, fin1, fin2, f2);
625 
626  cin2 *= f2;
627  if(cin2.R > cin1.R) cin1.R = cin2.R;
628  if(cin2.G > cin1.G) cin1.G = cin2.G;
629  if(cin2.B > cin1.B) cin1.B = cin2.B;
630  if(cin2.A > cin1.A) cin1.A = cin2.A;
631  fin2 *= f2;
632  if(fin2 > fin1) fin1 = fin2;
633  stack[this->ID] = nodeResult_t(cin1, fin1);
634  }
635 };
636 
638 {
639  public:
640  virtual void eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp)const
641  {
642  float f1, f2, fin1, fin2;
643  colorA_t cin1, cin2;
644  getInputs(stack, cin1, cin2, fin1, fin2, f2);
645  f1 = 1.f - f2;
646 
647  colorA_t color;
648  color.R = (cin1.R < 0.5f) ? cin1.R * (f1 + 2.0f*f2*cin2.R) : 1.0 - (f1 + 2.0f*f2*(1.0 - cin2.R)) * (1.0 - cin1.R);
649  color.G = (cin1.G < 0.5f) ? cin1.G * (f1 + 2.0f*f2*cin2.G) : 1.0 - (f1 + 2.0f*f2*(1.0 - cin2.G)) * (1.0 - cin1.G);
650  color.B = (cin1.B < 0.5f) ? cin1.B * (f1 + 2.0f*f2*cin2.B) : 1.0 - (f1 + 2.0f*f2*(1.0 - cin2.B)) * (1.0 - cin1.B);
651  color.A = (cin1.A < 0.5f) ? cin1.A * (f1 + 2.0f*f2*cin2.A) : 1.0 - (f1 + 2.0f*f2*(1.0 - cin2.A)) * (1.0 - cin1.A);
652  float scalar = (fin1 < 0.5f) ? fin1 * (f1 + 2.0f*f2*fin2) : 1.0 - (f1 + 2.0f*f2*(1.0 - fin2)) * (1.0 - fin1);
653  stack[this->ID] = nodeResult_t(color, scalar);
654  }
655 };
656 
657 
659 {
660  float val=0.5f;
661  int mode=0;
662  params.getParam("cfactor", val);
663  params.getParam("mode", mode);
664 
665  switch(mode)
666  {
667  case MN_MIX: return new mixNode_t(val);
668  case MN_ADD: return new addNode_t();
669  case MN_MULT: return new multNode_t();
670  case MN_SUB: return new subNode_t();
671  case MN_SCREEN: return new screenNode_t();
672  case MN_DIFF: return new diffNode_t();
673  case MN_DARK: return new darkNode_t();
674  case MN_LIGHT: return new lightNode_t();
675  case MN_OVERLAY: return new overlayNode_t();
676  }
677  return new mixNode_t(val);
678 }
679 
680 // ==================
681 
682 extern "C"
683 {
685  {
686  render.registerFactory("texture_mapper", textureMapper_t::factory);
687  render.registerFactory("value", valueNode_t::factory);
688  render.registerFactory("mix", mixNode_t::factory);
689  render.registerFactory("layer", layerNode_t::factory);
690  }
691 }
692 
void getCoords(point3d_t &texpt, vector3d_t &Ng, const surfacePoint_t &sp, const renderState_t &state) const
Definition: basicnodes.cc:131
virtual void resolution(int &x, int &y, int &z) const
Definition: texture.h:30
Definition: shader.h:49
virtual void registerFactory(const std::string &name, light_factory_t *f)
Definition: environment.cc:997
Definition: shader.h:49
const texture_t * tex
Definition: basicnodes.h:33
virtual void eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp) const
Definition: basicnodes.cc:390
const shaderNode_t * input2
Definition: basicnodes.h:69
Definition: shader.h:49
virtual bool discrete() const
Definition: texture.h:15
vector3d_t offset
Definition: basicnodes.h:35
vector3d_t & normalize()
Definition: vector3d.h:267
float fAcos(float x)
float getB() const
Definition: color.h:89
float val1
Definition: basicnodes.h:67
point3d_t cubemap(const point3d_t &p, const vector3d_t &n)
Definition: basicnodes.cc:70
Definition: shader.h:49
TEX_PROJ tex_maptype
Definition: basicnodes.h:29
Definition: shader.h:49
point3d_t eval_uv(const surfacePoint_t &sp)
Definition: basicnodes.cc:126
float G
Definition: color.h:157
bool hasUV
Definition: surface.h:76
float getScalar(const nodeStack_t &stack) const
Definition: shader.h:84
const shaderNode_t * factor
Definition: basicnodes.h:70
float V
the v texture coord.
Definition: surface.h:82
int map_z
axis mapping; 0:set to zero, 1:x, 2:y, 3:z
Definition: basicnodes.h:30
float z
Definition: vector3d.h:140
point3d_t pDV
Definition: basicnodes.h:31
virtual void eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp) const
Definition: basicnodes.cc:581
vector3d_t dSdU
u-axis in shading space (NU, NV, N)
Definition: surface.h:87
YAFRAYPLUGIN_EXPORT void registerPlugin(renderEnvironment_t &render)
Definition: basicnodes.cc:684
#define __BEGIN_YAFRAY
textureMapper_t(const texture_t *texture)
Definition: basicnodes.cc:10
colorA_t getColor(const nodeStack_t &stack) const
Definition: shader.h:82
bool getMatrix(const std::string &name, matrix4x4_t &m) const
Definition: params.h:89
float A
Definition: color.h:234
point3d_t flatmap(const point3d_t &p)
Definition: basicnodes.cc:92
void getUVdifferentials(float &dUdx, float &dVdx, float &dUdy, float &dVdy) const
Definition: surface.cc:112
TEX_PROJ
Definition: basicnodes.h:12
vector3d_t NV
third vector building orthogonal shading space with N
Definition: surface.h:84
virtual void eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp) const
Definition: basicnodes.cc:565
static shaderNode_t * factory(const paraMap_t &params, renderEnvironment_t &render)
Definition: layernode.cc:193
static shaderNode_t * factory(const paraMap_t &params, renderEnvironment_t &render)
Definition: basicnodes.cc:400
const diffRay_t * ray
Definition: surface.h:97
vector3d_t Ng
the geometric normal.
Definition: surface.h:71
virtual void eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp) const
Definition: basicnodes.cc:156
const camera_t * cam
Definition: scene.h:78
point3d_t doMapping(const point3d_t &p, const vector3d_t &N) const
Definition: basicnodes.cc:97
bool hasDifferentials
Definition: ray.h:31
#define YAFRAYPLUGIN_EXPORT
Definition: color.h:49
float B
Definition: color.h:157
virtual void evalDerivative(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp) const
Definition: basicnodes.cc:207
virtual colorA_t getRawColor(const point3d_t &p, mipMapParams_t *mmParams=nullptr) const
Definition: texture.h:23
int getInterpolationType() const
Definition: texture.h:42
virtual bool isNormalmap() const
Definition: texture.h:19
point3d_t spheremap(const point3d_t &p)
Definition: basicnodes.cc:57
float max(float a, float b)
Definition: GridVolume.cc:117
float z
Definition: vector3d.h:92
unsigned int ID
Definition: shader.h:92
Definition: shader.h:49
vector3d_t NU
second vector building orthogonal shading space with N
Definition: surface.h:83
float U
the u texture coord.
Definition: surface.h:81
virtual float getFloat(const point3d_t &p, mipMapParams_t *mmParams=nullptr) const
Definition: texture.h:26
point3d_t pDU
Definition: basicnodes.h:31
virtual void eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp) const
Definition: basicnodes.cc:620
float x
Definition: vector3d.h:92
virtual texture_t * getTexture(const std::string &name) const
Definition: environment.cc:211
vector3d_t N
the shading normal.
Definition: surface.h:70
float length() const
Definition: vector3d.h:262
matrix4x4_t mtx
Definition: basicnodes.h:38
float val2
Definition: basicnodes.h:67
bool getParam(const std::string &name, T &val) const
template function to get a value, available types are those of parameter_t::getVal() ...
Definition: params.h:82
#define M_1_PI
float getG() const
Definition: color.h:88
float x
Definition: vector3d.h:140
static shaderNode_t * factory(const paraMap_t &params, renderEnvironment_t &render)
Definition: basicnodes.cc:658
float R
Definition: color.h:157
point3d_t mult(const point3d_t &a, const vector3d_t &b)
Definition: vector3d.h:257
TEX_COORDS tex_coords
Definition: basicnodes.h:28
virtual void eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp) const
Definition: basicnodes.cc:550
vector3d_t dSdV
v-axis in shading space (NU, NV, N)
Definition: surface.h:88
point3d_t tubemap(const point3d_t &p)
Definition: basicnodes.cc:43
float getR() const
Definition: color.h:87
point3d_t P
the (world) position.
Definition: surface.h:73
virtual void eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp) const
Definition: basicnodes.cc:421
virtual colorA_t getColor(const point3d_t &p, mipMapParams_t *mmParams=nullptr) const
Definition: texture.h:21
float cfactor
Definition: basicnodes.h:67
vector3d_t orcoNg
the untransformed geometric normal.
Definition: surface.h:72
float y
Definition: vector3d.h:92
virtual void eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp) const
Definition: basicnodes.cc:519
colorA_t col2
Definition: basicnodes.h:66
virtual void getAxis(vector3d_t &vx, vector3d_t &vy, vector3d_t &vz) const
Get camera axis.
Definition: camera.h:72
virtual point3d_t screenproject(const point3d_t &p) const =0
Get projection of point p into camera plane.
virtual void eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp) const
Definition: basicnodes.cc:600
const shaderNode_t * input1
Definition: basicnodes.h:68
colorA_t col1
Definition: basicnodes.h:66
TEX_COORDS
Definition: basicnodes.h:11
point3d_t pDW
Definition: basicnodes.h:31
void getInputs(nodeStack_t &stack, colorA_t &cin1, colorA_t &cin2, float &fin1, float &fin2, float &f2) const
Definition: basicnodes.h:73
virtual bool isThreeD() const
Definition: texture.h:18
float y
Definition: vector3d.h:140
point3d_t orcoP
Definition: surface.h:74
virtual void eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp) const
Definition: basicnodes.cc:534
static shaderNode_t * factory(const paraMap_t &params, renderEnvironment_t &render)
Definition: basicnodes.cc:320
vector3d_t scale
Definition: basicnodes.h:34
float fSqrt(float a)
virtual bool configInputs(const paraMap_t &params, const nodeFinder_t &find)
Definition: basicnodes.cc:457
virtual void eval(nodeStack_t &stack, const renderState_t &state, const surfacePoint_t &sp) const
Definition: basicnodes.cc:640
virtual bool getDependencies(std::vector< const shaderNode_t * > &dep) const
return the nodes on which the output of this one depends
Definition: basicnodes.cc:508
#define __END_YAFRAY
float min(float a, float b)
Definition: GridVolume.cc:116