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.
This commit is contained in:
parent
b2188d631a
commit
817cf2a317
|
@ -224,12 +224,15 @@ data_to_c_simple(modes/shaders/common_globals_lib.glsl SRC)
|
|||
data_to_c_simple(modes/shaders/common_view_lib.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/common_fxaa_lib.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/common_fullscreen_vert.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/armature_sphere_vert.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/armature_sphere_frag.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/armature_sphere_solid_vert.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/armature_sphere_solid_frag.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/armature_sphere_outline_vert.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/armature_envelope_vert.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/armature_envelope_frag.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/armature_envelope_solid_vert.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/armature_envelope_solid_frag.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/armature_envelope_outline_vert.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/armature_envelope_distance_frag.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/armature_shape_solid_vert.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/armature_shape_solid_frag.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/armature_shape_outline_vert.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/armature_shape_outline_geom.glsl SRC)
|
||||
data_to_c_simple(modes/shaders/edit_mesh_overlay_frag.glsl SRC)
|
||||
|
|
|
@ -260,7 +260,7 @@ static void drw_shgroup_bone_envelope_solid(
|
|||
DRW_shgroup_state_enable(g_data.bone_envelope_solid, DRW_STATE_CULL_BACK);
|
||||
}
|
||||
if (g_data.bone_point_solid == NULL) {
|
||||
g_data.bone_point_solid = shgroup_instance_bone_sphere(g_data.pass_bone_solid);
|
||||
g_data.bone_point_solid = shgroup_instance_bone_sphere_solid(g_data.pass_bone_solid);
|
||||
}
|
||||
|
||||
drw_shgroup_bone_envelope(g_data.bone_point_solid,
|
||||
|
@ -350,7 +350,7 @@ static void drw_shgroup_bone_custom_wire(const float (*bone_mat)[4], const float
|
|||
static void drw_shgroup_bone_point_solid(const float (*bone_mat)[4], const float color[4])
|
||||
{
|
||||
if (g_data.bone_point_solid == NULL) {
|
||||
g_data.bone_point_solid = shgroup_instance_bone_sphere(g_data.pass_bone_solid);
|
||||
g_data.bone_point_solid = shgroup_instance_bone_sphere_solid(g_data.pass_bone_solid);
|
||||
}
|
||||
float final_bonemat[4][4];
|
||||
mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat);
|
||||
|
|
|
@ -153,12 +153,15 @@ void DRW_globals_update(void)
|
|||
|
||||
/* ********************************* SHGROUP ************************************* */
|
||||
|
||||
extern char datatoc_armature_sphere_vert_glsl[];
|
||||
extern char datatoc_armature_sphere_frag_glsl[];
|
||||
extern char datatoc_armature_sphere_solid_vert_glsl[];
|
||||
extern char datatoc_armature_sphere_solid_frag_glsl[];
|
||||
extern char datatoc_armature_sphere_outline_vert_glsl[];
|
||||
extern char datatoc_armature_envelope_vert_glsl[];
|
||||
extern char datatoc_armature_envelope_frag_glsl[];
|
||||
extern char datatoc_armature_envelope_solid_vert_glsl[];
|
||||
extern char datatoc_armature_envelope_solid_frag_glsl[];
|
||||
extern char datatoc_armature_envelope_outline_vert_glsl[];
|
||||
extern char datatoc_armature_envelope_distance_frag_glsl[];
|
||||
extern char datatoc_armature_shape_solid_vert_glsl[];
|
||||
extern char datatoc_armature_shape_solid_frag_glsl[];
|
||||
extern char datatoc_armature_shape_outline_vert_glsl[];
|
||||
extern char datatoc_armature_shape_outline_geom_glsl[];
|
||||
extern char datatoc_gpu_shader_flat_color_frag_glsl[];
|
||||
|
@ -167,6 +170,7 @@ extern char datatoc_object_mball_handles_vert_glsl[];
|
|||
|
||||
static struct {
|
||||
struct GPUShader *shape_outline;
|
||||
struct GPUShader *shape_solid;
|
||||
struct GPUShader *bone_envelope;
|
||||
struct GPUShader *bone_envelope_distance;
|
||||
struct GPUShader *bone_envelope_outline;
|
||||
|
@ -187,8 +191,10 @@ static struct {
|
|||
struct Gwn_VertFormat *instance_camera;
|
||||
struct Gwn_VertFormat *instance_distance_lines;
|
||||
struct Gwn_VertFormat *instance_spot;
|
||||
struct Gwn_VertFormat *instance_bone;
|
||||
struct Gwn_VertFormat *instance_bone_outline;
|
||||
struct Gwn_VertFormat *instance_bone_envelope;
|
||||
struct Gwn_VertFormat *instance_bone_envelope_distance;
|
||||
struct Gwn_VertFormat *instance_bone_envelope_outline;
|
||||
struct Gwn_VertFormat *instance_mball_handles;
|
||||
} g_formats = {NULL};
|
||||
|
@ -456,20 +462,19 @@ DRWShadingGroup *shgroup_instance_bone_envelope_distance(DRWPass *pass)
|
|||
{
|
||||
if (g_shaders.bone_envelope_distance == NULL) {
|
||||
g_shaders.bone_envelope_distance = DRW_shader_create(
|
||||
datatoc_armature_envelope_vert_glsl, NULL,
|
||||
datatoc_armature_envelope_frag_glsl, NULL);
|
||||
datatoc_armature_envelope_solid_vert_glsl, NULL,
|
||||
datatoc_armature_envelope_distance_frag_glsl, NULL);
|
||||
}
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_bone_envelope, {
|
||||
DRW_shgroup_instance_format(g_formats.instance_bone_envelope_distance, {
|
||||
{"headSphere" , DRW_ATTRIB_FLOAT, 4},
|
||||
{"tailSphere" , DRW_ATTRIB_FLOAT, 4},
|
||||
{"color" , DRW_ATTRIB_FLOAT, 4},
|
||||
{"xAxis" , DRW_ATTRIB_FLOAT, 3}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(g_shaders.bone_envelope_distance,
|
||||
pass, DRW_cache_bone_envelope_solid_get(),
|
||||
g_formats.instance_bone_envelope);
|
||||
g_formats.instance_bone_envelope_distance);
|
||||
|
||||
return grp;
|
||||
}
|
||||
|
@ -478,14 +483,15 @@ DRWShadingGroup *shgroup_instance_bone_envelope_solid(DRWPass *pass)
|
|||
{
|
||||
if (g_shaders.bone_envelope == NULL) {
|
||||
g_shaders.bone_envelope = DRW_shader_create(
|
||||
datatoc_armature_envelope_vert_glsl, NULL,
|
||||
datatoc_armature_envelope_frag_glsl, "#define SMOOTH_ENVELOPE\n");
|
||||
datatoc_armature_envelope_solid_vert_glsl, NULL,
|
||||
datatoc_armature_envelope_solid_frag_glsl, "#define SMOOTH_ENVELOPE\n");
|
||||
}
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_bone_envelope, {
|
||||
{"headSphere" , DRW_ATTRIB_FLOAT, 4},
|
||||
{"tailSphere" , DRW_ATTRIB_FLOAT, 4},
|
||||
{"color" , DRW_ATTRIB_FLOAT, 4},
|
||||
{"boneColor" , DRW_ATTRIB_FLOAT, 3},
|
||||
{"stateColor" , DRW_ATTRIB_FLOAT, 3},
|
||||
{"xAxis" , DRW_ATTRIB_FLOAT, 3}
|
||||
});
|
||||
|
||||
|
@ -541,22 +547,43 @@ DRWShadingGroup *shgroup_instance_bone_shape_outline(DRWPass *pass, struct Gwn_B
|
|||
return grp;
|
||||
}
|
||||
|
||||
DRWShadingGroup *shgroup_instance_bone_sphere(DRWPass *pass)
|
||||
DRWShadingGroup *shgroup_instance_bone_shape_solid(DRWPass *pass, struct Gwn_Batch *geom)
|
||||
{
|
||||
if (g_shaders.shape_solid == NULL) {
|
||||
g_shaders.shape_solid = DRW_shader_create(
|
||||
datatoc_armature_shape_solid_vert_glsl, NULL,
|
||||
datatoc_armature_shape_solid_frag_glsl, NULL);
|
||||
}
|
||||
|
||||
DRW_shgroup_instance_format(g_formats.instance_bone, {
|
||||
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16},
|
||||
{"boneColor" , DRW_ATTRIB_FLOAT, 3},
|
||||
{"stateColor" , DRW_ATTRIB_FLOAT, 3}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(g_shaders.shape_solid,
|
||||
pass, geom, g_formats.instance_bone);
|
||||
DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
|
||||
|
||||
return grp;
|
||||
}
|
||||
|
||||
DRWShadingGroup *shgroup_instance_bone_sphere_solid(DRWPass *pass)
|
||||
{
|
||||
if (g_shaders.bone_sphere == NULL) {
|
||||
g_shaders.bone_sphere = DRW_shader_create(
|
||||
datatoc_armature_sphere_vert_glsl, NULL,
|
||||
datatoc_armature_sphere_frag_glsl, NULL);
|
||||
datatoc_armature_sphere_solid_vert_glsl, NULL,
|
||||
datatoc_armature_sphere_solid_frag_glsl, NULL);
|
||||
}
|
||||
|
||||
/* TODO own format? */
|
||||
DRW_shgroup_instance_format(g_formats.instance_color, {
|
||||
DRW_shgroup_instance_format(g_formats.instance_bone, {
|
||||
{"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16},
|
||||
{"color" , DRW_ATTRIB_FLOAT, 4}
|
||||
{"boneColor" , DRW_ATTRIB_FLOAT, 3},
|
||||
{"stateColor" , DRW_ATTRIB_FLOAT, 3}
|
||||
});
|
||||
|
||||
DRWShadingGroup *grp = DRW_shgroup_instance_create(g_shaders.bone_sphere,
|
||||
pass, DRW_cache_bone_point_get(), g_formats.instance_color);
|
||||
pass, DRW_cache_bone_point_get(), g_formats.instance_bone);
|
||||
|
||||
return grp;
|
||||
}
|
||||
|
|
|
@ -115,13 +115,14 @@ struct DRWShadingGroup *shgroup_instance_outline(struct DRWPass *pass, struct Gw
|
|||
struct DRWShadingGroup *shgroup_camera_instance(struct DRWPass *pass, struct Gwn_Batch *geom);
|
||||
struct DRWShadingGroup *shgroup_distance_lines_instance(struct DRWPass *pass, struct Gwn_Batch *geom);
|
||||
struct DRWShadingGroup *shgroup_spot_instance(struct DRWPass *pass, struct Gwn_Batch *geom);
|
||||
struct DRWShadingGroup *shgroup_instance_mball_handles(struct DRWPass *pass);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_envelope_distance(struct DRWPass *pass);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_envelope_outline(struct DRWPass *pass);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_envelope_solid(struct DRWPass *pass);
|
||||
struct DRWShadingGroup *shgroup_instance_mball_handles(struct DRWPass *pass);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_shape_outline(struct DRWPass *pass, struct Gwn_Batch *geom);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_sphere(struct DRWPass *pass);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_shape_solid(struct DRWPass *pass, struct Gwn_Batch *geom);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_sphere_outline(struct DRWPass *pass);
|
||||
struct DRWShadingGroup *shgroup_instance_bone_sphere_solid(struct DRWPass *pass);
|
||||
|
||||
int DRW_object_wire_theme_get(
|
||||
struct Object *ob, struct ViewLayer *view_layer, float **r_color);
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
flat in vec3 finalStateColor; /* UNUSED */
|
||||
flat in vec3 finalBoneColor; /* UNUSED */
|
||||
in vec3 normalView;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
uniform vec4 color = vec4(1.0, 1.0, 1.0, 0.2);
|
||||
|
||||
void main()
|
||||
{
|
||||
float n = normalize(normalView).z;
|
||||
n = 1.0 - clamp(-n, 0.0, 1.0);
|
||||
fragColor = color * n;
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
|
||||
flat in vec4 finalColor;
|
||||
in vec3 normalView;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
float n = normalize(normalView).z;
|
||||
n = gl_FrontFacing ? n : -n;
|
||||
n = clamp(n, 0.0, 1.0);
|
||||
n = gl_FrontFacing ? n : 1.0 - n;
|
||||
fragColor = finalColor;
|
||||
fragColor.rgb *= n;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
flat in vec3 finalStateColor;
|
||||
flat in vec3 finalBoneColor;
|
||||
in vec3 normalView;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
/* Smooth lighting factor. */
|
||||
const float s = 0.2; /* [0.0-0.5] range */
|
||||
float n = normalize(normalView).z;
|
||||
float fac = clamp((n * (1.0 - s)) + s, 0.0, 1.0);
|
||||
fragColor.rgb = mix(finalStateColor, finalBoneColor, fac);
|
||||
fragColor.a = 1.0;
|
||||
}
|
|
@ -10,10 +10,12 @@ in vec3 pos;
|
|||
/* Assumed to be in world coordinate already. */
|
||||
in vec4 headSphere;
|
||||
in vec4 tailSphere;
|
||||
in vec4 color;
|
||||
in vec3 xAxis;
|
||||
in vec3 stateColor;
|
||||
in vec3 boneColor;
|
||||
|
||||
flat out vec4 finalColor;
|
||||
flat out vec3 finalStateColor;
|
||||
flat out vec3 finalBoneColor;
|
||||
out vec3 normalView;
|
||||
|
||||
void main()
|
||||
|
@ -48,5 +50,6 @@ void main()
|
|||
|
||||
gl_Position = ViewProjectionMatrix * vec4(sp, 1.0);
|
||||
|
||||
finalColor = color;
|
||||
finalStateColor = stateColor;
|
||||
finalBoneColor = boneColor;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
flat in vec4 finalColor;
|
||||
|
||||
out vec4 fragColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
fragColor = finalColor;
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
|
||||
uniform mat3 NormalMatrix;
|
||||
uniform mat4 ViewMatrixInverse;
|
||||
uniform mat4 ViewProjectionMatrix;
|
||||
|
||||
uniform mat4 ViewMatrix;
|
||||
uniform mat4 ProjectionMatrix;
|
||||
uniform vec2 viewportSize;
|
||||
|
||||
/* ---- Instanciated Attribs ---- */
|
||||
in vec3 pos;
|
||||
in vec3 nor;
|
||||
|
||||
/* ---- Per instance Attribs ---- */
|
||||
in mat4 InstanceModelMatrix;
|
||||
in vec3 boneColor;
|
||||
in vec3 stateColor;
|
||||
|
||||
flat out vec4 finalColor;
|
||||
|
||||
void main()
|
||||
{
|
||||
mat3 NormalMatrix = transpose(inverse(mat3(ViewMatrix * InstanceModelMatrix)));
|
||||
vec3 normal = normalize(NormalMatrix * nor);
|
||||
|
||||
/* Do lighting at an angle to avoid flat shading on front facing bone. */
|
||||
const vec3 light = vec3(0.1, 0.1, 0.8);
|
||||
float n = dot(normal, light);
|
||||
|
||||
/* Smooth lighting factor. */
|
||||
const float s = 0.2; /* [0.0-0.5] range */
|
||||
float fac = clamp((n * (1.0 - s)) + s, 0.0, 1.0);
|
||||
finalColor.rgb = mix(stateColor, boneColor, fac);
|
||||
finalColor.a = 1.0;
|
||||
|
||||
gl_Position = ViewProjectionMatrix * (InstanceModelMatrix * vec4(pos, 1.0));
|
||||
}
|
|
@ -4,7 +4,8 @@
|
|||
uniform mat4 ViewMatrixInverse;
|
||||
uniform mat4 ProjectionMatrix;
|
||||
|
||||
flat in vec3 solidColor;
|
||||
flat in vec3 finalStateColor;
|
||||
flat in vec3 finalBoneColor;
|
||||
flat in mat4 sphereMatrix;
|
||||
in vec3 viewPosition;
|
||||
|
||||
|
@ -61,13 +62,18 @@ void main()
|
|||
vec3 p = ray_dir * t + ray_ori; /* Point on sphere */
|
||||
vec3 n = normalize(p); /* Normal is just the point in sphere space, normalized. */
|
||||
vec3 l = normalize(sphereMatrix[2].xyz); /* Just the view Z axis in the sphere space. */
|
||||
float col = clamp(dot(n, l), 0.0, 1.0);
|
||||
|
||||
|
||||
/* Smooth lighting factor. */
|
||||
const float s = 0.2; /* [0.0-0.5] range */
|
||||
float fac = clamp((dot(n, l) * (1.0 - s)) + s, 0.0, 1.0);
|
||||
fragColor.rgb = mix(finalStateColor, finalBoneColor, fac);
|
||||
|
||||
/* 2x2 dither pattern to smooth the lighting. */
|
||||
float dither = (0.5 + dot(vec2(ivec2(gl_FragCoord.xy) & ivec2(1)), vec2(1.0, 2.0))) * 0.25;
|
||||
dither *= (1.0 / 255.0); /* Assume 8bit per color buffer. */
|
||||
|
||||
fragColor = vec4(col * solidColor + dither, 1.0);
|
||||
fragColor = vec4(fragColor.rgb + dither, 1.0);
|
||||
|
||||
t /= ray_len;
|
||||
gl_FragDepth = get_depth_from_view_z(ray_dir_view.z * t + ray_ori_view.z);
|
|
@ -7,9 +7,11 @@ in vec2 pos;
|
|||
|
||||
/* ---- Per instance Attribs ---- */
|
||||
in mat4 InstanceModelMatrix;
|
||||
in vec3 color;
|
||||
in vec3 stateColor;
|
||||
in vec3 boneColor;
|
||||
|
||||
flat out vec3 solidColor;
|
||||
flat out vec3 finalStateColor;
|
||||
flat out vec3 finalBoneColor;
|
||||
flat out mat4 sphereMatrix;
|
||||
out vec3 viewPosition;
|
||||
|
||||
|
@ -75,5 +77,6 @@ void main()
|
|||
gl_Position = ProjectionMatrix * V;
|
||||
viewPosition = V.xyz;
|
||||
|
||||
solidColor = color;
|
||||
finalStateColor = stateColor;
|
||||
finalBoneColor = boneColor;
|
||||
}
|
Loading…
Reference in New Issue