xoreos  0.0.5
shaderbuilder.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
31 
32 namespace Graphics {
33 
34 namespace Shader {
35 
37 }
38 
40 }
41 
43  _inputDescriptors.push_back(input);
44 }
45 
47  SamplerDescriptor descriptor = {};
48  descriptor.sampler = sampler;
49  descriptor.type = type;
50  _samplerDescriptors.push_back(descriptor);
51 }
52 
54  UniformDescriptor descriptor = {};
55  descriptor.uniform = uniform;
56  _uniformDescriptors.push_back(descriptor);
57 }
58 
60  Connector connector = {};
61  connector.sampler = sampler;
62  connector.input = input;
63  connector.action = action;
64  _connectors.push_back(connector);
65 }
66 
68  Pass pass = {};
69  pass.action = action;
70  pass.blend = blend;
71  _passes.push_back(pass);
72 }
73 
74 void ShaderDescriptor::build(bool isGL3, Common::UString &v_string, Common::UString &f_string) {
75  Common::UString v_header, f_header;
76  Common::UString v_body, f_body;
77 
78 
85  if (isGL3) {
86  v_header = "#version 150\n\n"
87  "uniform mat4 _objectModelviewMatrix;\n"
88  "uniform mat4 _projectionMatrix;\n"
89  "uniform mat4 _modelviewMatrix;\n";
90 
91  v_body = "void main(void) {\n"
92  " mat4 mo = (_modelviewMatrix * _objectModelviewMatrix);\n";
93 
94 
95  f_header = "#version 150\n\n"
96  "precision highp float;\n\n"
97  "uniform float _alpha;\n";
98 
99  f_body = "out vec4 outColor;\n"
100  "void main(void) {\n"
101  " vec4 fraggle = vec4(1.0, 0.0, 0.0, 1.0);\n"
102  " vec4 froggle = vec4(1.0, 0.0, 0.0, 1.0);\n";
103  } else {
104  v_header = "#version 120\n\n"
105  "uniform mat4 _objectModelviewMatrix;\n"
106  "uniform mat4 _projectionMatrix;\n"
107  "uniform mat4 _modelviewMatrix;\n";
108 
109  v_body = "void main(void) {\n"
110  " mat4 mo = (_modelviewMatrix * _objectModelviewMatrix);\n";
111 
112  f_header = "#version 120\n\n"
113  "uniform float _alpha;\n";
114 
115  f_body = "void main(void) {\n"
116  " vec4 fraggle = vec4(1.0, 0.0, 0.0, 1.0);\n"
117  " vec4 froggle = vec4(1.0, 0.0, 0.0, 1.0);\n";
118  }
119 
124  for (size_t i = 0; i < _uniformDescriptors.size(); ++i) {
125  switch (_uniformDescriptors[i].uniform) {
127  case UNIFORM_V_PROJECTION_MATRIX: break;
128  case UNIFOM_V_MODELVIEW_MATRIX: break;
129  case UNIFORM_F_ALPHA: break;
130  case UNIFORM_F_COLOUR:
131  f_header += "uniform vec4 _colour;\n";
132  break;
133  default: break;
134  }
135  }
136 
159  for (size_t i = 0; i < _inputDescriptors.size(); ++i) {
160  Common::UString input_desc_string;
161  Common::UString output_desc_string;
162  Common::UString body_desc_string;
163  Common::UString f_desc_string;
164  switch (_inputDescriptors[i]) {
165  case INPUT_POSITION0:
166  if (isGL3) {
167  input_desc_string = "in vec3 inputPosition0;\n";
168  output_desc_string = "out vec3 position0;\n";
169  f_desc_string = "in vec3 position0;\n";
170  } else {
171  input_desc_string = "#define inputPosition0 gl_Vertex\n";
172  output_desc_string = "varying vec3 position0;\n";
173  f_desc_string = "varying vec3 position0;\n";
174  }
176  body_desc_string = "vec4 _vertex = mo * vec4(inputPosition0.xyz, 1.0f);\n"
177  "gl_Position = _projectionMatrix * _vertex;\n"
178  "position0 = vec3(_vertex);\n";
179  break;
180  case INPUT_POSITION1:
181  if (isGL3) {
182  input_desc_string = "in vec3 inputPosition1;\n";
183  output_desc_string = "out vec3 position1;\n";
184  f_desc_string = "in vec3 position1;\n";
185  } else {
186  input_desc_string = "#define inputPosition1 gl_Vertex\n";
187  output_desc_string = "varying vec3 position1;\n";
188  f_desc_string = "varying vec3 position1;\n";
189  }
190  body_desc_string = "position1 = inputPosition1;\n";
191  break;
192  case INPUT_POSITION2:
193  if (isGL3) {
194  input_desc_string = "in vec3 inputPosition2;\n";
195  output_desc_string = "out vec3 position2;\n";
196  f_desc_string = "in vec3 position2;\n";
197  } else {
198  input_desc_string = "#define inputPosition2 gl_Vertex\n";
199  output_desc_string = "varying vec3 position2;\n";
200  f_desc_string = "varying vec3 position2;\n";
201  }
202  body_desc_string = "position2 = inputPosition2;\n";
203  break;
204  case INPUT_POSITION3:
205  if (isGL3) {
206  input_desc_string = "in vec3 inputPosition3;\n";
207  output_desc_string = "out vec3 position3;\n";
208  f_desc_string = "in vec3 position3;\n";
209  } else {
210  input_desc_string = "#define inputPosition3 gl_Vertex\n";
211  output_desc_string = "varying vec3 position3;\n";
212  f_desc_string = "varying vec3 position3;\n";
213  }
214  body_desc_string = "position3 = inputPosition3;\n";
215  break;
216  case INPUT_NORMAL0:
217  if (isGL3) {
218  input_desc_string = "in vec3 inputNormal0;\n";
219  output_desc_string = "out vec3 normal0;\n";
220  f_desc_string = "in vec3 normal0;\n";
221  } else {
222  input_desc_string = "#define inputNormal0 gl_Normal\n";
223  output_desc_string = "varying vec3 normal0;\n";
224  f_desc_string = "varying vec3 normal0;\n";
225  }
227  body_desc_string = "normal0 = inputNormal0.xyz;\n";
228  break;
229  case INPUT_NORMAL1:
230  if (isGL3) {
231  input_desc_string = "in vec3 inputNormal1;\n";
232  output_desc_string = "out vec3 normal1;\n";
233  f_desc_string = "in vec3 normal1;\n";
234  } else {
235  input_desc_string = "#define inputNormal1 gl_Normal\n";
236  output_desc_string = "varying vec3 normal1;\n";
237  f_desc_string = "varying vec3 normal1;\n";
238  }
239  break;
240  case INPUT_NORMAL2:
241  if (isGL3) {
242  input_desc_string = "in vec3 inputNormal2;\n";
243  output_desc_string = "out vec3 normal2;\n";
244  f_desc_string = "in vec3 normal2;\n";
245  } else {
246  input_desc_string = "#define inputNormal2 gl_Normal\n";
247  output_desc_string = "varying vec3 normal2;\n";
248  f_desc_string = "varying vec3 normal2;\n";
249  }
250  break;
251  case INPUT_NORMAL3:
252  if (isGL3) {
253  input_desc_string = "in vec3 inputNormal3;\n";
254  output_desc_string = "out vec3 normal3;\n";
255  f_desc_string = "in vec3 normal3;\n";
256  } else {
257  input_desc_string = "#define inputNormal3 gl_Normal\n";
258  output_desc_string = "varying vec3 normal3;\n";
259  f_desc_string = "varying vec3 normal3;\n";
260  }
261  break;
262  case INPUT_UV0:
263  if (isGL3) {
264  input_desc_string = "in vec2 inputUV0;\n";
265  output_desc_string = "out vec2 uv0;\n";
266  f_desc_string = "in vec2 uv0;\n";
267  } else {
268  input_desc_string = "#define inputUV0 gl_MultiTexCoord0\n";
269  output_desc_string = "varying vec2 uv0;\n";
270  f_desc_string = "varying vec2 uv0;\n";
271  }
272  body_desc_string = "uv0 = inputUV0.xy;\n";
273  break;
274  case INPUT_UV1:
275  if (isGL3) {
276  input_desc_string = "in vec2 inputUV1;\n";
277  output_desc_string = "out vec2 uv1;\n";
278  f_desc_string = "in vec2 uv1;\n";
279  } else {
280  input_desc_string = "#define inputUV1 gl_MultiTexCoord1\n";
281  output_desc_string = "varying vec2 uv1;\n";
282  f_desc_string = "varying vec2 uv1;\n";
283  }
284  body_desc_string = "uv1 = inputUV1.xy;\n";
285  break;
286  case INPUT_UV0_MATRIX:
287  if (isGL3) {
288  input_desc_string = "in vec2 inputUV0;\n"
289  "uniform mat4 _uv0Matrix;\n";
290  output_desc_string = "out vec2 uv0;\n";
291  f_desc_string = "in vec2 uv0;\n";
292  } else {
293  input_desc_string = "#define inputUV0 gl_MultiTexCoord0\n"
294  "uniform mat4 _uv0Matrix;\n";
295  output_desc_string = "varying vec2 uv0;\n";
296  f_desc_string = "varying vec2 uv0;\n";
297  }
298  body_desc_string = "uv0 = (_uv0Matrix * vec4(inputUV0.xy, 0.0, 1.0)).xy;\n";
299  break;
300  case INPUT_UV1_MATRIX:
301  if (isGL3) {
302  input_desc_string = "in vec2 inputUV1;\n"
303  "uniform mat2 _uv1Matrix;\n";
304  output_desc_string = "out vec2 uv1;\n";
305  f_desc_string = "in vec2 uv1;\n";
306  } else {
307  input_desc_string = "#define inputUV1 gl_MultiTexCoord1\n"
308  "uniform mat2 _uv1Matrix;\n";
309  output_desc_string = "varying vec2 uv1;\n";
310  f_desc_string = "varying vec2 uv1;\n";
311  }
312  body_desc_string = "uv1 = (_uv1Matrix * vec4(inputUV1.xy, 0.0, 1.0)).xy;\n";
313  break;
314  case INPUT_UV_CUBE:
315  if (isGL3) {
316  input_desc_string = "// UV Cube coordinates declared.\n";
317  output_desc_string = "out vec3 uvCube;\n";
318  f_desc_string = "in vec3 uvCube;\n";
319  } else {
320  input_desc_string = "// UV Cube coordinates declared.\n";
321  output_desc_string = "varying vec3 uvCube;\n";
322  f_desc_string = "varying vec3 uvCube;\n";
323  }
324  body_desc_string = " vec3 ucube = normalize(position0);\n"
325  " vec3 ncube = normalize(normal0);\n"
326  " uvCube = reflect(ucube, ncube);\n";
327  break;
328  case INPUT_UV_SPHERE:
329  if (isGL3) {
330  input_desc_string = "// UV Sphere coordinates declared.\n";
331  output_desc_string = "out vec2 uvSphere;\n";
332  f_desc_string = "in vec2 uvSphere;\n";
333  } else {
334  input_desc_string = "// UV Sphere coordinates declared.\n";
335  output_desc_string = "varying vec2 uvSphere;\n";
336  f_desc_string = "varying vec2 uvSphere;\n";
337  }
338  body_desc_string = " vec3 usphere = normalize(position0);\n"
339  " vec3 nsphere = normalize(normal0);\n"
340  " vec3 rsphere = reflect(usphere, nsphere);\n"
341  " float msphere = 2.0 * sqrt(rsphere.x * rsphere.x + rsphere.y * rsphere.y + (rsphere.z + 1.0) * (rsphere.z + 1.0));\n"
342  " uvSphere = vec2(rsphere.x / msphere + 0.5, rsphere.y / msphere + 0.5);\n";
343  break;
344  case INPUT_COLOUR:
345  if (isGL3) {
346  input_desc_string = "in vec4 inputColour;\n";
347  output_desc_string = "out vec4 xColour;\n";
348  f_desc_string = "in vec4 xColour;\n";
349  } else {
350  input_desc_string = "#define inputColour gl_Color\n";
351  output_desc_string = "varying vec4 xColour;\n";
352  f_desc_string = "varying vec4 xColour;\n";
353  }
354  body_desc_string = "xColour = inputColour;\n";
355  }
356  v_header += input_desc_string;
357  v_header += output_desc_string;
358  v_body += body_desc_string;
359  f_header += f_desc_string;
360  }
361 
369  for (size_t i = 0; i < _samplerDescriptors.size(); ++i) {
370  Common::UString sampler_descriptor_string = "uniform ";
371  Common::UString sampler_type_string = "sampler";
372  Common::UString sampler_id_string = "sampler_";
373  switch (_samplerDescriptors[i].type) {
374  case SAMPLER_1D: sampler_type_string += "1D"; break;
375  case SAMPLER_2D: sampler_type_string += "2D"; break;
376  case SAMPLER_3D: sampler_type_string += "3D"; break;
377  case SAMPLER_CUBE: sampler_type_string += "Cube"; break;
378  default: break;
379  }
380 
381  switch (_samplerDescriptors[i].sampler) {
382  case SAMPLER_TEXTURE_0: sampler_id_string += "0"; break;
383  case SAMPLER_TEXTURE_1: sampler_id_string += "1"; break;
384  case SAMPLER_TEXTURE_2: sampler_id_string += "2"; break;
385  case SAMPLER_TEXTURE_3: sampler_id_string += "3"; break;
386  case SAMPLER_TEXTURE_4: sampler_id_string += "4"; break;
387  case SAMPLER_TEXTURE_5: sampler_id_string += "5"; break;
388  case SAMPLER_TEXTURE_6: sampler_id_string += "6"; break;
389  case SAMPLER_TEXTURE_7: sampler_id_string += "7"; break;
390  case SAMPLER_TEXTURE_NONE: sampler_id_string += "uv"; break;
391  }
392  sampler_id_string += "_id";
393 
394  sampler_descriptor_string += sampler_type_string;
395  sampler_descriptor_string += " ";
396  sampler_descriptor_string += sampler_id_string;
397  sampler_descriptor_string += ";\n";
398 
399  f_header += sampler_descriptor_string;
400  }
401 
413  for (size_t i = 0; i < _connectors.size(); ++i) {
414 
415  Common::UString f_sampler_id_string;
416  switch (_connectors[i].sampler) {
417  case SAMPLER_TEXTURE_0: f_sampler_id_string = "0"; break;
418  case SAMPLER_TEXTURE_1: f_sampler_id_string = "1"; break;
419  case SAMPLER_TEXTURE_2: f_sampler_id_string = "2"; break;
420  case SAMPLER_TEXTURE_3: f_sampler_id_string = "3"; break;
421  case SAMPLER_TEXTURE_4: f_sampler_id_string = "4"; break;
422  case SAMPLER_TEXTURE_5: f_sampler_id_string = "5"; break;
423  case SAMPLER_TEXTURE_6: f_sampler_id_string = "6"; break;
424  case SAMPLER_TEXTURE_7: f_sampler_id_string = "7"; break;
425  case SAMPLER_TEXTURE_NONE: f_sampler_id_string = "uv"; break;
426  }
427 
428  Common::UString f_input_string;
429  switch (_connectors[i].input) {
430  case INPUT_POSITION0: f_input_string = "position0"; break;
431  case INPUT_POSITION1: f_input_string = "position1"; break;
432  case INPUT_POSITION2: f_input_string = "position2"; break;
433  case INPUT_POSITION3: f_input_string = "position3"; break;
434  case INPUT_NORMAL0: f_input_string = "normal0"; break;
435  case INPUT_NORMAL1: f_input_string = "normal1"; break;
436  case INPUT_NORMAL2: f_input_string = "normal2"; break;
437  case INPUT_NORMAL3: f_input_string = "normal3"; break;
438  case INPUT_UV0: f_input_string = "uv0"; break;
439  case INPUT_UV1: f_input_string = "uv1"; break;
440  case INPUT_UV0_MATRIX: f_input_string = "uv0"; break;
441  case INPUT_UV1_MATRIX: f_input_string = "uv1"; break;
442  case INPUT_UV_CUBE: f_input_string = "uvCube"; break;
443  case INPUT_UV_SPHERE: f_input_string = "uvSphere"; break;
444  case INPUT_COLOUR: f_input_string = "xColour"; break;
445  }
446 
447  Common::UString f_action_string;
448  switch (_connectors[i].action) {
449  case ENV_CUBE: f_action_string = "env_cube"; break;
450  case ENV_SPHERE: f_action_string = "env_sphere"; break;
451  case COLOUR: f_action_string = "colour"; break;
452  case X_COLOUR: f_action_string = "xcolour"; break;
453  case TEXTURE_DIFFUSE: f_action_string = "diffuse"; break;
454  case TEXTURE_LIGHTMAP: f_action_string = "lightmap"; break;
455  case TEXTURE_BUMPMAP: f_action_string = "bumpmap"; break;
456  case FORCE_OPAQUE: f_action_string = "force_opaque"; break;
457  case NOOP: f_action_string = "noop"; break;
458  }
459 
460  // Map an input to a sampler coordinate.
461  Common::UString f_connector_input_sampler_string = "#define sampler_";
462  f_connector_input_sampler_string += f_sampler_id_string;
463  f_connector_input_sampler_string += "_coords ";
464  f_connector_input_sampler_string += f_input_string;
465  f_connector_input_sampler_string += "\n";
466  f_header += f_connector_input_sampler_string;
467 
468  // Map a sampler to an action.
469  Common::UString f_connector_sampler_action_string = "#define action_";
470  f_connector_sampler_action_string += f_action_string;
471  f_connector_sampler_action_string += "_sampler sampler_";
472  f_connector_sampler_action_string += f_sampler_id_string;
473  f_connector_sampler_action_string += "_id";
474  f_connector_sampler_action_string += "\n";
475  f_header += f_connector_sampler_action_string;
476 
477  // Map an input to an action (identical to sampler coordinate).
478  Common::UString f_connector_input_action_string = "#define action_";
479  f_connector_input_action_string += f_action_string;
480  f_connector_input_action_string += "_coords ";
481  f_connector_input_action_string += f_input_string;
482  f_connector_input_action_string += "\n";
483  f_header += f_connector_input_action_string;
484  }
485 
486 
490  for (size_t i = 0; i < _passes.size(); ++i) {
491  Common::UString f_action_string;
492  switch (_passes[i].action) {
493  case ENV_CUBE:
494  if (isGL3) {
495  f_action_string = "froggle = texture(action_env_cube_sampler, action_env_cube_coords);\n";
496  } else {
497  f_action_string = "froggle = textureCube(action_env_cube_sampler, action_env_cube_coords);\n";
498  }
499  break;
500  case ENV_SPHERE:
501  if (isGL3) {
502  f_action_string = "froggle = texture(action_env_sphere_sampler, action_env_sphere_coords);\n";
503  } else {
504  f_action_string = "froggle = texture2D(action_env_sphere_sampler, action_env_sphere_coords);\n";
505  }
506  break;
507  case COLOUR:
508  f_action_string = "froggle = _colour; // TODO: colour is not a sampler.\n";
509  break;
510  case X_COLOUR:
511  f_action_string = "froggle = xColour; // TODO: colour is not a sampler.\n";
512  break;
513  case TEXTURE_DIFFUSE:
514  if (isGL3) {
515  f_action_string = "froggle = texture(action_diffuse_sampler, action_diffuse_coords);\n";
516  } else {
517  f_action_string = "froggle = texture2D(action_diffuse_sampler, action_diffuse_coords);\n";
518  }
519  break;
520  case TEXTURE_LIGHTMAP:
521  if (isGL3) {
522  f_action_string = "froggle = vec4(texture(action_lightmap_sampler, action_lightmap_coords).xyz, 1.0);\n";
523  } else {
524  f_action_string = "froggle = vec4(texture2D(action_lightmap_sampler, action_lightmap_coords).xyz, 1.0);\n";
525  }
526  break;
527  case TEXTURE_BUMPMAP:
528  if (isGL3) {
529  f_action_string = "froggle = texture(action_bumpmap_sampler, action_bumpmap_coords);\n";
530  } else {
531  f_action_string = "froggle = texture2D(action_bumpmap_sampler, action_bumpmap_coords);\n";
532  }
533  break;
534  case FORCE_OPAQUE:
535  f_action_string = "fraggle.a = 1.0f;\n";
536  break;
537  case NOOP:
538  f_action_string = "// noop;\n";
539  break;
540  }
541 
542  Common::UString f_blend_string;
543  switch (_passes[i].blend) {
544  case BLEND_SRC_ALPHA:
545  f_blend_string = "fraggle = mix(fraggle, froggle, froggle.a);\n";
546  break;
547  case BLEND_DST_ALPHA:
548  f_blend_string = "fraggle += (froggle * (1.0f - fraggle.a));\n";
549  break;
550  case BLEND_ZERO:
551  f_blend_string = "\n";
552  break;
553  case BLEND_ONE:
554  f_blend_string = "fraggle = froggle;\n";
555  break;
556  case BLEND_MULTIPLY:
557  f_blend_string = "fraggle *= froggle;\n";
558  break;
559  case BLEND_IGNORED:
560  break;
561  }
562 
563  f_body += f_action_string;
564  f_body += f_blend_string;
565  }
566 
570  if (isGL3) {
571  v_body += "}\n";
572 
573  f_body += "fraggle.a = fraggle.a * _alpha;\n"
574  "outColor = fraggle;\n"
575  "}\n";
576  } else {
577  v_body += "}\n";
578 
579  f_body += "fraggle.a = fraggle.a * _alpha;\n"
580  "gl_FragColor = fraggle;\n"
581  "}\n";
582  }
583 
589  Common::UString v_shader_string = v_header + v_body;
590  Common::UString f_shader_string = f_header + f_body;
591 
592  v_string = v_header + v_body;
593  f_string = f_header + f_body;
594 }
595 
597  _inputDescriptors.clear();
598  _samplerDescriptors.clear();
599  _uniformDescriptors.clear();
600  _connectors.clear();
601  _passes.clear();
602 }
603 
605  for (size_t i = 0; i < _inputDescriptors.size(); ++i) {
606  n_string += "__";
607  switch (_inputDescriptors[i]) {
608  case INPUT_POSITION0: n_string += "input_position0"; break;
609  case INPUT_POSITION1: n_string += "input_position1"; break;
610  case INPUT_POSITION2: n_string += "input_position2"; break;
611  case INPUT_POSITION3: n_string += "input_position3"; break;
612  case INPUT_NORMAL0: n_string += "input_normal0"; break;
613  case INPUT_NORMAL1: n_string += "input_normal1"; break;
614  case INPUT_NORMAL2: n_string += "input_normal2"; break;
615  case INPUT_NORMAL3: n_string += "input_normal3"; break;
616  case INPUT_UV0: n_string += "input_uv0"; break;
617  case INPUT_UV1: n_string += "input_uv1"; break;
618  case INPUT_UV0_MATRIX: n_string += "input_uv0"; break;
619  case INPUT_UV1_MATRIX: n_string += "input_uv1"; break;
620  case INPUT_UV_CUBE: n_string += "input_uv_cube"; break;
621  case INPUT_UV_SPHERE: n_string += "input_uv_sphere"; break;
622  case INPUT_COLOUR: n_string += "input_colour"; break;
623  }
624  }
625 
626  for (size_t i = 0; i < _samplerDescriptors.size(); ++i) {
627  n_string += "__";
628  switch (_samplerDescriptors[i].type) {
629  case SAMPLER_1D: n_string += "sampler_1d"; break;
630  case SAMPLER_2D: n_string += "sampler_2d"; break;
631  case SAMPLER_3D: n_string += "sampler_3d"; break;
632  case SAMPLER_CUBE: n_string += "sampler_cube"; break;
633  default: break;
634  }
635 
636  n_string += "-";
637  switch (_samplerDescriptors[i].sampler) {
638  case SAMPLER_TEXTURE_0: n_string += "texture0"; break;
639  case SAMPLER_TEXTURE_1: n_string += "texture1"; break;
640  case SAMPLER_TEXTURE_2: n_string += "texture2"; break;
641  case SAMPLER_TEXTURE_3: n_string += "texture3"; break;
642  case SAMPLER_TEXTURE_4: n_string += "texture4"; break;
643  case SAMPLER_TEXTURE_5: n_string += "texture5"; break;
644  case SAMPLER_TEXTURE_6: n_string += "texture6"; break;
645  case SAMPLER_TEXTURE_7: n_string += "texture7"; break;
646  case SAMPLER_TEXTURE_NONE: n_string += "textureUV"; break;
647  }
648  }
649 
650  for (size_t i = 0; i < _connectors.size(); ++i) {
651  n_string += "__";
652  switch (_connectors[i].sampler) {
653  case SAMPLER_TEXTURE_0: n_string += "texture0"; break;
654  case SAMPLER_TEXTURE_1: n_string += "texture1"; break;
655  case SAMPLER_TEXTURE_2: n_string += "texture2"; break;
656  case SAMPLER_TEXTURE_3: n_string += "texture3"; break;
657  case SAMPLER_TEXTURE_4: n_string += "texture4"; break;
658  case SAMPLER_TEXTURE_5: n_string += "texture5"; break;
659  case SAMPLER_TEXTURE_6: n_string += "texture6"; break;
660  case SAMPLER_TEXTURE_7: n_string += "texture7"; break;
661  case SAMPLER_TEXTURE_NONE: n_string += "textureUV"; break;
662  }
663 
664  n_string += "-";
665  switch (_connectors[i].input) {
666  case INPUT_POSITION0: n_string += "input_position0"; break;
667  case INPUT_POSITION1: n_string += "input_position1"; break;
668  case INPUT_POSITION2: n_string += "input_position2"; break;
669  case INPUT_POSITION3: n_string += "input_position3"; break;
670  case INPUT_NORMAL0: n_string += "input_normal0"; break;
671  case INPUT_NORMAL1: n_string += "input_normal1"; break;
672  case INPUT_NORMAL2: n_string += "input_normal2"; break;
673  case INPUT_NORMAL3: n_string += "input_normal3"; break;
674  case INPUT_UV0: n_string += "input_uv0"; break;
675  case INPUT_UV1: n_string += "input_uv1"; break;
676  case INPUT_UV0_MATRIX: n_string += "input_uv0"; break;
677  case INPUT_UV1_MATRIX: n_string += "input_uv1"; break;
678  case INPUT_UV_CUBE: n_string += "input_uv_cube"; break;
679  case INPUT_UV_SPHERE: n_string += "input_uv_sphere"; break;
680  case INPUT_COLOUR: n_string += "input_colour"; break;
681  }
682 
683  n_string += "-";
684  switch (_connectors[i].action) {
685  case ENV_CUBE: n_string += "env_cube"; break;
686  case ENV_SPHERE: n_string += "env_sphere"; break;
687  case COLOUR: n_string += "colour"; break;
688  case X_COLOUR: n_string += "xcolour"; break;
689  case TEXTURE_DIFFUSE: n_string += "diffuse"; break;
690  case TEXTURE_LIGHTMAP: n_string += "lightmap"; break;
691  case TEXTURE_BUMPMAP: n_string += "bumpmap"; break;
692  case FORCE_OPAQUE: n_string += "force_opaque"; break;
693  case NOOP: n_string += "noop"; break;
694  }
695  }
696 
697  for (size_t i = 0; i < _passes.size(); ++i) {
698  n_string += "__";
699  switch (_passes[i].action) {
700  case ENV_CUBE: n_string += "env_cube"; break;
701  case ENV_SPHERE: n_string += "env_sphere"; break;
702  case COLOUR: n_string += "colour"; break;
703  case X_COLOUR: n_string += "xcolour"; break;
704  case TEXTURE_DIFFUSE: n_string += "diffuse"; break;
705  case TEXTURE_LIGHTMAP: n_string += "lightmap"; break;
706  case TEXTURE_BUMPMAP: n_string += "bumpmap"; break;
707  case FORCE_OPAQUE: n_string += "force_opaque"; break;
708  case NOOP: n_string += "noop"; break;
709  }
710 
711  n_string += "-";
712  switch (_passes[i].blend) {
713  case BLEND_SRC_ALPHA: n_string += "blend_src_alpha"; break;
714  case BLEND_DST_ALPHA: n_string += "blend_dst_alpha"; break;
715  case BLEND_ZERO: n_string += "blend_zero"; break;
716  case BLEND_ONE: n_string += "blend_one"; break;
717  case BLEND_MULTIPLY: n_string += "blend_multiply"; break;
718  case BLEND_IGNORED: n_string += "blend_ignored"; break;
719  }
720  }
721 }
722 
723 } // End of namespace Shader
724 
725 } // End of namespace Graphics
Input
< Vertex shader input data. Each should have a corresponding output.
Definition: shaderbuilder.h:50
void build(bool isGL3, Common::UString &v_string, Common::UString &f_string)
Not strictly speaking an input, but generated for an output.
Definition: shaderbuilder.h:63
A class holding an UTF-8 string.
Definition: ustring.h:48
std::vector< Input > _inputDescriptors
Shader runtime builder.
void declareSampler(ShaderDescriptor::Sampler sampler, ShaderDescriptor::SamplerType type)
void connect(ShaderDescriptor::Sampler sampler, ShaderDescriptor::Input input, ShaderDescriptor::Action action)
Connect an input to a sampler and an action.
Same as INPUT_UV1, but specifies input matrix too.
Definition: shaderbuilder.h:62
void clear()
Clear shader descriptor information.
Not strictly speaking an input, but generated for an output.
Definition: shaderbuilder.h:64
Not really blending, but component-wise multiply.
void declareUniform(ShaderDescriptor::Uniform uniform)
std::vector< Connector > _connectors
std::vector< UniformDescriptor > _uniformDescriptors
Same as INPUT_UV0, but specifies input matrix too.
Definition: shaderbuilder.h:61
Uniform variable colour information.
Blending not applicable to the component.
void genName(Common::UString &n_string)
Generate a name to asscoiate with the current description.
void addPass(ShaderDescriptor::Action action, ShaderDescriptor::Blend blend)
std::vector< SamplerDescriptor > _samplerDescriptors
#define pass
Definition: fft.cpp:257
void declareInput(ShaderDescriptor::Input input)
Per-vertex colour information.