This commit is contained in:
Carl Olsson 2015-02-02 21:34:47 +10:00
commit ee44664b2a
20 changed files with 369 additions and 42 deletions

View file

@ -62,6 +62,8 @@ void Input::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_mouse_mode","mode"),&Input::set_mouse_mode);
ObjectTypeDB::bind_method(_MD("get_mouse_mode"),&Input::get_mouse_mode);
ObjectTypeDB::bind_method(_MD("warp_mouse_pos","to"),&Input::warp_mouse_pos);
ObjectTypeDB::bind_method(_MD("action_press"),&Input::action_press);
ObjectTypeDB::bind_method(_MD("action_release"),&Input::action_release);
BIND_CONSTANT( MOUSE_MODE_VISIBLE );
BIND_CONSTANT( MOUSE_MODE_HIDDEN );

View file

@ -1687,6 +1687,19 @@ void Variant::set(const Variant& p_index, const Variant& p_value, bool *r_valid)
return;
}
}
if (ie.type == InputEvent::ACTION) {
if (str =="action") {
valid=true;
ie.action.action=p_value;
return;
}
else if (str == "pressed") {
valid=true;
ie.action.pressed=p_value;
return;
}
}
} break;
case DICTIONARY: {
@ -2365,6 +2378,17 @@ Variant Variant::get(const Variant& p_index, bool *r_valid) const {
return Vector2(ie.screen_drag.speed_x,ie.screen_drag.speed_y);
}
}
if (ie.type == InputEvent::ACTION) {
if (str =="action") {
valid=true;
return ie.action.action;
}
else if (str == "pressed") {
valid=true;
ie.action.pressed;
}
}
} break;
case DICTIONARY: {

View file

@ -4588,6 +4588,9 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
enablers.push_back("#define USE_TEXPIXEL_SIZE\n");
}
if (vertex_flags.uses_worldvec) {
enablers.push_back("#define USE_WORLD_VEC\n");
}
canvas_shader.set_custom_shader_code(p_shader->custom_code_id,vertex_code, vertex_globals,fragment_code, light_code, fragment_globals,uniform_names,enablers);
//postprocess_shader.set_custom_shader_code(p_shader->custom_code_id,vertex_code, vertex_globals,fragment_code, fragment_globals,uniform_names);
@ -4954,12 +4957,26 @@ _FORCE_INLINE_ void RasterizerGLES2::_update_material_shader_params(Material *p_
Material::UniformData ud;
bool keep=true; //keep material value
bool has_old = old_mparams.has(E->key());
Map<StringName,Material::UniformData>::Element *OLD=old_mparams.find(E->key());
bool has_old = OLD;
bool old_inuse=has_old && old_mparams[E->key()].inuse;
if (!has_old || !old_inuse)
ud.istexture=(E->get().type==ShaderLanguage::TYPE_TEXTURE || E->get().type==ShaderLanguage::TYPE_CUBEMAP);
if (!has_old || !old_inuse) {
keep=false;
else if (old_mparams[E->key()].value.get_type()!=E->value().default_value.get_type()) {
}
else if (OLD->get().value.get_type()!=E->value().default_value.get_type()) {
if (OLD->get().value.get_type()==Variant::INT && E->get().type==ShaderLanguage::TYPE_FLOAT) {
//handle common mistake using shaders (feeding ints instead of float)
OLD->get().value=float(OLD->get().value);
keep=true;
} else if (!ud.istexture && E->value().default_value.get_type()!=Variant::NIL) {
keep=false;
}
//type changed between old and new
/* if (old_mparams[E->key()].value.get_type()==Variant::OBJECT) {
if (E->value().default_value.get_type()!=Variant::_RID) //hackfor textures
@ -4968,11 +4985,9 @@ _FORCE_INLINE_ void RasterizerGLES2::_update_material_shader_params(Material *p_
keep=false;*/
//value is invalid because type differs and default is not null
if (E->value().default_value.get_type()!=Variant::NIL)
keep=false;
;
}
ud.istexture=(E->get().type==ShaderLanguage::TYPE_TEXTURE || E->get().type==ShaderLanguage::TYPE_CUBEMAP);
if (keep) {
ud.value=old_mparams[E->key()].value;
@ -5096,8 +5111,10 @@ bool RasterizerGLES2::_setup_material(const Geometry *p_geometry,const Material
int texcoord=0;
for (Map<StringName,Material::UniformData>::Element *E=p_material->shader_params.front();E;E=E->next()) {
if (E->get().index<0)
continue;
// print_line(String(E->key())+": "+E->get().value);
if (E->get().istexture) {
//clearly a texture..
RID rid = E->get().value;
@ -8365,24 +8382,39 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list) {
int idx=0;
for(Map<StringName,ShaderLanguage::Uniform>::Element *E=shader->uniforms.front();E;E=E->next()) {
Map<StringName,Variant>::Element *F=shader_owner->shader_param.find(E->key());
Variant &v=F?F->get():E->get().default_value;
if (v.get_type()==Variant::_RID || v.get_type()==Variant::OBJECT) {
int loc = canvas_shader.get_custom_uniform_location(idx); //should be automatic..
glActiveTexture(GL_TEXTURE0+tex_id);
RID tex = v;
Texture *t=texture_owner.get(tex);
if (!t)
glBindTexture(GL_TEXTURE_2D,white_tex);
else
glBindTexture(t->target,t->tex_id);
if ((E->get().type==ShaderLanguage::TYPE_TEXTURE || E->get().type==ShaderLanguage::TYPE_CUBEMAP)) {
glUniform1i(loc,tex_id);
tex_id++;
RID rid;
if (F) {
rid=F->get();
}
if (!rid.is_valid()) {
Map<StringName,RID>::Element *DT=shader->default_textures.find(E->key());
if (DT) {
rid=DT->get();
}
}
if (rid.is_valid()) {
int loc = canvas_shader.get_custom_uniform_location(idx); //should be automatic..
glActiveTexture(GL_TEXTURE0+tex_id);
Texture *t=texture_owner.get(rid);
if (!t)
glBindTexture(GL_TEXTURE_2D,white_tex);
else
glBindTexture(t->target,t->tex_id);
glUniform1i(loc,tex_id);
tex_id++;
}
} else {
Variant &v=F?F->get():E->get().default_value;
canvas_shader.set_custom_uniform(idx,v);
}
@ -8406,7 +8438,7 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list) {
#endif
glCopyTexSubImage2D(GL_TEXTURE_2D,0,x,y,x,y,viewport.width,viewport.height);
if (current_clip) {
print_line(" a clip ");
// print_line(" a clip ");
}
canvas_texscreen_used=true;

View file

@ -226,6 +226,9 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
if (vnode->name==vname_var2_interp) {
flags->use_var2_interp=true;
}
if (vnode->name==vname_world_vec) {
uses_worldvec=true;
}
}
@ -307,13 +310,13 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
String mul_l=dump_node_code(onode->arguments[0],p_level,true);
String mul_r=dump_node_code(onode->arguments[1],p_level);
code=mul_l+"=(vec4("+mul_l+",1.0,1.0)*("+mul_r+")).xy";
code=mul_l+"=(vec4("+mul_l+",0.0,1.0)*("+mul_r+")).xy";
break;
} else if (onode->arguments[0]->get_datatype()==SL::TYPE_MAT4 && onode->arguments[1]->get_datatype()==SL::TYPE_VEC2) {
String mul_l=dump_node_code(onode->arguments[0],p_level,true);
String mul_r=dump_node_code(onode->arguments[1],p_level);
code=mul_l+"=(("+mul_l+")*vec4("+mul_r+",1.0,1.0)).xy";
code=mul_l+"=(("+mul_l+")*vec4("+mul_r+",0.0,1.0)).xy";
break;
} else if (onode->arguments[0]->get_datatype()==SL::TYPE_VEC2 && onode->arguments[1]->get_datatype()==SL::TYPE_MAT3) {
String mul_l=dump_node_code(onode->arguments[0],p_level,true);
@ -343,11 +346,11 @@ String ShaderCompilerGLES2::dump_node_code(SL::Node *p_node,int p_level,bool p_a
break;
} else if (onode->arguments[0]->get_datatype()==SL::TYPE_MAT4 && onode->arguments[1]->get_datatype()==SL::TYPE_VEC2) {
code="("+dump_node_code(onode->arguments[0],p_level)+"*vec4("+dump_node_code(onode->arguments[1],p_level)+",1.0,1.0)).xyz";
code="("+dump_node_code(onode->arguments[0],p_level)+"*vec4("+dump_node_code(onode->arguments[1],p_level)+",0.0,1.0)).xy";
break;
} else if (onode->arguments[0]->get_datatype()==SL::TYPE_VEC2 && onode->arguments[1]->get_datatype()==SL::TYPE_MAT4) {
code="(vec4("+dump_node_code(onode->arguments[0],p_level)+",1.0,1.0)*"+dump_node_code(onode->arguments[1],p_level)+").xyz";
code="(vec4("+dump_node_code(onode->arguments[0],p_level)+",0.0,1.0)*"+dump_node_code(onode->arguments[1],p_level)+").xy";
break;
} else if (onode->arguments[0]->get_datatype()==SL::TYPE_MAT3 && onode->arguments[1]->get_datatype()==SL::TYPE_VEC2) {
@ -599,6 +602,7 @@ Error ShaderCompilerGLES2::compile(const String& p_code, ShaderLanguage::ShaderT
uses_normalmap=false;
uses_normal=false;
uses_texpixel_size=false;
uses_worldvec=false;
vertex_code_writes_vertex=false;
uniforms=r_uniforms;
flags=&r_flags;
@ -634,6 +638,7 @@ Error ShaderCompilerGLES2::compile(const String& p_code, ShaderLanguage::ShaderT
r_flags.uses_normalmap=uses_normalmap;
r_flags.uses_normal=uses_normalmap;
r_flags.uses_texpixel_size=uses_texpixel_size;
r_flags.uses_worldvec=uses_worldvec;
r_code_line=code;
r_globals_line=global_code;
@ -774,6 +779,7 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
mode_replace_table[3]["SRC_VERTEX"]="src_vtx";
mode_replace_table[3]["VERTEX"]="outvec.xy";
mode_replace_table[3]["WORLD_VERTEX"]="outvec.xy";
mode_replace_table[3]["UV"]="uv_interp";
mode_replace_table[3]["COLOR"]="color_interp";
mode_replace_table[3]["VAR1"]="var1_interp";
@ -830,5 +836,6 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
vname_normalmap="NORMALMAP";
vname_normal="NORMAL";
vname_texpixel_size="TEXTURE_PIXEL_SIZE";
vname_world_vec="WORLD_VERTEX";
}

View file

@ -53,6 +53,7 @@ private:
bool uses_normalmap;
bool uses_normal;
bool uses_texpixel_size;
bool uses_worldvec;
bool vertex_code_writes_vertex;
Flags *flags;
@ -72,6 +73,7 @@ private:
StringName vname_normalmap;
StringName vname_normal;
StringName vname_texpixel_size;
StringName vname_world_vec;
Map<StringName,ShaderLanguage::Uniform> *uniforms;
@ -107,6 +109,7 @@ public:
bool uses_time;
bool uses_normal;
bool uses_texpixel_size;
bool uses_worldvec;
};
Error compile(const String& p_code, ShaderLanguage::ShaderType p_type, String& r_code_line, String& r_globals_line, Flags& r_flags, Map<StringName,ShaderLanguage::Uniform> *r_uniforms=NULL);

View file

@ -52,8 +52,10 @@ void main() {
VERTEX_SHADER_CODE
}
#if !defined(USE_WORLD_VEC)
outvec = extra_matrix * outvec;
outvec = modelview_matrix * outvec;
#endif
#ifdef USE_PIXEL_SNAP
@ -61,15 +63,15 @@ VERTEX_SHADER_CODE
#endif
gl_Position = projection_matrix * outvec;
#ifdef USE_LIGHTING
light_tex_pos.xy = light_matrix * outvec;
light_tex_pos.xy = light_matrix * gl_Position;
light_tex_pos.zw=outvec.xy - light_matrix[4].xy; //likely wrong
#endif
gl_Position = projection_matrix * outvec;
}
[fragment]

View file

@ -969,7 +969,7 @@ CanvasItem::CanvasItem() : xform_change(this) {
block_transform_notify=false;
// viewport=NULL;
canvas_layer=NULL;
use_parent_shader;
use_parent_shader=false;
global_invalid=true;
C=NULL;

View file

@ -2472,6 +2472,10 @@ void Tree::_notification(int p_what) {
}
}
if (p_what==NOTIFICATION_THEME_CHANGED) {
update_cache();
}
}

View file

@ -499,6 +499,7 @@ void register_scene_types() {
ObjectTypeDB::register_virtual_type<Shader>();
ObjectTypeDB::register_virtual_type<ShaderGraph>();
ObjectTypeDB::register_type<CanvasItemShader>();
ObjectTypeDB::register_type<CanvasItemShaderGraph>();
#ifndef _3D_DISABLED
ObjectTypeDB::register_type<Mesh>();

View file

@ -1289,7 +1289,7 @@ const ShaderGraph::InOutParamInfo ShaderGraph::inout_param_info[]={
{MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Binormal","BINORMAL","",SLOT_TYPE_VEC,SLOT_IN},
{MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"UV","vec3(UV,0);","",SLOT_TYPE_VEC,SLOT_IN},
{MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"UV2","UV2","",SLOT_TYPE_VEC,SLOT_IN},
{MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"UVScreen","SCREEN_UV","",SLOT_TYPE_VEC,SLOT_IN},
{MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"UVScreen","vec3(SCREEN_UV,0)","",SLOT_TYPE_VEC,SLOT_IN},
{MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"PointCoord","POINT_COORD","",SLOT_TYPE_VEC,SLOT_IN},
{MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Color","COLOR.rgb","",SLOT_TYPE_VEC,SLOT_IN},
{MODE_MATERIAL,SHADER_TYPE_FRAGMENT,"Alpha","COLOR.a","",SLOT_TYPE_SCALAR,SLOT_IN},
@ -1320,6 +1320,43 @@ const ShaderGraph::InOutParamInfo ShaderGraph::inout_param_info[]={
{MODE_MATERIAL,SHADER_TYPE_LIGHT,"ShadeParam","SHADE_PARAM","",SLOT_TYPE_SCALAR,SLOT_IN},
//light out
{MODE_MATERIAL,SHADER_TYPE_LIGHT,"Light","LIGHT","",SLOT_TYPE_VEC,SLOT_OUT},
//canvas item vertex in
{MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Vertex","vec3(SRC_VERTEX,0)","",SLOT_TYPE_VEC,SLOT_IN},
{MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"UV","SRC_UV","",SLOT_TYPE_VEC,SLOT_IN},
{MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Color","SRC_COLOR.rgb","",SLOT_TYPE_VEC,SLOT_IN},
{MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Alpha","SRC_COLOR.a","",SLOT_TYPE_SCALAR,SLOT_IN},
{MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"WorldMatrix","WORLD_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN},
{MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"ExtraMatrix","EXTRA_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN},
{MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"ProjectionMatrix","PROJECTION_MATRIX","",SLOT_TYPE_XFORM,SLOT_IN},
//canvas item vertex out
{MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Vertex","VERTEX",".xy",SLOT_TYPE_VEC,SLOT_OUT},
{MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"UV","UV",".xy",SLOT_TYPE_VEC,SLOT_OUT},
{MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Color","COLOR.rgb","",SLOT_TYPE_VEC,SLOT_OUT},
{MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Alpha","COLOR.a","",SLOT_TYPE_SCALAR,SLOT_OUT},
{MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Var1","VAR1.rgb","",SLOT_TYPE_VEC,SLOT_OUT},
{MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"Var2","VAR2.rgb","",SLOT_TYPE_VEC,SLOT_OUT},
{MODE_CANVAS_ITEM,SHADER_TYPE_VERTEX,"PointSize","POINT_SIZE","",SLOT_TYPE_SCALAR,SLOT_OUT},
//canvas item fragment in
{MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Color","SRC_COLOR.rgb","",SLOT_TYPE_VEC,SLOT_IN},
{MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Alpha","SRC_COLOR.a","",SLOT_TYPE_SCALAR,SLOT_IN},
{MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"UV","vec3(UV,0)","",SLOT_TYPE_VEC,SLOT_IN},
{MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"UVScreen","vec3(SCREEN_UV,0)","",SLOT_TYPE_VEC,SLOT_IN},
{MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"TexPixelSize","vec3(TEXTURE_PIXEL_SIZE,0)","",SLOT_TYPE_VEC,SLOT_IN},
{MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Var1","VAR1.rgb","",SLOT_TYPE_VEC,SLOT_IN},
{MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Var2","VAR2.rgb","",SLOT_TYPE_VEC,SLOT_IN},
{MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"PointCoord","POINT_COORD","",SLOT_TYPE_VEC,SLOT_IN},
//canvas item fragment out
{MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Color","COLOR.rgb","",SLOT_TYPE_VEC,SLOT_OUT},
{MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Alpha","COLOR.a","",SLOT_TYPE_SCALAR,SLOT_OUT},
{MODE_CANVAS_ITEM,SHADER_TYPE_FRAGMENT,"Normal","NORMAL","",SLOT_TYPE_VEC,SLOT_OUT},
//canvas item light in
{MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Color","COLOR.rgb","",SLOT_TYPE_VEC,SLOT_IN},
{MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Normal","NORMAL","",SLOT_TYPE_VEC,SLOT_IN},
{MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightDist","LIGHT_DISTANCE","",SLOT_TYPE_SCALAR,SLOT_IN},
{MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"LightDir","vec3(LIGHT_DIR,0)","",SLOT_TYPE_VEC,SLOT_IN},
{MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"PointCoord","POINT_COORD","",SLOT_TYPE_VEC,SLOT_IN},
//canvas item light out
{MODE_CANVAS_ITEM,SHADER_TYPE_LIGHT,"Light","LIGHT","",SLOT_TYPE_VEC,SLOT_OUT},
//end
{MODE_MATERIAL,SHADER_TYPE_FRAGMENT,NULL,NULL,NULL,SLOT_TYPE_SCALAR,SLOT_OUT},
@ -1373,6 +1410,7 @@ const ShaderGraph::NodeSlotInfo ShaderGraph::node_slot_info[]= {
{NODE_XFORM_INPUT,{SLOT_MAX},{SLOT_TYPE_XFORM,SLOT_MAX}}, // mat4 uniform (assignable in material)
{NODE_TEXTURE_INPUT,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX}}, // texture input (assignable in material)
{NODE_CUBEMAP_INPUT,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX}}, // cubemap input (assignable in material)
{NODE_DEFAULT_TEXTURE,{SLOT_TYPE_VEC,SLOT_MAX},{SLOT_TYPE_VEC,SLOT_TYPE_SCALAR,SLOT_MAX}}, // cubemap input (assignable in material)
{NODE_COMMENT,{SLOT_MAX},{SLOT_MAX}}, // comment
{NODE_TYPE_MAX,{SLOT_MAX},{SLOT_MAX}}
};
@ -1731,6 +1769,11 @@ void ShaderGraph::_update_shader() {
} else if (i==SHADER_TYPE_FRAGMENT && get_mode()==MODE_MATERIAL) {
if (name==("IN_NORMAL"))
code[i]="vec3 IN_NORMAL=NORMAL;\n"+code[i];
} else if (i==SHADER_TYPE_VERTEX && get_mode()==MODE_CANVAS_ITEM) {
if (name==("SRC_COLOR"))
code[i]="vec3 SRC_COLOR=COLOR.rgb;\n"+code[i];
if (name==("SRC_UV"))
code[i]="vec3 SRC_UV=vec3(UV,0);\n"+code[i];
}
}
@ -1747,6 +1790,10 @@ void ShaderGraph::_update_shader() {
all_ok=false;
}
/*print_line("VERTEX: \n"+code[0]);
print_line("FRAGMENT: \n"+code[1]);
print_line("LIGHT: \n"+code[2]);*/
if (all_ok) {
set_code(code[0],code[1],code[2]);
}
@ -1926,7 +1973,7 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vector<Str
code+=OUTNAME(p_node->id,0)+"=TIME;\n";
}break;
case NODE_SCREEN_TEX: {
code+=OUTNAME(p_node->id,0)+"=texscreen("+p_inputs[0]+");\n";
code+=OUTNAME(p_node->id,0)+"=texscreen("+p_inputs[0]+".xy);\n";
}break;
case NODE_SCALAR_OP: {
int op = p_node->param1;
@ -2372,7 +2419,7 @@ void ShaderGraph::_add_node_code(ShaderType p_type,Node *p_node,const Vector<Str
code += OUTNAME(p_node->id,1)+"="+rname+".a;\n";
} else {
//not supported
code += OUTNAME(p_node->id,0)+"=vec3(0,0,0);\n";
code += OUTNAME(p_node->id,1)+"=1.0;\n";

View file

@ -406,7 +406,6 @@ VARIANT_ENUM_CAST( ShaderGraph::GraphError );
class MaterialShaderGraph : public ShaderGraph {
OBJ_TYPE( MaterialShaderGraph, ShaderGraph );
RES_BASE_EXTENSION("sgp");
public:
@ -416,4 +415,17 @@ public:
}
};
class CanvasItemShaderGraph : public ShaderGraph {
OBJ_TYPE( CanvasItemShaderGraph, ShaderGraph );
public:
CanvasItemShaderGraph() : ShaderGraph(MODE_CANVAS_ITEM) {
}
};
#endif // SHADER_GRAPH_H

View file

@ -1112,6 +1112,7 @@ const ShaderLanguage::BuiltinsDef ShaderLanguage::ci_vertex_builtins_defs[]={
{ "SRC_VERTEX", TYPE_VEC2},
{ "VERTEX", TYPE_VEC2},
{ "WORLD_VERTEX", TYPE_VEC2},
{ "UV", TYPE_VEC2},
{ "COLOR", TYPE_VEC4},
{ "VAR1", TYPE_VEC4},

View file

@ -3828,6 +3828,91 @@ void VisualServerRaster::canvas_item_raise(RID p_item) {
}
/***** CANVAS LIGHT *******/
RID VisualServerRaster::canvas_light_create() {
return RID();
}
void VisualServerRaster::canvas_light_attach_to_canvas(RID p_light,RID p_canvas){
}
void VisualServerRaster::canvas_light_set_enabled(RID p_light, bool p_enabled){
}
void VisualServerRaster::canvas_light_set_transform(RID p_light, const Matrix32& p_transform){
}
void VisualServerRaster::canvas_light_set_texture(RID p_light, RID p_texture){
}
void VisualServerRaster::canvas_light_set_texture_offset(RID p_light, const Vector2& p_offset){
}
void VisualServerRaster::canvas_light_set_color(RID p_light, const Color& p_color){
}
void VisualServerRaster::canvas_light_set_height(RID p_light, float p_height){
}
void VisualServerRaster::canvas_light_set_z_range(RID p_light, int p_min_z,int p_max_z){
}
void VisualServerRaster::canvas_light_set_item_mask(RID p_light, int p_mask){
}
void VisualServerRaster::canvas_light_set_blend_mode(RID p_light, CanvasLightBlendMode p_blend_mode){
}
void VisualServerRaster::canvas_light_set_shadow_enabled(RID p_light, bool p_enabled){
}
void VisualServerRaster::canvas_light_set_shadow_buffer_size(RID p_light, int p_size){
}
void VisualServerRaster::canvas_light_set_shadow_filter(RID p_light, int p_size){
}
/****** CANVAS LIGHT OCCLUDER ******/
RID VisualServerRaster::canvas_light_occluder_create() {
return RID();
}
void VisualServerRaster::canvas_light_occluder_attach_to_canvas(RID p_occluder,RID p_canvas) {
}
void VisualServerRaster::canvas_light_occluder_set_enabled(RID p_occluder,bool p_enabled){
}
void VisualServerRaster::canvas_light_occluder_set_shape(RID p_occluder,const DVector<Vector2>& p_shape){
}
/******** CANVAS *********/

View file

@ -1122,9 +1122,43 @@ public:
virtual void canvas_item_set_use_parent_shader(RID p_item, bool p_enable);
virtual void canvas_item_set_shader_param(RID p_canvas_item, const StringName& p_param, const Variant& p_value);
virtual Variant canvas_item_get_shader_param(RID p_canvas_item, const StringName& p_param) const;
virtual RID canvas_light_create();
virtual void canvas_light_attach_to_canvas(RID p_light,RID p_canvas);
virtual void canvas_light_set_enabled(RID p_light, bool p_enabled);
virtual void canvas_light_set_transform(RID p_light, const Matrix32& p_transform);
virtual void canvas_light_set_texture(RID p_light, RID p_texture);
virtual void canvas_light_set_texture_offset(RID p_light, const Vector2& p_offset);
virtual void canvas_light_set_color(RID p_light, const Color& p_color);
virtual void canvas_light_set_height(RID p_light, float p_height);
virtual void canvas_light_set_z_range(RID p_light, int p_min_z,int p_max_z);
virtual void canvas_light_set_item_mask(RID p_light, int p_mask);
enum CanvasightBlendMode {
CANVAS_LIGHT_BLEND_ADD,
CANVAS_LIGHT_BLEND_SUB,
CANVAS_LIGHT_BLEND_MULTIPLY,
CANVAS_LIGHT_BLEND_DODGE,
CANVAS_LIGHT_BLEND_BURN,
CANVAS_LIGHT_BLEND_LIGHTEN,
CANVAS_LIGHT_BLEND_DARKEN,
CANVAS_LIGHT_BLEND_OVERLAY,
CANVAS_LIGHT_BLEND_SCREEN,
};
virtual void canvas_light_set_blend_mode(RID p_light, CanvasLightBlendMode p_blend_mode);
virtual void canvas_light_set_shadow_enabled(RID p_light, bool p_enabled);
virtual void canvas_light_set_shadow_buffer_size(RID p_light, int p_size);
virtual void canvas_light_set_shadow_filter(RID p_light, int p_size);
virtual RID canvas_light_occluder_create();
virtual void canvas_light_occluder_attach_to_canvas(RID p_occluder,RID p_canvas);
virtual void canvas_light_occluder_set_enabled(RID p_occluder,bool p_enabled);
virtual void canvas_light_occluder_set_shape(RID p_occluder,const DVector<Vector2>& p_shape);
virtual void canvas_item_clear(RID p_item);
virtual void canvas_item_raise(RID p_item);

View file

@ -1145,6 +1145,29 @@ public:
FUNC1(canvas_item_clear,RID);
FUNC1(canvas_item_raise,RID);
/* CANVAS LIGHT */
FUNC0R(RID,canvas_light_create);
FUNC2(canvas_light_attach_to_canvas,RID,RID);
FUNC2(canvas_light_set_enabled,RID,bool);
FUNC2(canvas_light_set_transform,RID,const Matrix32&);
FUNC2(canvas_light_set_texture,RID,RID);
FUNC2(canvas_light_set_texture_offset,RID,const Vector2&);
FUNC2(canvas_light_set_color,RID,const Color&);
FUNC2(canvas_light_set_height,RID,float);
FUNC3(canvas_light_set_z_range,RID,int,int);
FUNC2(canvas_light_set_item_mask,RID,int);
FUNC2(canvas_light_set_blend_mode,RID,CanvasLightBlendMode);
FUNC2(canvas_light_set_shadow_enabled,RID,bool);
FUNC2(canvas_light_set_shadow_buffer_size,RID,int);
FUNC2(canvas_light_set_shadow_filter,RID,int);
/* CANVAS OCCLUDER */
FUNC0R(RID,canvas_light_occluder_create);
FUNC2(canvas_light_occluder_attach_to_canvas,RID,RID);
FUNC2(canvas_light_occluder_set_enabled,RID,bool);
FUNC2(canvas_light_occluder_set_shape,RID,const DVector<Vector2>&);
/* CURSOR */
FUNC2(cursor_set_rotation,float , int ); // radians

View file

@ -999,6 +999,39 @@ public:
virtual void canvas_item_set_shader_param(RID p_canvas_item, const StringName& p_param, const Variant& p_value)=0;
virtual Variant canvas_item_get_shader_param(RID p_canvas_item, const StringName& p_param) const=0;
virtual RID canvas_light_create()=0;
virtual void canvas_light_attach_to_canvas(RID p_light,RID p_canvas)=0;
virtual void canvas_light_set_enabled(RID p_light, bool p_enabled)=0;
virtual void canvas_light_set_transform(RID p_light, const Matrix32& p_transform)=0;
virtual void canvas_light_set_texture(RID p_light, RID p_texture)=0;
virtual void canvas_light_set_texture_offset(RID p_light, const Vector2& p_offset)=0;
virtual void canvas_light_set_color(RID p_light, const Color& p_color)=0;
virtual void canvas_light_set_height(RID p_light, float p_height)=0;
virtual void canvas_light_set_z_range(RID p_light, int p_min_z,int p_max_z)=0;
virtual void canvas_light_set_item_mask(RID p_light, int p_mask)=0;
enum CanvasLightBlendMode {
CANVAS_LIGHT_BLEND_ADD,
CANVAS_LIGHT_BLEND_SUB,
CANVAS_LIGHT_BLEND_MULTIPLY,
CANVAS_LIGHT_BLEND_DODGE,
CANVAS_LIGHT_BLEND_BURN,
CANVAS_LIGHT_BLEND_LIGHTEN,
CANVAS_LIGHT_BLEND_DARKEN,
CANVAS_LIGHT_BLEND_OVERLAY,
CANVAS_LIGHT_BLEND_SCREEN,
};
virtual void canvas_light_set_blend_mode(RID p_light, CanvasLightBlendMode p_blend_mode)=0;
virtual void canvas_light_set_shadow_enabled(RID p_light, bool p_enabled)=0;
virtual void canvas_light_set_shadow_buffer_size(RID p_light, int p_size)=0;
virtual void canvas_light_set_shadow_filter(RID p_light, int p_size)=0;
virtual RID canvas_light_occluder_create()=0;
virtual void canvas_light_occluder_attach_to_canvas(RID p_occluder,RID p_canvas)=0;
virtual void canvas_light_occluder_set_enabled(RID p_occluder,bool p_enabled)=0;
virtual void canvas_light_occluder_set_shape(RID p_occluder,const DVector<Vector2>& p_shape)=0;
/* CURSOR */
virtual void cursor_set_rotation(float p_rotation, int p_cursor = 0)=0; // radians
virtual void cursor_set_texture(RID p_texture, const Point2 &p_center_offset = Point2(0, 0), int p_cursor=0)=0;

View file

@ -4035,7 +4035,8 @@ EditorNode::EditorNode() {
add_editor_plugin( memnew( ScriptEditorPlugin(this) ) );
add_editor_plugin( memnew( EditorHelpPlugin(this) ) );
add_editor_plugin( memnew( AnimationPlayerEditorPlugin(this) ) );
add_editor_plugin( memnew( ShaderGraphEditorPlugin(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) ) );

View file

@ -396,7 +396,7 @@ void ShaderEditor::edit(const Ref<Shader>& p_shader) {
light_editor->set_edited_shader(shader,ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT);
}
vertex_editor->set_edited_shader(shader,ShaderLanguage::SHADER_MATERIAL_VERTEX);
//vertex_editor->set_edited_shader(shader,ShaderLanguage::SHADER_MATERIAL_VERTEX);
// see if already has it

View file

@ -33,7 +33,7 @@
#include "scene/gui/panel.h"
#include "spatial_editor_plugin.h"
#include "os/keyboard.h"
#include "canvas_item_editor_plugin.h"
void GraphColorRampEdit::_input_event(const InputEvent& p_event) {
@ -2234,6 +2234,9 @@ void ShaderGraphEditor::_notification(int p_what) {
if (i==ShaderGraph::NODE_OUTPUT)
continue;
if (!_2d && i==ShaderGraph::NODE_DEFAULT_TEXTURE)
continue;
String nn = node_names[i];
String ic = nn.get_slice(":",0);
String v = nn.get_slice(":",1);
@ -2297,7 +2300,8 @@ const char* ShaderGraphEditor::node_names[ShaderGraph::NODE_TYPE_MAX]={
};
ShaderGraphEditor::ShaderGraphEditor() {
ShaderGraphEditor::ShaderGraphEditor(bool p_2d) {
_2d=p_2d;
HBoxContainer *hbc = memnew( HBoxContainer );
menu = memnew( MenuButton );
@ -2339,7 +2343,13 @@ void ShaderGraphEditorPlugin::edit(Object *p_object) {
bool ShaderGraphEditorPlugin::handles(Object *p_object) const {
return p_object->is_type("ShaderGraph");
ShaderGraph *shader=p_object->cast_to<ShaderGraph>();
if (!shader)
return false;
if (_2d)
return shader->get_mode()==Shader::MODE_CANVAS_ITEM;
else
return shader->get_mode()==Shader::MODE_MATERIAL;
}
void ShaderGraphEditorPlugin::make_visible(bool p_visible) {
@ -2353,12 +2363,16 @@ void ShaderGraphEditorPlugin::make_visible(bool p_visible) {
}
ShaderGraphEditorPlugin::ShaderGraphEditorPlugin(EditorNode *p_node) {
ShaderGraphEditorPlugin::ShaderGraphEditorPlugin(EditorNode *p_node, bool p_2d) {
_2d=p_2d;
editor=p_node;
shader_editor = memnew( ShaderGraphEditor );
shader_editor = memnew( ShaderGraphEditor(p_2d) );
shader_editor->hide();
SpatialEditor::get_singleton()->get_shader_split()->add_child(shader_editor);
if (p_2d)
CanvasItemEditor::get_singleton()->get_bottom_split()->add_child(shader_editor);
else
SpatialEditor::get_singleton()->get_shader_split()->add_child(shader_editor);
// editor->get_viewport()->add_child(shader_editor);

View file

@ -191,6 +191,7 @@ class ShaderGraphEditor : public VBoxContainer {
ShaderGraphView *graph_edits[ShaderGraph::SHADER_TYPE_MAX];
static const char* node_names[ShaderGraph::NODE_TYPE_MAX];
bool _2d;
void _add_node(int p_type);
protected:
void _notification(int p_what);
@ -198,13 +199,14 @@ protected:
public:
void edit(Ref<ShaderGraph> p_shader);
ShaderGraphEditor();
ShaderGraphEditor(bool p_2d);
};
class ShaderGraphEditorPlugin : public EditorPlugin {
OBJ_TYPE( ShaderGraphEditorPlugin, EditorPlugin );
bool _2d;
ShaderGraphEditor *shader_editor;
EditorNode *editor;
@ -216,7 +218,7 @@ public:
virtual bool handles(Object *p_node) const;
virtual void make_visible(bool p_visible);
ShaderGraphEditorPlugin(EditorNode *p_node);
ShaderGraphEditorPlugin(EditorNode *p_node,bool p_2d);
~ShaderGraphEditorPlugin();
};