Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored 2D shader and lighting system #43052

Merged
merged 1 commit into from
Oct 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions drivers/vulkan/rendering_device_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3258,7 +3258,7 @@ VkRenderPass RenderingDeviceVulkan::_render_pass_create(const Vector<AttachmentF
render_pass_create_info.pAttachments = attachments.ptr();
render_pass_create_info.subpassCount = 1;
render_pass_create_info.pSubpasses = &subpass;
render_pass_create_info.dependencyCount = 2;
render_pass_create_info.dependencyCount = 0; //2 - throws validation layer error
render_pass_create_info.pDependencies = dependencies;

VkRenderPass render_pass;
Expand Down Expand Up @@ -4610,12 +4610,12 @@ RID RenderingDeviceVulkan::uniform_set_create(const Vector<Uniform> &p_uniforms,
}
}
ERR_FAIL_COND_V_MSG(uniform_idx == -1, RID(),
"All the shader bindings for the given set must be covered by the uniforms provided. Binding (" + itos(set_uniform.binding) + ") was not provided.");
"All the shader bindings for the given set must be covered by the uniforms provided. Binding (" + itos(set_uniform.binding) + "), set (" + itos(p_shader_set) + ") was not provided.");

const Uniform &uniform = uniforms[uniform_idx];

ERR_FAIL_COND_V_MSG(uniform.type != set_uniform.type, RID(),
"Mismatch uniform type for binding (" + itos(set_uniform.binding) + "). Expected '" + shader_uniform_names[set_uniform.type] + "', supplied: '" + shader_uniform_names[uniform.type] + "'.");
"Mismatch uniform type for binding (" + itos(set_uniform.binding) + "), set (" + itos(p_shader_set) + "). Expected '" + shader_uniform_names[set_uniform.type] + "', supplied: '" + shader_uniform_names[uniform.type] + "'.");

VkWriteDescriptorSet write; //common header
write.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
Expand Down
1 change: 1 addition & 0 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ void EditorNode::_notification(int p_what) {
RS::get_singleton()->environment_set_volumetric_fog_filter_active(bool(GLOBAL_GET("rendering/volumetric_fog/use_filter")));
RS::get_singleton()->environment_set_volumetric_fog_directional_shadow_shrink_size(GLOBAL_GET("rendering/volumetric_fog/directional_shadow_shrink"));
RS::get_singleton()->environment_set_volumetric_fog_positional_shadow_shrink_size(GLOBAL_GET("rendering/volumetric_fog/positional_shadow_shrink"));
RS::get_singleton()->canvas_set_shadow_texture_size(GLOBAL_GET("rendering/quality/2d_shadow_atlas/size"));
}

