How to write Slate HLSL/USF shaders?

Is it currently possible to make a Slate brush use a custom shader (HLSL .usf file)?

I have looked through the source, and I assume I need to make a Box-type FSlateDrawElement in the widget’s OnPaint. The FSlateBrush of that element should then somehow have the custom shader applied to it. FSlateBrush has a UObject* ResourceObject, comment says it is

The image to render for this brush, can be a UTexture or UMaterialInterface or an object implementing the AtlasedTextureInterface.

Is it possible to make a UMaterialInterface type object that uses custom shader code? If so, what is that code like?

Is there an example of how GPU code specifically for Slate would look like? For example, where is the shader code that draws a normal UTexture2D using the widget’s UVs? I cannot find any related shader files in the source at all.

Hey k_a_s_s_k_a_s_s,
you should be able to use materials as a brush, because as you already found in the source, the ResourceObject can be a Texture or a Material, so you should be able to use shader code inside the UI.
I don’t have specific examples for the UI, but you can find HLSL implementations on the material editor, even with an external HLSL file.
I found this guide on the internet where there are more infos on how to implement custom shader code files (.usf) inside the material editor:

Hope it helps!

Thank you for the reply, however the Custom material node isn’t really helpful for most cases. I need to send custom buffers to the GPU, and I don’t think the node allows to access that.

I don’t know what kind of code you want to make, but maybe the only way is to take a look at SlateRHIRenderer module or platform-specific code (for example SlateD3DShaders.h or SlateOpenGLShaders.h) for OpenGL or DirectX. Anyway I have never done something like this, so if there’s someone with more knowledge of this part of the engine, I will be happy to read him and learn more. Unfortunately there’s no documentation about many engine modules or how the engine works with some specific things (except the one wrapped from the code comments, that I don’t find very useful), and at the moment the only way to learn more about how some modules work is to read the code and lose a lot of time.
I hope I’ve been helpful in some way! :grinning:

Thank you! Found those as well, and seems like that’s the only way.

But as you say, quite a poking-in-the-dark approach.