Login / Register  0 items | $0.00 New What is KVR? Submit News Advertise
User avatar
Architeuthis
KVRAF
 
2647 posts since 27 Jan, 2006, from Phoenix, AZ

Postby Architeuthis; Thu Mar 09, 2017 6:45 pm Looking for an OpenGL programmer (not much experience needed!)

If you have any level of experience with OpenGL, please contact me: "soundemote gmail com" and we can work out payment details.

I'm not trying to do anything complex, just drawing lines and dots. This is what I have so far: https://youtu.be/70WSnwLvcIE

So, right now I'm drawing lines and it looks great. Now I want to draw dots on top of the lines. Because of my lack of experience with openGL I don't know how to expand on what I already have. The code for drawing lines is very simple, so you won't have to go through much code and I can guide you through it. For someone with basic openGL knowledge and experience, I think everything I want to do will be pretty easy.
stratum
KVRian
 
1058 posts since 29 May, 2012

Postby stratum; Fri Mar 10, 2017 12:20 am Re: Looking for an OpenGL programmer (not much experience needed!)

Not that I spend most of my time with opengl/directx, but 'dots' are just circles and circles are connected lines. Give it a try :wink:
~stratum~
User avatar
nonnaci
KVRist
 
122 posts since 7 Feb, 2017

Postby nonnaci; Fri Mar 10, 2017 1:22 am Re: Looking for an OpenGL programmer (not much experience needed!)

Already looks pretty sweet ;). If you want next level fancy, I'd ask for someone with experience with GLSL/shaders.
User avatar
Architeuthis
KVRAF
 
2647 posts since 27 Jan, 2006, from Phoenix, AZ

Postby Architeuthis; Fri Mar 10, 2017 2:01 am Re: Looking for an OpenGL programmer (not much experience needed!)

stratum wrote:Not that I spend most of my time with opengl/directx, but 'dots' are just circles and circles are connected lines. Give it a try :wink:

Would like to focus on what I am good at, I have bills to pay. Spending 24 hours on openGL and only managing to get a colormap working, very bad use of my time.

nonnaci wrote:Already looks pretty sweet ;). If you want next level fancy, I'd ask for someone with experience with GLSL/shaders.

All the drawing is done with shaders already.
PurpleSunray
KVRist
 
454 posts since 13 Mar, 2012

Postby PurpleSunray; Fri Mar 10, 2017 2:10 am Re: Looking for an OpenGL programmer (not much experience needed!)

I won't have time to help you on "commercial basis".. but let's see if we can solve it here ;)

There 2 ways to do it: draw the line as a triangle stip and fill it with the pattern you want to have (via texture mapping or fragment shader). Or use a point-sprite. If you are fine with only running OpenGL v1.5 or later, use point sprites (better performance).

See here for how point sprites work:
http://www.informit.com/articles/articl ... 9&seqNum=7

If you want to draw triangles, first change you code to use GL_TRIANGLE_STRIP instead of LINE_STRIP.
After this works, learn how to draw/fill dots on fragement shader. See here: https://www.desultoryquest.com/blog/dra ... ash-webgl/ (it's WebGL, but shader code should be about the same for native OpenGL).
Last edited by PurpleSunray on Fri Mar 10, 2017 2:14 am, edited 3 times in total.
PurpleSunray
KVRist
 
454 posts since 13 Mar, 2012

Postby PurpleSunray; Fri Mar 10, 2017 2:12 am Re: Looking for an OpenGL programmer (not much experience needed!)

Edit: missed the last post from Architeuthis ;)

If you use shaders already to draw the lines, it should be pretty easy to change it draw dots instead of gradients.
( https://www.desultoryquest.com/blog/dra ... ash-webgl/ ;) )
User avatar
nonnaci
KVRist
 
122 posts since 7 Feb, 2017

Postby nonnaci; Fri Mar 10, 2017 2:19 am Re: Looking for an OpenGL programmer (not much experience needed!)

Architeuthis wrote:All the drawing is done with shaders already.


Ah, makes sense after second look. Just to throw some ideas at this (worked with shaders many years ago), have you thought about adding dynamics such as fire and fluid simulation (I recall source-codes/tutorials online). Could achieve some interesting effects with that.
User avatar
Architeuthis
KVRAF
 
2647 posts since 27 Jan, 2006, from Phoenix, AZ

Postby Architeuthis; Fri Mar 10, 2017 3:17 am Re: Looking for an OpenGL programmer (not much experience needed!)

PurpleSunray wrote:Edit: missed the last post from Architeuthis ;)

