simple GL3 particles to image color change with distance from original position


    Jul 10 2020 | 7:11 pm
    Hello I am trying to adapt a particle shader so that my particles turn green as they get farther from their original position. I have had luck with the line
    outputColor = inputColor +  (vec4(0.0 1.0 0.0 0.0) * lengthOfTheDistanceFromOriginal);
    The image starts in original position and when i switch to have the particles follow a target everything but the whites turn green as they leave their original position. Although when i bring the particles back to its original position it does not turn back into the original color and I wondering why and how to achieve this.
    Thanks for any help. Hope this is enough info, can add a patch if need be.
    Just in case this is helpful information lengthOfTheDistanceFromOriginal is derived from this code:
    //force from position to original position particles RETURN
    	vec3 dirOrig = vec3(iOrigPos.xy, 0.0) - iPosition;
    	vec3 normDirOrig = normalize(dirOrig);
    	float origDist = length(dirOrig);

    • Jul 12 2020 | 3:48 am
      can you post the code for the vertex shader?
    • Jul 12 2020 | 2:16 pm
      Sure thanks for taking a look. Ive been experimenting more, and so i started trying the mix function, but still does not return to original color with original coordinate.
    • Jul 13 2020 | 3:50 pm
      it's hard to say much without a working patch and all shader files. if you decide to share, please just zip everything up.
      my guess is the original color needs to be stored somewhere (texture or buffer, or maybe texturebuffer?), so that i can be accessed in the shader.
    • Jul 13 2020 | 4:30 pm
      yes sorry, i was hopping it would be a simple math problem and i could get away without having to make a clean presentation. : ) Ok, first off, most of this is adapted from one of Mr. Foderaro's particle patches.
      Question: Maybe I have the wrong understanding of these 'buffers', but think it stores the original color of the image . So when I create a mix function(terminology?) and use the original color, a green vector, and a mix amount, I should be able to fade between the two, correct? Although what occurs is a teeny number (0.0001) causes a slow fade to green and then no use of the mix amount param will fade back to original color.
      Thanks for any help i really appreciate it.
    • Jul 13 2020 | 4:50 pm
      without looking at your patch, I can say probably that's the wrong understanding. It's a feedback process so the input buffer is modified by the output, and you will never retrieve your original input values. you can however store them in a separate buffer. if/when I can take a look I'll let you know.
    • Jul 13 2020 | 4:57 pm
      oh ok, thank you for clearing that up for me.
    • Jul 13 2020 | 7:51 pm
      I was also going to add that looking at the vertex shader I think with transform feedback the original position of the vertices may not be saved so using the distance from the original position may not work. Rob has some very clear examples in the GL3-Launch extras. The first 3 under Transform Feedback might be good to look at for clear examples of how feedback works.