Merge pull request #70016 from Chaosus/refactor_rd_shader_data
fixed https://github.com/godotengine/godot/issues/69949
This commit is contained in:
commit
5c83e95103
|
@ -922,6 +922,104 @@ _FORCE_INLINE_ static void _fill_std140_ubo_empty(ShaderLanguage::DataType type,
|
|||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// ShaderData
|
||||
|
||||
void ShaderData::set_path_hint(const String &p_hint) {
|
||||
path = p_hint;
|
||||
}
|
||||
|
||||
void ShaderData::set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index) {
|
||||
if (!p_texture.is_valid()) {
|
||||
if (default_texture_params.has(p_name) && default_texture_params[p_name].has(p_index)) {
|
||||
default_texture_params[p_name].erase(p_index);
|
||||
|
||||
if (default_texture_params[p_name].is_empty()) {
|
||||
default_texture_params.erase(p_name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!default_texture_params.has(p_name)) {
|
||||
default_texture_params[p_name] = HashMap<int, RID>();
|
||||
}
|
||||
default_texture_params[p_name][p_index] = p_texture;
|
||||
}
|
||||
}
|
||||
|
||||
Variant ShaderData::get_default_parameter(const StringName &p_parameter) const {
|
||||
if (uniforms.has(p_parameter)) {
|
||||
ShaderLanguage::ShaderNode::Uniform uniform = uniforms[p_parameter];
|
||||
Vector<ShaderLanguage::ConstantNode::Value> default_value = uniform.default_value;
|
||||
return ShaderLanguage::constant_value_to_variant(default_value, uniform.type, uniform.array_size, uniform.hint);
|
||||
}
|
||||
return Variant();
|
||||
}
|
||||
|
||||
void ShaderData::get_shader_uniform_list(List<PropertyInfo> *p_param_list) const {
|
||||
SortArray<Pair<StringName, int>, ShaderLanguage::UniformOrderComparator> sorter;
|
||||
LocalVector<Pair<StringName, int>> filtered_uniforms;
|
||||
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_LOCAL) {
|
||||
continue;
|
||||
}
|
||||
if (E.value.texture_order >= 0) {
|
||||
filtered_uniforms.push_back(Pair<StringName, int>(E.key, E.value.texture_order + 100000));
|
||||
} else {
|
||||
filtered_uniforms.push_back(Pair<StringName, int>(E.key, E.value.order));
|
||||
}
|
||||
}
|
||||
int uniform_count = filtered_uniforms.size();
|
||||
sorter.sort(filtered_uniforms.ptr(), uniform_count);
|
||||
|
||||
String last_group;
|
||||
for (int i = 0; i < uniform_count; i++) {
|
||||
const StringName &uniform_name = filtered_uniforms[i].first;
|
||||
const ShaderLanguage::ShaderNode::Uniform &uniform = uniforms[uniform_name];
|
||||
|
||||
String group = uniform.group;
|
||||
if (!uniform.subgroup.is_empty()) {
|
||||
group += "::" + uniform.subgroup;
|
||||
}
|
||||
|
||||
if (group != last_group) {
|
||||
PropertyInfo pi;
|
||||
pi.usage = PROPERTY_USAGE_GROUP;
|
||||
pi.name = group;
|
||||
p_param_list->push_back(pi);
|
||||
|
||||
last_group = group;
|
||||
}
|
||||
|
||||
PropertyInfo pi = ShaderLanguage::uniform_to_property_info(uniform);
|
||||
pi.name = uniform_name;
|
||||
p_param_list->push_back(pi);
|
||||
}
|
||||
}
|
||||
|
||||
void ShaderData::get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const {
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
RendererMaterialStorage::InstanceShaderParam p;
|
||||
p.info = ShaderLanguage::uniform_to_property_info(E.value);
|
||||
p.info.name = E.key; //supply name
|
||||
p.index = E.value.instance_index;
|
||||
p.default_value = ShaderLanguage::constant_value_to_variant(E.value.default_value, E.value.type, E.value.array_size, E.value.hint);
|
||||
p_param_list->push_back(p);
|
||||
}
|
||||
}
|
||||
|
||||
bool ShaderData::is_parameter_texture(const StringName &p_param) const {
|
||||
if (!uniforms.has(p_param)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return uniforms[p_param].texture_order >= 0;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// MaterialData
|
||||
|
||||
|
@ -2806,10 +2904,6 @@ void MaterialStorage::material_update_dependency(RID p_material, DependencyTrack
|
|||
|
||||
/* Canvas Shader Data */
|
||||
|
||||
void CanvasShaderData::set_path_hint(const String &p_path) {
|
||||
path = p_path;
|
||||
}
|
||||
|
||||
void CanvasShaderData::set_code(const String &p_code) {
|
||||
// compile the shader
|
||||
|
||||
|
@ -2890,85 +2984,6 @@ void CanvasShaderData::set_code(const String &p_code) {
|
|||
valid = true;
|
||||
}
|
||||
|
||||
void CanvasShaderData::set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index) {
|
||||
if (!p_texture.is_valid()) {
|
||||
if (default_texture_params.has(p_name) && default_texture_params[p_name].has(p_index)) {
|
||||
default_texture_params[p_name].erase(p_index);
|
||||
|
||||
if (default_texture_params[p_name].is_empty()) {
|
||||
default_texture_params.erase(p_name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!default_texture_params.has(p_name)) {
|
||||
default_texture_params[p_name] = HashMap<int, RID>();
|
||||
}
|
||||
default_texture_params[p_name][p_index] = p_texture;
|
||||
}
|
||||
}
|
||||
|
||||
void CanvasShaderData::get_shader_uniform_list(List<PropertyInfo> *p_param_list) const {
|
||||
HashMap<int, StringName> order;
|
||||
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_LOCAL ||
|
||||
E.value.hint == ShaderLanguage::ShaderNode::Uniform::HINT_SCREEN_TEXTURE ||
|
||||
E.value.hint == ShaderLanguage::ShaderNode::Uniform::HINT_NORMAL_ROUGHNESS_TEXTURE ||
|
||||
E.value.hint == ShaderLanguage::ShaderNode::Uniform::HINT_DEPTH_TEXTURE) {
|
||||
continue;
|
||||
}
|
||||
if (E.value.texture_order >= 0) {
|
||||
order[E.value.texture_order + 100000] = E.key;
|
||||
} else {
|
||||
order[E.value.order] = E.key;
|
||||
}
|
||||
}
|
||||
|
||||
String last_group;
|
||||
for (const KeyValue<int, StringName> &E : order) {
|
||||
String group = uniforms[E.value].group;
|
||||
if (!uniforms[E.value].subgroup.is_empty()) {
|
||||
group += "::" + uniforms[E.value].subgroup;
|
||||
}
|
||||
|
||||
if (group != last_group) {
|
||||
PropertyInfo pi;
|
||||
pi.usage = PROPERTY_USAGE_GROUP;
|
||||
pi.name = group;
|
||||
p_param_list->push_back(pi);
|
||||
|
||||
last_group = group;
|
||||
}
|
||||
|
||||
PropertyInfo pi = ShaderLanguage::uniform_to_property_info(uniforms[E.value]);
|
||||
pi.name = E.value;
|
||||
p_param_list->push_back(pi);
|
||||
}
|
||||
}
|
||||
|
||||
void CanvasShaderData::get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const {
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
RendererMaterialStorage::InstanceShaderParam p;
|
||||
p.info = ShaderLanguage::uniform_to_property_info(E.value);
|
||||
p.info.name = E.key; //supply name
|
||||
p.index = E.value.instance_index;
|
||||
p.default_value = ShaderLanguage::constant_value_to_variant(E.value.default_value, E.value.type, E.value.array_size, E.value.hint);
|
||||
p_param_list->push_back(p);
|
||||
}
|
||||
}
|
||||
|
||||
bool CanvasShaderData::is_parameter_texture(const StringName &p_param) const {
|
||||
if (!uniforms.has(p_param)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return uniforms[p_param].texture_order >= 0;
|
||||
}
|
||||
|
||||
bool CanvasShaderData::is_animated() const {
|
||||
return false;
|
||||
}
|
||||
|
@ -2977,15 +2992,6 @@ bool CanvasShaderData::casts_shadows() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
Variant CanvasShaderData::get_default_parameter(const StringName &p_parameter) const {
|
||||
if (uniforms.has(p_parameter)) {
|
||||
ShaderLanguage::ShaderNode::Uniform uniform = uniforms[p_parameter];
|
||||
Vector<ShaderLanguage::ConstantNode::Value> default_value = uniform.default_value;
|
||||
return ShaderLanguage::constant_value_to_variant(default_value, uniform.type, uniform.array_size, uniform.hint);
|
||||
}
|
||||
return Variant();
|
||||
}
|
||||
|
||||
RS::ShaderNativeSourceCode CanvasShaderData::get_native_source_code() const {
|
||||
return MaterialStorage::get_singleton()->shaders.canvas_shader.version_get_native_source_code(version);
|
||||
}
|
||||
|
@ -3044,10 +3050,6 @@ GLES3::MaterialData *GLES3::_create_canvas_material_func(ShaderData *p_shader) {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// SKY SHADER
|
||||
|
||||
void SkyShaderData::set_path_hint(const String &p_path) {
|
||||
path = p_path;
|
||||
}
|
||||
|
||||
void SkyShaderData::set_code(const String &p_code) {
|
||||
//compile
|
||||
|
||||
|
@ -3138,83 +3140,6 @@ void SkyShaderData::set_code(const String &p_code) {
|
|||
valid = true;
|
||||
}
|
||||
|
||||
void SkyShaderData::set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index) {
|
||||
if (!p_texture.is_valid()) {
|
||||
if (default_texture_params.has(p_name) && default_texture_params[p_name].has(p_index)) {
|
||||
default_texture_params[p_name].erase(p_index);
|
||||
|
||||
if (default_texture_params[p_name].is_empty()) {
|
||||
default_texture_params.erase(p_name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!default_texture_params.has(p_name)) {
|
||||
default_texture_params[p_name] = HashMap<int, RID>();
|
||||
}
|
||||
default_texture_params[p_name][p_index] = p_texture;
|
||||
}
|
||||
}
|
||||
|
||||
void SkyShaderData::get_shader_uniform_list(List<PropertyInfo> *p_param_list) const {
|
||||
RBMap<int, StringName> order;
|
||||
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope == ShaderLanguage::ShaderNode::Uniform::SCOPE_GLOBAL || E.value.scope == ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (E.value.texture_order >= 0) {
|
||||
order[E.value.texture_order + 100000] = E.key;
|
||||
} else {
|
||||
order[E.value.order] = E.key;
|
||||
}
|
||||
}
|
||||
|
||||
String last_group;
|
||||
for (const KeyValue<int, StringName> &E : order) {
|
||||
String group = uniforms[E.value].group;
|
||||
if (!uniforms[E.value].subgroup.is_empty()) {
|
||||
group += "::" + uniforms[E.value].subgroup;
|
||||
}
|
||||
|
||||
if (group != last_group) {
|
||||
PropertyInfo pi;
|
||||
pi.usage = PROPERTY_USAGE_GROUP;
|
||||
pi.name = group;
|
||||
p_param_list->push_back(pi);
|
||||
|
||||
last_group = group;
|
||||
}
|
||||
|
||||
PropertyInfo pi = ShaderLanguage::uniform_to_property_info(uniforms[E.value]);
|
||||
pi.name = E.value;
|
||||
p_param_list->push_back(pi);
|
||||
}
|
||||
}
|
||||
|
||||
void SkyShaderData::get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const {
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
RendererMaterialStorage::InstanceShaderParam p;
|
||||
p.info = ShaderLanguage::uniform_to_property_info(E.value);
|
||||
p.info.name = E.key; //supply name
|
||||
p.index = E.value.instance_index;
|
||||
p.default_value = ShaderLanguage::constant_value_to_variant(E.value.default_value, E.value.type, E.value.array_size, E.value.hint);
|
||||
p_param_list->push_back(p);
|
||||
}
|
||||
}
|
||||
|
||||
bool SkyShaderData::is_parameter_texture(const StringName &p_param) const {
|
||||
if (!uniforms.has(p_param)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return uniforms[p_param].texture_order >= 0;
|
||||
}
|
||||
|
||||
bool SkyShaderData::is_animated() const {
|
||||
return false;
|
||||
}
|
||||
|
@ -3223,15 +3148,6 @@ bool SkyShaderData::casts_shadows() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
Variant SkyShaderData::get_default_parameter(const StringName &p_parameter) const {
|
||||
if (uniforms.has(p_parameter)) {
|
||||
ShaderLanguage::ShaderNode::Uniform uniform = uniforms[p_parameter];
|
||||
Vector<ShaderLanguage::ConstantNode::Value> default_value = uniform.default_value;
|
||||
return ShaderLanguage::constant_value_to_variant(default_value, uniform.type, uniform.array_size, uniform.hint);
|
||||
}
|
||||
return Variant();
|
||||
}
|
||||
|
||||
RS::ShaderNativeSourceCode SkyShaderData::get_native_source_code() const {
|
||||
return MaterialStorage::get_singleton()->shaders.sky_shader.version_get_native_source_code(version);
|
||||
}
|
||||
|
@ -3291,10 +3207,6 @@ void SkyMaterialData::bind_uniforms() {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Scene SHADER
|
||||
|
||||
void SceneShaderData::set_path_hint(const String &p_path) {
|
||||
path = p_path;
|
||||
}
|
||||
|
||||
void SceneShaderData::set_code(const String &p_code) {
|
||||
//compile
|
||||
|
||||
|
@ -3471,86 +3383,6 @@ void SceneShaderData::set_code(const String &p_code) {
|
|||
valid = true;
|
||||
}
|
||||
|
||||
void SceneShaderData::set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index) {
|
||||
if (!p_texture.is_valid()) {
|
||||
if (default_texture_params.has(p_name) && default_texture_params[p_name].has(p_index)) {
|
||||
default_texture_params[p_name].erase(p_index);
|
||||
|
||||
if (default_texture_params[p_name].is_empty()) {
|
||||
default_texture_params.erase(p_name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!default_texture_params.has(p_name)) {
|
||||
default_texture_params[p_name] = HashMap<int, RID>();
|
||||
}
|
||||
default_texture_params[p_name][p_index] = p_texture;
|
||||
}
|
||||
}
|
||||
|
||||
void SceneShaderData::get_shader_uniform_list(List<PropertyInfo> *p_param_list) const {
|
||||
RBMap<int, StringName> order;
|
||||
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_LOCAL ||
|
||||
E.value.hint == ShaderLanguage::ShaderNode::Uniform::HINT_SCREEN_TEXTURE ||
|
||||
E.value.hint == ShaderLanguage::ShaderNode::Uniform::HINT_NORMAL_ROUGHNESS_TEXTURE ||
|
||||
E.value.hint == ShaderLanguage::ShaderNode::Uniform::HINT_DEPTH_TEXTURE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (E.value.texture_order >= 0) {
|
||||
order[E.value.texture_order + 100000] = E.key;
|
||||
} else {
|
||||
order[E.value.order] = E.key;
|
||||
}
|
||||
}
|
||||
|
||||
String last_group;
|
||||
for (const KeyValue<int, StringName> &E : order) {
|
||||
String group = uniforms[E.value].group;
|
||||
if (!uniforms[E.value].subgroup.is_empty()) {
|
||||
group += "::" + uniforms[E.value].subgroup;
|
||||
}
|
||||
|
||||
if (group != last_group) {
|
||||
PropertyInfo pi;
|
||||
pi.usage = PROPERTY_USAGE_GROUP;
|
||||
pi.name = group;
|
||||
p_param_list->push_back(pi);
|
||||
|
||||
last_group = group;
|
||||
}
|
||||
|
||||
PropertyInfo pi = ShaderLanguage::uniform_to_property_info(uniforms[E.value]);
|
||||
pi.name = E.value;
|
||||
p_param_list->push_back(pi);
|
||||
}
|
||||
}
|
||||
|
||||
void SceneShaderData::get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const {
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
RendererMaterialStorage::InstanceShaderParam p;
|
||||
p.info = ShaderLanguage::uniform_to_property_info(E.value);
|
||||
p.info.name = E.key; //supply name
|
||||
p.index = E.value.instance_index;
|
||||
p.default_value = ShaderLanguage::constant_value_to_variant(E.value.default_value, E.value.type, E.value.array_size, E.value.hint);
|
||||
p_param_list->push_back(p);
|
||||
}
|
||||
}
|
||||
|
||||
bool SceneShaderData::is_parameter_texture(const StringName &p_param) const {
|
||||
if (!uniforms.has(p_param)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return uniforms[p_param].texture_order >= 0;
|
||||
}
|
||||
|
||||
bool SceneShaderData::is_animated() const {
|
||||
return (uses_fragment_time && uses_discard) || (uses_vertex_time && uses_vertex);
|
||||
}
|
||||
|
@ -3563,15 +3395,6 @@ bool SceneShaderData::casts_shadows() const {
|
|||
return !has_alpha || (uses_depth_pre_pass && !(depth_draw == DEPTH_DRAW_DISABLED || depth_test == DEPTH_TEST_DISABLED));
|
||||
}
|
||||
|
||||
Variant SceneShaderData::get_default_parameter(const StringName &p_parameter) const {
|
||||
if (uniforms.has(p_parameter)) {
|
||||
ShaderLanguage::ShaderNode::Uniform uniform = uniforms[p_parameter];
|
||||
Vector<ShaderLanguage::ConstantNode::Value> default_value = uniform.default_value;
|
||||
return ShaderLanguage::constant_value_to_variant(default_value, uniform.type, uniform.array_size, uniform.hint);
|
||||
}
|
||||
return Variant();
|
||||
}
|
||||
|
||||
RS::ShaderNativeSourceCode SceneShaderData::get_native_source_code() const {
|
||||
return MaterialStorage::get_singleton()->shaders.scene_shader.version_get_native_source_code(version);
|
||||
}
|
||||
|
@ -3636,10 +3459,6 @@ void SceneMaterialData::bind_uniforms() {
|
|||
|
||||
/* Particles SHADER */
|
||||
|
||||
void ParticlesShaderData::set_path_hint(const String &p_path) {
|
||||
path = p_path;
|
||||
}
|
||||
|
||||
void ParticlesShaderData::set_code(const String &p_code) {
|
||||
//compile
|
||||
|
||||
|
@ -3696,83 +3515,6 @@ void ParticlesShaderData::set_code(const String &p_code) {
|
|||
valid = true;
|
||||
}
|
||||
|
||||
void ParticlesShaderData::set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index) {
|
||||
if (!p_texture.is_valid()) {
|
||||
if (default_texture_params.has(p_name) && default_texture_params[p_name].has(p_index)) {
|
||||
default_texture_params[p_name].erase(p_index);
|
||||
|
||||
if (default_texture_params[p_name].is_empty()) {
|
||||
default_texture_params.erase(p_name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!default_texture_params.has(p_name)) {
|
||||
default_texture_params[p_name] = HashMap<int, RID>();
|
||||
}
|
||||
default_texture_params[p_name][p_index] = p_texture;
|
||||
}
|
||||
}
|
||||
|
||||
void ParticlesShaderData::get_shader_uniform_list(List<PropertyInfo> *p_param_list) const {
|
||||
HashMap<int, StringName> order;
|
||||
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope == ShaderLanguage::ShaderNode::Uniform::SCOPE_GLOBAL || E.value.scope == ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (E.value.texture_order >= 0) {
|
||||
order[E.value.texture_order + 100000] = E.key;
|
||||
} else {
|
||||
order[E.value.order] = E.key;
|
||||
}
|
||||
}
|
||||
|
||||
String last_group;
|
||||
for (const KeyValue<int, StringName> &E : order) {
|
||||
String group = uniforms[E.value].group;
|
||||
if (!uniforms[E.value].subgroup.is_empty()) {
|
||||
group += "::" + uniforms[E.value].subgroup;
|
||||
}
|
||||
|
||||
if (group != last_group) {
|
||||
PropertyInfo pi;
|
||||
pi.usage = PROPERTY_USAGE_GROUP;
|
||||
pi.name = group;
|
||||
p_param_list->push_back(pi);
|
||||
|
||||
last_group = group;
|
||||
}
|
||||
|
||||
PropertyInfo pi = ShaderLanguage::uniform_to_property_info(uniforms[E.value]);
|
||||
pi.name = E.value;
|
||||
p_param_list->push_back(pi);
|
||||
}
|
||||
}
|
||||
|
||||
void ParticlesShaderData::get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const {
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
RendererMaterialStorage::InstanceShaderParam p;
|
||||
p.info = ShaderLanguage::uniform_to_property_info(E.value);
|
||||
p.info.name = E.key; //supply name
|
||||
p.index = E.value.instance_index;
|
||||
p.default_value = ShaderLanguage::constant_value_to_variant(E.value.default_value, E.value.type, E.value.array_size, E.value.hint);
|
||||
p_param_list->push_back(p);
|
||||
}
|
||||
}
|
||||
|
||||
bool ParticlesShaderData::is_parameter_texture(const StringName &p_param) const {
|
||||
if (!uniforms.has(p_param)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return uniforms[p_param].texture_order >= 0;
|
||||
}
|
||||
|
||||
bool ParticlesShaderData::is_animated() const {
|
||||
return false;
|
||||
}
|
||||
|
@ -3781,15 +3523,6 @@ bool ParticlesShaderData::casts_shadows() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
Variant ParticlesShaderData::get_default_parameter(const StringName &p_parameter) const {
|
||||
if (uniforms.has(p_parameter)) {
|
||||
ShaderLanguage::ShaderNode::Uniform uniform = uniforms[p_parameter];
|
||||
Vector<ShaderLanguage::ConstantNode::Value> default_value = uniform.default_value;
|
||||
return ShaderLanguage::constant_value_to_variant(default_value, uniform.type, uniform.array_size, uniform.hint);
|
||||
}
|
||||
return Variant();
|
||||
}
|
||||
|
||||
RS::ShaderNativeSourceCode ParticlesShaderData::get_native_source_code() const {
|
||||
return MaterialStorage::get_singleton()->shaders.particles_process_shader.version_get_native_source_code(version);
|
||||
}
|
||||
|
|
|
@ -53,16 +53,20 @@ namespace GLES3 {
|
|||
/* Shader Structs */
|
||||
|
||||
struct ShaderData {
|
||||
virtual void set_code(const String &p_Code) = 0;
|
||||
virtual void set_path_hint(const String &p_hint) = 0;
|
||||
virtual void set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index) = 0;
|
||||
virtual void get_shader_uniform_list(List<PropertyInfo> *p_param_list) const = 0;
|
||||
String path;
|
||||
HashMap<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
|
||||
HashMap<StringName, HashMap<int, RID>> default_texture_params;
|
||||
|
||||
virtual void get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const = 0;
|
||||
virtual bool is_parameter_texture(const StringName &p_param) const = 0;
|
||||
virtual void set_path_hint(const String &p_hint);
|
||||
virtual void set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index);
|
||||
virtual Variant get_default_parameter(const StringName &p_parameter) const;
|
||||
virtual void get_shader_uniform_list(List<PropertyInfo> *p_param_list) const;
|
||||
virtual void get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const;
|
||||
virtual bool is_parameter_texture(const StringName &p_param) const;
|
||||
|
||||
virtual void set_code(const String &p_Code) = 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 RS::ShaderNativeSourceCode get_native_source_code() const { return RS::ShaderNativeSourceCode(); }
|
||||
|
||||
virtual ~ShaderData() {}
|
||||
|
@ -149,17 +153,14 @@ struct CanvasShaderData : public ShaderData {
|
|||
|
||||
bool valid;
|
||||
RID version;
|
||||
String path;
|
||||
BlendMode blend_mode = BLEND_MODE_MIX;
|
||||
|
||||
HashMap<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
|
||||
Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms;
|
||||
|
||||
Vector<uint32_t> ubo_offsets;
|
||||
uint32_t ubo_size;
|
||||
|
||||
String code;
|
||||
HashMap<StringName, HashMap<int, RID>> default_texture_params;
|
||||
|
||||
bool uses_screen_texture = false;
|
||||
bool uses_screen_texture_mipmaps = false;
|
||||
|
@ -167,15 +168,8 @@ struct CanvasShaderData : public ShaderData {
|
|||
bool uses_time = false;
|
||||
|
||||
virtual void set_code(const String &p_Code);
|
||||
virtual void set_path_hint(const String &p_hint);
|
||||
virtual void set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index);
|
||||
virtual void get_shader_uniform_list(List<PropertyInfo> *p_param_list) const;
|
||||
virtual void get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const;
|
||||
|
||||
virtual bool is_parameter_texture(const StringName &p_param) const;
|
||||
virtual bool is_animated() const;
|
||||
virtual bool casts_shadows() const;
|
||||
virtual Variant get_default_parameter(const StringName &p_parameter) const;
|
||||
virtual RS::ShaderNativeSourceCode get_native_source_code() const;
|
||||
|
||||
CanvasShaderData();
|
||||
|
@ -202,15 +196,12 @@ struct SkyShaderData : public ShaderData {
|
|||
bool valid;
|
||||
RID version;
|
||||
|
||||
HashMap<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
|
||||
Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms;
|
||||
|
||||
Vector<uint32_t> ubo_offsets;
|
||||
uint32_t ubo_size;
|
||||
|
||||
String path;
|
||||
String code;
|
||||
HashMap<StringName, HashMap<int, RID>> default_texture_params;
|
||||
|
||||
bool uses_time;
|
||||
bool uses_position;
|
||||
|
@ -219,14 +210,8 @@ struct SkyShaderData : public ShaderData {
|
|||
bool uses_light;
|
||||
|
||||
virtual void set_code(const String &p_Code);
|
||||
virtual void set_path_hint(const String &p_hint);
|
||||
virtual void set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index);
|
||||
virtual void get_shader_uniform_list(List<PropertyInfo> *p_param_list) const;
|
||||
virtual void get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const;
|
||||
virtual bool is_parameter_texture(const StringName &p_param) const;
|
||||
virtual bool is_animated() const;
|
||||
virtual bool casts_shadows() const;
|
||||
virtual Variant get_default_parameter(const StringName &p_parameter) const;
|
||||
virtual RS::ShaderNativeSourceCode get_native_source_code() const;
|
||||
SkyShaderData();
|
||||
virtual ~SkyShaderData();
|
||||
|
@ -284,16 +269,12 @@ struct SceneShaderData : public ShaderData {
|
|||
bool valid;
|
||||
RID version;
|
||||
|
||||
String path;
|
||||
|
||||
HashMap<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
|
||||
Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms;
|
||||
|
||||
Vector<uint32_t> ubo_offsets;
|
||||
uint32_t ubo_size;
|
||||
|
||||
String code;
|
||||
HashMap<StringName, HashMap<int, RID>> default_texture_params;
|
||||
|
||||
BlendMode blend_mode;
|
||||
AlphaAntiAliasing alpha_antialiasing_mode;
|
||||
|
@ -343,15 +324,8 @@ struct SceneShaderData : public ShaderData {
|
|||
uint32_t index = 0;
|
||||
|
||||
virtual void set_code(const String &p_Code);
|
||||
virtual void set_path_hint(const String &p_hint);
|
||||
virtual void set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index);
|
||||
virtual void get_shader_uniform_list(List<PropertyInfo> *p_param_list) const;
|
||||
virtual void get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const;
|
||||
|
||||
virtual bool is_parameter_texture(const StringName &p_param) const;
|
||||
virtual bool is_animated() const;
|
||||
virtual bool casts_shadows() const;
|
||||
virtual Variant get_default_parameter(const StringName &p_parameter) const;
|
||||
virtual RS::ShaderNativeSourceCode get_native_source_code() const;
|
||||
|
||||
SceneShaderData();
|
||||
|
@ -386,15 +360,12 @@ struct ParticlesShaderData : public ShaderData {
|
|||
RID version;
|
||||
bool uses_collision = false;
|
||||
|
||||
HashMap<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
|
||||
Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms;
|
||||
|
||||
Vector<uint32_t> ubo_offsets;
|
||||
uint32_t ubo_size = 0;
|
||||
|
||||
String path;
|
||||
String code;
|
||||
HashMap<StringName, HashMap<int, RID>> default_texture_params;
|
||||
|
||||
bool uses_time = false;
|
||||
|
||||
|
@ -402,14 +373,8 @@ struct ParticlesShaderData : public ShaderData {
|
|||
uint32_t userdata_count = 0;
|
||||
|
||||
virtual void set_code(const String &p_Code);
|
||||
virtual void set_path_hint(const String &p_hint);
|
||||
virtual void set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index);
|
||||
virtual void get_shader_uniform_list(List<PropertyInfo> *p_param_list) const;
|
||||
virtual void get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const;
|
||||
virtual bool is_parameter_texture(const StringName &p_param) const;
|
||||
virtual bool is_animated() const;
|
||||
virtual bool casts_shadows() const;
|
||||
virtual Variant get_default_parameter(const StringName &p_parameter) const;
|
||||
virtual RS::ShaderNativeSourceCode get_native_source_code() const;
|
||||
|
||||
ParticlesShaderData() {}
|
||||
|
|
|
@ -319,10 +319,6 @@ void Fog::free_fog_shader() {
|
|||
material_storage->material_free(volumetric_fog.default_material);
|
||||
}
|
||||
|
||||
void Fog::FogShaderData::set_path_hint(const String &p_path) {
|
||||
path = p_path;
|
||||
}
|
||||
|
||||
void Fog::FogShaderData::set_code(const String &p_code) {
|
||||
//compile
|
||||
|
||||
|
@ -366,83 +362,6 @@ void Fog::FogShaderData::set_code(const String &p_code) {
|
|||
valid = true;
|
||||
}
|
||||
|
||||
void Fog::FogShaderData::set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index) {
|
||||
if (!p_texture.is_valid()) {
|
||||
if (default_texture_params.has(p_name) && default_texture_params[p_name].has(p_index)) {
|
||||
default_texture_params[p_name].erase(p_index);
|
||||
|
||||
if (default_texture_params[p_name].is_empty()) {
|
||||
default_texture_params.erase(p_name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!default_texture_params.has(p_name)) {
|
||||
default_texture_params[p_name] = HashMap<int, RID>();
|
||||
}
|
||||
default_texture_params[p_name][p_index] = p_texture;
|
||||
}
|
||||
}
|
||||
|
||||
void Fog::FogShaderData::get_shader_uniform_list(List<PropertyInfo> *p_param_list) const {
|
||||
RBMap<int, StringName> order;
|
||||
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope == ShaderLanguage::ShaderNode::Uniform::SCOPE_GLOBAL || E.value.scope == ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (E.value.texture_order >= 0) {
|
||||
order[E.value.texture_order + 100000] = E.key;
|
||||
} else {
|
||||
order[E.value.order] = E.key;
|
||||
}
|
||||
}
|
||||
|
||||
String last_group;
|
||||
for (const KeyValue<int, StringName> &E : order) {
|
||||
String group = uniforms[E.value].group;
|
||||
if (!uniforms[E.value].subgroup.is_empty()) {
|
||||
group += "::" + uniforms[E.value].subgroup;
|
||||
}
|
||||
|
||||
if (group != last_group) {
|
||||
PropertyInfo pi;
|
||||
pi.usage = PROPERTY_USAGE_GROUP;
|
||||
pi.name = group;
|
||||
p_param_list->push_back(pi);
|
||||
|
||||
last_group = group;
|
||||
}
|
||||
|
||||
PropertyInfo pi = ShaderLanguage::uniform_to_property_info(uniforms[E.value]);
|
||||
pi.name = E.value;
|
||||
p_param_list->push_back(pi);
|
||||
}
|
||||
}
|
||||
|
||||
void Fog::FogShaderData::get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const {
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
RendererMaterialStorage::InstanceShaderParam p;
|
||||
p.info = ShaderLanguage::uniform_to_property_info(E.value);
|
||||
p.info.name = E.key; //supply name
|
||||
p.index = E.value.instance_index;
|
||||
p.default_value = ShaderLanguage::constant_value_to_variant(E.value.default_value, E.value.type, E.value.array_size, E.value.hint);
|
||||
p_param_list->push_back(p);
|
||||
}
|
||||
}
|
||||
|
||||
bool Fog::FogShaderData::is_parameter_texture(const StringName &p_param) const {
|
||||
if (!uniforms.has(p_param)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return uniforms[p_param].texture_order >= 0;
|
||||
}
|
||||
|
||||
bool Fog::FogShaderData::is_animated() const {
|
||||
return false;
|
||||
}
|
||||
|
@ -451,15 +370,6 @@ bool Fog::FogShaderData::casts_shadows() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
Variant Fog::FogShaderData::get_default_parameter(const StringName &p_parameter) const {
|
||||
if (uniforms.has(p_parameter)) {
|
||||
ShaderLanguage::ShaderNode::Uniform uniform = uniforms[p_parameter];
|
||||
Vector<ShaderLanguage::ConstantNode::Value> default_value = uniform.default_value;
|
||||
return ShaderLanguage::constant_value_to_variant(default_value, uniform.type, uniform.array_size, uniform.hint);
|
||||
}
|
||||
return Variant();
|
||||
}
|
||||
|
||||
RS::ShaderNativeSourceCode Fog::FogShaderData::get_native_source_code() const {
|
||||
Fog *fog_singleton = Fog::get_singleton();
|
||||
|
||||
|
|
|
@ -188,27 +188,18 @@ private:
|
|||
RID version;
|
||||
|
||||
RID pipeline;
|
||||
HashMap<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
|
||||
Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms;
|
||||
|
||||
Vector<uint32_t> ubo_offsets;
|
||||
uint32_t ubo_size = 0;
|
||||
|
||||
String path;
|
||||
String code;
|
||||
HashMap<StringName, HashMap<int, RID>> default_texture_params;
|
||||
|
||||
bool uses_time = false;
|
||||
|
||||
virtual void set_path_hint(const String &p_hint);
|
||||
virtual void set_code(const String &p_Code);
|
||||
virtual void set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index);
|
||||
virtual void get_shader_uniform_list(List<PropertyInfo> *p_param_list) const;
|
||||
virtual void get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const;
|
||||
virtual bool is_parameter_texture(const StringName &p_param) const;
|
||||
virtual bool is_animated() const;
|
||||
virtual bool casts_shadows() const;
|
||||
virtual Variant get_default_parameter(const StringName &p_parameter) const;
|
||||
virtual RS::ShaderNativeSourceCode get_native_source_code() const;
|
||||
|
||||
FogShaderData() {}
|
||||
|
|
|
@ -45,10 +45,6 @@ using namespace RendererRD;
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// SKY SHADER
|
||||
|
||||
void SkyRD::SkyShaderData::set_path_hint(const String &p_path) {
|
||||
path = p_path;
|
||||
}
|
||||
|
||||
void SkyRD::SkyShaderData::set_code(const String &p_code) {
|
||||
//compile
|
||||
|
||||
|
@ -152,82 +148,6 @@ void SkyRD::SkyShaderData::set_code(const String &p_code) {
|
|||
valid = true;
|
||||
}
|
||||
|
||||
void SkyRD::SkyShaderData::set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index) {
|
||||
if (!p_texture.is_valid()) {
|
||||
if (default_texture_params.has(p_name) && default_texture_params[p_name].has(p_index)) {
|
||||
default_texture_params[p_name].erase(p_index);
|
||||
|
||||
if (default_texture_params[p_name].is_empty()) {
|
||||
default_texture_params.erase(p_name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!default_texture_params.has(p_name)) {
|
||||
default_texture_params[p_name] = HashMap<int, RID>();
|
||||
}
|
||||
default_texture_params[p_name][p_index] = p_texture;
|
||||
}
|
||||
}
|
||||
|
||||
void SkyRD::SkyShaderData::get_shader_uniform_list(List<PropertyInfo> *p_param_list) const {
|
||||
HashMap<int, StringName> order;
|
||||
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope == ShaderLanguage::ShaderNode::Uniform::SCOPE_GLOBAL || E.value.scope == ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (E.value.texture_order >= 0) {
|
||||
order[E.value.texture_order + 100000] = E.key;
|
||||
} else {
|
||||
order[E.value.order] = E.key;
|
||||
}
|
||||
}
|
||||
String last_group;
|
||||
for (const KeyValue<int, StringName> &E : order) {
|
||||
String group = uniforms[E.value].group;
|
||||
if (!uniforms[E.value].subgroup.is_empty()) {
|
||||
group += "::" + uniforms[E.value].subgroup;
|
||||
}
|
||||
|
||||
if (group != last_group) {
|
||||
PropertyInfo pi;
|
||||
pi.usage = PROPERTY_USAGE_GROUP;
|
||||
pi.name = group;
|
||||
p_param_list->push_back(pi);
|
||||
|
||||
last_group = group;
|
||||
}
|
||||
|
||||
PropertyInfo pi = ShaderLanguage::uniform_to_property_info(uniforms[E.value]);
|
||||
pi.name = E.value;
|
||||
p_param_list->push_back(pi);
|
||||
}
|
||||
}
|
||||
|
||||
void SkyRD::SkyShaderData::get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const {
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
RendererMaterialStorage::InstanceShaderParam p;
|
||||
p.info = ShaderLanguage::uniform_to_property_info(E.value);
|
||||
p.info.name = E.key; //supply name
|
||||
p.index = E.value.instance_index;
|
||||
p.default_value = ShaderLanguage::constant_value_to_variant(E.value.default_value, E.value.type, E.value.array_size, E.value.hint);
|
||||
p_param_list->push_back(p);
|
||||
}
|
||||
}
|
||||
|
||||
bool SkyRD::SkyShaderData::is_parameter_texture(const StringName &p_param) const {
|
||||
if (!uniforms.has(p_param)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return uniforms[p_param].texture_order >= 0;
|
||||
}
|
||||
|
||||
bool SkyRD::SkyShaderData::is_animated() const {
|
||||
return false;
|
||||
}
|
||||
|
@ -236,15 +156,6 @@ bool SkyRD::SkyShaderData::casts_shadows() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
Variant SkyRD::SkyShaderData::get_default_parameter(const StringName &p_parameter) const {
|
||||
if (uniforms.has(p_parameter)) {
|
||||
ShaderLanguage::ShaderNode::Uniform uniform = uniforms[p_parameter];
|
||||
Vector<ShaderLanguage::ConstantNode::Value> default_value = uniform.default_value;
|
||||
return ShaderLanguage::constant_value_to_variant(default_value, uniform.type, uniform.array_size, uniform.hint);
|
||||
}
|
||||
return Variant();
|
||||
}
|
||||
|
||||
RS::ShaderNativeSourceCode SkyRD::SkyShaderData::get_native_source_code() const {
|
||||
RendererSceneRenderRD *scene_singleton = static_cast<RendererSceneRenderRD *>(RendererSceneRenderRD::singleton);
|
||||
|
||||
|
|
|
@ -112,15 +112,12 @@ private:
|
|||
RID version;
|
||||
|
||||
PipelineCacheRD pipelines[SKY_VERSION_MAX];
|
||||
HashMap<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
|
||||
Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms;
|
||||
|
||||
Vector<uint32_t> ubo_offsets;
|
||||
uint32_t ubo_size = 0;
|
||||
|
||||
String path;
|
||||
String code;
|
||||
HashMap<StringName, HashMap<int, RID>> default_texture_params;
|
||||
|
||||
bool uses_time = false;
|
||||
bool uses_position = false;
|
||||
|
@ -129,14 +126,8 @@ private:
|
|||
bool uses_light = false;
|
||||
|
||||
virtual void set_code(const String &p_Code);
|
||||
virtual void set_path_hint(const String &p_hint);
|
||||
virtual void set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index);
|
||||
virtual void get_shader_uniform_list(List<PropertyInfo> *p_param_list) const;
|
||||
virtual void get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const;
|
||||
virtual bool is_parameter_texture(const StringName &p_param) const;
|
||||
virtual bool is_animated() const;
|
||||
virtual bool casts_shadows() const;
|
||||
virtual Variant get_default_parameter(const StringName &p_parameter) const;
|
||||
virtual RS::ShaderNativeSourceCode get_native_source_code() const;
|
||||
|
||||
SkyShaderData() {}
|
||||
|
|
|
@ -37,10 +37,6 @@
|
|||
|
||||
using namespace RendererSceneRenderImplementation;
|
||||
|
||||
void SceneShaderForwardClustered::ShaderData::set_path_hint(const String &p_path) {
|
||||
path = p_path;
|
||||
}
|
||||
|
||||
void SceneShaderForwardClustered::ShaderData::set_code(const String &p_code) {
|
||||
//compile
|
||||
|
||||
|
@ -380,87 +376,6 @@ void SceneShaderForwardClustered::ShaderData::set_code(const String &p_code) {
|
|||
valid = true;
|
||||
}
|
||||
|
||||
void SceneShaderForwardClustered::ShaderData::set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index) {
|
||||
if (!p_texture.is_valid()) {
|
||||
if (default_texture_params.has(p_name) && default_texture_params[p_name].has(p_index)) {
|
||||
default_texture_params[p_name].erase(p_index);
|
||||
|
||||
if (default_texture_params[p_name].is_empty()) {
|
||||
default_texture_params.erase(p_name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!default_texture_params.has(p_name)) {
|
||||
default_texture_params[p_name] = HashMap<int, RID>();
|
||||
}
|
||||
default_texture_params[p_name][p_index] = p_texture;
|
||||
}
|
||||
}
|
||||
|
||||
void SceneShaderForwardClustered::ShaderData::get_shader_uniform_list(List<PropertyInfo> *p_param_list) const {
|
||||
HashMap<int, StringName> order;
|
||||
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_LOCAL ||
|
||||
E.value.hint == ShaderLanguage::ShaderNode::Uniform::HINT_SCREEN_TEXTURE ||
|
||||
E.value.hint == ShaderLanguage::ShaderNode::Uniform::HINT_NORMAL_ROUGHNESS_TEXTURE ||
|
||||
E.value.hint == ShaderLanguage::ShaderNode::Uniform::HINT_DEPTH_TEXTURE) {
|
||||
// Don't expose any of these.
|
||||
continue;
|
||||
}
|
||||
|
||||
if (E.value.texture_order >= 0) {
|
||||
order[E.value.texture_order + 100000] = E.key;
|
||||
} else {
|
||||
order[E.value.order] = E.key;
|
||||
}
|
||||
}
|
||||
|
||||
String last_group;
|
||||
for (const KeyValue<int, StringName> &E : order) {
|
||||
String group = uniforms[E.value].group;
|
||||
if (!uniforms[E.value].subgroup.is_empty()) {
|
||||
group += "::" + uniforms[E.value].subgroup;
|
||||
}
|
||||
|
||||
if (group != last_group) {
|
||||
PropertyInfo pi;
|
||||
pi.usage = PROPERTY_USAGE_GROUP;
|
||||
pi.name = group;
|
||||
p_param_list->push_back(pi);
|
||||
|
||||
last_group = group;
|
||||
}
|
||||
|
||||
PropertyInfo pi = ShaderLanguage::uniform_to_property_info(uniforms[E.value]);
|
||||
pi.name = E.value;
|
||||
p_param_list->push_back(pi);
|
||||
}
|
||||
}
|
||||
|
||||
void SceneShaderForwardClustered::ShaderData::get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const {
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
RendererMaterialStorage::InstanceShaderParam p;
|
||||
p.info = ShaderLanguage::uniform_to_property_info(E.value);
|
||||
p.info.name = E.key; //supply name
|
||||
p.index = E.value.instance_index;
|
||||
p.default_value = ShaderLanguage::constant_value_to_variant(E.value.default_value, E.value.type, E.value.array_size, E.value.hint);
|
||||
p_param_list->push_back(p);
|
||||
}
|
||||
}
|
||||
|
||||
bool SceneShaderForwardClustered::ShaderData::is_parameter_texture(const StringName &p_param) const {
|
||||
if (!uniforms.has(p_param)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return uniforms[p_param].texture_order >= 0;
|
||||
}
|
||||
|
||||
bool SceneShaderForwardClustered::ShaderData::is_animated() const {
|
||||
return (uses_fragment_time && uses_discard) || (uses_vertex_time && uses_vertex);
|
||||
}
|
||||
|
@ -473,15 +388,6 @@ bool SceneShaderForwardClustered::ShaderData::casts_shadows() const {
|
|||
return !has_alpha || (uses_depth_pre_pass && !(depth_draw == DEPTH_DRAW_DISABLED || depth_test == DEPTH_TEST_DISABLED));
|
||||
}
|
||||
|
||||
Variant SceneShaderForwardClustered::ShaderData::get_default_parameter(const StringName &p_parameter) const {
|
||||
if (uniforms.has(p_parameter)) {
|
||||
ShaderLanguage::ShaderNode::Uniform uniform = uniforms[p_parameter];
|
||||
Vector<ShaderLanguage::ConstantNode::Value> default_value = uniform.default_value;
|
||||
return ShaderLanguage::constant_value_to_variant(default_value, uniform.type, uniform.array_size, uniform.hint);
|
||||
}
|
||||
return Variant();
|
||||
}
|
||||
|
||||
RS::ShaderNativeSourceCode SceneShaderForwardClustered::ShaderData::get_native_source_code() const {
|
||||
SceneShaderForwardClustered *shader_singleton = (SceneShaderForwardClustered *)SceneShaderForwardClustered::singleton;
|
||||
|
||||
|
|
|
@ -139,16 +139,12 @@ public:
|
|||
PipelineCacheRD pipelines[CULL_VARIANT_MAX][RS::PRIMITIVE_MAX][PIPELINE_VERSION_MAX];
|
||||
PipelineCacheRD color_pipelines[CULL_VARIANT_MAX][RS::PRIMITIVE_MAX][PIPELINE_COLOR_PASS_FLAG_COUNT];
|
||||
|
||||
String path;
|
||||
|
||||
HashMap<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
|
||||
Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms;
|
||||
|
||||
Vector<uint32_t> ubo_offsets;
|
||||
uint32_t ubo_size = 0;
|
||||
|
||||
String code;
|
||||
HashMap<StringName, HashMap<int, RID>> default_texture_params;
|
||||
|
||||
DepthDraw depth_draw = DEPTH_DRAW_OPAQUE;
|
||||
DepthTest depth_test = DEPTH_TEST_ENABLED;
|
||||
|
@ -183,15 +179,9 @@ public:
|
|||
uint32_t index = 0;
|
||||
|
||||
virtual void set_code(const String &p_Code);
|
||||
virtual void set_path_hint(const String &p_path);
|
||||
virtual void set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index);
|
||||
virtual void get_shader_uniform_list(List<PropertyInfo> *p_param_list) const;
|
||||
void get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const;
|
||||
|
||||
virtual bool is_parameter_texture(const StringName &p_param) const;
|
||||
virtual bool is_animated() const;
|
||||
virtual bool casts_shadows() const;
|
||||
virtual Variant get_default_parameter(const StringName &p_parameter) const;
|
||||
virtual RS::ShaderNativeSourceCode get_native_source_code() const;
|
||||
|
||||
SelfList<ShaderData> shader_list_element;
|
||||
|
|
|
@ -39,10 +39,6 @@ using namespace RendererSceneRenderImplementation;
|
|||
|
||||
/* ShaderData */
|
||||
|
||||
void SceneShaderForwardMobile::ShaderData::set_path_hint(const String &p_path) {
|
||||
path = p_path;
|
||||
}
|
||||
|
||||
void SceneShaderForwardMobile::ShaderData::set_code(const String &p_code) {
|
||||
//compile
|
||||
|
||||
|
@ -336,86 +332,6 @@ void SceneShaderForwardMobile::ShaderData::set_code(const String &p_code) {
|
|||
valid = true;
|
||||
}
|
||||
|
||||
void SceneShaderForwardMobile::ShaderData::set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index) {
|
||||
if (!p_texture.is_valid()) {
|
||||
if (default_texture_params.has(p_name) && default_texture_params[p_name].has(p_index)) {
|
||||
default_texture_params[p_name].erase(p_index);
|
||||
|
||||
if (default_texture_params[p_name].is_empty()) {
|
||||
default_texture_params.erase(p_name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!default_texture_params.has(p_name)) {
|
||||
default_texture_params[p_name] = HashMap<int, RID>();
|
||||
}
|
||||
default_texture_params[p_name][p_index] = p_texture;
|
||||
}
|
||||
}
|
||||
|
||||
void SceneShaderForwardMobile::ShaderData::get_shader_uniform_list(List<PropertyInfo> *p_param_list) const {
|
||||
HashMap<int, StringName> order;
|
||||
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_LOCAL ||
|
||||
E.value.hint == ShaderLanguage::ShaderNode::Uniform::HINT_SCREEN_TEXTURE ||
|
||||
E.value.hint == ShaderLanguage::ShaderNode::Uniform::HINT_NORMAL_ROUGHNESS_TEXTURE ||
|
||||
E.value.hint == ShaderLanguage::ShaderNode::Uniform::HINT_DEPTH_TEXTURE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (E.value.texture_order >= 0) {
|
||||
order[E.value.texture_order + 100000] = E.key;
|
||||
} else {
|
||||
order[E.value.order] = E.key;
|
||||
}
|
||||
}
|
||||
|
||||
String last_group;
|
||||
for (const KeyValue<int, StringName> &E : order) {
|
||||
String group = uniforms[E.value].group;
|
||||
if (!uniforms[E.value].subgroup.is_empty()) {
|
||||
group += "::" + uniforms[E.value].subgroup;
|
||||
}
|
||||
|
||||
if (group != last_group) {
|
||||
PropertyInfo pi;
|
||||
pi.usage = PROPERTY_USAGE_GROUP;
|
||||
pi.name = group;
|
||||
p_param_list->push_back(pi);
|
||||
|
||||
last_group = group;
|
||||
}
|
||||
|
||||
PropertyInfo pi = ShaderLanguage::uniform_to_property_info(uniforms[E.value]);
|
||||
pi.name = E.value;
|
||||
p_param_list->push_back(pi);
|
||||
}
|
||||
}
|
||||
|
||||
void SceneShaderForwardMobile::ShaderData::get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const {
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
RendererMaterialStorage::InstanceShaderParam p;
|
||||
p.info = ShaderLanguage::uniform_to_property_info(E.value);
|
||||
p.info.name = E.key; //supply name
|
||||
p.index = E.value.instance_index;
|
||||
p.default_value = ShaderLanguage::constant_value_to_variant(E.value.default_value, E.value.type, E.value.array_size, E.value.hint);
|
||||
p_param_list->push_back(p);
|
||||
}
|
||||
}
|
||||
|
||||
bool SceneShaderForwardMobile::ShaderData::is_parameter_texture(const StringName &p_param) const {
|
||||
if (!uniforms.has(p_param)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return uniforms[p_param].texture_order >= 0;
|
||||
}
|
||||
|
||||
bool SceneShaderForwardMobile::ShaderData::is_animated() const {
|
||||
return (uses_fragment_time && uses_discard) || (uses_vertex_time && uses_vertex);
|
||||
}
|
||||
|
@ -428,15 +344,6 @@ bool SceneShaderForwardMobile::ShaderData::casts_shadows() const {
|
|||
return !has_alpha || (uses_depth_pre_pass && !(depth_draw == DEPTH_DRAW_DISABLED || depth_test == DEPTH_TEST_DISABLED));
|
||||
}
|
||||
|
||||
Variant SceneShaderForwardMobile::ShaderData::get_default_parameter(const StringName &p_parameter) const {
|
||||
if (uniforms.has(p_parameter)) {
|
||||
ShaderLanguage::ShaderNode::Uniform uniform = uniforms[p_parameter];
|
||||
Vector<ShaderLanguage::ConstantNode::Value> default_value = uniform.default_value;
|
||||
return ShaderLanguage::constant_value_to_variant(default_value, uniform.type, uniform.array_size, uniform.hint);
|
||||
}
|
||||
return Variant();
|
||||
}
|
||||
|
||||
RS::ShaderNativeSourceCode SceneShaderForwardMobile::ShaderData::get_native_source_code() const {
|
||||
SceneShaderForwardMobile *shader_singleton = (SceneShaderForwardMobile *)SceneShaderForwardMobile::singleton;
|
||||
|
||||
|
|
|
@ -100,16 +100,12 @@ public:
|
|||
uint32_t vertex_input_mask = 0;
|
||||
PipelineCacheRD pipelines[CULL_VARIANT_MAX][RS::PRIMITIVE_MAX][SHADER_VERSION_MAX];
|
||||
|
||||
String path;
|
||||
|
||||
HashMap<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
|
||||
Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms;
|
||||
|
||||
Vector<uint32_t> ubo_offsets;
|
||||
uint32_t ubo_size = 0;
|
||||
|
||||
String code;
|
||||
HashMap<StringName, HashMap<int, RID>> default_texture_params;
|
||||
|
||||
DepthDraw depth_draw;
|
||||
DepthTest depth_test;
|
||||
|
@ -141,16 +137,8 @@ public:
|
|||
uint32_t index = 0;
|
||||
|
||||
virtual void set_code(const String &p_Code);
|
||||
virtual void set_path_hint(const String &p_path);
|
||||
|
||||
virtual void set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index);
|
||||
virtual void get_shader_uniform_list(List<PropertyInfo> *p_param_list) const;
|
||||
void get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const;
|
||||
|
||||
virtual bool is_parameter_texture(const StringName &p_param) const;
|
||||
virtual bool is_animated() const;
|
||||
virtual bool casts_shadows() const;
|
||||
virtual Variant get_default_parameter(const StringName &p_parameter) const;
|
||||
virtual RS::ShaderNativeSourceCode get_native_source_code() const;
|
||||
|
||||
SelfList<ShaderData> shader_list_element;
|
||||
|
|
|
@ -2001,10 +2001,6 @@ void RendererCanvasRenderRD::occluder_polygon_set_cull_mode(RID p_occluder, RS::
|
|||
oc->cull_mode = p_mode;
|
||||
}
|
||||
|
||||
void RendererCanvasRenderRD::CanvasShaderData::set_path_hint(const String &p_path) {
|
||||
path = p_path;
|
||||
}
|
||||
|
||||
void RendererCanvasRenderRD::CanvasShaderData::set_code(const String &p_code) {
|
||||
//compile
|
||||
|
||||
|
@ -2216,86 +2212,6 @@ void RendererCanvasRenderRD::CanvasShaderData::set_code(const String &p_code) {
|
|||
valid = true;
|
||||
}
|
||||
|
||||
void RendererCanvasRenderRD::CanvasShaderData::set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index) {
|
||||
if (!p_texture.is_valid()) {
|
||||
if (default_texture_params.has(p_name) && default_texture_params[p_name].has(p_index)) {
|
||||
default_texture_params[p_name].erase(p_index);
|
||||
|
||||
if (default_texture_params[p_name].is_empty()) {
|
||||
default_texture_params.erase(p_name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!default_texture_params.has(p_name)) {
|
||||
default_texture_params[p_name] = HashMap<int, RID>();
|
||||
}
|
||||
default_texture_params[p_name][p_index] = p_texture;
|
||||
}
|
||||
}
|
||||
|
||||
void RendererCanvasRenderRD::CanvasShaderData::get_shader_uniform_list(List<PropertyInfo> *p_param_list) const {
|
||||
HashMap<int, StringName> order;
|
||||
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_LOCAL ||
|
||||
E.value.hint == ShaderLanguage::ShaderNode::Uniform::HINT_SCREEN_TEXTURE ||
|
||||
E.value.hint == ShaderLanguage::ShaderNode::Uniform::HINT_NORMAL_ROUGHNESS_TEXTURE ||
|
||||
E.value.hint == ShaderLanguage::ShaderNode::Uniform::HINT_DEPTH_TEXTURE) {
|
||||
// Don't expose any of these.
|
||||
continue;
|
||||
}
|
||||
if (E.value.texture_order >= 0) {
|
||||
order[E.value.texture_order + 100000] = E.key;
|
||||
} else {
|
||||
order[E.value.order] = E.key;
|
||||
}
|
||||
}
|
||||
|
||||
String last_group;
|
||||
for (const KeyValue<int, StringName> &E : order) {
|
||||
String group = uniforms[E.value].group;
|
||||
if (!uniforms[E.value].subgroup.is_empty()) {
|
||||
group += "::" + uniforms[E.value].subgroup;
|
||||
}
|
||||
|
||||
if (group != last_group) {
|
||||
PropertyInfo pi;
|
||||
pi.usage = PROPERTY_USAGE_GROUP;
|
||||
pi.name = group;
|
||||
p_param_list->push_back(pi);
|
||||
|
||||
last_group = group;
|
||||
}
|
||||
|
||||
PropertyInfo pi = ShaderLanguage::uniform_to_property_info(uniforms[E.value]);
|
||||
pi.name = E.value;
|
||||
p_param_list->push_back(pi);
|
||||
}
|
||||
}
|
||||
|
||||
void RendererCanvasRenderRD::CanvasShaderData::get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const {
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
RendererMaterialStorage::InstanceShaderParam p;
|
||||
p.info = ShaderLanguage::uniform_to_property_info(E.value);
|
||||
p.info.name = E.key; //supply name
|
||||
p.index = E.value.instance_index;
|
||||
p.default_value = ShaderLanguage::constant_value_to_variant(E.value.default_value, E.value.type, E.value.array_size, E.value.hint);
|
||||
p_param_list->push_back(p);
|
||||
}
|
||||
}
|
||||
|
||||
bool RendererCanvasRenderRD::CanvasShaderData::is_parameter_texture(const StringName &p_param) const {
|
||||
if (!uniforms.has(p_param)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return uniforms[p_param].texture_order >= 0;
|
||||
}
|
||||
|
||||
bool RendererCanvasRenderRD::CanvasShaderData::is_animated() const {
|
||||
return false;
|
||||
}
|
||||
|
@ -2304,15 +2220,6 @@ bool RendererCanvasRenderRD::CanvasShaderData::casts_shadows() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
Variant RendererCanvasRenderRD::CanvasShaderData::get_default_parameter(const StringName &p_parameter) const {
|
||||
if (uniforms.has(p_parameter)) {
|
||||
ShaderLanguage::ShaderNode::Uniform uniform = uniforms[p_parameter];
|
||||
Vector<ShaderLanguage::ConstantNode::Value> default_value = uniform.default_value;
|
||||
return ShaderLanguage::constant_value_to_variant(default_value, uniform.type, uniform.array_size, uniform.hint);
|
||||
}
|
||||
return Variant();
|
||||
}
|
||||
|
||||
RS::ShaderNativeSourceCode RendererCanvasRenderRD::CanvasShaderData::get_native_source_code() const {
|
||||
RendererCanvasRenderRD *canvas_singleton = static_cast<RendererCanvasRenderRD *>(RendererCanvasRender::singleton);
|
||||
return canvas_singleton->shader.canvas_shader.version_get_native_source_code(version);
|
||||
|
|
|
@ -160,16 +160,13 @@ class RendererCanvasRenderRD : public RendererCanvasRender {
|
|||
bool valid = false;
|
||||
RID version;
|
||||
PipelineVariants pipeline_variants;
|
||||
String path;
|
||||
|
||||
HashMap<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
|
||||
Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms;
|
||||
|
||||
Vector<uint32_t> ubo_offsets;
|
||||
uint32_t ubo_size = 0;
|
||||
|
||||
String code;
|
||||
HashMap<StringName, HashMap<int, RID>> default_texture_params;
|
||||
|
||||
bool uses_screen_texture = false;
|
||||
bool uses_screen_texture_mipmaps = false;
|
||||
|
@ -177,15 +174,8 @@ class RendererCanvasRenderRD : public RendererCanvasRender {
|
|||
bool uses_time = false;
|
||||
|
||||
virtual void set_code(const String &p_Code);
|
||||
virtual void set_path_hint(const String &p_path);
|
||||
virtual void set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index);
|
||||
virtual void get_shader_uniform_list(List<PropertyInfo> *p_param_list) const;
|
||||
virtual void get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const;
|
||||
|
||||
virtual bool is_parameter_texture(const StringName &p_param) const;
|
||||
virtual bool is_animated() const;
|
||||
virtual bool casts_shadows() const;
|
||||
virtual Variant get_default_parameter(const StringName &p_parameter) const;
|
||||
virtual RS::ShaderNativeSourceCode get_native_source_code() const;
|
||||
|
||||
CanvasShaderData() {}
|
||||
|
|
|
@ -927,6 +927,104 @@ _FORCE_INLINE_ static void _fill_std140_ubo_empty(ShaderLanguage::DataType type,
|
|||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// MaterialStorage::ShaderData
|
||||
|
||||
void MaterialStorage::ShaderData::set_path_hint(const String &p_hint) {
|
||||
path = p_hint;
|
||||
}
|
||||
|
||||
void MaterialStorage::ShaderData::set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index) {
|
||||
if (!p_texture.is_valid()) {
|
||||
if (default_texture_params.has(p_name) && default_texture_params[p_name].has(p_index)) {
|
||||
default_texture_params[p_name].erase(p_index);
|
||||
|
||||
if (default_texture_params[p_name].is_empty()) {
|
||||
default_texture_params.erase(p_name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!default_texture_params.has(p_name)) {
|
||||
default_texture_params[p_name] = HashMap<int, RID>();
|
||||
}
|
||||
default_texture_params[p_name][p_index] = p_texture;
|
||||
}
|
||||
}
|
||||
|
||||
Variant MaterialStorage::ShaderData::get_default_parameter(const StringName &p_parameter) const {
|
||||
if (uniforms.has(p_parameter)) {
|
||||
ShaderLanguage::ShaderNode::Uniform uniform = uniforms[p_parameter];
|
||||
Vector<ShaderLanguage::ConstantNode::Value> default_value = uniform.default_value;
|
||||
return ShaderLanguage::constant_value_to_variant(default_value, uniform.type, uniform.array_size, uniform.hint);
|
||||
}
|
||||
return Variant();
|
||||
}
|
||||
|
||||
void MaterialStorage::ShaderData::get_shader_uniform_list(List<PropertyInfo> *p_param_list) const {
|
||||
SortArray<Pair<StringName, int>, ShaderLanguage::UniformOrderComparator> sorter;
|
||||
LocalVector<Pair<StringName, int>> filtered_uniforms;
|
||||
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_LOCAL) {
|
||||
continue;
|
||||
}
|
||||
if (E.value.texture_order >= 0) {
|
||||
filtered_uniforms.push_back(Pair<StringName, int>(E.key, E.value.texture_order + 100000));
|
||||
} else {
|
||||
filtered_uniforms.push_back(Pair<StringName, int>(E.key, E.value.order));
|
||||
}
|
||||
}
|
||||
int uniform_count = filtered_uniforms.size();
|
||||
sorter.sort(filtered_uniforms.ptr(), uniform_count);
|
||||
|
||||
String last_group;
|
||||
for (int i = 0; i < uniform_count; i++) {
|
||||
const StringName &uniform_name = filtered_uniforms[i].first;
|
||||
const ShaderLanguage::ShaderNode::Uniform &uniform = uniforms[uniform_name];
|
||||
|
||||
String group = uniform.group;
|
||||
if (!uniform.subgroup.is_empty()) {
|
||||
group += "::" + uniform.subgroup;
|
||||
}
|
||||
|
||||
if (group != last_group) {
|
||||
PropertyInfo pi;
|
||||
pi.usage = PROPERTY_USAGE_GROUP;
|
||||
pi.name = group;
|
||||
p_param_list->push_back(pi);
|
||||
|
||||
last_group = group;
|
||||
}
|
||||
|
||||
PropertyInfo pi = ShaderLanguage::uniform_to_property_info(uniform);
|
||||
pi.name = uniform_name;
|
||||
p_param_list->push_back(pi);
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialStorage::ShaderData::get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const {
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
RendererMaterialStorage::InstanceShaderParam p;
|
||||
p.info = ShaderLanguage::uniform_to_property_info(E.value);
|
||||
p.info.name = E.key; //supply name
|
||||
p.index = E.value.instance_index;
|
||||
p.default_value = ShaderLanguage::constant_value_to_variant(E.value.default_value, E.value.type, E.value.array_size, E.value.hint);
|
||||
p_param_list->push_back(p);
|
||||
}
|
||||
}
|
||||
|
||||
bool MaterialStorage::ShaderData::is_parameter_texture(const StringName &p_param) const {
|
||||
if (!uniforms.has(p_param)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return uniforms[p_param].texture_order >= 0;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// MaterialStorage::MaterialData
|
||||
|
||||
|
|
|
@ -54,16 +54,20 @@ public:
|
|||
};
|
||||
|
||||
struct ShaderData {
|
||||
virtual void set_code(const String &p_Code) = 0;
|
||||
virtual void set_path_hint(const String &p_hint) = 0;
|
||||
virtual void set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index) = 0;
|
||||
virtual void get_shader_uniform_list(List<PropertyInfo> *p_param_list) const = 0;
|
||||
String path;
|
||||
HashMap<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
|
||||
HashMap<StringName, HashMap<int, RID>> default_texture_params;
|
||||
|
||||
virtual void get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const = 0;
|
||||
virtual bool is_parameter_texture(const StringName &p_param) const = 0;
|
||||
virtual void set_path_hint(const String &p_hint);
|
||||
virtual void set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index);
|
||||
virtual Variant get_default_parameter(const StringName &p_parameter) const;
|
||||
virtual void get_shader_uniform_list(List<PropertyInfo> *p_param_list) const;
|
||||
virtual void get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const;
|
||||
virtual bool is_parameter_texture(const StringName &p_param) const;
|
||||
|
||||
virtual void set_code(const String &p_Code) = 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 RS::ShaderNativeSourceCode get_native_source_code() const { return RS::ShaderNativeSourceCode(); }
|
||||
|
||||
virtual ~ShaderData() {}
|
||||
|
|
|
@ -1534,9 +1534,6 @@ bool ParticlesStorage::particles_is_inactive(RID p_particles) const {
|
|||
|
||||
/* Particles SHADER */
|
||||
|
||||
void ParticlesStorage::ParticlesShaderData::set_path_hint(const String &p_path) {
|
||||
path = p_path;
|
||||
}
|
||||
void ParticlesStorage::ParticlesShaderData::set_code(const String &p_code) {
|
||||
ParticlesStorage *particles_storage = ParticlesStorage::get_singleton();
|
||||
//compile
|
||||
|
@ -1602,83 +1599,6 @@ void ParticlesStorage::ParticlesShaderData::set_code(const String &p_code) {
|
|||
valid = true;
|
||||
}
|
||||
|
||||
void ParticlesStorage::ParticlesShaderData::set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index) {
|
||||
if (!p_texture.is_valid()) {
|
||||
if (default_texture_params.has(p_name) && default_texture_params[p_name].has(p_index)) {
|
||||
default_texture_params[p_name].erase(p_index);
|
||||
|
||||
if (default_texture_params[p_name].is_empty()) {
|
||||
default_texture_params.erase(p_name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!default_texture_params.has(p_name)) {
|
||||
default_texture_params[p_name] = HashMap<int, RID>();
|
||||
}
|
||||
default_texture_params[p_name][p_index] = p_texture;
|
||||
}
|
||||
}
|
||||
|
||||
void ParticlesStorage::ParticlesShaderData::get_shader_uniform_list(List<PropertyInfo> *p_param_list) const {
|
||||
HashMap<int, StringName> order;
|
||||
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope == ShaderLanguage::ShaderNode::Uniform::SCOPE_GLOBAL || E.value.scope == ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (E.value.texture_order >= 0) {
|
||||
order[E.value.texture_order + 100000] = E.key;
|
||||
} else {
|
||||
order[E.value.order] = E.key;
|
||||
}
|
||||
}
|
||||
|
||||
String last_group;
|
||||
for (const KeyValue<int, StringName> &E : order) {
|
||||
String group = uniforms[E.value].group;
|
||||
if (!uniforms[E.value].subgroup.is_empty()) {
|
||||
group += "::" + uniforms[E.value].subgroup;
|
||||
}
|
||||
|
||||
if (group != last_group) {
|
||||
PropertyInfo pi;
|
||||
pi.usage = PROPERTY_USAGE_GROUP;
|
||||
pi.name = group;
|
||||
p_param_list->push_back(pi);
|
||||
|
||||
last_group = group;
|
||||
}
|
||||
|
||||
PropertyInfo pi = ShaderLanguage::uniform_to_property_info(uniforms[E.value]);
|
||||
pi.name = E.value;
|
||||
p_param_list->push_back(pi);
|
||||
}
|
||||
}
|
||||
|
||||
void ParticlesStorage::ParticlesShaderData::get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const {
|
||||
for (const KeyValue<StringName, ShaderLanguage::ShaderNode::Uniform> &E : uniforms) {
|
||||
if (E.value.scope != ShaderLanguage::ShaderNode::Uniform::SCOPE_INSTANCE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
RendererMaterialStorage::InstanceShaderParam p;
|
||||
p.info = ShaderLanguage::uniform_to_property_info(E.value);
|
||||
p.info.name = E.key; //supply name
|
||||
p.index = E.value.instance_index;
|
||||
p.default_value = ShaderLanguage::constant_value_to_variant(E.value.default_value, E.value.type, E.value.array_size, E.value.hint);
|
||||
p_param_list->push_back(p);
|
||||
}
|
||||
}
|
||||
|
||||
bool ParticlesStorage::ParticlesShaderData::is_parameter_texture(const StringName &p_param) const {
|
||||
if (!uniforms.has(p_param)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return uniforms[p_param].texture_order >= 0;
|
||||
}
|
||||
|
||||
bool ParticlesStorage::ParticlesShaderData::is_animated() const {
|
||||
return false;
|
||||
}
|
||||
|
@ -1687,15 +1607,6 @@ bool ParticlesStorage::ParticlesShaderData::casts_shadows() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
Variant ParticlesStorage::ParticlesShaderData::get_default_parameter(const StringName &p_parameter) const {
|
||||
if (uniforms.has(p_parameter)) {
|
||||
ShaderLanguage::ShaderNode::Uniform uniform = uniforms[p_parameter];
|
||||
Vector<ShaderLanguage::ConstantNode::Value> default_value = uniform.default_value;
|
||||
return ShaderLanguage::constant_value_to_variant(default_value, uniform.type, uniform.array_size, uniform.hint);
|
||||
}
|
||||
return Variant();
|
||||
}
|
||||
|
||||
RS::ShaderNativeSourceCode ParticlesStorage::ParticlesShaderData::get_native_source_code() const {
|
||||
return ParticlesStorage::get_singleton()->particles_shader.shader.version_get_native_source_code(version);
|
||||
}
|
||||
|
|
|
@ -313,15 +313,12 @@ private:
|
|||
RID version;
|
||||
bool uses_collision = false;
|
||||
|
||||
HashMap<StringName, ShaderLanguage::ShaderNode::Uniform> uniforms;
|
||||
Vector<ShaderCompiler::GeneratedCode::Texture> texture_uniforms;
|
||||
|
||||
Vector<uint32_t> ubo_offsets;
|
||||
uint32_t ubo_size = 0;
|
||||
|
||||
String path;
|
||||
String code;
|
||||
HashMap<StringName, HashMap<int, RID>> default_texture_params;
|
||||
|
||||
RID pipeline;
|
||||
|
||||
|
@ -331,14 +328,8 @@ private:
|
|||
uint32_t userdata_count = 0;
|
||||
|
||||
virtual void set_code(const String &p_Code);
|
||||
virtual void set_path_hint(const String &p_hint);
|
||||
virtual void set_default_texture_parameter(const StringName &p_name, RID p_texture, int p_index);
|
||||
virtual void get_shader_uniform_list(List<PropertyInfo> *p_param_list) const;
|
||||
virtual void get_instance_param_list(List<RendererMaterialStorage::InstanceShaderParam> *p_param_list) const;
|
||||
virtual bool is_parameter_texture(const StringName &p_param) const;
|
||||
virtual bool is_animated() const;
|
||||
virtual bool casts_shadows() const;
|
||||
virtual Variant get_default_parameter(const StringName &p_parameter) const;
|
||||
virtual RS::ShaderNativeSourceCode get_native_source_code() const;
|
||||
|
||||
ParticlesShaderData() {}
|
||||
|
|
|
@ -720,6 +720,12 @@ public:
|
|||
Node(TYPE_SHADER) {}
|
||||
};
|
||||
|
||||
struct UniformOrderComparator {
|
||||
_FORCE_INLINE_ bool operator()(const Pair<StringName, int> &A, const Pair<StringName, int> &B) const {
|
||||
return A.second < B.second;
|
||||
}
|
||||
};
|
||||
|
||||
struct Expression {
|
||||
bool is_op;
|
||||
union {
|
||||
|
|
Loading…
Reference in New Issue