Changes to material required to add custom shaders in RD renderer
This commit is contained in:
parent
ef083a583b
commit
50e9befb88
|
@ -549,7 +549,6 @@ Polygon3DEditor::Polygon3DEditor(EditorNode *p_editor) {
|
|||
|
||||
line_material = Ref<SpatialMaterial>(memnew(SpatialMaterial));
|
||||
line_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
|
||||
line_material->set_line_width(3.0);
|
||||
line_material->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
|
||||
line_material->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
|
||||
line_material->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true);
|
||||
|
|
|
@ -1585,7 +1585,7 @@ Position3DSpatialGizmoPlugin::Position3DSpatialGizmoPlugin() {
|
|||
mat->set_flag(SpatialMaterial::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
|
||||
mat->set_flag(SpatialMaterial::FLAG_SRGB_VERTEX_COLOR, true);
|
||||
mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
|
||||
mat->set_line_width(3);
|
||||
|
||||
Array d;
|
||||
d.resize(VS::ARRAY_MAX);
|
||||
d[Mesh::ARRAY_VERTEX] = cursor_points;
|
||||
|
|
|
@ -1458,14 +1458,12 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
|
|||
outer_mat->set_albedo(Color(0.7, 0.7, 1.0, 0.8));
|
||||
outer_mat->set_on_top_of_alpha();
|
||||
outer_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
|
||||
outer_mat->set_line_width(3.0);
|
||||
outer_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true);
|
||||
|
||||
selection_floor_mat.instance();
|
||||
selection_floor_mat->set_albedo(Color(0.80, 0.80, 1.0, 1));
|
||||
selection_floor_mat->set_on_top_of_alpha();
|
||||
selection_floor_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
|
||||
selection_floor_mat->set_line_width(3.0);
|
||||
|
||||
d[VS::ARRAY_VERTEX] = lines;
|
||||
VisualServer::get_singleton()->mesh_add_surface_from_arrays(selection_mesh, VS::PRIMITIVE_LINES, d);
|
||||
|
|
|
@ -337,7 +337,6 @@ void RayCast::_create_debug_shape() {
|
|||
|
||||
Ref<SpatialMaterial> line_material = static_cast<Ref<SpatialMaterial> >(debug_material);
|
||||
line_material->set_flag(SpatialMaterial::FLAG_UNSHADED, true);
|
||||
line_material->set_line_width(3.0);
|
||||
line_material->set_albedo(Color(1.0, 0.8, 0.6));
|
||||
}
|
||||
|
||||
|
|
|
@ -171,7 +171,7 @@ bool ShaderMaterial::property_can_revert(const String &p_name) {
|
|||
|
||||
StringName pr = shader->remap_param(p_name);
|
||||
if (pr) {
|
||||
Variant default_value = VisualServer::get_singleton()->material_get_param_default(_get_material(), pr);
|
||||
Variant default_value = VisualServer::get_singleton()->shader_get_param_default(shader->get_rid(), pr);
|
||||
Variant current_value;
|
||||
_get(p_name, current_value);
|
||||
return default_value.get_type() != Variant::NIL && default_value != current_value;
|
||||
|
@ -185,7 +185,7 @@ Variant ShaderMaterial::property_get_revert(const String &p_name) {
|
|||
if (shader.is_valid()) {
|
||||
StringName pr = shader->remap_param(p_name);
|
||||
if (pr) {
|
||||
r_ret = VisualServer::get_singleton()->material_get_param_default(_get_material(), pr);
|
||||
r_ret = VisualServer::get_singleton()->shader_get_param_default(shader->get_rid(), pr);
|
||||
}
|
||||
}
|
||||
return r_ret;
|
||||
|
@ -1530,17 +1530,6 @@ void SpatialMaterial::_validate_property(PropertyInfo &property) const {
|
|||
}
|
||||
}
|
||||
|
||||
void SpatialMaterial::set_line_width(float p_line_width) {
|
||||
|
||||
line_width = p_line_width;
|
||||
VS::get_singleton()->material_set_line_width(_get_material(), line_width);
|
||||
}
|
||||
|
||||
float SpatialMaterial::get_line_width() const {
|
||||
|
||||
return line_width;
|
||||
}
|
||||
|
||||
void SpatialMaterial::set_point_size(float p_point_size) {
|
||||
|
||||
point_size = p_point_size;
|
||||
|
@ -1976,9 +1965,6 @@ void SpatialMaterial::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("set_refraction", "refraction"), &SpatialMaterial::set_refraction);
|
||||
ClassDB::bind_method(D_METHOD("get_refraction"), &SpatialMaterial::get_refraction);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_line_width", "line_width"), &SpatialMaterial::set_line_width);
|
||||
ClassDB::bind_method(D_METHOD("get_line_width"), &SpatialMaterial::get_line_width);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_point_size", "point_size"), &SpatialMaterial::set_point_size);
|
||||
ClassDB::bind_method(D_METHOD("get_point_size"), &SpatialMaterial::get_point_size);
|
||||
|
||||
|
@ -2122,7 +2108,6 @@ void SpatialMaterial::_bind_methods() {
|
|||
ADD_PROPERTY(PropertyInfo(Variant::INT, "params_blend_mode", PROPERTY_HINT_ENUM, "Mix,Add,Sub,Mul"), "set_blend_mode", "get_blend_mode");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "params_cull_mode", PROPERTY_HINT_ENUM, "Back,Front,Disabled"), "set_cull_mode", "get_cull_mode");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "params_depth_draw_mode", PROPERTY_HINT_ENUM, "Opaque Only,Always,Never,Opaque Pre-Pass"), "set_depth_draw_mode", "get_depth_draw_mode");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "params_line_width", PROPERTY_HINT_RANGE, "0.1,128,0.1"), "set_line_width", "get_line_width");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "params_point_size", PROPERTY_HINT_RANGE, "0.1,128,0.1"), "set_point_size", "get_point_size");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "params_billboard_mode", PROPERTY_HINT_ENUM, "Disabled,Enabled,Y-Billboard,Particle Billboard"), "set_billboard_mode", "get_billboard_mode");
|
||||
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "params_billboard_keep_scale"), "set_flag", "get_flag", FLAG_BILLBOARD_KEEP_SCALE);
|
||||
|
@ -2363,7 +2348,6 @@ SpatialMaterial::SpatialMaterial() :
|
|||
set_subsurface_scattering_strength(0);
|
||||
set_transmission(Color(0, 0, 0));
|
||||
set_refraction(0.05);
|
||||
set_line_width(1);
|
||||
set_point_size(1);
|
||||
set_uv1_offset(Vector3(0, 0, 0));
|
||||
set_uv1_scale(Vector3(1, 1, 1));
|
||||
|
|
|
@ -387,7 +387,6 @@ private:
|
|||
float subsurface_scattering_strength;
|
||||
Color transmission;
|
||||
float refraction;
|
||||
float line_width;
|
||||
float point_size;
|
||||
float alpha_scissor_threshold;
|
||||
bool grow_enabled;
|
||||
|
@ -519,9 +518,6 @@ public:
|
|||
void set_refraction(float p_refraction);
|
||||
float get_refraction() const;
|
||||
|
||||
void set_line_width(float p_line_width);
|
||||
float get_line_width() const;
|
||||
|
||||
void set_point_size(float p_point_size);
|
||||
float get_point_size() const;
|
||||
|
||||
|
|
|
@ -233,6 +233,7 @@ public:
|
|||
|
||||
virtual void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) = 0;
|
||||
virtual RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const = 0;
|
||||
virtual Variant shader_get_param_default(RID p_material, const StringName &p_param) const = 0;
|
||||
|
||||
/* COMMON MATERIAL API */
|
||||
|
||||
|
@ -244,9 +245,6 @@ public:
|
|||
|
||||
virtual void material_set_param(RID p_material, const StringName &p_param, const Variant &p_value) = 0;
|
||||
virtual Variant material_get_param(RID p_material, const StringName &p_param) const = 0;
|
||||
virtual Variant material_get_param_default(RID p_material, const StringName &p_param) const = 0;
|
||||
|
||||
virtual void material_set_line_width(RID p_material, float p_width) = 0;
|
||||
|
||||
virtual void material_set_next_pass(RID p_material, RID p_next_material) = 0;
|
||||
|
||||
|
|
|
@ -1974,15 +1974,12 @@ RasterizerCanvasRD::RasterizerCanvasRD(RasterizerStorageRD *p_storage) {
|
|||
RD::AttachmentFormat af_color;
|
||||
af_color.format = RD::DATA_FORMAT_R32_SFLOAT;
|
||||
af_color.usage_flags = RD::TEXTURE_USAGE_SAMPLING_BIT | RD::TEXTURE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
af_color.samples = RenderingDevice::TEXTURE_SAMPLES_64;
|
||||
|
||||
attachments.push_back(af_color);
|
||||
|
||||
RD::AttachmentFormat af_depth;
|
||||
af_depth.format = RD::DATA_FORMAT_D24_UNORM_S8_UINT;
|
||||
af_depth.format = RD::get_singleton()->texture_is_format_supported_for_usage(RD::DATA_FORMAT_X8_D24_UNORM_PACK32, RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) ? RD::DATA_FORMAT_X8_D24_UNORM_PACK32 : RD::DATA_FORMAT_D32_SFLOAT;
|
||||
af_depth.usage_flags = RD::TEXTURE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
|
||||
af_depth.samples = RenderingDevice::TEXTURE_SAMPLES_64;
|
||||
|
||||
attachments.push_back(af_depth);
|
||||
|
||||
|
|
|
@ -189,6 +189,26 @@ public:
|
|||
|
||||
/* SHADER API */
|
||||
|
||||
enum ShaderType {
|
||||
SHADER_TYPE_2D,
|
||||
SHADER_TYPE_3D,
|
||||
SHADER_TYPE_3D_POST_PROCESS,
|
||||
SHADER_TYPE_PARTICLES
|
||||
};
|
||||
|
||||
class ShaderData {
|
||||
public:
|
||||
virtual void set_code(const String &p_Code) = 0;
|
||||
virtual void set_default_texture_param(const StringName &p_name, RID p_texture) = 0;
|
||||
virtual void get_param_list(List<PropertyInfo> *p_param_list) const = 0;
|
||||
virtual bool is_animated() const = 0;
|
||||
virtual bool casts_shadows() const = 0;
|
||||
virtual Variant get_default_parameter(const StringName &p_parameter) const = 0;
|
||||
virtual ~ShaderData() {}
|
||||
};
|
||||
|
||||
typedef ShaderData *(ShaderDataRequestFunction)();
|
||||
|
||||
RID shader_create() { return RID(); }
|
||||
|
||||
void shader_set_code(RID p_shader, const String &p_code) {}
|
||||
|
@ -197,22 +217,29 @@ public:
|
|||
|
||||
void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) {}
|
||||
RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const { return RID(); }
|
||||
Variant shader_get_param_default(RID p_material, const StringName &p_param) const { return Variant(); }
|
||||
|
||||
/* COMMON MATERIAL API */
|
||||
|
||||
struct MaterialData {
|
||||
|
||||
virtual void set_render_priority(int p_priority) = 0;
|
||||
virtual void set_next_pass(RID p_pass) = 0;
|
||||
virtual void update_parameters(const Map<StringName, Variant> &p_parameters) = 0;
|
||||
virtual ~MaterialData() {}
|
||||
};
|
||||
typedef MaterialData *(MaterialDataRequestFunction)(ShaderData *);
|
||||
|
||||
RID material_create() { return RID(); }
|
||||
|
||||
void material_set_render_priority(RID p_material, int priority) {}
|
||||
void material_set_shader(RID p_shader_material, RID p_shader) {}
|
||||
RID material_get_shader(RID p_shader_material) const { return RID(); }
|
||||
|
||||
void material_set_param(RID p_material, const StringName &p_param, const Variant &p_value) {}
|
||||
Variant material_get_param(RID p_material, const StringName &p_param) const { return Variant(); }
|
||||
Variant material_get_param_default(RID p_material, const StringName &p_param) const { return Variant(); }
|
||||
|
||||
void material_set_line_width(RID p_material, float p_width) {}
|
||||
|
||||
void material_set_next_pass(RID p_material, RID p_next_material) {}
|
||||
void material_set_render_priority(RID p_material, int priority) {}
|
||||
|
||||
bool material_is_animated(RID p_material) { return false; }
|
||||
bool material_casts_shadows(RID p_material) { return false; }
|
||||
|
|
|
@ -370,6 +370,11 @@ public:
|
|||
DataFormat format;
|
||||
TextureSamples samples;
|
||||
uint32_t usage_flags;
|
||||
AttachmentFormat() {
|
||||
format=DATA_FORMAT_R8G8B8A8_UNORM;
|
||||
samples=TEXTURE_SAMPLES_1;
|
||||
usage_flags=0;
|
||||
}
|
||||
};
|
||||
|
||||
typedef int64_t FramebufferFormatID;
|
||||
|
|
|
@ -202,6 +202,7 @@ public:
|
|||
|
||||
BIND3(shader_set_default_texture_param, RID, const StringName &, RID)
|
||||
BIND2RC(RID, shader_get_default_texture_param, RID, const StringName &)
|
||||
BIND2RC(Variant, shader_get_param_default, RID, const StringName &)
|
||||
|
||||
/* COMMON MATERIAL API */
|
||||
|
||||
|
@ -212,10 +213,8 @@ public:
|
|||
|
||||
BIND3(material_set_param, RID, const StringName &, const Variant &)
|
||||
BIND2RC(Variant, material_get_param, RID, const StringName &)
|
||||
BIND2RC(Variant, material_get_param_default, RID, const StringName &)
|
||||
|
||||
BIND2(material_set_render_priority, RID, int)
|
||||
BIND2(material_set_line_width, RID, float)
|
||||
BIND2(material_set_next_pass, RID, RID)
|
||||
|
||||
/* MESH API */
|
||||
|
|
|
@ -133,6 +133,7 @@ public:
|
|||
|
||||
FUNC3(shader_set_default_texture_param, RID, const StringName &, RID)
|
||||
FUNC2RC(RID, shader_get_default_texture_param, RID, const StringName &)
|
||||
FUNC2RC(Variant, shader_get_param_default, RID, const StringName &)
|
||||
|
||||
/* COMMON MATERIAL API */
|
||||
|
||||
|
@ -143,10 +144,8 @@ public:
|
|||
|
||||
FUNC3(material_set_param, RID, const StringName &, const Variant &)
|
||||
FUNC2RC(Variant, material_get_param, RID, const StringName &)
|
||||
FUNC2RC(Variant, material_get_param_default, RID, const StringName &)
|
||||
|
||||
FUNC2(material_set_render_priority, RID, int)
|
||||
FUNC2(material_set_line_width, RID, float)
|
||||
FUNC2(material_set_next_pass, RID, RID)
|
||||
|
||||
/* MESH API */
|
||||
|
|
|
@ -1648,15 +1648,15 @@ void VisualServer::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("shader_get_param_list", "shader"), &VisualServer::_shader_get_param_list_bind);
|
||||
ClassDB::bind_method(D_METHOD("shader_set_default_texture_param", "shader", "name", "texture"), &VisualServer::shader_set_default_texture_param);
|
||||
ClassDB::bind_method(D_METHOD("shader_get_default_texture_param", "shader", "name"), &VisualServer::shader_get_default_texture_param);
|
||||
ClassDB::bind_method(D_METHOD("shader_get_param_default", "material", "parameter"), &VisualServer::shader_get_param_default);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("material_create"), &VisualServer::material_create);
|
||||
ClassDB::bind_method(D_METHOD("material_set_shader", "shader_material", "shader"), &VisualServer::material_set_shader);
|
||||
ClassDB::bind_method(D_METHOD("material_get_shader", "shader_material"), &VisualServer::material_get_shader);
|
||||
ClassDB::bind_method(D_METHOD("material_set_param", "material", "parameter", "value"), &VisualServer::material_set_param);
|
||||
ClassDB::bind_method(D_METHOD("material_get_param", "material", "parameter"), &VisualServer::material_get_param);
|
||||
ClassDB::bind_method(D_METHOD("material_get_param_default", "material", "parameter"), &VisualServer::material_get_param_default);
|
||||
ClassDB::bind_method(D_METHOD("material_set_render_priority", "material", "priority"), &VisualServer::material_set_render_priority);
|
||||
ClassDB::bind_method(D_METHOD("material_set_line_width", "material", "width"), &VisualServer::material_set_line_width);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("material_set_next_pass", "material", "next_material"), &VisualServer::material_set_next_pass);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("mesh_create"), &VisualServer::mesh_create);
|
||||
|
|
|
@ -177,6 +177,7 @@ public:
|
|||
virtual String shader_get_code(RID p_shader) const = 0;
|
||||
virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const = 0;
|
||||
Array _shader_get_param_list_bind(RID p_shader) const;
|
||||
virtual Variant shader_get_param_default(RID p_shader, const StringName &p_param) const = 0;
|
||||
|
||||
virtual void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) = 0;
|
||||
virtual RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const = 0;
|
||||
|
@ -195,11 +196,9 @@ public:
|
|||
|
||||
virtual void material_set_param(RID p_material, const StringName &p_param, const Variant &p_value) = 0;
|
||||
virtual Variant material_get_param(RID p_material, const StringName &p_param) const = 0;
|
||||
virtual Variant material_get_param_default(RID p_material, const StringName &p_param) const = 0;
|
||||
|
||||
virtual void material_set_render_priority(RID p_material, int priority) = 0;
|
||||
|
||||
virtual void material_set_line_width(RID p_material, float p_width) = 0;
|
||||
virtual void material_set_next_pass(RID p_material, RID p_next_material) = 0;
|
||||
|
||||
/* MESH API */
|
||||
|
|
Loading…
Reference in New Issue