You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Vertex attributes are passed in view space instead of model space to the vertex shader #2904
I just set a color if the vertex X position is > 0 or not. So if the vertex is really in world space, not in view, if i move the camera the color would stay at the same position on the box. Here, the color move on the box when i move the camera not the world(so the view matrix ?)
Thanks for your report. What you observe is correct, right now vertex positions are premultiplied by modelview matrix before passing them to vertex shader. We will discuss if there is a way to make it easier for people to get model coordinates.
Right now you can convert them back using inverted modelview matrix like this:
Just for information, the matrix you get by the PGraphicsOpenGL object seams not really right.
For example the cameraInv and the camera matrix are the same of the modelview / modelviewInv, according usual GLSL, the cameraInv and camera may be the same of the view / viewInv matrix.
More strange, when i get the modelview from the PGraphicsOpenGL, and pass this matrix to the shader via Shader.set, this matrix is not the same passed automatically by the processing.
Hi guys, by default the vertices are indeed sent to the vertex shader already multiplied by the modelview matrix (and so the modelview matrix in the vertex shader is set to the identity to avoid applying the transformation twice, so this might be one reason for the discrepancies you have observed).
The reason for this seemingly puzzling approach is to optimize performance when drawing multiple shapes: since it is most efficient to minimize the number of buffer copies between CPU and GPU memory, the renderer batches as many shapes together as possible to draw them in a single call. However, if each shape had a different transformation, then it wouldn't be possible to group them because they would have different uniform matrices.
You can disable the batching with the following hint: hint(DISABLE_OPTIMIZED_STROKE)
@P0ulp regarding the relationship between the modelview and the camera matrices in Processing is the following:
modelview = camera * [all other geometry transformations applied after camera()]
The camera matrix is really not used for anything by the OpenGL renderer (by the exception of the modelXYZ functions), it more of a legacy from the renderers in 1.x
I'm happy to discuss the matrix handling further if you thing it needs to be changed/improved/clarified.
After reading this thread, I really need some help to understand the tutorial on Shaders in the official Processing page. https://processing.org/tutorials/pshader/
If the modelview matrix in vertex shader is the identity, this means that transform * vertex = projection * vertex ?
Even though, in some tutorials with the position in eye coordinates, expressions like "ecPosition = modelview * position" are used, does this equal to "ecPosition = position" ?
I am not sure what the meaning of modelview matrix is in the vertex shader in Processing.
Activity
JakubValtar commentedon Oct 21, 2014
Thanks for your report. What you observe is correct, right now vertex positions are premultiplied by modelview matrix before passing them to vertex shader. We will discuss if there is a way to make it easier for people to get model coordinates.
Right now you can convert them back using inverted modelview matrix like this:
If you need more help, please post on processing forum.
AmnonOwed commentedon Oct 21, 2014
Please also discuss a way for easy world space coordinates. Is this even possible, currently?
P0ulp commentedon Oct 23, 2014
Just for information, the matrix you get by the PGraphicsOpenGL object seams not really right.
For example the cameraInv and the camera matrix are the same of the modelview / modelviewInv, according usual GLSL, the cameraInv and camera may be the same of the view / viewInv matrix.
More strange, when i get the modelview from the PGraphicsOpenGL, and pass this matrix to the shader via Shader.set, this matrix is not the same passed automatically by the processing.
So lot of strange things ...
codeanticode commentedon Nov 3, 2014
Hi guys, by default the vertices are indeed sent to the vertex shader already multiplied by the modelview matrix (and so the modelview matrix in the vertex shader is set to the identity to avoid applying the transformation twice, so this might be one reason for the discrepancies you have observed).
The reason for this seemingly puzzling approach is to optimize performance when drawing multiple shapes: since it is most efficient to minimize the number of buffer copies between CPU and GPU memory, the renderer batches as many shapes together as possible to draw them in a single call. However, if each shape had a different transformation, then it wouldn't be possible to group them because they would have different uniform matrices.
You can disable the batching with the following hint: hint(DISABLE_OPTIMIZED_STROKE)
@P0ulp regarding the relationship between the modelview and the camera matrices in Processing is the following:
modelview = camera * [all other geometry transformations applied after camera()]
The camera matrix is really not used for anything by the OpenGL renderer (by the exception of the modelXYZ functions), it more of a legacy from the renderers in 1.x
I'm happy to discuss the matrix handling further if you thing it needs to be changed/improved/clarified.
codeanticode commentedon Jul 16, 2015
We will add a section in the wiki explaining the workarounds discussed in this thread.
technosalon commentedon Sep 3, 2017
After reading this thread, I really need some help to understand the tutorial on Shaders in the official Processing page. https://processing.org/tutorials/pshader/
If the modelview matrix in vertex shader is the identity, this means that transform * vertex = projection * vertex ?
Even though, in some tutorials with the position in eye coordinates, expressions like "ecPosition = modelview * position" are used, does this equal to "ecPosition = position" ?
I am not sure what the meaning of modelview matrix is in the vertex shader in Processing.
benfry commentedon Sep 4, 2017
Please use the forum for coding questions.