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 = sys.ResourceManager.GetOpenCylinder(SIDES); bandNormal = bandTransform; bandNormal.Invert(); bandNormal.Transpose(); }
public PhysicsDebugRenderer() { shader = ShaderCache.Get("physicsdebug.vs", "physicsdebug.frag"); linebuffer = new VertexBuffer(typeof(VertexPositionColor), MAX_LINES * 2, true); }
static ShaderVariables GetShader(IVertexType vertextype, ShaderCaps caps) { var i = caps.GetIndex(); if (vertextype is VertexPositionNormalTexture || vertextype is Utf.Dfm.DfmVertex) { if (sh_posNormalTexture[i] == null) { sh_posNormalTexture[i] = ShaderCache.Get( "Basic_PositionNormalTexture.vs", "Basic_Fragment.frag", caps ); } return(sh_posNormalTexture[i]); } if (vertextype is VertexPositionNormalTextureTwo) { if (sh_posNormalTextureTwo[i] == null) { sh_posNormalTextureTwo[i] = ShaderCache.Get( "Basic_PositionNormalTextureTwo.vs", "Basic_Fragment.frag", caps ); } return(sh_posNormalTextureTwo[i]); } if (vertextype is VertexPositionNormalColorTexture) { if (sh_posNormalColorTexture[i] == null) { sh_posNormalColorTexture[i] = ShaderCache.Get( "Basic_PositionNormalColorTexture.vs", "Basic_Fragment.frag", caps ); } return(sh_posNormalColorTexture[i]); } if (vertextype is VertexPositionTexture) { if (sh_posTexture[i] == null) { sh_posTexture[i] = ShaderCache.Get( "Basic_PositionTexture.vs", "Basic_Fragment.frag", caps ); } return(sh_posTexture[i]); } if (vertextype is VertexPosition) { if (sh_pos[i] == null) { sh_pos[i] = ShaderCache.Get( "Basic_PositionTexture.vs", "Basic_Fragment.frag", caps ); } return(sh_pos[i]); } if (vertextype is VertexPositionColor) { if (sh_posColor[i] == null) { sh_posColor[i] = ShaderCache.Get( "Basic_PositionColor.vs", "Basic_Fragment.frag", caps ); } return(sh_posColor[i]); } throw new NotImplementedException(vertextype.GetType().Name); }
public override void Draw(ICamera camera, CommandBuffer commands, SystemLighting lights, NebulaRenderer nr) { if (sysr == null || vertices == null) { return; } float z = RenderHelpers.GetZ(Matrix4.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, Matrix4.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, Matrix4.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, Matrix4.Identity, new RenderUserData() { Texture = spinetex }, sysr.StaticBillboards.VertexBuffer, PrimitiveTypes.TriangleList, idx, 2 * Sun.Spines.Count, true, SortLayers.SUN, z + 1112f); } }