mirror of
https://github.com/godotengine/godot.git
synced 2024-11-15 16:43:10 +00:00
-the new shader language seems to work
-shader editor plugin can edit shaders -code completion in shader editor plugin
This commit is contained in:
parent
cf5778e51a
commit
850eaf7ed7
@ -39,7 +39,7 @@
|
||||
#include "servers/visual/shader_language.h"
|
||||
//#include "drivers/gles2/shader_compiler_gles2.h"
|
||||
|
||||
#if 0
|
||||
|
||||
typedef ShaderLanguage SL;
|
||||
|
||||
namespace TestShaderLang {
|
||||
@ -57,50 +57,54 @@ static String _mktab(int p_level) {
|
||||
|
||||
static String _typestr(SL::DataType p_type) {
|
||||
|
||||
switch(p_type) {
|
||||
|
||||
case SL::TYPE_VOID: return "void";
|
||||
case SL::TYPE_BOOL: return "bool";
|
||||
case SL::TYPE_FLOAT: return "float";
|
||||
case SL::TYPE_VEC2: return "vec2";
|
||||
case SL::TYPE_VEC3: return "vec3";
|
||||
case SL::TYPE_VEC4: return "vec4";
|
||||
case SL::TYPE_MAT3: return "mat3";
|
||||
case SL::TYPE_MAT4: return "mat4";
|
||||
case SL::TYPE_TEXTURE: return "texture";
|
||||
case SL::TYPE_CUBEMAP: return "cubemap";
|
||||
default: {}
|
||||
}
|
||||
return ShaderLanguage::get_datatype_name(p_type);
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
static String _prestr(SL::DataPrecision p_pres) {
|
||||
|
||||
|
||||
switch(p_pres) {
|
||||
case SL::PRECISION_LOWP: return "lowp ";
|
||||
case SL::PRECISION_MEDIUMP: return "mediump ";
|
||||
case SL::PRECISION_HIGHP: return "highp ";
|
||||
case SL::PRECISION_DEFAULT: return "";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
static String _opstr(SL::Operator p_op) {
|
||||
|
||||
switch(p_op) {
|
||||
case SL::OP_ASSIGN: return "=";
|
||||
case SL::OP_ADD: return "+";
|
||||
case SL::OP_SUB: return "-";
|
||||
case SL::OP_MUL: return "*";
|
||||
case SL::OP_DIV: return "/";
|
||||
case SL::OP_ASSIGN_ADD: return "+=";
|
||||
case SL::OP_ASSIGN_SUB: return "-=";
|
||||
case SL::OP_ASSIGN_MUL: return "*=";
|
||||
case SL::OP_ASSIGN_DIV: return "/=";
|
||||
case SL::OP_NEG: return "-";
|
||||
case SL::OP_NOT: return "!";
|
||||
case SL::OP_CMP_EQ: return "==";
|
||||
case SL::OP_CMP_NEQ: return "!=";
|
||||
case SL::OP_CMP_LEQ: return "<=";
|
||||
case SL::OP_CMP_GEQ: return ">=";
|
||||
case SL::OP_CMP_LESS: return "<";
|
||||
case SL::OP_CMP_GREATER: return ">";
|
||||
case SL::OP_CMP_OR: return "||";
|
||||
case SL::OP_CMP_AND: return "&&";
|
||||
default: return "";
|
||||
}
|
||||
return ShaderLanguage::get_operator_text(p_op);
|
||||
|
||||
return "";
|
||||
|
||||
}
|
||||
|
||||
|
||||
static String get_constant_text(SL::DataType p_type, const Vector<SL::ConstantNode::Value>& p_values) {
|
||||
|
||||
switch(p_type) {
|
||||
case SL::TYPE_BOOL: return p_values[0].boolean?"true":"false";
|
||||
case SL::TYPE_BVEC2: return String()+"bvec2("+(p_values[0].boolean?"true":"false")+(p_values[1].boolean?"true":"false")+")";
|
||||
case SL::TYPE_BVEC3: return String()+"bvec3("+(p_values[0].boolean?"true":"false")+","+(p_values[1].boolean?"true":"false")+","+(p_values[2].boolean?"true":"false")+")";
|
||||
case SL::TYPE_BVEC4: return String()+"bvec4("+(p_values[0].boolean?"true":"false")+","+(p_values[1].boolean?"true":"false")+","+(p_values[2].boolean?"true":"false")+","+(p_values[3].boolean?"true":"false")+")";
|
||||
case SL::TYPE_INT: return rtos(p_values[0].sint);
|
||||
case SL::TYPE_IVEC2: return String()+"ivec2("+rtos(p_values[0].sint)+","+rtos(p_values[1].sint)+")";
|
||||
case SL::TYPE_IVEC3: return String()+"ivec3("+rtos(p_values[0].sint)+","+rtos(p_values[1].sint)+","+rtos(p_values[2].sint)+")";
|
||||
case SL::TYPE_IVEC4: return String()+"ivec4("+rtos(p_values[0].sint)+","+rtos(p_values[1].sint)+","+rtos(p_values[2].sint)+","+rtos(p_values[3].sint)+")";
|
||||
case SL::TYPE_UINT: return rtos(p_values[0].real);
|
||||
case SL::TYPE_UVEC2: return String()+"uvec2("+rtos(p_values[0].real)+","+rtos(p_values[1].real)+")";
|
||||
case SL::TYPE_UVEC3: return String()+"uvec3("+rtos(p_values[0].real)+","+rtos(p_values[1].real)+","+rtos(p_values[2].real)+")";
|
||||
case SL::TYPE_UVEC4: return String()+"uvec4("+rtos(p_values[0].real)+","+rtos(p_values[1].real)+","+rtos(p_values[2].real)+","+rtos(p_values[3].real)+")";
|
||||
case SL::TYPE_FLOAT: return rtos(p_values[0].real);
|
||||
case SL::TYPE_VEC2: return String()+"vec2("+rtos(p_values[0].real)+","+rtos(p_values[1].real)+")";
|
||||
case SL::TYPE_VEC3: return String()+"vec3("+rtos(p_values[0].real)+","+rtos(p_values[1].real)+","+rtos(p_values[2].real)+")";
|
||||
case SL::TYPE_VEC4: return String()+"vec4("+rtos(p_values[0].real)+","+rtos(p_values[1].real)+","+rtos(p_values[2].real)+","+rtos(p_values[3].real)+")";
|
||||
default: ERR_FAIL_V(String());
|
||||
}
|
||||
}
|
||||
|
||||
static String dump_node_code(SL::Node *p_node,int p_level) {
|
||||
@ -109,18 +113,48 @@ static String dump_node_code(SL::Node *p_node,int p_level) {
|
||||
|
||||
switch(p_node->type) {
|
||||
|
||||
case SL::Node::TYPE_PROGRAM: {
|
||||
case SL::Node::TYPE_SHADER: {
|
||||
|
||||
SL::ProgramNode *pnode=(SL::ProgramNode*)p_node;
|
||||
SL::ShaderNode *pnode=(SL::ShaderNode*)p_node;
|
||||
|
||||
for(Map<StringName,SL::Uniform>::Element *E=pnode->uniforms.front();E;E=E->next()) {
|
||||
for(Map<StringName,SL::ShaderNode::Uniform>::Element *E=pnode->uniforms.front();E;E=E->next()) {
|
||||
|
||||
String ucode="uniform ";
|
||||
ucode+=_typestr(E->get().type)+"="+String(E->get().default_value)+"\n";
|
||||
code+=ucode;
|
||||
ucode+=_prestr(E->get().precission);
|
||||
ucode+=_typestr(E->get().type);
|
||||
ucode+=" "+String(E->key());
|
||||
|
||||
if (E->get().default_value.size()) {
|
||||
ucode+=" = "+get_constant_text(E->get().type,E->get().default_value);
|
||||
}
|
||||
|
||||
static const char*hint_name[SL::ShaderNode::Uniform::HINT_MAX]={
|
||||
"",
|
||||
"color",
|
||||
"range",
|
||||
"albedo",
|
||||
"normal",
|
||||
"black",
|
||||
"white"
|
||||
};
|
||||
|
||||
if (E->get().hint)
|
||||
ucode+=" : "+String(hint_name[E->get().hint]);
|
||||
|
||||
code+=ucode+"\n";
|
||||
|
||||
}
|
||||
|
||||
for(Map<StringName,SL::ShaderNode::Varying>::Element *E=pnode->varyings.front();E;E=E->next()) {
|
||||
|
||||
String vcode="varying ";
|
||||
vcode+=_prestr(E->get().precission);
|
||||
vcode+=_typestr(E->get().type);
|
||||
vcode+=" "+String(E->key());
|
||||
|
||||
code+=vcode+"\n";
|
||||
|
||||
}
|
||||
for(int i=0;i<pnode->functions.size();i++) {
|
||||
|
||||
SL::FunctionNode *fnode=pnode->functions[i].function;
|
||||
@ -131,16 +165,15 @@ static String dump_node_code(SL::Node *p_node,int p_level) {
|
||||
|
||||
if (i>0)
|
||||
header+=", ";
|
||||
header+=_typestr(fnode->arguments[i].type)+" "+fnode->arguments[i].name;
|
||||
header+=_prestr(fnode->arguments[i].precision)+_typestr(fnode->arguments[i].type)+" "+fnode->arguments[i].name;
|
||||
}
|
||||
|
||||
header+=") {\n";
|
||||
header+=")\n";
|
||||
code+=header;
|
||||
code+=dump_node_code(fnode->body,p_level+1);
|
||||
code+="}\n";
|
||||
}
|
||||
|
||||
code+=dump_node_code(pnode->body,p_level);
|
||||
//code+=dump_node_code(pnode->body,p_level);
|
||||
} break;
|
||||
case SL::Node::TYPE_FUNCTION: {
|
||||
|
||||
@ -149,15 +182,23 @@ static String dump_node_code(SL::Node *p_node,int p_level) {
|
||||
SL::BlockNode *bnode=(SL::BlockNode*)p_node;
|
||||
|
||||
//variables
|
||||
for(Map<StringName,SL::DataType>::Element *E=bnode->variables.front();E;E=E->next()) {
|
||||
code+=_mktab(p_level-1)+"{\n";
|
||||
for(Map<StringName,SL::BlockNode::Variable>::Element *E=bnode->variables.front();E;E=E->next()) {
|
||||
|
||||
code+=_mktab(p_level)+_typestr(E->value())+" "+E->key()+";\n";
|
||||
code+=_mktab(p_level)+_prestr(E->get().precision)+_typestr(E->get().type)+" "+E->key()+";\n";
|
||||
}
|
||||
|
||||
for(int i=0;i<bnode->statements.size();i++) {
|
||||
|
||||
code+=_mktab(p_level)+dump_node_code(bnode->statements[i],p_level)+";\n";
|
||||
String scode = dump_node_code(bnode->statements[i],p_level);
|
||||
|
||||
if (bnode->statements[i]->type==SL::Node::TYPE_CONTROL_FLOW || bnode->statements[i]->type==SL::Node::TYPE_CONTROL_FLOW) {
|
||||
code+=scode; //use directly
|
||||
} else {
|
||||
code+=_mktab(p_level)+scode+";\n";
|
||||
}
|
||||
}
|
||||
code+=_mktab(p_level-1)+"}\n";
|
||||
|
||||
|
||||
} break;
|
||||
@ -168,18 +209,7 @@ static String dump_node_code(SL::Node *p_node,int p_level) {
|
||||
} break;
|
||||
case SL::Node::TYPE_CONSTANT: {
|
||||
SL::ConstantNode *cnode=(SL::ConstantNode*)p_node;
|
||||
switch(cnode->datatype) {
|
||||
|
||||
|
||||
case SL::TYPE_BOOL: code=cnode->value.operator bool()?"true":"false"; break;
|
||||
case SL::TYPE_FLOAT: code=cnode->value; break;
|
||||
case SL::TYPE_VEC2: { Vector2 v = cnode->value; code="vec2("+rtos(v.x)+", "+rtos(v.y)+")"; } break;
|
||||
case SL::TYPE_VEC3: { Vector3 v = cnode->value; code="vec3("+rtos(v.x)+", "+rtos(v.y)+", "+rtos(v.z)+")"; } break;
|
||||
case SL::TYPE_VEC4: { Plane v = cnode->value; code="vec4("+rtos(v.normal.x)+", "+rtos(v.normal.y)+", "+rtos(v.normal.z)+", "+rtos(v.d)+")"; } break;
|
||||
case SL::TYPE_MAT3: { Matrix3 x = cnode->value; code="mat3( vec3("+rtos(x.get_axis(0).x)+", "+rtos(x.get_axis(0).y)+", "+rtos(x.get_axis(0).z)+"), vec3("+rtos(x.get_axis(1).x)+", "+rtos(x.get_axis(1).y)+", "+rtos(x.get_axis(1).z)+"), vec3("+rtos(x.get_axis(2).x)+", "+rtos(x.get_axis(2).y)+", "+rtos(x.get_axis(2).z)+"))"; } break;
|
||||
case SL::TYPE_MAT4: { Transform x = cnode->value; code="mat4( vec3("+rtos(x.basis.get_axis(0).x)+", "+rtos(x.basis.get_axis(0).y)+", "+rtos(x.basis.get_axis(0).z)+"), vec3("+rtos(x.basis.get_axis(1).x)+", "+rtos(x.basis.get_axis(1).y)+", "+rtos(x.basis.get_axis(1).z)+"), vec3("+rtos(x.basis.get_axis(2).x)+", "+rtos(x.basis.get_axis(2).y)+", "+rtos(x.basis.get_axis(2).z)+"), vec3("+rtos(x.origin.x)+", "+rtos(x.origin.y)+", "+rtos(x.origin.z)+"))"; } break;
|
||||
default: code="<error: "+Variant::get_type_name(cnode->value.get_type())+" ("+itos(cnode->datatype)+">";
|
||||
}
|
||||
return get_constant_text(cnode->datatype,cnode->values);
|
||||
|
||||
} break;
|
||||
case SL::Node::TYPE_OPERATOR: {
|
||||
@ -193,28 +223,25 @@ static String dump_node_code(SL::Node *p_node,int p_level) {
|
||||
case SL::OP_ASSIGN_SUB:
|
||||
case SL::OP_ASSIGN_MUL:
|
||||
case SL::OP_ASSIGN_DIV:
|
||||
case SL::OP_ASSIGN_SHIFT_LEFT:
|
||||
case SL::OP_ASSIGN_SHIFT_RIGHT:
|
||||
case SL::OP_ASSIGN_MOD:
|
||||
case SL::OP_ASSIGN_BIT_AND:
|
||||
case SL::OP_ASSIGN_BIT_OR:
|
||||
case SL::OP_ASSIGN_BIT_XOR:
|
||||
code=dump_node_code(onode->arguments[0],p_level)+_opstr(onode->op)+dump_node_code(onode->arguments[1],p_level);
|
||||
break;
|
||||
|
||||
case SL::OP_ADD:
|
||||
case SL::OP_SUB:
|
||||
case SL::OP_MUL:
|
||||
case SL::OP_DIV:
|
||||
case SL::OP_CMP_EQ:
|
||||
case SL::OP_CMP_NEQ:
|
||||
case SL::OP_CMP_LEQ:
|
||||
case SL::OP_CMP_GEQ:
|
||||
case SL::OP_CMP_LESS:
|
||||
case SL::OP_CMP_GREATER:
|
||||
case SL::OP_CMP_OR:
|
||||
case SL::OP_CMP_AND:
|
||||
|
||||
code="("+dump_node_code(onode->arguments[0],p_level)+_opstr(onode->op)+dump_node_code(onode->arguments[1],p_level)+")";
|
||||
break;
|
||||
case SL::OP_NEG:
|
||||
case SL::OP_BIT_INVERT:
|
||||
case SL::OP_NEGATE:
|
||||
case SL::OP_NOT:
|
||||
case SL::OP_DECREMENT:
|
||||
case SL::OP_INCREMENT:
|
||||
code=_opstr(onode->op)+dump_node_code(onode->arguments[0],p_level);
|
||||
break;
|
||||
case SL::OP_POST_DECREMENT:
|
||||
case SL::OP_POST_INCREMENT:
|
||||
code=dump_node_code(onode->arguments[0],p_level)+_opstr(onode->op);
|
||||
break;
|
||||
case SL::OP_CALL:
|
||||
case SL::OP_CONSTRUCT:
|
||||
code=dump_node_code(onode->arguments[0],p_level)+"(";
|
||||
@ -225,7 +252,12 @@ static String dump_node_code(SL::Node *p_node,int p_level) {
|
||||
}
|
||||
code+=")";
|
||||
break;
|
||||
default: {}
|
||||
default: {
|
||||
|
||||
code="("+dump_node_code(onode->arguments[0],p_level)+_opstr(onode->op)+dump_node_code(onode->arguments[1],p_level)+")";
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} break;
|
||||
@ -233,20 +265,19 @@ static String dump_node_code(SL::Node *p_node,int p_level) {
|
||||
SL::ControlFlowNode *cfnode=(SL::ControlFlowNode*)p_node;
|
||||
if (cfnode->flow_op==SL::FLOW_OP_IF) {
|
||||
|
||||
code+="if ("+dump_node_code(cfnode->statements[0],p_level)+") {\n";
|
||||
code+=dump_node_code(cfnode->statements[1],p_level+1);
|
||||
if (cfnode->statements.size()==3) {
|
||||
code+=_mktab(p_level)+"if ("+dump_node_code(cfnode->expressions[0],p_level)+")\n";
|
||||
code+=dump_node_code(cfnode->blocks[0],p_level+1);
|
||||
if (cfnode->blocks.size()==2) {
|
||||
|
||||
code+="} else {\n";
|
||||
code+=dump_node_code(cfnode->statements[2],p_level+1);
|
||||
code+=_mktab(p_level)+"else\n";
|
||||
code+=dump_node_code(cfnode->blocks[1],p_level+1);
|
||||
}
|
||||
|
||||
code+="}\n";
|
||||
|
||||
} else if (cfnode->flow_op==SL::FLOW_OP_RETURN) {
|
||||
|
||||
if (cfnode->statements.size()) {
|
||||
code="return "+dump_node_code(cfnode->statements[0],p_level);
|
||||
if (cfnode->blocks.size()) {
|
||||
code="return "+dump_node_code(cfnode->blocks[0],p_level);
|
||||
} else {
|
||||
code="return";
|
||||
}
|
||||
@ -264,16 +295,14 @@ static String dump_node_code(SL::Node *p_node,int p_level) {
|
||||
|
||||
}
|
||||
|
||||
static Error recreate_code(void *p_str,SL::ProgramNode *p_program) {
|
||||
static Error recreate_code(void *p_str,SL::ShaderNode *p_program) {
|
||||
|
||||
|
||||
print_line("recr");
|
||||
String *str=(String*)p_str;
|
||||
|
||||
*str=dump_node_code(p_program,0);
|
||||
|
||||
return OK;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -283,6 +312,7 @@ MainLoop* test() {
|
||||
|
||||
if (cmdlargs.empty()) {
|
||||
//try editor!
|
||||
print_line("usage: godot -test shader_lang <shader>");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -303,50 +333,29 @@ MainLoop* test() {
|
||||
code+=c;
|
||||
}
|
||||
|
||||
int errline;
|
||||
int errcol;
|
||||
String error;
|
||||
print_line(SL::lex_debug(code));
|
||||
Error err = SL::compile(code,ShaderLanguage::SHADER_MATERIAL_FRAGMENT,NULL,NULL,&error,&errline,&errcol);
|
||||
SL sl;
|
||||
print_line("tokens:\n\n"+sl.token_debug(code));
|
||||
|
||||
Map<StringName,Map<StringName,SL::DataType> > dt;
|
||||
dt["fragment"]["ALBEDO"]=SL::TYPE_VEC3;
|
||||
|
||||
Set<String> rm;
|
||||
rm.insert("popo");
|
||||
|
||||
Error err = sl.compile(code,dt,rm);
|
||||
|
||||
if (err) {
|
||||
|
||||
print_line("Error: "+itos(errline)+":"+itos(errcol)+" "+error);
|
||||
print_line("Error at line: "+rtos(sl.get_error_line())+": "+sl.get_error_text());
|
||||
return NULL;
|
||||
} else {
|
||||
String code;
|
||||
recreate_code(&code,sl.get_shader());
|
||||
print_line("code:\n\n"+code);
|
||||
}
|
||||
|
||||
print_line("Compile OK! - pretty printing");
|
||||
|
||||
String rcode;
|
||||
err = SL::compile(code,ShaderLanguage::SHADER_MATERIAL_FRAGMENT,recreate_code,&rcode,&error,&errline,&errcol);
|
||||
|
||||
if (!err) {
|
||||
print_line(rcode);
|
||||
}
|
||||
#if 0
|
||||
ShaderCompilerGLES2 comp;
|
||||
String codeline,globalsline;
|
||||
SL::VarInfo vi;
|
||||
vi.name="mongs";
|
||||
vi.type=SL::TYPE_VEC3;
|
||||
|
||||
|
||||
ShaderCompilerGLES2::Flags fl;
|
||||
comp.compile(code,ShaderLanguage::SHADER_MATERIAL_FRAGMENT,codeline,globalsline,fl);
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef ShaderLanguage SL;
|
||||
|
||||
namespace TestShaderLang {
|
||||
|
||||
MainLoop* test() {
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -548,7 +548,7 @@ void register_scene_types() {
|
||||
// ObjectTypeDB::register_type<ShaderMaterial>();
|
||||
ObjectTypeDB::register_type<RoomBounds>();
|
||||
// ObjectTypeDB::register_type<MaterialShaderGraph>();
|
||||
ObjectTypeDB::register_type<MaterialShader>();
|
||||
ObjectTypeDB::register_type<SpatialShader>();
|
||||
ObjectTypeDB::add_compatibility_type("Shader","MaterialShader");
|
||||
ObjectTypeDB::add_compatibility_type("ParticleSystemMaterial","FixedMaterial");
|
||||
ObjectTypeDB::add_compatibility_type("UnshadedMaterial","FixedMaterial");
|
||||
|
@ -131,7 +131,7 @@ void Shader::_bind_methods() {
|
||||
|
||||
ADD_PROPERTY( PropertyInfo(Variant::STRING, "code",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR), _SCS("set_code"), _SCS("get_code") );
|
||||
|
||||
BIND_CONSTANT( MODE_MATERIAL );
|
||||
BIND_CONSTANT( MODE_SPATIAL);
|
||||
BIND_CONSTANT( MODE_CANVAS_ITEM );
|
||||
BIND_CONSTANT( MODE_POST_PROCESS );
|
||||
|
||||
|
@ -42,7 +42,7 @@ class Shader : public Resource {
|
||||
public:
|
||||
enum Mode {
|
||||
|
||||
MODE_MATERIAL,
|
||||
MODE_SPATIAL,
|
||||
MODE_CANVAS_ITEM,
|
||||
MODE_POST_PROCESS,
|
||||
MODE_MAX
|
||||
@ -100,13 +100,13 @@ public:
|
||||
|
||||
VARIANT_ENUM_CAST( Shader::Mode );
|
||||
|
||||
class MaterialShader : public Shader {
|
||||
class SpatialShader : public Shader {
|
||||
|
||||
OBJ_TYPE(MaterialShader,Shader);
|
||||
OBJ_TYPE(SpatialShader,Shader);
|
||||
|
||||
public:
|
||||
|
||||
MaterialShader() : Shader(MODE_MATERIAL) {};
|
||||
SpatialShader() : Shader(MODE_SPATIAL) {};
|
||||
};
|
||||
|
||||
class CanvasItemShader : public Shader {
|
||||
|
@ -36,7 +36,7 @@
|
||||
#include "spatial_sound_server.h"
|
||||
#include "spatial_sound_2d_server.h"
|
||||
#include "script_debugger_remote.h"
|
||||
|
||||
#include "visual/shader_types.h"
|
||||
static void _debugger_get_resource_usage(List<ScriptDebuggerRemote::ResourceUsage>* r_usage) {
|
||||
|
||||
List<VS::TextureInfo> tinfo;
|
||||
@ -55,6 +55,8 @@ static void _debugger_get_resource_usage(List<ScriptDebuggerRemote::ResourceUsag
|
||||
|
||||
}
|
||||
|
||||
ShaderTypes *shader_types=NULL;
|
||||
|
||||
void register_server_types() {
|
||||
|
||||
Globals::get_singleton()->add_singleton( Globals::Singleton("VisualServer",VisualServer::get_singleton()) );
|
||||
@ -70,6 +72,8 @@ void register_server_types() {
|
||||
Globals::get_singleton()->add_singleton( Globals::Singleton("SpatialSound2DServer",SpatialSound2DServer::get_singleton()) );
|
||||
Globals::get_singleton()->add_singleton( Globals::Singleton("SS2D",SpatialSound2DServer::get_singleton()) );
|
||||
|
||||
shader_types = memnew( ShaderTypes );
|
||||
|
||||
|
||||
ObjectTypeDB::register_virtual_type<Physics2DDirectBodyState>();
|
||||
ObjectTypeDB::register_virtual_type<Physics2DDirectSpaceState>();
|
||||
@ -87,5 +91,5 @@ void register_server_types() {
|
||||
|
||||
void unregister_server_types(){
|
||||
|
||||
|
||||
memdelete( shader_types );
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -138,7 +138,10 @@ public:
|
||||
TK_HINT_WHITE_TEXTURE,
|
||||
TK_HINT_BLACK_TEXTURE,
|
||||
TK_HINT_NORMAL_TEXTURE,
|
||||
TK_HINT_ALBEDO_TEXTURE,
|
||||
TK_HINT_COLOR,
|
||||
TK_HINT_RANGE,
|
||||
TK_CURSOR,
|
||||
TK_ERROR,
|
||||
TK_EOF,
|
||||
TK_MAX
|
||||
@ -291,7 +294,15 @@ public:
|
||||
struct ConstantNode : public Node {
|
||||
|
||||
DataType datatype;
|
||||
Variant value;
|
||||
|
||||
union Value {
|
||||
bool boolean;
|
||||
float real;
|
||||
int32_t sint;
|
||||
uint32_t uint;
|
||||
};
|
||||
|
||||
Vector<Value> values;
|
||||
virtual DataType get_datatype() const { return datatype; }
|
||||
|
||||
ConstantNode() { type=TYPE_CONSTANT; }
|
||||
@ -306,6 +317,7 @@ public:
|
||||
struct Variable {
|
||||
DataType type;
|
||||
DataPrecision precision;
|
||||
int line; //for completion
|
||||
};
|
||||
|
||||
Map<StringName,Variable> variables;
|
||||
@ -316,6 +328,7 @@ public:
|
||||
struct ControlFlowNode : public Node {
|
||||
|
||||
FlowOperation flow_op;
|
||||
Vector<Node*> expressions;
|
||||
Vector<BlockNode*> blocks;
|
||||
ControlFlowNode() { type=TYPE_CONTROL_FLOW; flow_op=FLOW_OP_IF;}
|
||||
};
|
||||
@ -368,16 +381,19 @@ public:
|
||||
struct Uniform {
|
||||
enum Hint {
|
||||
HINT_NONE,
|
||||
HINT_WHITE_TEXTURE,
|
||||
HINT_BLACK_TEXTURE,
|
||||
HINT_NORMAL_TEXTURE,
|
||||
HINT_COLOR,
|
||||
HINT_RANGE,
|
||||
HINT_ALBEDO,
|
||||
HINT_NORMAL,
|
||||
HINT_BLACK,
|
||||
HINT_WHITE,
|
||||
HINT_MAX
|
||||
};
|
||||
|
||||
int order;
|
||||
DataType type;
|
||||
DataPrecision precission;
|
||||
Variant default_value;
|
||||
Vector<ConstantNode::Value> default_value;
|
||||
Hint hint;
|
||||
float hint_range[3];
|
||||
|
||||
@ -414,15 +430,12 @@ public:
|
||||
|
||||
enum CompletionType {
|
||||
COMPLETION_NONE,
|
||||
COMPLETION_BUILT_IN_TYPE_CONSTANT,
|
||||
COMPLETION_FUNCTION,
|
||||
COMPLETION_RENDER_MODE,
|
||||
COMPLETION_MAIN_FUNCTION,
|
||||
COMPLETION_IDENTIFIER,
|
||||
COMPLETION_PARENT_FUNCTION,
|
||||
COMPLETION_METHOD,
|
||||
COMPLETION_FUNCTION_CALL,
|
||||
COMPLETION_CALL_ARGUMENTS,
|
||||
COMPLETION_INDEX,
|
||||
COMPLETION_VIRTUAL_FUNC,
|
||||
COMPLETION_YIELD,
|
||||
};
|
||||
|
||||
struct Token {
|
||||
@ -433,7 +446,10 @@ public:
|
||||
uint16_t line;
|
||||
};
|
||||
|
||||
|
||||
static String get_operator_text(Operator p_op);
|
||||
static String get_token_text(Token p_token);
|
||||
|
||||
static bool is_token_datatype(TokenType p_type);
|
||||
static DataType get_token_datatype(TokenType p_type);
|
||||
static bool is_token_precision(TokenType p_type);
|
||||
@ -442,8 +458,16 @@ public:
|
||||
static bool is_token_nonvoid_datatype(TokenType p_type);
|
||||
static bool is_token_operator(TokenType p_type);
|
||||
|
||||
static bool convert_constant(ConstantNode* p_constant, DataType p_to_type,ConstantNode::Value *p_value=NULL);
|
||||
static DataType get_scalar_type(DataType p_type);
|
||||
static bool is_scalar_type(DataType p_type);
|
||||
|
||||
static void get_keyword_list(List<String> *r_keywords);
|
||||
private:
|
||||
|
||||
struct KeyWord { TokenType token; const char *text;};
|
||||
static const KeyWord keyword_list[];
|
||||
|
||||
bool error_set;
|
||||
String error_str;
|
||||
int error_line;
|
||||
@ -452,10 +476,29 @@ private:
|
||||
int char_idx;
|
||||
int tk_line;
|
||||
|
||||
struct TkPos {
|
||||
int char_idx;
|
||||
int tk_line;
|
||||
};
|
||||
|
||||
TkPos _get_tkpos() {
|
||||
TkPos tkp;
|
||||
tkp.char_idx=char_idx;
|
||||
tkp.tk_line=tk_line;
|
||||
return tkp;
|
||||
}
|
||||
|
||||
|
||||
void _set_tkpos(TkPos p_pos) {
|
||||
char_idx=p_pos.char_idx;
|
||||
tk_line=p_pos.tk_line;
|
||||
}
|
||||
|
||||
void _set_error(const String& p_str) {
|
||||
if (error_set)
|
||||
return;
|
||||
|
||||
error_line=tk_line;
|
||||
error_set=true;
|
||||
error_str=p_str;
|
||||
}
|
||||
@ -485,7 +528,7 @@ private:
|
||||
bool _validate_operator(OperatorNode *p_op,DataType *r_ret_type=NULL);
|
||||
|
||||
|
||||
struct IntrinsicFuncDef {
|
||||
struct BuiltinFuncDef {
|
||||
|
||||
enum { MAX_ARGS=5 };
|
||||
const char* name;
|
||||
@ -494,11 +537,20 @@ private:
|
||||
|
||||
};
|
||||
|
||||
CompletionType completion_type;
|
||||
int completion_line;
|
||||
BlockNode *completion_block;
|
||||
DataType completion_base;
|
||||
StringName completion_function;
|
||||
int completion_argument;
|
||||
|
||||
static const IntrinsicFuncDef intrinsic_func_defs[];
|
||||
|
||||
bool _get_completable_identifier(BlockNode *p_block, CompletionType p_type, StringName& identifier);
|
||||
|
||||
static const BuiltinFuncDef builtin_func_defs[];
|
||||
bool _validate_function_call(BlockNode* p_block, OperatorNode *p_func,DataType *r_ret_type);
|
||||
|
||||
bool _parse_function_arguments(BlockNode *p_block, const Map<StringName,DataType> &p_builtin_types, OperatorNode* p_func);
|
||||
bool _parse_function_arguments(BlockNode *p_block, const Map<StringName,DataType> &p_builtin_types, OperatorNode* p_func, int *r_complete_arg=NULL);
|
||||
|
||||
Node* _parse_expression(BlockNode *p_block, const Map<StringName,DataType> &p_builtin_types);
|
||||
|
||||
@ -516,10 +568,16 @@ public:
|
||||
|
||||
void clear();
|
||||
Error compile(const String& p_code,const Map< StringName, Map<StringName,DataType> > &p_functions,const Set<String>& p_render_modes);
|
||||
Error complete(const String& p_code,const Map< StringName, Map<StringName,DataType> > &p_functions,const Set<String>& p_render_modes,List<String>* r_options,String& r_call_hint);
|
||||
|
||||
|
||||
|
||||
String get_error_text();
|
||||
int get_error_line();
|
||||
|
||||
static String lex_debug(const String& p_code);
|
||||
ShaderNode *get_shader();
|
||||
|
||||
String token_debug(const String& p_code);
|
||||
|
||||
ShaderLanguage();
|
||||
~ShaderLanguage();
|
||||
|
99
servers/visual/shader_types.cpp
Normal file
99
servers/visual/shader_types.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
#include "shader_types.h"
|
||||
|
||||
|
||||
const Map< StringName, Map<StringName,ShaderLanguage::DataType> >& ShaderTypes::get_functions(VS::ShaderMode p_mode) {
|
||||
|
||||
return shader_modes[p_mode].functions;
|
||||
}
|
||||
|
||||
const Set<String>& ShaderTypes::get_modes(VS::ShaderMode p_mode) {
|
||||
|
||||
return shader_modes[p_mode].modes;
|
||||
}
|
||||
|
||||
|
||||
ShaderTypes *ShaderTypes::singleton=NULL;
|
||||
|
||||
ShaderTypes::ShaderTypes()
|
||||
{
|
||||
singleton=this;
|
||||
|
||||
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["SRC_VERTEX"]=ShaderLanguage::TYPE_VEC3;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["SRC_NORMAL"]=ShaderLanguage::TYPE_VEC3;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["SRC_TANGENT"]=ShaderLanguage::TYPE_VEC4;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["SRC_BONES"]=ShaderLanguage::TYPE_IVEC4;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["SRC_WEIGHTS"]=ShaderLanguage::TYPE_VEC4;
|
||||
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["POSITION"]=ShaderLanguage::TYPE_VEC4 ;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["VERTEX"]=ShaderLanguage::TYPE_VEC3;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["NORMAL"]=ShaderLanguage::TYPE_VEC3;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["TANGENT"]=ShaderLanguage::TYPE_VEC3;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["BINORMAL"]=ShaderLanguage::TYPE_VEC3;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["UV"]=ShaderLanguage::TYPE_VEC2;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["UV2"]=ShaderLanguage::TYPE_VEC2;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["COLOR"]=ShaderLanguage::TYPE_VEC4;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["POINT_SIZE"]=ShaderLanguage::TYPE_FLOAT;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["INSTANCE_ID"]=ShaderLanguage::TYPE_INT;
|
||||
|
||||
//builtins
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["WORLD_MATRIX"]=ShaderLanguage::TYPE_MAT4;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["INV_CAMERA_MATRIX"]=ShaderLanguage::TYPE_MAT4;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["PROJECTION_MATRIX"]=ShaderLanguage::TYPE_MAT4;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["TIME"]=ShaderLanguage::TYPE_FLOAT;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["vertex"]["VIEWPORT_SIZE"]=ShaderLanguage::TYPE_VEC2;
|
||||
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["VERTEX"]=ShaderLanguage::TYPE_VEC3;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["FRAGCOORD"]=ShaderLanguage::TYPE_VEC4;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["FRONT_FACING"]=ShaderLanguage::TYPE_BOOL;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["NORMAL"]=ShaderLanguage::TYPE_VEC3;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["TANGENT"]=ShaderLanguage::TYPE_VEC3;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["BINORMAL"]=ShaderLanguage::TYPE_VEC3;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["NORMALMAP"]=ShaderLanguage::TYPE_VEC3;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["NORMALMAP_DEPTH"]=ShaderLanguage::TYPE_FLOAT;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["UV"]=ShaderLanguage::TYPE_VEC2;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["UV2"]=ShaderLanguage::TYPE_VEC2;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["COLOR"]=ShaderLanguage::TYPE_VEC4;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["NORMAL"]=ShaderLanguage::TYPE_VEC3;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["ALBEDO"]=ShaderLanguage::TYPE_VEC3;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["ALPHA"]=ShaderLanguage::TYPE_FLOAT;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["METAL"]=ShaderLanguage::TYPE_FLOAT;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["ROUGH"]=ShaderLanguage::TYPE_FLOAT;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["EMISSION"]=ShaderLanguage::TYPE_VEC3;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["SPECIAL"]=ShaderLanguage::TYPE_FLOAT;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["DISCARD"]=ShaderLanguage::TYPE_BOOL;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["SCREEN_UV"]=ShaderLanguage::TYPE_VEC2;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["POINT_COORD"]=ShaderLanguage::TYPE_VEC2;
|
||||
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["WORLD_MATRIX"]=ShaderLanguage::TYPE_MAT4;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["INV_CAMERA_MATRIX"]=ShaderLanguage::TYPE_MAT4;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["PROJECTION_MATRIX"]=ShaderLanguage::TYPE_MAT4;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["TIME"]=ShaderLanguage::TYPE_FLOAT;
|
||||
shader_modes[VS::SHADER_SPATIAL].functions["fragment"]["VIEWPORT_SIZE"]=ShaderLanguage::TYPE_VEC2;
|
||||
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("blend_mix");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("blend_add");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("blend_sub");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("blend_mul");
|
||||
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("special_glow");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("special_subsurf");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("special_specular");
|
||||
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("depth_draw_opaque");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("depth_draw_always");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("depth_draw_never");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("depth_draw_alpha_prepass");
|
||||
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("cull_front");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("cull_back");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("cull_disable");
|
||||
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("lightmap_on_uv2");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("unshaded");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("ontop");
|
||||
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("vertex_model_space");
|
||||
shader_modes[VS::SHADER_SPATIAL].modes.insert("vertex_camera_space");
|
||||
|
||||
}
|
27
servers/visual/shader_types.h
Normal file
27
servers/visual/shader_types.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef SHADERTYPES_H
|
||||
#define SHADERTYPES_H
|
||||
|
||||
#include "shader_language.h"
|
||||
#include "servers/visual_server.h"
|
||||
class ShaderTypes {
|
||||
|
||||
|
||||
struct Type {
|
||||
|
||||
Map< StringName, Map<StringName,ShaderLanguage::DataType> > functions;
|
||||
Set<String> modes;
|
||||
};
|
||||
|
||||
Map<VS::ShaderMode,Type> shader_modes;
|
||||
|
||||
static ShaderTypes *singleton;
|
||||
public:
|
||||
static ShaderTypes *get_singleton() { return singleton; }
|
||||
|
||||
const Map< StringName, Map<StringName,ShaderLanguage::DataType> >& get_functions(VS::ShaderMode p_mode);
|
||||
const Set<String>& get_modes(VS::ShaderMode p_mode);
|
||||
|
||||
ShaderTypes();
|
||||
};
|
||||
|
||||
#endif // SHADERTYPES_H
|
@ -6540,9 +6540,10 @@ EditorNode::EditorNode() {
|
||||
//more visually meaningful to have this later
|
||||
raise_bottom_panel_item(AnimationPlayerEditor::singleton);
|
||||
|
||||
add_editor_plugin( memnew( ShaderEditorPlugin(this) ) );
|
||||
/* add_editor_plugin( memnew( ShaderGraphEditorPlugin(this,true) ) );
|
||||
add_editor_plugin( memnew( ShaderGraphEditorPlugin(this,false) ) );
|
||||
add_editor_plugin( memnew( ShaderEditorPlugin(this,true) ) );
|
||||
|
||||
add_editor_plugin( memnew( ShaderEditorPlugin(this,false) ) );*/
|
||||
add_editor_plugin( memnew( CameraEditorPlugin(this) ) );
|
||||
add_editor_plugin( memnew( SampleEditorPlugin(this) ) );
|
||||
|
@ -37,8 +37,8 @@
|
||||
#include "tools/editor/editor_node.h"
|
||||
#include "tools/editor/property_editor.h"
|
||||
#include "os/os.h"
|
||||
#include "servers/visual/shader_types.h"
|
||||
|
||||
#if 0
|
||||
/*** SETTINGS EDITOR ****/
|
||||
|
||||
|
||||
@ -51,19 +51,14 @@ Ref<Shader> ShaderTextEditor::get_edited_shader() const {
|
||||
|
||||
return shader;
|
||||
}
|
||||
void ShaderTextEditor::set_edited_shader(const Ref<Shader>& p_shader,ShaderLanguage::ShaderType p_type) {
|
||||
void ShaderTextEditor::set_edited_shader(const Ref<Shader>& p_shader) {
|
||||
|
||||
shader=p_shader;
|
||||
type=p_type;
|
||||
|
||||
|
||||
_load_theme_settings();
|
||||
|
||||
if (p_type==ShaderLanguage::SHADER_MATERIAL_LIGHT || p_type==ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT)
|
||||
get_text_edit()->set_text(shader->get_light_code());
|
||||
else if (p_type==ShaderLanguage::SHADER_MATERIAL_VERTEX || p_type==ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX)
|
||||
get_text_edit()->set_text(shader->get_vertex_code());
|
||||
else
|
||||
get_text_edit()->set_text(shader->get_fragment_code());
|
||||
get_text_edit()->set_text(p_shader->get_code());
|
||||
|
||||
_line_col_changed();
|
||||
|
||||
@ -104,7 +99,25 @@ void ShaderTextEditor::_load_theme_settings() {
|
||||
|
||||
|
||||
List<String> keywords;
|
||||
ShaderLanguage::get_keyword_list(type,&keywords);
|
||||
ShaderLanguage::get_keyword_list(&keywords);
|
||||
|
||||
if (shader.is_valid()) {
|
||||
|
||||
|
||||
for(const Map< StringName, Map<StringName,ShaderLanguage::DataType> >::Element *E=ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(shader->get_mode())).front();E;E=E->next()) {
|
||||
|
||||
for (const Map<StringName,ShaderLanguage::DataType>::Element *F=E->get().front();F;F=F->next()) {
|
||||
keywords.push_back(F->key());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for(const Set<String>::Element *E =ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode())).front();E;E=E->next()) {
|
||||
|
||||
keywords.push_back(E->get());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(List<String>::Element *E=keywords.front();E;E=E->next()) {
|
||||
@ -142,22 +155,34 @@ void ShaderTextEditor::_load_theme_settings() {
|
||||
|
||||
}
|
||||
|
||||
void ShaderTextEditor::_code_complete_script(const String& p_code, List<String>* r_options) {
|
||||
|
||||
print_line("code complete");
|
||||
|
||||
ShaderLanguage sl;
|
||||
String calltip;
|
||||
|
||||
Error err = sl.complete(p_code,ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(shader->get_mode())),ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode())),r_options,calltip);
|
||||
|
||||
if (calltip!="") {
|
||||
get_text_edit()->set_code_hint(calltip);
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderTextEditor::_validate_script() {
|
||||
|
||||
String errortxt;
|
||||
int line,col;
|
||||
|
||||
String code=get_text_edit()->get_text();
|
||||
//List<StringName> params;
|
||||
//shader->get_param_list(¶ms);
|
||||
|
||||
Error err = ShaderLanguage::compile(code,type,NULL,NULL,&errortxt,&line,&col);
|
||||
ShaderLanguage sl;
|
||||
|
||||
Error err = sl.compile(code,ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(shader->get_mode())),ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(shader->get_mode())));
|
||||
|
||||
if (err!=OK) {
|
||||
String error_text="error("+itos(line+1)+","+itos(col)+"): "+errortxt;
|
||||
String error_text="error("+itos(sl.get_error_line())+"): "+sl.get_error_text();
|
||||
set_error(error_text);
|
||||
get_text_edit()->set_line_as_marked(line,true);
|
||||
get_text_edit()->set_line_as_marked(sl.get_error_line(),true);
|
||||
|
||||
} else {
|
||||
for(int i=0;i<get_text_edit()->get_line_count();i++)
|
||||
@ -187,9 +212,7 @@ ShaderTextEditor::ShaderTextEditor() {
|
||||
void ShaderEditor::_menu_option(int p_option) {
|
||||
|
||||
|
||||
ShaderTextEditor *current = tab_container->get_current_tab_control()->cast_to<ShaderTextEditor>();
|
||||
if (!current)
|
||||
return;
|
||||
ShaderTextEditor *current = shader_editor;
|
||||
|
||||
switch(p_option) {
|
||||
case EDIT_UNDO: {
|
||||
@ -245,24 +268,11 @@ void ShaderEditor::_menu_option(int p_option) {
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderEditor::_tab_changed(int p_which) {
|
||||
|
||||
ShaderTextEditor *shader_editor = tab_container->get_tab_control(p_which)->cast_to<ShaderTextEditor>();
|
||||
|
||||
if (shader_editor && is_inside_tree())
|
||||
shader_editor->get_text_edit()->grab_focus();
|
||||
|
||||
ensure_select_current();
|
||||
}
|
||||
|
||||
void ShaderEditor::_notification(int p_what) {
|
||||
|
||||
if (p_what==NOTIFICATION_ENTER_TREE) {
|
||||
|
||||
close->set_normal_texture( get_icon("Close","EditorIcons"));
|
||||
close->set_hover_texture( get_icon("CloseHover","EditorIcons"));
|
||||
close->set_pressed_texture( get_icon("Close","EditorIcons"));
|
||||
close->connect("pressed",this,"_close_callback");
|
||||
|
||||
}
|
||||
if (p_what==NOTIFICATION_DRAW) {
|
||||
@ -365,57 +375,31 @@ void ShaderEditor::clear() {
|
||||
void ShaderEditor::_params_changed() {
|
||||
|
||||
|
||||
fragment_editor->_validate_script();
|
||||
vertex_editor->_validate_script();
|
||||
light_editor->_validate_script();
|
||||
shader_editor->_validate_script();
|
||||
}
|
||||
|
||||
void ShaderEditor::_editor_settings_changed() {
|
||||
|
||||
vertex_editor->get_text_edit()->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/auto_brace_complete"));
|
||||
vertex_editor->get_text_edit()->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/scroll_past_end_of_file"));
|
||||
vertex_editor->get_text_edit()->set_tab_size(EditorSettings::get_singleton()->get("text_editor/tab_size"));
|
||||
vertex_editor->get_text_edit()->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/draw_tabs"));
|
||||
vertex_editor->get_text_edit()->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/show_line_numbers"));
|
||||
vertex_editor->get_text_edit()->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/syntax_highlighting"));
|
||||
vertex_editor->get_text_edit()->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlight_all_occurrences"));
|
||||
vertex_editor->get_text_edit()->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/caret_blink"));
|
||||
vertex_editor->get_text_edit()->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/caret_blink_speed"));
|
||||
vertex_editor->get_text_edit()->add_constant_override("line_spacing", EditorSettings::get_singleton()->get("text_editor/line_spacing"));
|
||||
vertex_editor->get_text_edit()->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/block_caret"));
|
||||
shader_editor->get_text_edit()->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/auto_brace_complete"));
|
||||
shader_editor->get_text_edit()->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/scroll_past_end_of_file"));
|
||||
shader_editor->get_text_edit()->set_tab_size(EditorSettings::get_singleton()->get("text_editor/tab_size"));
|
||||
shader_editor->get_text_edit()->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/draw_tabs"));
|
||||
shader_editor->get_text_edit()->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/show_line_numbers"));
|
||||
shader_editor->get_text_edit()->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/syntax_highlighting"));
|
||||
shader_editor->get_text_edit()->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlight_all_occurrences"));
|
||||
shader_editor->get_text_edit()->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/caret_blink"));
|
||||
shader_editor->get_text_edit()->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/caret_blink_speed"));
|
||||
shader_editor->get_text_edit()->add_constant_override("line_spacing", EditorSettings::get_singleton()->get("text_editor/line_spacing"));
|
||||
shader_editor->get_text_edit()->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/block_caret"));
|
||||
|
||||
fragment_editor->get_text_edit()->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/auto_brace_complete"));
|
||||
fragment_editor->get_text_edit()->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/scroll_past_end_of_file"));
|
||||
fragment_editor->get_text_edit()->set_tab_size(EditorSettings::get_singleton()->get("text_editor/tab_size"));
|
||||
fragment_editor->get_text_edit()->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/draw_tabs"));
|
||||
fragment_editor->get_text_edit()->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/show_line_numbers"));
|
||||
fragment_editor->get_text_edit()->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/syntax_highlighting"));
|
||||
fragment_editor->get_text_edit()->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlight_all_occurrences"));
|
||||
fragment_editor->get_text_edit()->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/caret_blink"));
|
||||
fragment_editor->get_text_edit()->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/caret_blink_speed"));
|
||||
fragment_editor->get_text_edit()->add_constant_override("line_spacing", EditorSettings::get_singleton()->get("text_editor/line_spacing"));
|
||||
fragment_editor->get_text_edit()->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/block_caret"));
|
||||
|
||||
light_editor->get_text_edit()->set_auto_brace_completion(EditorSettings::get_singleton()->get("text_editor/auto_brace_complete"));
|
||||
light_editor->get_text_edit()->set_scroll_pass_end_of_file(EditorSettings::get_singleton()->get("text_editor/scroll_past_end_of_file"));
|
||||
light_editor->get_text_edit()->set_tab_size(EditorSettings::get_singleton()->get("text_editor/tab_size"));
|
||||
light_editor->get_text_edit()->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/draw_tabs"));
|
||||
light_editor->get_text_edit()->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/show_line_numbers"));
|
||||
light_editor->get_text_edit()->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/syntax_highlighting"));
|
||||
light_editor->get_text_edit()->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlight_all_occurrences"));
|
||||
light_editor->get_text_edit()->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/caret_blink"));
|
||||
light_editor->get_text_edit()->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/caret_blink_speed"));
|
||||
light_editor->get_text_edit()->add_constant_override("line_spacing", EditorSettings::get_singleton()->get("text_editor/line_spacing"));
|
||||
light_editor->get_text_edit()->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/block_caret"));
|
||||
}
|
||||
|
||||
void ShaderEditor::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method("_editor_settings_changed",&ShaderEditor::_editor_settings_changed);
|
||||
ObjectTypeDB::bind_method("_tab_changed",&ShaderEditor::_tab_changed);
|
||||
|
||||
ObjectTypeDB::bind_method("_menu_option",&ShaderEditor::_menu_option);
|
||||
ObjectTypeDB::bind_method("_params_changed",&ShaderEditor::_params_changed);
|
||||
ObjectTypeDB::bind_method("_close_callback",&ShaderEditor::_close_callback);
|
||||
ObjectTypeDB::bind_method("apply_shaders",&ShaderEditor::apply_shaders);
|
||||
// ObjectTypeDB::bind_method("_close_current_tab",&ShaderEditor::_close_current_tab);
|
||||
}
|
||||
@ -441,16 +425,7 @@ void ShaderEditor::edit(const Ref<Shader>& p_shader) {
|
||||
|
||||
shader=p_shader;
|
||||
|
||||
if (shader->get_mode()==Shader::MODE_MATERIAL) {
|
||||
vertex_editor->set_edited_shader(p_shader,ShaderLanguage::SHADER_MATERIAL_VERTEX);
|
||||
fragment_editor->set_edited_shader(p_shader,ShaderLanguage::SHADER_MATERIAL_FRAGMENT);
|
||||
light_editor->set_edited_shader(shader,ShaderLanguage::SHADER_MATERIAL_LIGHT);
|
||||
} else if (shader->get_mode()==Shader::MODE_CANVAS_ITEM) {
|
||||
|
||||
vertex_editor->set_edited_shader(p_shader,ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX);
|
||||
fragment_editor->set_edited_shader(p_shader,ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT);
|
||||
light_editor->set_edited_shader(shader,ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT);
|
||||
}
|
||||
shader_editor->set_edited_shader(p_shader);
|
||||
|
||||
//vertex_editor->set_edited_shader(shader,ShaderLanguage::SHADER_MATERIAL_VERTEX);
|
||||
// see if already has it
|
||||
@ -474,35 +449,21 @@ void ShaderEditor::apply_shaders() {
|
||||
|
||||
|
||||
if (shader.is_valid()) {
|
||||
shader->set_code(vertex_editor->get_text_edit()->get_text(),fragment_editor->get_text_edit()->get_text(),light_editor->get_text_edit()->get_text(),0,0);
|
||||
shader->set_code(shader_editor->get_text_edit()->get_text());
|
||||
shader->set_edited(true);
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderEditor::_close_callback() {
|
||||
|
||||
hide();
|
||||
}
|
||||
|
||||
|
||||
ShaderEditor::ShaderEditor() {
|
||||
|
||||
tab_container = memnew( TabContainer );
|
||||
add_child(tab_container);
|
||||
tab_container->set_area_as_parent_rect();
|
||||
tab_container->set_begin(Point2(0,0));
|
||||
//tab_container->set_begin(Point2(0,0));
|
||||
|
||||
close = memnew( TextureButton );
|
||||
close->set_anchor_and_margin(MARGIN_LEFT,ANCHOR_END,20);
|
||||
close->set_anchor_and_margin(MARGIN_RIGHT,ANCHOR_END,4);
|
||||
close->set_anchor_and_margin(MARGIN_TOP,ANCHOR_BEGIN,2);
|
||||
add_child(close);
|
||||
|
||||
HBoxContainer *hbc = memnew( HBoxContainer);
|
||||
|
||||
add_child(hbc);
|
||||
|
||||
edit_menu = memnew( MenuButton );
|
||||
add_child(edit_menu);
|
||||
hbc->add_child(edit_menu);
|
||||
edit_menu->set_pos(Point2(5,-1));
|
||||
edit_menu->set_text(TTR("Edit"));
|
||||
edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/undo", TTR("Undo"), KEY_MASK_CMD|KEY_Z), EDIT_UNDO);
|
||||
@ -517,7 +478,7 @@ ShaderEditor::ShaderEditor() {
|
||||
|
||||
|
||||
search_menu = memnew( MenuButton );
|
||||
add_child(search_menu);
|
||||
hbc->add_child(search_menu);
|
||||
search_menu->set_pos(Point2(38,-1));
|
||||
search_menu->set_text(TTR("Search"));
|
||||
search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find", TTR("Find.."), KEY_MASK_CMD|KEY_F), SEARCH_FIND);
|
||||
@ -530,34 +491,15 @@ ShaderEditor::ShaderEditor() {
|
||||
search_menu->get_popup()->connect("item_pressed", this,"_menu_option");
|
||||
|
||||
|
||||
tab_container->connect("tab_changed", this,"_tab_changed");
|
||||
|
||||
erase_tab_confirm = memnew( ConfirmationDialog );
|
||||
add_child(erase_tab_confirm);
|
||||
erase_tab_confirm->connect("confirmed", this,"_close_current_tab");
|
||||
|
||||
|
||||
goto_line_dialog = memnew(GotoLineDialog);
|
||||
add_child(goto_line_dialog);
|
||||
|
||||
vertex_editor = memnew( ShaderTextEditor );
|
||||
tab_container->add_child(vertex_editor);
|
||||
vertex_editor->set_name(TTR("Vertex"));
|
||||
|
||||
fragment_editor = memnew( ShaderTextEditor );
|
||||
tab_container->add_child(fragment_editor);
|
||||
fragment_editor->set_name(TTR("Fragment"));
|
||||
|
||||
light_editor = memnew( ShaderTextEditor );
|
||||
tab_container->add_child(light_editor);
|
||||
light_editor->set_name(TTR("Lighting"));
|
||||
|
||||
tab_container->set_current_tab(1);
|
||||
shader_editor = memnew( ShaderTextEditor );
|
||||
add_child(shader_editor);
|
||||
shader_editor->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
|
||||
|
||||
vertex_editor->connect("script_changed", this,"apply_shaders");
|
||||
fragment_editor->connect("script_changed", this,"apply_shaders");
|
||||
light_editor->connect("script_changed", this,"apply_shaders");
|
||||
shader_editor->connect("script_changed", this,"apply_shaders");
|
||||
EditorSettings::get_singleton()->connect("settings_changed",this,"_editor_settings_changed");
|
||||
|
||||
_editor_settings_changed();
|
||||
@ -567,15 +509,7 @@ ShaderEditor::ShaderEditor() {
|
||||
void ShaderEditorPlugin::edit(Object *p_object) {
|
||||
|
||||
Shader* s = p_object->cast_to<Shader>();
|
||||
if (!s || s->cast_to<ShaderGraph>()) {
|
||||
shader_editor->hide(); //Dont edit ShaderGraph
|
||||
return;
|
||||
}
|
||||
|
||||
if (_2d && s->get_mode()==Shader::MODE_CANVAS_ITEM)
|
||||
shader_editor->edit(s);
|
||||
else if (!_2d && s->get_mode()==Shader::MODE_MATERIAL)
|
||||
shader_editor->edit(s);
|
||||
shader_editor->edit(s);
|
||||
|
||||
}
|
||||
|
||||
@ -583,24 +517,25 @@ bool ShaderEditorPlugin::handles(Object *p_object) const {
|
||||
|
||||
bool handles = true;
|
||||
Shader *shader=p_object->cast_to<Shader>();
|
||||
if (!shader || shader->cast_to<ShaderGraph>()) // Dont handle ShaderGraph's
|
||||
handles = false;
|
||||
if (handles && _2d)
|
||||
handles = shader->get_mode()==Shader::MODE_CANVAS_ITEM;
|
||||
else if (handles && !_2d)
|
||||
return shader->get_mode()==Shader::MODE_MATERIAL;
|
||||
//if (!shader || shader->cast_to<ShaderGraph>()) // Dont handle ShaderGraph's
|
||||
// handles = false;
|
||||
|
||||
if (!handles)
|
||||
shader_editor->hide();
|
||||
return handles;
|
||||
return shader!=NULL;
|
||||
}
|
||||
|
||||
void ShaderEditorPlugin::make_visible(bool p_visible) {
|
||||
|
||||
if (p_visible) {
|
||||
shader_editor->show();
|
||||
button->show();
|
||||
editor->make_bottom_panel_item_visible(shader_editor);
|
||||
|
||||
} else {
|
||||
|
||||
button->hide();
|
||||
if (shader_editor->is_visible())
|
||||
editor->hide_bottom_panel();
|
||||
shader_editor->apply_shaders();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -634,19 +569,14 @@ void ShaderEditorPlugin::apply_changes() {
|
||||
shader_editor->apply_shaders();
|
||||
}
|
||||
|
||||
ShaderEditorPlugin::ShaderEditorPlugin(EditorNode *p_node, bool p_2d) {
|
||||
ShaderEditorPlugin::ShaderEditorPlugin(EditorNode *p_node) {
|
||||
|
||||
|
||||
editor=p_node;
|
||||
shader_editor = memnew( ShaderEditor );
|
||||
_2d=p_2d;
|
||||
if (p_2d)
|
||||
add_control_to_container(CONTAINER_CANVAS_EDITOR_BOTTOM,shader_editor);
|
||||
else
|
||||
add_control_to_container(CONTAINER_SPATIAL_EDITOR_BOTTOM,shader_editor);
|
||||
// editor->get_viewport()->add_child(shader_editor);
|
||||
// shader_editor->set_area_as_parent_rect();
|
||||
|
||||
shader_editor->hide();
|
||||
shader_editor->set_custom_minimum_size(Size2(0,300));
|
||||
button=editor->add_bottom_panel_item("Shader",shader_editor);
|
||||
|
||||
}
|
||||
|
||||
@ -654,4 +584,4 @@ ShaderEditorPlugin::ShaderEditorPlugin(EditorNode *p_node, bool p_2d) {
|
||||
ShaderEditorPlugin::~ShaderEditorPlugin() {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -38,33 +38,34 @@
|
||||
#include "scene/resources/shader.h"
|
||||
#include "servers/visual/shader_language.h"
|
||||
|
||||
#if 0
|
||||
class ShaderTextEditor : public CodeTextEditor {
|
||||
|
||||
OBJ_TYPE( ShaderTextEditor, CodeTextEditor );
|
||||
|
||||
Ref<Shader> shader;
|
||||
ShaderLanguage::ShaderType type;
|
||||
|
||||
protected:
|
||||
|
||||
static void _bind_methods();
|
||||
virtual void _load_theme_settings();
|
||||
|
||||
virtual void _code_complete_script(const String& p_code, List<String>* r_options);
|
||||
|
||||
public:
|
||||
|
||||
virtual void _validate_script();
|
||||
|
||||
|
||||
Ref<Shader> get_edited_shader() const;
|
||||
void set_edited_shader(const Ref<Shader>& p_shader,ShaderLanguage::ShaderType p_type);
|
||||
void set_edited_shader(const Ref<Shader>& p_shader);
|
||||
ShaderTextEditor();
|
||||
|
||||
};
|
||||
|
||||
|
||||
class ShaderEditor : public Control {
|
||||
class ShaderEditor : public VBoxContainer {
|
||||
|
||||
OBJ_TYPE(ShaderEditor, Control );
|
||||
OBJ_TYPE(ShaderEditor, VBoxContainer );
|
||||
|
||||
enum {
|
||||
|
||||
@ -88,22 +89,17 @@ class ShaderEditor : public Control {
|
||||
MenuButton *settings_menu;
|
||||
uint64_t idle;
|
||||
|
||||
TabContainer *tab_container;
|
||||
GotoLineDialog *goto_line_dialog;
|
||||
ConfirmationDialog *erase_tab_confirm;
|
||||
|
||||
TextureButton *close;
|
||||
|
||||
ShaderTextEditor *vertex_editor;
|
||||
ShaderTextEditor *fragment_editor;
|
||||
ShaderTextEditor *light_editor;
|
||||
ShaderTextEditor *shader_editor;
|
||||
|
||||
|
||||
void _tab_changed(int p_which);
|
||||
void _menu_option(int p_optin);
|
||||
void _params_changed();
|
||||
mutable Ref<Shader> shader;
|
||||
|
||||
void _close_callback();
|
||||
|
||||
void _editor_settings_changed();
|
||||
|
||||
@ -134,6 +130,8 @@ class ShaderEditorPlugin : public EditorPlugin {
|
||||
bool _2d;
|
||||
ShaderEditor *shader_editor;
|
||||
EditorNode *editor;
|
||||
Button *button;
|
||||
|
||||
public:
|
||||
|
||||
virtual String get_name() const { return "Shader"; }
|
||||
@ -150,10 +148,9 @@ public:
|
||||
virtual void save_external_data();
|
||||
virtual void apply_changes();
|
||||
|
||||
ShaderEditorPlugin(EditorNode *p_node,bool p_2d);
|
||||
ShaderEditorPlugin(EditorNode *p_node);
|
||||
~ShaderEditorPlugin();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user