#Spawn objects using a texture

1 messages Β· Page 1 of 1 (latest)

wicked abyss
#

Hey all, before I go down this path and find out it is not possible, I was wondering if anyone knows if this is possible? I have a player that has two modes, light and dark, when he goes into dark mode, I overlay a cracked texture onto my world inside of the material, and in that cracked texture, I plan to have a wind noise cross over the map, hoping to have it effected by distance of walls as well to add some gameplay
Can you make a wind texture inside of a material to be a spawning platform? I have never spawned anything yet, still learning! Thanks for any help!

silver matrix
#

Not sure I quite understand. Are you wanting to spawn stuff based on say, how intense the wind is at a particular point? This isn't really something that is possible in a material. The communication with a material is generally only one way (Blueprint / particle system -> Material), as reading information back from the GPU is usually very slow.

wicked abyss
#

Thank you so much for a reply! valuable information!
So I have a wave of cracks that cross the map when in dark mode, and in the wave of cracks, I wanted to have a them be a spawn platform thing, and have the player carry a sphere trigger, the trigger would be a % chance a skeleton can spawn in them but it sounds like its not possible?
As the cracks are a red emissive, am I able to trigger if a red colour passed by?
attaching a video of the waves of cracks which I would like to spawn on

silver matrix
#

With just a material, I don't think you would be able to do it easily. You might be able to do something with the Niagara particle system as I think it has more advanced CPU / GPU communication features. I'm unfortunately not very familiar with Niagara yet though. What I would probably do is have some very simple rough approximation of the red areas on the CPU and pan those at the same rate. You could use simple box colliders for this. That's probably the easiest way.

wicked abyss
#

I will try and do some research into it, thanks for a pointer and really appreciate the reply πŸ™‚

silver matrix
#

I also found a way you can do what you were initially thinking with just blueprints. Though it might be a bit expensive performance wise. You may be able to mitigate by using a very small render target. Basically you can put a scene capture in you level and capture a picture of the ground. Then you can call one of the read render target blueprint nodes to get the color values from a portion of the image.

#

Note the tooltip πŸ˜‚

#

You can set the scene capture up to just capture the landscape as well to save some more perf

#

I would still probably try not to do this though. But if it's too difficult to do any other way, then this might be an option.

wicked abyss
#

i never expected another reply, thank you so much for going deep into it and finding a solution for me! I think if its expensive it might not be a good idea as its kind of a open world but happy to know its possible, I might try think of another way I can create a moveable spawn which matches the game style that doesn't bog the cpu, or I could just stick to a cube spawn that follows the player for now and just add some % chance of a skeleton spawn, and then upgrade on it as I progress into the game design
Thank you again! honestly so appreciate this! Will keep this info in mind πŸ™‚

silver matrix
#

No worries. Another shower thought I had was that you could bake your noise mask to a render target texture, as described here https://www.unrealengine.com/en-US/tech-blog/getting-the-most-out-of-noise-in-ue4 . Maybe at a lower resolution. Then use those blueprint nodes as a one off to read your noise texture to a CPU color array. That gives you a representation on the CPU that exactly matches the noise you use in your material. Then you can just pan / scale the lookup coordinates on in a blueprint to match the uv panning / scaling you use in your material.

Unreal Engine

UE4 has had material based procedural noise for some time now, but most users have had to limit their usage of it due to its high performance cost.Β We have addressed these needs in Unreal Engine 4.13, and here's how you can get the most out of it.

wicked abyss
#

So I am using a noise map I made in substance designer, blended a few noises together and leveled the blacks/whites out to create the noise below, its only a 512x512 so I guess I wouldn't have to bake it? baking is only if you decide to use the procedural noises correct? Trying to wrap my head around it sorry haha
I've decided to come back to this another time now as I feel like I am on a road block and progression has halted, going to follow a few more tutorials and return πŸ™‚ I might end up re-replying here when I return
Thanks again for more info! πŸ™‚ you have been a huge help!

dim quail
#

I'll chime in because I recently dived-ed-ed in to this. Usually the best way would be to make the noise in the shader completely mathematical. Eg, if the waves were a sine wave using world position XY then you could use the exact same math on the Blueprint side of things to know where the tips of the waves are. This is essentially how all buoyancy systems work

