Jump to content
  • Advertisement
Sign in to follow this  
simonlourson

Help with 2D post processing pixel shader

This topic is 3912 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm having a problem with shaders in managed directX9, here it is: I'm curretly able to do a simple pixel shader to distort the scene, but what I would like to do is using a texture to store distort information, so I don't have to compute it each frame. To achieve this I created a texture, wich I called "bumpMapTexture", filled it with blue, and the problem is: I can't access that blue from the shader... Here is the shader code: <source> texture screenTex; texture bumpMap; sampler Screen = sampler_state { Texture = <screenTex>; }; sampler Bump = sampler_state { Texture = <bumpMap>; }; float4 PixelShader(float2 texCoord: TEXCOORD0) : COLOR { float4 color = tex2D(Screen, texCoord); float4 bumpMapColor = tex2D(Bump, texCoord); color = bumpMapColor; return color; } technique { pass P0 { PixelShader = compile ps_2_0 PixelShader(); } } </source> And here is the code from my application: <source> // Initialising EffectsTexture = new Texture(D3DDevice, (int)VideoSettings.resolution.X, (int)VideoSettings.resolution.Y, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default); bumpMapTexture = new Texture(D3DDevice, (int)VideoSettings.resolution.X, (int)VideoSettings.resolution.Y, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default); rippleEffect = Effect.FromFile(D3DDevice, "myShader.fx", null, ShaderFlags.None, null); rippleEffect.Technique = rippleEffect.GetTechnique(0); // Drawing // Fill bumpMapTexture with blue batchSprite.Device.SetRenderTarget(0, bumpMapTexture.GetSurfaceLevel(0)); batchSprite.Device.BeginScene(); batchSprite.Device.Clear(ClearFlags.Target, System.Drawing.Color.FromArgb(0, 0, 0, 255), 1, 0); batchSprite.Device.EndScene(); // Set the bumpMapTexture in the shader EffectHandle bumpMap = "bumpMap"; rippleEffect.SetValue(bumpMap, bumpMapTexture); // Actually using the shader (between D3DDevice.Begin / EndScene rippleEffect.Begin(FX.None); rippleEffect.BeginPass(0); batchSprite.Draw(EffectsTexture, new System.Drawing.Rectangle(0, 0, (int)VideoSettings.resolution.X, (int)VideoSettings.resolution.Y), Vector3.Empty, Vector3.Empty, System.Drawing.Color.White); batchSprite.End(); rippleEffect.End(); rippleEffect.EndPass(); </source> As I said, to me with this the wole screen should be blue, instead it renders the EffectsTexture unmodified... This is probably very simple as I am one-week new to shaders, but I need it to go on with my project. Thank you all! [Edited by - simonlourson on May 2, 2008 6:11:22 AM]

Share this post


Link to post
Share on other sites
Advertisement

hey there

i'm not that familiar with the managed version so this might not help, but i see a couple things that messed me up initially...


float4 PixelShader(float2 texCoord: TEXCOORD0) : COLOR
{
float4 color = tex2D(Screen, texCoord);
float4 bumpMapColor = tex2D(Bump, texCoord);

color = bumpMapColor;
return color;
}

it looks like you are overwriting color with bumpMapColor.

so, there is no need to sample the tex2D(Screen, texCoord), because
the result is being overwritten.

so, the shader compiler sees this, optimizes, and you aren't actually sampling the texture you want when you call tex2D(Bump, texCoord);



technique
{
pass P0
{
PixelShader = compile ps_2_0 PixelShader();
}
}

don't you have to say VertexShader = NULL; if you want the standard pipeline t+l. maybe not i'm not sure.


</code>
i believe the keywords are 'source and /source'

you can edit your posts after you commit them too you know.

hope this helped.

-programmer_tom

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!