shader_compiler_gles3.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. #include "shader_compiler_gles3.h"
  2. #include "os/os.h"
  3. #define SL ShaderLanguage
  4. static String _mktab(int p_level) {
  5. String tb;
  6. for(int i=0;i<p_level;i++) {
  7. tb+="\t";
  8. }
  9. return tb;
  10. }
  11. static String _typestr(SL::DataType p_type) {
  12. return ShaderLanguage::get_datatype_name(p_type);
  13. }
  14. static int _get_datatype_size(SL::DataType p_type) {
  15. switch(p_type) {
  16. case SL::TYPE_VOID: return 0;
  17. case SL::TYPE_BOOL: return 4;
  18. case SL::TYPE_BVEC2: return 8;
  19. case SL::TYPE_BVEC3: return 16;
  20. case SL::TYPE_BVEC4: return 16;
  21. case SL::TYPE_INT: return 4;
  22. case SL::TYPE_IVEC2: return 8;
  23. case SL::TYPE_IVEC3: return 16;
  24. case SL::TYPE_IVEC4: return 16;
  25. case SL::TYPE_UINT: return 4;
  26. case SL::TYPE_UVEC2: return 8;
  27. case SL::TYPE_UVEC3: return 16;
  28. case SL::TYPE_UVEC4: return 16;
  29. case SL::TYPE_FLOAT: return 4;
  30. case SL::TYPE_VEC2: return 8;
  31. case SL::TYPE_VEC3: return 16;
  32. case SL::TYPE_VEC4: return 16;
  33. case SL::TYPE_MAT2: return 16;
  34. case SL::TYPE_MAT3: return 48;
  35. case SL::TYPE_MAT4: return 64;
  36. case SL::TYPE_SAMPLER2D: return 16;
  37. case SL::TYPE_ISAMPLER2D: return 16;
  38. case SL::TYPE_USAMPLER2D: return 16;
  39. case SL::TYPE_SAMPLERCUBE: return 16;
  40. }
  41. ERR_FAIL_V(0);
  42. }
  43. static String _prestr(SL::DataPrecision p_pres) {
  44. switch(p_pres) {
  45. case SL::PRECISION_LOWP: return "lowp ";
  46. case SL::PRECISION_MEDIUMP: return "mediump ";
  47. case SL::PRECISION_HIGHP: return "highp ";
  48. case SL::PRECISION_DEFAULT: return "";
  49. }
  50. return "";
  51. }
  52. static String _opstr(SL::Operator p_op) {
  53. return SL::get_operator_text(p_op);
  54. }
  55. static String _mkid(const String& p_id) {
  56. return "m_"+p_id;
  57. }
  58. static String f2sp0(float p_float) {
  59. if (int(p_float)==p_float)
  60. return itos(p_float)+".0";
  61. else
  62. return rtoss(p_float);
  63. }
  64. static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNode::Value>& p_values) {
  65. switch(p_type) {
  66. case SL::TYPE_BOOL: return p_values[0].boolean?"true":"false";
  67. case SL::TYPE_BVEC2:
  68. case SL::TYPE_BVEC3:
  69. case SL::TYPE_BVEC4: {
  70. String text="bvec"+itos(p_type-SL::TYPE_BOOL+1)+"(";
  71. for(int i=0;i<p_values.size();i++) {
  72. if (i>0)
  73. text+=",";
  74. text+=p_values[i].boolean?"true":"false";
  75. }
  76. text+=")";
  77. return text;
  78. }
  79. case SL::TYPE_INT: return itos(p_values[0].sint);
  80. case SL::TYPE_IVEC2:
  81. case SL::TYPE_IVEC3:
  82. case SL::TYPE_IVEC4: {
  83. String text="ivec"+itos(p_type-SL::TYPE_INT+1)+"(";
  84. for(int i=0;i<p_values.size();i++) {
  85. if (i>0)
  86. text+=",";
  87. text+=itos(p_values[i].sint);
  88. }
  89. text+=")";
  90. return text;
  91. } break;
  92. case SL::TYPE_UINT: return itos(p_values[0].uint)+"u";
  93. case SL::TYPE_UVEC2:
  94. case SL::TYPE_UVEC3:
  95. case SL::TYPE_UVEC4: {
  96. String text="uvec"+itos(p_type-SL::TYPE_UINT+1)+"(";
  97. for(int i=0;i<p_values.size();i++) {
  98. if (i>0)
  99. text+=",";
  100. text+=itos(p_values[i].uint)+"u";
  101. }
  102. text+=")";
  103. return text;
  104. } break;
  105. case SL::TYPE_FLOAT: return f2sp0(p_values[0].real)+"f";
  106. case SL::TYPE_VEC2:
  107. case SL::TYPE_VEC3:
  108. case SL::TYPE_VEC4: {
  109. String text="vec"+itos(p_type-SL::TYPE_FLOAT+1)+"(";
  110. for(int i=0;i<p_values.size();i++) {
  111. if (i>0)
  112. text+=",";
  113. text+=f2sp0(p_values[i].real);
  114. }
  115. text+=")";
  116. return text;
  117. } break;
  118. default: ERR_FAIL_V(String());
  119. }
  120. }
  121. 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) {
  122. int fidx=-1;
  123. for(int i=0;i<p_node->functions.size();i++) {
  124. if (p_node->functions[i].name==p_for_func) {
  125. fidx=i;
  126. break;
  127. }
  128. }
  129. ERR_FAIL_COND(fidx==-1);
  130. for (Set<StringName>::Element *E=p_node->functions[fidx].uses_function.front();E;E=E->next()) {
  131. if (added.has(E->get())) {
  132. continue; //was added already
  133. }
  134. _dump_function_deps(p_node,E->get(),p_func_code,r_to_add,added);
  135. SL::FunctionNode *fnode=NULL;
  136. for(int i=0;i<p_node->functions.size();i++) {
  137. if (p_node->functions[i].name==E->get()) {
  138. fnode=p_node->functions[i].function;
  139. break;
  140. }
  141. }
  142. ERR_FAIL_COND(!fnode);
  143. r_to_add+="\n";
  144. String header;
  145. header=_typestr(fnode->return_type)+" "+_mkid(fnode->name)+"(";
  146. for(int i=0;i<fnode->arguments.size();i++) {
  147. if (i>0)
  148. header+=", ";
  149. header+=_prestr(fnode->arguments[i].precision)+_typestr(fnode->arguments[i].type)+" "+_mkid(fnode->arguments[i].name);
  150. }
  151. header+=")\n";
  152. r_to_add+=header;
  153. r_to_add+=p_func_code[E->get()];
  154. added.insert(E->get());
  155. }
  156. }
  157. String ShaderCompilerGLES3::_dump_node_code(SL::Node *p_node, int p_level, GeneratedCode& r_gen_code, IdentifierActions &p_actions, const DefaultIdentifierActions &p_default_actions) {
  158. String code;
  159. switch(p_node->type) {
  160. case SL::Node::TYPE_SHADER: {
  161. SL::ShaderNode *pnode=(SL::ShaderNode*)p_node;
  162. for(int i=0;i<pnode->render_modes.size();i++) {
  163. if (p_default_actions.render_mode_defines.has(pnode->render_modes[i]) && !used_rmode_defines.has(pnode->render_modes[i])) {
  164. r_gen_code.defines.push_back(p_default_actions.render_mode_defines[pnode->render_modes[i]].utf8());
  165. used_rmode_defines.insert(pnode->render_modes[i]);
  166. }
  167. if (p_actions.render_mode_flags.has(pnode->render_modes[i])) {
  168. *p_actions.render_mode_flags[pnode->render_modes[i]]=true;
  169. }
  170. if (p_actions.render_mode_values.has(pnode->render_modes[i])) {
  171. Pair<int*,int> &p = p_actions.render_mode_values[pnode->render_modes[i]];
  172. *p.first=p.second;
  173. }
  174. }
  175. int max_texture_uniforms=0;
  176. int max_uniforms=0;
  177. for(Map<StringName,SL::ShaderNode::Uniform>::Element *E=pnode->uniforms.front();E;E=E->next()) {
  178. if (SL::is_sampler_type(E->get().type))
  179. max_texture_uniforms++;
  180. else
  181. max_uniforms++;
  182. }
  183. r_gen_code.texture_uniforms.resize(max_texture_uniforms);
  184. r_gen_code.texture_hints.resize(max_texture_uniforms);
  185. Vector<int> uniform_sizes;
  186. uniform_sizes.resize(max_uniforms);
  187. for(Map<StringName,SL::ShaderNode::Uniform>::Element *E=pnode->uniforms.front();E;E=E->next()) {
  188. String ucode;
  189. if (SL::is_sampler_type(E->get().type)) {
  190. ucode="uniform ";
  191. }
  192. ucode+=_prestr(E->get().precission);
  193. ucode+=_typestr(E->get().type);
  194. ucode+=" "+_mkid(E->key());
  195. ucode+=";\n";
  196. if (SL::is_sampler_type(E->get().type)) {
  197. r_gen_code.vertex_global+=ucode;
  198. r_gen_code.fragment_global+=ucode;
  199. r_gen_code.texture_uniforms[E->get().texture_order]=_mkid(E->key());
  200. r_gen_code.texture_hints[E->get().texture_order]=E->get().hint;
  201. } else {
  202. if (r_gen_code.uniforms.empty()) {
  203. r_gen_code.defines.push_back(String("#define USE_MATERIAL\n").ascii());
  204. }
  205. r_gen_code.uniforms+=ucode;
  206. uniform_sizes[E->get().order]=_get_datatype_size(E->get().type);
  207. }
  208. p_actions.uniforms->insert(E->key(),E->get());
  209. }
  210. // add up
  211. for(int i=0;i<uniform_sizes.size();i++) {
  212. if (i>0)
  213. uniform_sizes[i]=uniform_sizes[i]+uniform_sizes[i-1];
  214. }
  215. //offset
  216. r_gen_code.uniform_offsets.resize(uniform_sizes.size());
  217. for(int i=0;i<uniform_sizes.size();i++) {
  218. if (i>0)
  219. r_gen_code.uniform_offsets[i]=uniform_sizes[i-1];
  220. else
  221. r_gen_code.uniform_offsets[i]=0;
  222. }
  223. if (uniform_sizes.size()) {
  224. r_gen_code.uniform_total_size=uniform_sizes[ uniform_sizes.size() -1 ];
  225. } else {
  226. r_gen_code.uniform_total_size=0;
  227. }
  228. for(Map<StringName,SL::ShaderNode::Varying>::Element *E=pnode->varyings.front();E;E=E->next()) {
  229. String vcode;
  230. vcode+=_prestr(E->get().precission);
  231. vcode+=_typestr(E->get().type);
  232. vcode+=" "+String(E->key());
  233. vcode+=";\n";
  234. r_gen_code.vertex_global+="out "+vcode;
  235. r_gen_code.fragment_global+="in "+vcode;
  236. }
  237. Map<StringName,String> function_code;
  238. //code for functions
  239. for(int i=0;i<pnode->functions.size();i++) {
  240. SL::FunctionNode *fnode=pnode->functions[i].function;
  241. function_code[fnode->name]=_dump_node_code(fnode->body,p_level+1,r_gen_code,p_actions,p_default_actions);
  242. }
  243. //place functions in actual code
  244. Set<StringName> added_vtx;
  245. Set<StringName> added_fragment; //share for light
  246. for(int i=0;i<pnode->functions.size();i++) {
  247. SL::FunctionNode *fnode=pnode->functions[i].function;
  248. current_func_name=fnode->name;
  249. if (fnode->name=="vertex") {
  250. _dump_function_deps(pnode,fnode->name,function_code,r_gen_code.vertex_global,added_vtx);
  251. r_gen_code.vertex=function_code["vertex"];
  252. }
  253. if (fnode->name=="fragment") {
  254. _dump_function_deps(pnode,fnode->name,function_code,r_gen_code.fragment_global,added_fragment);
  255. r_gen_code.fragment=function_code["fragment"];
  256. }
  257. if (fnode->name=="light") {
  258. _dump_function_deps(pnode,fnode->name,function_code,r_gen_code.fragment_global,added_fragment);
  259. r_gen_code.light=function_code["light"];
  260. }
  261. }
  262. //code+=dump_node_code(pnode->body,p_level);
  263. } break;
  264. case SL::Node::TYPE_FUNCTION: {
  265. } break;
  266. case SL::Node::TYPE_BLOCK: {
  267. SL::BlockNode *bnode=(SL::BlockNode*)p_node;
  268. //variables
  269. code+=_mktab(p_level-1)+"{\n";
  270. for(Map<StringName,SL::BlockNode::Variable>::Element *E=bnode->variables.front();E;E=E->next()) {
  271. code+=_mktab(p_level)+_prestr(E->get().precision)+_typestr(E->get().type)+" "+_mkid(E->key())+";\n";
  272. }
  273. for(int i=0;i<bnode->statements.size();i++) {
  274. String scode = _dump_node_code(bnode->statements[i],p_level,r_gen_code,p_actions,p_default_actions);
  275. if (bnode->statements[i]->type==SL::Node::TYPE_CONTROL_FLOW || bnode->statements[i]->type==SL::Node::TYPE_CONTROL_FLOW) {
  276. code+=scode; //use directly
  277. } else {
  278. code+=_mktab(p_level)+scode+";\n";
  279. }
  280. }
  281. code+=_mktab(p_level-1)+"}\n";
  282. } break;
  283. case SL::Node::TYPE_VARIABLE: {
  284. SL::VariableNode *vnode=(SL::VariableNode*)p_node;
  285. if (p_default_actions.usage_defines.has(vnode->name) && !used_name_defines.has(vnode->name)) {
  286. String define = p_default_actions.usage_defines[vnode->name];
  287. if (define.begins_with("@")) {
  288. define = p_default_actions.usage_defines[define.substr(1,define.length())];
  289. }
  290. r_gen_code.defines.push_back(define.utf8());
  291. used_name_defines.insert(vnode->name);
  292. }
  293. if (p_actions.usage_flag_pointers.has(vnode->name) && !used_name_defines.has(vnode->name)) {
  294. *p_actions.usage_flag_pointers[vnode->name]=true;
  295. used_name_defines.insert(vnode->name);
  296. }
  297. if (p_default_actions.renames.has(vnode->name))
  298. code=p_default_actions.renames[vnode->name];
  299. else
  300. code=_mkid(vnode->name);
  301. if (vnode->name==time_name) {
  302. if (current_func_name==vertex_name) {
  303. r_gen_code.uses_vertex_time=true;
  304. }
  305. if (current_func_name==fragment_name) {
  306. r_gen_code.uses_fragment_time=true;
  307. }
  308. }
  309. } break;
  310. case SL::Node::TYPE_CONSTANT: {
  311. SL::ConstantNode *cnode=(SL::ConstantNode*)p_node;
  312. return get_constant_text(cnode->datatype,cnode->values);
  313. } break;
  314. case SL::Node::TYPE_OPERATOR: {
  315. SL::OperatorNode *onode=(SL::OperatorNode*)p_node;
  316. switch(onode->op) {
  317. case SL::OP_ASSIGN:
  318. case SL::OP_ASSIGN_ADD:
  319. case SL::OP_ASSIGN_SUB:
  320. case SL::OP_ASSIGN_MUL:
  321. case SL::OP_ASSIGN_DIV:
  322. case SL::OP_ASSIGN_SHIFT_LEFT:
  323. case SL::OP_ASSIGN_SHIFT_RIGHT:
  324. case SL::OP_ASSIGN_MOD:
  325. case SL::OP_ASSIGN_BIT_AND:
  326. case SL::OP_ASSIGN_BIT_OR:
  327. case SL::OP_ASSIGN_BIT_XOR:
  328. 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);
  329. break;
  330. case SL::OP_BIT_INVERT:
  331. case SL::OP_NEGATE:
  332. case SL::OP_NOT:
  333. case SL::OP_DECREMENT:
  334. case SL::OP_INCREMENT:
  335. code=_opstr(onode->op)+_dump_node_code(onode->arguments[0],p_level,r_gen_code,p_actions,p_default_actions);
  336. break;
  337. case SL::OP_POST_DECREMENT:
  338. case SL::OP_POST_INCREMENT:
  339. code=_dump_node_code(onode->arguments[0],p_level,r_gen_code,p_actions,p_default_actions)+_opstr(onode->op);
  340. break;
  341. case SL::OP_CALL:
  342. case SL::OP_CONSTRUCT: {
  343. ERR_FAIL_COND_V(onode->arguments[0]->type!=SL::Node::TYPE_VARIABLE,String());
  344. SL::VariableNode *vnode=(SL::VariableNode*)onode->arguments[0];
  345. if (onode->op==SL::OP_CONSTRUCT) {
  346. code+=String(vnode->name);
  347. } else {
  348. if (internal_functions.has(vnode->name)) {
  349. code+=vnode->name;
  350. } else if (p_default_actions.renames.has(vnode->name)) {
  351. code+=p_default_actions.renames[vnode->name];
  352. } else {
  353. code+=_mkid(vnode->name);
  354. }
  355. }
  356. code+="(";
  357. for(int i=1;i<onode->arguments.size();i++) {
  358. if (i>1)
  359. code+=", ";
  360. code+=_dump_node_code(onode->arguments[i],p_level,r_gen_code,p_actions,p_default_actions);
  361. }
  362. code+=")";
  363. } break;
  364. default: {
  365. 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)+")";
  366. break;
  367. }
  368. }
  369. } break;
  370. case SL::Node::TYPE_CONTROL_FLOW: {
  371. SL::ControlFlowNode *cfnode=(SL::ControlFlowNode*)p_node;
  372. if (cfnode->flow_op==SL::FLOW_OP_IF) {
  373. code+=_mktab(p_level)+"if ("+_dump_node_code(cfnode->expressions[0],p_level,r_gen_code,p_actions,p_default_actions)+")\n";
  374. code+=_dump_node_code(cfnode->blocks[0],p_level+1,r_gen_code,p_actions,p_default_actions);
  375. if (cfnode->blocks.size()==2) {
  376. code+=_mktab(p_level)+"else\n";
  377. code+=_dump_node_code(cfnode->blocks[1],p_level+1,r_gen_code,p_actions,p_default_actions);
  378. }
  379. } else if (cfnode->flow_op==SL::FLOW_OP_RETURN) {
  380. if (cfnode->blocks.size()) {
  381. code="return "+_dump_node_code(cfnode->blocks[0],p_level,r_gen_code,p_actions,p_default_actions);
  382. } else {
  383. code="return";
  384. }
  385. }
  386. } break;
  387. case SL::Node::TYPE_MEMBER: {
  388. SL::MemberNode *mnode=(SL::MemberNode*)p_node;
  389. code=_dump_node_code(mnode->owner,p_level,r_gen_code,p_actions,p_default_actions)+"."+mnode->name;
  390. } break;
  391. }
  392. return code;
  393. }
  394. Error ShaderCompilerGLES3::compile(VS::ShaderMode p_mode, const String& p_code, IdentifierActions* p_actions, const String &p_path,GeneratedCode& r_gen_code) {
  395. Error err = parser.compile(p_code,ShaderTypes::get_singleton()->get_functions(p_mode),ShaderTypes::get_singleton()->get_modes(p_mode));
  396. if (err!=OK) {
  397. #if 1
  398. Vector<String> shader = p_code.split("\n");
  399. for(int i=0;i<shader.size();i++) {
  400. print_line(itos(i)+" "+shader[i]);
  401. }
  402. #endif
  403. _err_print_error(NULL,p_path.utf8().get_data(),parser.get_error_line(),parser.get_error_text().utf8().get_data(),ERR_HANDLER_SHADER);
  404. return err;
  405. }
  406. r_gen_code.defines.clear();
  407. r_gen_code.vertex=String();
  408. r_gen_code.vertex_global=String();
  409. r_gen_code.fragment=String();
  410. r_gen_code.fragment_global=String();
  411. r_gen_code.light=String();
  412. r_gen_code.uses_fragment_time=false;
  413. r_gen_code.uses_vertex_time=false;
  414. used_name_defines.clear();
  415. used_rmode_defines.clear();
  416. _dump_node_code(parser.get_shader(),1,r_gen_code,*p_actions,actions[p_mode]);
  417. return OK;
  418. }
  419. ShaderCompilerGLES3::ShaderCompilerGLES3() {
  420. /** CANVAS ITEM SHADER **/
  421. actions[VS::SHADER_CANVAS_ITEM].renames["SRC_VERTEX"]="vertex";
  422. actions[VS::SHADER_CANVAS_ITEM].renames["VERTEX"]="outvec.xy";
  423. actions[VS::SHADER_CANVAS_ITEM].renames["VERTEX_COLOR"]="vertex_color";
  424. actions[VS::SHADER_CANVAS_ITEM].renames["UV"]="uv_interp";
  425. actions[VS::SHADER_CANVAS_ITEM].renames["POINT_SIZE"]="gl_PointSize";
  426. actions[VS::SHADER_CANVAS_ITEM].renames["WORLD_MATRIX"]="modelview_matrix";
  427. actions[VS::SHADER_CANVAS_ITEM].renames["PROJECTION_MATRIX"]="projection_matrix";
  428. actions[VS::SHADER_CANVAS_ITEM].renames["EXTRA_MATRIX"]=="extra_matrix";
  429. actions[VS::SHADER_CANVAS_ITEM].renames["TIME"]="time";
  430. actions[VS::SHADER_CANVAS_ITEM].renames["COLOR"]="color";
  431. actions[VS::SHADER_CANVAS_ITEM].renames["NORMAL"]="normal";
  432. actions[VS::SHADER_CANVAS_ITEM].renames["NORMALMAP"]="normal_map";
  433. actions[VS::SHADER_CANVAS_ITEM].renames["NORMALMAP_DEPTH"]="normal_depth";
  434. actions[VS::SHADER_CANVAS_ITEM].renames["UV"]="uv_interp";
  435. actions[VS::SHADER_CANVAS_ITEM].renames["COLOR"]="color";
  436. actions[VS::SHADER_CANVAS_ITEM].renames["TEXTURE"]="color_texture";
  437. actions[VS::SHADER_CANVAS_ITEM].renames["TEXTURE_PIXEL_SIZE"]="color_texpixel_size";
  438. actions[VS::SHADER_CANVAS_ITEM].renames["SCREEN_UV"]="screen_uv";
  439. actions[VS::SHADER_CANVAS_ITEM].renames["SCREEN_TEXTURE"]="screen_texture";
  440. actions[VS::SHADER_CANVAS_ITEM].renames["POINT_COORD"]="gl_PointCoord";
  441. actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_VEC"]="light_vec";
  442. actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_HEIGHT"]="light_height";
  443. actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_COLOR"]="light_color";
  444. actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_UV"]="light_uv";
  445. //actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT_SHADOW_COLOR"]="light_shadow_color";
  446. actions[VS::SHADER_CANVAS_ITEM].renames["LIGHT"]="light";
  447. actions[VS::SHADER_CANVAS_ITEM].renames["SHADOW_COLOR"]="shadow_color";
  448. actions[VS::SHADER_CANVAS_ITEM].usage_defines["COLOR"]="#define COLOR_USED\n";
  449. actions[VS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_TEXTURE"]="#define SCREEN_TEXTURE_USED\n";
  450. actions[VS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_UV"]="#define SCREEN_UV_USED\n";
  451. actions[VS::SHADER_CANVAS_ITEM].usage_defines["NORMAL"]="#define NORMAL_USED\n";
  452. actions[VS::SHADER_CANVAS_ITEM].usage_defines["NORMALMAP"]="#define NORMALMAP_USED\n";
  453. actions[VS::SHADER_CANVAS_ITEM].usage_defines["SHADOW_COLOR"]="#define SHADOW_COLOR_USED\n";
  454. actions[VS::SHADER_CANVAS_ITEM].render_mode_defines["skip_transform"]="#define SKIP_TRANSFORM_USED\n";
  455. /** SPATIAL SHADER **/
  456. actions[VS::SHADER_SPATIAL].renames["WORLD_MATRIX"]="world_transform";
  457. actions[VS::SHADER_SPATIAL].renames["INV_CAMERA_MATRIX"]="camera_inverse_matrix";
  458. actions[VS::SHADER_SPATIAL].renames["PROJECTION_MATRIX"]="projection_matrix";
  459. actions[VS::SHADER_SPATIAL].renames["VERTEX"]="vertex.xyz";
  460. actions[VS::SHADER_SPATIAL].renames["NORMAL"]="normal";
  461. actions[VS::SHADER_SPATIAL].renames["TANGENT"]="tangent";
  462. actions[VS::SHADER_SPATIAL].renames["BINORMAL"]="binormal";
  463. actions[VS::SHADER_SPATIAL].renames["UV"]="uv_interp";
  464. actions[VS::SHADER_SPATIAL].renames["UV2"]="uv2_interp";
  465. actions[VS::SHADER_SPATIAL].renames["COLOR"]="color_interp";
  466. actions[VS::SHADER_SPATIAL].renames["POINT_SIZE"]="gl_PointSize";
  467. //actions[VS::SHADER_SPATIAL].renames["INSTANCE_ID"]=ShaderLanguage::TYPE_INT;
  468. //builtins
  469. actions[VS::SHADER_SPATIAL].renames["TIME"]="time";
  470. //actions[VS::SHADER_SPATIAL].renames["VIEWPORT_SIZE"]=ShaderLanguage::TYPE_VEC2;
  471. actions[VS::SHADER_SPATIAL].renames["FRAGCOORD"]="gl_FragCoord";
  472. actions[VS::SHADER_SPATIAL].renames["FRONT_FACING"]="gl_FrotFacing";
  473. actions[VS::SHADER_SPATIAL].renames["NORMALMAP"]="normalmap";
  474. actions[VS::SHADER_SPATIAL].renames["NORMALMAP_DEPTH"]="normaldepth";
  475. actions[VS::SHADER_SPATIAL].renames["ALBEDO"]="albedo";
  476. actions[VS::SHADER_SPATIAL].renames["ALPHA"]="alpha";
  477. actions[VS::SHADER_SPATIAL].renames["SPECULAR"]="specular";
  478. actions[VS::SHADER_SPATIAL].renames["ROUGHNESS"]="roughness";
  479. actions[VS::SHADER_SPATIAL].renames["EMISSION"]="emission";
  480. actions[VS::SHADER_SPATIAL].renames["SPECIAL"]="special";
  481. actions[VS::SHADER_SPATIAL].renames["DISCARD"]="_discard";
  482. // actions[VS::SHADER_SPATIAL].renames["SCREEN_UV"]=ShaderLanguage::TYPE_VEC2;
  483. actions[VS::SHADER_SPATIAL].renames["POINT_COORD"]="gl_PointCoord";
  484. actions[VS::SHADER_SPATIAL].usage_defines["TANGENT"]="#define ENABLE_TANGENT_INTERP\n";
  485. actions[VS::SHADER_SPATIAL].usage_defines["BINORMAL"]="@TANGENT";
  486. actions[VS::SHADER_SPATIAL].usage_defines["UV"]="#define ENABLE_UV_INTERP\n";
  487. actions[VS::SHADER_SPATIAL].usage_defines["UV2"]="#define ENABLE_UV2_INTERP\n";
  488. actions[VS::SHADER_SPATIAL].usage_defines["NORMALMAP"]="#define ENABLE_NORMALMAP\n";
  489. actions[VS::SHADER_SPATIAL].usage_defines["NORMALMAP_DEPTH"]="@NORMALMAP";
  490. actions[VS::SHADER_SPATIAL].usage_defines["COLOR"]="#define ENABLE_COLOR_INTERP\n";
  491. actions[VS::SHADER_SPATIAL].render_mode_defines["skip_transform"]="#define SKIP_TRANSFORM_USED\n";
  492. vertex_name="vertex";
  493. fragment_name="fragment";
  494. time_name="TIME";
  495. List<String> func_list;
  496. ShaderLanguage::get_builtin_funcs(&func_list);
  497. for (List<String>::Element *E=func_list.front();E;E=E->next()) {
  498. internal_functions.insert(E->get());
  499. }
  500. }