We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I have written this algorithm with Processing and I'm trying to rewrite it in glsl. I think I'm close to the solution but I'm missing something because I don't get the same result:
code to translate :
PVector camPos = cameraPos.get();
PVector v = PVector.sub(pos, psCenter);
float sn = -camPos.dot(v);
float sd = camPos.mag();
sd *= sd;
camPos.mult(sn / sd);
PVector isec = PVector.add(pos, camPos);
float dist = isec.dist(pos);
Can you find a mistake below ?
vec3 camPos = cameraPosition;
vec3 v = vertex.xyz - psCenter;
//----- calculate sn -----//
float sn = dot(-camPos, v);
//----- calculate sd -----//
float sd = length(camPos);
sd = sd * sd;
//----- calculate isec -----//
camPos *= sn/sd;
vec3 isec = vertex.xyz + camPos;
float dist = distance(isec, vertex.xyz);
float distToFocalPlane = dist;
Answers
a runnable example would help
Hello,
You will find at this adress a runnable example: https://www.dropbox.com/s/2q15pjslwwb23uq/points_v000.zip?dl=0
The image shows what I'm trying to achieve using a shader. You can active the shader by setting
USESHADER
totrue
. As you will see the blur effect is not at the same place.It seems like you didn't take into account that Processing is applying the modelview matrix to each vertex before sending it to the shader. Try to replace lines 79 and 80 with this:
Thank you so much! I think it was the solution I was looking for. I don't get exactly the same visual result (with and without shader) but I think it's because of the way I use offset (and m0ffset) in the vertex shader.
Do you know where I can learn a lot more about PGraphicsOpenGL ?
Well, when I want to learn about a library or class I look at it's source. But there's also the javadoc.
I was speaking more about a book or a collection of examples but I can start with this. Thanks again.
As far as I know there is no book about Processing's PGraphicsOpenGL, especially as it is constantly changing from version to version.
learnopengl.com looks really great. It's extreme well written. If I could only get it to work with Xcode...
Thank you. I will take a look.