In the shader wiki page, in the vertex shader example, in the following line,
[java] gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);[/java]
what’s the significance of 1.0 in vec4(inPosition, 1.0) ?
and why we pass g_WorldViewProjectionMatrix with a uniform scope? we are not using it on fragment shader. If i want i can send it in using attribute scope to just, vextex shader while writing unshaded material. right?
As far as I understand:
inPosition is vec3
g_WorldViewProjectionMatrix is vec4
you cannot multiply vec3 to vec4. You need to multiply vec4 to vec4.
So, 1.0 is a fourth value to make inPosition like vec4.
its the scale of the matrix that transformes the gemoetry, set it to 2.0 and model appears double sized if i remeber correctly
uniformes are everything set code wise
attributes are in the vertexbuffers, so for stuff like the viewtransformation that needs to be set every frame the buffer had to be updated every frame as well if done taht way. this would eat away quite some performance(also what to do if you have multiple instance of the same mesh at different positions?)
Another question is, its written, “Those attributes are deprecated since GLSL 1.3 (opengl 3), hence JME3 global uniforms and attributes. Here is a list of deprecated attributes and their equivalent in JME3”
I really don’t understand. Why even come up with alternatives when they are deprecated? Should we just leave them?
The deprecation of all things OpenGL1/2 basically means “use your own” and thats what we do.
iamcreasy said:
In the shader wiki page, in the vertex shader example, in the following line,
[java] gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);[/java]
what's the significance of 1.0 in vec4(inPosition, 1.0) ?
and why we pass g_WorldViewProjectionMatrix with a uniform scope? we are not using it on fragment shader. If i want i can send it in using attribute scope to just, vextex shader while writing unshaded material. right?
Just wanted to add that g_WorldViewProjectionMatrix is as the name already says a matrix. This matrix is a 4x4 matrix. Because the star-operator here indicates a matrix-vector multiplication you need a vector with 4 components (see http://en.wikipedia.org/wiki/Matrix_(mathematics)).
More about the rasterisation process in rendering can be found here: http://en.wikipedia.org/wiki/Rasterisation
iamcreasy said:
In the shader wiki page, in the vertex shader example, in the following line,
[java] gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);[/java]
what's the significance of 1.0 in vec4(inPosition, 1.0) ?
inPosition is a vec3, you can't multiply a vec3 with a 4x4 matrix (g_WorldViewProjectionMatrix is a 4x4 matrix :p ), so you have to "convert" it to a vec4.
vec4(inPosition, 1.0) is just a vec4 constructor think of it as vec4(vec3,float). The 1.0 here is the w value of the vec4.
this is the equivalent of vec4(inPosition.x,inPosition.y,inPosition.z,1.0);
iamcreasy said:
and why we pass g_WorldViewProjectionMatrix with a uniform scope? we are not using it on fragment shader. If i want i can send it in using attribute scope to just, vextex shader while writing unshaded material. right?
You have to understand that the attribute scope is for variable associated with the current vertex. The g_WorldViewProjectionMatrix is the same for every vertice for the current frame, passing it as an attribute would require to pass it for each vertex. Using a uniform allow us to pass it once per mesh. (or per material? )
So, Vertex shader is called for every vertex is the scene?
iamcreasy said:
So, Vertex shader is called for every vertex is the scene?
Every vertex that is rendered... ie: sent to the GPU by JME... ie: not frustum culled.