Is there a way to use for loop in a material?

I have a material in which I have to calculate the contribution of every pixel neighbors. Is there a better way of doing so than duplicating my code as many time as there are pixel neighbors?

The only way to do loops in materials is with a Custom Shader Expression:

Due to how shader code is compiled to be compliant with the various different platforms, loops can’t be implemented like they are in blueprints.

Hum interesting… is there a way to call a material function that I made in a custom shader expression or do I have to rewrite my function in the shader?

As far as I can tell, you’ll have to rewrite your material function inside the custom expression.

Aww too bad. Thanks anyway! Didn’t know about Custom Shaders :wink:

This might help, but could also confuse. Once, I asked this same question about shaders.

I look at UE4 materials as being like shaders (not the same tho). The code used in shaders (GLSL, HLSL) is really the body of a for-loop, which determines how each pixel affected by that shader is drawn.

Adding a loop to a material (or shader) would be really inefficient.

https://forums.unrealengine.com/community/general-discussion/28082-are-shaders-and-materials-the-same-thing

Others with more shader experience might have a different view.

The thread looks interesting, I’m gonna read it later today. Alos I understand your thinking, since I used HLSL in the past, when working with materials, I think of them as HLSL codes. Thanks!