nodes.h 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505
  1. /*
  2. * Copyright 2011-2013 Blender Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef __NODES_H__
  17. #define __NODES_H__
  18. #include "render/graph.h"
  19. #include "graph/node.h"
  20. #include "util/util_array.h"
  21. #include "util/util_string.h"
  22. CCL_NAMESPACE_BEGIN
  23. class ImageManager;
  24. class LightManager;
  25. class Scene;
  26. class Shader;
  27. /* Texture Mapping */
  28. class TextureMapping {
  29. public:
  30. TextureMapping();
  31. Transform compute_transform();
  32. bool skip();
  33. void compile(SVMCompiler &compiler, int offset_in, int offset_out);
  34. int compile(SVMCompiler &compiler, ShaderInput *vector_in);
  35. void compile(OSLCompiler &compiler);
  36. int compile_begin(SVMCompiler &compiler, ShaderInput *vector_in);
  37. void compile_end(SVMCompiler &compiler, ShaderInput *vector_in, int vector_offset);
  38. float3 translation;
  39. float3 rotation;
  40. float3 scale;
  41. float3 min, max;
  42. bool use_minmax;
  43. enum Type { POINT = 0, TEXTURE = 1, VECTOR = 2, NORMAL = 3 };
  44. Type type;
  45. enum Mapping { NONE = 0, X = 1, Y = 2, Z = 3 };
  46. Mapping x_mapping, y_mapping, z_mapping;
  47. enum Projection { FLAT, CUBE, TUBE, SPHERE };
  48. Projection projection;
  49. };
  50. /* Nodes */
  51. class TextureNode : public ShaderNode {
  52. public:
  53. explicit TextureNode(const NodeType *node_type) : ShaderNode(node_type)
  54. {
  55. }
  56. TextureMapping tex_mapping;
  57. };
  58. /* Any node which uses image manager's slot should be a subclass of this one. */
  59. class ImageSlotTextureNode : public TextureNode {
  60. public:
  61. explicit ImageSlotTextureNode(const NodeType *node_type) : TextureNode(node_type)
  62. {
  63. special_type = SHADER_SPECIAL_TYPE_IMAGE_SLOT;
  64. }
  65. int slot;
  66. };
  67. class ImageTextureNode : public ImageSlotTextureNode {
  68. public:
  69. SHADER_NODE_NO_CLONE_CLASS(ImageTextureNode)
  70. ~ImageTextureNode();
  71. ShaderNode *clone() const;
  72. void attributes(Shader *shader, AttributeRequestSet *attributes);
  73. bool has_attribute_dependency()
  74. {
  75. return true;
  76. }
  77. virtual bool equals(const ShaderNode &other)
  78. {
  79. const ImageTextureNode &image_node = (const ImageTextureNode &)other;
  80. return ImageSlotTextureNode::equals(other) && builtin_data == image_node.builtin_data &&
  81. animated == image_node.animated;
  82. }
  83. /* Parameters. */
  84. ustring filename;
  85. void *builtin_data;
  86. ustring colorspace;
  87. ImageAlphaType alpha_type;
  88. NodeImageProjection projection;
  89. InterpolationType interpolation;
  90. ExtensionType extension;
  91. float projection_blend;
  92. bool animated;
  93. float3 vector;
  94. /* Runtime. */
  95. ImageManager *image_manager;
  96. int is_float;
  97. bool compress_as_srgb;
  98. ustring known_colorspace;
  99. };
  100. class EnvironmentTextureNode : public ImageSlotTextureNode {
  101. public:
  102. SHADER_NODE_NO_CLONE_CLASS(EnvironmentTextureNode)
  103. ~EnvironmentTextureNode();
  104. ShaderNode *clone() const;
  105. void attributes(Shader *shader, AttributeRequestSet *attributes);
  106. bool has_attribute_dependency()
  107. {
  108. return true;
  109. }
  110. virtual int get_group()
  111. {
  112. return NODE_GROUP_LEVEL_2;
  113. }
  114. virtual bool equals(const ShaderNode &other)
  115. {
  116. const EnvironmentTextureNode &env_node = (const EnvironmentTextureNode &)other;
  117. return ImageSlotTextureNode::equals(other) && builtin_data == env_node.builtin_data &&
  118. animated == env_node.animated;
  119. }
  120. /* Parameters. */
  121. ustring filename;
  122. void *builtin_data;
  123. ustring colorspace;
  124. ImageAlphaType alpha_type;
  125. NodeEnvironmentProjection projection;
  126. InterpolationType interpolation;
  127. bool animated;
  128. float3 vector;
  129. /* Runtime. */
  130. ImageManager *image_manager;
  131. int is_float;
  132. bool compress_as_srgb;
  133. ustring known_colorspace;
  134. };
  135. class SkyTextureNode : public TextureNode {
  136. public:
  137. SHADER_NODE_CLASS(SkyTextureNode)
  138. virtual int get_group()
  139. {
  140. return NODE_GROUP_LEVEL_2;
  141. }
  142. NodeSkyType type;
  143. float3 sun_direction;
  144. float turbidity;
  145. float ground_albedo;
  146. float3 vector;
  147. };
  148. class OutputNode : public ShaderNode {
  149. public:
  150. SHADER_NODE_CLASS(OutputNode)
  151. void *surface;
  152. void *volume;
  153. float3 displacement;
  154. float3 normal;
  155. /* Don't allow output node de-duplication. */
  156. virtual bool equals(const ShaderNode & /*other*/)
  157. {
  158. return false;
  159. }
  160. };
  161. class GradientTextureNode : public TextureNode {
  162. public:
  163. SHADER_NODE_CLASS(GradientTextureNode)
  164. virtual int get_group()
  165. {
  166. return NODE_GROUP_LEVEL_2;
  167. }
  168. NodeGradientType type;
  169. float3 vector;
  170. };
  171. class NoiseTextureNode : public TextureNode {
  172. public:
  173. SHADER_NODE_CLASS(NoiseTextureNode)
  174. float scale, detail, distortion;
  175. float3 vector;
  176. };
  177. class VoronoiTextureNode : public TextureNode {
  178. public:
  179. SHADER_NODE_CLASS(VoronoiTextureNode)
  180. virtual int get_group()
  181. {
  182. return NODE_GROUP_LEVEL_2;
  183. }
  184. NodeVoronoiColoring coloring;
  185. NodeVoronoiDistanceMetric metric;
  186. NodeVoronoiFeature feature;
  187. float scale, exponent;
  188. float3 vector;
  189. };
  190. class MusgraveTextureNode : public TextureNode {
  191. public:
  192. SHADER_NODE_CLASS(MusgraveTextureNode)
  193. virtual int get_group()
  194. {
  195. return NODE_GROUP_LEVEL_2;
  196. }
  197. NodeMusgraveType type;
  198. float scale, detail, dimension, lacunarity, offset, gain;
  199. float3 vector;
  200. };
  201. class WaveTextureNode : public TextureNode {
  202. public:
  203. SHADER_NODE_CLASS(WaveTextureNode)
  204. virtual int get_group()
  205. {
  206. return NODE_GROUP_LEVEL_2;
  207. }
  208. NodeWaveType type;
  209. NodeWaveProfile profile;
  210. float scale, distortion, detail, detail_scale;
  211. float3 vector;
  212. };
  213. class MagicTextureNode : public TextureNode {
  214. public:
  215. SHADER_NODE_CLASS(MagicTextureNode)
  216. virtual int get_group()
  217. {
  218. return NODE_GROUP_LEVEL_2;
  219. }
  220. int depth;
  221. float3 vector;
  222. float scale, distortion;
  223. };
  224. class CheckerTextureNode : public TextureNode {
  225. public:
  226. SHADER_NODE_CLASS(CheckerTextureNode)
  227. float3 vector, color1, color2;
  228. float scale;
  229. virtual int get_group()
  230. {
  231. return NODE_GROUP_LEVEL_2;
  232. }
  233. };
  234. class BrickTextureNode : public TextureNode {
  235. public:
  236. SHADER_NODE_CLASS(BrickTextureNode)
  237. float offset, squash;
  238. int offset_frequency, squash_frequency;
  239. float3 color1, color2, mortar;
  240. float scale, mortar_size, mortar_smooth, bias, brick_width, row_height;
  241. float3 vector;
  242. virtual int get_group()
  243. {
  244. return NODE_GROUP_LEVEL_2;
  245. }
  246. };
  247. class PointDensityTextureNode : public ShaderNode {
  248. public:
  249. SHADER_NODE_NO_CLONE_CLASS(PointDensityTextureNode)
  250. virtual int get_group()
  251. {
  252. return NODE_GROUP_LEVEL_3;
  253. }
  254. ~PointDensityTextureNode();
  255. ShaderNode *clone() const;
  256. void attributes(Shader *shader, AttributeRequestSet *attributes);
  257. bool has_attribute_dependency()
  258. {
  259. return true;
  260. }
  261. bool has_spatial_varying()
  262. {
  263. return true;
  264. }
  265. bool has_object_dependency()
  266. {
  267. return true;
  268. }
  269. void add_image();
  270. /* Parameters. */
  271. ustring filename;
  272. NodeTexVoxelSpace space;
  273. InterpolationType interpolation;
  274. Transform tfm;
  275. float3 vector;
  276. void *builtin_data;
  277. /* Runtime. */
  278. ImageManager *image_manager;
  279. int slot;
  280. virtual bool equals(const ShaderNode &other)
  281. {
  282. const PointDensityTextureNode &point_dendity_node = (const PointDensityTextureNode &)other;
  283. return ShaderNode::equals(other) && builtin_data == point_dendity_node.builtin_data;
  284. }
  285. };
  286. class IESLightNode : public TextureNode {
  287. public:
  288. SHADER_NODE_NO_CLONE_CLASS(IESLightNode)
  289. ~IESLightNode();
  290. ShaderNode *clone() const;
  291. virtual int get_group()
  292. {
  293. return NODE_GROUP_LEVEL_2;
  294. }
  295. ustring filename;
  296. ustring ies;
  297. float strength;
  298. float3 vector;
  299. private:
  300. LightManager *light_manager;
  301. int slot;
  302. void get_slot();
  303. };
  304. class MappingNode : public ShaderNode {
  305. public:
  306. SHADER_NODE_CLASS(MappingNode)
  307. virtual int get_group()
  308. {
  309. return NODE_GROUP_LEVEL_2;
  310. }
  311. float3 vector;
  312. TextureMapping tex_mapping;
  313. };
  314. class RGBToBWNode : public ShaderNode {
  315. public:
  316. SHADER_NODE_CLASS(RGBToBWNode)
  317. void constant_fold(const ConstantFolder &folder);
  318. float3 color;
  319. };
  320. class ConvertNode : public ShaderNode {
  321. public:
  322. ConvertNode(SocketType::Type from, SocketType::Type to, bool autoconvert = false);
  323. SHADER_NODE_BASE_CLASS(ConvertNode)
  324. void constant_fold(const ConstantFolder &folder);
  325. SocketType::Type from, to;
  326. union {
  327. float value_float;
  328. int value_int;
  329. float3 value_color;
  330. float3 value_vector;
  331. float3 value_point;
  332. float3 value_normal;
  333. };
  334. ustring value_string;
  335. private:
  336. static const int MAX_TYPE = 12;
  337. static bool register_types();
  338. static Node *create(const NodeType *type);
  339. static const NodeType *node_types[MAX_TYPE][MAX_TYPE];
  340. static bool initialized;
  341. };
  342. class BsdfBaseNode : public ShaderNode {
  343. public:
  344. BsdfBaseNode(const NodeType *node_type);
  345. bool has_spatial_varying()
  346. {
  347. return true;
  348. }
  349. virtual ClosureType get_closure_type()
  350. {
  351. return closure;
  352. }
  353. virtual bool has_bump();
  354. virtual bool equals(const ShaderNode & /*other*/)
  355. {
  356. /* TODO(sergey): With some care BSDF nodes can be de-duplicated. */
  357. return false;
  358. }
  359. ClosureType closure;
  360. };
  361. class BsdfNode : public BsdfBaseNode {
  362. public:
  363. explicit BsdfNode(const NodeType *node_type);
  364. SHADER_NODE_BASE_CLASS(BsdfNode)
  365. void compile(SVMCompiler &compiler,
  366. ShaderInput *param1,
  367. ShaderInput *param2,
  368. ShaderInput *param3 = NULL,
  369. ShaderInput *param4 = NULL);
  370. float3 color;
  371. float3 normal;
  372. float surface_mix_weight;
  373. };
  374. class AnisotropicBsdfNode : public BsdfNode {
  375. public:
  376. SHADER_NODE_CLASS(AnisotropicBsdfNode)
  377. float3 tangent;
  378. float roughness, anisotropy, rotation;
  379. ClosureType distribution;
  380. ClosureType get_closure_type()
  381. {
  382. return distribution;
  383. }
  384. void attributes(Shader *shader, AttributeRequestSet *attributes);
  385. bool has_attribute_dependency()
  386. {
  387. return true;
  388. }
  389. };
  390. class DiffuseBsdfNode : public BsdfNode {
  391. public:
  392. SHADER_NODE_CLASS(DiffuseBsdfNode)
  393. float roughness;
  394. };
  395. /* Disney principled BRDF */
  396. class PrincipledBsdfNode : public BsdfBaseNode {
  397. public:
  398. SHADER_NODE_CLASS(PrincipledBsdfNode)
  399. void expand(ShaderGraph *graph);
  400. bool has_surface_bssrdf();
  401. bool has_bssrdf_bump();
  402. void compile(SVMCompiler &compiler,
  403. ShaderInput *metallic,
  404. ShaderInput *subsurface,
  405. ShaderInput *subsurface_radius,
  406. ShaderInput *specular,
  407. ShaderInput *roughness,
  408. ShaderInput *specular_tint,
  409. ShaderInput *anisotropic,
  410. ShaderInput *sheen,
  411. ShaderInput *sheen_tint,
  412. ShaderInput *clearcoat,
  413. ShaderInput *clearcoat_roughness,
  414. ShaderInput *ior,
  415. ShaderInput *transmission,
  416. ShaderInput *anisotropic_rotation,
  417. ShaderInput *transmission_roughness);
  418. float3 base_color;
  419. float3 subsurface_color, subsurface_radius;
  420. float metallic, subsurface, specular, roughness, specular_tint, anisotropic, sheen, sheen_tint,
  421. clearcoat, clearcoat_roughness, ior, transmission, anisotropic_rotation,
  422. transmission_roughness;
  423. float3 normal, clearcoat_normal, tangent;
  424. float surface_mix_weight;
  425. ClosureType distribution, distribution_orig;
  426. ClosureType subsurface_method;
  427. float3 emission;
  428. float alpha;
  429. bool has_integrator_dependency();
  430. void attributes(Shader *shader, AttributeRequestSet *attributes);
  431. bool has_attribute_dependency()
  432. {
  433. return true;
  434. }
  435. };
  436. class TranslucentBsdfNode : public BsdfNode {
  437. public:
  438. SHADER_NODE_CLASS(TranslucentBsdfNode)
  439. };
  440. class TransparentBsdfNode : public BsdfNode {
  441. public:
  442. SHADER_NODE_CLASS(TransparentBsdfNode)
  443. bool has_surface_transparent()
  444. {
  445. return true;
  446. }
  447. };
  448. class VelvetBsdfNode : public BsdfNode {
  449. public:
  450. SHADER_NODE_CLASS(VelvetBsdfNode)
  451. float sigma;
  452. };
  453. class GlossyBsdfNode : public BsdfNode {
  454. public:
  455. SHADER_NODE_CLASS(GlossyBsdfNode)
  456. void simplify_settings(Scene *scene);
  457. bool has_integrator_dependency();
  458. ClosureType get_closure_type()
  459. {
  460. return distribution;
  461. }
  462. float roughness, roughness_orig;
  463. ClosureType distribution, distribution_orig;
  464. };
  465. class GlassBsdfNode : public BsdfNode {
  466. public:
  467. SHADER_NODE_CLASS(GlassBsdfNode)
  468. void simplify_settings(Scene *scene);
  469. bool has_integrator_dependency();
  470. ClosureType get_closure_type()
  471. {
  472. return distribution;
  473. }
  474. float roughness, roughness_orig, IOR;
  475. ClosureType distribution, distribution_orig;
  476. };
  477. class RefractionBsdfNode : public BsdfNode {
  478. public:
  479. SHADER_NODE_CLASS(RefractionBsdfNode)
  480. void simplify_settings(Scene *scene);
  481. bool has_integrator_dependency();
  482. ClosureType get_closure_type()
  483. {
  484. return distribution;
  485. }
  486. float roughness, roughness_orig, IOR;
  487. ClosureType distribution, distribution_orig;
  488. };
  489. class ToonBsdfNode : public BsdfNode {
  490. public:
  491. SHADER_NODE_CLASS(ToonBsdfNode)
  492. float smooth, size;
  493. ClosureType component;
  494. };
  495. class SubsurfaceScatteringNode : public BsdfNode {
  496. public:
  497. SHADER_NODE_CLASS(SubsurfaceScatteringNode)
  498. bool has_surface_bssrdf()
  499. {
  500. return true;
  501. }
  502. bool has_bssrdf_bump();
  503. ClosureType get_closure_type()
  504. {
  505. return falloff;
  506. }
  507. float scale;
  508. float3 radius;
  509. float sharpness;
  510. float texture_blur;
  511. ClosureType falloff;
  512. };
  513. class EmissionNode : public ShaderNode {
  514. public:
  515. SHADER_NODE_CLASS(EmissionNode)
  516. void constant_fold(const ConstantFolder &folder);
  517. bool has_surface_emission()
  518. {
  519. return true;
  520. }
  521. bool has_volume_support()
  522. {
  523. return true;
  524. }
  525. float3 color;
  526. float strength;
  527. float surface_mix_weight;
  528. };
  529. class BackgroundNode : public ShaderNode {
  530. public:
  531. SHADER_NODE_CLASS(BackgroundNode)
  532. void constant_fold(const ConstantFolder &folder);
  533. float3 color;
  534. float strength;
  535. float surface_mix_weight;
  536. };
  537. class HoldoutNode : public ShaderNode {
  538. public:
  539. SHADER_NODE_CLASS(HoldoutNode)
  540. virtual int get_group()
  541. {
  542. return NODE_GROUP_LEVEL_1;
  543. }
  544. virtual ClosureType get_closure_type()
  545. {
  546. return CLOSURE_HOLDOUT_ID;
  547. }
  548. float surface_mix_weight;
  549. float volume_mix_weight;
  550. };
  551. class AmbientOcclusionNode : public ShaderNode {
  552. public:
  553. SHADER_NODE_CLASS(AmbientOcclusionNode)
  554. bool has_spatial_varying()
  555. {
  556. return true;
  557. }
  558. virtual int get_group()
  559. {
  560. return NODE_GROUP_LEVEL_3;
  561. }
  562. virtual bool has_raytrace()
  563. {
  564. return true;
  565. }
  566. float3 color;
  567. float distance;
  568. float3 normal;
  569. int samples;
  570. bool only_local;
  571. bool inside;
  572. };
  573. class VolumeNode : public ShaderNode {
  574. public:
  575. VolumeNode(const NodeType *node_type);
  576. SHADER_NODE_BASE_CLASS(VolumeNode)
  577. void compile(SVMCompiler &compiler, ShaderInput *param1, ShaderInput *param2);
  578. virtual int get_group()
  579. {
  580. return NODE_GROUP_LEVEL_1;
  581. }
  582. virtual int get_feature()
  583. {
  584. return ShaderNode::get_feature() | NODE_FEATURE_VOLUME;
  585. }
  586. virtual ClosureType get_closure_type()
  587. {
  588. return closure;
  589. }
  590. virtual bool has_volume_support()
  591. {
  592. return true;
  593. }
  594. float3 color;
  595. float density;
  596. float volume_mix_weight;
  597. ClosureType closure;
  598. virtual bool equals(const ShaderNode & /*other*/)
  599. {
  600. /* TODO(sergey): With some care Volume nodes can be de-duplicated. */
  601. return false;
  602. }
  603. };
  604. class AbsorptionVolumeNode : public VolumeNode {
  605. public:
  606. SHADER_NODE_CLASS(AbsorptionVolumeNode)
  607. };
  608. class ScatterVolumeNode : public VolumeNode {
  609. public:
  610. SHADER_NODE_CLASS(ScatterVolumeNode)
  611. float anisotropy;
  612. };
  613. class PrincipledVolumeNode : public VolumeNode {
  614. public:
  615. SHADER_NODE_CLASS(PrincipledVolumeNode)
  616. void attributes(Shader *shader, AttributeRequestSet *attributes);
  617. bool has_attribute_dependency()
  618. {
  619. return true;
  620. }
  621. ustring density_attribute;
  622. ustring color_attribute;
  623. ustring temperature_attribute;
  624. float anisotropy;
  625. float3 absorption_color;
  626. float emission_strength;
  627. float3 emission_color;
  628. float blackbody_intensity;
  629. float3 blackbody_tint;
  630. float temperature;
  631. };
  632. /* Interface between the I/O sockets and the SVM/OSL backend. */
  633. class PrincipledHairBsdfNode : public BsdfBaseNode {
  634. public:
  635. SHADER_NODE_CLASS(PrincipledHairBsdfNode)
  636. void attributes(Shader *shader, AttributeRequestSet *attributes);
  637. /* Longitudinal roughness. */
  638. float roughness;
  639. /* Azimuthal roughness. */
  640. float radial_roughness;
  641. /* Randomization factor for roughnesses. */
  642. float random_roughness;
  643. /* Longitudinal roughness factor for only the diffuse bounce (shiny undercoat). */
  644. float coat;
  645. /* Index of reflection. */
  646. float ior;
  647. /* Cuticle tilt angle. */
  648. float offset;
  649. /* Direct coloring's color. */
  650. float3 color;
  651. /* Melanin concentration. */
  652. float melanin;
  653. /* Melanin redness ratio. */
  654. float melanin_redness;
  655. /* Dye color. */
  656. float3 tint;
  657. /* Randomization factor for melanin quantities. */
  658. float random_color;
  659. /* Absorption coefficient (unfiltered). */
  660. float3 absorption_coefficient;
  661. float3 normal;
  662. float surface_mix_weight;
  663. /* If linked, here will be the given random number. */
  664. float random;
  665. /* Selected coloring parametrization. */
  666. NodePrincipledHairParametrization parametrization;
  667. };
  668. class HairBsdfNode : public BsdfNode {
  669. public:
  670. SHADER_NODE_CLASS(HairBsdfNode)
  671. ClosureType get_closure_type()
  672. {
  673. return component;
  674. }
  675. ClosureType component;
  676. float offset;
  677. float roughness_u;
  678. float roughness_v;
  679. float3 tangent;
  680. };
  681. class GeometryNode : public ShaderNode {
  682. public:
  683. SHADER_NODE_CLASS(GeometryNode)
  684. void attributes(Shader *shader, AttributeRequestSet *attributes);
  685. bool has_attribute_dependency()
  686. {
  687. return true;
  688. }
  689. bool has_spatial_varying()
  690. {
  691. return true;
  692. }
  693. int get_group();
  694. float3 normal_osl;
  695. };
  696. class TextureCoordinateNode : public ShaderNode {
  697. public:
  698. SHADER_NODE_CLASS(TextureCoordinateNode)
  699. void attributes(Shader *shader, AttributeRequestSet *attributes);
  700. bool has_attribute_dependency()
  701. {
  702. return true;
  703. }
  704. bool has_spatial_varying()
  705. {
  706. return true;
  707. }
  708. bool has_object_dependency()
  709. {
  710. return use_transform;
  711. }
  712. float3 normal_osl;
  713. bool from_dupli;
  714. bool use_transform;
  715. Transform ob_tfm;
  716. };
  717. class UVMapNode : public ShaderNode {
  718. public:
  719. SHADER_NODE_CLASS(UVMapNode)
  720. void attributes(Shader *shader, AttributeRequestSet *attributes);
  721. bool has_attribute_dependency()
  722. {
  723. return true;
  724. }
  725. bool has_spatial_varying()
  726. {
  727. return true;
  728. }
  729. virtual int get_group()
  730. {
  731. return NODE_GROUP_LEVEL_1;
  732. }
  733. ustring attribute;
  734. bool from_dupli;
  735. };
  736. class LightPathNode : public ShaderNode {
  737. public:
  738. SHADER_NODE_CLASS(LightPathNode)
  739. virtual int get_group()
  740. {
  741. return NODE_GROUP_LEVEL_1;
  742. }
  743. };
  744. class LightFalloffNode : public ShaderNode {
  745. public:
  746. SHADER_NODE_CLASS(LightFalloffNode)
  747. bool has_spatial_varying()
  748. {
  749. return true;
  750. }
  751. virtual int get_group()
  752. {
  753. return NODE_GROUP_LEVEL_2;
  754. }
  755. float strength;
  756. float smooth;
  757. };
  758. class ObjectInfoNode : public ShaderNode {
  759. public:
  760. SHADER_NODE_CLASS(ObjectInfoNode)
  761. virtual int get_group()
  762. {
  763. return NODE_GROUP_LEVEL_1;
  764. }
  765. };
  766. class ParticleInfoNode : public ShaderNode {
  767. public:
  768. SHADER_NODE_CLASS(ParticleInfoNode)
  769. void attributes(Shader *shader, AttributeRequestSet *attributes);
  770. bool has_attribute_dependency()
  771. {
  772. return true;
  773. }
  774. virtual int get_group()
  775. {
  776. return NODE_GROUP_LEVEL_1;
  777. }
  778. };
  779. class HairInfoNode : public ShaderNode {
  780. public:
  781. SHADER_NODE_CLASS(HairInfoNode)
  782. void attributes(Shader *shader, AttributeRequestSet *attributes);
  783. bool has_attribute_dependency()
  784. {
  785. return true;
  786. }
  787. bool has_spatial_varying()
  788. {
  789. return true;
  790. }
  791. virtual int get_group()
  792. {
  793. return NODE_GROUP_LEVEL_1;
  794. }
  795. virtual int get_feature()
  796. {
  797. return ShaderNode::get_feature() | NODE_FEATURE_HAIR;
  798. }
  799. };
  800. class ValueNode : public ShaderNode {
  801. public:
  802. SHADER_NODE_CLASS(ValueNode)
  803. void constant_fold(const ConstantFolder &folder);
  804. float value;
  805. };
  806. class ColorNode : public ShaderNode {
  807. public:
  808. SHADER_NODE_CLASS(ColorNode)
  809. void constant_fold(const ConstantFolder &folder);
  810. float3 value;
  811. };
  812. class AddClosureNode : public ShaderNode {
  813. public:
  814. SHADER_NODE_CLASS(AddClosureNode)
  815. void constant_fold(const ConstantFolder &folder);
  816. };
  817. class MixClosureNode : public ShaderNode {
  818. public:
  819. SHADER_NODE_CLASS(MixClosureNode)
  820. void constant_fold(const ConstantFolder &folder);
  821. float fac;
  822. };
  823. class MixClosureWeightNode : public ShaderNode {
  824. public:
  825. SHADER_NODE_CLASS(MixClosureWeightNode)
  826. float weight;
  827. float fac;
  828. };
  829. class InvertNode : public ShaderNode {
  830. public:
  831. SHADER_NODE_CLASS(InvertNode)
  832. void constant_fold(const ConstantFolder &folder);
  833. virtual int get_group()
  834. {
  835. return NODE_GROUP_LEVEL_3;
  836. }
  837. float fac;
  838. float3 color;
  839. };
  840. class MixNode : public ShaderNode {
  841. public:
  842. SHADER_NODE_CLASS(MixNode)
  843. void constant_fold(const ConstantFolder &folder);
  844. virtual int get_group()
  845. {
  846. return NODE_GROUP_LEVEL_3;
  847. }
  848. NodeMix type;
  849. bool use_clamp;
  850. float3 color1;
  851. float3 color2;
  852. float fac;
  853. };
  854. class CombineRGBNode : public ShaderNode {
  855. public:
  856. SHADER_NODE_CLASS(CombineRGBNode)
  857. void constant_fold(const ConstantFolder &folder);
  858. virtual int get_group()
  859. {
  860. return NODE_GROUP_LEVEL_3;
  861. }
  862. float r, g, b;
  863. };
  864. class CombineHSVNode : public ShaderNode {
  865. public:
  866. SHADER_NODE_CLASS(CombineHSVNode)
  867. void constant_fold(const ConstantFolder &folder);
  868. virtual int get_group()
  869. {
  870. return NODE_GROUP_LEVEL_3;
  871. }
  872. float h, s, v;
  873. };
  874. class CombineXYZNode : public ShaderNode {
  875. public:
  876. SHADER_NODE_CLASS(CombineXYZNode)
  877. void constant_fold(const ConstantFolder &folder);
  878. virtual int get_group()
  879. {
  880. return NODE_GROUP_LEVEL_3;
  881. }
  882. float x, y, z;
  883. };
  884. class GammaNode : public ShaderNode {
  885. public:
  886. SHADER_NODE_CLASS(GammaNode)
  887. void constant_fold(const ConstantFolder &folder);
  888. virtual int get_group()
  889. {
  890. return NODE_GROUP_LEVEL_1;
  891. }
  892. float3 color;
  893. float gamma;
  894. };
  895. class BrightContrastNode : public ShaderNode {
  896. public:
  897. SHADER_NODE_CLASS(BrightContrastNode)
  898. void constant_fold(const ConstantFolder &folder);
  899. virtual int get_group()
  900. {
  901. return NODE_GROUP_LEVEL_1;
  902. }
  903. float3 color;
  904. float bright;
  905. float contrast;
  906. };
  907. class SeparateRGBNode : public ShaderNode {
  908. public:
  909. SHADER_NODE_CLASS(SeparateRGBNode)
  910. void constant_fold(const ConstantFolder &folder);
  911. virtual int get_group()
  912. {
  913. return NODE_GROUP_LEVEL_3;
  914. }
  915. float3 color;
  916. };
  917. class SeparateHSVNode : public ShaderNode {
  918. public:
  919. SHADER_NODE_CLASS(SeparateHSVNode)
  920. void constant_fold(const ConstantFolder &folder);
  921. virtual int get_group()
  922. {
  923. return NODE_GROUP_LEVEL_3;
  924. }
  925. float3 color;
  926. };
  927. class SeparateXYZNode : public ShaderNode {
  928. public:
  929. SHADER_NODE_CLASS(SeparateXYZNode)
  930. void constant_fold(const ConstantFolder &folder);
  931. virtual int get_group()
  932. {
  933. return NODE_GROUP_LEVEL_3;
  934. }
  935. float3 vector;
  936. };
  937. class HSVNode : public ShaderNode {
  938. public:
  939. SHADER_NODE_CLASS(HSVNode)
  940. float hue;
  941. float saturation;
  942. float value;
  943. float fac;
  944. float3 color;
  945. };
  946. class AttributeNode : public ShaderNode {
  947. public:
  948. SHADER_NODE_CLASS(AttributeNode)
  949. void attributes(Shader *shader, AttributeRequestSet *attributes);
  950. bool has_attribute_dependency()
  951. {
  952. return true;
  953. }
  954. bool has_spatial_varying()
  955. {
  956. return true;
  957. }
  958. ustring attribute;
  959. };
  960. class CameraNode : public ShaderNode {
  961. public:
  962. SHADER_NODE_CLASS(CameraNode)
  963. bool has_spatial_varying()
  964. {
  965. return true;
  966. }
  967. virtual int get_group()
  968. {
  969. return NODE_GROUP_LEVEL_2;
  970. }
  971. };
  972. class FresnelNode : public ShaderNode {
  973. public:
  974. SHADER_NODE_CLASS(FresnelNode)
  975. bool has_spatial_varying()
  976. {
  977. return true;
  978. }
  979. virtual int get_group()
  980. {
  981. return NODE_GROUP_LEVEL_1;
  982. }
  983. float3 normal;
  984. float IOR;
  985. };
  986. class LayerWeightNode : public ShaderNode {
  987. public:
  988. SHADER_NODE_CLASS(LayerWeightNode)
  989. bool has_spatial_varying()
  990. {
  991. return true;
  992. }
  993. virtual int get_group()
  994. {
  995. return NODE_GROUP_LEVEL_1;
  996. }
  997. float3 normal;
  998. float blend;
  999. };
  1000. class WireframeNode : public ShaderNode {
  1001. public:
  1002. SHADER_NODE_CLASS(WireframeNode)
  1003. bool has_spatial_varying()
  1004. {
  1005. return true;
  1006. }
  1007. virtual int get_group()
  1008. {
  1009. return NODE_GROUP_LEVEL_3;
  1010. }
  1011. float size;
  1012. bool use_pixel_size;
  1013. };
  1014. class WavelengthNode : public ShaderNode {
  1015. public:
  1016. SHADER_NODE_CLASS(WavelengthNode)
  1017. virtual int get_group()
  1018. {
  1019. return NODE_GROUP_LEVEL_3;
  1020. }
  1021. float wavelength;
  1022. };
  1023. class BlackbodyNode : public ShaderNode {
  1024. public:
  1025. SHADER_NODE_CLASS(BlackbodyNode)
  1026. void constant_fold(const ConstantFolder &folder);
  1027. virtual int get_group()
  1028. {
  1029. return NODE_GROUP_LEVEL_3;
  1030. }
  1031. float temperature;
  1032. };
  1033. class MathNode : public ShaderNode {
  1034. public:
  1035. SHADER_NODE_CLASS(MathNode)
  1036. virtual int get_group()
  1037. {
  1038. return NODE_GROUP_LEVEL_1;
  1039. }
  1040. void constant_fold(const ConstantFolder &folder);
  1041. float value1;
  1042. float value2;
  1043. NodeMath type;
  1044. bool use_clamp;
  1045. };
  1046. class NormalNode : public ShaderNode {
  1047. public:
  1048. SHADER_NODE_CLASS(NormalNode)
  1049. virtual int get_group()
  1050. {
  1051. return NODE_GROUP_LEVEL_2;
  1052. }
  1053. float3 direction;
  1054. float3 normal;
  1055. };
  1056. class VectorMathNode : public ShaderNode {
  1057. public:
  1058. SHADER_NODE_CLASS(VectorMathNode)
  1059. virtual int get_group()
  1060. {
  1061. return NODE_GROUP_LEVEL_1;
  1062. }
  1063. void constant_fold(const ConstantFolder &folder);
  1064. float3 vector1;
  1065. float3 vector2;
  1066. NodeVectorMath type;
  1067. };
  1068. class VectorTransformNode : public ShaderNode {
  1069. public:
  1070. SHADER_NODE_CLASS(VectorTransformNode)
  1071. virtual int get_group()
  1072. {
  1073. return NODE_GROUP_LEVEL_3;
  1074. }
  1075. NodeVectorTransformType type;
  1076. NodeVectorTransformConvertSpace convert_from;
  1077. NodeVectorTransformConvertSpace convert_to;
  1078. float3 vector;
  1079. };
  1080. class BumpNode : public ShaderNode {
  1081. public:
  1082. SHADER_NODE_CLASS(BumpNode)
  1083. void constant_fold(const ConstantFolder &folder);
  1084. bool has_spatial_varying()
  1085. {
  1086. return true;
  1087. }
  1088. virtual int get_feature()
  1089. {
  1090. return NODE_FEATURE_BUMP;
  1091. }
  1092. bool invert;
  1093. bool use_object_space;
  1094. float height;
  1095. float sample_center;
  1096. float sample_x;
  1097. float sample_y;
  1098. float3 normal;
  1099. float strength;
  1100. float distance;
  1101. };
  1102. class CurvesNode : public ShaderNode {
  1103. public:
  1104. explicit CurvesNode(const NodeType *node_type);
  1105. SHADER_NODE_BASE_CLASS(CurvesNode)
  1106. virtual int get_group()
  1107. {
  1108. return NODE_GROUP_LEVEL_3;
  1109. }
  1110. array<float3> curves;
  1111. float min_x, max_x, fac;
  1112. float3 value;
  1113. protected:
  1114. using ShaderNode::constant_fold;
  1115. void constant_fold(const ConstantFolder &folder, ShaderInput *value_in);
  1116. void compile(SVMCompiler &compiler, int type, ShaderInput *value_in, ShaderOutput *value_out);
  1117. void compile(OSLCompiler &compiler, const char *name);
  1118. };
  1119. class RGBCurvesNode : public CurvesNode {
  1120. public:
  1121. SHADER_NODE_CLASS(RGBCurvesNode)
  1122. void constant_fold(const ConstantFolder &folder);
  1123. };
  1124. class VectorCurvesNode : public CurvesNode {
  1125. public:
  1126. SHADER_NODE_CLASS(VectorCurvesNode)
  1127. void constant_fold(const ConstantFolder &folder);
  1128. };
  1129. class RGBRampNode : public ShaderNode {
  1130. public:
  1131. SHADER_NODE_CLASS(RGBRampNode)
  1132. void constant_fold(const ConstantFolder &folder);
  1133. virtual int get_group()
  1134. {
  1135. return NODE_GROUP_LEVEL_1;
  1136. }
  1137. array<float3> ramp;
  1138. array<float> ramp_alpha;
  1139. float fac;
  1140. bool interpolate;
  1141. };
  1142. class SetNormalNode : public ShaderNode {
  1143. public:
  1144. SHADER_NODE_CLASS(SetNormalNode)
  1145. float3 direction;
  1146. };
  1147. class OSLNode : public ShaderNode {
  1148. public:
  1149. static OSLNode *create(size_t num_inputs, const OSLNode *from = NULL);
  1150. ~OSLNode();
  1151. ShaderNode *clone() const;
  1152. char *input_default_value();
  1153. void add_input(ustring name, SocketType::Type type);
  1154. void add_output(ustring name, SocketType::Type type);
  1155. SHADER_NODE_NO_CLONE_CLASS(OSLNode)
  1156. /* ideally we could beter detect this, but we can't query this now */
  1157. bool has_spatial_varying()
  1158. {
  1159. return true;
  1160. }
  1161. bool has_volume_support()
  1162. {
  1163. return true;
  1164. }
  1165. virtual bool equals(const ShaderNode & /*other*/)
  1166. {
  1167. return false;
  1168. }
  1169. string filepath;
  1170. string bytecode_hash;
  1171. };
  1172. class NormalMapNode : public ShaderNode {
  1173. public:
  1174. SHADER_NODE_CLASS(NormalMapNode)
  1175. void attributes(Shader *shader, AttributeRequestSet *attributes);
  1176. bool has_attribute_dependency()
  1177. {
  1178. return true;
  1179. }
  1180. bool has_spatial_varying()
  1181. {
  1182. return true;
  1183. }
  1184. virtual int get_group()
  1185. {
  1186. return NODE_GROUP_LEVEL_3;
  1187. }
  1188. NodeNormalMapSpace space;
  1189. ustring attribute;
  1190. float strength;
  1191. float3 color;
  1192. float3 normal_osl;
  1193. };
  1194. class TangentNode : public ShaderNode {
  1195. public:
  1196. SHADER_NODE_CLASS(TangentNode)
  1197. void attributes(Shader *shader, AttributeRequestSet *attributes);
  1198. bool has_attribute_dependency()
  1199. {
  1200. return true;
  1201. }
  1202. bool has_spatial_varying()
  1203. {
  1204. return true;
  1205. }
  1206. virtual int get_group()
  1207. {
  1208. return NODE_GROUP_LEVEL_3;
  1209. }
  1210. NodeTangentDirectionType direction_type;
  1211. NodeTangentAxis axis;
  1212. ustring attribute;
  1213. float3 normal_osl;
  1214. };
  1215. class BevelNode : public ShaderNode {
  1216. public:
  1217. SHADER_NODE_CLASS(BevelNode)
  1218. bool has_spatial_varying()
  1219. {
  1220. return true;
  1221. }
  1222. virtual int get_group()
  1223. {
  1224. return NODE_GROUP_LEVEL_3;
  1225. }
  1226. virtual bool has_raytrace()
  1227. {
  1228. return true;
  1229. }
  1230. float radius;
  1231. float3 normal;
  1232. int samples;
  1233. };
  1234. class DisplacementNode : public ShaderNode {
  1235. public:
  1236. SHADER_NODE_CLASS(DisplacementNode)
  1237. void constant_fold(const ConstantFolder &folder);
  1238. virtual int get_feature()
  1239. {
  1240. return NODE_FEATURE_BUMP;
  1241. }
  1242. NodeNormalMapSpace space;
  1243. float height;
  1244. float midlevel;
  1245. float scale;
  1246. float3 normal;
  1247. };
  1248. class VectorDisplacementNode : public ShaderNode {
  1249. public:
  1250. SHADER_NODE_CLASS(VectorDisplacementNode)
  1251. void attributes(Shader *shader, AttributeRequestSet *attributes);
  1252. bool has_attribute_dependency()
  1253. {
  1254. return true;
  1255. }
  1256. void constant_fold(const ConstantFolder &folder);
  1257. virtual int get_feature()
  1258. {
  1259. return NODE_FEATURE_BUMP;
  1260. }
  1261. NodeNormalMapSpace space;
  1262. ustring attribute;
  1263. float3 vector;
  1264. float midlevel;
  1265. float scale;
  1266. };
  1267. CCL_NAMESPACE_END
  1268. #endif /* __NODES_H__ */