當前位置: 首頁>>代碼示例>>C#>>正文


C# RenderContext11.PreDraw方法代碼示例

本文整理匯總了C#中TerraViewer.RenderContext11.PreDraw方法的典型用法代碼示例。如果您正苦於以下問題:C# RenderContext11.PreDraw方法的具體用法?C# RenderContext11.PreDraw怎麽用?C# RenderContext11.PreDraw使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在TerraViewer.RenderContext11的用法示例。


在下文中一共展示了RenderContext11.PreDraw方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Draw

        public void Draw(RenderContext11 renderContext)
        {
            renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
            renderContext.devContext.InputAssembler.SetVertexBuffers(0, vertexBufferBinding);
            renderContext.devContext.InputAssembler.SetIndexBuffer(indexBuffer, SharpDX.DXGI.Format.R32_UInt, 0);



            renderContext.SunPosition = new Vector3d(500, 500, 0.0);
            renderContext.SunlightColor = System.Drawing.Color.White;
            renderContext.AmbientLightColor = System.Drawing.Color.DarkGray;

            renderContext.SetupBasicEffect(BasicEffect.TextureOnly, 1.0f, System.Drawing.Color.White);
            renderContext.MainTexture = texture;

            renderContext.PreDraw();


            if (layout == null)
            {
                layout = new SharpDX.Direct3D11.InputLayout(renderContext.Device, renderContext.Shader.InputSignature, new[]
                           {
                               new SharpDX.Direct3D11.InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32_Float,     0, 0),
                               new SharpDX.Direct3D11.InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32_Float,       16, 0),
                           });
                renderContext.Device.ImmediateContext.InputAssembler.InputLayout = layout;
            }


            // Draw the cube
            renderContext.devContext.DrawIndexed(triangleCount * 3, 0, 0);
        }
開發者ID:keenedge,項目名稱:wwt-windows-client,代碼行數:32,代碼來源:3dWIndow.cs

示例2: Draw

        public void Draw(RenderContext11 renderContext, float Opacity, Color drawColor)
        {
            if (glyphCache == null || glyphCache.Version > glyphVersion)
            {
                PrepareBatch();
            }

            //todo11 Use Shader

            renderContext.SetupBasicEffect(BasicEffect.TextureColorOpacity, Opacity, drawColor);
            renderContext.MainTexture = glyphCache.Texture;
            renderContext.devContext.InputAssembler.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;

            renderContext.PreDraw();

            if (layout == null)
            {
                layout = new SharpDX.Direct3D11.InputLayout(renderContext.Device, renderContext.Shader.InputSignature, new[]
                           {
                               new SharpDX.Direct3D11.InputElement("POSITION", 0, SharpDX.DXGI.Format.R32G32B32_Float,     0, 0),
                               new SharpDX.Direct3D11.InputElement("TEXCOORD", 0, SharpDX.DXGI.Format.R32G32_Float,       12, 0),
                           });
            }
            renderContext.Device.ImmediateContext.InputAssembler.InputLayout = layout;

            renderContext.SetVertexBuffer(vertexBuffer);

            renderContext.devContext.Draw(vertexBuffer.Count, 0);
        }
開發者ID:china-vo,項目名稱:wwt-windows-client,代碼行數:29,代碼來源:SkyText.cs

示例3: Draw3D

        public override bool Draw3D(RenderContext11 renderContext, float transparancy, Tile parent)
        {
            InViewFrustum = true;

            transparancy = transparancy / 100;
            if (transparancy > 1f)
            {
                transparancy = 1.0f;
            }

            if (transparancy < 0f)
            {
                transparancy = 0;
            }

            if (!ReadyToRender)
            {
                TileCache.AddTileToQueue(this);
                if (texture == null)
                {
                    return false;
                }
            }

            if (!CreateGeometry(renderContext, true))
            {
                return false;
            }

            renderContext.MainTexture = texture;

            renderContext.SetVertexBuffer(vertexBuffer);
            renderContext.SetIndexBuffer(indexBuffer);
            renderContext.PreDraw();
            renderContext.devContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
            renderContext.devContext.DrawIndexed(6, 0, 0);

            return true;
        }
開發者ID:bluephoton,項目名稱:wwt-windows-client,代碼行數:39,代碼來源:SkyImage.cs

