2017-03-05 15:47:28 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* shader_compiler_gles3.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2017-03-05 15:47:28 +01:00
|
|
|
/*************************************************************************/
|
2022-01-13 09:45:09 +01:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-03-05 15:47:28 +01:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
#include "shader_compiler_gles3.h"
|
2017-03-05 15:47:28 +01:00
|
|
|
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/os/os.h"
|
2018-09-23 17:12:30 +02:00
|
|
|
#include "core/project_settings.h"
|
2016-10-10 23:31:01 +02:00
|
|
|
|
|
|
|
#define SL ShaderLanguage
|
|
|
|
|
|
|
|
static String _mktab(int p_level) {
|
|
|
|
String tb;
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_level; i++) {
|
|
|
|
tb += "\t";
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2018-01-12 16:42:07 +01:00
|
|
|
switch (p_type) {
|
2021-05-04 14:35:44 +02:00
|
|
|
case SL::TYPE_VOID:
|
|
|
|
return 0;
|
|
|
|
case SL::TYPE_BOOL:
|
|
|
|
return 4;
|
|
|
|
case SL::TYPE_BVEC2:
|
|
|
|
return 8;
|
|
|
|
case SL::TYPE_BVEC3:
|
|
|
|
return 12;
|
|
|
|
case SL::TYPE_BVEC4:
|
|
|
|
return 16;
|
|
|
|
case SL::TYPE_INT:
|
|
|
|
return 4;
|
|
|
|
case SL::TYPE_IVEC2:
|
|
|
|
return 8;
|
|
|
|
case SL::TYPE_IVEC3:
|
|
|
|
return 12;
|
|
|
|
case SL::TYPE_IVEC4:
|
|
|
|
return 16;
|
|
|
|
case SL::TYPE_UINT:
|
|
|
|
return 4;
|
|
|
|
case SL::TYPE_UVEC2:
|
|
|
|
return 8;
|
|
|
|
case SL::TYPE_UVEC3:
|
|
|
|
return 12;
|
|
|
|
case SL::TYPE_UVEC4:
|
|
|
|
return 16;
|
|
|
|
case SL::TYPE_FLOAT:
|
|
|
|
return 4;
|
|
|
|
case SL::TYPE_VEC2:
|
|
|
|
return 8;
|
|
|
|
case SL::TYPE_VEC3:
|
|
|
|
return 12;
|
|
|
|
case SL::TYPE_VEC4:
|
|
|
|
return 16;
|
2018-01-12 16:45:16 +01:00
|
|
|
case SL::TYPE_MAT2:
|
2018-01-12 20:36:13 +01:00
|
|
|
return 32; //4 * 4 + 4 * 4
|
2018-01-12 16:45:16 +01:00
|
|
|
case SL::TYPE_MAT3:
|
2018-01-12 20:36:13 +01:00
|
|
|
return 48; // 4 * 4 + 4 * 4 + 4 * 4
|
2021-05-04 14:35:44 +02:00
|
|
|
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_SAMPLER2DARRAY:
|
|
|
|
return 16;
|
|
|
|
case SL::TYPE_ISAMPLER2DARRAY:
|
|
|
|
return 16;
|
|
|
|
case SL::TYPE_USAMPLER2DARRAY:
|
|
|
|
return 16;
|
|
|
|
case SL::TYPE_SAMPLER3D:
|
|
|
|
return 16;
|
|
|
|
case SL::TYPE_ISAMPLER3D:
|
|
|
|
return 16;
|
|
|
|
case SL::TYPE_USAMPLER3D:
|
|
|
|
return 16;
|
|
|
|
case SL::TYPE_SAMPLERCUBE:
|
|
|
|
return 16;
|
|
|
|
case SL::TYPE_SAMPLEREXT:
|
|
|
|
return 16;
|
2020-08-26 08:11:57 +02:00
|
|
|
case SL::TYPE_STRUCT:
|
|
|
|
return 0;
|
2018-01-12 16:42:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ERR_FAIL_V(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int _get_datatype_alignment(SL::DataType p_type) {
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (p_type) {
|
2021-05-04 14:35:44 +02:00
|
|
|
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 16;
|
|
|
|
case SL::TYPE_MAT4:
|
|
|
|
return 16;
|
|
|
|
case SL::TYPE_SAMPLER2D:
|
|
|
|
return 16;
|
|
|
|
case SL::TYPE_ISAMPLER2D:
|
|
|
|
return 16;
|
|
|
|
case SL::TYPE_USAMPLER2D:
|
|
|
|
return 16;
|
|
|
|
case SL::TYPE_SAMPLER2DARRAY:
|
|
|
|
return 16;
|
|
|
|
case SL::TYPE_ISAMPLER2DARRAY:
|
|
|
|
return 16;
|
|
|
|
case SL::TYPE_USAMPLER2DARRAY:
|
|
|
|
return 16;
|
|
|
|
case SL::TYPE_SAMPLER3D:
|
|
|
|
return 16;
|
|
|
|
case SL::TYPE_ISAMPLER3D:
|
|
|
|
return 16;
|
|
|
|
case SL::TYPE_USAMPLER3D:
|
|
|
|
return 16;
|
|
|
|
case SL::TYPE_SAMPLERCUBE:
|
|
|
|
return 16;
|
|
|
|
case SL::TYPE_SAMPLEREXT:
|
|
|
|
return 16;
|
2020-08-26 08:11:57 +02:00
|
|
|
case SL::TYPE_STRUCT:
|
|
|
|
return 0;
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
|
2016-10-27 16:50:26 +02:00
|
|
|
ERR_FAIL_V(0);
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
2017-11-27 16:47:46 +01:00
|
|
|
static String _interpstr(SL::DataInterpolation p_interp) {
|
|
|
|
switch (p_interp) {
|
2021-05-04 14:35:44 +02:00
|
|
|
case SL::INTERPOLATION_FLAT:
|
|
|
|
return "flat ";
|
|
|
|
case SL::INTERPOLATION_SMOOTH:
|
|
|
|
return "";
|
2017-11-27 16:47:46 +01:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
static String _prestr(SL::DataPrecision p_pres) {
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (p_pres) {
|
2021-05-04 14:35:44 +02:00
|
|
|
case SL::PRECISION_LOWP:
|
|
|
|
return "lowp ";
|
|
|
|
case SL::PRECISION_MEDIUMP:
|
|
|
|
return "mediump ";
|
|
|
|
case SL::PRECISION_HIGHP:
|
|
|
|
return "highp ";
|
|
|
|
case SL::PRECISION_DEFAULT:
|
|
|
|
return "";
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2021-11-18 22:20:07 +01:00
|
|
|
static String _constr(bool p_is_const) {
|
|
|
|
if (p_is_const) {
|
|
|
|
return "const ";
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
static String _qualstr(SL::ArgumentQualifier p_qual) {
|
|
|
|
switch (p_qual) {
|
2021-05-04 14:35:44 +02:00
|
|
|
case SL::ARGUMENT_QUALIFIER_IN:
|
|
|
|
return "";
|
|
|
|
case SL::ARGUMENT_QUALIFIER_OUT:
|
|
|
|
return "out ";
|
|
|
|
case SL::ARGUMENT_QUALIFIER_INOUT:
|
|
|
|
return "inout ";
|
2017-04-07 04:36:37 +02:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
static String _opstr(SL::Operator p_op) {
|
|
|
|
return SL::get_operator_text(p_op);
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
static String _mkid(const String &p_id) {
|
2020-01-31 07:11:17 +01:00
|
|
|
String id = "m_" + p_id.replace("__", "_dus_");
|
2019-02-13 09:23:29 +01:00
|
|
|
return id.replace("__", "_dus_"); //doubleunderscore is reserved in glsl
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
|
2016-10-30 01:48:09 +02:00
|
|
|
static String f2sp0(float p_float) {
|
2018-11-20 03:41:18 +01:00
|
|
|
String num = rtoss(p_float);
|
|
|
|
if (num.find(".") == -1 && num.find("e") == -1) {
|
|
|
|
num += ".0";
|
|
|
|
}
|
|
|
|
return num;
|
2016-10-30 01:48:09 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNode::Value> &p_values) {
|
|
|
|
switch (p_type) {
|
2021-05-04 14:35:44 +02:00
|
|
|
case SL::TYPE_BOOL:
|
|
|
|
return p_values[0].boolean ? "true" : "false";
|
2016-10-30 01:48:09 +02:00
|
|
|
case SL::TYPE_BVEC2:
|
|
|
|
case SL::TYPE_BVEC3:
|
|
|
|
case SL::TYPE_BVEC4: {
|
2017-03-05 16:44:50 +01:00
|
|
|
String text = "bvec" + itos(p_type - SL::TYPE_BOOL + 1) + "(";
|
|
|
|
for (int i = 0; i < p_values.size(); i++) {
|
2021-05-05 12:44:11 +02:00
|
|
|
if (i > 0) {
|
2017-03-05 16:44:50 +01:00
|
|
|
text += ",";
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2016-10-30 01:48:09 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
text += p_values[i].boolean ? "true" : "false";
|
2016-10-30 01:48:09 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
text += ")";
|
2016-10-30 01:48:09 +02:00
|
|
|
return text;
|
|
|
|
}
|
|
|
|
|
2021-05-04 14:35:44 +02:00
|
|
|
case SL::TYPE_INT:
|
|
|
|
return itos(p_values[0].sint);
|
2016-10-30 01:48:09 +02:00
|
|
|
case SL::TYPE_IVEC2:
|
|
|
|
case SL::TYPE_IVEC3:
|
|
|
|
case SL::TYPE_IVEC4: {
|
2017-03-05 16:44:50 +01:00
|
|
|
String text = "ivec" + itos(p_type - SL::TYPE_INT + 1) + "(";
|
|
|
|
for (int i = 0; i < p_values.size(); i++) {
|
2021-05-05 12:44:11 +02:00
|
|
|
if (i > 0) {
|
2017-03-05 16:44:50 +01:00
|
|
|
text += ",";
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2016-10-30 01:48:09 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
text += itos(p_values[i].sint);
|
2016-10-30 01:48:09 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
text += ")";
|
2016-10-30 01:48:09 +02:00
|
|
|
return text;
|
|
|
|
|
|
|
|
} break;
|
2021-05-04 14:35:44 +02:00
|
|
|
case SL::TYPE_UINT:
|
|
|
|
return itos(p_values[0].uint) + "u";
|
2016-10-30 01:48:09 +02:00
|
|
|
case SL::TYPE_UVEC2:
|
|
|
|
case SL::TYPE_UVEC3:
|
2017-03-05 16:44:50 +01:00
|
|
|
case SL::TYPE_UVEC4: {
|
|
|
|
String text = "uvec" + itos(p_type - SL::TYPE_UINT + 1) + "(";
|
|
|
|
for (int i = 0; i < p_values.size(); i++) {
|
2021-05-05 12:44:11 +02:00
|
|
|
if (i > 0) {
|
2017-03-05 16:44:50 +01:00
|
|
|
text += ",";
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2016-10-30 01:48:09 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
text += itos(p_values[i].uint) + "u";
|
2016-10-30 01:48:09 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
text += ")";
|
2016-10-30 01:48:09 +02:00
|
|
|
return text;
|
|
|
|
} break;
|
2021-05-04 14:35:44 +02:00
|
|
|
case SL::TYPE_FLOAT:
|
|
|
|
return f2sp0(p_values[0].real);
|
2016-10-30 01:48:09 +02:00
|
|
|
case SL::TYPE_VEC2:
|
|
|
|
case SL::TYPE_VEC3:
|
2017-03-05 16:44:50 +01:00
|
|
|
case SL::TYPE_VEC4: {
|
|
|
|
String text = "vec" + itos(p_type - SL::TYPE_FLOAT + 1) + "(";
|
|
|
|
for (int i = 0; i < p_values.size(); i++) {
|
2021-05-05 12:44:11 +02:00
|
|
|
if (i > 0) {
|
2017-03-05 16:44:50 +01:00
|
|
|
text += ",";
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2016-10-30 01:48:09 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
text += f2sp0(p_values[i].real);
|
2016-10-30 01:48:09 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
text += ")";
|
2016-10-30 01:48:09 +02:00
|
|
|
return text;
|
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
} break;
|
|
|
|
case SL::TYPE_MAT2:
|
|
|
|
case SL::TYPE_MAT3:
|
|
|
|
case SL::TYPE_MAT4: {
|
|
|
|
String text = "mat" + itos(p_type - SL::TYPE_MAT2 + 2) + "(";
|
|
|
|
for (int i = 0; i < p_values.size(); i++) {
|
2021-05-05 12:44:11 +02:00
|
|
|
if (i > 0) {
|
2017-04-07 04:36:37 +02:00
|
|
|
text += ",";
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2017-04-07 04:36:37 +02:00
|
|
|
|
|
|
|
text += f2sp0(p_values[i].real);
|
|
|
|
}
|
|
|
|
text += ")";
|
|
|
|
return text;
|
|
|
|
|
2016-10-30 01:48:09 +02:00
|
|
|
} break;
|
2021-05-04 14:35:44 +02:00
|
|
|
default:
|
|
|
|
ERR_FAIL_V(String());
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-22 02:55:27 +02:00
|
|
|
void ShaderCompilerGLES3::_dump_function_deps(const SL::ShaderNode *p_node, const StringName &p_for_func, const Map<StringName, String> &p_func_code, String &r_to_add, Set<StringName> &added) {
|
2017-03-05 16:44:50 +01:00
|
|
|
int fidx = -1;
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_node->functions.size(); i++) {
|
|
|
|
if (p_node->functions[i].name == p_for_func) {
|
|
|
|
fidx = i;
|
2016-10-10 23:31:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND(fidx == -1);
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Set<StringName>::Element *E = p_node->functions[fidx].uses_function.front(); E; E = E->next()) {
|
2016-10-10 23:31:01 +02:00
|
|
|
if (added.has(E->get())) {
|
|
|
|
continue; //was added already
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_dump_function_deps(p_node, E->get(), p_func_code, r_to_add, added);
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2021-05-04 16:00:45 +02:00
|
|
|
SL::FunctionNode *fnode = nullptr;
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_node->functions.size(); i++) {
|
|
|
|
if (p_node->functions[i].name == E->get()) {
|
|
|
|
fnode = p_node->functions[i].function;
|
2016-10-10 23:31:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!fnode);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
r_to_add += "\n";
|
2016-10-10 23:31:01 +02:00
|
|
|
|
|
|
|
String header;
|
2020-08-26 08:11:57 +02:00
|
|
|
if (fnode->return_type == SL::TYPE_STRUCT) {
|
|
|
|
header = _mkid(fnode->return_struct_name) + " " + _mkid(fnode->name) + "(";
|
|
|
|
} else {
|
|
|
|
header = _typestr(fnode->return_type) + " " + _mkid(fnode->name) + "(";
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < fnode->arguments.size(); i++) {
|
2021-05-05 12:44:11 +02:00
|
|
|
if (i > 0) {
|
2017-03-05 16:44:50 +01:00
|
|
|
header += ", ";
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2021-11-18 22:20:07 +01:00
|
|
|
|
|
|
|
header += _constr(fnode->arguments[i].is_const);
|
|
|
|
|
2020-08-26 08:11:57 +02:00
|
|
|
if (fnode->arguments[i].type == SL::TYPE_STRUCT) {
|
|
|
|
header += _qualstr(fnode->arguments[i].qualifier) + _mkid(fnode->arguments[i].type_str) + " " + _mkid(fnode->arguments[i].name);
|
|
|
|
} else {
|
|
|
|
header += _qualstr(fnode->arguments[i].qualifier) + _prestr(fnode->arguments[i].precision) + _typestr(fnode->arguments[i].type) + " " + _mkid(fnode->arguments[i].name);
|
|
|
|
}
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
header += ")\n";
|
|
|
|
r_to_add += header;
|
|
|
|
r_to_add += p_func_code[E->get()];
|
2016-10-10 23:31:01 +02:00
|
|
|
|
|
|
|
added.insert(E->get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-22 02:55:27 +02:00
|
|
|
String ShaderCompilerGLES3::_dump_node_code(const SL::Node *p_node, int p_level, GeneratedCode &r_gen_code, IdentifierActions &p_actions, const DefaultIdentifierActions &p_default_actions, bool p_assigning, bool p_use_scope) {
|
2016-10-10 23:31:01 +02:00
|
|
|
String code;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (p_node->type) {
|
2016-10-10 23:31:01 +02:00
|
|
|
case SL::Node::TYPE_SHADER: {
|
2017-03-05 16:44:50 +01:00
|
|
|
SL::ShaderNode *pnode = (SL::ShaderNode *)p_node;
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < pnode->render_modes.size(); i++) {
|
2016-10-10 23:31:01 +02:00
|
|
|
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])) {
|
2017-03-05 16:44:50 +01:00
|
|
|
*p_actions.render_mode_flags[pnode->render_modes[i]] = true;
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (p_actions.render_mode_values.has(pnode->render_modes[i])) {
|
2017-03-05 16:44:50 +01:00
|
|
|
Pair<int *, int> &p = p_actions.render_mode_values[pnode->render_modes[i]];
|
|
|
|
*p.first = p.second;
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-26 08:11:57 +02:00
|
|
|
// structs
|
|
|
|
|
|
|
|
for (int i = 0; i < pnode->vstructs.size(); i++) {
|
|
|
|
SL::StructNode *st = pnode->vstructs[i].shader_struct;
|
|
|
|
String struct_code;
|
|
|
|
|
|
|
|
struct_code += "struct ";
|
|
|
|
struct_code += _mkid(pnode->vstructs[i].name);
|
|
|
|
struct_code += " ";
|
|
|
|
struct_code += "{\n";
|
|
|
|
for (int j = 0; j < st->members.size(); j++) {
|
|
|
|
SL::MemberNode *m = st->members[j];
|
|
|
|
if (m->datatype == SL::TYPE_STRUCT) {
|
|
|
|
struct_code += _mkid(m->struct_name);
|
|
|
|
} else {
|
|
|
|
struct_code += _prestr(m->precision);
|
|
|
|
struct_code += _typestr(m->datatype);
|
|
|
|
}
|
|
|
|
struct_code += " ";
|
|
|
|
struct_code += m->name;
|
2021-04-22 02:54:46 +02:00
|
|
|
if (m->array_size > 0) {
|
|
|
|
struct_code += "[";
|
|
|
|
struct_code += itos(m->array_size);
|
|
|
|
struct_code += "]";
|
|
|
|
}
|
2020-08-26 08:11:57 +02:00
|
|
|
struct_code += ";\n";
|
|
|
|
}
|
|
|
|
struct_code += "}";
|
|
|
|
struct_code += ";\n";
|
|
|
|
|
|
|
|
r_gen_code.vertex_global += struct_code;
|
|
|
|
r_gen_code.fragment_global += struct_code;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int max_texture_uniforms = 0;
|
|
|
|
int max_uniforms = 0;
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2021-09-26 21:31:17 +02:00
|
|
|
for (OrderedHashMap<StringName, SL::ShaderNode::Uniform>::Element E = pnode->uniforms.front(); E; E = E.next()) {
|
|
|
|
if (SL::is_sampler_type(E.get().type)) {
|
2016-10-10 23:31:01 +02:00
|
|
|
max_texture_uniforms++;
|
2021-05-05 12:44:11 +02:00
|
|
|
} else {
|
2016-10-10 23:31:01 +02:00
|
|
|
max_uniforms++;
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
r_gen_code.texture_uniforms.resize(max_texture_uniforms);
|
2016-10-30 01:48:09 +02:00
|
|
|
r_gen_code.texture_hints.resize(max_texture_uniforms);
|
2018-06-26 13:59:26 +02:00
|
|
|
r_gen_code.texture_types.resize(max_texture_uniforms);
|
2016-10-10 23:31:01 +02:00
|
|
|
|
|
|
|
Vector<int> uniform_sizes;
|
2016-11-21 02:49:53 +01:00
|
|
|
Vector<int> uniform_alignments;
|
|
|
|
Vector<StringName> uniform_defines;
|
2016-10-10 23:31:01 +02:00
|
|
|
uniform_sizes.resize(max_uniforms);
|
2016-11-21 02:49:53 +01:00
|
|
|
uniform_alignments.resize(max_uniforms);
|
|
|
|
uniform_defines.resize(max_uniforms);
|
2017-07-08 13:06:13 +02:00
|
|
|
bool uses_uniforms = false;
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2021-09-26 21:31:17 +02:00
|
|
|
for (OrderedHashMap<StringName, SL::ShaderNode::Uniform>::Element E = pnode->uniforms.front(); E; E = E.next()) {
|
2016-10-27 16:50:26 +02:00
|
|
|
String ucode;
|
|
|
|
|
2021-09-26 21:31:17 +02:00
|
|
|
if (SL::is_sampler_type(E.get().type)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
ucode = "uniform ";
|
2016-10-27 16:50:26 +02:00
|
|
|
}
|
|
|
|
|
2021-09-26 21:31:17 +02:00
|
|
|
ucode += _prestr(E.get().precision);
|
|
|
|
ucode += _typestr(E.get().type);
|
|
|
|
ucode += " " + _mkid(E.key());
|
2017-03-05 16:44:50 +01:00
|
|
|
ucode += ";\n";
|
2021-09-26 21:31:17 +02:00
|
|
|
if (SL::is_sampler_type(E.get().type)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_gen_code.vertex_global += ucode;
|
|
|
|
r_gen_code.fragment_global += ucode;
|
2021-09-26 21:31:17 +02:00
|
|
|
r_gen_code.texture_uniforms.write[E.get().texture_order] = _mkid(E.key());
|
|
|
|
r_gen_code.texture_hints.write[E.get().texture_order] = E.get().hint;
|
|
|
|
r_gen_code.texture_types.write[E.get().texture_order] = E.get().type;
|
2016-10-10 23:31:01 +02:00
|
|
|
} else {
|
2017-07-08 13:06:13 +02:00
|
|
|
if (!uses_uniforms) {
|
2016-10-10 23:31:01 +02:00
|
|
|
r_gen_code.defines.push_back(String("#define USE_MATERIAL\n").ascii());
|
2017-07-08 13:06:13 +02:00
|
|
|
uses_uniforms = true;
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
2021-09-26 21:31:17 +02:00
|
|
|
uniform_defines.write[E.get().order] = ucode;
|
|
|
|
uniform_sizes.write[E.get().order] = _get_datatype_size(E.get().type);
|
|
|
|
uniform_alignments.write[E.get().order] = _get_datatype_alignment(E.get().type);
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
|
2021-09-26 21:31:17 +02:00
|
|
|
p_actions.uniforms->insert(E.key(), E.get());
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < max_uniforms; i++) {
|
|
|
|
r_gen_code.uniforms += uniform_defines[i];
|
2016-11-21 02:49:53 +01:00
|
|
|
}
|
2020-01-21 21:32:27 +01:00
|
|
|
|
2018-01-12 16:42:07 +01:00
|
|
|
// add up
|
|
|
|
int offset = 0;
|
|
|
|
for (int i = 0; i < uniform_sizes.size(); i++) {
|
|
|
|
int align = offset % uniform_alignments[i];
|
|
|
|
|
|
|
|
if (align != 0) {
|
|
|
|
offset += uniform_alignments[i] - align;
|
|
|
|
}
|
|
|
|
|
|
|
|
r_gen_code.uniform_offsets.push_back(offset);
|
|
|
|
|
|
|
|
offset += uniform_sizes[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
r_gen_code.uniform_total_size = offset;
|
|
|
|
if (r_gen_code.uniform_total_size % 16 != 0) { //UBO sizes must be multiples of 16
|
|
|
|
r_gen_code.uniform_total_size += r_gen_code.uniform_total_size % 16;
|
|
|
|
}
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2021-04-22 02:55:27 +02:00
|
|
|
List<Pair<StringName, SL::ShaderNode::Varying>> var_frag_to_light;
|
|
|
|
|
2021-09-26 21:31:17 +02:00
|
|
|
for (OrderedHashMap<StringName, SL::ShaderNode::Varying>::Element E = pnode->varyings.front(); E; E = E.next()) {
|
|
|
|
if (E.get().stage == SL::ShaderNode::Varying::STAGE_FRAGMENT_TO_LIGHT || E.get().stage == SL::ShaderNode::Varying::STAGE_FRAGMENT) {
|
|
|
|
var_frag_to_light.push_back(Pair<StringName, SL::ShaderNode::Varying>(E.key(), E.get()));
|
|
|
|
fragment_varyings.insert(E.key());
|
2021-04-22 02:55:27 +02:00
|
|
|
continue;
|
|
|
|
}
|
2016-10-10 23:31:01 +02:00
|
|
|
String vcode;
|
2021-09-26 21:31:17 +02:00
|
|
|
String interp_mode = _interpstr(E.get().interpolation);
|
|
|
|
vcode += _prestr(E.get().precision);
|
|
|
|
vcode += _typestr(E.get().type);
|
|
|
|
vcode += " " + _mkid(E.key());
|
|
|
|
if (E.get().array_size > 0) {
|
2019-07-29 16:08:25 +02:00
|
|
|
vcode += "[";
|
2021-09-26 21:31:17 +02:00
|
|
|
vcode += itos(E.get().array_size);
|
2019-07-29 16:08:25 +02:00
|
|
|
vcode += "]";
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
vcode += ";\n";
|
2017-11-27 16:47:46 +01:00
|
|
|
r_gen_code.vertex_global += interp_mode + "out " + vcode;
|
|
|
|
r_gen_code.fragment_global += interp_mode + "in " + vcode;
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
|
2021-04-22 02:55:27 +02:00
|
|
|
if (var_frag_to_light.size() > 0) {
|
|
|
|
String gcode = "\n\nstruct {\n";
|
|
|
|
for (List<Pair<StringName, SL::ShaderNode::Varying>>::Element *E = var_frag_to_light.front(); E; E = E->next()) {
|
|
|
|
gcode += "\t" + _prestr(E->get().second.precision) + _typestr(E->get().second.type) + " " + _mkid(E->get().first);
|
|
|
|
if (E->get().second.array_size > 0) {
|
|
|
|
gcode += "[";
|
|
|
|
gcode += itos(E->get().second.array_size);
|
|
|
|
gcode += "]";
|
|
|
|
}
|
|
|
|
gcode += ";\n";
|
|
|
|
}
|
|
|
|
gcode += "} frag_to_light;\n";
|
|
|
|
r_gen_code.fragment_global += gcode;
|
|
|
|
}
|
|
|
|
|
2020-03-31 13:32:33 +02:00
|
|
|
for (int i = 0; i < pnode->vconstants.size(); i++) {
|
2021-07-26 15:29:39 +02:00
|
|
|
const SL::ShaderNode::Constant &cnode = pnode->vconstants[i];
|
2019-05-30 16:19:24 +02:00
|
|
|
String gcode;
|
2021-11-18 22:20:07 +01:00
|
|
|
gcode += _constr(true);
|
2020-08-26 08:11:57 +02:00
|
|
|
if (pnode->vconstants[i].type == SL::TYPE_STRUCT) {
|
2021-07-26 15:29:39 +02:00
|
|
|
gcode += _mkid(cnode.type_str);
|
2020-08-26 08:11:57 +02:00
|
|
|
} else {
|
2021-07-26 15:29:39 +02:00
|
|
|
gcode += _prestr(cnode.precision);
|
|
|
|
gcode += _typestr(cnode.type);
|
|
|
|
}
|
|
|
|
gcode += " " + _mkid(String(cnode.name));
|
|
|
|
if (cnode.array_size > 0) {
|
|
|
|
gcode += "[";
|
|
|
|
gcode += itos(cnode.array_size);
|
|
|
|
gcode += "]";
|
2020-08-26 08:11:57 +02:00
|
|
|
}
|
2019-05-30 16:19:24 +02:00
|
|
|
gcode += "=";
|
2021-07-26 15:29:39 +02:00
|
|
|
gcode += _dump_node_code(cnode.initializer, p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
2019-05-30 16:19:24 +02:00
|
|
|
gcode += ";\n";
|
|
|
|
r_gen_code.vertex_global += gcode;
|
|
|
|
r_gen_code.fragment_global += gcode;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<StringName, String> function_code;
|
2016-10-10 23:31:01 +02:00
|
|
|
|
|
|
|
//code for functions
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < pnode->functions.size(); i++) {
|
|
|
|
SL::FunctionNode *fnode = pnode->functions[i].function;
|
2021-04-22 02:55:27 +02:00
|
|
|
function = fnode;
|
2018-11-14 13:32:39 +01:00
|
|
|
current_func_name = fnode->name;
|
2018-01-06 13:56:00 +01:00
|
|
|
function_code[fnode->name] = _dump_node_code(fnode->body, p_level + 1, r_gen_code, p_actions, p_default_actions, p_assigning);
|
2021-04-22 02:55:27 +02:00
|
|
|
function = nullptr;
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//place functions in actual code
|
|
|
|
|
|
|
|
Set<StringName> added_vtx;
|
|
|
|
Set<StringName> added_fragment; //share for light
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < pnode->functions.size(); i++) {
|
|
|
|
SL::FunctionNode *fnode = pnode->functions[i].function;
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2021-04-22 02:55:27 +02:00
|
|
|
function = fnode;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
current_func_name = fnode->name;
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2018-02-07 11:56:52 +01:00
|
|
|
if (fnode->name == vertex_name) {
|
2017-03-05 16:44:50 +01:00
|
|
|
_dump_function_deps(pnode, fnode->name, function_code, r_gen_code.vertex_global, added_vtx);
|
2018-02-07 11:56:52 +01:00
|
|
|
r_gen_code.vertex = function_code[vertex_name];
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
|
2018-02-07 11:56:52 +01:00
|
|
|
if (fnode->name == fragment_name) {
|
2017-03-05 16:44:50 +01:00
|
|
|
_dump_function_deps(pnode, fnode->name, function_code, r_gen_code.fragment_global, added_fragment);
|
2018-02-07 11:56:52 +01:00
|
|
|
r_gen_code.fragment = function_code[fragment_name];
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
|
2018-02-07 11:56:52 +01:00
|
|
|
if (fnode->name == light_name) {
|
2017-03-05 16:44:50 +01:00
|
|
|
_dump_function_deps(pnode, fnode->name, function_code, r_gen_code.fragment_global, added_fragment);
|
2018-02-07 11:56:52 +01:00
|
|
|
r_gen_code.light = function_code[light_name];
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
2021-04-22 02:55:27 +02:00
|
|
|
|
|
|
|
function = nullptr;
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//code+=dump_node_code(pnode->body,p_level);
|
|
|
|
} break;
|
2020-08-26 08:11:57 +02:00
|
|
|
case SL::Node::TYPE_STRUCT: {
|
|
|
|
} break;
|
2016-10-10 23:31:01 +02:00
|
|
|
case SL::Node::TYPE_FUNCTION: {
|
|
|
|
} break;
|
|
|
|
case SL::Node::TYPE_BLOCK: {
|
2017-03-05 16:44:50 +01:00
|
|
|
SL::BlockNode *bnode = (SL::BlockNode *)p_node;
|
2016-10-10 23:31:01 +02:00
|
|
|
|
|
|
|
//variables
|
2017-09-05 20:22:33 +02:00
|
|
|
if (!bnode->single_statement) {
|
|
|
|
code += _mktab(p_level - 1) + "{\n";
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
2017-09-13 09:13:23 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < bnode->statements.size(); i++) {
|
2018-01-06 13:56:00 +01:00
|
|
|
String scode = _dump_node_code(bnode->statements[i], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2017-09-13 09:13:23 +02:00
|
|
|
if (bnode->statements[i]->type == SL::Node::TYPE_CONTROL_FLOW || bnode->single_statement) {
|
2017-03-05 16:44:50 +01:00
|
|
|
code += scode; //use directly
|
2016-10-10 23:31:01 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
code += _mktab(p_level) + scode + ";\n";
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
}
|
2017-09-05 20:22:33 +02:00
|
|
|
if (!bnode->single_statement) {
|
|
|
|
code += _mktab(p_level - 1) + "}\n";
|
|
|
|
}
|
2016-10-10 23:31:01 +02:00
|
|
|
|
|
|
|
} break;
|
2017-09-05 20:22:33 +02:00
|
|
|
case SL::Node::TYPE_VARIABLE_DECLARATION: {
|
|
|
|
SL::VariableDeclarationNode *vdnode = (SL::VariableDeclarationNode *)p_node;
|
|
|
|
|
2019-08-05 09:35:53 +02:00
|
|
|
String declaration;
|
2021-11-18 22:20:07 +01:00
|
|
|
declaration += _constr(vdnode->is_const);
|
2020-08-26 08:11:57 +02:00
|
|
|
if (vdnode->datatype == SL::TYPE_STRUCT) {
|
|
|
|
declaration += _mkid(vdnode->struct_name);
|
|
|
|
} else {
|
|
|
|
declaration += _prestr(vdnode->precision);
|
|
|
|
declaration += _typestr(vdnode->datatype);
|
|
|
|
}
|
2017-09-13 09:13:23 +02:00
|
|
|
for (int i = 0; i < vdnode->declarations.size(); i++) {
|
|
|
|
if (i > 0) {
|
|
|
|
declaration += ",";
|
2017-09-05 20:22:33 +02:00
|
|
|
} else {
|
2017-09-13 09:13:23 +02:00
|
|
|
declaration += " ";
|
2017-09-05 20:22:33 +02:00
|
|
|
}
|
2017-09-13 09:13:23 +02:00
|
|
|
declaration += _mkid(vdnode->declarations[i].name);
|
2017-09-05 20:22:33 +02:00
|
|
|
if (vdnode->declarations[i].initializer) {
|
2017-09-13 09:13:23 +02:00
|
|
|
declaration += "=";
|
2018-01-06 13:56:00 +01:00
|
|
|
declaration += _dump_node_code(vdnode->declarations[i].initializer, p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
2017-09-05 20:22:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-13 09:13:23 +02:00
|
|
|
code += declaration;
|
2017-09-05 20:22:33 +02:00
|
|
|
} break;
|
2016-10-10 23:31:01 +02:00
|
|
|
case SL::Node::TYPE_VARIABLE: {
|
2017-03-05 16:44:50 +01:00
|
|
|
SL::VariableNode *vnode = (SL::VariableNode *)p_node;
|
2021-04-22 02:55:27 +02:00
|
|
|
bool use_fragment_varying = false;
|
|
|
|
|
2021-08-13 08:30:35 +02:00
|
|
|
if (!vnode->is_local && current_func_name != vertex_name) {
|
2021-04-22 02:55:27 +02:00
|
|
|
if (p_assigning) {
|
|
|
|
if (shader->varyings.has(vnode->name)) {
|
|
|
|
use_fragment_varying = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (fragment_varyings.has(vnode->name)) {
|
|
|
|
use_fragment_varying = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2018-01-06 13:56:00 +01:00
|
|
|
if (p_assigning && p_actions.write_flag_pointers.has(vnode->name)) {
|
|
|
|
*p_actions.write_flag_pointers[vnode->name] = true;
|
|
|
|
}
|
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
if (p_default_actions.usage_defines.has(vnode->name) && !used_name_defines.has(vnode->name)) {
|
2016-10-27 16:50:26 +02:00
|
|
|
String define = p_default_actions.usage_defines[vnode->name];
|
|
|
|
if (define.begins_with("@")) {
|
2017-03-05 16:44:50 +01:00
|
|
|
define = p_default_actions.usage_defines[define.substr(1, define.length())];
|
2016-10-27 16:50:26 +02:00
|
|
|
}
|
|
|
|
r_gen_code.defines.push_back(define.utf8());
|
2016-10-10 23:31:01 +02:00
|
|
|
used_name_defines.insert(vnode->name);
|
|
|
|
}
|
|
|
|
|
2016-12-03 02:23:16 +01:00
|
|
|
if (p_actions.usage_flag_pointers.has(vnode->name) && !used_flag_pointers.has(vnode->name)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
*p_actions.usage_flag_pointers[vnode->name] = true;
|
2016-12-03 02:23:16 +01:00
|
|
|
used_flag_pointers.insert(vnode->name);
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
|
2021-05-05 12:44:11 +02:00
|
|
|
if (p_default_actions.renames.has(vnode->name)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
code = p_default_actions.renames[vnode->name];
|
2021-04-22 02:55:27 +02:00
|
|
|
} else if (use_fragment_varying) {
|
|
|
|
code = "frag_to_light." + _mkid(vnode->name);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
code = _mkid(vnode->name);
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2019-07-10 18:52:50 +02:00
|
|
|
if (vnode->name == time_name) {
|
|
|
|
if (current_func_name == vertex_name) {
|
|
|
|
r_gen_code.uses_vertex_time = true;
|
|
|
|
}
|
|
|
|
if (current_func_name == fragment_name || current_func_name == light_name) {
|
|
|
|
r_gen_code.uses_fragment_time = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2021-04-22 02:54:46 +02:00
|
|
|
case SL::Node::TYPE_ARRAY_CONSTRUCT: {
|
|
|
|
SL::ArrayConstructNode *acnode = (SL::ArrayConstructNode *)p_node;
|
|
|
|
int sz = acnode->initializer.size();
|
|
|
|
if (acnode->datatype == SL::TYPE_STRUCT) {
|
|
|
|
code += _mkid(acnode->struct_name);
|
|
|
|
} else {
|
|
|
|
code += _typestr(acnode->datatype);
|
|
|
|
}
|
|
|
|
code += "[";
|
|
|
|
code += itos(acnode->initializer.size());
|
|
|
|
code += "]";
|
|
|
|
code += "(";
|
|
|
|
for (int i = 0; i < sz; i++) {
|
|
|
|
code += _dump_node_code(acnode->initializer[i], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
|
|
|
if (i != sz - 1) {
|
|
|
|
code += ", ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
code += ")";
|
|
|
|
} break;
|
2019-07-10 18:52:50 +02:00
|
|
|
case SL::Node::TYPE_ARRAY_DECLARATION: {
|
2019-08-05 09:35:53 +02:00
|
|
|
SL::ArrayDeclarationNode *adnode = (SL::ArrayDeclarationNode *)p_node;
|
2019-07-10 18:52:50 +02:00
|
|
|
|
2019-08-05 09:35:53 +02:00
|
|
|
String declaration;
|
|
|
|
if (adnode->is_const) {
|
|
|
|
declaration += "const ";
|
|
|
|
}
|
2020-08-26 08:11:57 +02:00
|
|
|
if (adnode->datatype == SL::TYPE_STRUCT) {
|
|
|
|
declaration += _mkid(adnode->struct_name);
|
|
|
|
} else {
|
|
|
|
declaration += _prestr(adnode->precision);
|
|
|
|
declaration += _typestr(adnode->datatype);
|
|
|
|
}
|
2019-08-05 09:35:53 +02:00
|
|
|
for (int i = 0; i < adnode->declarations.size(); i++) {
|
2019-07-10 18:52:50 +02:00
|
|
|
if (i > 0) {
|
|
|
|
declaration += ",";
|
|
|
|
} else {
|
|
|
|
declaration += " ";
|
|
|
|
}
|
2019-08-05 09:35:53 +02:00
|
|
|
declaration += _mkid(adnode->declarations[i].name);
|
2019-07-10 18:52:50 +02:00
|
|
|
declaration += "[";
|
2019-08-05 09:35:53 +02:00
|
|
|
declaration += itos(adnode->declarations[i].size);
|
2019-07-10 18:52:50 +02:00
|
|
|
declaration += "]";
|
2019-08-05 09:35:53 +02:00
|
|
|
int sz = adnode->declarations[i].initializer.size();
|
2019-07-15 17:47:22 +02:00
|
|
|
if (sz > 0) {
|
|
|
|
declaration += "=";
|
2020-08-26 08:11:57 +02:00
|
|
|
if (adnode->datatype == SL::TYPE_STRUCT) {
|
|
|
|
declaration += _mkid(adnode->struct_name);
|
|
|
|
} else {
|
|
|
|
declaration += _typestr(adnode->datatype);
|
|
|
|
}
|
2019-07-15 17:47:22 +02:00
|
|
|
declaration += "[";
|
|
|
|
declaration += itos(sz);
|
|
|
|
declaration += "]";
|
|
|
|
declaration += "(";
|
|
|
|
for (int j = 0; j < sz; j++) {
|
2019-08-05 09:35:53 +02:00
|
|
|
declaration += _dump_node_code(adnode->declarations[i].initializer[j], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
2019-07-15 17:47:22 +02:00
|
|
|
if (j != sz - 1) {
|
|
|
|
declaration += ", ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
declaration += ")";
|
|
|
|
}
|
2019-07-10 18:52:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
code += declaration;
|
|
|
|
} break;
|
|
|
|
case SL::Node::TYPE_ARRAY: {
|
2019-08-05 09:35:53 +02:00
|
|
|
SL::ArrayNode *anode = (SL::ArrayNode *)p_node;
|
2021-04-22 02:55:27 +02:00
|
|
|
bool use_fragment_varying = false;
|
|
|
|
|
2021-08-13 08:30:35 +02:00
|
|
|
if (!anode->is_local && current_func_name != vertex_name) {
|
2021-04-22 02:55:27 +02:00
|
|
|
if (anode->assign_expression != nullptr) {
|
|
|
|
use_fragment_varying = true;
|
|
|
|
} else {
|
|
|
|
if (p_assigning) {
|
|
|
|
if (shader->varyings.has(anode->name)) {
|
|
|
|
use_fragment_varying = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (fragment_varyings.has(anode->name)) {
|
|
|
|
use_fragment_varying = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-10 18:52:50 +02:00
|
|
|
|
2019-08-05 09:35:53 +02:00
|
|
|
if (p_assigning && p_actions.write_flag_pointers.has(anode->name)) {
|
|
|
|
*p_actions.write_flag_pointers[anode->name] = true;
|
2019-07-10 18:52:50 +02:00
|
|
|
}
|
|
|
|
|
2019-08-05 09:35:53 +02:00
|
|
|
if (p_default_actions.usage_defines.has(anode->name) && !used_name_defines.has(anode->name)) {
|
|
|
|
String define = p_default_actions.usage_defines[anode->name];
|
2019-07-10 18:52:50 +02:00
|
|
|
if (define.begins_with("@")) {
|
|
|
|
define = p_default_actions.usage_defines[define.substr(1, define.length())];
|
|
|
|
}
|
|
|
|
r_gen_code.defines.push_back(define.utf8());
|
2019-08-05 09:35:53 +02:00
|
|
|
used_name_defines.insert(anode->name);
|
2019-07-10 18:52:50 +02:00
|
|
|
}
|
|
|
|
|
2019-08-05 09:35:53 +02:00
|
|
|
if (p_actions.usage_flag_pointers.has(anode->name) && !used_flag_pointers.has(anode->name)) {
|
|
|
|
*p_actions.usage_flag_pointers[anode->name] = true;
|
|
|
|
used_flag_pointers.insert(anode->name);
|
2019-07-10 18:52:50 +02:00
|
|
|
}
|
|
|
|
|
2021-05-05 12:44:11 +02:00
|
|
|
if (p_default_actions.renames.has(anode->name)) {
|
2019-08-05 09:35:53 +02:00
|
|
|
code = p_default_actions.renames[anode->name];
|
2021-04-22 02:55:27 +02:00
|
|
|
} else if (use_fragment_varying) {
|
|
|
|
code = "frag_to_light." + _mkid(anode->name);
|
2021-05-05 12:44:11 +02:00
|
|
|
} else {
|
2019-08-05 09:35:53 +02:00
|
|
|
code = _mkid(anode->name);
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2019-07-10 18:52:50 +02:00
|
|
|
|
2021-05-04 16:00:45 +02:00
|
|
|
if (anode->call_expression != nullptr) {
|
2019-07-10 18:52:50 +02:00
|
|
|
code += ".";
|
2020-06-03 18:43:47 +02:00
|
|
|
code += _dump_node_code(anode->call_expression, p_level, r_gen_code, p_actions, p_default_actions, p_assigning, false);
|
2021-04-22 02:55:05 +02:00
|
|
|
} else if (anode->index_expression != nullptr) {
|
2019-07-10 18:52:50 +02:00
|
|
|
code += "[";
|
2019-08-05 09:35:53 +02:00
|
|
|
code += _dump_node_code(anode->index_expression, p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
2019-07-10 18:52:50 +02:00
|
|
|
code += "]";
|
2021-04-22 02:55:27 +02:00
|
|
|
} else if (anode->assign_expression != nullptr) {
|
2021-04-22 02:55:05 +02:00
|
|
|
code += "=";
|
|
|
|
code += _dump_node_code(anode->assign_expression, p_level, r_gen_code, p_actions, p_default_actions, true, false);
|
2019-07-10 18:52:50 +02:00
|
|
|
}
|
|
|
|
|
2019-08-05 09:35:53 +02:00
|
|
|
if (anode->name == time_name) {
|
2017-03-05 16:44:50 +01:00
|
|
|
if (current_func_name == vertex_name) {
|
|
|
|
r_gen_code.uses_vertex_time = true;
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
2018-02-07 11:56:52 +01:00
|
|
|
if (current_func_name == fragment_name || current_func_name == light_name) {
|
2017-03-05 16:44:50 +01:00
|
|
|
r_gen_code.uses_fragment_time = true;
|
2016-11-10 03:55:06 +01:00
|
|
|
}
|
|
|
|
}
|
2016-10-10 23:31:01 +02:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case SL::Node::TYPE_CONSTANT: {
|
2017-03-05 16:44:50 +01:00
|
|
|
SL::ConstantNode *cnode = (SL::ConstantNode *)p_node;
|
2021-07-26 15:29:39 +02:00
|
|
|
|
|
|
|
if (cnode->array_size == 0) {
|
|
|
|
return get_constant_text(cnode->datatype, cnode->values);
|
|
|
|
} else {
|
|
|
|
if (cnode->get_datatype() == SL::TYPE_STRUCT) {
|
|
|
|
code += _mkid(cnode->struct_name);
|
|
|
|
} else {
|
|
|
|
code += _typestr(cnode->datatype);
|
|
|
|
}
|
|
|
|
code += "[";
|
|
|
|
code += itos(cnode->array_size);
|
|
|
|
code += "]";
|
|
|
|
code += "(";
|
|
|
|
for (int i = 0; i < cnode->array_size; i++) {
|
|
|
|
if (i > 0) {
|
|
|
|
code += ",";
|
|
|
|
} else {
|
|
|
|
code += "";
|
|
|
|
}
|
|
|
|
code += _dump_node_code(cnode->array_declarations[0].initializer[i], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
|
|
|
}
|
|
|
|
code += ")";
|
|
|
|
}
|
2016-10-10 23:31:01 +02:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case SL::Node::TYPE_OPERATOR: {
|
2017-03-05 16:44:50 +01:00
|
|
|
SL::OperatorNode *onode = (SL::OperatorNode *)p_node;
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (onode->op) {
|
2016-10-10 23:31:01 +02:00
|
|
|
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:
|
2018-01-06 13:56:00 +01:00
|
|
|
code = _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions, true) + _opstr(onode->op) + _dump_node_code(onode->arguments[1], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
2016-10-10 23:31:01 +02:00
|
|
|
break;
|
|
|
|
case SL::OP_BIT_INVERT:
|
|
|
|
case SL::OP_NEGATE:
|
|
|
|
case SL::OP_NOT:
|
|
|
|
case SL::OP_DECREMENT:
|
|
|
|
case SL::OP_INCREMENT:
|
2018-01-06 13:56:00 +01:00
|
|
|
code = _opstr(onode->op) + _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
2016-10-10 23:31:01 +02:00
|
|
|
break;
|
|
|
|
case SL::OP_POST_DECREMENT:
|
|
|
|
case SL::OP_POST_INCREMENT:
|
2018-01-06 13:56:00 +01:00
|
|
|
code = _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning) + _opstr(onode->op);
|
2016-10-10 23:31:01 +02:00
|
|
|
break;
|
|
|
|
case SL::OP_CALL:
|
2020-08-26 08:11:57 +02:00
|
|
|
case SL::OP_STRUCT:
|
2016-10-10 23:31:01 +02:00
|
|
|
case SL::OP_CONSTRUCT: {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(onode->arguments[0]->type != SL::Node::TYPE_VARIABLE, String());
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
SL::VariableNode *vnode = (SL::VariableNode *)onode->arguments[0];
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2020-08-26 08:11:57 +02:00
|
|
|
if (onode->op == SL::OP_STRUCT) {
|
|
|
|
code += _mkid(vnode->name);
|
|
|
|
} else if (onode->op == SL::OP_CONSTRUCT) {
|
2017-03-05 16:44:50 +01:00
|
|
|
code += String(vnode->name);
|
2016-10-10 23:31:01 +02:00
|
|
|
} else {
|
|
|
|
if (internal_functions.has(vnode->name)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
code += vnode->name;
|
2016-10-10 23:31:01 +02:00
|
|
|
} else if (p_default_actions.renames.has(vnode->name)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
code += p_default_actions.renames[vnode->name];
|
2016-10-10 23:31:01 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
code += _mkid(vnode->name);
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
code += "(";
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 1; i < onode->arguments.size(); i++) {
|
2021-05-05 12:44:11 +02:00
|
|
|
if (i > 1) {
|
2017-03-05 16:44:50 +01:00
|
|
|
code += ", ";
|
2021-05-05 12:44:11 +02:00
|
|
|
}
|
2018-01-06 13:56:00 +01:00
|
|
|
code += _dump_node_code(onode->arguments[i], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
code += ")";
|
2016-10-10 23:31:01 +02:00
|
|
|
} break;
|
2017-04-07 04:36:37 +02:00
|
|
|
case SL::OP_INDEX: {
|
2018-01-06 13:56:00 +01:00
|
|
|
code += _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
2017-04-07 04:36:37 +02:00
|
|
|
code += "[";
|
2018-01-06 13:56:00 +01:00
|
|
|
code += _dump_node_code(onode->arguments[1], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
2017-04-07 04:36:37 +02:00
|
|
|
code += "]";
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case SL::OP_SELECT_IF: {
|
2019-08-19 07:40:54 +02:00
|
|
|
code += "(";
|
2018-01-06 13:56:00 +01:00
|
|
|
code += _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
2017-04-07 04:36:37 +02:00
|
|
|
code += "?";
|
2018-01-06 13:56:00 +01:00
|
|
|
code += _dump_node_code(onode->arguments[1], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
2017-04-07 04:36:37 +02:00
|
|
|
code += ":";
|
2018-01-06 13:56:00 +01:00
|
|
|
code += _dump_node_code(onode->arguments[2], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
2019-08-19 07:40:54 +02:00
|
|
|
code += ")";
|
2017-04-07 04:36:37 +02:00
|
|
|
|
|
|
|
} break;
|
2017-06-04 23:08:06 +02:00
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
default: {
|
2020-06-03 18:43:47 +02:00
|
|
|
if (p_use_scope) {
|
|
|
|
code += "(";
|
|
|
|
}
|
|
|
|
code += _dump_node_code(onode->arguments[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning) + _opstr(onode->op) + _dump_node_code(onode->arguments[1], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
|
|
|
if (p_use_scope) {
|
|
|
|
code += ")";
|
|
|
|
}
|
2016-10-10 23:31:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case SL::Node::TYPE_CONTROL_FLOW: {
|
2017-03-05 16:44:50 +01:00
|
|
|
SL::ControlFlowNode *cfnode = (SL::ControlFlowNode *)p_node;
|
|
|
|
if (cfnode->flow_op == SL::FLOW_OP_IF) {
|
2018-01-06 13:56:00 +01:00
|
|
|
code += _mktab(p_level) + "if (" + _dump_node_code(cfnode->expressions[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning) + ")\n";
|
|
|
|
code += _dump_node_code(cfnode->blocks[0], p_level + 1, r_gen_code, p_actions, p_default_actions, p_assigning);
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cfnode->blocks.size() == 2) {
|
|
|
|
code += _mktab(p_level) + "else\n";
|
2018-01-06 13:56:00 +01:00
|
|
|
code += _dump_node_code(cfnode->blocks[1], p_level + 1, r_gen_code, p_actions, p_default_actions, p_assigning);
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
2019-08-14 13:22:25 +02:00
|
|
|
} else if (cfnode->flow_op == SL::FLOW_OP_SWITCH) {
|
|
|
|
code += _mktab(p_level) + "switch (" + _dump_node_code(cfnode->expressions[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning) + ")\n";
|
|
|
|
code += _dump_node_code(cfnode->blocks[0], p_level + 1, r_gen_code, p_actions, p_default_actions, p_assigning);
|
|
|
|
} else if (cfnode->flow_op == SL::FLOW_OP_CASE) {
|
|
|
|
code += _mktab(p_level) + "case " + _dump_node_code(cfnode->expressions[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning) + ":\n";
|
|
|
|
code += _dump_node_code(cfnode->blocks[0], p_level + 1, r_gen_code, p_actions, p_default_actions, p_assigning);
|
|
|
|
} else if (cfnode->flow_op == SL::FLOW_OP_DEFAULT) {
|
|
|
|
code += _mktab(p_level) + "default:\n";
|
|
|
|
code += _dump_node_code(cfnode->blocks[0], p_level + 1, r_gen_code, p_actions, p_default_actions, p_assigning);
|
2019-08-13 15:19:14 +02:00
|
|
|
} else if (cfnode->flow_op == SL::FLOW_OP_DO) {
|
|
|
|
code += _mktab(p_level) + "do";
|
|
|
|
code += _dump_node_code(cfnode->blocks[0], p_level + 1, r_gen_code, p_actions, p_default_actions, p_assigning);
|
|
|
|
code += _mktab(p_level) + "while (" + _dump_node_code(cfnode->expressions[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning) + ");";
|
|
|
|
|
2017-06-04 23:08:06 +02:00
|
|
|
} else if (cfnode->flow_op == SL::FLOW_OP_WHILE) {
|
2018-01-06 13:56:00 +01:00
|
|
|
code += _mktab(p_level) + "while (" + _dump_node_code(cfnode->expressions[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning) + ")\n";
|
|
|
|
code += _dump_node_code(cfnode->blocks[0], p_level + 1, r_gen_code, p_actions, p_default_actions, p_assigning);
|
2017-09-05 20:22:33 +02:00
|
|
|
} else if (cfnode->flow_op == SL::FLOW_OP_FOR) {
|
2018-01-06 13:56:00 +01:00
|
|
|
String left = _dump_node_code(cfnode->blocks[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
|
|
|
String middle = _dump_node_code(cfnode->expressions[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
|
|
|
String right = _dump_node_code(cfnode->expressions[1], p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
2017-09-13 09:13:23 +02:00
|
|
|
code += _mktab(p_level) + "for (" + left + ";" + middle + ";" + right + ")\n";
|
2018-01-06 13:56:00 +01:00
|
|
|
code += _dump_node_code(cfnode->blocks[1], p_level + 1, r_gen_code, p_actions, p_default_actions, p_assigning);
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (cfnode->flow_op == SL::FLOW_OP_RETURN) {
|
2017-04-07 04:36:37 +02:00
|
|
|
if (cfnode->expressions.size()) {
|
2018-01-06 13:56:00 +01:00
|
|
|
code = "return " + _dump_node_code(cfnode->expressions[0], p_level, r_gen_code, p_actions, p_default_actions, p_assigning) + ";";
|
2016-10-10 23:31:01 +02:00
|
|
|
} else {
|
2017-04-07 04:36:37 +02:00
|
|
|
code = "return;";
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
2017-08-29 15:14:07 +02:00
|
|
|
} else if (cfnode->flow_op == SL::FLOW_OP_DISCARD) {
|
2018-08-02 21:04:33 +02:00
|
|
|
if (p_actions.usage_flag_pointers.has("DISCARD") && !used_flag_pointers.has("DISCARD")) {
|
|
|
|
*p_actions.usage_flag_pointers["DISCARD"] = true;
|
|
|
|
used_flag_pointers.insert("DISCARD");
|
|
|
|
}
|
|
|
|
|
2017-08-29 15:14:07 +02:00
|
|
|
code = "discard;";
|
2017-09-05 20:22:33 +02:00
|
|
|
} else if (cfnode->flow_op == SL::FLOW_OP_CONTINUE) {
|
|
|
|
code = "continue;";
|
|
|
|
} else if (cfnode->flow_op == SL::FLOW_OP_BREAK) {
|
|
|
|
code = "break;";
|
2016-10-10 23:31:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case SL::Node::TYPE_MEMBER: {
|
2017-03-05 16:44:50 +01:00
|
|
|
SL::MemberNode *mnode = (SL::MemberNode *)p_node;
|
2018-01-06 13:56:00 +01:00
|
|
|
code = _dump_node_code(mnode->owner, p_level, r_gen_code, p_actions, p_default_actions, p_assigning) + "." + mnode->name;
|
2021-04-22 02:55:27 +02:00
|
|
|
if (mnode->index_expression != nullptr) {
|
2021-04-22 02:54:46 +02:00
|
|
|
code += "[";
|
|
|
|
code += _dump_node_code(mnode->index_expression, p_level, r_gen_code, p_actions, p_default_actions, p_assigning);
|
|
|
|
code += "]";
|
2021-04-22 02:55:05 +02:00
|
|
|
} else if (mnode->assign_expression != nullptr) {
|
|
|
|
code += "=";
|
|
|
|
code += _dump_node_code(mnode->assign_expression, p_level, r_gen_code, p_actions, p_default_actions, true, false);
|
2021-04-22 02:54:46 +02:00
|
|
|
}
|
2016-10-10 23:31:01 +02:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Error ShaderCompilerGLES3::compile(VS::ShaderMode p_mode, const String &p_code, IdentifierActions *p_actions, const String &p_path, GeneratedCode &r_gen_code) {
|
2017-04-07 04:36:37 +02:00
|
|
|
Error err = parser.compile(p_code, ShaderTypes::get_singleton()->get_functions(p_mode), ShaderTypes::get_singleton()->get_modes(p_mode), ShaderTypes::get_singleton()->get_types());
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (err != OK) {
|
2016-10-27 16:50:26 +02:00
|
|
|
Vector<String> shader = p_code.split("\n");
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < shader.size(); i++) {
|
2021-07-17 02:37:01 +02:00
|
|
|
if (i + 1 == parser.get_error_line()) {
|
|
|
|
// Mark the error line to be visible without having to look at
|
|
|
|
// the trace at the end.
|
|
|
|
print_line(vformat("E%4d-> %s", i + 1, shader[i]));
|
|
|
|
} else {
|
|
|
|
print_line(vformat("%5d | %s", i + 1, shader[i]));
|
|
|
|
}
|
2016-10-27 16:50:26 +02:00
|
|
|
}
|
|
|
|
|
2021-05-04 16:00:45 +02:00
|
|
|
_err_print_error(nullptr, p_path.utf8().get_data(), parser.get_error_line(), parser.get_error_text().utf8().get_data(), ERR_HANDLER_SHADER);
|
2016-10-10 23:31:01 +02:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
r_gen_code.defines.clear();
|
2017-03-05 16:44:50 +01:00
|
|
|
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;
|
2016-12-23 12:47:16 +01:00
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
used_name_defines.clear();
|
|
|
|
used_rmode_defines.clear();
|
2017-02-06 04:38:39 +01:00
|
|
|
used_flag_pointers.clear();
|
2021-04-22 02:55:27 +02:00
|
|
|
fragment_varyings.clear();
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2021-04-22 02:55:27 +02:00
|
|
|
shader = parser.get_shader();
|
|
|
|
function = nullptr;
|
|
|
|
_dump_node_code(shader, 1, r_gen_code, *p_actions, actions[p_mode], false);
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2017-07-08 13:06:13 +02:00
|
|
|
if (r_gen_code.uniform_total_size) { //uniforms used?
|
|
|
|
int md = sizeof(float) * 4;
|
|
|
|
if (r_gen_code.uniform_total_size % md) {
|
|
|
|
r_gen_code.uniform_total_size += md - (r_gen_code.uniform_total_size % md);
|
|
|
|
}
|
|
|
|
r_gen_code.uniform_total_size += md; //pad just in case
|
|
|
|
}
|
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ShaderCompilerGLES3::ShaderCompilerGLES3() {
|
|
|
|
/** CANVAS ITEM SHADER **/
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["VERTEX"] = "outvec.xy";
|
2018-10-18 23:28:51 +02:00
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["UV"] = "uv";
|
2019-12-11 08:08:20 +01:00
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["POINT_SIZE"] = "point_size";
|
2017-03-05 16:44:50 +01:00
|
|
|
|
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["WORLD_MATRIX"] = "modelview_matrix";
|
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["PROJECTION_MATRIX"] = "projection_matrix";
|
2018-01-10 12:37:28 +01:00
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["EXTRA_MATRIX"] = "extra_matrix";
|
2017-03-05 16:44:50 +01:00
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["TIME"] = "time";
|
2017-06-12 16:32:59 +02:00
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["AT_LIGHT_PASS"] = "at_light_pass";
|
2017-09-29 23:56:05 +02:00
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["INSTANCE_CUSTOM"] = "instance_custom";
|
2017-03-05 16:44:50 +01:00
|
|
|
|
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["COLOR"] = "color";
|
2021-03-11 13:57:52 +01:00
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["MODULATE"] = "final_modulate_alias";
|
2017-03-05 16:44:50 +01:00
|
|
|
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["TEXTURE"] = "color_texture";
|
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["TEXTURE_PIXEL_SIZE"] = "color_texpixel_size";
|
2017-09-29 23:56:05 +02:00
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["NORMAL_TEXTURE"] = "normal_texture";
|
2017-03-05 16:44:50 +01:00
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["SCREEN_UV"] = "screen_uv";
|
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["SCREEN_TEXTURE"] = "screen_texture";
|
2017-06-27 03:58:03 +02:00
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["SCREEN_PIXEL_SIZE"] = "screen_pixel_size";
|
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["FRAGCOORD"] = "gl_FragCoord";
|
2017-03-05 16:44:50 +01:00
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["POINT_COORD"] = "gl_PointCoord";
|
2021-11-08 06:49:55 +01:00
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["INSTANCE_ID"] = "gl_InstanceID";
|
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["VERTEX_ID"] = "gl_VertexID";
|
2017-03-05 16:44:50 +01:00
|
|
|
|
|
|
|
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"] = "light";
|
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["SHADOW_COLOR"] = "shadow_color";
|
2019-08-08 15:24:44 +02:00
|
|
|
actions[VS::SHADER_CANVAS_ITEM].renames["SHADOW_VEC"] = "shadow_vec";
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
actions[VS::SHADER_CANVAS_ITEM].usage_defines["COLOR"] = "#define COLOR_USED\n";
|
2020-05-03 02:55:14 +02:00
|
|
|
actions[VS::SHADER_CANVAS_ITEM].usage_defines["MODULATE"] = "#define MODULATE_USED\n";
|
2017-03-05 16:44:50 +01:00
|
|
|
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";
|
2017-06-27 03:58:03 +02:00
|
|
|
actions[VS::SHADER_CANVAS_ITEM].usage_defines["SCREEN_PIXEL_SIZE"] = "@SCREEN_UV";
|
2017-03-05 16:44:50 +01:00
|
|
|
actions[VS::SHADER_CANVAS_ITEM].usage_defines["NORMAL"] = "#define NORMAL_USED\n";
|
|
|
|
actions[VS::SHADER_CANVAS_ITEM].usage_defines["NORMALMAP"] = "#define NORMALMAP_USED\n";
|
2017-11-14 16:08:03 +01:00
|
|
|
actions[VS::SHADER_CANVAS_ITEM].usage_defines["LIGHT"] = "#define USE_LIGHT_SHADER_CODE\n";
|
2019-08-08 15:24:44 +02:00
|
|
|
actions[VS::SHADER_CANVAS_ITEM].usage_defines["SHADOW_VEC"] = "#define SHADOW_VEC_USED\n";
|
2017-07-08 13:06:13 +02:00
|
|
|
actions[VS::SHADER_CANVAS_ITEM].render_mode_defines["skip_vertex_transform"] = "#define SKIP_TRANSFORM_USED\n";
|
2016-10-10 23:31:01 +02:00
|
|
|
|
2016-10-27 16:50:26 +02:00
|
|
|
/** SPATIAL SHADER **/
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["WORLD_MATRIX"] = "world_transform";
|
|
|
|
actions[VS::SHADER_SPATIAL].renames["INV_CAMERA_MATRIX"] = "camera_inverse_matrix";
|
2017-04-07 04:36:37 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["CAMERA_MATRIX"] = "camera_matrix";
|
2017-03-05 16:44:50 +01:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["PROJECTION_MATRIX"] = "projection_matrix";
|
2017-09-21 20:20:00 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["INV_PROJECTION_MATRIX"] = "inv_projection_matrix";
|
2017-04-07 04:36:37 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["MODELVIEW_MATRIX"] = "modelview";
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2021-04-19 05:32:23 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["VIEW_INDEX"] = "view_index";
|
|
|
|
actions[VS::SHADER_SPATIAL].renames["VIEW_MONO_LEFT"] = "0";
|
|
|
|
actions[VS::SHADER_SPATIAL].renames["VIEW_RIGHT"] = "1";
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
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";
|
2018-11-28 12:07:33 +01:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["POSITION"] = "position";
|
2017-03-05 16:44:50 +01:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["UV"] = "uv_interp";
|
|
|
|
actions[VS::SHADER_SPATIAL].renames["UV2"] = "uv2_interp";
|
|
|
|
actions[VS::SHADER_SPATIAL].renames["COLOR"] = "color_interp";
|
2019-12-11 08:08:20 +01:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["POINT_SIZE"] = "point_size";
|
2018-07-22 12:42:29 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["INSTANCE_ID"] = "gl_InstanceID";
|
2021-11-08 06:49:55 +01:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["VERTEX_ID"] = "gl_VertexID";
|
2016-10-27 16:50:26 +02:00
|
|
|
|
|
|
|
//builtins
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["TIME"] = "time";
|
2017-10-21 20:05:57 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["VIEWPORT_SIZE"] = "viewport_size";
|
2016-10-27 16:50:26 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["FRAGCOORD"] = "gl_FragCoord";
|
2017-10-27 15:31:24 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["FRONT_FACING"] = "gl_FrontFacing";
|
2017-03-05 16:44:50 +01:00
|
|
|
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";
|
2017-06-01 01:16:38 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["METALLIC"] = "metallic";
|
2017-03-05 16:44:50 +01:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["SPECULAR"] = "specular";
|
|
|
|
actions[VS::SHADER_SPATIAL].renames["ROUGHNESS"] = "roughness";
|
|
|
|
actions[VS::SHADER_SPATIAL].renames["RIM"] = "rim";
|
|
|
|
actions[VS::SHADER_SPATIAL].renames["RIM_TINT"] = "rim_tint";
|
|
|
|
actions[VS::SHADER_SPATIAL].renames["CLEARCOAT"] = "clearcoat";
|
|
|
|
actions[VS::SHADER_SPATIAL].renames["CLEARCOAT_GLOSS"] = "clearcoat_gloss";
|
|
|
|
actions[VS::SHADER_SPATIAL].renames["ANISOTROPY"] = "anisotropy";
|
|
|
|
actions[VS::SHADER_SPATIAL].renames["ANISOTROPY_FLOW"] = "anisotropy_flow";
|
|
|
|
actions[VS::SHADER_SPATIAL].renames["SSS_STRENGTH"] = "sss_strength";
|
2017-09-03 15:29:56 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["TRANSMISSION"] = "transmission";
|
2017-03-05 16:44:50 +01:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["AO"] = "ao";
|
2017-09-24 04:10:34 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["AO_LIGHT_AFFECT"] = "ao_light_affect";
|
2017-03-05 16:44:50 +01:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["EMISSION"] = "emission";
|
|
|
|
actions[VS::SHADER_SPATIAL].renames["POINT_COORD"] = "gl_PointCoord";
|
2017-04-07 04:36:37 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["INSTANCE_CUSTOM"] = "instance_custom";
|
2017-06-06 03:33:01 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["SCREEN_UV"] = "screen_uv";
|
|
|
|
actions[VS::SHADER_SPATIAL].renames["SCREEN_TEXTURE"] = "screen_texture";
|
2017-06-07 23:18:55 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["DEPTH_TEXTURE"] = "depth_buffer";
|
2018-10-06 14:59:42 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["DEPTH"] = "gl_FragDepth";
|
2017-08-08 22:23:44 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["ALPHA_SCISSOR"] = "alpha_scissor";
|
2018-09-23 17:12:30 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["OUTPUT_IS_SRGB"] = "SHADER_IS_SRGB";
|
2016-12-03 02:23:16 +01:00
|
|
|
|
2017-09-28 02:45:13 +02:00
|
|
|
//for light
|
|
|
|
actions[VS::SHADER_SPATIAL].renames["VIEW"] = "view";
|
|
|
|
actions[VS::SHADER_SPATIAL].renames["LIGHT_COLOR"] = "light_color";
|
2017-12-14 14:38:52 +01:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["LIGHT"] = "light";
|
2017-09-28 02:45:13 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].renames["ATTENUATION"] = "attenuation";
|
|
|
|
actions[VS::SHADER_SPATIAL].renames["DIFFUSE_LIGHT"] = "diffuse_light";
|
|
|
|
actions[VS::SHADER_SPATIAL].renames["SPECULAR_LIGHT"] = "specular_light";
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
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["RIM"] = "#define LIGHT_USE_RIM\n";
|
|
|
|
actions[VS::SHADER_SPATIAL].usage_defines["RIM_TINT"] = "@RIM";
|
|
|
|
actions[VS::SHADER_SPATIAL].usage_defines["CLEARCOAT"] = "#define LIGHT_USE_CLEARCOAT\n";
|
|
|
|
actions[VS::SHADER_SPATIAL].usage_defines["CLEARCOAT_GLOSS"] = "@CLEARCOAT";
|
|
|
|
actions[VS::SHADER_SPATIAL].usage_defines["ANISOTROPY"] = "#define LIGHT_USE_ANISOTROPY\n";
|
|
|
|
actions[VS::SHADER_SPATIAL].usage_defines["ANISOTROPY_FLOW"] = "@ANISOTROPY";
|
|
|
|
actions[VS::SHADER_SPATIAL].usage_defines["AO"] = "#define ENABLE_AO\n";
|
2017-09-24 04:10:34 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].usage_defines["AO_LIGHT_AFFECT"] = "#define ENABLE_AO\n";
|
2017-03-05 16:44:50 +01:00
|
|
|
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";
|
2017-04-07 04:36:37 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].usage_defines["INSTANCE_CUSTOM"] = "#define ENABLE_INSTANCE_CUSTOM\n";
|
2017-08-08 22:23:44 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].usage_defines["ALPHA_SCISSOR"] = "#define ALPHA_SCISSOR_USED\n";
|
2018-11-28 12:07:33 +01:00
|
|
|
actions[VS::SHADER_SPATIAL].usage_defines["POSITION"] = "#define OVERRIDE_POSITION\n";
|
2016-12-03 02:23:16 +01:00
|
|
|
|
2017-06-04 02:13:03 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].usage_defines["SSS_STRENGTH"] = "#define ENABLE_SSS\n";
|
2017-09-03 15:29:56 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].usage_defines["TRANSMISSION"] = "#define TRANSMISSION_USED\n";
|
2017-06-06 03:33:01 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].usage_defines["SCREEN_TEXTURE"] = "#define SCREEN_TEXTURE_USED\n";
|
|
|
|
actions[VS::SHADER_SPATIAL].usage_defines["SCREEN_UV"] = "#define SCREEN_UV_USED\n";
|
2016-12-03 02:23:16 +01:00
|
|
|
|
2017-11-14 16:08:03 +01:00
|
|
|
actions[VS::SHADER_SPATIAL].usage_defines["DIFFUSE_LIGHT"] = "#define USE_LIGHT_SHADER_CODE\n";
|
|
|
|
actions[VS::SHADER_SPATIAL].usage_defines["SPECULAR_LIGHT"] = "#define USE_LIGHT_SHADER_CODE\n";
|
|
|
|
|
2017-07-08 13:06:13 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].render_mode_defines["skip_vertex_transform"] = "#define SKIP_TRANSFORM_USED\n";
|
|
|
|
actions[VS::SHADER_SPATIAL].render_mode_defines["world_vertex_coords"] = "#define VERTEX_WORLD_COORDS_USED\n";
|
2018-06-21 00:12:12 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].render_mode_defines["ensure_correct_normals"] = "#define ENSURE_CORRECT_NORMALS\n";
|
2017-12-26 15:09:52 +01:00
|
|
|
actions[VS::SHADER_SPATIAL].render_mode_defines["cull_front"] = "#define DO_SIDE_CHECK\n";
|
|
|
|
actions[VS::SHADER_SPATIAL].render_mode_defines["cull_disabled"] = "#define DO_SIDE_CHECK\n";
|
2016-10-27 16:50:26 +02:00
|
|
|
|
2018-09-23 17:12:30 +02:00
|
|
|
bool force_lambert = GLOBAL_GET("rendering/quality/shading/force_lambert_over_burley");
|
|
|
|
|
|
|
|
if (!force_lambert) {
|
|
|
|
actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_burley"] = "#define DIFFUSE_BURLEY\n";
|
|
|
|
}
|
|
|
|
|
2017-06-01 23:55:24 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_oren_nayar"] = "#define DIFFUSE_OREN_NAYAR\n";
|
2017-09-03 15:29:56 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_lambert_wrap"] = "#define DIFFUSE_LAMBERT_WRAP\n";
|
2017-07-08 17:34:05 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].render_mode_defines["diffuse_toon"] = "#define DIFFUSE_TOON\n";
|
|
|
|
|
2018-09-23 17:12:30 +02:00
|
|
|
bool force_blinn = GLOBAL_GET("rendering/quality/shading/force_blinn_over_ggx");
|
|
|
|
|
|
|
|
if (!force_blinn) {
|
|
|
|
actions[VS::SHADER_SPATIAL].render_mode_defines["specular_schlick_ggx"] = "#define SPECULAR_SCHLICK_GGX\n";
|
|
|
|
} else {
|
|
|
|
actions[VS::SHADER_SPATIAL].render_mode_defines["specular_schlick_ggx"] = "#define SPECULAR_BLINN\n";
|
|
|
|
}
|
|
|
|
|
2017-07-08 17:34:05 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].render_mode_defines["specular_blinn"] = "#define SPECULAR_BLINN\n";
|
|
|
|
actions[VS::SHADER_SPATIAL].render_mode_defines["specular_phong"] = "#define SPECULAR_PHONG\n";
|
|
|
|
actions[VS::SHADER_SPATIAL].render_mode_defines["specular_toon"] = "#define SPECULAR_TOON\n";
|
2017-07-08 19:01:56 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].render_mode_defines["specular_disabled"] = "#define SPECULAR_DISABLED\n";
|
2018-03-29 18:46:42 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].render_mode_defines["shadows_disabled"] = "#define SHADOWS_DISABLED\n";
|
2018-07-17 21:30:43 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].render_mode_defines["ambient_light_disabled"] = "#define AMBIENT_LIGHT_DISABLED\n";
|
2019-05-20 16:37:13 +02:00
|
|
|
actions[VS::SHADER_SPATIAL].render_mode_defines["shadow_to_opacity"] = "#define USE_SHADOW_TO_OPACITY\n";
|
2017-06-01 23:55:24 +02:00
|
|
|
|
2017-01-02 02:16:52 +01:00
|
|
|
/* PARTICLES SHADER */
|
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
actions[VS::SHADER_PARTICLES].renames["COLOR"] = "out_color";
|
2017-03-05 16:44:50 +01:00
|
|
|
actions[VS::SHADER_PARTICLES].renames["VELOCITY"] = "out_velocity_active.xyz";
|
|
|
|
actions[VS::SHADER_PARTICLES].renames["MASS"] = "mass";
|
2018-11-22 14:04:52 +01:00
|
|
|
actions[VS::SHADER_PARTICLES].renames["ACTIVE"] = "shader_active";
|
2017-03-05 16:44:50 +01:00
|
|
|
actions[VS::SHADER_PARTICLES].renames["RESTART"] = "restart";
|
|
|
|
actions[VS::SHADER_PARTICLES].renames["CUSTOM"] = "out_custom";
|
|
|
|
actions[VS::SHADER_PARTICLES].renames["TRANSFORM"] = "xform";
|
|
|
|
actions[VS::SHADER_PARTICLES].renames["TIME"] = "time";
|
|
|
|
actions[VS::SHADER_PARTICLES].renames["LIFETIME"] = "lifetime";
|
2017-04-07 04:36:37 +02:00
|
|
|
actions[VS::SHADER_PARTICLES].renames["DELTA"] = "local_delta";
|
|
|
|
actions[VS::SHADER_PARTICLES].renames["NUMBER"] = "particle_number";
|
2017-03-05 16:44:50 +01:00
|
|
|
actions[VS::SHADER_PARTICLES].renames["INDEX"] = "index";
|
2017-04-07 04:36:37 +02:00
|
|
|
actions[VS::SHADER_PARTICLES].renames["GRAVITY"] = "current_gravity";
|
|
|
|
actions[VS::SHADER_PARTICLES].renames["EMISSION_TRANSFORM"] = "emission_transform";
|
2017-06-23 19:31:21 +02:00
|
|
|
actions[VS::SHADER_PARTICLES].renames["RANDOM_SEED"] = "random_seed";
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2019-01-28 19:27:32 +01:00
|
|
|
actions[VS::SHADER_PARTICLES].render_mode_defines["disable_force"] = "#define DISABLE_FORCE\n";
|
|
|
|
actions[VS::SHADER_PARTICLES].render_mode_defines["disable_velocity"] = "#define DISABLE_VELOCITY\n";
|
|
|
|
actions[VS::SHADER_PARTICLES].render_mode_defines["keep_data"] = "#define ENABLE_KEEP_DATA\n";
|
2017-03-05 16:44:50 +01:00
|
|
|
|
|
|
|
vertex_name = "vertex";
|
|
|
|
fragment_name = "fragment";
|
2018-02-07 11:56:52 +01:00
|
|
|
light_name = "light";
|
2017-03-05 16:44:50 +01:00
|
|
|
time_name = "TIME";
|
2016-10-27 16:50:26 +02:00
|
|
|
|
2016-10-10 23:31:01 +02:00
|
|
|
List<String> func_list;
|
|
|
|
|
|
|
|
ShaderLanguage::get_builtin_funcs(&func_list);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<String>::Element *E = func_list.front(); E; E = E->next()) {
|
2016-10-10 23:31:01 +02:00
|
|
|
internal_functions.insert(E->get());
|
|
|
|
}
|
|
|
|
}
|