private void DrawSolidColorMesh(GLFrameworkEngine.ShaderProgram shader, BfresMeshAsset mesh)
        {
            if (!mesh.IsVisible)
            {
                return;
            }

            if (mesh.SkinCount > 0)
            {
                SetModelMatrix(shader.program, ModelData.Skeleton, mesh.SkinCount > 1);
            }

            var worldTransform = ParentRender.Transform.TransformMatrix;
            var transform      = this.ModelData.Skeleton.Bones[mesh.BoneIndex].Transform;

            shader.SetMatrix4x4("RigidBindTransform", ref transform);
            shader.SetMatrix4x4("mtxMdl", ref worldTransform);
            shader.SetInt("SkinCount", mesh.SkinCount);
            shader.SetInt("UseSkinning", 1);

            //Draw the mesh
            mesh.defaultVao.Enable(shader);
            mesh.defaultVao.Use();
            mesh.Draw();
        }
        public void SetPickingColorFaces(List <IPickable> pickables, ShaderProgram shader)
        {
            shader.SetInt("pickFace", 1);
            shader.SetInt("pickedIndex", pickingIndex);

            for (int i = 0; i < pickables.Count; i++)
            {
                var color = new Vector4(
                    ((pickingIndex >> 16) & 0xFF),
                    ((pickingIndex >> 8) & 0xFF),
                    (pickingIndex & 0xFF),
                    ((pickingIndex++ >> 24) & 0xFF)
                    );

                color = new Vector4(color.X, color.Y, color.Z, color.W);

                var key = BitConverter.ToUInt32(new byte[] {
                    (byte)color.X, (byte)color.Y,
                    (byte)color.Z, (byte)color.W
                }, 0);
                ColorPassIDs.Add(key, pickables[i]);
            }
        }
Exemple #3
0
        public static void Draw(ShaderProgram shader, int textureID)
        {
            Init();

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();

            GL.ActiveTexture(TextureUnit.Texture1);
            GL.BindTexture(TextureTarget.Texture2D, textureID);
            shader.SetInt("screenTexture", 1);

            GL.Enable(EnableCap.CullFace);
            GL.Enable(EnableCap.DepthTest);
            GL.CullFace(CullFaceMode.Back);

            vao.Enable(shader);
            vao.Use();
            GL.DrawArrays(PrimitiveType.TriangleStrip, 0, Length);
        }
Exemple #4
0
 static void BindTexture(ShaderProgram shader, GLTexture tex, string uniform, int slot)
 {
     GL.ActiveTexture(TextureUnit.Texture0 + slot);
     tex.Bind();
     shader.SetInt(uniform, slot);
 }
        public void CreateMaterialRender(GLContext control, GenericPickableMesh mesh,
                                         RenderObject renderObject, EventHandler thumbnailUpdated, int width = 50, int height = 50)
        {
            ShaderProgram shader = this.GetShader();

            if (shader == null)
            {
                return;
            }

            Framebuffer frameBuffer = new Framebuffer(FramebufferTarget.Framebuffer, width, height);

            frameBuffer.Bind();

            //Create a simple mvp matrix to render the material data
            Matrix4 modelMatrix = Matrix4.CreateTranslation(0, 0, -12);
            Matrix4 viewMatrix  = Matrix4.Identity;
            Matrix4 mtxProj     = Matrix4.CreatePerspectiveFieldOfView(MathHelper.DegreesToRadians(90), 1.0f, 1.0f, 1000f);
            Matrix4 viewProj    = mtxProj * viewMatrix;

            GL.UseProgram(shader.program);
            shader.SetMatrix4x4("mtxCam", ref viewProj);
            shader.SetMatrix4x4("mtxMdl", ref modelMatrix);
            shader.SetVector3("camPosition", control.Camera.TargetPosition);
            shader.SetVector2("iResolution", new Vector2(control.Width, control.Height));
            shader.SetInt("materialRenderDisplay", 1);

            GL.ClearColor(0, 0, 0, 0);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.Viewport(0, 0, width, height);

            //Render material data onto a textured sphere
            Render(control, shader, mesh);

            GL.Enable(EnableCap.Blend);
            GL.BlendFuncSeparate(
                BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha,
                BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcAlpha);

            //Draw the model to render onto
            switch (renderObject)
            {
            case RenderObject.Sphere:
                DrawSphere(control);
                break;

            case RenderObject.Plane:
                DrawPlane(control);
                break;
            }

            //Disable the uniform data
            shader.SetInt("materialRenderDisplay", 0);

            //Disable shader and textures
            GL.UseProgram(0);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            var thumbnail = frameBuffer.ReadImagePixels(true);

            //Dispose frame buffer
            frameBuffer.Dispoe();
            frameBuffer.DisposeRenderBuffer();

            this.Thumbnail = thumbnail;
            thumbnailUpdated?.Invoke(this, EventArgs.Empty);
        }