示例4: Render

        public void Render(RenderContext11 renderContext, float opacity)
        {
            if (dirty && !(ISSLayer))
            {
                Reload();
            }
            Matrix3d oldWorld = renderContext.World;

            Vector3 offset = mesh.BoundingSphere.Center;
            float unitScale = 1.0f;
            if (mesh.BoundingSphere.Radius > 0.0f)
            {
                unitScale = 1.0f / mesh.BoundingSphere.Radius;
            }
            renderContext.World = Matrix3d.Translation(-offset.X, -offset.Y, -offset.Z) * Matrix3d.Scaling(unitScale, unitScale, unitScale) * oldWorld;

            Matrix3d worldView = renderContext.World * renderContext.View;
            Vector3d v = worldView.Transform(Vector3d.Empty);
            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)
//.........這裏部分代碼省略.........
開發者ID:ngonzalezromero,項目名稱:wwt-windows-client,代碼行數:101,代碼來源:Object3d.cs

示例5: Draw3D


//.........這裏部分代碼省略.........
                            {
                                renderPart[childIndex].TargetState = renderPart[childIndex].State = false;
                            }

                            if (renderPart[childIndex].TargetState == true || !blendMode)
                            {
                                renderPart[childIndex].State = renderPart[childIndex].TargetState;
                            }
                        }
                        else
                        {
                            renderPart[childIndex].State = true;
                        }
                        if (renderPart[childIndex].State == true)
                        {
                            anythingToRender = true;
                        }
                        childIndex++;
                    }
                }

                if (childRendered || anythingToRender)
                {
                    RenderedAtOrBelowGeneration = CurrentRenderGeneration;
                    if (parent != null)
                    {
                        parent.RenderedAtOrBelowGeneration = RenderedAtOrBelowGeneration;
                    }
                }

                if (!anythingToRender)
                {
                    return true;
                }

                if (!CreateGeometry(renderContext, true))
                {
                    return false;
                }

                TilesInView++;

                if ( wireFrame)
                {
                    renderContext.MainTexture = null;
                }
                else
                {
                    renderContext.MainTexture = texture;
                }

                renderContext.SetVertexBuffer(vertexBuffer);

                accomidation = ComputeAccomidation();

                for (int i = 0; i < 4; i++)
                {
                    if (blendMode) //|| ShowElevation == false)
                    {
                        if ((renderPart[i].State && opacity == 1.0) || renderPart[i].TargetState)
                        {
                            renderContext.LocalCenter = localCenter;
                            renderContext.PreDraw();
                            if (dataset.DataSetType == ImageSetType.Sky)
                            {
                                HDRPixelShader.constants.opacity = renderPart[i].Opacity * opacity;
                                HDRPixelShader.Use(renderContext.devContext);
                            }

                            RenderPart(renderContext, i, renderPart[i].Opacity * opacity, false);
                        }

                    }
                    else
                    {
                        if (renderPart[i].TargetState)
                        {
                            renderContext.LocalCenter = localCenter;
                            renderContext.PreDraw();
                            if (dataset.DataSetType == ImageSetType.Sky)
                            {
                                HDRPixelShader.constants.opacity = opacity;
                                HDRPixelShader.Use(renderContext.devContext);
                            }
                            RenderPart(renderContext, i, opacity, false);
                        }
                    }
                }
            }
            finally
            {

                if (usingLocalCenter)
                {
                    renderContext.World = savedWorld;
                    renderContext.View = savedView;
                }
            }
            return true;
        }
開發者ID:china-vo,項目名稱:wwt-windows-client,代碼行數:101,代碼來源:Tile.cs

示例6: DrawFixedResolutionSphere

        public static void DrawFixedResolutionSphere(RenderContext11 renderContext, int sphereIndex)
        {
            if (sphereVertexBuffers != null && sphereVertexBuffers[sphereIndex] != null)
            {
                renderContext.Device.ImmediateContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
                renderContext.Device.ImmediateContext.InputAssembler.InputLayout = renderContext.Shader.inputLayout(PlanetShader11.StandardVertexLayout.PositionNormalTex2);

                renderContext.PreDraw();
                renderContext.SetVertexBuffer(sphereVertexBuffers[sphereIndex]);
                renderContext.SetIndexBuffer(sphereIndexBuffers[sphereIndex]);
                renderContext.devContext.DrawIndexed(sphereIndexBuffers[sphereIndex].Count, 0, 0);
            }
        }
開發者ID:bluephoton,項目名稱:wwt-windows-client,代碼行數:13,代碼來源:Planets.cs

示例7: DrawSphere


