summaryrefslogtreecommitdiff
path: root/servers/visual/shader_language.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'servers/visual/shader_language.cpp')
-rw-r--r--servers/visual/shader_language.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp
index 246a80280e..e10a57c571 100644
--- a/servers/visual/shader_language.cpp
+++ b/servers/visual/shader_language.cpp
@@ -254,6 +254,9 @@ const ShaderLanguage::KeyWord ShaderLanguage::keyword_list[] = {
{ TK_TYPE_ISAMPLER2D, "isampler2D" },
{ TK_TYPE_USAMPLER2D, "usampler2D" },
{ TK_TYPE_SAMPLERCUBE, "samplerCube" },
+ { TK_INTERPOLATION_FLAT, "flat" },
+ { TK_INTERPOLATION_NO_PERSPECTIVE, "noperspective" },
+ { TK_INTERPOLATION_SMOOTH, "smooth" },
{ TK_PRECISION_LOW, "lowp" },
{ TK_PRECISION_MID, "mediump" },
{ TK_PRECISION_HIGH, "highp" },
@@ -658,6 +661,24 @@ ShaderLanguage::DataType ShaderLanguage::get_token_datatype(TokenType p_type) {
return DataType(p_type - TK_TYPE_VOID);
}
+bool ShaderLanguage::is_token_interpolation(TokenType p_type) {
+
+ return (
+ p_type == TK_INTERPOLATION_FLAT ||
+ p_type == TK_INTERPOLATION_NO_PERSPECTIVE ||
+ p_type == TK_INTERPOLATION_SMOOTH);
+}
+
+ShaderLanguage::DataInterpolation ShaderLanguage::get_token_interpolation(TokenType p_type) {
+
+ if (p_type == TK_INTERPOLATION_FLAT)
+ return INTERPOLATION_FLAT;
+ else if (p_type == TK_INTERPOLATION_NO_PERSPECTIVE)
+ return INTERPOLATION_NO_PERSPECTIVE;
+ else
+ return INTERPOLATION_SMOOTH;
+}
+
bool ShaderLanguage::is_token_precision(TokenType p_type) {
return (
@@ -1352,15 +1373,54 @@ const ShaderLanguage::BuiltinFuncDef ShaderLanguage::builtin_func_defs[] = {
//builtins - trigonometry
{ "sin", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
+ { "sin", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
+ { "sin", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
+ { "sin", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
+
{ "cos", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
+ { "cos", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
+ { "cos", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
+ { "cos", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
+
{ "tan", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
+ { "tan", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
+ { "tan", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
+ { "tan", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
+
{ "asin", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
+ { "asin", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
+ { "asin", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
+ { "asin", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
+
{ "acos", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
+ { "acos", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
+ { "acos", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
+ { "acos", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
+
{ "atan", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
+ { "atan", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
+ { "atan", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
+ { "atan", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
{ "atan", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
+ { "atan", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
+ { "atan", TYPE_VEC3, { TYPE_VEC3, TYPE_VEC3, TYPE_VOID } },
+ { "atan", TYPE_VEC4, { TYPE_VEC4, TYPE_VEC4, TYPE_VOID } },
+
{ "sinh", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
+ { "sinh", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
+ { "sinh", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
+ { "sinh", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
+
{ "cosh", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
+ { "cosh", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
+ { "cosh", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
+ { "cosh", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
+
{ "tanh", TYPE_FLOAT, { TYPE_FLOAT, TYPE_VOID } },
+ { "tanh", TYPE_VEC2, { TYPE_VEC2, TYPE_VOID } },
+ { "tanh", TYPE_VEC3, { TYPE_VEC3, TYPE_VOID } },
+ { "tanh", TYPE_VEC4, { TYPE_VEC4, TYPE_VOID } },
+
//builtins - exponential
{ "pow", TYPE_FLOAT, { TYPE_FLOAT, TYPE_FLOAT, TYPE_VOID } },
{ "pow", TYPE_VEC2, { TYPE_VEC2, TYPE_VEC2, TYPE_VOID } },
@@ -3537,10 +3597,16 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
bool uniform = tk.type == TK_UNIFORM;
DataPrecision precision = PRECISION_DEFAULT;
+ DataInterpolation interpolation = INTERPOLATION_SMOOTH;
DataType type;
StringName name;
tk = _get_token();
+ if (is_token_interpolation(tk.type)) {
+ interpolation = get_token_interpolation(tk.type);
+ tk = _get_token();
+ }
+
if (is_token_precision(tk.type)) {
precision = get_token_precision(tk.type);
tk = _get_token();
@@ -3738,6 +3804,7 @@ Error ShaderLanguage::_parse_shader(const Map<StringName, FunctionInfo> &p_funct
ShaderNode::Varying varying;
varying.type = type;
varying.precission = precision;
+ varying.interpolation = interpolation;
shader->varyings[name] = varying;
tk = _get_token();