#

Basically the gpu and cpu are both given the same commands, but are completely separate and don't have to communicate

#

Now, when it comes to textures... You could maybe create an "offline" version of your texture by converting it to an Array, but that would be pretty much as slow as reading from the texture

#

As for interacting with walls and stuff, you could use Distance Fields on the gpu side of things and sphere traces on the cpu side of things

silver matrix
# wicked abyss So I am using a noise map I made in substance designer, blended a few noises tog...

The only reason you would really need to bake your texture to a render target is so that you can use those blueprint nodes to read back the texture to the CPU. This is because they unfortunately only take render targets types as arguments. If your fine with some C++ though, you can just read the data directly from your noise texture, all on the CPU. See here https://isaratech.com/ue4-reading-the-pixels-from-a-utexture2d/

Reading the pixels from a UTexture2D is not particularly difficult, indeed this post on Unreal AnswerHub resume almost perfectly how to do it. However, there are some points missing and one could go in the case where a call to RawImageData->Lock(LOCK_READ_ONLY) will return nullptr. When it happens, it prevents us from reading the pixels,

silver matrix
# dim quail Now, when it comes to textures... You could maybe create an "offline" version of...

I agree that using a bunch of sine waves to create the noise and replicating it on the CPU is another good way to do this. I don't see any reason why using a CPU version of the noise would be slow however. Reading from the GPU is slow because you have to wait for other commands in the GPU command buffer queue to execute before your read-back will execute. Then you have to wait for the data to actually transfer from the GPU, which takes considerably longer than going out to main memory. If the texture is already stored as a 2D float array on the CPU however, reading a single value from this shouldn't be slower than reading from any other array. Panning and other warping effects can be handled by simply replicated the math you are doing on your UVs GPU side to your lookup index on the CPU side. As for memory usage, a 512 x 512 float array would take up about 1MB of memory, which is very reasonable.

silver matrix
#

Just a heads up, if you decide to follow that article on reading texture from C++. Take a look at the comments section to help resolve issues in a packaged build. Looks like a lot of people had trouble with this, but someone at the bottom of the comments got it working and posted the fix.

wicked abyss
#

Thanks for the responses! So you can repeat the same code inside of a blueprint like how you use the materials? Sorry Kind of new to blueprints and learning as I make this game. Thanks for the distance fields suggestion, checked out your video and understand it now! And I have not used C++ inside of Unreal yet, the last time I touched C++ would be in college which was awhile ago now, and most likely would fail to get it to run! I've been learning mainly 3D modelling and texturing but have wanted to adventure over to the coding side of things for awhile now
Do you know of a tutorial I can follow to see how material code can be replicated as a blueprint so I can keep the same values? or how to bake the texture so I can get the blueprint to read back on the texture? I have searched youtube without much luck.
Completely scratching my head over this haha Ill get this figured out in my head soon 🀞

silver matrix
#

I didn't mean anything special by replicate. You will still have to copy the math you do in the material to the blueprint yourself. There's no way to do it automatically. This applies to pretty much any method you use. After baking your noise texture to a render target (like in the article above) and copied it to the CPU. The first thing I would figure out is how to convert from a location on your landscape to a pixel position in the 512 X 512 noise texture. I'd start with no UV modification, panning, or tiling in the material. Then I would add back each of those, and apply the same logic on-top of the CPU side lookup index I calculated before.

wicked abyss
#

sorry I am being slow haha, I saw a screenshot of a simplex noise 2D inside of a blueprint, but I cant seem to use them inside of my blueprints? Do you need a plugin to do this? If I could repeat the exact same code both ends, it would make things easier i think
Otherwise, i will follow a few pixel position tutorials and try figure this out, i would love to get this to work!
You have been such a help, but i think all of this is alittle ahead of me right now haha I need to see it in action to understand it, and i havnt found many videos on this!
I feel like I should follow a minecraft procedural world tutorial to understand how to get the pixel position of a noise?

frosty river
#

There's a GetPixelColor node but it's slow and you would still be a long ways away from getting the actual crack path

#

I would do it the other way around, have the crack path exist as splines or something and then render it to a texture for the post process etc.