summaryrefslogtreecommitdiff
path: root/drivers/gles3/shader_compiler_gles3.cpp
blob: dce52ecd9347992af871fce43416dbcc9bc6261c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
#include "shader_compiler_gles3.h"
#include "os/os.h"

#define SL ShaderLanguage

static String _mktab(int p_level) {

	String tb;
	for(int i=0;i<p_level;i++) {
		tb+="\t";
	}

	return tb;
}

static String _typestr(SL::DataType p_type) {

	return ShaderLanguage::get_datatype_name(p_type);
}

static int _get_datatype_size(SL::DataType p_type) {

	switch(p_type) {

		case SL::TYPE_VOID: return 0;
		case SL::TYPE_BOOL: return 4;
		case SL::TYPE_BVEC2: return 8;
		case SL::TYPE_BVEC3: return 16;
		case SL::TYPE_BVEC4: return 16;
		case SL::TYPE_INT: return 4;
		case SL::TYPE_IVEC2: return 8;
		case SL::TYPE_IVEC3: return 16;
		case SL::TYPE_IVEC4: return 16;
		case SL::TYPE_UINT: return 4;
		case SL::TYPE_UVEC2: return 8;
		case SL::TYPE_UVEC3: return 16;
		case SL::TYPE_UVEC4: return 16;
		case SL::TYPE_FLOAT: return 4;
		case SL::TYPE_VEC2: return 8;
		case SL::TYPE_VEC3: return 16;
		case SL::TYPE_VEC4: return 16;
		case SL::TYPE_MAT2: return 16;
		case SL::TYPE_MAT3: return 48;
		case SL::TYPE_MAT4: return 64;
		case SL::TYPE_SAMPLER2D: return 16;
		case SL::TYPE_ISAMPLER2D: return 16;
		case SL::TYPE_USAMPLER2D: return 16;
		case SL::TYPE_SAMPLERCUBE: return 16;
	}

	ERR_FAIL_V(0);
}


static String _prestr(SL::DataPrecision p_pres) {


	switch(p_pres) {
		case SL::PRECISION_LOWP: return "lowp ";
		case SL::PRECISION_MEDIUMP: return "mediump ";
		case SL::PRECISION_HIGHP: return "highp ";
		case SL::PRECISION_DEFAULT: return "";
	}
	return "";
}


static String _opstr(SL::Operator p_op) {

	return SL::get_operator_text(p_op);
}

static String _mkid(const String& p_id) {

	return "m_"+p_id;
}

static String f2sp0(float p_float) {

	if (int(p_float)==p_float)
		return itos(p_float)+".0";
	else
		return rtoss(p_float);
}

static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNode::Value>& p_values) {

	switch(p_type) {
		case SL::TYPE_BOOL:  return p_values[0].boolean?"true":"false";
		case SL::TYPE_BVEC2:
		case SL::TYPE_BVEC3:
		case SL::TYPE_BVEC4: {


			String text="bvec"+itos(p_type-SL::TYPE_BOOL+1)+"(";
			for(int i=0;i<p_values.size();i++) {
				if (i>0)
					text+=",";

				text+=p_values[i].boolean?"true":"false";
			}
			text+=")";
			return text;
		}

		case SL::TYPE_INT:  return itos(p_values[0].sint);
		case SL::TYPE_IVEC2:
		case SL::TYPE_IVEC3:
		case SL::TYPE_IVEC4: {

			String text="ivec"+itos(p_type-SL::TYPE_INT+1)+"(";
			for(int i=0;i<p_values.size();i++) {
				if (i>0)
					text+=",";

				text+=itos(p_values[i].sint);
			}
			text+=")";
			return text;

		} break;
		case SL::TYPE_UINT:  return itos(p_values[0].uint)+"u";
		case SL::TYPE_UVEC2:
		case SL::TYPE_UVEC3:
		case SL::TYPE_UVEC4:   {

			String text="uvec"+itos(p_type-SL::TYPE_UINT+1)+"(";
			for(int i=0;i<p_values.size();i++) {
				if (i>0)
					text+=",";

				text+=itos(p_values[i].uint)+"u";
			}
			text+=")";
			return text;
		} break;
		case SL::TYPE_FLOAT:  return f2sp0(p_values[0].real)+"f";
		case SL::TYPE_VEC2:
		case SL::TYPE_VEC3:
		case SL::TYPE_VEC4:  {

			String text="vec"+itos(p_type-SL::TYPE_FLOAT+1)+"(";
			for(int i=0;i<p_values.size();i++) {
				if (i>0)
					text+=",";

				text+=f2sp0(p_values[i].real);
			}
			text+=")";
			return text;

		} break;
		default: ERR_FAIL_V(String());
	}
}

