Exemplo n.º 1
0
 static void Setup(Shader shdr, RenderState res, ref LibreLancer.RenderCommand cmd)
 {
     shader.SetViewProjection(cmd.UserData.Camera);
     cmd.UserData.Texture.BindTo(0);
     res.BlendMode = (BlendMode)(int)cmd.UserData.Float;
     res.Cull      = false;
 }
Exemplo n.º 2
0
        void DrawPuffRing(bool inside, CommandBuffer buffer)
        {
            /* Skip rendering puff rings */
            if (!inside)
            {
                Vector3 sz;
                if (Nebula.Zone.Shape is ZoneEllipsoid)
                {
                    sz = ((ZoneEllipsoid)Nebula.Zone.Shape).Size / 2; //we want radius instead of diameter
                }
                else if (Nebula.Zone.Shape is ZoneSphere)
                {
                    sz = new Vector3(((ZoneSphere)Nebula.Zone.Shape).Radius);
                }
                else
                {
                    return;
                }
                var bitRadius = Nebula.ExteriorBitRadius * (1 + Nebula.ExteriorBitRandomVariation);
                var szR       = Math.Max(sz.X, Math.Max(sz.Y, sz.Z));
                var sph       = new BoundingSphere(Nebula.Zone.Position, (szR + bitRadius) * 1.2f);
                if (camera.Frustum.Contains(sph) == ContainmentType.Disjoint)
                {
                    return;
                }
            }
            /* Actually Render */
            var       sd      = 1 - MathHelper.Clamp(Nebula.Zone.Shape.ScaledDistance(camera.Position), 0f, 1f);
            var       factor  = MathHelper.Clamp(sd / Nebula.Zone.EdgeFraction, 0, 1);
            int       idx     = GetPuffsIdx();
            string    lastTex = null;
            Texture2D tex     = null;
            var       sh      = GetPuffShader();

            _puffringsh.SetView(camera);
            _puffringsh.SetViewProjection(camera);
            for (int i = 0; i < Exterior.Count; i++)
            {
                var p = Exterior[i];
                if (p.Texture == null)
                {
                    lastTex = null;
                    tex     = resman.NullTexture;
                }
                else if (lastTex != p.Texture)
                {
                    tex     = (Texture2D)resman.FindTexture(p.Texture);
                    lastTex = p.Texture;
                }
                buffer.AddCommand(sh, puffSetup, puffCleanup, buffer.WorldBuffer.Identity,
                                  new RenderUserData()
                {
                    Texture = tex, Float = factor
                }, sysr.StaticBillboards.VertexBuffer,
                                  PrimitiveTypes.TriangleList, idx, 2, true, inside ? SortLayers.NEBULA_INSIDE : SortLayers.NEBULA_NORMAL,
                                  RenderHelpers.GetZ(camera.Position, p.Position));
                idx += 6;
            }
        }
Exemplo n.º 3
0
 public void Begin(CommandBuffer commands, ResourceManager res, ICamera cam)
 {
     this.commands = commands;
     this.res      = res;
     shader.SetViewProjection(cam);
     verticesSpear = (VertexPositionColorTexture *)bufferSpear.BeginStreaming();
     verticesBolt  = (VertexPositionColorTexture *)bufferBolt.BeginStreaming();
     if (begun)
     {
         throw new InvalidOperationException();
     }
     begun = true;
 }
        static void BandShaderSetup(Shader shader, RenderState state, ref RenderCommand command)
        {
            bandShader.SetWorld(command.World);
            var vp = command.UserData.Camera.ViewProjection;

            bandShader.SetViewProjection(ref vp);
            shader.SetInteger(_bsTexture, 0);
            shader.SetVector3(_bsCameraPosition, command.UserData.Camera.Position);
            shader.SetColor4(_bsColorShift, command.UserData.Color);
            shader.SetFloat(_bsTextureAspect, command.UserData.Float);
            RenderMaterial.SetLights(bandShader, ref command.Lights, bkf++);
            command.UserData.Texture.BindTo(0);
            shader.UseProgram();
            state.BlendMode = BlendMode.Normal;
            state.Cull      = false;
        }
        public void Render()
        {
            if (lineVertices == 0)
            {
                return;
            }
            rstate.Cull         = false;
            rstate.DepthEnabled = false;
            var vp = camera.ViewProjection;

            shader.SetViewProjection(ref vp);
            shader.UseProgram();
            linebuffer.SetData(lines, lineVertices);
            linebuffer.Draw(PrimitiveTypes.LineList, lineVertices / 2);
            rstate.Cull         = true;
            rstate.DepthEnabled = true;
        }
