コード例 #1
0
        public override void Use(RenderState rstate, IVertexType vertextype, Lighting lights)
        {
            rstate.DepthEnabled = true;
            rstate.BlendMode    = BlendMode.Opaque;

            ShaderVariables sh = GetShader(vertextype);

            sh.SetWorld(ref World);
            sh.SetViewProjection(Camera);
            sh.SetView(Camera);
            sh.SetAc(Ac);
            sh.SetDc(Dc);
            sh.SetTileRate(TileRate);
            sh.SetFlipU(FlipU);
            sh.SetFlipV(FlipV);

            sh.SetDtSampler(0);
            BindTexture(rstate, 0, DtSampler, 0, DtFlags);
            sh.SetDm1Sampler(1);
            BindTexture(rstate, 1, Dm1Sampler, 1, Dm1Flags);
            SetLights(sh, lights);
            var normalMatrix = World;

            normalMatrix.Invert();
            normalMatrix.Transpose();
            sh.SetNormalMatrix(ref normalMatrix);
            sh.UseProgram();
        }
コード例 #2
0
        public override void Use(RenderState rstate, IVertexType vertextype, ref Lighting lights)
        {
            ShaderVariables sh;

            //These things don't have normals
            if (vertextype is VertexPositionColorTexture ||
                vertextype is VertexPosition ||
                vertextype is VertexPositionColor || vertextype is VertexPositionTexture)
            {
                if (shader_null == null)
                {
                    shader_null = ShaderCache.Get("Normals_Position.vs", "Normals.frag");
                }
                sh = shader_null;
            }
            else
            {
                if (shader == null)
                {
                    shader = ShaderCache.Get("Normals_PositionNormal.vs", "Normals.frag");
                }
                sh = shader;
            }
            if (Camera == null)
            {
                return;
            }
            rstate.BlendMode = BlendMode.Opaque;
            sh.SetViewProjection(Camera);
            //Dt
            sh.SetWorld(World);
            sh.UseProgram();
        }
コード例 #3
0
        public static ShaderVariables Get(string vs, string fs, ShaderCaps caps = ShaderCaps.None)
        {
            var             k = new Strings2(vs, fs, caps);
            ShaderVariables sh;

            if (!shaders.TryGetValue(k, out sh))
            {
                string prelude;
                if (GLExtensions.Features430)
                {
                    prelude = "#version 430\n#define FEATURES430\n" + caps.GetDefines() + "\n#line 0\n";
                }
                else
                {
                    prelude = "#version 150\n" + caps.GetDefines() + "\n#line 0\n";
                }
                FLLog.Debug("Shader", "Compiling [ " + vs + " , " + fs + " ]");
                sh = new ShaderVariables(
                    new Shader(
                        prelude + "#define VERTEX_SHADER\n" + ProcessIncludes(Resources.LoadString("LibreLancer.Shaders." + vs)),
                        prelude + "#define FRAGMENT_SHADER\n" + ProcessIncludes(Resources.LoadString("LibreLancer.Shaders." + fs)))
                    );
                shaders.Add(k, sh);
            }
            return(sh);
        }
コード例 #4
0
        static void SetLight(ShaderVariables shader, bool hasSpotlight, int i, ref RenderLight lt)
        {
            float kind = 0;

            if (lt.Kind == LightKind.Point || lt.Kind == LightKind.Spotlight)
            {
                kind = 1;
            }
            else if (lt.Kind == LightKind.PointAttenCurve)
            {
                kind = 2;
            }
            shader.SetLightsPos(i, new Vector4(lt.Kind == LightKind.Directional ? lt.Direction : lt.Position, kind));
            shader.SetLightsColorRange(i, new Vector4(lt.Color.R, lt.Color.G, lt.Color.B, lt.Range));
            shader.SetLightsAttenuation(i, lt.Attenuation);
            if (hasSpotlight)
            {
                if (lt.Kind == LightKind.Spotlight)
                {
                    shader.SetLightsDir(i, lt.Direction);
                    shader.SetSpotlightParams(i, new Vector3(lt.Falloff, (float)(Math.Cos(lt.Theta / 2.0)), (float)(Math.Cos(lt.Phi / 2.0))));
                }
                else if (lt.Kind == LightKind.Point || lt.Kind == LightKind.PointAttenCurve)
                {
                    shader.SetSpotlightParams(i, Vector3.Zero);
                }
            }
        }
