• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Numsgil

[.net] C# PathGradientBrush

10 posts in this topic

I'm working on a color selector in C# for a particle emitter for a game. Users select a start min and max color, and an end min and max color, and I draw a quad representing those four colors, and all the possible values in between. At present I'm using a PathGradientBrush, and set four points up as the path, and assign colors to each of them. The problem I'm having is a visual artifact: a line that runs along the diagonal of the resultant image. Visual artifact Free Image Hosting at www.ImageShack.us No artifact going in the other direction, though: Free Image Hosting at www.ImageShack.us I know why the artifact appears. It has to do with where the "center" is. Right now I'm setting the center point to the upper left corner, as it minimizes the artifact (only shows up in one direction). I'm not sure how to remove it entirely though. Ideally I'd like something that looks like a quad in DirectX or OpenGL. (clicky), but I can't figure out how to get there. I've tried looking on sites that do C# graphics tutorials, but they all seem to have that same artifact. Here's the code I'm using to set up the PathGradientBrush:
brush = new PathGradientBrush(new PointF[]{
    new PointF(0,                        0),
    new PointF(0,                        ClientRectangle.Height),        //StartB
    new PointF(ClientRectangle.Width,    ClientRectangle.Height),        //EndB
    new PointF(ClientRectangle.Width,    0)});                           //EndA           

brush.CenterPoint = new PointF(0.0f, 0.0f);
brush.CenterColor = StartA.Color;
brush.SurroundColors = new Color[] { StartA.Color, StartB.Color, EndB.Color, EndA.Color };


Any ideas people have would be appreciated.
0

Share this post


Link to post
Share on other sites
You need a better anti-aliasing filter... does the PathGradientBrush have any quality properties? You need to enable bilinear filtering, it looks like it's using nearest-neighbor.

Trying setting Graphics.InterpolationMode to high quality.
0

Share this post


Link to post
Share on other sites
I tried various settings of interpolation mode but none of them have any noticable effect. I don't think this is an aliasing issue. I've seen it in pretty much every tutorial or article with pictures that talks about the pathgradientbrush. More and more I'm thinking it's a logical flaw in the way the brush interpolates between the center and it's edges.

At the moment I'm thinking of doing a four pass drawing using four linear gradient brushes. One would interpolate for each edge, and the results would be alpha blended. So if I had a square that looked like this:


R-G
| |
B-W


with R = red, G = green, B = blue, W = white, you'd do a base layer that was a Red to Blue, then a layer of Green to white, with alpha fading to 0 as it moved left. Then do the same along the vertical direction. Hope I've explained it well.
0

Share this post


Link to post
Share on other sites
Any reason why you can't use the [url=http://msdn2.microsoft.com/en-us/library/system.windows.forms.colordialog.aspx]ColorDialog[/url] class?

Another option is to use a pre-made image (in Photoshop or whatever) with the gradiants and then use a "GetPixel()" method to read the pixel from the bitmap to select the color.

You could have an image like the one you linked to for selecting the hue then you could have two rectangles with Black->Color and White->Color.
0

Share this post


Link to post
Share on other sites
Two reasons for not using the color dialog:

1. My custom control needs to show four user selected colors being Lerped together. The color dialog wasn't built for that.

2. My team got fed up with the default color dialog, so we built our own :P

Likewise a prebuilt bitmap wouldn't work because the four colors need to be selected at run time. I have, however, also tried outputting to a small bitmap and scaling the bitmap, but while the result is smooth it's a far cry from a true Lerp of the four colors. SetPixel is possible too, but I'm trying to avoid something so brute force.
0

Share this post


Link to post
Share on other sites
I have some code that I wrote that can do hue rotation if your interested. Basically you could have a pre-made image with all the shades of a color. Then using my ColorProcessing class you can rotate the hue using a slider. It also supports saturation and brightness. I've used this class in a few of my projects and it's fast enough to work on an image in real time using sliders. So probably ideal for you if you can't get the gradient thing sorted.

ColorProcessing.zip
0

Share this post


Link to post
Share on other sites
Thanks, but I did actually write my own little control to select a single color graphically using hue, sat, and lum. The problem here is that I have potentially four unique colors in the four corners, meaning that I need some way to bilinearly interpolate between those four colors quickly. And these four colors need to be determinable at run time from the user.

Basically, the user selects the upper left corner, and a dialog pops up, asking for a color choice (where either the default C# colordialog could be used, or a custom color control). Once the user selects a color, the control updates itself and that corner becomes the new color.

I got a hacky solution up right now, where I just brute force the bilinear calculation and SetPixel for each pixel. It takes about a second to draw, so it's something I could live with, but a more manageable draw time would be nice, too.
0

Share this post


Link to post
Share on other sites
A second for rendering? Hmm that's a performance drag. I suppose your using Bitmap.LockBits for that. Perhaps a C++ dll would improve that or you could use pointers with unsafe code.

Anyway found this on the Net, not sure if it will be any help

http://msdn2.microsoft.com/en-us/magazine/cc164113.aspx
0

Share this post


Link to post
Share on other sites
Not the most optimal way, but when I did my photoshop style color picker I ended up having a loop for the height of the image to be displayed and used a LinearGradientBrush/FillRectangle, I might be wrong but it could be that gradient/paths tend to use a fanning/triangle system, hence the results you get, I had to do it my way because of how the HSL works and can't work just using 4 color corners, otherwise the color you pick isn't usually the color you get.
0

Share this post


Link to post
Share on other sites
Actuallly Niksan2 reminded me of another optimization when using Bitmap.LockBits. For some reason if your looping through a bitmap's bits using Bitmap.Width and Bitmap.Height there is a substancial performance hit. It sounds crazy I know but creating variables for Width and Height and using them in your loops instead will actually improve the speed possibly with noticable effect.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0