I’ve set up a material that links from an Absolute World Position node through to the Base Color of the material. Essentially I’m setting up a material that’s noise and I then want to be able to read color values from that “noise material” in code to then build a terrain mesh. This is just a fun learning exercise in case you’re wondering why I’m doing something Unreal is already perfectly apt at doing.
But I can’t figure where to even start to plug a world position in to the material via code and extract a color value. I can’t see any function names that look remotely like they’d do this. Maybe the GetVectorParameterValue method but the parameters for that don’t seem relevant for what I want to do.
Can I even achieve this? Or is there perhaps a better way where I can still create a material/texture in Unreal and then extract color values in code?
However from material, no idea, unless you can get data out of HLSL code.
(there is with render target) and probably no way to get it directly by parameters etc.
For your idea maybe you do not need to use texture, instead use raw data, load it to some structure, and use C++ to get height values.
And add hlsl shader that renders texture from raw data.
You don’t read back values from the rendering pipeline, really. It’s super slow, because it will have to stall the GPU pipeline to synchronize with the CPU.
If you still need this, the best option is probably to render the material in question to a render target, and then read back the pixels of this render target. The good news is that you can efficiently render many points at once this way, which should help with performance when generating terrain.
Thanks for the tips. Looks like time to read up on render targets. That sounds the best solution. I’m not worried about performance so long as we’re not talking minutes to read all the pixel values for a 256x256 terrain.
I wonder alternatively whether I could somehow make a function node graph that I could plug in to the material graph which applies the noise to the material but which I could also read the function directly in code. That way I could tweak the functions nodes in a graph to see the visual representation of its changes in the material but I could read the function in the code rather than read the material output. I’m not sure I’m explaining that well or if such a thing exists.