コード例 #1
0
        public override void Render(Scene.RenderContext context)
        {
            if (!Enabled)
            {
                return;
            }

            var viewProjectionMatrix = (Transform * context.Camera.ViewProjectionMatrix).ToOpenTK();

            GL.UseProgram(shader.Program);

            GL.UniformMatrix4(shader.GetUniformLocation("uProjectionViewMatrix"), false, ref viewProjectionMatrix);
            GL.DepthMask(false);

            GL.BindVertexArray(vaoHandle);
            GL.DrawElements(PrimitiveType.Lines, indexCount, DrawElementsType.UnsignedInt, 0);
            GL.BindVertexArray(0);

            GL.DepthMask(true);
        }
コード例 #2
0
        public static void Render(List <Request> requests, Scene.RenderContext context)
        {
            // Opaque: Grouped by material
            if (context.RenderPass == RenderPass.Both || context.RenderPass == RenderPass.Opaque)
            {
                DrawBatch(requests, context);
            }

            // Translucent: In reverse order
            if (context.RenderPass == RenderPass.Both || context.RenderPass == RenderPass.Translucent)
            {
                var holder = new Request[1]; // Holds the one request we render at a time

                requests.Sort((a, b) => - a.DistanceFromCamera.CompareTo(b.DistanceFromCamera));

                foreach (var request in requests)
                {
                    holder[0] = request;
                    DrawBatch(holder, context);
                }
            }
        }
コード例 #3
0
 public override void Render(Scene.RenderContext context)
 {
     // This node does not render itself; it uses the batching system via IRenderableMeshCollection
 }
コード例 #4
0
        private static void DrawBatch(IEnumerable <Request> drawCalls, Scene.RenderContext context)
        {
            GL.Enable(EnableCap.DepthTest);

            var viewProjectionMatrix = context.Camera.ViewProjectionMatrix.ToOpenTK();
            var cameraPosition       = context.Camera.Location.ToOpenTK();

            foreach (var shaderGroup in drawCalls.GroupBy(a => a.Call.Shader))
            {
                var shader = shaderGroup.Key;

                var uniformLocationAnimated         = shader.GetUniformLocation("bAnimated");
                var uniformLocationAnimationTexture = shader.GetUniformLocation("animationTexture");
                var uniformLocationNumBones         = shader.GetUniformLocation("fNumBones");
                var uniformLocationTransform        = shader.GetUniformLocation("transform");
                var uniformLocationTint             = shader.GetUniformLocation("m_vTintColorSceneObject");
                var uniformLocationTintDrawCall     = shader.GetUniformLocation("m_vTintColorDrawCall");
                var uniformLocationTime             = shader.GetUniformLocation("g_flTime");

                GL.UseProgram(shader.Program);

                GL.Uniform3(shader.GetUniformLocation("vLightPosition"), cameraPosition);
                GL.Uniform3(shader.GetUniformLocation("vEyePosition"), cameraPosition);
                GL.UniformMatrix4(shader.GetUniformLocation("uProjectionViewMatrix"), false, ref viewProjectionMatrix);

                foreach (var materialGroup in shaderGroup.GroupBy(a => a.Call.Material))
                {
                    var material = materialGroup.Key;
                    material.Render(shader);

                    foreach (var request in materialGroup)
                    {
                        var transformTk = request.Transform.ToOpenTK();
                        GL.UniformMatrix4(uniformLocationTransform, false, ref transformTk);

                        if (uniformLocationTime != 1)
                        {
                            GL.Uniform1(uniformLocationTime, request.Mesh.Time);
                        }

                        if (uniformLocationAnimated != -1)
                        {
                            GL.Uniform1(uniformLocationAnimated, request.Mesh.AnimationTexture.HasValue ? 1.0f : 0.0f);
                        }

                        //Push animation texture to the shader (if it supports it)
                        if (request.Mesh.AnimationTexture.HasValue)
                        {
                            if (uniformLocationAnimationTexture != -1)
                            {
                                GL.ActiveTexture(TextureUnit.Texture0);
                                GL.BindTexture(TextureTarget.Texture2D, request.Mesh.AnimationTexture.Value);
                                GL.Uniform1(uniformLocationAnimationTexture, 0);
                            }

                            if (uniformLocationNumBones != -1)
                            {
                                var v = (float)Math.Max(1, request.Mesh.AnimationTextureSize - 1);
                                GL.Uniform1(uniformLocationNumBones, v);
                            }
                        }

                        if (uniformLocationTint > -1)
                        {
                            var tint = request.Mesh.Tint.ToOpenTK();
                            GL.Uniform4(uniformLocationTint, tint);
                        }

                        if (uniformLocationTintDrawCall > -1)
                        {
                            GL.Uniform3(uniformLocationTintDrawCall, request.Call.TintColor);
                        }

                        GL.BindVertexArray(request.Call.VertexArrayObject);
                        GL.DrawElements(request.Call.PrimitiveType, request.Call.IndexCount, request.Call.IndexType, (IntPtr)request.Call.StartIndex);
                    }

                    material.PostRender();
                }
            }

            GL.Disable(EnableCap.DepthTest);
        }
コード例 #5
0
 public override void Render(Scene.RenderContext context)
 {
     particleRenderer.Render(context.Camera, context.RenderPass);
 }