If you use shaders already to draw the lines, it should be pretty easy to change it draw dots instead of gradients.
( https://www.desultoryquest.com/blog/dra ... ash-webgl/ ;) )


I know it's going to be easy. I'm working on understanding openGL basics at the moment.
User avatar
Architeuthis
KVRAF
 
2647 posts since 27 Jan, 2006, from Phoenix, AZ

Postby Architeuthis; Fri Mar 10, 2017 3:43 am Re: Looking for an OpenGL programmer (not much experience needed!)

PurpleSunray wrote:I won't have time to help you on "commercial basis".. but let's see if we can solve it here ;)
Really need to figure out how to store pixel (1 channel of color i.e. brightness) values with the fragment shader to then do some per-pixel math to inc/dec those values, then finally display an image while translating brightness to colormap (colormap already implemented and works!).
PurpleSunray
KVRist
 
454 posts since 13 Mar, 2012

Postby PurpleSunray; Fri Mar 10, 2017 4:36 am Re: Looking for an OpenGL programmer (not much experience needed!)

Architeuthis wrote:
PurpleSunray wrote:I won't have time to help you on "commercial basis".. but let's see if we can solve it here ;)
Really need to figure out how to store pixel (1 channel of color i.e. brightness) values with the fragment shader to then do some per-pixel math to inc/dec those values, then finally display an image while translating brightness to colormap (colormap already implemented and works!).

I don't fully get what you want to do - but let me give you bit of background:
When rendering an OpenGL scene, your "scene data" passes two stages of shaders.
First your vertex buffers are processed by the vertex shader. That is the place where to apply any kind of geometry transformation. It receives vertices as input, then you do something and output the processed vertex from the shader. Now the GPU knows how/where to draw traingles and will do so.
Traingles should be filled with some color. The GPU does this by sending all the pixels that fill the triangle, to a fragment shader. The fragment shader input is the possition (x,y) of the pixel that is currently processed.

It is important to understand that those shader codes run in parallel.
Like, a GTX1070 has 1920 shader cores. Means it will process 1920 pixels on one "cycle". It also means that there is no way to reference other pixels out of that shader. You cannot so something like "make this pixel green, if the one to the left is red". No way to know what "the one the left" is, without running a second pass.

What you can do however, is working with textures.
On the texture you store the values you need on the fragement shader (i.e. brightness).

Let's do an example:
You want to fill your triangle with griandiet color from red to green as a backroung and then draw a :ud: image on top.
So you setup a vertex buffer, like
x=-1.0, y=0, z=0
x=0, y=1.0, z=0
x=0, y=0, z=0
You also need to know how to map the texture/color griandiet into the triangle, so it also needs texture mapping coordiantes (U is X, V is Y for textures):
x=-1.0, y=0, z=0, u=0, v=1
x=0, y=1.0, z=0, u=1, v=0
x=0, y=0, z=0, u=1, v=1

Now you render that triangle (let's skip vertex shader stage, because it is not that relevant).
The fragment shader code will now be called for each pixel within the triangle.
Input to the fragment shader is u and v (aka X/Y). Pixel that is on vertex x=-1, y=0 exactly, will have u=0, v=1. Other pixel will have interpolated u and v values.
So from u and v you know what pixel you are about to draw and that is pretty much all you need.
Cacluate the griandiet for the background color, like u=0 is red, u=1 green -> interpolate.
Then you want to add the :ud:
You do it by reading (sampling) the texture that has the :ud: image and blend it over the background color.
Some dummy code example (have not compiled it), to show how that looks like on a fragment shader:
Code: Select all
uniform vec3 color0; // that is your griandiet color 0. Use glUniform function to pass this value to the shader.
uniform vec3 color1; // that is your griandiet color 1. Use glUniform function to pass this value to the shader.
varying vec2 tex_coord;  // that is the U/V texture coordinate
uniform sampler2D tex; // that is the texture with simliey icon
void main()
{
// Calcuate the griandiet color, based on the pixel coorinates U/V
vec4 color = mix(color0, color1, tex_coord.u); // u=0 will be color0 ... u=1 will be color1
// Read pixel from the simley texture and multiply with background color
gl_FragColor = color * texture2D(tex, tex_coord);
}


Don't know if that has answert your question, but as said, I do not really understand what you mean by "how to store pixel (1 channel of color i.e. brightness) values with the fragment shader"
User avatar
Architeuthis
KVRAF
 
2647 posts since 27 Jan, 2006, from Phoenix, AZ

Postby Architeuthis; Fri Mar 10, 2017 5:04 am Re: Looking for an OpenGL programmer (not much experience needed!)

Ok, now how do you modify the smiley texture? I need to read, then write to it before going to gl_FragColor, so some pseudocode would look like this:

Code: Select all
pixel_brightness = GetCurrentPixel(); // I only need one channel of color, grayscale, not all 4 RGBA.
pixel_brightness -= brightness_decay_speed;
SetCurrentPixel(pixel_brightness ); // we have to save the new pixel value to maintain grayscale!

// The final RGB display value comes from a lookup table
gl_FragColor = texture(colormap_texture, brightness);
PurpleSunray
KVRist
 
454 posts since 13 Mar, 2012

Postby PurpleSunray; Fri Mar 10, 2017 5:26 am Re: Looking for an OpenGL programmer (not much experience needed!)

Ok.. I see.
Why do you need the grayscale data? It used from outside the shaders?

If yes, you will need to run 2 passes, where you first render the grayscale texture and on a second pass, you use the grayscale texture to render the final scene.
On first pass, grayscale texture is the framebuffer.
Means you do not render to the backbuffer of the window surface, but to an "offscreen buffer". Output of the fragment shader for this pass is the grayscale value. So you first fill the grayscale texture with data.
After that is done, you run a the second pass, but now the backbuffer of the window surface is the framebuffer. Grayscale texture has the grayscale data and you can sample any pixel from it (you can lookup grayscale values that are right/left/bottom/top of you current pixel).

Second possibility is to solve it by math inside the shader.
I understand it like: fill with a color from texture map and apply brightness, depending on where the pixel is.
Starts with a defined brightness (I start with max_brightness) and then it decays by brightness_decay_speed.
So you cloud do this:
pixel_brightness = max_brightness * tex_coord.u;
pixel_brightness is 0 on the pixels of the first row (u=0). pixel_brightness will be max_brightness on the pixels of the last row (u=1).
brightness_decay_speed is gone, because max_brightness implies it (brightness_decay_speed is max_brightness/height or max_brightness/width .. depending if that decay_speed is on X or Y or both). If you do not want to start on pixel_brightness=0, add an addtional min_brightness to your math ;)
User avatar
Architeuthis
KVRAF
 