//.........這裏部分代碼省略.........
            {
                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;
            renderContext.Device.ImmediateContext.InputAssembler.InputLayout = renderContext.Shader.inputLayout(PlanetShader11.StandardVertexLayout.PositionNormalTex2);

            renderContext.PreDraw();

            renderContext.SetVertexBuffer(sphereVertexBuffers[sphereIndex]);
            renderContext.SetIndexBuffer(sphereIndexBuffers[sphereIndex]);
            renderContext.devContext.DrawIndexed(sphereIndexBuffers[sphereIndex].Count, 0, 0);
        }
開發者ID:bluephoton,項目名稱:wwt-windows-client,代碼行數:101,代碼來源:Planets.cs

示例8: 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);
        }
開發者ID:bluephoton,項目名稱:wwt-windows-client,代碼行數:19,代碼來源:Planets.cs

示例9: DrawPlanet3d

        private static void DrawPlanet3d(RenderContext11 renderContext, int planetID, Vector3d centerPoint, float opacity)
        {
            // Assume that KML is only used for Earth
            KmlLabels kmlMarkers = null;
            if (planetID == (int)SolarSystemObjects.Earth)
            {
                kmlMarkers = Earth3d.MainWindow.KmlMarkers;
                if (kmlMarkers != null)
                {
                    kmlMarkers.ClearGroundOverlays();
                }
            }

            var matOld = renderContext.World;
            var matOldBase = renderContext.WorldBase;
            var matOldNonRotating = renderContext.WorldBaseNonRotating;

            var radius = GetAdjustedPlanetRadius(planetID);

            SetupPlanetMatrix(renderContext, planetID, centerPoint, true);

            LayerManager.PreDraw(renderContext, 1.0f, false, Enum.GetName(typeof(SolarSystemObjects), (SolarSystemObjects)planetID), true);

            float planetWidth = 1;

            if (planetID == (int)SolarSystemObjects.Saturn)
            {
                planetWidth = 3;
            }

            if (IsPlanetInFrustum(renderContext, planetWidth))
            {
                // Save all matrices modified by SetupMatrix...
                var matOld2 = renderContext.World;
                var matOldBase2 = renderContext.WorldBase;
                var matOldNonRotating2 = renderContext.WorldBaseNonRotating;

                renderContext.World = matOld;
                renderContext.WorldBase = matOldBase;
                renderContext.WorldBaseNonRotating = matOldNonRotating;
                SetupMatrixForPlanetGeometry(renderContext, planetID, centerPoint, true);

                var loc = planet3dLocations[planetID] - centerPoint;
                loc.Subtract(renderContext.CameraPosition);
                var dist = loc.Length();
                var sizeIndexParam = (2 * Math.Atan(.5 * (radius / dist))) / Math.PI * 180;

                // 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.
                var viewportHeight = renderContext.ViewPort.Height;
                var p11 = renderContext.Projection.M11;
                var p34 = renderContext.Projection.M34;
                var p44 = renderContext.Projection.M44;
                var w = Math.Abs(p34) * dist + p44;
                var pixelsPerUnit = (float)(p11 / w) * viewportHeight;
                var planetRadiusInPixels = (float)(radius * pixelsPerUnit);

                var sizeIndex = 0;
                if (sizeIndexParam > 10.5)
                {
                    sizeIndex = 0;
                }
                else if (sizeIndexParam > 3.9)
                {
                    sizeIndex = 1;
                }
                else if (sizeIndexParam > .72)
                {
                    sizeIndex = 2;
                }
                else if (sizeIndexParam > 0.057)
                {
                    sizeIndex = 3;
                }
                else
                {
                    sizeIndex = 4;
                }

                var eclipseShadowCount = 0;
                var hasRingShadowsOnPlanet = false;

                // No shadows should be drawn if Solar System Lighting is OFF
                if (Settings.Active.SolarSystemLighting)
                {
                    // Eclipse shadow setup for Earth
                    if (planetID == (int)SolarSystemObjects.Earth)
                    {
                        if (sizeIndex < 2)
                        {
                            var width = Settings.Active.SolarSystemScale * .00001f;

                            SetupShadow(renderContext, centerPoint, width, SolarSystemObjects.Moon, 0);

                            eclipseShadowCount = 1;
                        }
                    }

//.........這裏部分代碼省略.........
開發者ID:bluephoton,項目名稱:wwt-windows-client,代碼行數:101,代碼來源:Planets.cs


注:本文中的TerraViewer.RenderContext11.PreDraw方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。