Skip to content

Commit

Permalink
fixed outliner
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed Feb 8, 2023
1 parent 9da407e commit 2a6c42d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 27 deletions.
14 changes: 8 additions & 6 deletions FModel/Resources/default.vert
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ layout (location = 9) in mat4 vInstanceMatrix;
layout (location = 13) in vec3 vMorphTargetPos;
layout (location = 14) in vec3 vMorphTargetTangent;

uniform mat4 uView;
uniform mat4 uProjection;
uniform float uMorphTime;
layout(std430, binding = 1) buffer layoutName
layout(std430, binding = 1) buffer BoneMatrices
{
mat4 uFinalBonesMatrix[];
};

uniform mat4 uView;
uniform mat4 uProjection;
uniform float uMorphTime;

out vec3 fPos;
out vec3 fNormal;
out vec3 fTangent;
Expand All @@ -44,11 +45,12 @@ void main()
if(boneIndex < 0) break;

mat4 boneMatrix = uFinalBonesMatrix[boneIndex];
mat4 inverseBoneMatrix = transpose(inverse(boneMatrix));
float weight = vBoneWeights[i];

finalPos += boneMatrix * bindPos * weight;
finalNormal += boneMatrix * bindNormal * weight;
finalTangent += boneMatrix * bindTangent * weight;
finalNormal += inverseBoneMatrix * bindNormal * weight;
finalTangent += inverseBoneMatrix * bindTangent * weight;
}
}
else
Expand Down
14 changes: 8 additions & 6 deletions FModel/Resources/outline.vert
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ layout (location = 8) in vec4 vBoneWeights;
layout (location = 9) in mat4 vInstanceMatrix;
layout (location = 13) in vec3 vMorphTargetPos;

layout(std430, binding = 1) buffer BoneMatrices
{
mat4 uFinalBonesMatrix[];
};

uniform mat4 uView;
uniform vec3 uViewPos;
uniform mat4 uProjection;
uniform float uMorphTime;
layout(std430, binding = 1) buffer layoutName
{
mat4 uFinalBonesMatrix[];
};

void main()
{
Expand All @@ -34,7 +35,7 @@ void main()
float weight = vBoneWeights[i];

finalPos += boneMatrix * bindPos * weight;
finalNormal += boneMatrix * bindNormal * weight;
finalNormal += transpose(inverse(boneMatrix)) * bindNormal * weight;
}
}
else
Expand All @@ -43,9 +44,10 @@ void main()
finalNormal = bindNormal;
}

finalPos = vInstanceMatrix * finalPos;
float scaleFactor = distance(vec3(finalPos), uViewPos) * 0.0025;
vec4 nor = transpose(inverse(vInstanceMatrix)) * finalNormal * scaleFactor;
finalPos.xyz += nor.xyz;

gl_Position = uProjection * uView * vInstanceMatrix * finalPos;
gl_Position = uProjection * uView * finalPos;
}
19 changes: 7 additions & 12 deletions FModel/Resources/picking.vert
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ layout (location = 8) in vec4 vBoneWeights;
layout (location = 9) in mat4 vInstanceMatrix;
layout (location = 13) in vec3 vMorphTargetPos;

uniform mat4 uView;
uniform mat4 uProjection;
uniform float uMorphTime;
layout(std430, binding = 1) buffer layoutName
layout(std430, binding = 1) buffer BoneMatrices
{
mat4 uFinalBonesMatrix[];
};

uniform mat4 uView;
uniform mat4 uProjection;
uniform float uMorphTime;

void main()
{
vec4 bindPos = vec4(mix(vPos, vMorphTargetPos, uMorphTime), 1.0);
Expand All @@ -26,16 +27,10 @@ void main()
int boneIndex = int(vBoneIds[i]);
if(boneIndex < 0) break;

mat4 boneMatrix = uFinalBonesMatrix[boneIndex];
float weight = vBoneWeights[i];

finalPos += boneMatrix * bindPos * weight;
finalPos += uFinalBonesMatrix[boneIndex] * bindPos * vBoneWeights[i];
}
}
else
{
finalPos = bindPos;
}
else finalPos = bindPos;

gl_Position = uProjection * uView * vInstanceMatrix * finalPos;
}
5 changes: 5 additions & 0 deletions FModel/Views/Snooper/Buffers/BufferObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public unsafe BufferObject(TDataType[] data, BufferTarget bufferTarget) : this(b
GL.BufferData(bufferTarget, data.Length * sizeof(TDataType), data, BufferUsageHint.StaticDraw);
}

public unsafe BufferObject(int length, BufferTarget bufferTarget) : this(bufferTarget)
{
GL.BufferData(bufferTarget, length * sizeof(TDataType), IntPtr.Zero, BufferUsageHint.StaticDraw);
}

public unsafe void Update(int offset, TDataType data)
{
GL.BufferSubData(_bufferTarget, (IntPtr) (offset * sizeof(TDataType)), sizeof(TDataType), ref data);
Expand Down
7 changes: 4 additions & 3 deletions FModel/Views/Snooper/Models/Animations/Skeleton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void SetAnimation(CAnimSet anim, bool rotationOnly)
public void Setup()
{
_handle = GL.CreateProgram();
_ssbo = new BufferObject<Matrix4x4>(InvertedBonesMatrixByIndex, BufferTarget.ShaderStorageBuffer);
_ssbo = new BufferObject<Matrix4x4>(InvertedBonesMatrixByIndex.Length, BufferTarget.ShaderStorageBuffer);
}

public void Render(float deltaSeconds = 0f, bool update = false)
Expand All @@ -105,15 +105,15 @@ public void Render(float deltaSeconds = 0f, bool update = false)

if (!HasAnim)
{
foreach (var boneIndex in BonesTransformByIndex.Keys)
for (int boneIndex = 0; boneIndex < InvertedBonesMatrixByIndex.Length; boneIndex++)
{
_ssbo.Update(boneIndex, Matrix4x4.Identity);
}
}
else
{
if (update) Anim.Update(deltaSeconds);
foreach (var boneIndex in BonesTransformByIndex.Keys)
for (int boneIndex = 0; boneIndex < InvertedBonesMatrixByIndex.Length; boneIndex++)
{
_ssbo.Update(boneIndex, InvertedBonesMatrixByIndex[boneIndex] * Anim.InterpolateBoneTransform(boneIndex));
}
Expand All @@ -129,6 +129,7 @@ public void Dispose()
BonesTransformByIndex.Clear();
Anim?.Dispose();

_ssbo?.Dispose();
GL.DeleteProgram(_handle);
}
}

0 comments on commit 2a6c42d

Please sign in to comment.