コード例 #5
0
        public static void SetLights(ShaderVariables shader, Lighting lights)
        {
            bool hasSpotlight = HasSpotlight(ref lights);
            var  h            = lights.Hash;

            if (shader.UserTag == h)
            {
                return;
            }
            shader.UserTag = h;
            shader.SetLightingEnabled(lights.Enabled ? 1 : 0);
            if (!lights.Enabled)
            {
                return;
            }
            shader.SetAmbientColor(lights.Ambient);
            shader.SetLightCount(lights.Lights.Count);
            shader.SetTilesX(lights.NumberOfTilesX);
            for (int i = 0; i < lights.Lights.Count; i++)
            {
                var   lt   = lights.Lights[i];
                float kind = 0;
                if (lt.Kind == LightKind.Point || lt.Kind == LightKind.Spotlight)
                {
                    kind = 1;
                }
                else if (lt.Kind == LightKind.PointAttenCurve)
                {
                    kind = 2;
                }
                shader.SetLightsPos(i, new Vector4(lt.Kind == LightKind.Directional ? lt.Direction : lt.Position, kind));
                shader.SetLightsColorRange(i, new Vector4(lt.Color.R, lt.Color.G, lt.Color.B, lt.Range));
                shader.SetLightsAttenuation(i, lt.Attenuation);
                if (hasSpotlight)
                {
                    if (lt.Kind == LightKind.Spotlight)
                    {
                        shader.SetLightsDir(i, lt.Direction);
                        shader.SetSpotlightParams(i, new Vector3(lt.Falloff, (float)(Math.Cos(lt.Theta / 2.0)), (float)(Math.Cos(lt.Phi / 2.0))));
                    }
                    else if (lt.Kind == LightKind.Point || lt.Kind == LightKind.PointAttenCurve)
                    {
                        shader.SetSpotlightParams(i, Vector3.Zero);
                    }
                }
            }
            shader.SetFogMode((int)lights.FogMode);
            if (lights.FogMode == FogModes.Linear)
            {
                shader.SetFogColor(lights.FogColor);
                shader.SetFogRange(lights.FogRange);
            }
            else if (lights.FogMode == FogModes.Exp || lights.FogMode == FogModes.Exp2)
            {
                shader.SetFogColor(lights.FogColor);
                shader.SetFogRange(new Vector2(lights.FogDensity, 0));
            }
        }
コード例 #6
0
 Shader GetPuffShader()
 {
     if (_puffringsh == null)
     {
         _puffringsh = ShaderCache.Get("nebula_extpuff.vs", "nebula_extpuff.frag");
         _ptex0      = _puffringsh.Shader.GetLocation("tex0");
         _pfogfactor = _puffringsh.Shader.GetLocation("FogFactor");
     }
     return(_puffringsh.Shader);
 }
コード例 #7
0
 public Billboards()
 {
     shaderBasic = ShaderCache.Get(
         "Billboard.vs",
         "Billboard.frag"
         );
     shaderBasic.Shader.SetInteger(shaderBasic.Shader.GetLocation("tex0"), 0);
     rendat   = new RenderData[MAX_BILLBOARDS];
     vboBasic = new VertexBuffer(typeof(BillboardVert), MAX_BILLBOARDS * 4, true);
     iboBasic = new ElementBuffer(MAX_BILLBOARDS * 6, true);
     vboBasic.SetElementBuffer(iboBasic);
 }
コード例 #8
0
ファイル: PolylineRender.cs プロジェクト: gp-alex/Librelancer
 public PolylineRender(CommandBuffer buffer)
 {
     if (shader == null)
     {
         shader = ShaderCache.Get(
             "Polyline.vs",
             "Billboard.frag"
             );
         shader.Shader.SetInteger(shader.Shader.GetLocation("tex0"), 0);
     }
     vbo         = new VertexBuffer(typeof(VertexPositionColorTexture), MAX_VERTICES, true);
     this.buffer = buffer;
 }
コード例 #9
0
 static ShaderVariables GetShader(IVertexType vertextype)
 {
     if (vertextype is VertexPositionNormalTexture)
     {
         if (sh_posNormalTexture == null)
         {
             sh_posNormalTexture = ShaderCache.Get(
                 "PositionTextureFlip.vs",
                 "DetailMap2Dm1Msk2PassMaterial.frag"
                 );
         }
         return(sh_posNormalTexture);
     }
     throw new NotImplementedException();
 }
