Sign in to follow this  
ekba89

writing data to texture

Recommended Posts

ekba89    788
I'm implementing particle system in gpu and now i want to save some of particle's data which can change into a texture. But the problem is i don't know how can i select correct pixel to write since rendering in pixel shader is not controlled by us. Any ideas how can i do this? Thanks.

Share this post


Link to post
Share on other sites
Aqua Costa    3692
You can create a texture with size 5x1, so you can store 5 different colors (values). If you want to write a value to the first pixel set the viewport to (0,0), width = 1 and height = 1, if you want to replace the value in the second pixel set viewport to position (1,0) and so on.

Share this post


Link to post
Share on other sites
ekba89    788
But i want to update texture when i update particle. I mean i'm updating particle in vertex shader and there are some of it's attributes that can change. So when in pixel shader i want to save them.

Share this post


Link to post
Share on other sites
Aqua Costa    3692
What version of API are you using? And what kind of attributes (life time/position/velocity) do you want to store?

If you use DirectX 10, you can use Geometry shader stream-output to store particles attributes in vertex buffers... [url="http://developer.download.nvidia.com/SDK/10/direct3d/Source/rain/doc/RainSDKWhitePaper.pdf"]Like explained in this whitepaper[/url]. If you need some help ask for it :lol:

Share this post


Link to post
Share on other sites
ekba89    788
I'm using directx 9. And what i want to save is how much a particle moved. Let me show you the code.

[code]
float3 position = inPos.xyz;

float3 positionDelta = (velocityAndAge.xyz * xTotalGameTime);

position += positionDelta;
[/code]

Here i'm finding positionDelta with total game time and i want to change it to float3 positionDelta = (velocityAndAge.xyz * elapsedTime); where elapsed time is time between two frames and want to save position delta to a texture. Also i'm open to new ways of doing this i mean i'm not sure if saving data like this possible. But as you mentioned if there is a way to store output to vertex buffer from shader for dx9 it is what i'm looking for i think. Thanks.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this