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


C# RenderContext11.SetMaterial方法代碼示例

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


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

示例1: 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


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