コード例 #10
0
ファイル: BeamsBuffer.cs プロジェクト: sodomon2/Librelancer
        public BeamsBuffer()
        {
            var idx1 = ConstructIndices(spearIndices, MAX_BEAMS);

            bufferSpear = new VertexBuffer(typeof(VertexPositionColorTexture), MAX_BEAMS * 12, true);
            var el1 = new ElementBuffer(idx1.Length);

            el1.SetData(idx1);
            bufferSpear.SetElementBuffer(el1);
            var idx2 = ConstructIndices(boltIndices, MAX_BEAMS);

            bufferBolt = new VertexBuffer(typeof(VertexPositionColorTexture), MAX_BEAMS * 17, true);
            var el2 = new ElementBuffer(idx2.Length);

            el2.SetData(idx2);
            bufferBolt.SetElementBuffer(el2);
            shader = ShaderCache.Get("Projectile.vs", "Billboard.frag");
            shader.Shader.SetInteger(shader.Shader.GetLocation("tex0"), 0);
        }
コード例 #11
0
 static ShaderVariables GetShader(IVertexType vertexType)
 {
     if (vertexType is VertexPositionNormalTextureTwo)
     {
         if (sh_two == null)
         {
             sh_two = ShaderCache.Get("Basic_PositionNormalTextureTwo.vs", "NomadMaterial.frag");
         }
         return(sh_two);
     }
     else if (vertexType is VertexPositionNormalTexture)
     {
         if (sh_one == null)
         {
             sh_one = ShaderCache.Get("Nomad_PositionNormalTexture.vs", "NomadMaterial.frag");
         }
         return(sh_one);
     }
     throw new NotImplementedException(vertexType.GetType().Name);
 }
コード例 #12
0
        public override void Use(RenderState rstate, IVertexType vertextype, ref Lighting lights)
        {
            if (sh == null)
            {
                sh = ShaderCache.Get("Normals_PositionNormal.vs", "Normals.frag");
            }
            if (Camera == null)
            {
                return;
            }
            rstate.BlendMode = BlendMode.Opaque;
            sh.SetViewProjection(Camera);
            //Dt
            var normalMatrix = World;

            normalMatrix.Invert();
            normalMatrix.Transpose();
            sh.SetWorld(ref World);
            sh.SetNormalMatrix(ref normalMatrix);
            sh.UseProgram();
        }
コード例 #13
0
        public Billboards()
        {
            shaderBasic = ShaderCache.Get(
                "Billboard.vs",
                "Billboard.frag"
                );
            shaderBasic.Shader.SetInteger(shaderBasic.Shader.GetLocation("tex0"), 0);
            shaderRect = ShaderCache.Get(
                "Polyline.vs",
                "Billboard.frag"
                );
            shaderRect.Shader.SetInteger(shaderRect.Shader.GetLocation("tex0"), 0);
            verticesBasic = new BillboardVert[MAX_BILLBOARDS * 4];
            rendat        = new RenderData[MAX_BILLBOARDS];
            vboBasic      = new VertexBuffer(typeof(BillboardVert), MAX_BILLBOARDS * 4, true);
            iboBasic      = new ElementBuffer(MAX_BILLBOARDS * 6, true);
            vboBasic.SetElementBuffer(iboBasic);

            vboRect = new VertexBuffer(typeof(VertexPositionColorTexture), MAX_BILLBOARDS * 4, true);
            iboRect = new ElementBuffer(MAX_BILLBOARDS * 6, true);
            vboRect.SetElementBuffer(iboRect);
        }
