diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-05-05 21:51:16 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-05-05 22:04:21 +0300 |
commit | 817cf2a317388b8bfc29ddf27a49b0628eb8e1ab (patch) | |
tree | ba91e9fbe5ed957d05634de1f0df514d2b4d91ad /source/blender/draw/modes/shaders/armature_envelope_solid_vert.glsl | |
parent | b2188d631a81972f38548a333757eb21ddd784b0 (diff) |
Armature: Rename bone shaders and add 2 colors smooth blending.
This will enable us to do more nice stuff in future commits.
This commit is a temporary commit, it will compile but will crash if
trying to display any armature. Next commit does work.
Diffstat (limited to 'source/blender/draw/modes/shaders/armature_envelope_solid_vert.glsl')
-rw-r--r-- | source/blender/draw/modes/shaders/armature_envelope_solid_vert.glsl | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/source/blender/draw/modes/shaders/armature_envelope_solid_vert.glsl b/source/blender/draw/modes/shaders/armature_envelope_solid_vert.glsl new file mode 100644 index 00000000000..83ae720e70a --- /dev/null +++ b/source/blender/draw/modes/shaders/armature_envelope_solid_vert.glsl @@ -0,0 +1,55 @@ + +uniform mat4 ViewMatrix; +uniform mat4 ViewMatrixInverse; +uniform mat4 ViewProjectionMatrix; + +/* ---- Instanciated Attribs ---- */ +in vec3 pos; + +/* ---- Per instance Attribs ---- */ +/* Assumed to be in world coordinate already. */ +in vec4 headSphere; +in vec4 tailSphere; +in vec3 xAxis; +in vec3 stateColor; +in vec3 boneColor; + +flat out vec3 finalStateColor; +flat out vec3 finalBoneColor; +out vec3 normalView; + +void main() +{ + vec3 bone_vec = tailSphere.xyz - headSphere.xyz; + float bone_len = max(1e-8, sqrt(dot(bone_vec, bone_vec))); + float bone_lenrcp = 1.0 / bone_len; +#ifdef SMOOTH_ENVELOPE + float sinb = (tailSphere.w - headSphere.w) * bone_lenrcp; +#else + const float sinb = 0.0; +#endif + + vec3 y_axis = bone_vec * bone_lenrcp; + vec3 z_axis = normalize(cross(xAxis, -y_axis)); + vec3 x_axis = cross(y_axis, z_axis); /* cannot trust xAxis to be orthogonal. */ + + vec3 sp, nor; + nor = sp = pos.xyz; + + /* In bone space */ + bool is_head = (pos.z < -sinb); + sp *= (is_head) ? headSphere.w : tailSphere.w; + sp.z += (is_head) ? 0.0 : bone_len; + + /* Convert to world space */ + mat3 bone_mat = mat3(x_axis, y_axis, z_axis); + sp = bone_mat * sp.xzy + headSphere.xyz; + nor = bone_mat * nor.xzy; + + normalView = mat3(ViewMatrix) * nor; + + gl_Position = ViewProjectionMatrix * vec4(sp, 1.0); + + finalStateColor = stateColor; + finalBoneColor = boneColor; +} |