View Full Version : dot product, matrix mult
V-man
08-04-2006, 05:36 AM
I think I had asked this before but I forgot the answer by now :)
What is the equivalent of
/All are vec4
DP3 temp, variable1, variable2;
It could be
temp = vec4(dot(variable1.xyz, variable2.xyz), dot(variable1.xyz, variable2.xyz), dot(variable1.xyz, variable2.xyz), dot(variable1.xyz, variable2.xyz));
how about
//worldMatrix is a 4x4
//vector is a vec4
mult3x3 temp, worldMatrix, vector;
Roderic (Ingenu)
08-04-2006, 05:47 AM
/All are vec4
DP3 temp, variable1, variable2;
=> vec4 temp = vec4( dot( vec3(var1), vec3(var2) ) );
//worldMatrix is a 4x4
//vector is a vec4
mult3x3 temp, worldMatrix, vector;
=>vec3 temp = mat3( worldMatrix ) * vec3( vector );
(only with latest GLSlang specs, since previously you couldn't build a mat3 from a mat4 AFAIR)
V-man
08-04-2006, 09:21 AM
Thanks, the first one looks good.
For the second, yes I did notice they fix that.
WHat would be the way with the current GLSL 1.10
sqrt[-1]
08-04-2006, 06:04 PM
My take on this:
vec4 temp;
temp.xyz = dot( var1.xyz, var2.xyz );
// Depending on the column ordering of the matrix it is either:
temp.x = dot( worldMatrix[0].xyz, vector.xyz );
temp.y = dot( worldMatrix[1].xyz, vector.xyz );
temp.z = dot( worldMatrix[2].xyz, vector.xyz );
or
temp.xyz = worldMatrix[0].xyz * vector.xyz;
temp.xyz = (worldMatrix[1].xyz * vector.xyz) + temp.xyz;
temp.xyz = (worldMatrix[2].xyz * vector.xyz) + temp.xyz;
mjkrol
08-05-2006, 03:41 AM
@sqrt[-1]: I think you are doing the vec3*mat3, because you dot columns of a matrix, not rows.
Edit: sorry, your second version is okay.
If in GLSL 1.2 you can write:
vec3 temp = mat3( worldMatrix ) * vec3( vector );in GLSL 1.1 it must be this way:
mat3 m3 = mat3( worldMatrix[0].xyz, worldMatrix[1].xyz, worldMatrix[2].xyz );
vec3 temp = m3 * vec3( vector );
V-man
08-05-2006, 09:15 PM
vec4 temp;
temp.xyz = dot(var1.xyz, var2.xyz);That's actually not good because it will complain that you are trying to cast a float to vec3
This will work
temp.xyz = vec3(dot(var1.xyz, var2.xyz));
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.