Add skinning
This commit is contained in:
@@ -14,33 +14,9 @@ uniform mat4 u_viewMatrix;
|
||||
uniform mat4 u_projectionMatrix;
|
||||
uniform mat4 u_modelViewProjection;
|
||||
|
||||
vec3 CalcOmniLight()
|
||||
{
|
||||
vec3 lightPos = vec3(0.1, 2.1, 0.1);
|
||||
float d = distance(lightPos, v_position);
|
||||
vec3 L = normalize(lightPos-v_position);
|
||||
vec3 N = normalize(v_normal);
|
||||
vec3 col = vec3( max(0, dot(N, L) / d) );
|
||||
col = col * 0.8 + 0.2;
|
||||
return col;
|
||||
}
|
||||
|
||||
vec3 CalcDirLight()
|
||||
{
|
||||
vec3 lightPos = vec3(5.0, 10.0, 1.0);
|
||||
//lightPos = -lightPos;
|
||||
|
||||
vec3 L = normalize(lightPos);
|
||||
vec3 N = normalize(v_normal);
|
||||
vec3 col = vec3( max(0, dot(N, L)) );
|
||||
col = col * 0.8 + 0.2;
|
||||
return col;
|
||||
}
|
||||
|
||||
void main() {
|
||||
v_position = vec3( u_modelMatrix * vec4(a_position, 1.0) );
|
||||
v_normal = vec3( mat3(u_modelMatrix) * a_normal );
|
||||
v_texcoord = a_texcoord;
|
||||
v_finalColor = CalcDirLight();
|
||||
gl_Position = u_modelViewProjection * vec4(a_position, 1);
|
||||
}
|
||||
34
data/shaders/unlit_generic_skin.vs
Normal file
34
data/shaders/unlit_generic_skin.vs
Normal file
@@ -0,0 +1,34 @@
|
||||
#version 120
|
||||
|
||||
attribute vec3 a_position;
|
||||
attribute vec3 a_normal;
|
||||
attribute vec2 a_texcoord;
|
||||
attribute vec4 a_boneIds;
|
||||
attribute vec4 a_weights;
|
||||
|
||||
varying vec3 v_position;
|
||||
varying vec3 v_normal;
|
||||
varying vec2 v_texcoord;
|
||||
varying vec3 v_finalColor;
|
||||
|
||||
uniform mat4 u_modelMatrix;
|
||||
uniform mat4 u_viewMatrix;
|
||||
uniform mat4 u_projectionMatrix;
|
||||
uniform mat4 u_modelViewProjection;
|
||||
uniform mat4 u_boneMatrices[128];
|
||||
|
||||
void main() {
|
||||
// calculate bone transform
|
||||
mat4 skinMatrix = a_weights.x * u_boneMatrices[ int( a_boneIds.x ) ]
|
||||
+ a_weights.y * u_boneMatrices[ int( a_boneIds.y ) ]
|
||||
+ a_weights.z * u_boneMatrices[ int( a_boneIds.z ) ]
|
||||
+ a_weights.w * u_boneMatrices[ int( a_boneIds.w ) ];
|
||||
|
||||
// Position
|
||||
v_position = vec3( skinMatrix * vec4( a_position, 1.0 ) );
|
||||
v_position = vec3( u_modelMatrix * vec4( v_position, 1.0 ) );
|
||||
|
||||
v_normal = vec3( mat3(u_modelMatrix) * a_normal );
|
||||
v_texcoord = a_texcoord;
|
||||
gl_Position = u_projectionMatrix * u_viewMatrix * vec4( v_position, 1.0 );
|
||||
}
|
||||
Reference in New Issue
Block a user