Logo by AGUS - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Support us via Flattr FLATTR Link
 
*
Welcome, Guest. Please login or register. April 19, 2024, 07:28:29 PM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1]   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: GLSL vertex interpolation question/problem  (Read 4496 times)
0 Members and 2 Guests are viewing this topic.
cKleinhuis
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« on: April 13, 2013, 09:18:20 PM »

hi there, some of you seem to be perfect for helping me out with my current problem:

i want to do a vertex interpolation in the vertex shader

i am using a fixed pipeline attribute for giving the shader a secondary coordinate -> gl_Normal

i am somehow encountering a very strange problem, which i thought has to do with the "w" component, but this does not seem to be the issue, what is the problem ?

the problem is that when i put the same coordinate in
GL.vertex3f(mycoordinate)
GL.normal(mycoordinate)

they are NOT THE SAME ... huh? i am blending linearly between them:

vec3 vertex=mix(gl_Vertex.xyz,gl_Normal.xyz,interpolationvalue);
 
 and after the interpolation i calculate the final position with:

gl_Position = gl_ModelViewProjectionMatrix * vec4(vertex,1);

and, i thought the position should not change the slightest, but it is somehow strange, because the points actually move ... sad

any ideas !?

Logged

---

divide and conquer - iterate and rule - chaos is No random!
Syntopia
Fractal Molossus
**
Posts: 681



syntopiadk
WWW
« Reply #1 on: April 13, 2013, 10:50:00 PM »

the problem is that when i put the same coordinate in
GL.vertex3f(mycoordinate)
GL.normal(mycoordinate)

You are setting normal3f before calling vertex3f, right?
Logged
hobold
Fractal Bachius
*
Posts: 573


« Reply #2 on: April 13, 2013, 11:34:24 PM »

Not sure if this is relevant here, but there is a mathematical difference between transforming

- a location in space

- a normal vector

both seem to be the same kind of 3-component vector, but they have different meanings. The former simply moves as the transformation says. But the latter is really the orientation of a tangent plane, and so the normal vector cannot simply be transformed by the same matrix as a location in space. It must remain perpendicular to the surface.

Therefore another matrix is derived from the original transformation (the transpose of the adjoint? I am not sure offhand), and normal vectors are instead transformed by that derived matrix.


In other words, the mismatch might come from the fact that two identical input vectors are multiplied with different transformation matrices.
Logged
Syntopia
Fractal Molossus
**
Posts: 681



syntopiadk
WWW
« Reply #3 on: April 14, 2013, 09:41:50 AM »

In other words, the mismatch might come from the fact that two identical input vectors are multiplied with different transformation matrices.

OpenGL should not apply any transformations to the input vectors before the vertex shader. Typically, you apply these yourself in the vertex shader, e.g.:
Code:
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
    normal = normalize(gl_NormalMatrix * gl_Normal);

Btw, the gl_NormalMatrix is supplied by OpenGL, so you do not have to compute it yourself. It is the transposed inverse of the upper 3x3 part of the ModelViewProjectionMatrix matrix. Also, for typical projection matrices (uniform scaling + rotation), you don't need to take the transposed inverse, since these matrices are orthogonal. But you need to strip the fourth component translation away.
Logged
cKleinhuis
Administrator
Fractal Senior
*******
Posts: 7044


formerly known as 'Trifox'


WWW
« Reply #4 on: April 14, 2013, 04:00:23 PM »

You are setting normal3f before calling vertex3f, right?

arhh, lol this was the error, thank you for pointing!!!
Logged

---

divide and conquer - iterate and rule - chaos is No random!
Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
Bicubic interpolation Programming aluminumstudios 6 7798 Last post March 21, 2010, 11:47:08 AM
by aluminumstudios
Interpolation button tweak - dare I even ask? feature request kameelian 0 3351 Last post July 29, 2012, 11:12:28 AM
by kameelian
chaostv #4 - interpolation sequence chaosTube - News cKleinhuis 0 3104 Last post November 13, 2012, 05:32:45 AM
by cKleinhuis
new GPU generator called crash developed by vertex 3D Fractal Generation Mrz00m 5 4641 Last post October 24, 2013, 11:40:48 PM
by knighty
sampler2D question/problem Fragmentarium Feline 11 1599 Last post May 05, 2015, 04:43:49 AM
by Feline

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.141 seconds with 24 queries. (Pretty URLs adds 0.009s, 2q)