Archived

This topic is now archived and is closed to further replies.

softimage

how to pass a value among PS calls?

Recommended Posts

even if i use static to prefix a variable in HLSL, it seems only static inside one function of one pixel shader invocation. when it comes to processing another pixel, the static variable is assigned the initial value again. does that mean registers except constant ones will be reset for each invocation? so how can i save a value for the next PS calls?

Share this post


Link to post
Share on other sites
You have three kinds of data. The pixel shader transforms this into a pixel with a certain color.
The data is:
- static, the constants you describe
- vector related data, interpolated texture coordinates, so if you draw a triangle with tex coords between 0 and 1 and you draw the center pixel you get 0.5,0.5.
Normals are also interpolated, if the normal varies between 0,1,0 and 0,1,1 your pixel would get the normal vector 0,1,0.5 as input.
- user supplied variable data. These are the textures you have loaded.
Traditionally you take the vector data as-is, and process the textures as pixel input unmodified. But because it''s a pixel shader you can do much nicer things. For example ignore the normal data you get and use the second texture for normals (a normal map, used for bumpmapping).

So, to answer your question, statics are really static and cannot be changed between pixels. If you want that, store your data in a texture, add a pair of texture coordinates and a texture state and use that as input.

Share this post


Link to post
Share on other sites
quote:
Original post by Fidelio66
If you want that, store your data in a texture, add a pair of texture coordinates and a texture state and use that as input.


So how could I save it to a texture?
I can only find texture lookup functions like tex2D in HLSL.
Should I change my rendertarget to a temporal texture and change back later?
But it seems that inside HLSL I can''t SetRenderTarget.

Share this post


Link to post
Share on other sites
You save it to a texture by outputing it from the pixel shader. Then in a seperate pass, you read that data back in and continue computation.

What is it exactly that you''re trying to do? Maybe if you describe what you''re trying to accomplish, the members of this board could suggest different ideas that would do what you want.

neneboricua

Share this post


Link to post
Share on other sites
What I want to do is like this:

float4 colorTemp, colorResult, colorSource;
colorSource = tex2D(samplerCurrent, coordCurrent);
if (coordCurrent.x == 0)
colorTemp = colorResult = colorSource;
else {
colorTemp = Process(colorTemp, colorSource);
colorResult = Process2(colorTemp);
}
return colorResult;

So colorTemp after one pixel''s shading should be passed
to the next pixel, not the next pixel shader pass within the
same pixel''s shading.

Share this post


Link to post
Share on other sites
Ok. I''m sorry to tell you that there is no way for a GPU to do what you''re asking for. Graphics chips are SIMD (Single-Instruction Mulitple-Issue) machines. You give the chip a bunch of data and ask it to perform the same operation on all that data.

GPU''s capable of using pixel shaders have more than one pixel shading pipeline (for example: the Radeon 9800 has 8 pixel shading pipelines so that it''s working on shading 8 pixels at once). Since the card is shading more than one pixel at a time, there is no way for you to pass data computed during the shading of one pixel to influence the shading of another pixel. Also, there is no way to control the order in which pixels are shaded; that''s up to the driver

Unfortunately, if you really need to do what you stated above, you''re going to have to do this computation on the CPU. That means you''ll need to lock the texture you''re reading from and perform those calculations in C++ code.

neneboricua

Share this post


Link to post
Share on other sites