void ShaderCompilerGLES3::_dump_function_deps(SL::ShaderNode* p_node, const StringName& p_for_func, const Map<StringName,String>& p_func_code, String& r_to_add, Set<StringName> &added) {

	int fidx=-1;

	for(int i=0;i<p_node->functions.size();i++) {
		if (p_node->functions[i].name==p_for_func) {
			fidx=i;
			break;
		}
	}

	ERR_FAIL_COND(fidx==-1);

	for (Set<StringName>::Element *E=p_node->functions[fidx].uses_function.front();E;E=E->next()) {

		if (added.has(E->get())) {
			continue; //was added already
		}

		_dump_function_deps(p_node,E->get(),p_func_code,r_to_add,added);

		SL::FunctionNode *fnode=NULL;

		for(int i=0;i<p_node->functions.size();i++) {
			if (p_node->functions[i].name==E->get()) {
				fnode=p_node->functions[i].function;
				break;
			}
		}

		ERR_FAIL_COND(!fnode);

		r_to_add+="\n";

		String header;
		header=_typestr(fnode->return_type)+" "+_mkid(fnode->name)+"(";
		for(int i=0;i<fnode->arguments.size();i++) {

			if (i>0)
				header+=", ";
			header+=_prestr(fnode->arguments[i].precision)+_typestr(fnode->arguments[i].type)+" "+_mkid(fnode->arguments[i].name);
		}

		header+=")\n";
		r_to_add+=header;
		r_to_add+=p_func_code[E->get()];

		added.insert(E->get());
	}
}

