Jump to content
  • Advertisement
Sign in to follow this  
guru_florida

OpenGL PixelShader question - I am doing 2D graphing with effects

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

I need some advice. This should be an easy question to answer but not one I can get a clear answer in my searches.

I am drawing 2D graphs using OpenGL and GLSL shader. My goal is to be able to have various effects like the gradient (below the line), line shadows or glow and not just simple 1pixel line.

What I have done is create a quad that fills the graph area. I also loaded my data point array into a 1D texture, like you do for height maps. The shader then does a simple < and > test and if greater it draws transparent, else it computes the gradient. The white line is drawn using regular line drawing over the quad. The green background grid was also done by regular line drawing. I was hoping to do the white line within the shader instead but that may be impossible. (the grid will stay as line drawing.)

Computing the gradient was easy with the pixel shader. But I am unable to detect the edge of the graph/line. Of course, I could pass in a pixelSize uniform and use that to detect when I am in the transition. Easy. But for steep slopes where more than 1 pixel is part of the line this wont work.

I was thinking of drawing the line to a texture, then I can sample the texture but this is a bit of a memory hog especially when I already have the 1D texture with the data points. The point is if I can sample the line, then I can do the line glow, shadow, etc.

Would I be able to do some sort of line drawing algo in the shader or am I fitting a square peg in a round hole.

C

Share this post


Link to post
Share on other sites
Advertisement
ah, I figured this out on my own. I have to sample the previous and next value in the data texture. For ranges where V is between lastV or nextV I must color the pixel the line color.

I have 3 1d texture lookups per pixel...how efficient is that?

Share this post


Link to post
Share on other sites
Apparently, some shaders can have 100 or more texture lookups so I am ok on that one! :)

This is business software, not games, so it may not be running on the fastest video cards so I am trying to keep it light.

C

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!