Exemplo n.º 6
0
        void DrawCommands(RenderContext rs, int start, int count)
        {
            shaderBasic.UseProgram();
            rs.Cull = false;

            rs.BlendMode = rendat[datindex].BlendMode;
            if (_frameStart)
            {
                var v  = camera.View;
                var vp = camera.ViewProjection;
                shaderBasic.SetView(ref v);
                shaderBasic.SetViewProjection(ref vp);
                _frameStart = false;
            }

            rendat[datindex].Texture.BindTo(0);
            vboBasic.Draw(PrimitiveTypes.TriangleList, 0, start, count / 3);
            rs.Cull     = true;
            lastDatHash = -1;
        }
Exemplo n.º 7
0
        public override void Draw(ICamera camera, CommandBuffer commands, SystemLighting lights, NebulaRenderer nr)
        {
            if (sysr == null || vertices == null)
            {
                return;
            }
            float z = RenderHelpers.GetZ(Matrix4x4.Identity, camera.Position, pos);

            if (z > 900000) // Reduce artefacts from fast Z-sort calculation. This'll probably cause issues somewhere else
            {
                z = 900000;
            }
            var dist_scale = nr != null ? nr.Nebula.SunBurnthroughScale : 1;
            var alpha      = nr != null ? nr.Nebula.SunBurnthroughIntensity : 1;

            if (radialShader == null)
            {
                radialShader = Shaders.SunRadial.Get();
                radialTex0   = radialShader.Shader.GetLocation("tex0");
                radialSize   = radialShader.Shader.GetLocation("SizeMultiplier");
                radialAlpha  = radialShader.Shader.GetLocation("outerAlpha");
            }
            if (spineShader == null)
            {
                spineShader = Shaders.SunSpine.Get();
                spineTex0   = spineShader.Shader.GetLocation("tex0");
                spineSize   = spineShader.Shader.GetLocation("SizeMultiplier");
            }
            radialShader.SetViewProjection(camera);
            radialShader.SetView(camera);
            spineShader.SetViewProjection(camera);
            spineShader.SetView(camera);

            int idx = sysr.StaticBillboards.DoVertices(ref ID, vertices);

            if (Sun.CenterSprite != null)
            {
                //draw center
                var cr = (Texture2D)sysr.ResourceManager.FindTexture(Sun.CenterSprite);
                commands.AddCommand(radialShader.Shader, RadialSetup, Cleanup, commands.WorldBuffer.Identity,
                                    new RenderUserData()
                {
                    Float = 0, Color = new Color4(dist_scale, alpha, 0, 0), Texture = cr
                }, sysr.StaticBillboards.VertexBuffer, PrimitiveTypes.TriangleList,
                                    idx, 2, true, SortLayers.SUN, z);
                //next
                idx += 6;
            }
            //draw glow
            var gr = (Texture2D)sysr.ResourceManager.FindTexture(Sun.GlowSprite);

            commands.AddCommand(radialShader.Shader, RadialSetup, Cleanup, commands.WorldBuffer.Identity,
                                new RenderUserData()
            {
                Float = 1, Color = new Color4(dist_scale, alpha, 0, 0), Texture = gr
            }, sysr.StaticBillboards.VertexBuffer, PrimitiveTypes.TriangleList,
                                idx, 2, true, SortLayers.SUN, z + 108f);
            //next
            idx += 6;
            //draw spines
            if (Sun.SpinesSprite != null && nr == null)
            {
                var spinetex = (Texture2D)sysr.ResourceManager.FindTexture(Sun.SpinesSprite);
                commands.AddCommand(spineShader.Shader, SpineSetup, Cleanup, commands.WorldBuffer.Identity,
                                    new RenderUserData()
                {
                    Texture = spinetex
                }, sysr.StaticBillboards.VertexBuffer, PrimitiveTypes.TriangleList,
                                    idx, 2 * Sun.Spines.Count, true, SortLayers.SUN, z + 1112f);
            }
        }