Merge pull request #41935 from Chaosus/vs_texture3d

Added Texture3D to visual shaders
This commit is contained in:
Rémi Verschelde 2020-09-10 11:18:37 +02:00 committed by GitHub
commit 58dcde344c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 264 additions and 3 deletions

49
doc/classes/Texture3D.xml Normal file
View File

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="Texture3D" inherits="Texture" version="4.0">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<methods>
<method name="get_data" qualifiers="const">
<return type="Image[]">
</return>
<description>
</description>
</method>
<method name="get_depth" qualifiers="const">
<return type="int">
</return>
<description>
</description>
</method>
<method name="get_format" qualifiers="const">
<return type="int" enum="Image.Format">
</return>
<description>
</description>
</method>
<method name="get_height" qualifiers="const">
<return type="int">
</return>
<description>
</description>
</method>
<method name="get_width" qualifiers="const">
<return type="int">
</return>
<description>
</description>
</method>
<method name="has_mipmaps" qualifiers="const">
<return type="bool">
</return>
<description>
</description>
</method>
</methods>
<constants>
</constants>
</class>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="VisualShaderNodeTexture" inherits="VisualShaderNode" version="4.0">
<brief_description>
Performs a texture lookup within the visual shader graph.
Performs a 2D texture lookup within the visual shader graph.
</brief_description>
<description>
Performs a lookup operation on the provided texture, with support for multiple texture sources to choose from.

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="VisualShaderNodeTexture3D" inherits="VisualShaderNodeSample3D" version="4.0">
<brief_description>
Performs a 3D texture lookup within the visual shader graph.
</brief_description>
<description>
Performs a lookup operation on the provided texture, with support for multiple texture sources to choose from.
</description>
<tutorials>
</tutorials>
<methods>
</methods>
<members>
<member name="texture" type="Texture3D" setter="set_texture" getter="get_texture">
A source texture. Used if [member VisualShaderNodeSample3D.source] is set to [constant VisualShaderNodeSample3D.SOURCE_TEXTURE].
</member>
</members>
<constants>
</constants>
</class>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="VisualShaderNodeTexture3DUniform" inherits="VisualShaderNodeTextureUniform" version="4.0">
<brief_description>
Provides a 3D texture uniform within the visual shader graph.
</brief_description>
<description>
Translated to [code]uniform sampler3D[/code] in the shader language.
</description>
<tutorials>
</tutorials>
<methods>
</methods>
<constants>
</constants>
</class>

View File

