summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRay <[email protected]>2021-04-19 19:41:41 +0200
committerRay <[email protected]>2021-04-19 19:41:41 +0200
commit63a1bf373c588d2c7c43e2aff37c4e5e54fdb7eb (patch)
treed54a85e1bf3f2af70e8fc2a23d4fe33e0c313250
parent899afcbdcaa25ff856e698eaecaa9c4ec395159e (diff)
parent7f1068ef96685b174883b2bd1c9781fe7c1ad0d4 (diff)
downloadraylib-63a1bf373c588d2c7c43e2aff37c4e5e54fdb7eb.tar.gz
raylib-63a1bf373c588d2c7c43e2aff37c4e5e54fdb7eb.zip
Merge branch 'master' of https://github.com/raysan5/raylib
-rw-r--r--examples/text/resources/shaders/glsl330/sdf.fs6
-rw-r--r--src/models.c70
2 files changed, 44 insertions, 32 deletions
diff --git a/examples/text/resources/shaders/glsl330/sdf.fs b/examples/text/resources/shaders/glsl330/sdf.fs
index 44d33e9b..45e1cabe 100644
--- a/examples/text/resources/shaders/glsl330/sdf.fs
+++ b/examples/text/resources/shaders/glsl330/sdf.fs
@@ -12,14 +12,14 @@ uniform vec4 colDiffuse;
out vec4 finalColor;
// NOTE: Add here your custom variables
-const float smoothing = 1.0/16.0;
void main()
{
// Texel color fetching from texture sampler
// NOTE: Calculate alpha using signed distance field (SDF)
- float distance = texture(texture0, fragTexCoord).a;
- float alpha = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance);
+ float distanceFromOutline = texture(texture0, fragTexCoord).a - 0.5;
+ float distanceChangePerFragment = length(vec2(dFdx(distanceFromOutline), dFdy(distanceFromOutline)));
+ float alpha = smoothstep(-distanceChangePerFragment, distanceChangePerFragment, distanceFromOutline);
// Calculate final fragment color
finalColor = vec4(fragColor.rgb, fragColor.a*alpha);
diff --git a/src/models.c b/src/models.c
index 81f27f38..3dc6c3d5 100644
--- a/src/models.c
+++ b/src/models.c
@@ -1425,41 +1425,53 @@ void UpdateModelAnimation(Model model, ModelAnimation anim, int frame)
int vCounter = 0;
int boneCounter = 0;
int boneId = 0;
+ float boneWeight = 0.0;
for (int i = 0; i < model.meshes[m].vertexCount; i++)
{
- boneId = model.meshes[m].boneIds[boneCounter];
- inTranslation = model.bindPose[boneId].translation;
- inRotation = model.bindPose[boneId].rotation;
- //inScale = model.bindPose[boneId].scale;
- outTranslation = anim.framePoses[frame][boneId].translation;
- outRotation = anim.framePoses[frame][boneId].rotation;
- outScale = anim.framePoses[frame][boneId].scale;
-
- // Vertices processing
- // NOTE: We use meshes.vertices (default vertex position) to calculate meshes.animVertices (animated vertex position)
- animVertex = (Vector3){ model.meshes[m].vertices[vCounter], model.meshes[m].vertices[vCounter + 1], model.meshes[m].vertices[vCounter + 2] };
- animVertex = Vector3Multiply(animVertex, outScale);
- animVertex = Vector3Subtract(animVertex, inTranslation);
- animVertex = Vector3RotateByQuaternion(animVertex, QuaternionMultiply(outRotation, QuaternionInvert(inRotation)));
- animVertex = Vector3Add(animVertex, outTranslation);
- model.meshes[m].animVertices[vCounter] = animVertex.x;
- model.meshes[m].animVertices[vCounter + 1] = animVertex.y;
- model.meshes[m].animVertices[vCounter + 2] = animVertex.z;
-
- // Normals processing
- // NOTE: We use meshes.baseNormals (default normal) to calculate meshes.normals (animated normals)
- if (model.meshes[m].normals != NULL)
+ model.meshes[m].animVertices[vCounter] = 0;
+ model.meshes[m].animVertices[vCounter + 1] = 0;
+ model.meshes[m].animVertices[vCounter + 2] = 0;
+
+ model.meshes[m].animNormals[vCounter] = 0;
+ model.meshes[m].animNormals[vCounter + 1] = 0;
+ model.meshes[m].animNormals[vCounter + 2] = 0;
+
+ for (int j = 0; j < 4; j++)
{
- animNormal = (Vector3){ model.meshes[m].normals[vCounter], model.meshes[m].normals[vCounter + 1], model.meshes[m].normals[vCounter + 2] };
- animNormal = Vector3RotateByQuaternion(animNormal, QuaternionMultiply(outRotation, QuaternionInvert(inRotation)));
- model.meshes[m].animNormals[vCounter] = animNormal.x;
- model.meshes[m].animNormals[vCounter + 1] = animNormal.y;
- model.meshes[m].animNormals[vCounter + 2] = animNormal.z;
- }
+ boneId = model.meshes[m].boneIds[boneCounter];
+ boneWeight = model.meshes[m].boneWeights[boneCounter];
+ inTranslation = model.bindPose[boneId].translation;
+ inRotation = model.bindPose[boneId].rotation;
+ //inScale = model.bindPose[boneId].scale;
+ outTranslation = anim.framePoses[frame][boneId].translation;
+ outRotation = anim.framePoses[frame][boneId].rotation;
+ outScale = anim.framePoses[frame][boneId].scale;
+
+ // Vertices processing
+ // NOTE: We use meshes.vertices (default vertex position) to calculate meshes.animVertices (animated vertex position)
+ animVertex = (Vector3){ model.meshes[m].vertices[vCounter], model.meshes[m].vertices[vCounter + 1], model.meshes[m].vertices[vCounter + 2] };
+ animVertex = Vector3Multiply(animVertex, outScale);
+ animVertex = Vector3Subtract(animVertex, inTranslation);
+ animVertex = Vector3RotateByQuaternion(animVertex, QuaternionMultiply(outRotation, QuaternionInvert(inRotation)));
+ animVertex = Vector3Add(animVertex, outTranslation);
+ model.meshes[m].animVertices[vCounter] += animVertex.x * boneWeight;
+ model.meshes[m].animVertices[vCounter + 1] += animVertex.y * boneWeight;
+ model.meshes[m].animVertices[vCounter + 2] += animVertex.z * boneWeight;
+ // Normals processing
+ // NOTE: We use meshes.baseNormals (default normal) to calculate meshes.normals (animated normals)
+ if (model.meshes[m].normals != NULL)
+ {
+ animNormal = (Vector3){ model.meshes[m].normals[vCounter], model.meshes[m].normals[vCounter + 1], model.meshes[m].normals[vCounter + 2] };
+ animNormal = Vector3RotateByQuaternion(animNormal, QuaternionMultiply(outRotation, QuaternionInvert(inRotation)));
+ model.meshes[m].animNormals[vCounter] += animNormal.x * boneWeight;
+ model.meshes[m].animNormals[vCounter + 1] += animNormal.y * boneWeight;
+ model.meshes[m].animNormals[vCounter + 2] += animNormal.z * boneWeight;
+ }
+ boneCounter += 1;
+ }
vCounter += 3;
- boneCounter += 4;
}
// Upload new vertex data to GPU for model drawing