String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, GeneratedCode& r_gen_code, IdentifierActions &p_actions, const DefaultIdentifierActions &p_default_actions) {

	String code;

	switch(p_node->type) {

		case SL::Node::TYPE_SHADER: {

			SL::ShaderNode *pnode=(SL::ShaderNode*)p_node;

			for(int i=0;i<pnode->render_modes.size();i++) {

				if (p_default_actions.render_mode_defines.has(pnode->render_modes[i]) && !used_rmode_defines.has(pnode->render_modes[i])) {

					r_gen_code.defines.push_back(p_default_actions.render_mode_defines[pnode->render_modes[i]].utf8());
					used_rmode_defines.insert(pnode->render_modes[i]);
				}

				if (p_actions.render_mode_flags.has(pnode->render_modes[i])) {
					*p_actions.render_mode_flags[pnode->render_modes[i]]=true;
				}

				if (p_actions.render_mode_values.has(pnode->render_modes[i])) {
					Pair<int*,int> &p = p_actions.render_mode_values[pnode->render_modes[i]];
					*p.first=p.second;
				}
			}


			int max_texture_uniforms=0;
			int max_uniforms=0;

			for(Map<StringName,SL::ShaderNode::Uniform>::Element *E=pnode->uniforms.front();E;E=E->next()) {
				if (SL::is_sampler_type(E->get().type))
					max_texture_uniforms++;
				else
					max_uniforms++;
			}

			r_gen_code.texture_uniforms.resize(max_texture_uniforms);
			r_gen_code.texture_hints.resize(max_texture_uniforms);

			Vector<int> uniform_sizes;
			uniform_sizes.resize(max_uniforms);

			for(Map<StringName,SL::ShaderNode::Uniform>::Element *E=pnode->uniforms.front();E;E=E->next()) {

				String ucode;

				if (SL::is_sampler_type(E->get().type)) {
					ucode="uniform ";
				}

				ucode+=_prestr(E->get().precission);
				ucode+=_typestr(E->get().type);
				ucode+=" "+_mkid(E->key());
				ucode+=";\n";
				if (SL::is_sampler_type(E->get().type)) {
					r_gen_code.vertex_global+=ucode;
					r_gen_code.fragment_global+=ucode;
					r_gen_code.texture_uniforms[E->get().texture_order]=_mkid(E->key());
					r_gen_code.texture_hints[E->get().texture_order]=E->get().hint;
				} else {
					if (r_gen_code.uniforms.empty()) {

						r_gen_code.defines.push_back(String("#define USE_MATERIAL\n").ascii());
					}
					r_gen_code.uniforms+=ucode;
					uniform_sizes[E->get().order]=_get_datatype_size(E->get().type);
				}

				p_actions.uniforms->insert(E->key(),E->get());

			}

			// add up
			for(int i=0;i<uniform_sizes.size();i++) {

				if (i>0)
					uniform_sizes[i]=uniform_sizes[i]+uniform_sizes[i-1];
			}
			//offset
			r_gen_code.uniform_offsets.resize(uniform_sizes.size());
			for(int i=0;i<uniform_sizes.size();i++) {

				if (i>0)
					r_gen_code.uniform_offsets[i]=uniform_sizes[i-1];
				else
					r_gen_code.uniform_offsets[i]=0;
			}

			if (uniform_sizes.size()) {
				r_gen_code.uniform_total_size=uniform_sizes[ uniform_sizes.size() -1 ];
			} else {
				r_gen_code.uniform_total_size=0;
			}

			for(Map<StringName,SL::ShaderNode::Varying>::Element *E=pnode->varyings.front();E;E=E->next()) {

				String vcode;
				vcode+=_prestr(E->get().precission);
				vcode+=_typestr(E->get().type);
				vcode+=" "+String(E->key());
				vcode+=";\n";
				r_gen_code.vertex_global+="out "+vcode;
				r_gen_code.fragment_global+="in "+vcode;
			}

			Map<StringName,String> function_code;

			//code for functions
			for(int i=0;i<pnode->functions.size();i++) {
				SL::FunctionNode *fnode=pnode->functions[i].function;
				function_code[fnode->name]=_dump_node_code(fnode->body,p_level+1,r_gen_code,p_actions,p_default_actions);
			}

			//place functions in actual code

			Set<StringName> added_vtx;
			Set<StringName> added_fragment; //share for light

			for(int i=0;i<pnode->functions.size();i++) {

				SL::FunctionNode *fnode=pnode->functions[i].function;

				current_func_name=fnode->name;

				if (fnode->name=="vertex") {

					_dump_function_deps(pnode,fnode->name,function_code,r_gen_code.vertex_global,added_vtx);
					r_gen_code.vertex=function_code["vertex"];
				}

				if (fnode->name=="fragment") {

					_dump_function_deps(pnode,fnode->name,function_code,r_gen_code.fragment_global,added_fragment);
					r_gen_code.fragment=function_code["fragment"];
				}

				if (fnode->name=="light") {

					_dump_function_deps(pnode,fnode->name,function_code,r_gen_code.fragment_global,added_fragment);
					r_gen_code.light=function_code["light"];
				}
			}

			//code+=dump_node_code(pnode->body,p_level);
		} break;
		case SL::Node::TYPE_FUNCTION: {

		} break;
		case SL::Node::TYPE_BLOCK: {
			SL::BlockNode *bnode=(SL::BlockNode*)p_node;

			//variables
			code+=_mktab(p_level-1)+"{\n";
			for(Map<StringName,SL::BlockNode::Variable>::Element *E=bnode->variables.front();E;E=E->next()) {

				code+=_mktab(p_level)+_prestr(E->get().precision)+_typestr(E->get().type)+" "+_mkid(E->key())+";\n";
			}

			for(int i=0;i<bnode->statements.size();i++) {

				String scode = _dump_node_code(bnode->statements[i],p_level,r_gen_code,p_actions,p_default_actions);

				if (bnode->statements[i]->type==SL::Node::TYPE_CONTROL_FLOW || bnode->statements[i]->type==SL::Node::TYPE_CONTROL_FLOW) {
					code+=scode; //use directly
				} else {
					code+=_mktab(p_level)+scode+";\n";
				}
			}
			code+=_mktab(p_level-1)+"}\n";


		} break;
		case SL::Node::TYPE_VARIABLE: {
			SL::VariableNode *vnode=(SL::VariableNode*)p_node;

			if (p_default_actions.usage_defines.has(vnode->name) && !used_name_defines.has(vnode->name)) {
				String define = p_default_actions.usage_defines[vnode->name];
				if (define.begins_with("@")) {
					define = p_default_actions.usage_defines[define.substr(1,define.length())];
				}
				r_gen_code.defines.push_back(define.utf8());
				used_name_defines.insert(vnode->name);
			}

			if (p_actions.usage_flag_pointers.has(vnode->name) && !used_name_defines.has(vnode->name)) {
				*p_actions.usage_flag_pointers[vnode->name]=true;
				used_name_defines.insert(vnode->name);
			}

			if (p_default_actions.renames.has(vnode->name))
				code=p_default_actions.renames[vnode->name];
			else
				code=_mkid(vnode->name);

			if (vnode->name==time_name) {
				if (current_func_name==vertex_name) {
					r_gen_code.uses_vertex_time=true;
				}
				if (current_func_name==fragment_name) {
					r_gen_code.uses_fragment_time=true;
				}
			}

		} break;
		case SL::Node::TYPE_CONSTANT: {
			SL::ConstantNode *cnode=(SL::ConstantNode*)p_node;
			return get_constant_text(cnode->datatype,cnode->values);

		} break;
		case SL::Node::TYPE_OPERATOR: {
			SL::OperatorNode *onode=(SL::OperatorNode*)p_node;


			switch(onode->op) {

				case SL::OP_ASSIGN:
				case SL::OP_ASSIGN_ADD:
				case SL::OP_ASSIGN_SUB:
				case SL::OP_ASSIGN_MUL:
				case SL::OP_ASSIGN_DIV:
				case SL::OP_ASSIGN_SHIFT_LEFT:
				case SL::OP_ASSIGN_SHIFT_RIGHT:
				case SL::OP_ASSIGN_MOD:
				case SL::OP_ASSIGN_BIT_AND:
				case SL::OP_ASSIGN_BIT_OR:
				case SL::OP_ASSIGN_BIT_XOR:
					code=_dump_node_code(onode->arguments[0],p_level,r_gen_code,p_actions,p_default_actions)+_opstr(onode->op)+_dump_node_code(onode->arguments[1],p_level,r_gen_code,p_actions,p_default_actions);
					break;
				case SL::OP_BIT_INVERT:
				case SL::OP_NEGATE:
				case SL::OP_NOT:
				case SL::OP_DECREMENT:
				case SL::OP_INCREMENT:
					code=_opstr(onode->op)+_dump_node_code(onode->arguments[0],p_level,r_gen_code,p_actions,p_default_actions);
					break;
				case SL::OP_POST_DECREMENT:
				case SL::OP_POST_INCREMENT:
					code=_dump_node_code(onode->arguments[0],p_level,r_gen_code,p_actions,p_default_actions)+_opstr(onode->op);
					break;
				case SL::OP_CALL:
				case SL::OP_CONSTRUCT: {

					ERR_FAIL_COND_V(onode->arguments[0]->type!=SL::Node::TYPE_VARIABLE,String());

					SL::VariableNode *vnode=(SL::VariableNode*)onode->arguments[0];

					if (onode->op==SL::OP_CONSTRUCT) {
						code+=String(vnode->name);
					} else {

						if (internal_functions.has(vnode->name)) {
							code+=vnode->name;
						} else if (p_default_actions.renames.has(vnode->name)) {
							code+=p_default_actions.renames[vnode->name];
						} else {
							code+=_mkid(vnode->name);
						}
					}

					code+="(";

					for(int i=1;i<onode->arguments.size();i++) {
						if (i>1)
							code+=", ";
						code+=_dump_node_code(onode->arguments[i],p_level,r_gen_code,p_actions,p_default_actions);
					}
					code+=")";
				} break;
				default: {

					code="("+_dump_node_code(onode->arguments[0],p_level,r_gen_code,p_actions,p_default_actions)+_opstr(onode->op)+_dump_node_code(onode->arguments[1],p_level,r_gen_code,p_actions,p_default_actions)+")";
					break;

				}
			}

		} break;
		case SL::Node::TYPE_CONTROL_FLOW: {
			SL::ControlFlowNode *cfnode=(SL::ControlFlowNode*)p_node;
			if (cfnode->flow_op==SL::FLOW_OP_IF) {

				code+=_mktab(p_level)+"if ("+_dump_node_code(cfnode->expressions[0],p_level,r_gen_code,p_actions,p_default_actions)+")\n";
				code+=_dump_node_code(cfnode->blocks[0],p_level+1,r_gen_code,p_actions,p_default_actions);
				if (cfnode->blocks.size()==2) {

					code+=_mktab(p_level)+"else\n";
					code+=_dump_node_code(cfnode->blocks[1],p_level+1,r_gen_code,p_actions,p_default_actions);
				}


			} else if (cfnode->flow_op==SL::FLOW_OP_RETURN) {

				if (cfnode->blocks.size()) {
					code="return "+_dump_node_code(cfnode->blocks[0],p_level,r_gen_code,p_actions,p_default_actions);
				} else {
					code="return";
				}
			}

		} break;
		case SL::Node::TYPE_MEMBER: {
			SL::MemberNode *mnode=(SL::MemberNode*)p_node;
			code=_dump_node_code(mnode->owner,p_level,r_gen_code,p_actions,p_default_actions)+"."+mnode->name;

		} break;
	}

	return code;

}


