x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to create new state texture for GPU particles?

I'm modifying the engine source for a project I'm doing, and I'm trying to work with GPU particles.

For GPU particles, there are two state textures used for particle simulation: PositionTexture and VelocityTexture. I'm trying to add another texture ColorTexture that will store and update color in the GPU simulation just like the position and velocity texture.

I thought I could just go through the code and mirror the operations on the PositionTexture or VelocityTexture, but that hasn't been working. The part I'm missing is the specific place in the code where the FNewParticle attributes are first written to texture.

Product Version: UE 4.17
Tags:
more ▼

asked Feb 09 '18 at 12:50 AM in C++ Programming

avatar image

wingsoffir
1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Have a look at this shader in the engine's installed location: Engine\Shaders\Private\ParticleGPUSpriteVertexFactory.ush

 /** Texture containing positions for all particles. */
 Texture2D PositionTexture;
 SamplerState PositionTextureSampler;
 Texture2D VelocityTexture;
 SamplerState VelocityTextureSampler;
 Texture2D AttributesTexture;
 SamplerState AttributesTextureSampler;
 Texture2D CurveTexture;
 SamplerState CurveTextureSampler;

That is where you'd add your own texture and sampler and add in the gpu logic in that shader

This is a vertex factory shader. So you'll have a corresponding vertex factory class in C++. Have a look at FGPUSpriteVertexFactory under Engine\Source\Runtime\Engine\Private\Particles\ParticleGpuSimulation.cpp

This class takes in the references of the state textures (e.g. PositionTextureRHI, VelocityTextureRHI)

You set these textures from here: FGPUSpriteDynamicEmitterData::GetDynamicMeshElementsEmitter

more ▼

answered Feb 09 '18 at 05:45 AM

avatar image

Ali Akbar
681 2 5 8

avatar image wingsoffir Feb 09 '18 at 06:14 PM

I've been looking a lot at both Engine\Shaders\Private\ParticleGPUSpriteVertexFactory.ush and Engine\Source\Runtime\Engine\Private\Particles\ParticleGpuSimulation.cpp. If I could access my color texture in ParticleGPUpriteVertexFactory, it's clear to me what to do with it in that shader. I'm currently setting my color texture in FGPUSpriteDynamicEmitterData::GetDynamicMeshElementsEmitter like so:

 //Engine code to set Position and Velocity Texture
 VertexFactory.PositionTextureRHI = StateTextures.PositionTextureRHI;
 VertexFactory.VelocityTextureRHI = StateTextures.VelocityTextureRHI;
 
  //My code to set up my color texture
 VertexFactory.ColorTextureRHI = StateTextures.ColorTextureRHI;


Also, I've been looking at Engine\Shaders\Private\ParticleSimulationShader.usf, which is where the Position and Velocity of GPU simulated particles are updated. Do I also need to add my texture there so I can do color simulations?

I'm also still not sure exactly how we get from creating new particles in FGPUSpriteEmitterInstance::BuildNewParticles to actually writing the properties of those particles to the state textures.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question