Jump to content
  • Advertisement
Sign in to follow this  
TheSpotlessPane

Basic Image Processing (XNA)

This topic is 2632 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

Is there any way to achieve custom effects on images without having to use HLSL? (HLSL just seems too far above my level right now)
I'd like to be able to seamlessly blur an image into focus. I understand that this can be achieved (generally speaking) by individually modifying each pixel through the use of kernels.
In XNA, is there a way to access individual pixels in an image? I've searched the internet pretty thoroughly for blur techniques in XNA, but I usually just end up on a page where they're talking about HLSL shaders.
Is there not a way to achieve a blur effect like this by just processing the image directly through XNA? And of course, this question necessitates another one...if you CAN modify pixels individually, is it even realistic to expect to achieve a seamless "blur in" effect like this, or would it be way too costly? From what little I've gathered, HLSL gives you direct access to the power of the GPU so that you can do expensive things like this without compromising performance. Are most image processing techniques too expensive to aim for without going the HLSL route?

If most custom effects require HLSL, I guess I'm just gonna' have to man up and get a book on it. I don't want to program a game in a way that doesn't give me any more freedom than if I were to just download some software like RPGMaker or GameMaker.

Thanks for any guidance.

Share this post


Link to post
Share on other sites
Advertisement
It is possible to modify the individual pixels in a texture in XNA. It would go something like this:


Texture2D texture = Content.Load<Texture2D>(@"path\to\texture\to\blur");

Color[] textureData = new Color[texture.Width * texture.Height];
texture.GetData<Color>(textureData);

// do something with textureData

texture.SetData<Color>(textureData);



You would have to replace the type Color with whatever you texture actually holds (you can figure out by looking at the Format property).

The only drawback to this approach is that it's slower than using shaders. With this method you have to copy the texture from the graphics card to the cpu and back (with shaders the texture is modified by the graphics card and stays on the graphics card.) So with large textures this approach is not real-time friendly.

What you could do is blur your texture at run-time and blend between the blurred and unblurred version of the texture. Though I would recommend you to learn HLSL since no other options exist in XNA or DirectX 10+.

Victor

Share this post


Link to post
Share on other sites
My advice is to just dive into HLSL, it is not as intimidating as it first seems. And, once you get the hang of it, it's actually a blast to muck around with :)

I don't know of any books to recommend, but have you read through these yet? Especially the "post processing" tutorial?

Share this post


Link to post
Share on other sites
HLSL is child's play to learn if you are already familiar with programming.

Seriously, spend an evening or two and you'll have all the basics down needed for any simplistic shader work; probably enough for a decently complex one as well if your math skills are up for it.





Share this post


Link to post
Share on other sites
Even if you did all of the SIMD/multithreading magic required to make a CPU implementation fast, it would still slow you down tremendously due to CPU/GPU synchronization. The CPU will always be running ahead of the GPU (often 2 or 3 frames ahead), with the GPU running behind and executing commands from the command buffer. This allows them to work in parallel, so that you get the most out of both. If at some point you say "hey, I need the results of this drawing operations RIGHT NOW so that the CPU can do some stuff to it", you'll cause a sync point to occur where the CPU just sits around waiting for the GPU to finally catch up. Even worse, the GPU would then have to sit around and wait for CPU to finish the post processing which would slow you down even more.

To make a long story short, just learn how to do it with HLSL. It is not an understatement at all to say that writing shaders is the single-most important aspect of modern graphics programming, and learning how to do that will open you up to an enormous number of possibilities. There are some samples on the AppHub website that can help get you started, such as the Bloom sample.

Share this post


Link to post
Share on other sites
Thanks a lot, guys. The HLSL comments are definitely encouraging, I'm gonna' check out that link when I get a chance. The GetData method will come in handy as well, I'm sure. Sounds like it won't be a fool proof method for real time effects, but knowing about it will certainly open a lot of other doors, I imagine.

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!