Rotation Matrix about point

Started by
11 comments, last by SingularOne 12 years, 8 months ago
IMHO the shown adopted code snippet is missing a normalization of both n2 and t2 (assuming that "using V,N,T as regular" doesn't include it). The code snippet probably only works well if Bones.z == 1 and Bones.y < 0. In all other cases the lengths of n2 and t2 may be anything but are later expected to be 1.
Advertisement
yes, i've noticed before, it works ok if bone1 weight = 1.0 and bone2 is ineffective, but i do normalize resulting normal and tangent




vec3 T = normalize(gl_NormalMatrix * normalize(t2));
vec3 N = normalize(gl_NormalMatrix * normalize(n2));
vec3 B = cross(N, T);



and even if i remove normal rotation, problem doesn't go away.
also i modified code so second bone weight = 1.0 - FirstBoneWeight (because outside shader my program actually calculates weights for all affecting bones, but in examples i use to test it's always <= 2 bones affecting vertex);

and to avoid wasting your time with snippets:
full code of stuff that actually affects that problem,
[spoiler]
#version 110
attribute vec4 Bones;
attribute vec3 Tangent;
uniform mat4 BonesMat[30];
varying vec3 ld;
varying vec3 eye;
varying vec4 V;

void main()
{
V = gl_Vertex;
vec3 n2 = gl_Normal;
vec3 t2 = Tangent;
if(Bones.x >= 0.0)
{
mat4 tmat = BonesMat[int(Bones.x)];
mat3 nmat = mat3(tmat[0].xyz, tmat[1].xyz, tmat[2].xyz);

V = tmat * gl_Vertex * Bones.z;
n2 = nmat * gl_Normal * Bones.z;
t2 = nmat * Tangent * Bones.z;

if(Bones.y >= 0.0)
{
tmat = BonesMat[int(Bones.y)];
nmat = mat3(tmat[0].xyz, tmat[1].xyz, tmat[2].xyz);

V += tmat * gl_Vertex * (1.0-Bones.z);
n2 += nmat * gl_Normal * (1.0-Bones.z);
t2 += nmat * Tangent * (1.0-Bones.z);
}
}

gl_TexCoord[0] = gl_MultiTexCoord0;
V = gl_ModelViewMatrix * V;

vec3 T = -normalize(gl_NormalMatrix * normalize(t2));
vec3 N = normalize(gl_NormalMatrix * normalize(n2));
vec3 B = cross(N, T);

vec3 lv = (gl_LightSource[0].position - V).xyz;
ld.x = dot(lv, B);
ld.y = dot(lv, T);
ld.z = dot(lv, N);

vec3 vt = -V.xyz;
eye.x = dot(vt, B);
eye.y = dot(vt, T);
eye.z = dot(vt, N);
gl_Position = gl_ProjectionMatrix * V;
}


[/spoiler]
The problem was i'm using 3-component vectors for all my lighting calculation, so vertex w-component was modified by rotation matrix correctly, but wasn't affecting lighting. so i should do it manually.

This topic is closed to new replies.

Advertisement