ResourceImporterTexture::get_singleton()->update_imports();
Expand Down
4 changes: 0 additions & 4 deletions editor/plugins/tile_set_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ void TileSetEditor::_import_node(Node *p_node, Ref<TileSet> p_library) {

Sprite2D *mi = Object::cast_to<Sprite2D>(child);
Ref<Texture2D> texture = mi->get_texture();
Ref<Texture2D> normal_map = mi->get_normal_map();
Ref<ShaderMaterial> material = mi->get_material();

if (texture.is_null()) {
Expand All @@ -75,7 +74,6 @@ void TileSetEditor::_import_node(Node *p_node, Ref<TileSet> p_library) {
}

p_library->tile_set_texture(id, texture);
p_library->tile_set_normal_map(id, normal_map);
p_library->tile_set_material(id, material);

p_library->tile_set_modulate(id, mi->get_modulate());
Expand Down Expand Up @@ -2368,7 +2366,6 @@ void TileSetEditor::_select_edited_shape_coord() {
void TileSetEditor::_undo_tile_removal(int p_id) {
undo_redo->add_undo_method(tileset.ptr(), "create_tile", p_id);
undo_redo->add_undo_method(tileset.ptr(), "tile_set_name", p_id, tileset->tile_get_name(p_id));
undo_redo->add_undo_method(tileset.ptr(), "tile_set_normal_map", p_id, tileset->tile_get_normal_map(p_id));
undo_redo->add_undo_method(tileset.ptr(), "tile_set_texture_offset", p_id, tileset->tile_get_texture_offset(p_id));
undo_redo->add_undo_method(tileset.ptr(), "tile_set_material", p_id, tileset->tile_get_material(p_id));
undo_redo->add_undo_method(tileset.ptr(), "tile_set_modulate", p_id, tileset->tile_get_modulate(p_id));
Expand Down Expand Up @@ -3541,7 +3538,6 @@ void TilesetEditorContext::_get_property_list(List<PropertyInfo> *p_list) const
int id = tileset_editor->get_current_tile();
p_list->push_back(PropertyInfo(Variant::NIL, "Selected Tile", PROPERTY_HINT_NONE, "tile_", PROPERTY_USAGE_GROUP));
p_list->push_back(PropertyInfo(Variant::STRING, "tile_name"));
p_list->push_back(PropertyInfo(Variant::OBJECT, "tile_normal_map", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"));
p_list->push_back(PropertyInfo(Variant::VECTOR2, "tile_tex_offset"));
p_list->push_back(PropertyInfo(Variant::OBJECT, "tile_material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial"));
p_list->push_back(PropertyInfo(Variant::COLOR, "tile_modulate"));
Expand Down
41 changes: 1 addition & 40 deletions scene/2d/animated_sprite_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
#include "core/os/os.h"
#include "scene/scene_string_names.h"

#define NORMAL_SUFFIX "_normal"
#define SPECULAR_SUFFIX "_specular"

#ifdef TOOLS_ENABLED
Dictionary AnimatedSprite2D::_edit_get_state() const {
Dictionary state = Node2D::_edit_get_state();
Expand Down Expand Up @@ -152,8 +149,6 @@ void SpriteFrames::add_animation(const StringName &p_anim) {
ERR_FAIL_COND_MSG(animations.has(p_anim), "SpriteFrames already has animation '" + p_anim + "'.");

animations[p_anim] = Anim();
animations[p_anim].normal_name = String(p_anim) + NORMAL_SUFFIX;
animations[p_anim].specular_name = String(p_anim) + SPECULAR_SUFFIX;
}

bool SpriteFrames::has_animation(const StringName &p_anim) const {
Expand All @@ -171,8 +166,6 @@ void SpriteFrames::rename_animation(const StringName &p_prev, const StringName &
Anim anim = animations[p_prev];
animations.erase(p_prev);
animations[p_next] = anim;
animations[p_next].normal_name = String(p_next) + NORMAL_SUFFIX;
animations[p_next].specular_name = String(p_next) + SPECULAR_SUFFIX;
}

Vector<String> SpriteFrames::_get_animation_list() const {
Expand Down Expand Up @@ -441,9 +434,6 @@ void AnimatedSprite2D::_notification(int p_what) {
return;
}

Ref<Texture2D> normal = frames->get_normal_frame(animation, frame);
Ref<Texture2D> specular = frames->get_specular_frame(animation, frame);

RID ci = get_canvas_item();

Size2i s;
Expand All @@ -465,7 +455,7 @@ void AnimatedSprite2D::_notification(int p_what) {
dst_rect.size.y = -dst_rect.size.y;
}

texture->draw_rect_region(ci, dst_rect, Rect2(Vector2(), texture->get_size()), Color(1, 1, 1), false, normal, specular, Color(specular_color.r, specular_color.g, specular_color.b, shininess));
texture->draw_rect_region(ci, dst_rect, Rect2(Vector2(), texture->get_size()), Color(1, 1, 1), false);

} break;
}
Expand Down Expand Up @@ -672,24 +662,6 @@ String AnimatedSprite2D::get_configuration_warning() const {
return warning;
}

void AnimatedSprite2D::set_specular_color(const Color &p_color) {
specular_color = p_color;
update();
}

Color AnimatedSprite2D::get_specular_color() const {
return specular_color;
}

void AnimatedSprite2D::set_shininess(float p_shininess) {
shininess = CLAMP(p_shininess, 0.0, 1.0);
update();
}

float AnimatedSprite2D::get_shininess() const {
return shininess;
}

void AnimatedSprite2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_sprite_frames", "sprite_frames"), &AnimatedSprite2D::set_sprite_frames);
ClassDB::bind_method(D_METHOD("get_sprite_frames"), &AnimatedSprite2D::get_sprite_frames);
Expand Down Expand Up @@ -722,12 +694,6 @@ void AnimatedSprite2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_speed_scale", "speed_scale"), &AnimatedSprite2D::set_speed_scale);
ClassDB::bind_method(D_METHOD("get_speed_scale"), &AnimatedSprite2D::get_speed_scale);

ClassDB::bind_method(D_METHOD("set_specular_color", "color"), &AnimatedSprite2D::set_specular_color);
ClassDB::bind_method(D_METHOD("get_specular_color"), &AnimatedSprite2D::get_specular_color);

ClassDB::bind_method(D_METHOD("set_shininess", "shininess"), &AnimatedSprite2D::set_shininess);
ClassDB::bind_method(D_METHOD("get_shininess"), &AnimatedSprite2D::get_shininess);

ADD_SIGNAL(MethodInfo("frame_changed"));
ADD_SIGNAL(MethodInfo("animation_finished"));

Expand All @@ -737,9 +703,6 @@ void AnimatedSprite2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "frame"), "set_frame", "get_frame");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "speed_scale"), "set_speed_scale", "get_speed_scale");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playing"), "_set_playing", "_is_playing");
ADD_GROUP("Lighting", "");
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "specular_color", PROPERTY_HINT_COLOR_NO_ALPHA), "set_specular_color", "get_specular_color");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "shininess", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_shininess", "get_shininess");
ADD_GROUP("Offset", "");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "centered"), "set_centered", "is_centered");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
Expand All @@ -759,6 +722,4 @@ AnimatedSprite2D::AnimatedSprite2D() {
animation = "default";
timeout = 0;
is_over = false;
specular_color = Color(1, 1, 1, 1);
shininess = 1.0;
}
43 changes: 0 additions & 43 deletions scene/2d/animated_sprite_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,8 @@ class SpriteFrames : public Resource {
loop = true;
speed = 5;
}

