armory3d / armory

3D Engine with Blender Integration
https://armory3d.org/engine
zlib License
3.07k stars 315 forks source link

Bump Node not really working with procedural textures #935

Closed yboettcher closed 4 years ago

yboettcher commented 6 years ago

While trying around with some material Library, I noticed that some of them would fail to even compile with Armory. Looking for the cause of this issue I found that using the Bump node's height input with procedural textures was one of the problematic situations. (it seems like there was an issue about this node about a year ago, but it seems like it was about image textures: https://github.com/armory3d/armory/issues/322) Trying out most of the procedural textures, I found out that you can plug the color output of any of the textures into the height input and the game will compile and run. But it does not use the texture at all... If you try to use the Fac output, it will still compile for most of the nodes (you still don't see any texture in Armory), but fail at compiling for the Noise Texture and the Checker Texture.

This is my example setup I used for testing: image

If I use the Color Output of any Texture (Brick in this case) I can see it in Cycles, but it does not appear in Armory image The same happens when using the Fac output. Shader: Material_mesh.frag.glsl Looking at line 34/35, one can see that it does create the BrickTexture... but then uses the n variable and never touches the texture again. This seems to be caused by the sample_bump_res variable in the cycles.py file being empty (It also seems like the distance input is not used...)

If I use use the Fac output of either the Noise or Checker Texture, the compilation fails with this output:

Compiling shader 1 of 1 (Material_mesh.frag.glsl). ERROR: /run/media/yannik/Daten/Blender/Armory3D/Tests/MaterialLibrary/build_SingleMat/compiled/Shaders/Material_mesh.frag.glsl:37: '+' : wrong operand types: no operation '+' exists that takes a left-hand operand of type ' temp 3-component vector of float' and a right operand of type ' const 2-component vector of float' (or there is no acceptable conversion) ERROR: /run/media/yannik/Daten/Blender/Armory3D/Tests/MaterialLibrary/build_SingleMat/compiled/Shaders/Material_mesh.frag.glsl:37: '' : compilation terminated ERROR: 2 compilation errors. No code generated. SPIR-V is not generated for failed compile or link Compiling shader 1 of 1 (Material_mesh.frag.glsl) failed: Shader compiler error.

I guess the most interesting line is the first one starting with ERROR, which points at line 37, so here is the generated shader file Material_mesh.frag.glsl Line 37:

float NoiseTexture_store_bump_1 = tex_noise(bposition * 5.0 + vec2(-2, 0));

Yeah, this does not look right. Adding a vec3 and a vec2... It seems to be generated inside the write_bump method of the cycles.py file.

For the Checker texture the error is the same but pointing to line 35:

float CheckerTexture_store_bump_1 = tex_checker_f(bposition + vec2(-2, 0), 5.0).r;

once again trying to add vec3 and vec2.

yboettcher commented 6 years ago

It seems like the compile issues with the bump node have gone away. However it also seems like some textures (like magic) are still being ignored. If I connect the fac output of a magic texture, this appears in the resulting shader:

float MagicTexture_Fac_res = tex_magic_f(bposition * 13.399999618530273 * 4.0);
vec3 Bump_001_Normal_res = n;
basecol = Bump_001_Normal_res;

Yes, it creates the magic texture... but it does not use it.

Also it seems like none of the color outputs work. For example, if I use the fac output of a noise texture I can see the result in armory so it seems to be working. If I use the color output, I can't see any of it. Once again the noise texture is created but remains unused in the shader.

vec3 NoiseTexture_Color_res = vec3(tex_noise(bposition * 5.045670032501221), tex_noise(bposition * 5.045670032501221 + 0.33), tex_noise(bposition * 5.045670032501221 + 0.66));
vec3 Bump_001_Normal_res = n;
basecol = Bump_001_Normal_res;
ghost commented 5 years ago

default