How would I go about changing this vertex shader to use it with UE4s' materials?

Hey all, so I got this vertex shader that I use to generate a density field texture. I then use that texture and run a marching cubes algo. on it to create a mesh.

I believe I could achieve this by rendering to a texture using a material. Anyone know how to do that? This has to run on OpenGLES 3.0. That’s why I’m not doing it all in a compute or geometry shader.

Here’s the code, it’s really simple. In my engine that I’m porting from, I used a vertex shader and computed 16777216 values that get returned in an array.

out float density;
void main() {
vec3 p = to3D(gl_VertexID, 256, 256); //Gets a 3d position on a 256x256x256 grid, based off our 1d index(vertex id).
… compute density here…
density = someVal;

Here is a pic of my material attempt, it should work, It’d be nice if was able to sample a 3d texture.

Now I just need to output the material to a texture.

I use vertex shaders for stuff like this all the time and it’s incredibly handy, so any help is appreciated thanks.

why are you using texture object instead of texture sample?

I’m not sure I understand… I have both a texture sample and texture object. The texture sample needs a texture object…?

The only place you have an error on there is where you are imputing an object. Why not use a texture sample?

You’re plugging a Vector3 (3d whatever) into a Vector2 (UV) which probably won’t work.

I guess I didn’t word my questions properly. I’m trying to find out how to sample a 3d texture and how to get access to the texture output from the material at runtime. In OpenGL, normally this is called a transform feedback. No idea how to modify posts either, Epic, is there a reason I can’t edit my posts?

You could take a look at this plugin: , maybe you’ll find an answer there.

Definetly some interesting stuff in there, thanks for the link!