summaryrefslogtreecommitdiffstats
path: root/scene/resources/visual_shader_nodes.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2019-10-10 12:37:12 +0200
committerGitHub <noreply@github.com>2019-10-10 12:37:12 +0200
commit2c84a9651f25328d3cdde703e5eb4ea6387313b6 (patch)
tree221b3e69f4e16f8b90a8c74cf5b84e6b5d7223f9 /scene/resources/visual_shader_nodes.cpp
parentcfc26f53d695a2b3e4513958fa58b9b5dbb1a5ca (diff)
parentd2fd2f32fc0295b0f1c83cfa14fb78b4a903c04b (diff)
downloadredot-engine-2c84a9651f25328d3cdde703e5eb4ea6387313b6.tar.gz
Merge pull request #32707 from Chaosus/vs_lod_textures
Uses LoD even if UV slot is not used in visual shader textures
Diffstat (limited to 'scene/resources/visual_shader_nodes.cpp')
-rw-r--r--scene/resources/visual_shader_nodes.cpp58
1 files changed, 47 insertions, 11 deletions
diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp
index bb42e8fb9f..c56d5d7213 100644
--- a/scene/resources/visual_shader_nodes.cpp
+++ b/scene/resources/visual_shader_nodes.cpp
@@ -453,7 +453,12 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader:
String code;
if (p_input_vars[0] == String()) { // Use UV by default.
- code += "\tvec4 " + id + "_read = texture( " + id + " , UV.xy );\n";
+ if (p_input_vars[1] == String()) {
+ code += "\tvec4 " + id + "_read = texture( " + id + " , UV.xy );\n";
+ } else {
+ code += "\tvec4 " + id + "_read = textureLod( " + id + " , UV.xy , " + p_input_vars[1] + " );\n";
+ }
+
} else if (p_input_vars[1] == String()) {
//no lod
code += "\tvec4 " + id + "_read = texture( " + id + " , " + p_input_vars[0] + ".xy );\n";
@@ -485,10 +490,18 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader:
if (p_input_vars[0] == String()) { // Use UV by default.
switch (utype) {
case VisualShaderNodeUniform::UTYPE_CUBEMAP:
- code += "\tvec4 " + id + "_tex_read = texture( " + id + " , vec3(UV, 0.0) );\n";
+ if (p_input_vars[1] == String()) {
+ code += "\tvec4 " + id + "_tex_read = texture( " + id + " , vec3( UV, 0.0 ) );\n";
+ } else {
+ code += "\tvec4 " + id + "_tex_read = textureLod( " + id + " , vec3( UV, 0.0 ) , " + p_input_vars[1] + " );\n";
+ }
break;
case VisualShaderNodeUniform::UTYPE_SAMPLER2D:
- code += "\tvec4 " + id + "_tex_read = texture( " + id + " , UV.xy );\n";
+ if (p_input_vars[1] == String()) {
+ code += "\tvec4 " + id + "_tex_read = texture( " + id + " , UV.xy );\n";
+ } else {
+ code += "\tvec4 " + id + "_tex_read = textureLod( " + id + " , UV.xy , " + p_input_vars[1] + " );\n";
+ }
break;
default:
break;
@@ -530,11 +543,15 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader:
String code = "\t{\n";
if (p_input_vars[0] == String() || p_for_preview) { // Use UV by default.
- code += "\t\tvec4 _tex_read = textureLod( SCREEN_TEXTURE , UV.xy, 0.0 );\n";
+ if (p_input_vars[1] == String()) {
+ code += "\t\tvec4 _tex_read = textureLod( SCREEN_TEXTURE , UV.xy , 0.0 );\n";
+ } else {
+ code += "\t\tvec4 _tex_read = textureLod( SCREEN_TEXTURE , UV.xy , " + p_input_vars[1] + ");\n";
+ }
} else if (p_input_vars[1] == String()) {
//no lod
- code += "\t\tvec4 _tex_read = textureLod( SCREEN_TEXTURE , " + p_input_vars[0] + ".xy, 0.0 );\n";
+ code += "\t\tvec4 _tex_read = textureLod( SCREEN_TEXTURE , " + p_input_vars[0] + ".xy , 0.0 );\n";
} else {
code += "\t\tvec4 _tex_read = textureLod( SCREEN_TEXTURE , " + p_input_vars[0] + ".xy , " + p_input_vars[1] + " );\n";
}
@@ -550,7 +567,11 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader:
String code = "\t{\n";
if (p_input_vars[0] == String()) { // Use UV by default.
- code += "\t\tvec4 _tex_read = texture( TEXTURE , UV.xy );\n";
+ if (p_input_vars[1] == String()) {
+ code += "\t\tvec4 _tex_read = texture( TEXTURE , UV.xy );\n";
+ } else {
+ code += "\t\tvec4 _tex_read = textureLod( TEXTURE , UV.xy , " + p_input_vars[1] + " );\n";
+ }
} else if (p_input_vars[1] == String()) {
//no lod
@@ -570,7 +591,11 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader:
String code = "\t{\n";
if (p_input_vars[0] == String()) { // Use UV by default.
- code += "\t\tvec4 _tex_read = texture( NORMAL_TEXTURE , UV.xy );\n";
+ if (p_input_vars[1] == String()) {
+ code += "\t\tvec4 _tex_read = texture( NORMAL_TEXTURE , UV.xy );\n";
+ } else {
+ code += "\t\tvec4 _tex_read = textureLod( NORMAL_TEXTURE , UV.xy , " + p_input_vars[1] + " );\n";
+ }
} else if (p_input_vars[1] == String()) {
//no lod
@@ -600,7 +625,11 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader:
String code = "\t{\n";
if (p_input_vars[0] == String()) { // Use UV by default.
- code += "\t\tfloat _depth = texture( DEPTH_TEXTURE , UV.xy ).r;\n";
+ if (p_input_vars[1] == String()) {
+ code += "\t\tfloat _depth = texture( DEPTH_TEXTURE , UV.xy ).r;\n";
+ } else {
+ code += "\t\tfloat _depth = textureLod( DEPTH_TEXTURE , UV.xy , " + p_input_vars[1] + " ).r;\n";
+ }
} else if (p_input_vars[1] == String()) {
//no lod
@@ -789,7 +818,11 @@ String VisualShaderNodeCubeMap::generate_code(Shader::Mode p_mode, VisualShader:
String code;
if (p_input_vars[0] == String()) { // Use UV by default.
- code += "\tvec4 " + id + "_read = texture( " + id + " , vec3(UV, 0.0) );\n";
+ if (p_input_vars[1] == String()) {
+ code += "\tvec4 " + id + "_read = texture( " + id + " , vec3( UV, 0.0 ) );\n";
+ } else {
+ code += "\tvec4 " + id + "_read = textureLod( " + id + " , vec3( UV, 0.0 )" + " , " + p_input_vars[1] + " );\n";
+ }
} else if (p_input_vars[1] == String()) {
//no lod
@@ -3178,8 +3211,11 @@ String VisualShaderNodeTextureUniform::generate_code(Shader::Mode p_mode, Visual
String id = get_uniform_name();
String code = "\t{\n";
if (p_input_vars[0] == String()) { // Use UV by default.
-
- code += "\t\tvec4 n_tex_read = texture( " + id + " , UV.xy );\n";
+ if (p_input_vars[1] == String()) {
+ code += "\t\tvec4 n_tex_read = texture( " + id + " , UV.xy );\n";
+ } else {
+ code += "\t\tvec4 n_tex_read = textureLod( " + id + " , UV.xy , " + p_input_vars[1] + " );\n";
+ }
} else if (p_input_vars[1] == String()) {
//no lod
code += "\t\tvec4 n_tex_read = texture( " + id + " , " + p_input_vars[0] + ".xy );\n";