コード例 #1
0
        static public void UpdateForwardLights()
        {
            const float RADIUS_FOR_LIGHTS = 400;

            BoundingSphere sphere = new BoundingSphere(MyCamera.Position, RADIUS_FOR_LIGHTS);

            GetRenderProfiler().StartProfilingBlock("Setup lights");

            MyEffectModelsDNS effectDNS = (MyEffectModelsDNS)GetEffect(MyEffects.ModelDNS);

            MyLights.UpdateEffect(effectDNS.DynamicLights, ref sphere, true);
            MyLights.UpdateEffectReflector(effectDNS.Reflector, true);

            MyEffectVoxels effectVoxels = (MyEffectVoxels)GetEffect(MyEffects.VoxelsMRT);

            MyLights.UpdateEffect(effectVoxels.DynamicLights, ref sphere, true);
            MyLights.UpdateEffectReflector(effectVoxels.Reflector, true);

            MyEffectDecals effectDecals = (MyEffectDecals)GetEffect(MyEffects.Decals);

            MyLights.UpdateEffect(effectDecals.DynamicLights, ref sphere, true);
            MyLights.UpdateEffectReflector(effectDecals.Reflector, true);

            GetRenderProfiler().EndProfilingBlock(); //Setup lights
        }
コード例 #2
0
        static public void UpdateForwardLights()
        {
            GetRenderProfiler().StartProfilingBlock("Setup lights");

            MyEffectModelsDNS effectDNS = (MyEffectModelsDNS)GetEffect(MyEffects.ModelDNS);

            MyLights.UpdateEffect(effectDNS.DynamicLights, true);
            MyLights.UpdateEffectReflector(effectDNS.Reflector, true);

            MyEffectVoxels effectVoxels = (MyEffectVoxels)GetEffect(MyEffects.VoxelsMRT);

            MyLights.UpdateEffect(effectVoxels.DynamicLights, true);
            MyLights.UpdateEffectReflector(effectVoxels.Reflector, true);

            MyEffectDecals effectDecals = (MyEffectDecals)GetEffect(MyEffects.Decals);

            MyLights.UpdateEffect(effectDecals.DynamicLights, true);
            MyLights.UpdateEffectReflector(effectDecals.Reflector, true);

            GetRenderProfiler().EndProfilingBlock(); //Setup lights
        }
コード例 #3
0
        public void Draw(MyVertexFormatDecal[] vertices, MyEffectDecals effect, MyTexture2D[] texturesDiffuse, MyTexture2D[] texturesNormalMap)
        {
            CheckIfBufferIsFull();

            //  SortForSAP buffers by texture
            m_sortTriangleBuffersByTexture.Clear();
            foreach (MyDecalsForRenderObjectsTriangleBuffer buffer in m_usedTriangleBuffers)
            {
                if (buffer.RenderObject.Visible == true)
                {
                    /*  todo drawdecals flag
                     * if ((buffer.Entity == MyGuiScreenGamePlay.Static.ControlledEntity
                     || buffer.Entity.Parent == MyGuiScreenGamePlay.Static.ControlledEntity) &&
                     || MyGuiScreenGamePlay.Static.IsFirstPersonView)
                     ||{
                     || //  Don't draw decals if they are on an entity in which the camera is
                     || continue;
                     ||} */

                    // Decal with "ExplosionSmut" texture is much larger, so it must be drawed to larger distance.
                    float fadeoutDistance = MyDecals.GetMaxDistanceForDrawingDecals();
                    //if (buffer.DecalTexture == MyDecalTexturesEnum.ExplosionSmut)
                    //  fadeoutDistance *= MyDecalsConstants.DISTANCE_MULTIPLIER_FOR_LARGE_DECALS;

                    //if (Vector3.Distance(MyCamera.m_initialSunWindPosition, buffer.PhysObject.GetPosition()) >= (MyDecals.GetMaxDistanceForDrawingDecals()))
                    //if (buffer.PhysObject.GetDistanceBetweenCameraAndBoundingSphere() >= MyDecals.GetMaxDistanceForDrawingDecals())

                    /*if (buffer.RenderObject.GetDistanceBetweenCameraAndBoundingSphere() >= fadeoutDistance)
                     * {
                     *  continue;
                     * } */

                    m_sortTriangleBuffersByTexture.Add(buffer);
                }
            }
            m_sortTriangleBuffersByTexture.Sort();

            //  Draw decals - sorted by texture
            MyDecalTexturesEnum?lastDecalTexture = null;

            for (int i = 0; i < m_sortTriangleBuffersByTexture.Count; i++)
            {
                MyDecalsForRenderObjectsTriangleBuffer buffer = m_sortTriangleBuffersByTexture[i];

                int trianglesCount = buffer.CopyDecalsToVertices(vertices);

                if (trianglesCount <= 0)
                {
                    continue;
                }

                //  Switch texture only if different than previous one
                if ((lastDecalTexture == null) || (lastDecalTexture != buffer.DecalTexture))
                {
                    int textureIndex = (int)buffer.DecalTexture;
                    effect.SetDecalDiffuseTexture(texturesDiffuse[textureIndex]);
                    effect.SetDecalNormalMapTexture(texturesNormalMap[textureIndex]);
                    lastDecalTexture = buffer.DecalTexture;
                }

                //effect.SetWorldMatrix(buffer.Entity.WorldMatrix * Matrix.CreateTranslation(-MyCamera.Position));
                if (buffer.RenderObject is MyRenderTransformObject)
                {
                    effect.SetWorldMatrix((Matrix)((MyRenderTransformObject)buffer.RenderObject).GetWorldMatrixForDraw());
                }
                else
                {
                    effect.SetWorldMatrix((Matrix)((MyManualCullableRenderObject)buffer.RenderObject).GetWorldMatrixForDraw());
                }

                effect.SetViewProjectionMatrix(MyRenderCamera.ViewProjectionMatrixAtZero);

                // set FadeoutDistance
                float fadeoutDistance = MyDecals.GetMaxDistanceForDrawingDecals();
                //if (buffer.DecalTexture == MyDecalTexturesEnum.ExplosionSmut)
                //  fadeoutDistance *= MyDecalsConstants.DISTANCE_MULTIPLIER_FOR_LARGE_DECALS;

                effect.SetFadeoutDistance(fadeoutDistance);

                effect.SetTechnique(MyEffectDecals.Technique.Model);

                MyRender.GraphicsDevice.VertexDeclaration = MyVertexFormatDecal.VertexDeclaration;

                effect.Begin();
                MyRender.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, 0, trianglesCount, vertices);
                effect.End();

                MyPerformanceCounter.PerCameraDrawWrite.DecalsForEntitiesInFrustum += trianglesCount;
            }
        }