コード例 #14
0
ファイル: RenderMaterial.cs プロジェクト: gp-alex/Librelancer
        public static void SetLights(ShaderVariables shader, ref Lighting lights)
        {
            bool hasSpotlight = HasSpotlight(ref lights);

            //shader.SetLightingEnabled(lights.Enabled ? 1 : 0);
            shader.SetLightParameters(new Vector4i(0, 0, 0, -1));
            if (!lights.Enabled)
            {
                return;
            }
            shader.SetAmbientColor(lights.Ambient);
            int count = 0;

            if (lights.Lights.SourceLighting != null)
            {
                for (int i = 0; i < lights.Lights.SourceLighting.Lights.Count; i++)
                {
                    if (lights.Lights.SourceEnabled[i])
                    {
                        SetLight(shader, hasSpotlight, count++, ref lights.Lights.SourceLighting.Lights[i].Light);
                    }
                }
            }
            if (lights.Lights.NebulaCount == 1)
            {
                SetLight(shader, hasSpotlight, count++, ref lights.Lights.Nebula0);
            }
            shader.SetLightParameters(new Vector4i(1, count, (int)lights.FogMode, lights.NumberOfTilesX));
            if (lights.FogMode == FogModes.Linear)
            {
                shader.SetFogColor(lights.FogColor);
                shader.SetFogRange(lights.FogRange);
            }
            else if (lights.FogMode == FogModes.Exp || lights.FogMode == FogModes.Exp2)
            {
                shader.SetFogColor(lights.FogColor);
                shader.SetFogRange(new Vector2(lights.FogDensity, 0));
            }
        }
コード例 #15
0
        public override void Use(RenderState rstate, IVertexType vertextype, ref Lighting lights)
        {
            rstate.DepthEnabled = true;
            rstate.BlendMode    = BlendMode.Opaque;

            ShaderVariables sh = GetShader(vertextype);

            sh.SetWorld(World);
            sh.SetViewProjection(Camera);
            sh.SetView(Camera);
            sh.SetAc(Ac);
            sh.SetDc(Dc);
            sh.SetTileRate(TileRate);
            sh.SetFlipU(FlipU);
            sh.SetFlipV(FlipV);
            sh.SetDtSampler(0);
            BindTexture(rstate, 0, DtSampler, 0, DtFlags);
            sh.SetDm1Sampler(1);
            BindTexture(rstate, 1, Dm1Sampler, 1, Dm1Flags, ResourceManager.GreyTextureName);
            SetLights(sh, ref lights);
            sh.UseProgram();
        }
コード例 #16
0
ファイル: SunRenderer.cs プロジェクト: sodomon2/Librelancer
        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 = ShaderCache.Get("sun.vs", "sun_radial.frag");
                radialTex0   = radialShader.Shader.GetLocation("tex0");
                radialSize   = radialShader.Shader.GetLocation("SizeMultiplier");
                radialAlpha  = radialShader.Shader.GetLocation("outerAlpha");
            }
            if (spineShader == null)
            {
                spineShader = ShaderCache.Get("sun.vs", "sun_spine.frag");
                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);
            }
        }
コード例 #17
0
ファイル: BasicMaterial.cs プロジェクト: sodomon2/Librelancer
        public override void Use(RenderState rstate, IVertexType vertextype, ref Lighting lights)
        {
            if (Camera == null)
            {
                return;
            }
            ShaderCaps caps = ShaderCaps.None;

            if (VertexLighting)
            {
                caps |= ShaderCaps.VertexLighting;
            }
            if (HasSpotlight(ref lights))
            {
                caps |= ShaderCaps.Spotlight;
            }
            if (EtEnabled)
            {
                caps |= ShaderCaps.EtEnabled;
            }
            if (Fade)
            {
                caps |= ShaderCaps.FadeEnabled;
            }
            var dxt1 = GetDxt1();

            if (dxt1)
            {
                caps |= ShaderCaps.AlphaTestEnabled;
                //Shitty way of dealing with alpha_mask
                //FL has a lot of DXT1 textures that aren't part of alpha_mask
                //so this brings overall performance down.
                //Don't change any of this stuff unless you can verify it works
                //in all places! (Check Li01 shipyards, Bw10 tradelanes)
            }
            var shader = GetShader(vertextype, caps);

            lastShader = shader;
            shader.SetWorld(World);
            shader.SetView(Camera);
            shader.SetViewProjection(Camera);
            //Dt
            shader.SetDtSampler(0);
            BindTexture(rstate, 0, DtSampler, 0, DtFlags, ResourceManager.WhiteTextureName);
            //Dc
            shader.SetDc(Dc);
            //Oc
            shader.SetOc(Oc);
            if (AlphaEnabled || Fade || OcEnabled || dxt1)
            {
                rstate.BlendMode = BlendMode.Normal;
            }
            else
            {
                rstate.BlendMode = BlendMode.Opaque; //TODO: Maybe I can just leave this out?
            }
            //Fade
            if (Fade)
            {
                shader.SetFadeRange(new Vector2(FadeNear, FadeFar));
            }
            //MaterialAnim
            if (MaterialAnim != null)
            {
                shader.SetMaterialAnim(new Vector4(
                                           MaterialAnim.UOffset,
                                           MaterialAnim.VOffset,
                                           MaterialAnim.UScale,
                                           MaterialAnim.VScale
                                           ));
            }
            else
            {
                shader.SetMaterialAnim(new Vector4(0, 0, 1, 1));
            }
            shader.SetFlipNormal(FlipNormals);
            if (Bones != null && vertextype is DfmVertex)
            {
                shader.Shader.UniformBlockBinding("Bones", 1);
                shader.SetSkinningEnabled(true);
                Bones.BindTo(1, BufferOffset, 200);
            }
            else
            {
                shader.SetSkinningEnabled(false);
            }
            //Ec
            shader.SetEc(Ec);
            //EtSampler
            if (EtEnabled)
            {
                shader.SetEtSampler(1);
                BindTexture(rstate, 1, EtSampler, 1, EtFlags, ResourceManager.NullTextureName);
            }
            //Set lights
            SetLights(shader, ref lights);
            shader.UseProgram();
        }
