Free Electron
ShaderVariablesArnold.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __arnold_ShaderVariablesArnold_h__
8 #define __arnold_ShaderVariablesArnold_h__
9 
10 namespace fe
11 {
12 namespace ext
13 {
14 
15 /**************************************************************************//**
16  @brief Shader Variable Access
17 
18  @ingroup arnold
19 *//***************************************************************************/
20 class FE_DL_EXPORT ShaderVariablesArnold:
21  virtual public ShaderVariablesI
22 {
23  public:
25  m_pAtNode(NULL),
26  m_pAtShaderGlobals(NULL) {}
27 virtual ~ShaderVariablesArnold(void) {}
28 
29  //* as ShaderVariablesI
30 virtual String string(I32 a_channel) const
31  {
32  if(a_channel<paramOffset())
33  {
34  return (char*)((char*)&m_pAtShaderGlobals->x+
35  a_channel);
36  }
37  const String value=AiShaderEvalParamFuncStr(
38  m_pAtShaderGlobals,m_pAtNode,
39  a_channel-paramOffset());
40  return value;
41  }
42 
43 virtual I32 integer(I32 a_channel) const
44  {
45  if(a_channel<paramOffset())
46  {
47  return I32(*(I32*)
48  ((char*)&m_pAtShaderGlobals->x+
49  a_channel));
50  }
51  const I32 value=AiShaderEvalParamFuncInt(
52  m_pAtShaderGlobals,m_pAtNode,
53  a_channel-paramOffset());
54  return value;
55  }
56 
57 virtual Real real(I32 a_channel) const
58  {
59  if(a_channel<paramOffset())
60  {
61  return Real(*(float*)
62  ((char*)&m_pAtShaderGlobals->x+
63  a_channel));
64  }
65  const Real value=AiShaderEvalParamFuncFlt(
66  m_pAtShaderGlobals,m_pAtNode,
67  a_channel-paramOffset());
68  return value;
69  }
70 
71 virtual SpatialVector spatialVector(I32 a_channel) const
72  {
73  if(a_channel<paramOffset())
74  {
75  return SpatialVector(Vector3f((float*)
76  ((char*)&m_pAtShaderGlobals->x+
77  a_channel)));
78  }
79  const AtVector atVector=AiShaderEvalParamFuncVec(
80  m_pAtShaderGlobals,m_pAtNode,
81  a_channel-paramOffset());
82  return SpatialVector(atVector[0],
83  atVector[1],atVector[2]);
84  }
85 
86 virtual Color color(I32 a_channel) const
87  {
88  if(a_channel<paramOffset())
89  {
90  return Color(Vector3f((float*)
91  ((char*)&m_pAtShaderGlobals->x+
92  a_channel)));
93  }
94  const AtRGBA atRGBA=AiShaderEvalParamFuncRGBA(
95  m_pAtShaderGlobals,m_pAtNode,
96  a_channel-paramOffset());
97  return Color(atRGBA[0],atRGBA[1],
98  atRGBA[2],atRGBA[3]);
99  }
100 
101 virtual void set(String a_string)
102  {
103  m_pAtShaderGlobals->out.STR=a_string.c_str();
104  }
105 
106 virtual void set(I32 a_integer)
107  {
108  m_pAtShaderGlobals->out.INT=a_integer;
109  }
110 
111 virtual void set(Real a_real)
112  {
113  m_pAtShaderGlobals->out.FLT=a_real;
114  }
115 
116 virtual void set(SpatialVector a_spatialVector)
117  {
118  AtVector& rAtVector=m_pAtShaderGlobals->out.VEC;
119  rAtVector.x=a_spatialVector[0];
120  rAtVector.y=a_spatialVector[1];
121  rAtVector.z=a_spatialVector[2];
122  }
123 
124 virtual void set(Color a_color)
125  {
126  AtRGBA& rAtRGBA=m_pAtShaderGlobals->out.RGBA;
127  rAtRGBA.r=a_color[0];
128  rAtRGBA.g=a_color[1];
129  rAtRGBA.b=a_color[2];
130  rAtRGBA.a=a_color[3];
131  }
132 
133 static I32 variableOffset(String a_variable);
134 static I32 paramOffset(void) { return 1000; }
135 
136  //* as ShaderVariablesArnold
137  void setAtNode(AtNode* a_pAtNode)
138  { m_pAtNode=a_pAtNode; }
139 
140  void setAtShaderGlobals(AtShaderGlobals* a_pAtShaderGlobals)
141  { m_pAtShaderGlobals=a_pAtShaderGlobals; }
142 
143  private:
144 
145  AtNode* m_pAtNode;
146  AtShaderGlobals* m_pAtShaderGlobals;
147 };
148 
149 } /* namespace ext */
150 } /* namespace fe */
151 
152 #endif /* __arnold_ShaderVariablesArnold_h__ */
Surface Variable Access.
Definition: ShaderVariablesI.h:19
kernel
Definition: namespace.dox:3
Shader Variable Access.
Definition: ShaderVariablesArnold.h:20
Special vector for color (RGBA)
Definition: Color.h:21
Automatically reference-counted string container.
Definition: String.h:128