We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, I need some help to understand vertex shader in Processing.
What I want to do is just to change vertices coordinates in vertex shaders, such as in "www.vertexshaderart.com" . In order to do that:
restore the vertices coordinates into the world coordinates like worldPos = modlviewInv * vertex
move vertices as we like
re-restore the vertices coordinates into the eye coordinates like newPos = projection * modelview * worldPos
According to the official explanations (https://github.com/processing/processing/wiki/Advanced-OpenGL), the modelview matrix in the vertex shader in Processing is an "IDENTITY" matrix for some performance issues, which means our vertex shader does not know the original modelview matrix, we need to send the unmodified modelview matrix from the processing side to the vertex shader explicitly.
I thought the code below might work, but I failed, which I do not know why:
Processing side:
PGraphicsOpenGL pg = (PGraphicsOpenGL)g;
shader.set("modelviewOriginal", pg.modelview);//send the modelview matrix to the uniform mat4 variable "modelviewOriginal"
vertex shader side:
vec4 worldPos = modelviewInv * vertex;//restore world coordinates
worldPos = vec4(worldPos.x + 100., worldPos.yzw);//for example, translate x pos
vec4 newPos = projection * modelviewOriginal * worldPos;//re-restore eye coordinates
Probably, I have been missing something basic stuff, I could not have figured them out so far...
So...., please help me !!!!!
Answers
I experimented with processing and matrices few months ago that is what i came up with:
github.com/tolkanabroski/pshader-processing/tree/master/EnvironmentMapping
Sorry i can't help you any futher Good luck
Many thanks, nabr! Your code helps me a lot, and your project is also very inspiring!
I guess your point is in reconstructing the modelview matrix at every frame and sending it at every frame by ourselves, where I just sended the modelview matrix in Processing side... I would try your suggestion this night!
And, the code which you comment in your code (forum.processing.org/two/discussion/11186/edit-stroke-position-and-stroke-color-of-a-pshape-using-shader) seems to deal with exactly the same problem, which would also direct me to the clever way.
After doing several experiments, I would report my results.
Again, thank you very much for your swift and kind instructions !