StringName normal_name;
StringName specular_name;
};

Color specular_color;
float shininess;

Map<StringName, Anim> animations;

Array _get_frames() const;
Expand Down Expand Up @@ -95,34 +89,6 @@ class SpriteFrames : public Resource {
return E->get().frames[p_idx];
}

_FORCE_INLINE_ Ref<Texture2D> get_normal_frame(const StringName &p_anim, int p_idx) const {
const Map<StringName, Anim>::Element *E = animations.find(p_anim);
ERR_FAIL_COND_V_MSG(!E, Ref<Texture2D>(), "Animation '" + String(p_anim) + "' doesn't exist.");
ERR_FAIL_COND_V(p_idx < 0, Ref<Texture2D>());

const Map<StringName, Anim>::Element *EN = animations.find(E->get().normal_name);

if (!EN || p_idx >= EN->get().frames.size()) {
return Ref<Texture2D>();
}

return EN->get().frames[p_idx];
}

_FORCE_INLINE_ Ref<Texture2D> get_specular_frame(const StringName &p_anim, int p_idx) const {
const Map<StringName, Anim>::Element *E = animations.find(p_anim);
ERR_FAIL_COND_V(!E, Ref<Texture2D>());
ERR_FAIL_COND_V(p_idx < 0, Ref<Texture2D>());

const Map<StringName, Anim>::Element *EN = animations.find(E->get().specular_name);

if (!EN || p_idx >= EN->get().frames.size()) {
return Ref<Texture2D>();
}

return EN->get().frames[p_idx];
}

void set_frame(const StringName &p_anim, int p_idx, const Ref<Texture2D> &p_frame) {
Map<StringName, Anim>::Element *E = animations.find(p_anim);
ERR_FAIL_COND_MSG(!E, "Animation '" + String(p_anim) + "' doesn't exist.");
Expand Down Expand Up @@ -166,9 +132,6 @@ class AnimatedSprite2D : public Node2D {
bool _is_playing() const;
Rect2 _get_rect() const;

Color specular_color;
float shininess;

protected:
static void _bind_methods();
void _notification(int p_what);
Expand Down Expand Up @@ -216,12 +179,6 @@ class AnimatedSprite2D : public Node2D {
void set_flip_v(bool p_flip);
bool is_flipped_v() const;

void set_specular_color(const Color &p_color);
Color get_specular_color() const;

void set_shininess(float p_shininess);
float get_shininess() const;

virtual String get_configuration_warning() const override;
AnimatedSprite2D();
};
Expand Down
20 changes: 1 addition & 19 deletions scene/2d/cpu_particles_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,6 @@ Ref<Texture2D> CPUParticles2D::get_texture() const {
return texture;
}

void CPUParticles2D::set_normalmap(const Ref<Texture2D> &p_normalmap) {
normalmap = p_normalmap;
update();
}

Ref<Texture2D> CPUParticles2D::get_normalmap() const {
return normalmap;
}

void CPUParticles2D::set_fixed_fps(int p_count) {
fixed_fps = p_count;
}
Expand Down Expand Up @@ -1060,12 +1051,7 @@ void CPUParticles2D::_notification(int p_what) {
texrid = texture->get_rid();
}

RID normrid;
if (normalmap.is_valid()) {
normrid = normalmap->get_rid();
}

RS::get_singleton()->canvas_item_add_multimesh(get_canvas_item(), multimesh, texrid, normrid);
RS::get_singleton()->canvas_item_add_multimesh(get_canvas_item(), multimesh, texrid);
}

if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
Expand Down Expand Up @@ -1214,9 +1200,6 @@ void CPUParticles2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_texture", "texture"), &CPUParticles2D::set_texture);
ClassDB::bind_method(D_METHOD("get_texture"), &CPUParticles2D::get_texture);

ClassDB::bind_method(D_METHOD("set_normalmap", "normalmap"), &CPUParticles2D::set_normalmap);
ClassDB::bind_method(D_METHOD("get_normalmap"), &CPUParticles2D::get_normalmap);

ClassDB::bind_method(D_METHOD("restart"), &CPUParticles2D::restart);

ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emitting"), "set_emitting", "is_emitting");
Expand All @@ -1236,7 +1219,6 @@ void CPUParticles2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "local_coords"), "set_use_local_coordinates", "get_use_local_coordinates");
ADD_PROPERTY(PropertyInfo(Variant::INT, "draw_order", PROPERTY_HINT_ENUM, "Index,Lifetime"), "set_draw_order", "get_draw_order");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "normalmap", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_normalmap", "get_normalmap");