Error ShaderCompilerGLES3::compile(VS::ShaderMode p_mode, const String& p_code, IdentifierActions* p_actions, const String &p_path,GeneratedCode& r_gen_code) {



	Error err = parser.compile(p_code,ShaderTypes::get_singleton()->get_functions(p_mode),ShaderTypes::get_singleton()->get_modes(p_mode));

	if (err!=OK) {
#if 1

		Vector<String> shader = p_code.split("\n");
		for(int i=0;i<shader.size();i++) {
			print_line(itos(i)+" "+shader[i]);
		}
#endif

		_err_print_error(NULL,p_path.utf8().get_data(),parser.get_error_line(),parser.get_error_text().utf8().get_data(),ERR_HANDLER_SHADER);
		return err;
	}

	r_gen_code.defines.clear();
	r_gen_code.vertex=String();
	r_gen_code.vertex_global=String();
	r_gen_code.fragment=String();
	r_gen_code.fragment_global=String();
	r_gen_code.light=String();
	r_gen_code.uses_fragment_time=false;
	r_gen_code.uses_vertex_time=false;



	used_name_defines.clear();
	used_rmode_defines.clear();

	_dump_node_code(parser.get_shader(),1,r_gen_code,*p_actions,actions[p_mode]);


	return OK;

}


