49 descriptor.
type = type;
62 connector.
input = input;
86 v_header =
"#version 150\n\n" 87 "uniform mat4 _objectModelviewMatrix;\n" 88 "uniform mat4 _projectionMatrix;\n" 89 "uniform mat4 _modelviewMatrix;\n";
91 v_body =
"void main(void) {\n" 92 " mat4 mo = (_modelviewMatrix * _objectModelviewMatrix);\n";
95 f_header =
"#version 150\n\n" 96 "precision highp float;\n\n" 97 "uniform float _alpha;\n";
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";
104 v_header =
"#version 120\n\n" 105 "uniform mat4 _objectModelviewMatrix;\n" 106 "uniform mat4 _projectionMatrix;\n" 107 "uniform mat4 _modelviewMatrix;\n";
109 v_body =
"void main(void) {\n" 110 " mat4 mo = (_modelviewMatrix * _objectModelviewMatrix);\n";
112 f_header =
"#version 120\n\n" 113 "uniform float _alpha;\n";
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";
131 f_header +=
"uniform vec4 _colour;\n";
167 input_desc_string =
"in vec3 inputPosition0;\n";
168 output_desc_string =
"out vec3 position0;\n";
169 f_desc_string =
"in vec3 position0;\n";
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";
176 body_desc_string =
"vec4 _vertex = mo * vec4(inputPosition0.xyz, 1.0f);\n" 177 "gl_Position = _projectionMatrix * _vertex;\n" 178 "position0 = vec3(_vertex);\n";
182 input_desc_string =
"in vec3 inputPosition1;\n";
183 output_desc_string =
"out vec3 position1;\n";
184 f_desc_string =
"in vec3 position1;\n";
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";
190 body_desc_string =
"position1 = inputPosition1;\n";
194 input_desc_string =
"in vec3 inputPosition2;\n";
195 output_desc_string =
"out vec3 position2;\n";
196 f_desc_string =
"in vec3 position2;\n";
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";
202 body_desc_string =
"position2 = inputPosition2;\n";
206 input_desc_string =
"in vec3 inputPosition3;\n";
207 output_desc_string =
"out vec3 position3;\n";
208 f_desc_string =
"in vec3 position3;\n";
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";
214 body_desc_string =
"position3 = inputPosition3;\n";
218 input_desc_string =
"in vec3 inputNormal0;\n";
219 output_desc_string =
"out vec3 normal0;\n";
220 f_desc_string =
"in vec3 normal0;\n";
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";
227 body_desc_string =
"normal0 = inputNormal0.xyz;\n";
231 input_desc_string =
"in vec3 inputNormal1;\n";
232 output_desc_string =
"out vec3 normal1;\n";
233 f_desc_string =
"in vec3 normal1;\n";
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";
242 input_desc_string =
"in vec3 inputNormal2;\n";
243 output_desc_string =
"out vec3 normal2;\n";
244 f_desc_string =
"in vec3 normal2;\n";
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";
253 input_desc_string =
"in vec3 inputNormal3;\n";
254 output_desc_string =
"out vec3 normal3;\n";
255 f_desc_string =
"in vec3 normal3;\n";
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";
264 input_desc_string =
"in vec2 inputUV0;\n";
265 output_desc_string =
"out vec2 uv0;\n";
266 f_desc_string =
"in vec2 uv0;\n";
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";
272 body_desc_string =
"uv0 = inputUV0.xy;\n";
276 input_desc_string =
"in vec2 inputUV1;\n";
277 output_desc_string =
"out vec2 uv1;\n";
278 f_desc_string =
"in vec2 uv1;\n";
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";
284 body_desc_string =
"uv1 = inputUV1.xy;\n";
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";
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";
298 body_desc_string =
"uv0 = (_uv0Matrix * vec4(inputUV0.xy, 0.0, 1.0)).xy;\n";
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";
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";
312 body_desc_string =
"uv1 = (_uv1Matrix * vec4(inputUV1.xy, 0.0, 1.0)).xy;\n";
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";
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";
324 body_desc_string =
" vec3 ucube = normalize(position0);\n" 325 " vec3 ncube = normalize(normal0);\n" 326 " uvCube = reflect(ucube, ncube);\n";
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";
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";
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";
346 input_desc_string =
"in vec4 inputColour;\n";
347 output_desc_string =
"out vec4 xColour;\n";
348 f_desc_string =
"in vec4 xColour;\n";
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";
354 body_desc_string =
"xColour = inputColour;\n";
356 v_header += input_desc_string;
357 v_header += output_desc_string;
358 v_body += body_desc_string;
359 f_header += f_desc_string;
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;
392 sampler_id_string +=
"_id";
394 sampler_descriptor_string += sampler_type_string;
395 sampler_descriptor_string +=
" ";
396 sampler_descriptor_string += sampler_id_string;
397 sampler_descriptor_string +=
";\n";
399 f_header += sampler_descriptor_string;
438 case INPUT_UV0: f_input_string =
"uv0";
break;
439 case INPUT_UV1: f_input_string =
"uv1";
break;
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;
456 case FORCE_OPAQUE: f_action_string =
"force_opaque";
break;
457 case NOOP: f_action_string =
"noop";
break;
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;
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;
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;
490 for (
size_t i = 0; i <
_passes.size(); ++i) {
495 f_action_string =
"froggle = texture(action_env_cube_sampler, action_env_cube_coords);\n";
497 f_action_string =
"froggle = textureCube(action_env_cube_sampler, action_env_cube_coords);\n";
502 f_action_string =
"froggle = texture(action_env_sphere_sampler, action_env_sphere_coords);\n";
504 f_action_string =
"froggle = texture2D(action_env_sphere_sampler, action_env_sphere_coords);\n";
508 f_action_string =
"froggle = _colour; // TODO: colour is not a sampler.\n";
511 f_action_string =
"froggle = xColour; // TODO: colour is not a sampler.\n";
515 f_action_string =
"froggle = texture(action_diffuse_sampler, action_diffuse_coords);\n";
517 f_action_string =
"froggle = texture2D(action_diffuse_sampler, action_diffuse_coords);\n";
522 f_action_string =
"froggle = vec4(texture(action_lightmap_sampler, action_lightmap_coords).xyz, 1.0);\n";
524 f_action_string =
"froggle = vec4(texture2D(action_lightmap_sampler, action_lightmap_coords).xyz, 1.0);\n";
529 f_action_string =
"froggle = texture(action_bumpmap_sampler, action_bumpmap_coords);\n";
531 f_action_string =
"froggle = texture2D(action_bumpmap_sampler, action_bumpmap_coords);\n";
535 f_action_string =
"fraggle.a = 1.0f;\n";
538 f_action_string =
"// noop;\n";
545 f_blend_string =
"fraggle = mix(fraggle, froggle, froggle.a);\n";
548 f_blend_string =
"fraggle += (froggle * (1.0f - fraggle.a));\n";
551 f_blend_string =
"\n";
554 f_blend_string =
"fraggle = froggle;\n";
557 f_blend_string =
"fraggle *= froggle;\n";
563 f_body += f_action_string;
564 f_body += f_blend_string;
573 f_body +=
"fraggle.a = fraggle.a * _alpha;\n" 574 "outColor = fraggle;\n" 579 f_body +=
"fraggle.a = fraggle.a * _alpha;\n" 580 "gl_FragColor = fraggle;\n" 592 v_string = v_header + v_body;
593 f_string = f_header + f_body;
616 case INPUT_UV0: n_string +=
"input_uv0";
break;
617 case INPUT_UV1: n_string +=
"input_uv1";
break;
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;
674 case INPUT_UV0: n_string +=
"input_uv0";
break;
675 case INPUT_UV1: n_string +=
"input_uv1";
break;
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;
693 case NOOP: n_string +=
"noop";
break;
697 for (
size_t i = 0; i <
_passes.size(); ++i) {
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;
708 case NOOP: n_string +=
"noop";
break;
715 case BLEND_ZERO: n_string +=
"blend_zero";
break;
716 case BLEND_ONE: n_string +=
"blend_one";
break;
Input
< Vertex shader input data. Each should have a corresponding output.
void build(bool isGL3, Common::UString &v_string, Common::UString &f_string)
Not strictly speaking an input, but generated for an output.
A class holding an UTF-8 string.
std::vector< Input > _inputDescriptors
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.
void clear()
Clear shader descriptor information.
Not strictly speaking an input, but generated for an output.
Not really blending, but component-wise multiply.
void declareUniform(ShaderDescriptor::Uniform uniform)
std::vector< Pass > _passes
std::vector< Connector > _connectors
std::vector< UniformDescriptor > _uniformDescriptors
Same as INPUT_UV0, but specifies input matrix too.
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
void declareInput(ShaderDescriptor::Input input)
Per-vertex colour information.