- Joined
- Feb 5, 2008
- Messages
- 6,252
- Points
- 83
Alright I know there are some advanced coders there,
I recently started getting aquainted with 3D graphics and all, wanna start a few learning projects (among which is a rudimentary 3D engine), and on the way picked up some shader coding.
Anyway, here's the problem.
I have a shader file that has 4 passes. Each pass relies on the result of the one before it.
I am using the shader in managed C# environment, in XNA game studio.
I am having trouble saving the result of each pass and forwarding it to the next. Info on using in-shader texture buffers between passes and general shader scripting is unbelivably scarce on the internet, as well as any simple shader examples.
My ideal solution is to run the shader only once, and within the shader do all the saving of results but I just cannot find any way to do it. If anybody knows, I'd appreciate that first.
Second, if not, I'd appreciate to know what I'm doing wrong with the shader calls in C# code.
Here is the end code of the shader. The actual shader I'm sure works, since I based it off Microsoft's Post process Glow example which uses like, 6 game classes and 3 seperate FX files. I made it into one shader file to be used with one class - simple as.
Here is the code to call each individual pass, store the result, and forward it to the next pass:
As you can see, I am using rendering to texture method for the process rendering.
After this, I have made another Spritebatch.begin to draw 4 textures to 4 quarters of my screen.
Top left would be the rendered 3D geometry, before post process, and rest of three would be results of various passes.
The 3D geometry is rendered nicely, however all subsequent shader pass results are completely empty. Why?
What is the correct way to obtain shader pass result into a texture?
Here is the full shader source code in case I made a logical mistake porting it:
[C] Bloom shader - Pastebin.com
Help appreciated! Much! Lost sleep over this!
I recently started getting aquainted with 3D graphics and all, wanna start a few learning projects (among which is a rudimentary 3D engine), and on the way picked up some shader coding.
Anyway, here's the problem.
I have a shader file that has 4 passes. Each pass relies on the result of the one before it.
I am using the shader in managed C# environment, in XNA game studio.
I am having trouble saving the result of each pass and forwarding it to the next. Info on using in-shader texture buffers between passes and general shader scripting is unbelivably scarce on the internet, as well as any simple shader examples.
My ideal solution is to run the shader only once, and within the shader do all the saving of results but I just cannot find any way to do it. If anybody knows, I'd appreciate that first.
Second, if not, I'd appreciate to know what I'm doing wrong with the shader calls in C# code.
Here is the end code of the shader. The actual shader I'm sure works, since I based it off Microsoft's Post process Glow example which uses like, 6 game classes and 3 seperate FX files. I made it into one shader file to be used with one class - simple as.
Code:
technique Bloom
{
pass Pass1
{
PixelShader = compile ps_2_0 Extract();
}
pass Pass2
{
PixelShader = compile ps_2_0 BlurHorz();
}
pass Pass3
{
PixelShader = compile ps_2_0 BlurVert();
}
pass Pass4
{
PixelShader = compile ps_2_0 Combine();
}
}
Here is the code to call each individual pass, store the result, and forward it to the next pass:
Code:
spriteBatch.Begin(0, BlendState.Opaque, null, null, null, bloom);
graphicsDevice.SetRenderTarget(extract);
bloom.Parameters["procScene"].SetValue(renderOutput);
bloom.CurrentTechnique.Passes[0].Apply();
spriteBatch.Draw(extract, Vector2.Zero, Color.White);
graphicsDevice.SetRenderTarget(blur1);
bloom.Parameters["blur"].SetValue(extract);
bloom.CurrentTechnique.Passes[1].Apply();
spriteBatch.Draw(blur1, Vector2.Zero, Color.White);
graphicsDevice.SetRenderTarget(blur2);
bloom.Parameters["blur"].SetValue(blur1);
bloom.CurrentTechnique.Passes[2].Apply();
spriteBatch.Draw(blur2, Vector2.Zero, Color.White);
graphicsDevice.SetRenderTarget(finalRender);
bloom.Parameters["blur"].SetValue(blur2);
bloom.CurrentTechnique.Passes[3].Apply();
spriteBatch.Draw(finalRender, Vector2.Zero, Color.White);
graphicsDevice.SetRenderTarget(null);
//spriteBatch.Draw(finalRender, Vector2.Zero, Color.White);
spriteBatch.End();
As you can see, I am using rendering to texture method for the process rendering.
After this, I have made another Spritebatch.begin to draw 4 textures to 4 quarters of my screen.
Top left would be the rendered 3D geometry, before post process, and rest of three would be results of various passes.
The 3D geometry is rendered nicely, however all subsequent shader pass results are completely empty. Why?
What is the correct way to obtain shader pass result into a texture?
Here is the full shader source code in case I made a logical mistake porting it:
[C] Bloom shader - Pastebin.com
Help appreciated! Much! Lost sleep over this!