ShaderCompilerGLES3::ShaderCompilerGLES3() {

	/** CANVAS ITEM SHADER **/

	actions[VS::SHADER_CANVAS_ITEM].renames["SRC_VERTEX"]="vertex";
	actions[VS::SHADER_CANVAS_ITEM].renames["VERTEX"]="outvec.xy";
	actions[VS::SHADER_CANVAS_ITEM].renames["VERTEX_COLOR"]="vertex_color";
	actions[VS::SHADER_CANVAS_ITEM].renames["UV"]="uv_interp";
	actions[VS::SHADER_CANVAS_ITEM].renames["POINT_SIZE"]="gl_PointSize";

	actions[VS::SHADER_CANVAS_ITEM].renames["WORLD_MATRIX"]="modelview_matrix";
	actions[VS::SHADER_CANVAS_ITEM].renames["PROJECTION_MATRIX"]="projection_matrix";
	actions[VS::SHADER_CANVAS_ITEM].renames["EXTRA_MATRIX"]=="extra_matrix";
	actions[VS::SHADER_CANVAS_ITEM].renames["TIME"]="time";

	actions[VS::SHADER_CANVAS_ITEM].renames["COLOR"]="color";
	actions[VS::SHADER_CANVAS_ITEM].renames["NORMAL"]="normal";
	actions[VS::SHADER_CANVAS_ITEM].renames["NORMALMAP"]="normal_map";
	actions[VS::SHADER_CANVAS_ITEM].renames["NORMALMAP_DEPTH"]="normal_depth";
	actions[VS::SHADER_CANVAS_ITEM].renames["UV"]="uv_interp";
	actions[VS::SHADER_CANVAS_ITEM].renames["COLOR"]="color";
	actions[VS::SHADER_CANVAS_ITEM].renames["TEXTURE"]="color_texture";
	actions[VS::SHADER_CANVAS_ITEM].renames["TEXTURE_PIXEL_SIZE"]="color_texpixel_size";
	actions[VS::SHADER_CANVAS_ITEM].renames["SCREEN_UV"]="screen_uv";
	actions[VS::SHADER_CANVAS_ITEM].renames["SCREEN_TEXTURE"]="screen_texture";
	actions[VS::SHADER_CANVAS_ITEM].renames["POINT_COORD"]="gl_PointCoord";

	actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_VEC"]="light_vec";
	actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_HEIGHT"]="light_height";
	actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_COLOR"]="light_color";
	actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_UV"]="light_uv";
	//actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_SHADOW_COLOR"]="light_shadow_color";
	actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT"]="light";
	actions[VS::SHADER_CANVAS_ITEM].renames["SHADOW_COLOR"]="shadow_color";

	actions[VS::SHADER_CANVAS_ITEM].usage_defines["COLOR"]="#define COLOR_USED\n";
	actions[VS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_TEXTURE"]="#define SCREEN_TEXTURE_USED\n";
	actions[VS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_UV"]="#define SCREEN_UV_USED\n";
	actions[VS::SHADER_CANVAS_ITEM].usage_defines["NORMAL"]="#define NORMAL_USED\n";
	actions[VS::SHADER_CANVAS_ITEM].usage_defines["NORMALMAP"]="#define NORMALMAP_USED\n";
	actions[VS::SHADER_CANVAS_ITEM].usage_defines["SHADOW_COLOR"]="#define SHADOW_COLOR_USED\n";

	actions[VS::SHADER_CANVAS_ITEM].render_mode_defines["skip_transform"]="#define SKIP_TRANSFORM_USED\n";

	/** SPATIAL SHADER **/


	actions[VS::SHADER_SPATIAL].renames["WORLD_MATRIX"]="world_transform";
	actions[VS::SHADER_SPATIAL].renames["INV_CAMERA_MATRIX"]="camera_inverse_matrix";
	actions[VS::SHADER_SPATIAL].renames["PROJECTION_MATRIX"]="projection_matrix";


	actions[VS::SHADER_SPATIAL].renames["VERTEX"]="vertex.xyz";
	actions[VS::SHADER_SPATIAL].renames["NORMAL"]="normal";
	actions[VS::SHADER_SPATIAL].renames["TANGENT"]="tangent";
	actions[VS::SHADER_SPATIAL].renames["BINORMAL"]="binormal";
	actions[VS::SHADER_SPATIAL].renames["UV"]="uv_interp";
	actions[VS::SHADER_SPATIAL].renames["UV2"]="uv2_interp";
	actions[VS::SHADER_SPATIAL].renames["COLOR"]="color_interp";
	actions[VS::SHADER_SPATIAL].renames["POINT_SIZE"]="gl_PointSize";
	//actions[VS::SHADER_SPATIAL].renames["INSTANCE_ID"]=ShaderLanguage::TYPE_INT;

	//builtins

	actions[VS::SHADER_SPATIAL].renames["TIME"]="time";
	//actions[VS::SHADER_SPATIAL].renames["VIEWPORT_SIZE"]=ShaderLanguage::TYPE_VEC2;

	actions[VS::SHADER_SPATIAL].renames["FRAGCOORD"]="gl_FragCoord";
	actions[VS::SHADER_SPATIAL].renames["FRONT_FACING"]="gl_FrotFacing";
	actions[VS::SHADER_SPATIAL].renames["NORMALMAP"]="normalmap";
	actions[VS::SHADER_SPATIAL].renames["NORMALMAP_DEPTH"]="normaldepth";
	actions[VS::SHADER_SPATIAL].renames["ALBEDO"]="albedo";
	actions[VS::SHADER_SPATIAL].renames["ALPHA"]="alpha";
	actions[VS::SHADER_SPATIAL].renames["SPECULAR"]="specular";
	actions[VS::SHADER_SPATIAL].renames["ROUGHNESS"]="roughness";
	actions[VS::SHADER_SPATIAL].renames["EMISSION"]="emission";
	actions[VS::SHADER_SPATIAL].renames["SPECIAL"]="special";
	actions[VS::SHADER_SPATIAL].renames["DISCARD"]="_discard";
//	actions[VS::SHADER_SPATIAL].renames["SCREEN_UV"]=ShaderLanguage::TYPE_VEC2;
	actions[VS::SHADER_SPATIAL].renames["POINT_COORD"]="gl_PointCoord";


	actions[VS::SHADER_SPATIAL].usage_defines["TANGENT"]="#define ENABLE_TANGENT_INTERP\n";
	actions[VS::SHADER_SPATIAL].usage_defines["BINORMAL"]="@TANGENT";
	actions[VS::SHADER_SPATIAL].usage_defines["UV"]="#define ENABLE_UV_INTERP\n";
	actions[VS::SHADER_SPATIAL].usage_defines["UV2"]="#define ENABLE_UV2_INTERP\n";
	actions[VS::SHADER_SPATIAL].usage_defines["NORMALMAP"]="#define ENABLE_NORMALMAP\n";
	actions[VS::SHADER_SPATIAL].usage_defines["NORMALMAP_DEPTH"]="@NORMALMAP";
	actions[VS::SHADER_SPATIAL].usage_defines["COLOR"]="#define ENABLE_COLOR_INTERP\n";

	actions[VS::SHADER_SPATIAL].render_mode_defines["skip_transform"]="#define SKIP_TRANSFORM_USED\n";




	vertex_name="vertex";
	fragment_name="fragment";
	time_name="TIME";



	List<String> func_list;

	ShaderLanguage::get_builtin_funcs(&func_list);

	for (List<String>::Element *E=func_list.front();E;E=E->next()) {
		internal_functions.insert(E->get());
	}
}