コード例 #18
0
        public static unsafe void SetLights(ShaderVariables shader, ref Lighting lighting)
        {
            if (!lighting.Enabled)
            {
                shader.SetLightParameters(new Vector4i(0, 0, 0, -1));
                return;
            }
            shader.SetAmbientColor(new Color4(lighting.Ambient, 1));
            bool hasSpotlight = HasSpotlight(ref lighting);
            //Prepare shader array (TODO: make faster?)
            PackedSpotlight *spots   = stackalloc PackedSpotlight[MAX_SET_LIGHTS];
            PackedLight *    pLights = stackalloc PackedLight[MAX_SET_LIGHTS];
            int lightCount           = 0;

            if (lighting.Lights.SourceLighting != null)
            {
                for (int i = 0; i < lighting.Lights.SourceLighting.Lights.Count; i++)
                {
                    if (lighting.Lights.SourceEnabled[i])
                    {
                        var   lt   = lighting.Lights.SourceLighting.Lights[i].Light;
                        float kind = 0;
                        if (lt.Kind == LightKind.Point || lt.Kind == LightKind.Spotlight)
                        {
                            kind = 1;
                        }
                        else if (lt.Kind == LightKind.PointAttenCurve)
                        {
                            kind = 2;
                        }
                        if (lightCount + 1 >= MAX_SET_LIGHTS)
                        {
                            throw new Exception("Internal too many lights");
                        }
                        pLights[lightCount].Position    = new Vector4(lt.Kind == LightKind.Directional ? lt.Direction : lt.Position, kind);
                        pLights[lightCount].ColorRange  = new Vector4(lt.Color.R, lt.Color.G, lt.Color.B, lt.Range);
                        pLights[lightCount].Attenuation = new Vector4(lt.Attenuation, 0);
                        if (hasSpotlight && lt.Kind == LightKind.Spotlight)
                        {
                            spots[lightCount].Direction       = new Vector4(lt.Direction, 1);
                            spots[lightCount].SpotlightParams = new Vector4(lt.Falloff, (float)(Math.Cos(lt.Theta / 2.0)), (float)(Math.Cos(lt.Phi / 2.0)), 1);
                        }

                        lightCount++;
                    }
                }
            }
            if (lighting.Lights.NebulaCount == 1)
            {
                if (lightCount + 1 >= MAX_SET_LIGHTS)
                {
                    throw new Exception("Internal too many lights");
                }
                var   lt   = lighting.Lights.Nebula0;
                float kind = 0;
                if (lt.Kind == LightKind.Point || lt.Kind == LightKind.Spotlight)
                {
                    kind = 1;
                }
                else if (lt.Kind == LightKind.PointAttenCurve)
                {
                    kind = 2;
                }
                if (lightCount + 1 >= MAX_SET_LIGHTS)
                {
                    throw new Exception("Internal too many lights");
                }
                pLights[lightCount].Position    = new Vector4(lt.Kind == LightKind.Directional ? lt.Direction : lt.Position, kind);
                pLights[lightCount].ColorRange  = new Vector4(lt.Color.R, lt.Color.G, lt.Color.B, lt.Range);
                pLights[lightCount].Attenuation = new Vector4(lt.Attenuation, 0);
                if (hasSpotlight && lt.Kind == LightKind.Spotlight)
                {
                    spots[lightCount].Direction       = new Vector4(lt.Direction, 1);
                    spots[lightCount].SpotlightParams = new Vector4(lt.Falloff, (float)(Math.Cos(lt.Theta / 2.0)), (float)(Math.Cos(lt.Phi / 2.0)), 1);
                }
                lightCount++;
            }
            //Upload!
            shader.SetLightData((Vector4 *)pLights, lightCount * 3);
            if (hasSpotlight)
            {
                shader.SetSpotlightData((Vector4 *)spots, lightCount * 2);
            }
            shader.SetLightParameters(new Vector4i(1, lightCount, (int)lighting.FogMode, lighting.NumberOfTilesX));
            if (lighting.FogMode == FogModes.Linear)
            {
                shader.SetFogColor(new Color4(lighting.FogColor, 1));
                shader.SetFogRange(lighting.FogRange);
            }
            else if (lighting.FogMode == FogModes.Exp || lighting.FogMode == FogModes.Exp2)
            {
                shader.SetFogColor(new Color4(lighting.FogColor, 1));
                shader.SetFogRange(new Vector2(lighting.FogRange.X, 0));
            }
        }
