public void Render(GLContext context, Vector3 position, bool[] isSelected)
        {
            var shader = GlobalShaders.GetShader("GIZMO");

            context.CurrentShader = shader;

            GL.Disable(EnableCap.DepthTest);

            //Scale from camera position
            float scale = 1.0f;
            // if (position.Length != 0)
            // scale *= (context.Camera.Translation.Length / position.Length) * 0.05f;

            var translateMtx = Matrix4.CreateTranslation(position);
            var scaleMtx     = Matrix4.CreateScale(scale);
            var transform    = scaleMtx * translateMtx;

            //Set a center cube
            context.CurrentShader.SetMatrix4x4("mtxMdl", ref transform);
            context.CurrentShader.SetVector4("color", new Vector4(1, 1, 1, 1));
            CubeRenderer.Draw(context, 0.255f);

            //Draw each axis object.
            var ray = context.PointScreenRay();

            for (int i = 0; i < 3; i++)
            {
                //Check ray hits inside bounding boxes
                DrawAxis(context, isSelected[i], ref transform, _endPostions[i], _rotations[i], _colors[i]);
            }

            context.CurrentShader = null;
            GL.Enable(EnableCap.DepthTest);
        }
        public void CreateTextureRender(GLContext control, EventHandler thumbnailUpdate, int width = 50, int height = 50)
        {
            var shader = GlobalShaders.GetShader("SCREEN");

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

            frameBuffer.Bind();

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

            GL.Disable(EnableCap.Blend);

            shader.Enable();

            //Draw the texture onto the framebuffer
            ScreenQuadRender.Draw(shader, RenderableTex.ID);

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

            var thumbnail = frameBuffer.ReadImagePixels(true);

            thumbnail.RotateFlip(System.Drawing.RotateFlipType.RotateNoneFlipY);

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

            this.Thumbnail = thumbnail;
            thumbnailUpdate?.Invoke(this, EventArgs.Empty);
        }
        public void Render(GLContext context, Vector3 lightDirection)
        {
            shadowBox.Update();
            Prepare(lightDirection, shadowBox);

            var shader = GlobalShaders.GetShader("SHADOW");

            context.CurrentShader = shader;

            foreach (var obj in context.Scene.Objects)
            {
                obj.DrawShadowModel(context);
            }

            context.CurrentShader = null;

            Finish();
        }
Exemplo n.º 4
0
        public void Draw(GLContext control, Pass pass, Vector4 sphereColor, Vector4 pickingColor, bool forceUpdate)
        {
            if (pass == Pass.TRANSPARENT)
            {
                return;
            }

            Init(forceUpdate);

            if (Length == 0)
            {
                return;
            }

            GL.LineWidth(5f);

            var shader = GlobalShaders.GetShader("BASIC");

            control.CurrentShader = shader;

            shader.SetMatrix4x4("mtxMdl", ref Transform);
            if (pass == Pass.OPAQUE)
            {
                shader.SetVector4("color", sphereColor);

                vao.Enable(control.CurrentShader);
                vao.Use();
                GL.DrawElements(BeginMode.Lines, Indices.Length, DrawElementsType.UnsignedInt, 0);
            }
            else
            {
                shader.SetVector4("color", pickingColor);

                vao.Enable(control.CurrentShader);
                vao.Use();
                GL.DrawElements(BeginMode.Lines, Indices.Length, DrawElementsType.UnsignedInt, 0);
            }

            GL.LineWidth(1f);
        }
Exemplo n.º 5
0
        public static int CreateTextureRender(int textureID, int width, int height)
        {
            if (lutCache.ContainsKey(textureID.ToString()))
            {
                return(lutCache[textureID.ToString()]);
            }

            var shader = GlobalShaders.GetShader("LUT_DISPLAY");

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

            frameBuffer.Bind();

            GL.Disable(EnableCap.Blend);

            shader.Enable();

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

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

            //Draw the texture onto the framebuffer
            ScreenQuadRender.Draw();

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

            var image = (GLTexture2D)frameBuffer.Attachments[0];

            ID = image.ID;

            lutCache.Add(textureID.ToString(), ID);
            return(ID);
        }
        public static GLTexture2D CreateTextureRender(GLTexture texture, int arrayLevel, int mipLevel, bool force = false)
        {
            if (!force && cubemapCache.ContainsKey(texture.ID.ToString()))
            {
                return(cubemapCache[texture.ID.ToString()]);
            }
            else
            {
                if (cubemapCache.ContainsKey(texture.ID.ToString()))
                {
                    cubemapCache[texture.ID.ToString()]?.Dispose();
                }
            }

            int width  = texture.Width * 4;
            int height = texture.Height * 3;

            width  = 512;
            height = 256;

            var shader        = GlobalShaders.GetShader("EQUIRECTANGULAR");
            var textureOutput = GLTexture2D.CreateUncompressedTexture(width, height, PixelInternalFormat.Rgba32f);

            textureOutput.MipCount = texture.MipCount;

            texture.Bind();

            textureOutput.Bind();
            textureOutput.GenerateMipmaps();
            textureOutput.Unbind();

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

            frameBuffer.Bind();

            GL.Disable(EnableCap.Blend);

            shader.Enable();
            shader.SetBoolToInt("is_array", texture is GLTextureCubeArray);

            if (texture is GLTextureCubeArray)
            {
                GL.ActiveTexture(TextureUnit.Texture1);
                texture.Bind();
                shader.SetInt("dynamic_texture_array", 1);
            }
            else
            {
                GL.ActiveTexture(TextureUnit.Texture1);
                texture.Bind();
                shader.SetInt("dynamic_texture", 1);
            }

            for (int i = 0; i < textureOutput.MipCount; i++)
            {
                int mipWidth  = (int)(width * Math.Pow(0.5, i));
                int mipHeight = (int)(height * Math.Pow(0.5, i));
                frameBuffer.Resize(mipWidth, mipHeight);

                GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0,
                                      textureOutput.ID, i);

                shader.SetInt("arrayLevel", arrayLevel);
                shader.SetInt("mipLevel", mipLevel);

                GL.ClearColor(0, 0, 0, 0);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                GL.Viewport(0, 0, mipWidth, mipHeight);

                //Draw the texture onto the framebuffer
                ScreenQuadRender.Draw();

                break;
            }

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

            if (cubemapCache.ContainsKey(texture.ID.ToString()))
            {
                cubemapCache[texture.ID.ToString()] = textureOutput;
            }
            else
            {
                cubemapCache.Add(texture.ID.ToString(), textureOutput);
            }
            return(textureOutput);
        }