@ -2974,12 +2974,15 @@ VisualShaderEditor::VisualShaderEditor() {
add_options.push_back(AddOption("CubeMap", "Textures", "Functions", "VisualShaderNodeCubemap", TTR("Perform the cubic texture lookup."), -1, -1));
texture_node_option_idx = add_options.size();
add_options.push_back(AddOption("Texture2D", "Textures", "Functions", "VisualShaderNodeTexture", TTR("Perform the texture lookup."), -1, -1));
add_options.push_back(AddOption("CubeMapUniform", "Textures", "Variables", "VisualShaderNodeCubemapUniform", TTR("Cubic texture uniform lookup."), -1, -1));
add_options.push_back(AddOption("Texture2D", "Textures", "Functions", "VisualShaderNodeTexture", TTR("Perform the 2D texture lookup."), -1, -1));
add_options.push_back(AddOption("Texture2DArray", "Textures", "Functions", "VisualShaderNodeTexture2DArray", TTR("Perform the 2D-array texture lookup."), -1, -1, -1, -1, -1));
add_options.push_back(AddOption("Texture3D", "Textures", "Functions", "VisualShaderNodeTexture3D", TTR("Perform the 3D texture lookup."), -1, -1));
add_options.push_back(AddOption("CubeMapUniform", "Textures", "Variables", "VisualShaderNodeCubemapUniform", TTR("Cubic texture uniform lookup."), -1, -1));
add_options.push_back(AddOption("TextureUniform", "Textures", "Variables", "VisualShaderNodeTextureUniform", TTR("2D texture uniform lookup."), -1, -1));
add_options.push_back(AddOption("TextureUniformTriplanar", "Textures", "Variables", "VisualShaderNodeTextureUniformTriplanar", TTR("2D texture uniform lookup with triplanar."), -1, -1, TYPE_FLAGS_FRAGMENT | TYPE_FLAGS_LIGHT, Shader::MODE_SPATIAL));
add_options.push_back(AddOption("Texture2DArrayUniform", "Textures", "Variables", "VisualShaderNodeTexture2DArrayUniform", TTR("2D array of textures uniform lookup."), -1, -1, -1, -1, -1));
add_options.push_back(AddOption("Texture3DUniform", "Textures", "Variables", "VisualShaderNodeTexture3DUniform", TTR("3D texture uniform lookup."), -1, -1, -1, -1, -1));
// TRANSFORM

View File

@ -553,6 +553,7 @@ void register_scene_types() {
ClassDB::register_class<VisualShaderNodeTexture>();
ClassDB::register_virtual_class<VisualShaderNodeSample3D>();
ClassDB::register_class<VisualShaderNodeTexture2DArray>();
ClassDB::register_class<VisualShaderNodeTexture3D>();
ClassDB::register_class<VisualShaderNodeCubemap>();
ClassDB::register_virtual_class<VisualShaderNodeUniform>();
ClassDB::register_class<VisualShaderNodeUniformRef>();
@ -565,6 +566,7 @@ void register_scene_types() {
ClassDB::register_class<VisualShaderNodeTextureUniform>();
ClassDB::register_class<VisualShaderNodeTextureUniformTriplanar>();
ClassDB::register_class<VisualShaderNodeTexture2DArrayUniform>();
ClassDB::register_class<VisualShaderNodeTexture3DUniform>();
ClassDB::register_class<VisualShaderNodeCubemapUniform>();
ClassDB::register_class<VisualShaderNodeIf>();
ClassDB::register_class<VisualShaderNodeSwitch>();

View File

@ -951,6 +951,64 @@ void VisualShaderNodeTexture2DArray::_bind_methods() {
VisualShaderNodeTexture2DArray::VisualShaderNodeTexture2DArray() {
}
////////////// Texture3D
String VisualShaderNodeTexture3D::get_caption() const {
return "Texture3D";
}
String VisualShaderNodeTexture3D::get_input_port_name(int p_port) const {
if (p_port == 2) {
return "sampler3D";
}
return VisualShaderNodeSample3D::get_input_port_name(p_port);
}
Vector<VisualShader::DefaultTextureParam> VisualShaderNodeTexture3D::get_default_texture_parameters(VisualShader::Type p_type, int p_id) const {
VisualShader::DefaultTextureParam dtp;
dtp.name = make_unique_id(p_type, p_id, "tex3d");
dtp.param = texture;
Vector<VisualShader::DefaultTextureParam> ret;
ret.push_back(dtp);
return ret;
}
String VisualShaderNodeTexture3D::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
if (source == SOURCE_TEXTURE) {
return "uniform sampler3D " + make_unique_id(p_type, p_id, "tex3d") + ";\n";
}
return String();
}
void VisualShaderNodeTexture3D::set_texture(Ref<Texture3D> p_value) {
texture = p_value;
emit_changed();
}
Ref<Texture3D> VisualShaderNodeTexture3D::get_texture() const {
return texture;
}
Vector<StringName> VisualShaderNodeTexture3D::get_editable_properties() const {
Vector<StringName> props;
props.push_back("source");
if (source == SOURCE_TEXTURE) {
props.push_back("texture");
}
return props;
}
void VisualShaderNodeTexture3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_texture", "value"), &VisualShaderNodeTexture3D::set_texture);
ClassDB::bind_method(D_METHOD("get_texture"), &VisualShaderNodeTexture3D::get_texture);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture3D"), "set_texture", "get_texture");
}
VisualShaderNodeTexture3D::VisualShaderNodeTexture3D() {
}
////////////// Cubemap
String VisualShaderNodeCubemap::get_caption() const {
@ -4397,6 +4455,74 @@ String VisualShaderNodeTexture2DArrayUniform::generate_code(Shader::Mode p_mode,
VisualShaderNodeTexture2DArrayUniform::VisualShaderNodeTexture2DArrayUniform() {
}
////////////// Texture3D Uniform
String VisualShaderNodeTexture3DUniform::get_caption() const {
return "Texture3DUniform";
}
int VisualShaderNodeTexture3DUniform::get_output_port_count() const {
return 1;
}
VisualShaderNodeTexture3DUniform::PortType VisualShaderNodeTexture3DUniform::get_output_port_type(int p_port) const {
return PORT_TYPE_SAMPLER;
}
String VisualShaderNodeTexture3DUniform::get_output_port_name(int p_port) const {
return "sampler3D";
}
int VisualShaderNodeTexture3DUniform::get_input_port_count() const {
return 0;
}
VisualShaderNodeTexture3DUniform::PortType VisualShaderNodeTexture3DUniform::get_input_port_type(int p_port) const {
return PORT_TYPE_SCALAR;
}
String VisualShaderNodeTexture3DUniform::get_input_port_name(int p_port) const {
return "";
}
String VisualShaderNodeTexture3DUniform::get_input_port_default_hint(int p_port) const {
return "";
}
String VisualShaderNodeTexture3DUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
String code = _get_qual_str() + "uniform sampler3D " + get_uniform_name();
switch (texture_type) {
case TYPE_DATA:
if (color_default == COLOR_DEFAULT_BLACK)
code += " : hint_black;\n";
else
code += ";\n";
break;
case TYPE_COLOR:
if (color_default == COLOR_DEFAULT_BLACK)
code += " : hint_black_albedo;\n";
else
code += " : hint_albedo;\n";
break;
case TYPE_NORMALMAP:
code += " : hint_normal;\n";
break;
case TYPE_ANISO:
code += " : hint_aniso;\n";
break;
}
return code;
}
String VisualShaderNodeTexture3DUniform::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
return String();
}
VisualShaderNodeTexture3DUniform::VisualShaderNodeTexture3DUniform() {
}
////////////// Cubemap Uniform
String VisualShaderNodeCubemapUniform::get_caption() const {

View File

@ -343,6 +343,29 @@ public:
VisualShaderNodeTexture2DArray();
};
class VisualShaderNodeTexture3D : public VisualShaderNodeSample3D {
GDCLASS(VisualShaderNodeTexture3D, VisualShaderNodeSample3D);
Ref<Texture3D> texture;
protected:
static void _bind_methods();
public:
virtual String get_caption() const override;
virtual String get_input_port_name(int p_port) const override;
virtual Vector<VisualShader::DefaultTextureParam> get_default_texture_parameters(VisualShader::Type p_type, int p_id) const override;
virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
void set_texture(Ref<Texture3D> p_value);
Ref<Texture3D> get_texture() const;
virtual Vector<StringName> get_editable_properties() const override;
VisualShaderNodeTexture3D();
};
class VisualShaderNodeCubemap : public VisualShaderNode {
GDCLASS(VisualShaderNodeCubemap, VisualShaderNode);
Ref<Cubemap> cube_map;
@ -1855,6 +1878,29 @@ public:
///////////////////////////////////////
class VisualShaderNodeTexture3DUniform : public VisualShaderNodeTextureUniform {
GDCLASS(VisualShaderNodeTexture3DUniform, VisualShaderNodeTextureUniform);
public:
virtual String get_caption() const override;
virtual int get_input_port_count() const override;
virtual PortType get_input_port_type(int p_port) const override;
virtual String get_input_port_name(int p_port) const override;
virtual int get_output_port_count() const override;
virtual PortType get_output_port_type(int p_port) const override;
virtual String get_output_port_name(int p_port) const override;
virtual String get_input_port_default_hint(int p_port) const override;
virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const override; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
VisualShaderNodeTexture3DUniform();
};
///////////////////////////////////////
class VisualShaderNodeCubemapUniform : public VisualShaderNodeTextureUniform {
GDCLASS(VisualShaderNodeCubemapUniform, VisualShaderNodeTextureUniform);