need help with "There was an error compiling expression"

Started by
10 comments, last by Cirno 11 years, 11 months ago
Hi!


Maybe it is because I don't know how to draw on a Texture2D object in HLSL..if the drawing code is in XNA(and the HLSL code only computes the particle positions), it seems not to have made full use of HLSL..

The XNA code is used to build a command list that tells the GPU what to do. Thus, at some point you need XNA code. The work is done on the GPU. Or what else do you mean with drawing code?

Here is an example that basically does what you want. It’s fairly detailed, so I hope you can work your way through it. If you have questions, feel free to ask!


Also, binding the texture to the pipeline may cause some strange problems, for example, if a rander target is current render target of the graphics device, sampling on that render may get strange color(when I was trying to write an additive color mixing type)...

That’s right. Reading from and writing to the same resource yields undefined behavior (before Dx11). For this reason, we maintain the data in two textures and toggle between them (ping-pong). Thus, you read from another texture than you write to. The sample above builds a temporary buffer to which the results are written. Afterwards the result is copied back to the other “original” texture. Actually, this is not necessary, since you can toggle between both textures, like this:
bool ping = true;
RenderTarget2D positionsPing;
RenderTarget2D positionsPong;

Draw() {
if (ping) { // Pong -> Ping
// Bind texture positionsPong
// Bind render target positionsPing
}
else { // Ping -> Pong
// Bind texture positionsPing
// Bind render target positionsPong
}
// Bind rendertarget 0. (Unbind render target)
ping = !ping; // Toggle ping pong.
}


Best regards!
Advertisement

bool ping = true;
RenderTarget2D positionsPing;
RenderTarget2D positionsPong;

Draw() {
if (ping) { // Pong -> Ping
// Bind texture positionsPong
// Bind render target positionsPing
}
else { // Ping -> Pong
// Bind texture positionsPing
// Bind render target positionsPong
}
// Bind rendertarget 0. (Unbind render target)
ping = !ping; // Toggle ping pong.
}

Thanks very much..now I understand the 'ping-pong' technique:)

This topic is closed to new replies.

Advertisement