summaryrefslogtreecommitdiff
path: root/servers/visual/shader_language.cpp
diff options
context:
space:
mode:
authorAnton Yabchinskiy <arn@bestmx.ru>2015-03-10 11:44:40 +0300
committerAnton Yabchinskiy <arn@bestmx.ru>2015-03-10 11:44:40 +0300
commit43713810deaadfec6a1656767cf5520073e58a06 (patch)
tree8b1c7e82562494e1889b1550b58b3d953f076696 /servers/visual/shader_language.cpp
parent19a99afa81354ed69e1c07b6050aeb438e4ee2cb (diff)
parent91744e9ed3124ca48e0837ee72bfe7182fd31701 (diff)
Merge branch 'master' of https://github.com/okamstudio/godot
Diffstat (limited to 'servers/visual/shader_language.cpp')
-rw-r--r--servers/visual/shader_language.cpp55
1 files changed, 43 insertions, 12 deletions
diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp
index dfa0172e82..af65a7a639 100644
--- a/servers/visual/shader_language.cpp
+++ b/servers/visual/shader_language.cpp
@@ -56,6 +56,7 @@ const char * ShaderLanguage::token_names[TK_MAX]={
"TYPE_VEC2",
"TYPE_VEC3",
"TYPE_VEC4",
+ "TYPE_MAT2",
"TYPE_MAT3",
"TYPE_MAT4",
"TYPE_TEXTURE",
@@ -403,9 +404,9 @@ ShaderLanguage::Token ShaderLanguage::read_token(const CharType* p_text,int p_le
{TK_TYPE_TEXTURE,"texture"},
{TK_TYPE_CUBEMAP,"cubemap"},
{TK_TYPE_COLOR,"color"},
- /*
+
{TK_TYPE_MAT2,"mat2"},
- {TK_TYPE_MAT3,"mat3"},
+ /*{TK_TYPE_MAT3,"mat3"},
{TK_TYPE_MAT4,"mat3"},*/
{TK_TYPE_MAT3,"mat3"},
{TK_TYPE_MAT4,"mat4"},
@@ -511,6 +512,7 @@ bool ShaderLanguage::is_token_datatype(TokenType p_type) {
(p_type==TK_TYPE_VEC3) ||
(p_type==TK_TYPE_VEC4) ||
(p_type==TK_TYPE_COLOR) ||
+ (p_type==TK_TYPE_MAT2) ||
(p_type==TK_TYPE_MAT3) ||
(p_type==TK_TYPE_MAT4) ||
(p_type==TK_TYPE_CUBEMAP) ||
@@ -529,6 +531,7 @@ ShaderLanguage::DataType ShaderLanguage::get_token_datatype(TokenType p_type) {
case TK_TYPE_VEC3: return TYPE_VEC3;
case TK_TYPE_VEC4: return TYPE_VEC4;
case TK_TYPE_COLOR: return TYPE_VEC4;
+ case TK_TYPE_MAT2: return TYPE_MAT2;
case TK_TYPE_MAT3: return TYPE_MAT3;
case TK_TYPE_MAT4: return TYPE_MAT4;
case TK_TYPE_TEXTURE: return TYPE_TEXTURE;
@@ -550,6 +553,7 @@ String ShaderLanguage::get_datatype_name(DataType p_type) {
case TYPE_VEC2: return "vec2";
case TYPE_VEC3: return "vec3";
case TYPE_VEC4: return "vec4";
+ case TYPE_MAT2: return "mat2";
case TYPE_MAT3: return "mat3";
case TYPE_MAT4: return "mat4";
case TYPE_TEXTURE: return "texture";
@@ -570,6 +574,7 @@ bool ShaderLanguage::is_token_nonvoid_datatype(TokenType p_type) {
(p_type==TK_TYPE_VEC3) ||
(p_type==TK_TYPE_VEC4) ||
(p_type==TK_TYPE_COLOR) ||
+ (p_type==TK_TYPE_MAT2) ||
(p_type==TK_TYPE_MAT3) ||
(p_type==TK_TYPE_MAT4) ||
(p_type==TK_TYPE_TEXTURE) ||
@@ -782,6 +787,7 @@ const ShaderLanguage::IntrinsicFuncDef ShaderLanguage::intrinsic_func_defs[]={
{"vec4",TYPE_VEC4,{TYPE_FLOAT,TYPE_VEC3,TYPE_VOID}},
{"vec4",TYPE_VEC4,{TYPE_VEC3,TYPE_FLOAT,TYPE_VOID}},
{"vec4",TYPE_VEC4,{TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
+ {"mat2",TYPE_MAT2,{TYPE_VEC2,TYPE_VEC2,TYPE_VOID}},
{"mat3",TYPE_MAT3,{TYPE_VEC3,TYPE_VEC3,TYPE_VEC3,TYPE_VOID}},
{"mat4",TYPE_MAT4,{TYPE_VEC4,TYPE_VEC4,TYPE_VEC4,TYPE_VEC4,TYPE_VOID}},
//intrinsics - trigonometry
@@ -918,6 +924,7 @@ const ShaderLanguage::OperatorDef ShaderLanguage::operator_defs[]={
{OP_ASSIGN,TYPE_VOID,{TYPE_VEC2,TYPE_VEC2}},
{OP_ASSIGN,TYPE_VOID,{TYPE_VEC3,TYPE_VEC3}},
{OP_ASSIGN,TYPE_VOID,{TYPE_VEC4,TYPE_VEC4}},
+ {OP_ASSIGN,TYPE_VOID,{TYPE_MAT2,TYPE_MAT2}},
{OP_ASSIGN,TYPE_VOID,{TYPE_MAT3,TYPE_MAT3}},
{OP_ASSIGN,TYPE_VOID,{TYPE_MAT4,TYPE_MAT4}},
{OP_ADD,TYPE_FLOAT,{TYPE_FLOAT,TYPE_FLOAT}},
@@ -933,6 +940,8 @@ const ShaderLanguage::OperatorDef ShaderLanguage::operator_defs[]={
{OP_MUL,TYPE_VEC2,{TYPE_VEC2,TYPE_FLOAT}},
{OP_MUL,TYPE_VEC2,{TYPE_FLOAT,TYPE_VEC2}},
{OP_MUL,TYPE_VEC2,{TYPE_VEC2,TYPE_MAT3}},
+ {OP_MUL,TYPE_VEC2,{TYPE_MAT2,TYPE_VEC2}},
+ {OP_MUL,TYPE_VEC2,{TYPE_VEC2,TYPE_MAT2}},
{OP_MUL,TYPE_VEC2,{TYPE_MAT3,TYPE_VEC2}},
{OP_MUL,TYPE_VEC2,{TYPE_VEC2,TYPE_MAT4}},
{OP_MUL,TYPE_VEC2,{TYPE_MAT4,TYPE_VEC2}},
@@ -947,6 +956,7 @@ const ShaderLanguage::OperatorDef ShaderLanguage::operator_defs[]={
{OP_MUL,TYPE_VEC4,{TYPE_FLOAT,TYPE_VEC4}},
{OP_MUL,TYPE_VEC4,{TYPE_MAT4,TYPE_VEC4}},
{OP_MUL,TYPE_VEC4,{TYPE_VEC4,TYPE_MAT4}},
+ {OP_MUL,TYPE_MAT2,{TYPE_MAT2,TYPE_MAT2}},
{OP_MUL,TYPE_MAT3,{TYPE_MAT3,TYPE_MAT3}},
{OP_MUL,TYPE_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YPE_MAT4}},
{OP_ASSIGN_DIV,TYPE_VOID,{TYPE_FLOAT,TYPE_FLOAT}},
@@ -1149,11 +1159,19 @@ const ShaderLanguage::BuiltinsDef ShaderLanguage::ci_fragment_builtins_defs[]={
const ShaderLanguage::BuiltinsDef ShaderLanguage::ci_light_builtins_defs[]={
- { "COLOR", TYPE_VEC4},
+ { "POSITION", TYPE_VEC4},
{ "NORMAL", TYPE_VEC3},
- { "LIGHT_DIR", TYPE_VEC2},
- { "LIGHT_DISTANCE", TYPE_FLOAT},
- { "LIGHT", TYPE_VEC3},
+ { "UV", TYPE_VEC2},
+ { "COLOR", TYPE_VEC4},
+ { "TEXTURE", TYPE_TEXTURE},
+ { "TEXTURE_PIXEL_SIZE", TYPE_VEC2},
+ { "VAR1", TYPE_VEC4},
+ { "VAR2", TYPE_VEC4},
+ { "SCREEN_UV", TYPE_VEC2},
+ { "LIGHT_VEC", TYPE_VEC2},
+ { "LIGHT_HEIGHT", TYPE_FLOAT},
+ { "LIGHT_COLOR", TYPE_VEC4},
+ { "LIGHT", TYPE_VEC4},
{ "POINT_COORD", TYPE_VEC2},
// { "SCREEN_POS", TYPE_VEC2},
// { "SCREEN_TEXEL_SIZE", TYPE_VEC2},
@@ -1558,6 +1576,7 @@ Error ShaderLanguage::parse_expression(Parser& parser,Node *p_parent,Node **r_ex
case TYPE_VEC2: name="vec2"; break;
case TYPE_VEC3: name="vec3"; break;
case TYPE_VEC4: name="vec4"; break;
+ case TYPE_MAT2: name="mat2"; break;
case TYPE_MAT3: name="mat3"; break;
case TYPE_MAT4: name="mat4"; break;
default: ERR_FAIL_V(ERR_BUG);
@@ -1852,6 +1871,7 @@ Error ShaderLanguage::parse_expression(Parser& parser,Node *p_parent,Node **r_ex
}
} break;
+ case TYPE_MAT2: ok=(ident=="x" || ident=="y"); member_type=TYPE_VEC2; break;
case TYPE_MAT3: ok=(ident=="x" || ident=="y" || ident=="z" ); member_type=TYPE_VEC3; break;
case TYPE_MAT4: ok=(ident=="x" || ident=="y" || ident=="z" || ident=="w"); member_type=TYPE_VEC4; break;
default: {}
@@ -2059,7 +2079,9 @@ Error ShaderLanguage::parse_expression(Parser& parser,Node *p_parent,Node **r_ex
at+=get_datatype_name(compute_node_type(op->arguments[i]));
}
- parser.set_error("Invalid arguments to operator "+String(token_names[op->op])+": "+at);
+ static const char *op_names[OP_MAX]={"=","+","-","*","/","+=","-=","*=","/=","-","!","==","!=","<=",">=","<",">","||","&&","call","()"};
+
+ parser.set_error("Invalid arguments to operator "+String(op_names[op->op])+": "+at);
return ERR_PARSE_ERROR;
}
expression.remove(next_op);
@@ -2236,6 +2258,7 @@ Error ShaderLanguage::parse_variable_declaration(Parser& parser,BlockNode *p_blo
case TYPE_VEC2: con->value=Vector2(); break;
case TYPE_VEC3: con->value=Vector3(); break;
case TYPE_VEC4: con->value=iscolor?Variant(Color()):Variant(Plane()); break;
+ case TYPE_MAT2: con->value=Matrix32(); break;
case TYPE_MAT3: con->value=Matrix3(); break;
case TYPE_MAT4: con->value=Transform(); break;
case TYPE_TEXTURE:
@@ -2618,12 +2641,20 @@ void ShaderLanguage::get_keyword_list(ShaderType p_type, List<String> *p_keyword
int idx=0;
+ p_keywords->push_back("uniform");
+ p_keywords->push_back("texture");
+ p_keywords->push_back("cubemap");
+ p_keywords->push_back("color");
+ p_keywords->push_back("if");
+ p_keywords->push_back("else");
+
while(intrinsic_func_defs[idx].name) {
p_keywords->push_back(intrinsic_func_defs[idx].name);
idx++;
}
+
switch(p_type) {
case SHADER_MATERIAL_VERTEX: {
idx=0;