2647 posts since 27 Jan, 2006, from Phoenix, AZ

Postby Architeuthis; Fri Mar 10, 2017 9:08 am Re: Looking for an OpenGL programmer (not much experience needed!)

PurpleSunray wrote:Ok.. I see.
Why do you need the grayscale data? It used from outside the shaders?
Because I'm not going to try to convert RGBA back to brightness to update brightness, that is a waste of processing, so I need to maintain a separate brightness buffer to read and write to as needed.

The pixels being accumulated in the brightness texture will be based on the current line drawing stuff.
PurpleSunray
KVRist
 
454 posts since 13 Mar, 2012

Postby PurpleSunray; Fri Mar 10, 2017 9:37 am Re: Looking for an OpenGL programmer (not much experience needed!)

Architeuthis wrote:Because I'm not going to try to convert RGBA back to brightness to update brightness, that is a waste of processing

Not necessary, depends on the GPU and driver.
Like it makes absolutly no difference if you work with RGB or RGBA data. Data-alignment constrains, padding, bus & register sizes & co will cause 4 bytes to be moved arround on most cards, even you don't need the A channel. So you win nothing on using RGB over RGBA. Not sure about how much optimizion there is for 8bit textures.

Architeuthis wrote:so I need to maintain a separate brightness buffer to read and write to as needed.

Reading the brightness buffer from the shader is no problem, but writing is.
A GPU basically is a pipeline - it works quite differnt to a generic purpose CPU.
You send vertices, shaders, uniforms and textures into the pipeline and result is a new texture. There is no "side-channel" where you can create an additional output, or modify one if the inputs buffers.

But what I don't fully get yet, is why you want to update the brightness buffer from the shader.
Is it about that the brightness decay carries over between two frames?
Like, if you run that code:
Code: Select all
pixel_brightness = GetCurrentPixel(); // I only need one channel of color, grayscale, not all 4 RGBA.
pixel_brightness -= brightness_decay_speed;
SetCurrentPixel(pixel_brightness ); // we have to save the new pixel value to maintain grayscale!

10x times, then on first frame, pixel brightness is pixel_brightness - brightness_decay_speed. Then you store that value. Next frame, pixel_brightness is pixel_brightness - 2 x brightness_decay_speed (because you already substracted before), next will by pixel_brightness is pixel_brightness - 3 x brightness_decay_speed ...

Is that what you want? Or why you do you need to modify the brightness from your shader?

Addition:
I think it's best if you briefly describe that you want to do :D
That brightness-thing is not realted to the painting dots, or is it? So what do you want to paint exactly?
User avatar
Architeuthis
KVRAF
 
2647 posts since 27 Jan, 2006, from Phoenix, AZ

Postby Architeuthis; Fri Mar 10, 2017 11:56 am Re: Looking for an OpenGL programmer (not much experience needed!)

Paint dots and lines. That goes into the brightness buffer (add values for said line and dot to the brightness buffer) Then do the brightness decay (de-accumulate ALL pixels). A dot moving across the screen would leave a trail.
Next

Moderator: Moderators (Main)

Return to DSP and Plug-in Development