2D shader progress
This commit is contained in:
parent
66afddb3e8
commit
f3dc51fc69
10 changed files with 95 additions and 59 deletions
|
@ -4440,6 +4440,13 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
|
|||
if (err) {
|
||||
return; //invalid
|
||||
}
|
||||
} else if (p_shader->mode==VS::SHADER_CANVAS_ITEM) {
|
||||
|
||||
Error err = shader_precompiler.compile(p_shader->vertex_code,ShaderLanguage::SHADER_CANVAS_ITEM_VERTEX,vertex_code,vertex_globals,vertex_flags,&p_shader->uniforms);
|
||||
if (err) {
|
||||
return; //invalid
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//print_line("compiled vertex: "+vertex_code);
|
||||
|
@ -4449,9 +4456,16 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
|
|||
String fragment_code;
|
||||
String fragment_globals;
|
||||
|
||||
Error err = shader_precompiler.compile(p_shader->fragment_code,(p_shader->mode==VS::SHADER_MATERIAL?ShaderLanguage::SHADER_MATERIAL_FRAGMENT:ShaderLanguage::SHADER_POST_PROCESS),fragment_code,fragment_globals,fragment_flags,&p_shader->uniforms);
|
||||
if (err) {
|
||||
return; //invalid
|
||||
if (p_shader->mode==VS::SHADER_MATERIAL) {
|
||||
Error err = shader_precompiler.compile(p_shader->fragment_code,ShaderLanguage::SHADER_MATERIAL_FRAGMENT,fragment_code,fragment_globals,fragment_flags,&p_shader->uniforms);
|
||||
if (err) {
|
||||
return; //invalid
|
||||
}
|
||||
} else if (p_shader->mode==VS::SHADER_CANVAS_ITEM) {
|
||||
Error err = shader_precompiler.compile(p_shader->fragment_code,ShaderLanguage::SHADER_CANVAS_ITEM_FRAGMENT,fragment_code,fragment_globals,fragment_flags,&p_shader->uniforms);
|
||||
if (err) {
|
||||
return; //invalid
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -4464,6 +4478,11 @@ void RasterizerGLES2::_update_shader( Shader* p_shader) const {
|
|||
if (err) {
|
||||
return; //invalid
|
||||
}
|
||||
} else if (p_shader->mode==VS::SHADER_CANVAS_ITEM) {
|
||||
Error err = shader_precompiler.compile(p_shader->light_code,(ShaderLanguage::SHADER_CANVAS_ITEM_LIGHT),light_code,light_globals,light_flags,&p_shader->uniforms);
|
||||
if (err) {
|
||||
return; //invalid
|
||||
}
|
||||
}
|
||||
|
||||
fragment_globals+=light_globals; //both fragment anyway
|
||||
|
@ -8366,9 +8385,12 @@ void RasterizerGLES2::canvas_render_items(CanvasItem *p_item_list) {
|
|||
|
||||
} else {
|
||||
canvas_shader.set_custom_shader(0);
|
||||
canvas_shader.bind();
|
||||
|
||||
}
|
||||
|
||||
canvas_shader.set_uniform(CanvasShaderGLES2::PROJECTION_MATRIX,canvas_transform);
|
||||
last_shader=ci->shader;
|
||||
}
|
||||
|
||||
canvas_shader.set_uniform(CanvasShaderGLES2::MODELVIEW_MATRIX,ci->final_transform);
|
||||
|
|
|
@ -742,7 +742,7 @@ ShaderCompilerGLES2::ShaderCompilerGLES2() {
|
|||
mode_replace_table[4]["POSITION"]="gl_Position";
|
||||
mode_replace_table[4]["NORMAL"]="normal";
|
||||
mode_replace_table[4]["UV"]="uv_interp";
|
||||
mode_replace_table[4]["COLOR"]="color_interp";
|
||||
mode_replace_table[4]["COLOR"]="color";
|
||||
mode_replace_table[4]["TEXTURE"]="texture";
|
||||
mode_replace_table[4]["VAR1"]="var1_interp";
|
||||
mode_replace_table[4]["VAR2"]="var2_interp";
|
||||
|
|
|
@ -2643,6 +2643,28 @@ void ShaderLanguage::get_keyword_list(ShaderType p_type, List<String> *p_keyword
|
|||
idx++;
|
||||
}
|
||||
} break;
|
||||
case SHADER_CANVAS_ITEM_VERTEX: {
|
||||
idx=0;
|
||||
while (ci_vertex_builtins_defs[idx].name) {
|
||||
p_keywords->push_back(ci_vertex_builtins_defs[idx].name);
|
||||
idx++;
|
||||
}
|
||||
} break;
|
||||
case SHADER_CANVAS_ITEM_FRAGMENT: {
|
||||
idx=0;
|
||||
while (ci_fragment_builtins_defs[idx].name) {
|
||||
p_keywords->push_back(ci_fragment_builtins_defs[idx].name);
|
||||
idx++;
|
||||
}
|
||||
} break;
|
||||
case SHADER_CANVAS_ITEM_LIGHT: {
|
||||
idx=0;
|
||||
while (ci_light_builtins_defs[idx].name) {
|
||||
p_keywords->push_back(ci_light_builtins_defs[idx].name);
|
||||
idx++;
|
||||
}
|
||||
} break;
|
||||
|
||||
case SHADER_POST_PROCESS: {
|
||||
idx=0;
|
||||
while (postprocess_fragment_builtins_defs[idx].name) {
|
||||
|
|
|
@ -4036,7 +4036,8 @@ EditorNode::EditorNode() {
|
|||
add_editor_plugin( memnew( EditorHelpPlugin(this) ) );
|
||||
add_editor_plugin( memnew( AnimationPlayerEditorPlugin(this) ) );
|
||||
add_editor_plugin( memnew( ShaderGraphEditorPlugin(this) ) );
|
||||
add_editor_plugin( memnew( ShaderEditorPlugin(this) ) );
|
||||
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) ) );
|
||||
add_editor_plugin( memnew( SampleLibraryEditorPlugin(this) ) );
|
||||
|
|
|
@ -73,6 +73,12 @@ void EditorPlugin::add_custom_control(CustomControlContainer p_location,Control
|
|||
} break;
|
||||
case CONTAINER_CANVAS_EDITOR_SIDE: {
|
||||
|
||||
CanvasItemEditor::get_singleton()->get_palette_split()->add_child(p_control);
|
||||
|
||||
} break;
|
||||
case CONTAINER_CANVAS_EDITOR_BOTTOM: {
|
||||
|
||||
CanvasItemEditor::get_singleton()->get_bottom_split()->add_child(p_control);
|
||||
|
||||
} break;
|
||||
|
||||
|
|
|
@ -66,7 +66,8 @@ public:
|
|||
CONTAINER_SPATIAL_EDITOR_SIDE,
|
||||
CONTAINER_SPATIAL_EDITOR_BOTTOM,
|
||||
CONTAINER_CANVAS_EDITOR_MENU,
|
||||
CONTAINER_CANVAS_EDITOR_SIDE
|
||||
CONTAINER_CANVAS_EDITOR_SIDE,
|
||||
CONTAINER_CANVAS_EDITOR_BOTTOM
|
||||
};
|
||||
|
||||
//TODO: send a resoucre for editing to the editor node?
|
||||
|
|
|
@ -2688,6 +2688,11 @@ HSplitContainer *CanvasItemEditor::get_palette_split() {
|
|||
return palette_split;
|
||||
}
|
||||
|
||||
VSplitContainer *CanvasItemEditor::get_bottom_split() {
|
||||
|
||||
return bottom_split;
|
||||
}
|
||||
|
||||
CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
|
||||
|
||||
tool = TOOL_SELECT;
|
||||
|
@ -2702,9 +2707,13 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
|
|||
add_child( hb );
|
||||
hb->set_area_as_parent_rect();
|
||||
|
||||
bottom_split = memnew( VSplitContainer );
|
||||
bottom_split->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
add_child(bottom_split);
|
||||
|
||||
palette_split = memnew( HSplitContainer);
|
||||
palette_split->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
add_child(palette_split);
|
||||
bottom_split->add_child(palette_split);
|
||||
|
||||
Control *vp_base = memnew (Control);
|
||||
vp_base->set_v_size_flags(SIZE_EXPAND_FILL);
|
||||
|
|
|
@ -290,8 +290,8 @@ class CanvasItemEditor : public VBoxContainer {
|
|||
void _viewport_input_event(const InputEvent& p_event);
|
||||
void _viewport_draw();
|
||||
|
||||
private:
|
||||
HSplitContainer *palette_split;
|
||||
VSplitContainer *bottom_split;
|
||||
|
||||
friend class CanvasItemEditorPlugin;
|
||||
protected:
|
||||
|
@ -346,6 +346,7 @@ public:
|
|||
void add_control_to_menu_panel(Control *p_control);
|
||||
|
||||
HSplitContainer *get_palette_split();
|
||||
VSplitContainer *get_bottom_split();
|
||||
|
||||
Control *get_viewport_control() { return viewport; }
|
||||
|
||||
|
|
|
@ -57,9 +57,9 @@ void ShaderTextEditor::set_edited_shader(const Ref<Shader>& p_shader,ShaderLangu
|
|||
|
||||
_load_theme_settings();
|
||||
|
||||
if (p_type==ShaderLanguage::SHADER_MATERIAL_LIGHT)
|
||||
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)
|
||||
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());
|
||||
|
@ -131,17 +131,12 @@ void ShaderTextEditor::_validate_script() {
|
|||
String errortxt;
|
||||
int line,col;
|
||||
|
||||
String code;
|
||||
if (type==ShaderLanguage::SHADER_MATERIAL_LIGHT)
|
||||
code=get_text_edit()->get_text();
|
||||
else if (type==ShaderLanguage::SHADER_MATERIAL_VERTEX)
|
||||
code=get_text_edit()->get_text();
|
||||
else
|
||||
code=get_text_edit()->get_text();
|
||||
|
||||
String code=get_text_edit()->get_text();
|
||||
//List<StringName> params;
|
||||
//shader->get_param_list(¶ms);
|
||||
|
||||
print_line("compile: type: "+itos(type)+" code:\n"+code);
|
||||
|
||||
Error err = ShaderLanguage::compile(code,type,NULL,NULL,&errortxt,&line,&col);
|
||||
|
||||
if (err!=OK) {
|
||||
|
@ -233,25 +228,7 @@ void ShaderEditor::_menu_option(int p_option) {
|
|||
|
||||
goto_line_dialog->popup_find_line(current->get_text_edit());
|
||||
} break;
|
||||
case SHADER_POST_PROCESS_MODE:{
|
||||
|
||||
fragment_editor->set_edited_shader(shader,ShaderLanguage::SHADER_POST_PROCESS);
|
||||
fragment_editor->_validate_script();
|
||||
apply_shaders();
|
||||
settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_MATERIAL_MODE), false);
|
||||
settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_POST_PROCESS_MODE), true);
|
||||
|
||||
|
||||
} break;
|
||||
case SHADER_MATERIAL_MODE: {
|
||||
|
||||
fragment_editor->set_edited_shader(shader,ShaderLanguage::SHADER_MATERIAL_FRAGMENT);
|
||||
fragment_editor->_validate_script();
|
||||
apply_shaders();
|
||||
settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_MATERIAL_MODE), true);
|
||||
settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_POST_PROCESS_MODE), false);
|
||||
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -408,15 +385,14 @@ 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);
|
||||
settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_MATERIAL_MODE), true);
|
||||
settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_POST_PROCESS_MODE), false);
|
||||
} else {
|
||||
} else if (shader->get_mode()==Shader::MODE_CANVAS_ITEM) {
|
||||
|
||||
fragment_editor->set_edited_shader(p_shader,ShaderLanguage::SHADER_POST_PROCESS);
|
||||
settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_MATERIAL_MODE), false);
|
||||
settings_menu->get_popup()->set_item_checked( settings_menu->get_popup()->get_item_index(SHADER_POST_PROCESS_MODE), true);
|
||||
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);
|
||||
}
|
||||
|
||||
vertex_editor->set_edited_shader(shader,ShaderLanguage::SHADER_MATERIAL_VERTEX);
|
||||
|
@ -495,15 +471,6 @@ ShaderEditor::ShaderEditor() {
|
|||
search_menu->get_popup()->add_item("Goto Line..",SEARCH_GOTO_LINE,KEY_MASK_CMD|KEY_G);
|
||||
search_menu->get_popup()->connect("item_pressed", this,"_menu_option");
|
||||
|
||||
settings_menu = memnew( MenuButton );
|
||||
add_child(settings_menu);
|
||||
settings_menu->set_pos(Point2(90,-1));
|
||||
settings_menu->set_text("Shader");
|
||||
settings_menu->get_popup()->add_check_item("Material Mode",SHADER_MATERIAL_MODE);
|
||||
settings_menu->get_popup()->set_item_checked(settings_menu->get_popup()->get_item_index(SHADER_MATERIAL_MODE),true);
|
||||
settings_menu->get_popup()->add_check_item("Post Process Mode",SHADER_POST_PROCESS_MODE);
|
||||
|
||||
settings_menu->get_popup()->connect("item_pressed", this,"_menu_option");
|
||||
|
||||
tab_container->connect("tab_changed", this,"_tab_changed");
|
||||
|
||||
|
@ -550,7 +517,13 @@ void ShaderEditorPlugin::edit(Object *p_object) {
|
|||
|
||||
bool ShaderEditorPlugin::handles(Object *p_object) const {
|
||||
|
||||
return p_object->is_type("Shader");
|
||||
Shader *shader=p_object->cast_to<Shader>();
|
||||
if (!shader)
|
||||
return false;
|
||||
if (_2d)
|
||||
return shader->get_mode()==Shader::MODE_CANVAS_ITEM;
|
||||
else
|
||||
return shader->get_mode()==Shader::MODE_MATERIAL;
|
||||
}
|
||||
|
||||
void ShaderEditorPlugin::make_visible(bool p_visible) {
|
||||
|
@ -596,12 +569,15 @@ void ShaderEditorPlugin::apply_changes() {
|
|||
shader_editor->apply_shaders();
|
||||
}
|
||||
|
||||
ShaderEditorPlugin::ShaderEditorPlugin(EditorNode *p_node) {
|
||||
ShaderEditorPlugin::ShaderEditorPlugin(EditorNode *p_node, bool p_2d) {
|
||||
|
||||
editor=p_node;
|
||||
shader_editor = memnew( ShaderEditor );
|
||||
|
||||
SpatialEditor::get_singleton()->get_shader_split()->add_child(shader_editor);
|
||||
_2d=p_2d;
|
||||
if (p_2d)
|
||||
add_custom_control(CONTAINER_CANVAS_EDITOR_BOTTOM,shader_editor);
|
||||
else
|
||||
add_custom_control(CONTAINER_SPATIAL_EDITOR_BOTTOM,shader_editor);
|
||||
// editor->get_viewport()->add_child(shader_editor);
|
||||
// shader_editor->set_area_as_parent_rect();
|
||||
|
||||
|
|
|
@ -79,9 +79,6 @@ class ShaderEditor : public Control {
|
|||
SEARCH_REPLACE,
|
||||
//SEARCH_LOCATE_SYMBOL,
|
||||
SEARCH_GOTO_LINE,
|
||||
SHADER_MATERIAL_MODE,
|
||||
SHADER_POST_PROCESS_MODE,
|
||||
SHADER_SHADE_MODEL_MODE,
|
||||
|
||||
};
|
||||
|
||||
|
@ -134,6 +131,7 @@ class ShaderEditorPlugin : public EditorPlugin {
|
|||
|
||||
OBJ_TYPE( ShaderEditorPlugin, EditorPlugin );
|
||||
|
||||
bool _2d;
|
||||
ShaderEditor *shader_editor;
|
||||
EditorNode *editor;
|
||||
public:
|
||||
|
@ -152,7 +150,7 @@ public:
|
|||
virtual void save_external_data();
|
||||
virtual void apply_changes();
|
||||
|
||||
ShaderEditorPlugin(EditorNode *p_node);
|
||||
ShaderEditorPlugin(EditorNode *p_node,bool p_2d);
|
||||
~ShaderEditorPlugin();
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue