mirror of
https://github.com/4sval/FModel.git
synced 2026-06-21 07:20:05 -05:00
fixed outliner
This commit is contained in:
parent
9da407ea39
commit
2a6c42d15f
|
|
@ -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;
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
|
|
@ -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
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,11 @@ public class BufferObject<TDataType> : IDisposable where TDataType : unmanaged
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ public class Skeleton : IDisposable
|
|||
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)
|
||||
|
|
@ -105,7 +105,7 @@ public class Skeleton : IDisposable
|
|||
|
||||
if (!HasAnim)
|
||||
{
|
||||
foreach (var boneIndex in BonesTransformByIndex.Keys)
|
||||
for (int boneIndex = 0; boneIndex < InvertedBonesMatrixByIndex.Length; boneIndex++)
|
||||
{
|
||||
_ssbo.Update(boneIndex, Matrix4x4.Identity);
|
||||
}
|
||||
|
|
@ -113,7 +113,7 @@ public class Skeleton : IDisposable
|
|||
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));
|
||||
}
|
||||
|
|
@ -129,6 +129,7 @@ public class Skeleton : IDisposable
|
|||
BonesTransformByIndex.Clear();
|
||||
Anim?.Dispose();
|
||||
|
||||
_ssbo?.Dispose();
|
||||
GL.DeleteProgram(_handle);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user