BIND_ENUM_CONSTANT(DRAW_ORDER_INDEX);
BIND_ENUM_CONSTANT(DRAW_ORDER_LIFETIME);
Expand Down
4 changes: 0 additions & 4 deletions scene/2d/cpu_particles_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ class CPUParticles2D : public Node2D {
DrawOrder draw_order;

Ref<Texture2D> texture;
Ref<Texture2D> normalmap;

////////

Expand Down Expand Up @@ -232,9 +231,6 @@ class CPUParticles2D : public Node2D {
void set_texture(const Ref<Texture2D> &p_texture);
Ref<Texture2D> get_texture() const;

void set_normalmap(const Ref<Texture2D> &p_normalmap);
Ref<Texture2D> get_normalmap() const;

///////////////////

void set_direction(Vector2 p_direction);
Expand Down
19 changes: 1 addition & 18 deletions scene/2d/gpu_particles_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,6 @@ Ref<Texture2D> GPUParticles2D::get_texture() const {
return texture;
}

void GPUParticles2D::set_normal_map(const Ref<Texture2D> &p_normal_map) {
normal_map = p_normal_map;
update();
}

Ref<Texture2D> GPUParticles2D::get_normal_map() const {
return normal_map;
}

void GPUParticles2D::_validate_property(PropertyInfo &property) const {
}

Expand All @@ -290,12 +281,8 @@ void GPUParticles2D::_notification(int p_what) {
if (texture.is_valid()) {
texture_rid = texture->get_rid();
}
RID normal_rid;
if (normal_map.is_valid()) {
normal_rid = normal_map->get_rid();
}

RS::get_singleton()->canvas_item_add_particles(get_canvas_item(), particles, texture_rid, normal_rid);
RS::get_singleton()->canvas_item_add_particles(get_canvas_item(), particles, texture_rid);

#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint() && (this == get_tree()->get_edited_scene_root() || get_tree()->get_edited_scene_root()->is_a_parent_of(this))) {
Expand Down Expand Up @@ -359,9 +346,6 @@ void GPUParticles2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_texture", "texture"), &GPUParticles2D::set_texture);
ClassDB::bind_method(D_METHOD("get_texture"), &GPUParticles2D::get_texture);

ClassDB::bind_method(D_METHOD("set_normal_map", "texture"), &GPUParticles2D::set_normal_map);
ClassDB::bind_method(D_METHOD("get_normal_map"), &GPUParticles2D::get_normal_map);

ClassDB::bind_method(D_METHOD("capture_rect"), &GPUParticles2D::capture_rect);

ClassDB::bind_method(D_METHOD("restart"), &GPUParticles2D::restart);
Expand All @@ -385,7 +369,6 @@ void GPUParticles2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "process_material", PROPERTY_HINT_RESOURCE_TYPE, "ShaderMaterial,ParticlesMaterial"), "set_process_material", "get_process_material");
ADD_GROUP("Textures", "");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "normal_map", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_normal_map", "get_normal_map");

BIND_ENUM_CONSTANT(DRAW_ORDER_INDEX);
BIND_ENUM_CONSTANT(DRAW_ORDER_LIFETIME);
Expand Down
4 changes: 0 additions & 4 deletions scene/2d/gpu_particles_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class GPUParticles2D : public Node2D {
DrawOrder draw_order;

Ref<Texture2D> texture;
Ref<Texture2D> normal_map;

void _update_particle_emission_transform();

Expand Down Expand Up @@ -111,9 +110,6 @@ class GPUParticles2D : public Node2D {
void set_texture(const Ref<Texture2D> &p_texture);
Ref<Texture2D> get_texture() const;

void set_normal_map(const Ref<Texture2D> &p_normal_map);
Ref<Texture2D> get_normal_map() const;

virtual String get_configuration_warning() const override;

void restart();
Expand Down
Loading