本文整理汇总了C#中TerraViewer.RenderContext11.setRasterizerState方法的典型用法代码示例。如果您正苦于以下问题:C# RenderContext11.setRasterizerState方法的具体用法?C# RenderContext11.setRasterizerState怎么用?C# RenderContext11.setRasterizerState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TerraViewer.RenderContext11
的用法示例。
在下文中一共展示了RenderContext11.setRasterizerState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Draw
public static void Draw(RenderContext11 renderContext, PositionColoredTextured[] points, int count, Texture11 texture, SharpDX.Direct3D.PrimitiveTopology primitiveType, float opacity = 1.0f)
{
if (VertexBuffer == null)
{
VertexBuffer = new Buffer(renderContext.Device, System.Runtime.InteropServices.Marshal.SizeOf(points[0]) * 2500, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, System.Runtime.InteropServices.Marshal.SizeOf(points[0]));
VertexBufferBinding = new VertexBufferBinding(VertexBuffer, System.Runtime.InteropServices.Marshal.SizeOf((points[0])), 0);
}
renderContext.devContext.InputAssembler.PrimitiveTopology = primitiveType;
renderContext.BlendMode = BlendMode.Alpha;
renderContext.setRasterizerState(TriangleCullMode.Off);
SharpDX.Matrix mat = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
mat.Transpose();
WarpOutputShader.MatWVP = mat;
WarpOutputShader.Use(renderContext.devContext, texture != null, opacity);
renderContext.SetVertexBuffer(VertexBufferBinding);
DataBox box = renderContext.devContext.MapSubresource(VertexBuffer, 0, MapMode.WriteDiscard, MapFlags.None);
Utilities.Write(box.DataPointer, points, 0, count);
renderContext.devContext.UnmapSubresource(VertexBuffer, 0);
if (texture != null)
{
renderContext.devContext.PixelShader.SetShaderResource(0, texture.ResourceView);
}
else
{
renderContext.devContext.PixelShader.SetShaderResource(0, null);
}
renderContext.devContext.Draw(count, 0);
}
示例2: DrawLabels
public void DrawLabels(RenderContext11 renderContext)
{
if (positions.Count < 1)
{
return;
}
InitLabelBuffer();
renderContext.SetVertexBuffer(labelBuffer);
renderContext.BlendMode = BlendMode.Alpha;
renderContext.DepthStencilMode = DepthStencilMode.Off;
renderContext.setRasterizerState(TriangleCullMode.Off);
var mvp = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
mvp.Transpose();
PointSpriteShader11.WVPMatrix = mvp;
PointSpriteShader11.Color = SharpDX.Color.White;
var adjustedScale = .01f; // (float)(1 / (Earth3d.MainWindow.ZoomFactor / 360));
PointSpriteShader11.ViewportScale = new Vector2((2.0f / renderContext.ViewPort.Width) * adjustedScale, (2.0f / renderContext.ViewPort.Height) * adjustedScale);
PointSpriteShader11.PointScaleFactors = new Vector3(0.0f, 0.0f, 10000.0f);
PointSpriteShader11.Use(renderContext.Device.ImmediateContext);
renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, texture.ResourceView);
renderContext.devContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.PointList;
renderContext.devContext.Draw(labelBuffer.Count, 0);
renderContext.Device.ImmediateContext.GeometryShader.Set(null);
}
示例3: Draw
public override bool Draw(RenderContext11 renderContext, float opacity, bool flat)
{
if (bufferIsFlat != flat)
{
CleanUp();
bufferIsFlat = flat;
}
if (!CleanAndReady)
{
PrepVertexBuffer( opacity);
}
var oldWorld = renderContext.World;
if (astronomical && !bufferIsFlat)
{
var ecliptic = Coordinates.MeanObliquityOfEcliptic(SpaceTimeController.JNow) / 180.0 * Math.PI;
renderContext.World = Matrix3d.RotationX(ecliptic) * renderContext.World;
}
if (triangleList2d != null)
{
triangleList2d.Decay = decay;
triangleList2d.Sky = Astronomical;
triangleList2d.TimeSeries = timeSeries;
triangleList2d.Draw(renderContext, opacity * Opacity, TriangleList.CullMode.CounterClockwise);
}
if (triangleList != null)
{
triangleList.Decay = decay;
triangleList.Sky = Astronomical;
triangleList.TimeSeries = timeSeries;
triangleList.Draw(renderContext, opacity * Opacity, TriangleList.CullMode.CounterClockwise);
}
if (lineList != null)
{
lineList.Sky = Astronomical;
lineList.Decay = decay;
lineList.TimeSeries = timeSeries;
lineList.DrawLines(renderContext, opacity * Opacity);
}
if (lineList2d != null)
{
lineList2d.Sky = !Astronomical;
lineList2d.Decay = decay;
lineList2d.TimeSeries = timeSeries;
lineList2d.ShowFarSide = ShowFarSide;
lineList2d.DrawLines(renderContext, opacity * Opacity);
}
if (textBatch != null)
{
var mode = renderContext.DepthStencilMode;
renderContext.DepthStencilMode = DepthStencilMode.Off;
textBatch.Draw(renderContext, 1, Color.White);
renderContext.DepthStencilMode = mode;
}
if (astronomical && !bufferIsFlat)
{
renderContext.DepthStencilMode = DepthStencilMode.ZReadWrite;
}
else
{
renderContext.DepthStencilMode = DepthStencilMode.Off;
}
var baseDate = new DateTime(2010, 1, 1, 12, 00, 00);
renderContext.setRasterizerState(TriangleCullMode.Off);
var cam = Vector3d.TransformCoordinate(renderContext.CameraPosition, Matrix3d.Invert(renderContext.World)).Vector311;
var adjustedScale = scaleFactor;
if (flat && astronomical && (markerScale == MarkerScales.World))
{
adjustedScale = (float)(scaleFactor / (Earth3d.MainWindow.ZoomFactor / 360));
}
var matrixWVP = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
matrixWVP.Transpose();
switch (plotType)
{
default:
case PlotTypes.Gaussian:
renderContext.BlendMode = BlendMode.Additive;
renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, Grids.StarProfile.ResourceView);
break;
case PlotTypes.Circle:
renderContext.BlendMode = BlendMode.Alpha;
renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, CircleTexture.ResourceView);
break;
case PlotTypes.Point:
renderContext.BlendMode = BlendMode.Alpha;
//.........这里部分代码省略.........
示例4: Draw3D
public override bool Draw3D(RenderContext11 renderContext, float opacity, Tile parent)
{
InViewFrustum = true;
RenderedGeneration = CurrentRenderGeneration;
if (!ReadyToRender)
{
TileCache.AddTileToQueue(this);
return false;
}
InViewFrustum = true;
if (starVertexBuffer == null)
{
starProfile = Texture11.FromBitmap( Resources.StarProfile);
var count = stars.Count;
var index = 0;
starCount = count;
starVertexBuffer = new PositionColorSizeVertexBuffer11(count, RenderContext11.PrepDevice);
var points = (PositionColorSize[])starVertexBuffer.Lock(0, 0); // Lock the buffer (which will return our structs)
foreach (var star in stars)
{
var pos = Coordinates.RADecTo3d(star.RA + 12, star.Dec, 1f);
points[index].Position = pos.Vector3;
points[index].Color = star.Col;
var radDec = (.5) / Math.Pow(1.6, star.Magnitude);
points[index].size = (float)radDec;
index++;
}
starVertexBuffer.Unlock();
}
renderContext.SetVertexBuffer(starVertexBuffer);
renderContext.BlendMode = BlendMode.Additive;
renderContext.DepthStencilMode = DepthStencilMode.Off;
renderContext.setRasterizerState(TriangleCullMode.Off);
var mvp = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
mvp.Transpose();
PointSpriteShader11.WVPMatrix = mvp;
PointSpriteShader11.Color = Color.White;
var adjustedScale = (float)(1 / (Earth3d.MainWindow.ZoomFactor / 360));
PointSpriteShader11.ViewportScale = new Vector2((2.0f / renderContext.ViewPort.Width) * adjustedScale, (2.0f / renderContext.ViewPort.Height) * adjustedScale);
PointSpriteShader11.PointScaleFactors = new Vector3(0.0f, 0.0f, 10000.0f);
PointSpriteShader11.Use(renderContext.Device.ImmediateContext);
renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, starProfile.ResourceView);
renderContext.devContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.PointList;
renderContext.devContext.Draw(starCount, 0);
renderContext.Device.ImmediateContext.GeometryShader.Set(null);
// Reset blend mode so we don't mess up subsequent sky layer rendering
renderContext.BlendMode = BlendMode.Alpha;
return true;
}
示例5: Render
//.........这里部分代码省略.........
double scaleFactor = Math.Sqrt(worldView.M11 * worldView.M11 + worldView.M22 * worldView.M22 + worldView.M33 * worldView.M33) / unitScale;
double dist = v.Length();
double radius = scaleFactor;
// Calculate pixelsPerUnit which is the number of pixels covered
// by an object 1 AU at the distance of the planet center from
// the camera. This calculation works regardless of the projection
// type.
int viewportHeight = (int)renderContext.ViewPort.Height;
double p11 = renderContext.Projection.M11;
double p34 = renderContext.Projection.M34;
double p44 = renderContext.Projection.M44;
double w = Math.Abs(p34) * dist + p44;
float pixelsPerUnit = (float)(p11 / w) * viewportHeight;
float radiusInPixels = (float)(radius * pixelsPerUnit);
if (radiusInPixels < 0.5f)
{
// Too small to be visible; skip rendering
return;
}
// These colors can be modified by shadows, distance from planet, etc. Restore
// the original values after rendering.
var savedSunlightColor = renderContext.SunlightColor;
var savedReflectedColor = renderContext.ReflectedLightColor;
var savedHemiColor = renderContext.HemisphereLightColor;
if (Properties.Settings.Default.SolarSystemLighting)
{
SetupLighting(renderContext);
renderContext.AmbientLightColor = System.Drawing.Color.FromArgb(11, 11, 11);
}
else
{
// No lighting: set ambient light to white and turn off all other light sources
renderContext.SunlightColor = System.Drawing.Color.Black;
renderContext.ReflectedLightColor = System.Drawing.Color.Black;
renderContext.HemisphereLightColor = System.Drawing.Color.Black;
renderContext.AmbientLightColor = System.Drawing.Color.White;
}
SharpDX.Direct3D11.Device device = renderContext.Device;
if (mesh == null)
{
return;
}
//Object3dLayer.sketch.DrawLines(renderContext, 1.0f, System.Drawing.Color.Red);
renderContext.DepthStencilMode = DepthStencilMode.ZReadWrite;
renderContext.BlendMode = BlendMode.Alpha;
int count = meshMaterials.Count;
mesh.beginDrawing(renderContext);
if (count > 0)
{
for (int i = 0; i < meshMaterials.Count; i++)
{
if (meshMaterials[i].Default)
{
Material mat = meshMaterials[i];
mat.Diffuse = Color;
mat.Ambient = Color;
meshMaterials[i] = mat;
}
// Set the material and texture for this subset
renderContext.SetMaterial(meshMaterials[i], meshTextures[i], meshSpecularTextures[i], meshNormalMaps[i], opacity);
renderContext.PreDraw();
renderContext.setSamplerState(0, renderContext.WrapSampler);
mesh.drawSubset(renderContext, i);
}
}
else
{
renderContext.PreDraw();
for (int i = 0; i < meshTextures.Count; i++)
{
var key = new PlanetShaderKey(PlanetSurfaceStyle.Diffuse, false, 0);
renderContext.SetupPlanetSurfaceEffect(key, 1.0f);
if (meshTextures[i] != null)
{
renderContext.MainTexture = meshTextures[i];
}
renderContext.PreDraw();
mesh.drawSubset(renderContext, i);
}
}
renderContext.setSamplerState(0, renderContext.ClampSampler);
renderContext.setRasterizerState(TriangleCullMode.CullClockwise);
renderContext.World = oldWorld;
renderContext.SunlightColor = savedSunlightColor;
renderContext.ReflectedLightColor = savedReflectedColor;
renderContext.HemisphereLightColor = savedHemiColor;
renderContext.AmbientLightColor = System.Drawing.Color.Black;
}
示例6: Draw
public override bool Draw(RenderContext11 renderContext, float opacity, bool flat)
{
Matrix3d oldWorld = renderContext.World;
Matrix3d rotation = Matrix3d.RotationZ(-roll / 180f * Math.PI) * Matrix3d.RotationX(-pitch / 180f * Math.PI) * Matrix3d.RotationY(heading / 180f * Math.PI);
renderContext.World = rotation * Matrix3d.Scaling(scale.X, scale.Y, scale.Z) * Matrix3d.Translation(translate) * oldWorld;
renderContext.TwoSidedLighting = TwoSidedGeometry;
renderContext.setRasterizerState(TwoSidedGeometry ? TriangleCullMode.Off : TriangleCullMode.CullCounterClockwise);
if (lightID > 0)
{
//draw light
// Planets.DrawPointPlanet(renderContext, new Vector3d(), 1, Color, false, 1.0f);
}
else
{
if (object3d != null)
{
object3d.Color = Color;
object3d.Render(renderContext, opacity * Opacity);
}
}
renderContext.setRasterizerState(TriangleCullMode.CullCounterClockwise);
renderContext.TwoSidedLighting = false;
if (showEditUi)
{
if (lightID > 0)
{
//draw light
Planets.DrawPointPlanet(renderContext, new Vector3d(), 1, Color, false, 1.0f);
}
DepthStencilMode oldDepthMode = renderContext.DepthStencilMode = DepthStencilMode.Off;
renderContext.World = Matrix3d.Translation(translate) * oldWorld;
Matrix3d wvp = renderContext.World * renderContext.View * renderContext.Projection;
Vector3d vc = new Vector3d(0, 0, 0);
Vector3d vc1 = new Vector3d(.001, 0, 0);
Vector3d vc2 = new Vector3d(0, .001, 0);
Vector3d vc3 = new Vector3d(0, 0, .001);
Vector3d vs = Vector3d.TransformCoordinate(vc, wvp);
Vector3d vs1 = Vector3d.TransformCoordinate(vc1, wvp);
Vector3d vs2 = Vector3d.TransformCoordinate(vc2, wvp);
Vector3d vs3 = Vector3d.TransformCoordinate(vc3, wvp);
Vector2d vsa = new Vector2d(vs.X, vs.Y);
Vector2d vsa1 = new Vector2d(vs1.X, vs1.Y) - vsa;
Vector2d vsa2 = new Vector2d(vs2.X, vs2.Y) - vsa;
Vector2d vsa3 = new Vector2d(vs3.X, vs3.Y) - vsa;
uiScale = .0003 / Math.Sqrt((vsa1.Length * vsa1.Length + vsa2.Length * vsa2.Length + vsa3.Length * vsa3.Length));
Matrix3d matUIScale = Matrix3d.Scaling(uiScale, uiScale, uiScale);
renderContext.World = matUIScale * renderContext.World;
wvp = renderContext.World * renderContext.View * renderContext.Projection;
vc1 = new Vector3d(.9, 0, 0);
vc2 = new Vector3d(0, .9, 0);
vc3 = new Vector3d(0, 0, .9);
vs = Vector3d.TransformCoordinate(vc, wvp);
vs1 = Vector3d.TransformCoordinate(vc1, wvp);
vs2 = Vector3d.TransformCoordinate(vc2, wvp);
vs3 = Vector3d.TransformCoordinate(vc3, wvp);
double h = renderContext.ViewPort.Height;
double w = renderContext.ViewPort.Width;
xHandle = new Vector2d((vs1.X + 1) * w / 2, h - ((vs1.Y + 1) * h / 2));
yHandle = new Vector2d((vs2.X + 1) * w / 2, h - ((vs2.Y + 1) * h / 2));
zHandle = new Vector2d((vs3.X + 1) * w / 2, h - ((vs3.Y + 1) * h / 2));
// draw UI
if (TranslateUI == null)
{
InitTranslateUI();
}
bool showTranslate = Control.ModifierKeys != Keys.Control && Control.ModifierKeys != Keys.Shift;
bool showRotate = Control.ModifierKeys == Keys.Control;
bool showScale = Control.ModifierKeys == Keys.Shift;
if (showTranslate)
{
TranslateUILines.DrawLines(renderContext, 1.0f);
TranslateUI.Draw(renderContext, 1.0f, TriangleList.CullMode.Clockwise);
}
else
{
if (showScale)
{
TranslateUILines.DrawLines(renderContext, 1.0f);
ScaleUI.Draw(renderContext, 1.0f, TriangleList.CullMode.Clockwise);
}
//.........这里部分代码省略.........
示例7: DrawRings
// Various input layouts used in 3D solar system mode
// TODO Replace with an input layout cache
static void DrawRings(RenderContext11 renderContext)
{
renderContext.setRasterizerState(TriangleCullMode.Off);
var ringsKey = new PlanetShaderKey(PlanetSurfaceStyle.PlanetaryRings, false, 0);
SetupPlanetSurfaceEffect(renderContext, ringsKey, 1.0f);
renderContext.Shader.MainTexture = RingsMap.ResourceView;
renderContext.devContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleStrip;
renderContext.Device.ImmediateContext.InputAssembler.InputLayout = renderContext.Shader.inputLayout(PlanetShader11.StandardVertexLayout.PositionNormalTex);
renderContext.PreDraw();
renderContext.SetVertexBuffer(ringsVertexBuffer);
renderContext.devContext.Draw((triangleCountRings+2), 0);
renderContext.setRasterizerState(TriangleCullMode.CullCounterClockwise);
}
示例8: Draw2D
public static void Draw2D(RenderContext11 renderContext, Texture11 srcTexture, SizeF size, PointF rotationCenter, float rotationAngle, PointF position, System.Drawing.Color color)
{
cornerPoints[0].Position = MakePosition(position.X, position.Y, -size.Width / 2, -size.Height / 2, rotationAngle).Vector4;
cornerPoints[0].Tu = 0;
cornerPoints[0].Tv = 0;
cornerPoints[0].Color = color;
cornerPoints[1].Position = MakePosition(position.X, position.Y, size.Width / 2, -size.Height / 2, rotationAngle).Vector4;
cornerPoints[1].Tu = 1;
cornerPoints[1].Tv = 0;
cornerPoints[1].Color = color;
cornerPoints[2].Position = MakePosition(position.X, position.Y, -size.Width / 2, size.Height / 2, rotationAngle).Vector4;
cornerPoints[2].Tu = 0;
cornerPoints[2].Tv = 1;
cornerPoints[2].Color = color;
cornerPoints[3].Position = MakePosition(position.X, position.Y, size.Width / 2, size.Height / 2, rotationAngle).Vector4;
cornerPoints[3].Tu = 1;
cornerPoints[3].Tv = 1;
cornerPoints[3].Color = color;
renderContext.setRasterizerState(TriangleCullMode.Off);
renderContext.DepthStencilMode = DepthStencilMode.Off;
DrawForScreen(renderContext, cornerPoints, 4, srcTexture, SharpDX.Direct3D.PrimitiveTopology.TriangleStrip);
}
示例9: DrawMPC3D
// ** Begin
public static void DrawMPC3D(RenderContext11 renderContext, float opacity, Vector3d centerPoint)
{
var zoom = Earth3d.MainWindow.ZoomFactor;
var distAlpha = ((Math.Log(Math.Max(1, zoom), 4)) - 15.5) * 90;
var alpha = Math.Min(255, Math.Max(0, (int)distAlpha));
if (alpha > 254)
{
return;
}
if (mpcVertexBuffer == null)
{
for (var i = 0; i < 7; i++)
{
mpcBlendStates[i] = new BlendState(false, 1000, 0);
}
if (!initBegun)
{
var initDelegate = new MethodInvoker(StartInit);
initDelegate.BeginInvoke(null, null);
initBegun = true;
}
return;
}
renderContext.DepthStencilMode = DepthStencilMode.Off;
renderContext.setRasterizerState(TriangleCullMode.Off);
var offset = Matrix3d.Translation(-centerPoint);
var world = renderContext.World * offset;
var matrixWVP = (world * renderContext.View * renderContext.Projection).Matrix11;
matrixWVP.Transpose();
var cam = Vector3.TransformCoordinate(renderContext.CameraPosition.Vector311, Matrix.Invert(renderContext.World.Matrix11));
renderContext.Device.ImmediateContext.PixelShader.SetShaderResource(0, Grids.StarProfile.ResourceView);
renderContext.BlendMode = BlendMode.Additive;
if (mpcVertexBuffer != null)
{
for (var i = 0; i < 7; i++)
{
mpcBlendStates[i].TargetState = ((Properties.Settings.Default.MinorPlanetsFilter & (int)Math.Pow(2, i)) != 0);
if (mpcBlendStates[i].State)
{
if (mpcVertexBuffer[i].Downlevel)
{
DownlevelKeplerPointSpriteShader11.Constants.JNow = (float)(SpaceTimeController.JNow - KeplerVertex.baseDate);
DownlevelKeplerPointSpriteShader11.Constants.Opacity = opacity * mpcBlendStates[i].Opacity;
DownlevelKeplerPointSpriteShader11.Constants.MM = 0;
DownlevelKeplerPointSpriteShader11.Constants.WorldViewProjection = matrixWVP;
DownlevelKeplerPointSpriteShader11.Constants.Scale = new Vector2(100f, 100f);
DownlevelKeplerPointSpriteShader11.Constants.ViewportScale = new Vector2(2f / renderContext.ViewPort.Width, 2f / renderContext.ViewPort.Height);
DownlevelKeplerPointSpriteShader11.Constants.CameraPosition = new Vector4(cam, 1);
DownlevelKeplerPointSpriteShader11.Use(renderContext.devContext, mpcVertexBuffer[i].Instanced);
}
else
{
KeplerPointSpriteShader11.Constants.JNow = (float)(SpaceTimeController.JNow - KeplerVertex.baseDate);
KeplerPointSpriteShader11.Constants.Opacity = opacity * mpcBlendStates[i].Opacity;
KeplerPointSpriteShader11.Constants.MM = 0;
KeplerPointSpriteShader11.Constants.WorldViewProjection = matrixWVP;
KeplerPointSpriteShader11.Constants.Scale = new Vector2(100f, 100f);
KeplerPointSpriteShader11.Constants.ViewportScale = new Vector2(2f / renderContext.ViewPort.Width, 2 / renderContext.ViewPort.Height);
KeplerPointSpriteShader11.Constants.CameraPosition = new Vector4(cam, 1);
KeplerPointSpriteShader11.Use(renderContext.devContext);
}
mpcVertexBuffer[i].Draw(renderContext, mpcVertexBuffer[i].Count, null, opacity);
}
}
}
renderContext.BlendMode = BlendMode.Alpha;
renderContext.Device.ImmediateContext.GeometryShader.Set(null);
}
示例10: Draw3D
public virtual bool Draw3D(RenderContext11 renderContext, bool showOnlySelected, float opacity, string focusConsteallation, bool reverse)
{
constToDraw = focusConsteallation;
Lineset lsSelected = null;
foreach (Lineset ls in this.lines)
{
bool enabled = boundry ? Settings.Active.ConstellationBoundariesFilter.IsSet(ls.Name) : Settings.Active.ConstellationFiguresFilter.IsSet(ls.Name);
if (enabled)
{
if (constToDraw == ls.Name && boundry)
{
lsSelected = ls;
}
else if (!showOnlySelected || !boundry)
{
DrawSingleConstellation(renderContext, ls, opacity, reverse, true);
}
}
}
if (lsSelected != null)
{
DrawSingleConstellation(renderContext, lsSelected, opacity, reverse, true);
}
renderContext.setRasterizerState(TriangleCullMode.Off, true);
return true;
}
示例11: DrawForScreen
public static void DrawForScreen(RenderContext11 renderContext, PositionColoredTextured[] points, int count, Texture11 texture, PrimitiveTopology primitiveType)
{
if (VertexBuffer == null)
{
VertexBuffer = new Buffer(renderContext.Device, Marshal.SizeOf(points[0]) * 2500, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, Marshal.SizeOf(points[0]));
VertexBufferBinding = new VertexBufferBinding(VertexBuffer, Marshal.SizeOf((points[0])), 0);
}
renderContext.devContext.InputAssembler.PrimitiveTopology = primitiveType;
renderContext.BlendMode = BlendMode.Alpha;
renderContext.setRasterizerState(TriangleCullMode.Off);
var mat =
Matrix.Translation(-renderContext.ViewPort.Width / 2, -renderContext.ViewPort.Height / 2, 0) *
Matrix.Scaling(1f, -1f, 1f)
* Matrix.OrthoLH(renderContext.ViewPort.Width, renderContext.ViewPort.Height, 1, -1);
mat.Transpose();
WarpOutputShader.MatWVP = mat;
WarpOutputShader.Use(renderContext.devContext, texture != null);
renderContext.SetVertexBuffer(VertexBufferBinding);
var box = renderContext.devContext.MapSubresource(VertexBuffer, 0, MapMode.WriteDiscard, MapFlags.None);
Utilities.Write(box.DataPointer, points, 0, count);
renderContext.devContext.UnmapSubresource(VertexBuffer, 0);
if (texture != null)
{
renderContext.devContext.PixelShader.SetShaderResource(0, texture.ResourceView);
}
else
{
renderContext.devContext.PixelShader.SetShaderResource(0, null);
}
renderContext.devContext.Draw(count, 0);
}
示例12: DrawPointPlanet
public static void DrawPointPlanet(RenderContext11 renderContext, Vector3d location, float size, Color color, bool zOrder, float opacity)
{
var vertices = new PositionColorSize[1];
vertices[0].Position = location.Vector311;
vertices[0].size = size * 200;
vertices[0].Color = color;
if (planetsPointSet == null)
{
planetsPointSet = new PointSpriteSet(renderContext.Device, vertices);
planetsPointSet.PointScaleFactors = new Vector3(1.0f, 0.0f, 0.0f);
}
else
{
planetsPointSet.updateVertexBuffer(vertices);
}
renderContext.BlendMode = BlendMode.Additive;
renderContext.DepthStencilMode = zOrder ? DepthStencilMode.ZReadOnly : DepthStencilMode.Off;
renderContext.setRasterizerState(TriangleCullMode.Off);
planetsPointSet.Draw(renderContext, 1, Grids.StarProfile, opacity);
renderContext.DepthStencilMode = DepthStencilMode.ZReadWrite;
renderContext.BlendMode = BlendMode.Alpha;
}
示例13: DrawPlanets3D
public static bool DrawPlanets3D(RenderContext11 renderContext, float opacity, Vector3d centerPoint)
{
InitPlanetResources();
renderContext.LightingEnabled = Settings.Active.SolarSystemLighting;
if (!Properties.Settings.Default.SolarSystemPlanets.TargetState)
{
return true;
}
drawOrder.Clear();
var camera = new Vector3d(renderContext.CameraPosition);
for (var planetId = 0; planetId < 14; planetId++)
{
if (!planetLocations[planetId].Eclipsed)
{
var distVector = camera - (planet3dLocations[planetId] - centerPoint);
if (!drawOrder.ContainsKey(-distVector.Length()))
{
drawOrder.Add(-distVector.Length(), planetId);
}
}
}
var distVectorEarth = camera - (planet3dLocations[(int)SolarSystemObjects.Earth] - centerPoint);
if (!drawOrder.ContainsKey(-distVectorEarth.Length()))
{
drawOrder.Add(-distVectorEarth.Length(), (int)SolarSystemObjects.Earth);
}
renderContext.DepthStencilMode = DepthStencilMode.ZReadWrite;
renderContext.setRasterizerState(TriangleCullMode.CullCounterClockwise);
foreach (var planetId in drawOrder.Values)
{
DrawPlanet3d(renderContext, planetId, centerPoint, opacity);
}
var distss = UiTools.SolarSystemToMeters(Earth3d.MainWindow.SolarSystemCameraDistance);
//double val1 = Math.Log(200000000, 10)-7.3;
//double val2 = Math.Log(20000000, 10)-7.3;
var moonFade = (float)Math.Min(1, Math.Max(Math.Log(distss, 10) - 7.3, 0));
var fade = (float)Math.Min(1, Math.Max(Math.Log(distss, 10) - 8.6, 0));
if (Properties.Settings.Default.SolarSystemOrbits.State ) // && fade > 0)
{
renderContext.DepthStencilMode = DepthStencilMode.ZReadOnly;
renderContext.BlendMode = BlendMode.Alpha;
renderContext.setRasterizerState(TriangleCullMode.Off, false);
var orbitColor = Color.FromArgb((int)(Properties.Settings.Default.SolarSystemOrbits.Opacity * 255), Properties.Settings.Default.SolarSystemOrbitColor).ToArgb();
for (var ii = 1; ii < 10; ii++)
{
var id = ii;
if (ii == 9)
{
id = 19;
}
var angle = Math.Atan2(planet3dLocations[id].Z, planet3dLocations[id].X);
orbitBlendStates[id].TargetState = (Properties.Settings.Default.PlanetOrbitsFilter & (int)Math.Pow(2, id)) != 0;
if (orbitBlendStates[id].State)
{
if (Properties.Settings.Default.UsePlanetColorsForOrbits)
{
DrawSingleOrbit(renderContext, UiTools.GetTransparentColor(planetColors[id].ToArgb(), Properties.Settings.Default.SolarSystemOrbits.Opacity * fade * orbitBlendStates[id].Opacity), id, centerPoint, angle, planet3dLocations[id]);
}
else
{
DrawSingleOrbit(renderContext, orbitColor, id, centerPoint, angle, planet3dLocations[id]);
}
}
}
// Show the orbit of the Moon
orbitBlendStates[(int)SolarSystemObjects.Moon].TargetState = (Properties.Settings.Default.PlanetOrbitsFilter & (int)Math.Pow(2, (int)SolarSystemObjects.Moon)) != 0;
if (orbitBlendStates[(int)SolarSystemObjects.Moon].State)
{
var id = (int)SolarSystemObjects.Moon;
DrawSingleOrbit(renderContext, UiTools.GetTransparentColor(planetColors[id].ToArgb(), Properties.Settings.Default.SolarSystemOrbits.Opacity * moonFade * orbitBlendStates[(int)SolarSystemObjects.Moon].Opacity), id, centerPoint, 0.0, planet3dLocations[id]);
}
// Show orbits of the Galilean satellites
{
var deltaT = 1.0 / 1440.0 * 0.1;
// Compute the positions of the Galilean satellites at two times; we need
// the second in order to estimate the velocity.
var gal0 = CAAGalileanMoons.Calculate(jNow);
var gal1 = CAAGalileanMoons.Calculate(jNow - deltaT);
//.........这里部分代码省略.........
示例14: DrawSphere
static void DrawSphere(RenderContext11 renderContext, Texture11 texture, int planetID, int sphereIndex, bool noMultires, bool drawLayers, PlanetShaderKey shaderKey)
{
var useMultires = Settings.Active.SolarSystemMultiRes && !noMultires;
// Let an override layer take the place of the standard layer
IImageSet defaultLayer = null;
var defaultLayerColor = Color.White;
if (drawLayers)
{
var referenceFrameName = Enum.GetName(typeof(SolarSystemObjects), (SolarSystemObjects)planetID);
foreach (var layer in LayerManager.AllMaps[referenceFrameName].Layers)
{
if (layer.Enabled && layer is ImageSetLayer)
{
if (((ImageSetLayer)layer).OverrideDefaultLayer)
{
defaultLayer = ((ImageSetLayer)layer).ImageSet;
defaultLayerColor = layer.Color;
useMultires = true;
break;
}
}
}
}
if (useMultires)
{
renderContext.DepthStencilMode = DepthStencilMode.ZReadWrite;
if (sphereIndex < 4)
{
IImageSet planet = null;
if (defaultLayer != null)
{
planet = defaultLayer;
}
else
{
var planetName = GetNameFrom3dId(planetID);
var imageSetName = planetName == "Mars" ? "Visible Imagery" : planetName;
planet = Earth3d.MainWindow.GetImagesetByName(imageSetName);
}
if (planet != null)
{
var normColor = new Vector4(defaultLayerColor.R, defaultLayerColor.G, defaultLayerColor.B, defaultLayerColor.A) * (1.0f / 255.0f);
if (RenderContext11.sRGB)
{
normColor.X = (float) Math.Pow(normColor.X, 2.2);
normColor.Y = (float)Math.Pow(normColor.Y, 2.2);
normColor.Z = (float)Math.Pow(normColor.Z, 2.2);
}
renderContext.Shader.DiffuseColor = normColor;
renderContext.setRasterizerState(TriangleCullMode.CullClockwise);
Earth3d.MainWindow.DrawTiledSphere(planet, 100, Color.White);
if (planetID == (int)SolarSystemObjects.Earth && Settings.Active.ShowClouds)
{
if (CloudTexture != null)
{
var cloudShaderKey = new PlanetShaderKey(PlanetSurfaceStyle.Diffuse, Settings.Active.ShowEarthSky, 0);
cloudShaderKey.eclipseShadowCount = shaderKey.eclipseShadowCount;
cloudShaderKey.HasAtmosphere = shaderKey.HasAtmosphere;
if (!Settings.Active.SolarSystemLighting)
{
cloudShaderKey.style = PlanetSurfaceStyle.Emissive;
}
SetupPlanetSurfaceEffect(renderContext, cloudShaderKey, 1.0f);
SetAtmosphereConstants(renderContext, planetID, 1.0f, CalcSkyGeometryHeight(planetID));
renderContext.MainTexture = CloudTexture;
var savedWorld = renderContext.World;
var cloudScale = 1.0 + (EarthCloudHeightMeters) / 6378100.0;
renderContext.World = Matrix3d.Scaling(cloudScale, cloudScale, cloudScale) * renderContext.World;
renderContext.setRasterizerState(TriangleCullMode.CullCounterClockwise);
renderContext.DepthStencilMode = DepthStencilMode.Off;
renderContext.BlendMode = BlendMode.Alpha;
DrawFixedResolutionSphere(renderContext, sphereIndex);
renderContext.World = savedWorld;
renderContext.DepthStencilMode = DepthStencilMode.ZReadWrite;
renderContext.BlendMode = BlendMode.None;
}
}
return;
}
}
}
renderContext.MainTexture = texture;
renderContext.Device.ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
//.........这里部分代码省略.........
示例15: DrawLines
public void DrawLines(RenderContext11 renderContext, float opacity, Color color)
{
if (linePoints.Count < 2)
{
return;
}
InitLineBuffer();
Matrix3d savedWorld = renderContext.World;
Matrix3d savedView = renderContext.View;
if (localCenter != Vector3d.Empty)
{
usingLocalCenter = true;
Vector3d temp = localCenter;
if (UseNonRotatingFrame)
{
renderContext.World = Matrix3d.Translation(temp) * renderContext.WorldBaseNonRotating * Matrix3d.Translation(-renderContext.CameraPosition);
}
else
{
renderContext.World = Matrix3d.Translation(temp) * renderContext.WorldBase * Matrix3d.Translation(-renderContext.CameraPosition);
}
renderContext.View = Matrix3d.Translation(renderContext.CameraPosition) * renderContext.ViewBase;
}
renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.LineList;
Color col = Color.FromArgb((int)(color.A * opacity), (int)(color.R * opacity), (int)(color.G * opacity), (int)(color.B * opacity));
SimpleLineShader11.Color = col;
SharpDX.Matrix mat = (renderContext.World * renderContext.View * renderContext.Projection).Matrix11;
mat.Transpose();
SimpleLineShader11.WVPMatrix = mat;
SimpleLineShader11.CameraPosition = Vector3d.TransformCoordinate(renderContext.CameraPosition, Matrix3d.Invert(renderContext.World)).Vector3;
SimpleLineShader11.ShowFarSide = true;
SimpleLineShader11.Sky = Sky;
renderContext.setRasterizerState(TriangleCullMode.CullClockwise);
if (DepthBuffered)
{
renderContext.DepthStencilMode = DepthStencilMode.ZReadWrite;
}
else
{
renderContext.DepthStencilMode = DepthStencilMode.Off;
}
SimpleLineShader11.Use(renderContext.devContext);
if (aaFix)
{
renderContext.setRasterizerState(TriangleCullMode.Off, false);
}
foreach (PositionVertexBuffer11 lineBuffer in lineBuffers)
{
renderContext.SetVertexBuffer(lineBuffer);
renderContext.SetIndexBuffer(null);
renderContext.devContext.Draw(lineBuffer.Count, 0);
}
if (aaFix)
{
renderContext.setRasterizerState(TriangleCullMode.Off, true);
}
if (usingLocalCenter)
{
renderContext.World = savedWorld;
renderContext.View = savedView;
}
}