GLSL

Hi,

I was wondering if there is a way to create GLSL shaders (in custom node with specific configuration written at start ?) to be able to use GLSL shaders already written without recreating everything in the material blueprint. Maybe a “custom GLSL node” or a specific way to implement GLSL using a Material C++ class ?

If not, is there an easy way to check if HLSL conversion done by Unreal will be OK for Android ? (I saw it should work but tried it and make my app crash on Android because of the shader)

Another point I have some process to do inside my shader and I should iterate (for loop) and break the loop regarding a condition. How could I do that ? (for instance to render a fractal as Mandelbrot checking the condition to stop the iteration to render the point inside (white) or outside (black) the fractal area).

Thanks in advance,

Regards

Steps to Reproduce

Hello there,

There isn’t a way to use GLSL that I’m aware of, though the engine should convert HLSL types to their equivalents. There are also MaterialFloat types for portability.

In terms of checking if a shader compiles for a given platform, provided the platform is available to target, it should be possible to check for a failure to compile.

Adding the Android Vulkan paths to the platform stats should give error messages on compile.

[Image Removed]Additionally, platform preview in editor should highlight any compile errors.

I believe all current platforms support loops in GPU code. I would be remiss not to mention that loops can lead to divergence between threads on the GPU, and that can lead to lowered performance. A standard loop with a break should be fine, you can decorate it with the LOOP macro to force the compiler to not unroll.

Best regards,

Chris

thanks !

There is no kind of rules to follow so we can be “sure” that the HLSL code inside the node can be converted & compiled for Android ? it should be great to have a kind of “HLSL functions available for Android compilation” guide.

Most HLSL should work without any issues.

If the mobile renders are selected, the material graph should warn or error on compile when a platform doesn’t compile, but the best way to be sure is to test on target. A SceneTexture lookup is one that doesn’t convert as mobile uses a version of those functions prefixed with ‘Mobile’ that may require:

#if SHADING_PATH_MOBILE
MobileSceneTextureLookup
#else
SceneTextureLookup
#endif

In general, most portability issues I’ve personally encountered have been the result of differences in the renderer rather than an HLSL conversion issue. For example, it’s common to run the forward rendering path on mobile platforms, and since forward rendering doesn’t emit GBuffer textures, attempting to sample these textures is not functional.

I hope that helps.

Best regards,

Chris