public void OnRender(Camera camera, Vector4 highlightColor) { if (ShaderProgram == null) { PrepareShaders(); } if (ShaderProgramDebug == null) { PrepareDebugShaders(); } //SkeletonRender.Render(camera); Matrix4 mtxMdl = camera.ModelMatrix * Matrix4.CreateScale(PreviewScale); Matrix4 mtxCam = camera.ViewMatrix * camera.ProjectionMatrix; if (Runtime.DebugRendering != Runtime.DebugRender.Default) { ShaderProgramDebug.Enable(); ShaderProgramDebug.SetVector4("highlight_color", highlightColor); ShaderProgramDebug.SetMatrix4x4("mtxMdl", ref mtxMdl); ShaderProgramDebug.SetMatrix4x4("mtxCam", ref mtxCam); ReloadUniforms(ShaderProgramDebug); } else { ShaderProgram.Enable(); ShaderProgram.SetVector4("highlight_color", highlightColor); ShaderProgram.SetMatrix4x4("mtxMdl", ref mtxMdl); ShaderProgram.SetMatrix4x4("mtxCam", ref mtxCam); ReloadUniforms(ShaderProgram); } }
public void Render(Camera camera) { if (Skeleton == null || !Visibile || !Runtime.DisplayBones) { return; } CheckBuffers(); if (!Runtime.OpenTKInitialized) { return; } Console.WriteLine($"Skeleton render {Skeleton.Bones.Count}"); ShaderProgram.Enable(); GL.Disable(EnableCap.CullFace); GL.Disable(EnableCap.DepthTest); ShaderProgram.EnableVertexAttributes(); ShaderProgram.SetMatrix4x4("rotation", ref prismRotation); Matrix4 camMat = camera.ViewMatrix; Matrix4 mdlMat = camera.ModelMatrix; Matrix4 projMat = camera.ProjectionMatrix; Matrix4 computedCamMtx = camMat * projMat; ShaderProgram.SetMatrix4x4("mtxCam", ref computedCamMtx); ShaderProgram.SetMatrix4x4("mtxMdl", ref mdlMat); foreach (STBone bn in Skeleton.Bones) { if (!bn.Visible) { continue; } Matrix4 modelMatrix = Matrix4.Identity; ShaderProgram.SetVector4("boneColor", ColorUtility.ToVector4(boneColor)); ShaderProgram.SetFloat("scale", Runtime.BonePointSize * Skeleton.PreviewScale); ShaderProgram.SetMatrix4x4("ModelMatrix", ref modelMatrix); Matrix4 transform = bn.Transform; ShaderProgram.SetMatrix4x4("bone", ref transform); ShaderProgram.SetInt("hasParent", bn.ParentIndex != -1 ? 1 : 0); if (bn.ParentIndex != -1) { var transformParent = ((STBone)bn.Parent).Transform; ShaderProgram.SetMatrix4x4("parent", ref transformParent); } Draw(ShaderProgram); if (Runtime.SelectedBoneIndex == Skeleton.Bones.IndexOf(bn)) { ShaderProgram.SetVector4("boneColor", ColorUtility.ToVector4(selectedBoneColor)); } ShaderProgram.SetInt("hasParent", 0); Draw(ShaderProgram); } ShaderProgram.DisableVertexAttributes(); GL.UseProgram(0); GL.Enable(EnableCap.CullFace); GL.Enable(EnableCap.DepthTest); }