コード例 #19
0
 public PhysicsDebugRenderer()
 {
     shader     = ShaderCache.Get("physicsdebug.vs", "physicsdebug.frag");
     linebuffer = new VertexBuffer(typeof(VertexPositionColor), MAX_LINES * 2, true);
 }
コード例 #20
0
        public AsteroidFieldRenderer(AsteroidField field, SystemRenderer sys)
        {
            this.field = field;
            this.sys   = sys;
            //Set up renderDistSq
            float rdist = 0f;

            if (field.Zone.Shape is ZoneSphere)
            {
                rdist = ((ZoneSphere)field.Zone.Shape).Radius;
            }
            else if (field.Zone.Shape is ZoneEllipsoid)
            {
                var s = ((ZoneEllipsoid)field.Zone.Shape).Size;
                rdist = Math.Max(Math.Max(s.X, s.Y), s.Z);
            }
            else if (field.Zone.Shape is ZoneBox)
            {
                var s = ((ZoneEllipsoid)field.Zone.Shape).Size;
                rdist = Math.Max(Math.Max(s.X, s.Y), s.Z);
            }
            if (field.BillboardCount != -1)
            {
                astbillboards = new AsteroidBillboard[field.BillboardCount];
            }
            rdist                += field.FillDist;
            renderDistSq          = rdist * rdist;
            cubes                 = new CalculatedCube[1000];
            _asteroidsCalculation = CalculateAsteroids;
            if (field.Cube.Count > 0)
            {
                CreateBufferObject();
            }
            //Set up band
            if (field.Band == null)
            {
                return;
            }
            if (bandShader == null)
            {
                bandShader        = ShaderCache.Get("AsteroidBand.vs", "AsteroidBand.frag");
                _bsTexture        = bandShader.Shader.GetLocation("Texture");
                _bsCameraPosition = bandShader.Shader.GetLocation("CameraPosition");
                _bsColorShift     = bandShader.Shader.GetLocation("ColorShift");
                _bsTextureAspect  = bandShader.Shader.GetLocation("TextureAspect");
            }
            Vector3 sz;

            if (field.Zone.Shape is ZoneSphere)
            {
                sz = new Vector3(((ZoneSphere)field.Zone.Shape).Radius);
            }
            else if (field.Zone.Shape is ZoneEllipsoid)
            {
                sz = ((ZoneEllipsoid)field.Zone.Shape).Size;
            }
            else
            {
                return;
            }
            sz.Xz         -= new Vector2(field.Band.OffsetDistance);
            lightingRadius = Math.Max(sz.X, sz.Z);
            renderBand     = true;
            bandTransform  = (
                Matrix4.CreateScale(sz.X, field.Band.Height / 2, sz.Z) *
                field.Zone.RotationMatrix *
                Matrix4.CreateTranslation(field.Zone.Position)
                );
            bandCylinder = new OpenCylinder(SIDES);
            bandNormal   = bandTransform;
            bandNormal.Invert();
            bandNormal.Transpose();
        }