diff --git a/FModel/FModel.csproj b/FModel/FModel.csproj index 064d87aa..52305c1c 100644 --- a/FModel/FModel.csproj +++ b/FModel/FModel.csproj @@ -77,6 +77,7 @@ + @@ -207,6 +208,7 @@ + diff --git a/FModel/Resources/checker.png b/FModel/Resources/checker.png new file mode 100644 index 00000000..8e1daf31 Binary files /dev/null and b/FModel/Resources/checker.png differ diff --git a/FModel/Resources/default.frag b/FModel/Resources/default.frag index 7e6aac04..29b9f84d 100644 --- a/FModel/Resources/default.frag +++ b/FModel/Resources/default.frag @@ -228,7 +228,7 @@ void main() } else if (bVertexColors[4]) { - FragColor = vec4(fTexCoords, 0.0, 1.0); + FragColor = SamplerToVector(uParameters.Diffuse[0].Sampler); } else { diff --git a/FModel/Views/Snooper/Animations/Skeleton.cs b/FModel/Views/Snooper/Animations/Skeleton.cs index 87febc9f..ff01318d 100644 --- a/FModel/Views/Snooper/Animations/Skeleton.cs +++ b/FModel/Views/Snooper/Animations/Skeleton.cs @@ -110,7 +110,6 @@ public class Skeleton : IDisposable _vaoHandle = GL.GenVertexArray(); GL.BindVertexArray(_vaoHandle); - _vbo = new BufferObject(_vertexSize * BoneCount, BufferTarget.ArrayBuffer); var sf = sizeof(float); @@ -224,18 +223,10 @@ public class Skeleton : IDisposable _vbo.Bind(); foreach (var (boneName, bone) in BonesByLoweredName) { - Matrix4x4 boneMatrix; - Matrix4x4 parentBoneMatrix; - if (IsAnimated) - { - boneMatrix = _boneMatriceAtFrame[bone.Index]; - parentBoneMatrix = bone.IsRoot ? boneMatrix : _boneMatriceAtFrame[bone.ParentIndex]; - } - else - { - boneMatrix = bone.Rest.Matrix; - parentBoneMatrix = bone.IsRoot ? boneMatrix : BonesByLoweredName[bone.LoweredParentName].Rest.Matrix; - } + var boneMatrix = IsAnimated ? _boneMatriceAtFrame[bone.Index] : bone.Rest.Matrix; + var parentBoneMatrix = bone.IsRoot ? boneMatrix : + IsAnimated ? _boneMatriceAtFrame[bone.ParentIndex] : + BonesByLoweredName[bone.LoweredParentName].Rest.Matrix; var count = 0; var baseIndex = bone.Index * _vertexSize; diff --git a/FModel/Views/Snooper/Models/IRenderableModel.cs b/FModel/Views/Snooper/Models/IRenderableModel.cs index a651bcc0..a863ec98 100644 --- a/FModel/Views/Snooper/Models/IRenderableModel.cs +++ b/FModel/Views/Snooper/Models/IRenderableModel.cs @@ -31,7 +31,7 @@ public interface IRenderableModel : IDisposable public void Setup(Options options); public void SetupInstances(); - public void Render(Shader shader, bool outline = false); + public void Render(Shader shader, Texture checker = null, bool outline = false); public void PickingRender(Shader shader); public void Update(Options options); public void AddInstance(Transform transform); diff --git a/FModel/Views/Snooper/Models/UModel.cs b/FModel/Views/Snooper/Models/UModel.cs index 836331ac..b73b0c84 100644 --- a/FModel/Views/Snooper/Models/UModel.cs +++ b/FModel/Views/Snooper/Models/UModel.cs @@ -227,7 +227,7 @@ public abstract class UModel : IRenderableModel IsSetup = true; } - public virtual void Render(Shader shader, bool outline = false) + public virtual void Render(Shader shader, Texture checker = null, bool outline = false) { if (outline) GL.Disable(EnableCap.DepthTest); if (IsTwoSided) GL.Disable(EnableCap.CullFace); @@ -252,8 +252,16 @@ public abstract class UModel : IRenderableModel if (!section.Show) continue; if (!outline) { - shader.SetUniform("uSectionColor", section.Color); - Materials[section.MaterialIndex].Render(shader); + if (checker != null) + { + shader.SetUniform("uParameters.Diffuse[0].Sampler", 0); + checker.Bind(TextureUnit.Texture0); + } + else + { + shader.SetUniform("uSectionColor", section.Color); + Materials[section.MaterialIndex].Render(shader); + } } GL.DrawElementsInstanced(PrimitiveType.Triangles, section.FacesCount, DrawElementsType.UnsignedInt, section.FirstFaceIndexPtr, TransformsCount); diff --git a/FModel/Views/Snooper/Options.cs b/FModel/Views/Snooper/Options.cs index 83d37d33..aab519e0 100644 --- a/FModel/Views/Snooper/Options.cs +++ b/FModel/Views/Snooper/Options.cs @@ -43,6 +43,7 @@ public class Options { ["material"] = new ("materialicon"), ["noimage"] = new ("T_Placeholder_Item_Image"), + ["checker"] = new ("checker"), ["pointlight"] = new ("pointlight"), ["spotlight"] = new ("spotlight"), ["link_on"] = new ("link_on"), diff --git a/FModel/Views/Snooper/Renderer.cs b/FModel/Views/Snooper/Renderer.cs index 285c8154..d5af993f 100644 --- a/FModel/Views/Snooper/Renderer.cs +++ b/FModel/Views/Snooper/Renderer.cs @@ -245,7 +245,7 @@ public class Renderer : IDisposable foreach (var model in Options.Models.Values) { if (!model.IsVisible) continue; - model.Render(_shader); + model.Render(_shader, Color == VertexColor.TextureCoordinates ? Options.Icons["checker"] : null); } { // light pass @@ -271,7 +271,7 @@ public class Renderer : IDisposable } _outline.Render(viewMatrix, CameraOp.Position, projMatrix); - selected.Render(_outline, true); + selected.Render(_outline, Color == VertexColor.TextureCoordinates ? Options.Icons["checker"] : null, true); } // picking pass (dedicated FBO, binding to 0 afterward) diff --git a/FModel/Views/Snooper/Shading/Material.cs b/FModel/Views/Snooper/Shading/Material.cs index 2540ecf5..7c1d6296 100644 --- a/FModel/Views/Snooper/Shading/Material.cs +++ b/FModel/Views/Snooper/Shading/Material.cs @@ -76,11 +76,11 @@ public class Material : IDisposable if (uvCount < 1 || Parameters.IsNull) { - Diffuse = new[] { new Texture(new FLinearColor(1f, 0f, 0f, 1f)) }; + Diffuse = new[] { options.Icons["checker"] }; Normals = new[] { new Texture(new FLinearColor(0.498f, 0.498f, 0.996f, 1f)) }; SpecularMasks = new [] { new Texture(new FLinearColor(1f, 0.5f, 0.5f, 1f)) }; Emissive = new Texture[1]; - DiffuseColor = new[] { new Vector4(0.5f) }; + DiffuseColor = new[] { Vector4.One }; EmissiveColor = new[] { Vector4.One }; } else