Ejemplo n.º 1
0
 public void Add(MyLodTypeEnum lod, MyRender.MyRenderElement renderElement)
 {
     if (renderElement.DrawTechnique == MyMeshDrawTechnique.VOXEL_MAP)
         AddVoxel(lod, renderElement);
     else
         AddModel(lod, renderElement);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Renders a list of models to the shadow map, and returns a surface
        /// containing the shadow occlusion factor
        /// </summary>
        public void Render()
        {
            int shadowBlock = -1;

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("MyShadowRenderer::Render", ref shadowBlock);

            if (MultiThreaded)
            {
                WaitUntilPrepareForDrawCompleted();
            }
            else
            {
                //PrepareFrame();
                PrepareCascadesForDraw();
            }

            IssueQueriesForCascades();

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("Set & Clear RT");

            // Set our targets
            MyMinerGame.SetRenderTarget(MyRender.GetRenderTarget(m_shadowRenderTarget), MyRender.GetRenderTarget(m_shadowDepthTarget));
            //MyMinerGameDX.Static.GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.White, 1.0f, 0);
            MyMinerGame.Static.GraphicsDevice.Clear(ClearFlags.ZBuffer, new ColorBGRA(1.0f), 1.0f, 0);

            DepthStencilState.Default.Apply();
            RasterizerState.CullCounterClockwise.Apply();
            BlendState.Opaque.Apply();

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("Render 4 ShadowMaps");

            // Render our scene geometry to each split of the cascade
            for (int i = 0; i < NumSplits; i++)
            {
                if (m_skip[i])
                {
                    continue;
                }
                if (!m_visibility[i])
                {
                    continue;
                }

                RenderShadowMap(i);
                //IssueQueriesForShadowMap(i);
            }

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

            //   MyGuiManager.TakeScreenshot();
            MyRender.TakeScreenshot("ShadowMap", MyRender.GetRenderTarget(m_shadowRenderTarget), MyEffectScreenshot.ScreenshotTechniqueEnum.Color);

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock(shadowBlock);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets the environment render targets.
        /// </summary>
        private static void SetEnvironmentRenderTargets()
        {
            var rt1 = MyRender.GetRenderTargetCube(MyRenderTargets.EnvironmentCube);
            var rt2 = MyRender.GetRenderTargetCube(MyRenderTargets.EnvironmentCubeAux);
            var rt3 = MyRender.GetRenderTargetCube(MyRenderTargets.AmbientCube);
            var rt4 = MyRender.GetRenderTargetCube(MyRenderTargets.AmbientCubeAux);
            var rt5 = MyRender.GetRenderTarget(MyRenderTargets.EnvironmentMap);

            MyEnvironmentMap.SetRenderTargets((CubeTexture)rt1, (CubeTexture)rt2, (CubeTexture)rt3, (CubeTexture)rt4, (Texture)rt5);
        }
Ejemplo n.º 4
0
        public void SetupShadowBaseEffect(MyEffectShadowBase effect)
        {
            //Matrix cameraTransform = Matrix.Invert(MyCamera.ViewMatrix);
            //effect.SetInvViewMatrix(cameraTransform);

            effect.SetLightViewProjMatrices(m_lightViewProjectionMatrices);
            effect.SetClipPlanes(m_lightClipPlanes);

            effect.SetShadowMapSize(new Vector4(ShadowMapCascadeSize * NumSplits, ShadowMapCascadeSize, m_shadowMapCascadeSizeInv.X, m_shadowMapCascadeSizeInv.Y));
            effect.SetShadowMap(MyRender.GetRenderTarget(m_shadowRenderTarget));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Render method is called directly by renderer. Depending on stage, post process can do various things
        /// </summary>
        /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights()
        public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget)
        {
            switch (postProcessStage)
            {
            case PostProcessStage.PostLighting:
            {
                if (MySector.FogProperties.FogMultiplier <= 0.0f)
                {
                    return(source);
                }

                //MyMinerGame.Static.GraphicsDevice.SetRenderTarget(availableRenderTarget);

                //MyMinerGame.Static.GraphicsDevice.BlendState = BlendState.NonPremultiplied;
                MyStateObjects.VolumetricFogBlend.Apply();

                //    MyMinerGame.Static.GraphicsDevice.RasterizerState = RasterizerState.CullClockwise;

                MyEffectVolumetricFog volumetricFog = MyRender.GetEffect(MyEffects.VolumetricFog) as MyEffectVolumetricFog;

                int width  = MyRender.GetRenderTarget(MyRenderTargets.Normals).GetLevelDescription(0).Width;
                int height = MyRender.GetRenderTarget(MyRenderTargets.Normals).GetLevelDescription(0).Height;

                volumetricFog.SetSourceRT(source);
                volumetricFog.SetDepthsRT(MyRender.GetRenderTarget(MyRenderTargets.Depth));
                volumetricFog.SetNormalsTexture(MyRender.GetRenderTarget(MyRenderTargets.Normals));
                volumetricFog.SetHalfPixel(width, height);
                volumetricFog.SetViewProjectionMatrix(MyCamera.ViewProjectionMatrix);
                volumetricFog.SetCameraPosition(MyCamera.Position);
                volumetricFog.SetCameraMatrix(Matrix.Invert(MyCamera.ViewMatrix));
                volumetricFog.SetFrustumCorners(MyRender.GetShadowRenderer().GetFrustumCorners());
                MyCamera.SetupBaseEffect(volumetricFog);

                //volumetricFog.SetWorldMatrix(Matrix.CreateScale(1000) * Matrix.CreateTranslation(MyCamera.Position));
                if (MyFakes.MWBUILDER)
                {
                    volumetricFog.SetTechnique(MyEffectVolumetricFog.TechniqueEnum.SkipBackground);
                }
                else
                {
                    volumetricFog.SetTechnique(MyEffectVolumetricFog.TechniqueEnum.Default);
                }

                MyGuiManager.GetFullscreenQuad().Draw(volumetricFog);

                //  MyMinerGame.Static.GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
                //  MyMinerGame.Static.GraphicsDevice.BlendState = BlendState.AlphaBlend;
            }
            break;
            }
            return(source);
        }
Ejemplo n.º 6
0
        internal static void DrawDebugBlendedRenderTargets()
        {
            BlendState.Opaque.Apply();

            //  All RT should be of same size, so for size we can use any of them we just pick up depthRT
            float renderTargetAspectRatio = (float)MyCamera.Viewport.Width / (float)MyCamera.Viewport.Height;

            float normalizedSizeY = 0.40f;
            //float normalizedSizeY = MyCamera.Viewport.Height / 1920f;
            float normalizedSizeX = normalizedSizeY * renderTargetAspectRatio;

            MyMwcVector2Int delta = new MyMwcVector2Int((int)(MyCamera.Viewport.Height * 0.015f), (int)(MyCamera.Viewport.Height * 0.015f));
            MyMwcVector2Int size  = new MyMwcVector2Int((int)(MyCamera.Viewport.Height * normalizedSizeX), (int)(MyCamera.Viewport.Height * normalizedSizeY));

            MyGuiManager.DrawSpriteFast(MyRender.GetRenderTarget(MyRenderTargets.Diffuse), delta.X, delta.Y, size.X, size.Y, Color.White);
            MyGuiManager.DrawSpriteFast(MyRender.GetRenderTarget(MyRenderTargets.Normals), delta.X + size.X + delta.X, delta.Y, size.X, size.Y, Color.White);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Renders the shadow map using the orthographic camera created in
        /// CalculateFrustum.
        /// </summary>
        /// <param name="modelList">The list of models to be rendered</param>
        protected void RenderShadowMap(int splitIndex)
        {
            PrepareViewportForCascade(splitIndex);

            // Set up the effect
            MyEffectShadowMap shadowMapEffect = MyRender.GetEffect(MyEffects.ShadowMap) as MinerWars.AppCode.Game.Effects.MyEffectShadowMap;

            // Clear shadow map
            shadowMapEffect.SetTechnique(MyEffectShadowMap.ShadowTechnique.Clear);
            MyGuiManager.GetFullscreenQuad().Draw(shadowMapEffect);

            shadowMapEffect.SetViewProjMatrix(m_lightCameras[splitIndex].ViewProjectionMatrix);

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("draw elements");
            // Draw the models
            DrawElements(m_lightCameras[splitIndex].CastingRenderElements, shadowMapEffect, false, splitIndex);

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
        }
Ejemplo n.º 8
0
        public void AddModel(MyLodTypeEnum lod, MyRender.MyRenderElement renderElement)
        {
            var matDict = Models[GetModelIndex(lod, renderElement.DrawTechnique)];
            ModelMaterialSet vbDict;
            if (!matDict.Models.TryGetValue(renderElement.Material, out vbDict))
            {
                vbDict = new ModelMaterialSet();
                matDict.Models[renderElement.Material] = vbDict;
            }

            List<MyRender.MyRenderElement> elements;
            if (!vbDict.Models.TryGetValue(renderElement.VertexBuffer, out elements))
            {
                elements = new List<MyRender.MyRenderElement>(20);
                vbDict.Models[renderElement.VertexBuffer] = elements;
            }

            matDict.RenderElementCount++;
            vbDict.RenderElementCount++;

            elements.Add(renderElement);
        }
Ejemplo n.º 9
0
        static MyEffectBase GetShader(MyMeshDrawTechnique technique)
        {
            switch (technique)
            {
            case MyMeshDrawTechnique.MESH:
            case MyMeshDrawTechnique.DECAL:
            case MyMeshDrawTechnique.HOLO:
            case MyMeshDrawTechnique.ALPHA_MASKED:
                return(GetEffect(MyEffects.ModelDNS) as MyEffectModelsDNS);

            case MyMeshDrawTechnique.VOXELS_DEBRIS:
                return(GetEffect(MyEffects.VoxelDebrisMRT) as MyEffectVoxelsDebris);

            case MyMeshDrawTechnique.VOXEL_MAP:
                return(MyRender.GetEffect(MyEffects.VoxelsMRT) as MyEffectVoxels);

            case MyMeshDrawTechnique.VOXELS_STATIC_ASTEROID:
                return(GetEffect(MyEffects.VoxelStaticAsteroidMRT) as MyEffectVoxelsStaticAsteroid);

            default:
                throw new MyMwcExceptionApplicationShouldNotGetHere();
            }
        }
Ejemplo n.º 10
0
 public void AddVoxel(MyLodTypeEnum lod, MyRender.MyRenderElement renderElement)
 {
     var matDict = Voxels[GetVoxelIndex(lod, renderElement.VoxelBatch.Type)];
     List<MyRender.MyRenderElement> elements;
     if (!matDict.Voxels.TryGetValue(renderElement.VoxelBatch.MaterialId, out elements))
     {
         elements = new List<MyRender.MyRenderElement>(20);
         matDict.Voxels[renderElement.VoxelBatch.MaterialId] = elements;
     }
     matDict.RenderElementCount++;
     elements.Add(renderElement);
 }
Ejemplo n.º 11
0
        internal static void RenderLights()
        {
            PrepareLights();

            RenderSpotShadows();

            m_renderProfiler.StartProfilingBlock("Render lights");
            MyMinerGame.SetRenderTarget(GetRenderTarget(MyRenderTargets.Auxiliary1), null, SetDepthTargetEnum.RestoreDefault);
            MyMinerGame.Static.GraphicsDevice.Clear(ClearFlags.Target, new ColorBGRA(0.0f), 1, 0);

            SetCorrectViewportSize();

            if (MyRender.CurrentRenderSetup.EnableSmallLights.Value)
            {
                MyEffectPointLight effectPointLight = (MyEffectPointLight)MyRender.GetEffect(MyEffects.PointLight);
                Texture            diffuseRT        = MyRender.GetRenderTarget(MyRenderTargets.Diffuse);
                effectPointLight.SetNormalsRT(MyRender.GetRenderTarget(MyRenderTargets.Normals));
                effectPointLight.SetDiffuseRT(diffuseRT);
                effectPointLight.SetDepthsRT(MyRender.GetRenderTarget(MyRenderTargets.Depth));
                effectPointLight.SetHalfPixel(diffuseRT.GetLevelDescription(0).Width, diffuseRT.GetLevelDescription(0).Height);
                effectPointLight.SetScale(GetScaleForViewport(diffuseRT));

                Matrix invViewProjMatrix = Matrix.Invert(MyCamera.ViewProjectionMatrix);
                Matrix invViewMatrix     = Matrix.Invert(MyCamera.ViewMatrix);

                effectPointLight.SetCameraPosition(MyCamera.Position);
                effectPointLight.SetViewMatrix(MyCamera.ViewMatrix);
                effectPointLight.SetInvViewMatrix(invViewMatrix);

                DepthStencilState.None.Apply();
                MyStateObjects.Light_Combination_BlendState.Apply();

                //Render each light with a model specific to the light
                m_renderProfiler.StartProfilingBlock("PointLight");

                var cullRationSq = MyRenderConstants.DISTANCE_LIGHT_CULL_RATIO * MyRenderConstants.DISTANCE_LIGHT_CULL_RATIO;

                effectPointLight.SetTechnique(effectPointLight.DefaultTechnique);
                foreach (MyLight light in m_pointLights)
                {
                    float distanceSq         = Vector3.DistanceSquared(MyCamera.Position, light.PositionWithOffset);
                    var   hasVolumetricGlare = light.GlareOn && light.Glare.Type == MyLightGlare.GlareTypeEnum.Distant;
                    var   isTooFarAway       = (light.Range * light.Range) < (distanceSq / cullRationSq);

                    if (!isTooFarAway)
                    {
                        // Always cull clockwise (render inner parts of object), depth test is done is PS using light radius
                        RasterizerState.CullClockwise.Apply();

                        effectPointLight.SetLightPosition(light.PositionWithOffset);
                        effectPointLight.SetLightIntensity(light.Intensity);
                        effectPointLight.SetSpecularLightColor(light.SpecularColor);
                        effectPointLight.SetFalloff(light.Falloff);

                        effectPointLight.SetLightRadius(light.Range);
                        effectPointLight.SetReflectorTexture(light.ReflectorTexture);
                        effectPointLight.SetLightColor(new Vector3(light.Color.X, light.Color.Y, light.Color.Z));
                        effectPointLight.SetTechnique(effectPointLight.DefaultTechnique);
                        MySimpleObjectDraw.DrawSphereForLight(effectPointLight, ref light.PositionWithOffset, light.Range, ref MyMath.Vector3One, 1);
                        MyPerformanceCounter.PerCameraDraw.LightsCount++;
                    }
                    if (!isTooFarAway || hasVolumetricGlare)
                    {
                        light.Draw();
                    }
                }


                m_renderProfiler.EndProfilingBlock();


                m_renderProfiler.StartProfilingBlock("Hemisphere");

                foreach (MyLight light in m_hemiLights)
                {
                    // compute bounding box
                    //Vector3 center = light.Position;// - light.Range * new Vector3(0,1,0);
                    //Vector3 extend = new Vector3(light.Range, light.Range, light.Range);
                    //m_lightBoundingBox.Min = center - extend;
                    //m_lightBoundingBox.Max = center + extend;
                    // Always cull clockwise (render inner parts of object), depth test is done is PS using light radius
                    if (Vector3.Dot(light.ReflectorDirection, MyCamera.Position - light.Position) > 0 && light.PointBoundingSphere.Contains(MyCamera.Position) == MinerWarsMath.ContainmentType.Contains)
                    {
                        RasterizerState.CullNone.Apply(); //zevnitr
                    }
                    else
                    {
                        RasterizerState.CullCounterClockwise.Apply(); //zvenku
                    }

                    effectPointLight.SetLightPosition(light.Position);
                    effectPointLight.SetLightIntensity(light.Intensity);
                    effectPointLight.SetSpecularLightColor(light.SpecularColor);
                    effectPointLight.SetFalloff(light.Falloff);

                    effectPointLight.SetLightRadius(light.Range);
                    effectPointLight.SetReflectorTexture(light.ReflectorTexture);
                    effectPointLight.SetLightColor(new Vector3(light.Color.X, light.Color.Y, light.Color.Z));
                    effectPointLight.SetTechnique(effectPointLight.DefaultHemisphereTechnique);

                    Matrix world = Matrix.CreateScale(light.Range) * Matrix.CreateWorld(light.Position, light.ReflectorDirection, light.ReflectorUp);
                    MySimpleObjectDraw.DrawHemisphereForLight(effectPointLight, ref world, ref MyMath.Vector3One, 1);
                    light.Draw();

                    MyPerformanceCounter.PerCameraDraw.LightsCount++;
                }
                m_renderProfiler.EndProfilingBlock();


                m_renderProfiler.StartProfilingBlock("Spotlight");
                RenderSpotLights(m_spotLightRenderElements, effectPointLight);

                m_renderProfiler.EndProfilingBlock();

                if (EnableSpectatorReflector && DrawSpectatorReflector && SpectatorReflector != null && SpectatorReflector.LightOn && SpectatorReflector.ReflectorOn)
                {
                    SpectatorReflector.ReflectorDirection = MyCamera.ForwardVector;
                    SpectatorReflector.ReflectorUp        = MyCamera.UpVector;
                    SpectatorReflector.SetPosition(MyCamera.Position);

                    effectPointLight.SetLightPosition(SpectatorReflector.Position);
                    effectPointLight.SetReflectorTexture(null);
                    effectPointLight.SetReflectorDirection(SpectatorReflector.ReflectorDirection);
                    effectPointLight.SetReflectorConeMaxAngleCos(1 - SpectatorReflector.ReflectorConeMaxAngleCos);
                    effectPointLight.SetReflectorColor(SpectatorReflector.ReflectorColor);
                    effectPointLight.SetReflectorRange(SpectatorReflector.ReflectorRange);
                    effectPointLight.SetCameraPosition(MyCamera.Position);

                    // Special case, for camera reflector
                    effectPointLight.SetReflectorIntensity(MyMinerShipConstants.MINER_SHIP_NEAR_REFLECTOR_INTENSITY * MySmallShip.ReflectorIntensityMultiplier);
                    effectPointLight.SetReflectorFalloff(MyMinerShipConstants.MINER_SHIP_NEAR_REFLECTOR_FALLOFF);

                    effectPointLight.SetTechnique(effectPointLight.DefaultSpotTechnique);
                    MySimpleObjectDraw.DrawConeForLight(effectPointLight, SpectatorReflector.SpotWorld);


                    // Always cull clockwise (render inner parts of object), depth test is done is PS using light radius
                    RasterizerState.CullClockwise.Apply();

                    effectPointLight.SetLightIntensity(MyMinerShipConstants.MINER_SHIP_NEAR_LIGHT_INTENSITY);
                    effectPointLight.SetSpecularLightColor(Color.White.ToVector3());
                    effectPointLight.SetFalloff(1.0f);

                    effectPointLight.SetLightRadius(MyMinerShipConstants.MINER_SHIP_NEAR_LIGHT_RANGE);
                    effectPointLight.SetLightColor(new Color(MyReflectorConstants.SHORT_REFLECTOR_LIGHT_COLOR).ToVector3());
                    effectPointLight.SetTechnique(effectPointLight.DefaultSpotTechnique);

                    MySimpleObjectDraw.DrawSphereForLight(effectPointLight, ref MyCamera.Position, MyMinerShipConstants.MINER_SHIP_NEAR_LIGHT_RANGE, ref MyMath.Vector3One, 1);
                    MyPerformanceCounter.PerCameraDraw.LightsCount++;
                }
            }

            DepthStencilState.None.Apply();
            RasterizerState.CullCounterClockwise.Apply();

            MyStateObjects.Sun_Combination_BlendState.Apply();

            m_renderProfiler.StartProfilingBlock("Sun light");

            if (EnableSun && CurrentRenderSetup.EnableSun.Value)
            {
                //Sun light
                MyEffectDirectionalLight effectDirectionalLight = MyRender.GetEffect(MyEffects.DirectionalLight) as MyEffectDirectionalLight;
                Texture diffuseRTSun = MyRender.GetRenderTarget(MyRenderTargets.Diffuse);
                effectDirectionalLight.SetNormalsRT(MyRender.GetRenderTarget(MyRenderTargets.Normals));
                effectDirectionalLight.SetDiffuseRT(diffuseRTSun);
                effectDirectionalLight.SetDepthsRT(MyRender.GetRenderTarget(MyRenderTargets.Depth));
                effectDirectionalLight.SetHalfPixelAndScale(diffuseRTSun.GetLevelDescription(0).Width, diffuseRTSun.GetLevelDescription(0).Height, GetScaleForViewport(diffuseRTSun));

                effectDirectionalLight.SetCameraMatrix(Matrix.Invert(MyCamera.ViewMatrix));

                effectDirectionalLight.SetAmbientMinimumAndIntensity(new Vector4(AmbientColor * AmbientMultiplier, EnvAmbientIntensity));
                effectDirectionalLight.SetTextureEnvironmentMain(MyEnvironmentMap.EnvironmentMainMap);
                effectDirectionalLight.SetTextureEnvironmentAux(MyEnvironmentMap.EnvironmentAuxMap);
                effectDirectionalLight.SetTextureAmbientMain(MyEnvironmentMap.AmbientMainMap);
                effectDirectionalLight.SetTextureAmbientAux(MyEnvironmentMap.AmbientAuxMap);
                effectDirectionalLight.SetTextureEnvironmentBlendFactor(MyEnvironmentMap.BlendFactor);
                effectDirectionalLight.SetCameraPosition(MyCamera.Position);

                //Set distance where no slope bias will be applied (because of cockpit artifacts)
                effectDirectionalLight.SetNearSlopeBiasDistance(3);

                effectDirectionalLight.ShowSplitColors(ShowCascadeSplits);
                effectDirectionalLight.SetShadowBias(0.0001f * MyRenderConstants.RenderQualityProfile.ShadowBiasMultiplier);
                effectDirectionalLight.SetSlopeBias(0.00002f);
                effectDirectionalLight.SetSlopeCascadeMultiplier(20.0f); //100 makes artifacts in prefabs

                MyRender.GetShadowRenderer().SetupShadowBaseEffect(effectDirectionalLight);

                effectDirectionalLight.SetLightDirection(-m_sun.Direction); //*-1 because of shader opts
                effectDirectionalLight.SetLightColorAndIntensity(new Vector3(m_sun.Color.X, m_sun.Color.Y, m_sun.Color.Z), m_sun.Intensity);
                effectDirectionalLight.SetBacklightColorAndIntensity(new Vector3(m_sun.BackColor.X, m_sun.BackColor.Y, m_sun.BackColor.Z), m_sun.BackIntensity);
                //m_sun.SpecularColor = {X:0,9137255 Y:0,6078432 Z:0,2078431} //nice yellow
                effectDirectionalLight.SetSpecularLightColor(m_sun.SpecularColor);
                effectDirectionalLight.EnableCascadeBlending(MyRenderConstants.RenderQualityProfile.EnableCascadeBlending);

                effectDirectionalLight.SetFrustumCorners(MyRender.GetShadowRenderer().GetFrustumCorners());

                effectDirectionalLight.SetEnableAmbientEnvironment(EnableEnvironmentMapAmbient && MyRenderConstants.RenderQualityProfile.EnableEnvironmentals && CurrentRenderSetup.EnableEnvironmentMapping.Value);
                effectDirectionalLight.SetEnableReflectionEnvironment(EnableEnvironmentMapReflection && MyRenderConstants.RenderQualityProfile.EnableEnvironmentals && CurrentRenderSetup.EnableEnvironmentMapping.Value);

                if (EnableShadows && MyRender.CurrentRenderSetup.ShadowRenderer != null)
                {
                    effectDirectionalLight.SetTechnique(effectDirectionalLight.DefaultTechnique);
                }
                else
                {
                    effectDirectionalLight.SetTechnique(effectDirectionalLight.DefaultWithoutShadowsTechnique);
                }

                MyGuiManager.GetFullscreenQuad().Draw(effectDirectionalLight);
            }
            m_renderProfiler.EndProfilingBlock();

            // Blend in background
            if (true) // blend background
            {
                m_renderProfiler.StartProfilingBlock("Blend background");
                if (MyFakes.RENDER_PREVIEWS_WITH_CORRECT_ALPHA)
                {
                    // for some reason the other option does not give 0 alpha for the background when rendering gui preview images
                    MyStateObjects.Additive_NoAlphaWrite_BlendState.Apply();
                }
                else
                {
                    MyStateObjects.NonPremultiplied_NoAlphaWrite_BlendState.Apply();
                    //BlendState.NonPremultiplied.Apply();
                }
                DepthStencilState.None.Apply();
                RasterizerState.CullCounterClockwise.Apply();

                MyEffectBlendLights effectBlendLights = MyRender.GetEffect(MyEffects.BlendLights) as MyEffectBlendLights;
                Texture             diffuseRT         = GetRenderTarget(MyRenderTargets.Diffuse);
                MyCamera.SetupBaseEffect(effectBlendLights, m_currentSetup.FogMultiplierMult);
                effectBlendLights.SetDiffuseTexture(diffuseRT);
                effectBlendLights.SetNormalTexture(GetRenderTarget(MyRenderTargets.Normals));
                effectBlendLights.SetDepthTexture(GetRenderTarget(MyRenderTargets.Depth));
                effectBlendLights.SetHalfPixel(diffuseRT.GetLevelDescription(0).Width, diffuseRT.GetLevelDescription(0).Height);
                effectBlendLights.SetScale(GetScaleForViewport(diffuseRT));
                effectBlendLights.SetBackgroundTexture(GetRenderTarget(MyRenderTargets.Auxiliary0));

                effectBlendLights.SetTechnique(effectBlendLights.DefaultTechnique);

                MyGuiManager.GetFullscreenQuad().Draw(effectBlendLights);
                m_renderProfiler.EndProfilingBlock();

                // Blend in emissive light, overwrite emissivity (alpha)
                m_renderProfiler.StartProfilingBlock("Copy emisivity");

                if (MyPostProcessHDR.RenderHDRThisFrame())
                {
                    MyStateObjects.AddEmissiveLight_BlendState.Apply();
                }
                else
                {
                    MyStateObjects.AddEmissiveLight_NoAlphaWrite_BlendState.Apply();
                }

                effectBlendLights.SetTechnique(effectBlendLights.CopyEmissivityTechnique);
                MyGuiManager.GetFullscreenQuad().Draw(effectBlendLights);


                bool showDebugLighting = false;

                if (ShowSpecularIntensity)
                {
                    effectBlendLights.SetTechnique(MyEffectBlendLights.Technique.OnlySpecularIntensity);
                    showDebugLighting = true;
                }
                else
                if (ShowSpecularPower)
                {
                    effectBlendLights.SetTechnique(MyEffectBlendLights.Technique.OnlySpecularPower);
                    showDebugLighting = true;
                }
                else
                if (ShowEmissivity)
                {
                    effectBlendLights.SetTechnique(MyEffectBlendLights.Technique.OnlyEmissivity);
                    showDebugLighting = true;
                }
                else
                if (ShowReflectivity)
                {
                    effectBlendLights.SetTechnique(MyEffectBlendLights.Technique.OnlyReflectivity);
                    showDebugLighting = true;
                }

                if (showDebugLighting)
                {
                    BlendState.Opaque.Apply();
                    MyGuiManager.GetFullscreenQuad().Draw(effectBlendLights);
                }

                m_renderProfiler.EndProfilingBlock();
            }

            //TakeScreenshot("Accumulated_lights", GetRenderTarget(MyRenderTargets.Lod0Depth), MyEffectScreenshot.ScreenshotTechniqueEnum.Default);

            /*TakeScreenshot("EnvironmentMap_1", GetRenderTargetCube(MyRenderTargets.EnvironmentCube), MyEffectScreenshot.ScreenshotTechniqueEnum.Default);
             * TakeScreenshot("EnvironmentMap_2", GetRenderTargetCube(MyRenderTargets.EnvironmentCubeAux), MyEffectScreenshot.ScreenshotTechniqueEnum.Default);
             * TakeScreenshot("AmbientMap_1", GetRenderTargetCube(MyRenderTargets.AmbientCube), MyEffectScreenshot.ScreenshotTechniqueEnum.Default);
             * TakeScreenshot("AmbientMap_2", GetRenderTargetCube(MyRenderTargets.AmbientCubeAux), MyEffectScreenshot.ScreenshotTechniqueEnum.Default);
             */
            m_renderProfiler.EndProfilingBlock();
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Render method is called directly by renderer. Depending on stage, post process can do various things
        /// </summary>
        /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights()
        public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget)
        {
            switch (postProcessStage)
            {
            case PostProcessStage.LODBlend:
            {
                MyEffectVolumetricSSAO2 volumetricSsao = MyRender.GetEffect(MyEffects.VolumetricSSAO) as MyEffectVolumetricSSAO2;

                int width      = MyRender.GetRenderTarget(MyRenderTargets.Normals).GetLevelDescription(0).Width;
                int height     = MyRender.GetRenderTarget(MyRenderTargets.Normals).GetLevelDescription(0).Height;
                int halfWidth  = width / 2;
                int halfHeight = height / 2;

                //Render SSAO
                MyMinerGame.SetRenderTarget(MyRender.GetRenderTarget(MyRenderTargets.SSAO), null);

                MyMinerGame.Static.GraphicsDevice.Clear(ClearFlags.Target, new SharpDX.ColorBGRA(0), 1, 0);
                DepthStencilState.None.Apply();
                BlendState.Opaque.Apply();

                Vector4 ssaoParams  = new Vector4(MinRadius, MaxRadius, RadiusGrowZScale, CameraZFar);
                Vector4 ssaoParams2 = new Vector4(Bias, Falloff, NormValue, 0);

                volumetricSsao.SetDepthsRT(MyRender.GetRenderTarget(MyRenderTargets.Depth));
                volumetricSsao.SetNormalsTexture(MyRender.GetRenderTarget(MyRenderTargets.Normals));
                volumetricSsao.SetHalfPixel(width, height);

                volumetricSsao.SetFrustumCorners(MyRender.GetShadowRenderer().GetFrustumCorners());

                volumetricSsao.SetViewMatrix(MyCamera.ViewMatrixAtZero);

                volumetricSsao.SetParams1(ssaoParams);
                volumetricSsao.SetParams2(ssaoParams2);

                volumetricSsao.SetProjectionMatrix(MyCamera.ProjectionMatrix);

                volumetricSsao.SetContrast(Contrast);


                MyGuiManager.GetFullscreenQuad().Draw(volumetricSsao);

                if (volumetricSsao.UseBlur)
                {
                    //SSAO Blur
                    MyMinerGame.SetRenderTarget(availableRenderTarget, null);
                    MyEffectSSAOBlur2 effectSsaoBlur = MyRender.GetEffect(MyEffects.SSAOBlur) as MyEffectSSAOBlur2;
                    effectSsaoBlur.SetDepthsRT(MyRender.GetRenderTarget(MyRenderTargets.Depth));
                    //effectSsaoBlur.SetNormalsRT(MyRender.GetRenderTarget(MyRenderTargets.Normals));
                    effectSsaoBlur.SetHalfPixel(width, height);
                    effectSsaoBlur.SetSSAOHalfPixel(halfWidth, halfHeight);
                    effectSsaoBlur.SetSsaoRT(MyRender.GetRenderTarget(MyRenderTargets.SSAO));
                    effectSsaoBlur.SetBlurDirection(new Vector2(0, 1f / (float)halfHeight));
                    //effectSsaoBlur.SetBlurDirection(new Vector2(1 / (float)halfWidth, 1f / (float)halfHeight));

                    MyGuiManager.GetFullscreenQuad().Draw(effectSsaoBlur);

                    MyMinerGame.SetRenderTarget(MyRender.GetRenderTarget(MyRenderTargets.SSAOBlur), null);
                    effectSsaoBlur.SetSsaoRT(availableRenderTarget);
                    effectSsaoBlur.SetBlurDirection(new Vector2(1f / (float)halfWidth, 0));
                    MyGuiManager.GetFullscreenQuad().Draw(effectSsaoBlur);
                }

                //Bake it into diffuse

                /*
                 * MyEffectScreenshot ssEffect = MyRender.GetEffect(MyEffects.Screenshot) as MyEffectScreenshot;
                 * MyMinerGame.SetRenderTarget(availableRenderTarget, null);
                 * ssEffect.SetSourceTexture(MyRender.GetRenderTarget(MyRenderTargets.Diffuse));
                 * ssEffect.SetScale(Vector2.One);
                 * ssEffect.SetTechnique(MyEffectScreenshot.ScreenshotTechniqueEnum.Default);
                 *
                 * MyGuiManager.GetFullscreenQuad().Draw(ssEffect);
                 *
                 */
                MyMinerGame.SetRenderTarget(MyRender.GetRenderTarget(MyRenderTargets.Diffuse), null);

                /*
                 * ssEffect.SetSourceTexture(availableRenderTarget);
                 * ssEffect.SetTechnique(MyEffectScreenshot.ScreenshotTechniqueEnum.Default);
                 * ssEffect.SetScale(Vector2.One);
                 * MyGuiManager.GetFullscreenQuad().Draw(ssEffect);
                 */
                MyEffectVolumetricSSAO2 effectVolumetricSsao = MyRender.GetEffect(MyEffects.VolumetricSSAO) as MyEffectVolumetricSSAO2;

                //Blend with SSAO together
                DepthStencilState.None.Apply();

                if (!effectVolumetricSsao.ShowOnlySSAO)
                {
                    MyStateObjects.SSAO_BlendState.Apply();
                }
                else
                {
                    MyRender.CurrentRenderSetup.EnableLights = false;
                    MyMinerGame.Static.GraphicsDevice.Clear(ClearFlags.Target, new SharpDX.ColorBGRA(1.0f), 1, 0);
                    MyStateObjects.SSAO_BlendState.Apply();
                }


                if (effectVolumetricSsao.UseBlur)
                {
                    MyGuiManager.DrawSpriteFast(MyRender.GetRenderTarget(MyRenderTargets.SSAOBlur), 0, 0, MyCamera.Viewport.Width, MyCamera.Viewport.Height, Color.White);
                }
                else
                {
                    MyGuiManager.DrawSpriteFast(MyRender.GetRenderTarget(MyRenderTargets.SSAO), 0, 0, MyCamera.Viewport.Width, MyCamera.Viewport.Height, Color.White);
                }
            }
            break;
            }
            return(source);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Render method is called directly by renderer. Depending on stage, post process can do various things
        /// </summary>
        /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights()
        public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget)
        {
            switch (postProcessStage)
            {
            case PostProcessStage.LODBlend:
            {
                //if (RenderHDRThisFrame())
                //{
                //    (MyRender.GetEffect(MyEffects.BlendLights) as MyEffectBlendLights).CopyEmissivityTechnique = MyEffectBlendLights.Technique.CopyEmissivityHDR;
                //    (MyRender.GetEffect(MyEffects.BlendLights) as MyEffectBlendLights).DefaultTechnique = MyEffectBlendLights.Technique.HDR;
                //    (MyRender.GetEffect(MyEffects.DirectionalLight) as MyEffectDirectionalLight).DefaultTechnique = MyEffectDirectionalLight.Technique.DefaultHDR;
                //    (MyRender.GetEffect(MyEffects.DirectionalLight) as MyEffectDirectionalLight).DefaultWithoutShadowsTechnique = MyEffectDirectionalLight.Technique.WithoutShadowsHDR;
                //    (MyRender.GetEffect(MyEffects.DirectionalLight) as MyEffectDirectionalLight).DefaultNoLightingTechnique = MyEffectDirectionalLight.Technique.NoLightingHDR;

                //    (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultTechnique = MyEffectPointLight.MyEffectPointLightTechnique.DefaultHDR;
                //    (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultPointTechnique = MyEffectPointLight.MyEffectPointLightTechnique.DefaultHDR;
                //    (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultHemisphereTechnique = MyEffectPointLight.MyEffectPointLightTechnique.DefaultHDR;
                //    (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultReflectorTechnique = MyEffectPointLight.MyEffectPointLightTechnique.ReflectorHDR; // unused, dont have instancing
                //    (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultSpotTechnique = MyEffectPointLight.MyEffectPointLightTechnique.SpotHDR;
                //    (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultSpotShadowTechnique = MyEffectPointLight.MyEffectPointLightTechnique.SpotShadowsHDR;

                //    (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultPointInstancedTechnique = MyEffectPointLight.MyEffectPointLightTechnique.PointHDR_Instanced;
                //    (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultHemisphereInstancedTechnique = MyEffectPointLight.MyEffectPointLightTechnique.HemisphereHDR_Instanced;
                //    (MyRender.GetEffect(MyEffects.PointLight) as MyEffectPointLight).DefaultSpotInstancedTechnique = MyEffectPointLight.MyEffectPointLightTechnique.SpotHDR_Instanced;
                //}
                break;
            }

            case PostProcessStage.HDR:
            {
                // if HDR is disabled or some debug rendering display
                // is enabled then skip HDR post process
                if (!RenderHDRThisFrame())
                {
                    return(source);
                }

                BlendState.Opaque.Apply();
                DepthStencilState.None.Apply();
                // RasterizerState.CullNone.Apply(MyMinerGameDX.Static.GraphicsDevice);

                m_thresholdTargets[0] = MyRender.GetRenderTarget(MyRenderTargets.Normals);
                m_thresholdTargets[1] = availableRenderTarget;

                // 1. threshold
                GenerateThreshold(
                    source,
                    MyRender.GetRenderTarget(MyRenderTargets.Diffuse),
                    m_thresholdTargets,
                    MyRender.GetEffect(MyEffects.Threshold) as MyEffectThreshold,
                    Threshold, BloomIntensity, BloomIntensityBackground, Exposure);

                /*
                 * MyMinerGame.SetRenderTarget(null, null,  SetDepthTargetEnum.RestoreDefault);
                 * MyMinerGame.SetRenderTarget(availableRenderTarget, null, SetDepthTargetEnum.RestoreDefault);
                 * MyEffectScreenshot ssEffect = MyRender.GetEffect(MyEffects.Screenshot) as MyEffectScreenshot;
                 * ssEffect.SetSourceTexture(m_thresholdTargets[0]);
                 * ssEffect.SetScale(MinerWarsMath.Vector2.One);
                 * ssEffect.SetTechnique(MyEffectScreenshot.ScreenshotTechniqueEnum.Default);
                 * MyGuiManager.GetFullscreenQuad().Draw(ssEffect);
                 * return availableRenderTarget;
                 */


                // 2. downscale HDR1 -> Downscaled8
                // !! IMPORTANT !! you cannot just switch the function call if you want different downscale
                // Also changing the RTs is necessary (they have fixed dimensions).
                GenerateDownscale4(
                    MyRender.GetRenderTarget(MyRenderTargets.Normals),
                    MyRender.GetRenderTarget(MyRenderTargets.Depth),
                    MyRender.GetRenderTarget(MyRenderTargets.HDR4Threshold),
                    MyRender.GetEffect(MyEffects.Scale) as MyEffectScale);

                /*
                 * // 3?. avg luminance
                 * float dt = (MyMinerGame.TotalGamePlayTimeInMilliseconds - lastTime) / 1000.0f;
                 * lastTime = MyMinerGame.TotalGamePlayTimeInMilliseconds;
                 * CalculateAverageLuminance(
                 *  MyRender.GetRenderTarget(MyRenderTargets.Downscaled8),
                 *  MyRender.GetRenderTarget(MyRenderTargets.Downscaled8Threshold),
                 *  MyRender.GetEffect(MyEffects.Luminance) as MyEffectLuminance,
                 *  MyRender.GetEffect(MyEffects.Scale) as MyEffectScale,
                 *  dt, 0.5f);
                 */

                // 4. blur
                Blur(MyRender.GetRenderTarget(MyRenderTargets.HDR4Threshold),
                     MyRender.GetRenderTarget(MyRenderTargets.HDR4),
                     MyRender.GetEffect(MyEffects.GaussianBlur) as MyEffectGaussianBlur,
                     VerticalBlurAmount, HorizontalBlurAmount);

                // 5. scale blurred to halfsize
                Upscale4To2(
                    MyRender.GetRenderTarget(MyRenderTargets.HDR4Threshold),
                    MyRender.GetRenderTarget(MyRenderTargets.AuxiliaryHalf1010102),
                    MyRender.GetEffect(MyEffects.Scale) as MyEffectScale);

                MyMinerGame.SetRenderTarget(availableRenderTarget, null, SetDepthTargetEnum.RestoreDefault);

                // 6. tonemap + apply bloom
                HDR(
                    source,
                    MyRender.GetRenderTarget(MyRenderTargets.Diffuse),
                    MyRender.GetRenderTarget(MyRenderTargets.AuxiliaryHalf1010102),
                    MyRender.GetEffect(MyEffects.HDR) as MyEffectHDR,
                    0.6f, Exposure);

                return(availableRenderTarget);

                //RenderTarget2D temp = currentFrameAdaptedLuminance;
                //currentFrameAdaptedLuminance = lastFrameAdaptedLuminance;
                //lastFrameAdaptedLuminance = temp;
            }
            }
            return(source);
        }
Ejemplo n.º 14
0
        public static void CreateRenderTargets()
        {
            if (MyRenderConstants.RenderQualityProfile.ForwardRender)
            {
                return;
            }

            MyMwcLog.WriteLine("MyRender.CreateRenderTargets - START");

            int forwardRTWidth      = (int)(MyCamera.ForwardViewport.Width);
            int forwardRTHeight     = (int)(MyCamera.ForwardViewport.Height);
            int forwardRTHalfWidth  = (int)(MyCamera.ForwardViewport.Width / 2);
            int forwardRTHalfHeight = (int)(MyCamera.ForwardViewport.Height / 2);
            int forwardRT4Width     = (int)(MyCamera.ForwardViewport.Width / 4);
            int forwardRT4Height    = (int)(MyCamera.ForwardViewport.Height / 4);
            int forwardRT8Width     = (int)(MyCamera.ForwardViewport.Width / 8);
            int forwardRT8Height    = (int)(MyCamera.ForwardViewport.Height / 8);

            int secondaryShadowMapSize = MyRenderConstants.RenderQualityProfile.SecondaryShadowMapCascadeSize;

            //Largest RT
#if COLOR_SHADOW_MAP_FORMAT
            CreateRenderTarget(MyRenderTargets.ShadowMap, MyShadowRenderer.NumSplits * GetShadowCascadeSize(), GetShadowCascadeSize(), SurfaceFormat.Color, DepthFormat.Depth24Stencil8);
            CreateRenderTarget(MyRenderTargets.SecondaryShadowMap, MyShadowRenderer.NumSplits * secondaryShadowMapSize, secondaryShadowMapSize, SurfaceFormat.Color, DepthFormat.Depth24Stencil8);
#else
            CreateRenderTarget(MyRenderTargets.ShadowMap, MyShadowRenderer.NumSplits * GetShadowCascadeSize(), GetShadowCascadeSize(), Format.R32F);
            CreateRenderTarget(MyRenderTargets.ShadowMapZBuffer, MyShadowRenderer.NumSplits * GetShadowCascadeSize(), GetShadowCascadeSize(), Format.D24S8, Usage.DepthStencil);

            CreateRenderTarget(MyRenderTargets.SecondaryShadowMap, MyShadowRenderer.NumSplits * secondaryShadowMapSize, secondaryShadowMapSize, Format.R32F);
            CreateRenderTarget(MyRenderTargets.SecondaryShadowMapZBuffer, MyShadowRenderer.NumSplits * secondaryShadowMapSize, secondaryShadowMapSize, Format.D24S8, Usage.DepthStencil);
#endif

            //Full viewport RTs
            CreateRenderTarget(MyRenderTargets.Auxiliary0, forwardRTWidth, forwardRTHeight, Format.A8R8G8B8);
            CreateRenderTarget(MyRenderTargets.Auxiliary1, forwardRTWidth, forwardRTHeight, Format.A16B16G16R16F);
            CreateRenderTarget(MyRenderTargets.Auxiliary2, forwardRTWidth, forwardRTHeight, Format.A8R8G8B8);

            CreateRenderTarget(MyRenderTargets.Normals, forwardRTWidth, forwardRTHeight, Format.A8R8G8B8, Usage.RenderTarget | Usage.AutoGenerateMipMap);
            CreateRenderTarget(MyRenderTargets.Diffuse, forwardRTWidth, forwardRTHeight, Format.A8R8G8B8, Usage.RenderTarget | Usage.AutoGenerateMipMap);
            CreateRenderTarget(MyRenderTargets.Depth, forwardRTWidth, forwardRTHeight, Format.A8R8G8B8, Usage.RenderTarget | Usage.AutoGenerateMipMap);
            CreateRenderTarget(MyRenderTargets.ZBuffer, forwardRTWidth, forwardRTHeight, Format.D24S8, Usage.DepthStencil);

            CreateRenderTarget(MyRenderTargets.EnvironmentMap, forwardRTWidth, forwardRTHeight, Format.A8R8G8B8);

            //Half viewport RTs
            CreateRenderTarget(MyRenderTargets.AuxiliaryHalf0, forwardRTHalfWidth, forwardRTHalfHeight, Format.A8R8G8B8);
            CreateRenderTarget(MyRenderTargets.AuxiliaryHalf1010102, forwardRTHalfWidth, forwardRTHalfHeight, Format.A2R10G10B10);

            CreateRenderTarget(MyRenderTargets.DepthHalf, forwardRTHalfWidth, forwardRTHalfHeight, Format.A8R8G8B8);
            CreateRenderTarget(MyRenderTargets.SSAO, forwardRTHalfWidth, forwardRTHalfHeight, Format.A8R8G8B8);
            CreateRenderTarget(MyRenderTargets.SSAOBlur, forwardRTHalfWidth, forwardRTHalfHeight, Format.A8R8G8B8);

            //Quarter viewport RTs
            CreateRenderTarget(MyRenderTargets.AuxiliaryQuarter0, forwardRT4Width, forwardRT4Height, Format.A8R8G8B8);

            if (MyPostProcessHDR.RenderHDR())
            {
                CreateRenderTarget(MyRenderTargets.HDR4, forwardRT4Width, forwardRT4Height, Format.A2R10G10B10);
                CreateRenderTarget(MyRenderTargets.HDR4Threshold, forwardRT4Width, forwardRT4Height, Format.A2R10G10B10);
            }

            //Low size RTs
            CreateRenderTarget(MyRenderTargets.SecondaryCamera, MyCamera.BackwardViewport.Width, MyCamera.BackwardViewport.Height, Format.A8R8G8B8);
            CreateRenderTarget(MyRenderTargets.SecondaryCameraZBuffer, MyCamera.BackwardViewport.Width, MyCamera.BackwardViewport.Height, Format.D24S8, Usage.DepthStencil);
            CreateSpotShadowRT();

            SetEnvironmentRenderTargets();


            m_GBufferDefaultBinding = new Texture[] { (Texture)MyRender.GetRenderTarget(MyRenderTargets.Normals), (Texture)MyRender.GetRenderTarget(MyRenderTargets.Diffuse), (Texture)MyRender.GetRenderTarget(MyRenderTargets.Depth) };
            m_aux0Binding           = new Texture[] { (Texture)MyRender.GetRenderTarget(MyRenderTargets.Auxiliary0) };

            MyMwcLog.WriteLine("MyRender.CreateRenderTargets - END");
        }
Ejemplo n.º 15
0
        public void DebugDraw()
        {
            return;

            MyStateObjects.WireframeRasterizerState.Apply();
            for (int i = 0; i < NumSplits; i++)
            {
                cameraFrustum.Matrix = m_lightCameras[i].CameraSubfrustum;
                cameraFrustum.GetCorners(frustum);

                var tmp = frustum[3];
                frustum[3] = frustum[2];
                frustum[2] = tmp;

                //MyDebugDraw.DrawBoundingFrustum(cameraFrustum, frustumColors[i]);
                MySimpleObjectDraw.OcclusionPlaneDraw(frustum);
                //MyDebugDraw.DrawTriangle(frustum[0], frustum[1], frustum[2], frustumColors[i], frustumColors[i], frustumColors[i]);
                //MyDebugDraw.DrawTriangle(frustum[1], frustum[2], frustum[3], frustumColors[i], frustumColors[i], frustumColors[i]);
            }

            return;

            bool update = false;

            if (MyRender.CurrentRenderSetup.CallerID.Value == MyRenderCallerEnum.Main)
            {
                if (update)
                {
                    mainCamera = MyCamera.GetBoundingFrustum().Matrix;
                }

                for (int i = 0; i < NumSplits; i++)
                {
                    if (update)
                    {
                        Vector4 c = frustumColors[i].ToVector4();

                        //MyDebugDraw.DrawAABBLowRes(ref box, ref c, 1);
                        //BoundingFrustum bf = new BoundingFrustum();

                        //frustumMatrices[i] = m_lightCameras[i].CameraSubfrustum;
                        frustumMatrices[i] = m_lightCameras[i].BoundingFrustum.Matrix;
                    }

                    DebugDrawFrustum(frustumMatrices[i], frustumColors[i]);


                    Vector4 cc = frustumColors[i].ToVector4();

                    BoundingFrustum frma = new BoundingFrustum(frustumMatrices[i]);
                    MyRender.PrepareEntitiesForDraw(ref frma, Vector3.Zero, 0, (MyOcclusionQueryID)(i + 1), m_castingRenderObjects, m_castingCullObjects, m_occlusionQueriesLists[i], ref MyPerformanceCounter.PerCameraDraw.ShadowEntitiesOccluded[i]);
                    BoundingBox aabbFr = new BoundingBox();
                    aabbFr = aabbFr.CreateInvalid();
                    foreach (MyRenderObject ro in m_castingRenderObjects)
                    {
                        BoundingBox vv = ro.GetWorldSpaceAABB();
                        //MyDebugDraw.DrawAABBLowRes(ref vv, ref cc, 1);
                        aabbFr = aabbFr.Include(ref vv);
                    }


                    //MyDebugDraw.DrawAABBLowRes(ref aabbFr, ref cc, 1);
                }

                // DebugDrawFrustum(mainCamera, new Color(1.0f, 1.0f, 1.0f));
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Render method is called directly by renderer. Depending on stage, post process can do various things
        /// </summary>
        /// <param name="postProcessStage">Stage indicating in which part renderer currently is.</param>public override void RenderAfterBlendLights()
        public override Texture Render(PostProcessStage postProcessStage, Texture source, Texture availableRenderTarget)
        {
            switch (postProcessStage)
            {
            case PostProcessStage.AlphaBlended:
            {
                Density    = MySector.GodRaysProperties.Density;
                Weight     = MySector.GodRaysProperties.Weight;
                Decay      = MySector.GodRaysProperties.Decay;
                Exposition = MySector.GodRaysProperties.Exposition;


                var halfRT = MyRender.GetRenderTarget(MyRenderTargets.AuxiliaryHalf0);

                MyMinerGame.SetRenderTarget(halfRT, null);
                BlendState.Opaque.Apply();
                RasterizerState.CullNone.Apply();
                DepthStencilState.None.Apply();

                MyEffectGodRays effectGodRays = MyRender.GetEffect(MyEffects.GodRays) as MyEffectGodRays;

                effectGodRays.SetDiffuseTexture(source);
                effectGodRays.SetDepthTexture(MyRender.GetRenderTarget(MyRenderTargets.Depth));
                effectGodRays.SetFrustumCorners(MyRender.GetShadowRenderer().GetFrustumCorners());
                effectGodRays.SetView(MyCamera.ViewMatrix);
                effectGodRays.SetWorldViewProjection(MyCamera.ViewProjectionMatrix);
                effectGodRays.SetDensity(Density);
                effectGodRays.SetDecay(Decay);
                effectGodRays.SetWeight(Weight * (1 - MySector.FogProperties.FogMultiplier));
                effectGodRays.SetExposition(Exposition);
                //effectGodRays.LightPosition.SetValue(1500f * -MySunGlare.GetSunDirection() * MySunConstants.RENDER_SUN_DISTANCE);
                effectGodRays.SetLightPosition(1500f * -MyRender.Sun.Direction * MySunConstants.RENDER_SUN_DISTANCE);
                effectGodRays.SetLightDirection(MyRender.Sun.Direction);
                effectGodRays.SetCameraPos(MyCamera.Position);

                MyGuiManager.GetFullscreenQuad().Draw(effectGodRays);

                if (ApplyBlur)
                {
                    var auxTarget = MyRender.GetRenderTarget(MyRenderTargets.AuxiliaryHalf1010102);

                    var blurEffect = MyRender.GetEffect(MyEffects.GaussianBlur) as MyEffectGaussianBlur;
                    blurEffect.SetHalfPixel(halfRT.GetLevelDescription(0).Width, halfRT.GetLevelDescription(0).Height);

                    // Apply vertical gaussian blur
                    MyMinerGame.SetRenderTarget(auxTarget, null);
                    blurEffect.BlurAmount = 1;
                    blurEffect.SetSourceTexture(halfRT);
                    blurEffect.SetHeightForVerticalPass(halfRT.GetLevelDescription(0).Height);
                    MyGuiManager.GetFullscreenQuad().Draw(blurEffect);

                    // Apply horizontal gaussian blur
                    MyMinerGame.SetRenderTarget(halfRT, null);
                    blurEffect.BlurAmount = 1;
                    blurEffect.SetSourceTexture(auxTarget);
                    blurEffect.SetWidthForHorisontalPass(auxTarget.GetLevelDescription(0).Width);
                    MyGuiManager.GetFullscreenQuad().Draw(blurEffect);
                }

                // Additive
                MyMinerGame.SetRenderTarget(availableRenderTarget, null);
                //MyMinerGame.Static.GraphicsDevice.Clear(ClearFlags.All, new SharpDX.ColorBGRA(0), 1, 0);
                BlendState.Opaque.Apply();
                MyRender.Blit(source, true);

                var upscaleEffect = MyRender.GetEffect(MyEffects.Scale) as MyEffectScale;
                upscaleEffect.SetScale(new Vector2(2));
                upscaleEffect.SetTechnique(MyEffectScale.Technique.HWScale);
                MyStateObjects.Additive_NoAlphaWrite_BlendState.Apply();

                upscaleEffect.SetSourceTextureMod(halfRT);
                MyGuiManager.GetFullscreenQuad().Draw(upscaleEffect);

                /*
                 * MyMinerGame.SetRenderTarget(availableRenderTarget, null);
                 * var upscaleEffect = MyRender.GetEffect(MyEffects.Scale) as MyEffectScale;
                 * upscaleEffect.SetScale(new Vector2(2));
                 * upscaleEffect.SetTechnique(MyEffectScale.Technique.HWScale);
                 * //MyStateObjects.Additive_NoAlphaWrite_BlendState.Apply();
                 * BlendState.Opaque.Apply();
                 *
                 * upscaleEffect.SetSourceTextureMod(halfRT);
                 * MyGuiManager.GetFullscreenQuad().Draw(upscaleEffect);
                 */
                return(availableRenderTarget);
            }
            break;
            }

            return(source);
        }
Ejemplo n.º 17
0
        void PrepareCascadesForDraw()
        {
            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("UpdateFrustums");

            SunLightDirection = -MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized();
            SunPosition       = 100000 * -SunLightDirection;
            UpdateFrustums();

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();

            // Set casting shadows geometry

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().StartProfilingBlock("update entities");

            int frustumIndex = 0;

            foreach (MyOrthographicCamera lightCamera in m_lightCameras)
            {
                if (m_skip[frustumIndex])
                {
                    frustumIndex++;
                    continue;
                }

                m_renderElementsForShadows.Clear();
                m_transparentRenderElementsForShadows.Clear();
                m_castingRenderObjectsUnique.Clear();

                MyRender.GetRenderProfiler().StartProfilingBlock("OverlapAllBoundingBox");


                BoundingBox     castersBox     = lightCamera.BoundingBox;     //Cannot use unscaled - incorrect result because of different cascade viewport size
                BoundingFrustum castersFrustum = lightCamera.BoundingFrustum; //Cannot use unscaled - incorrect result because of different cascade viewport size
                //MyRender.PrepareEntitiesForDraw(ref castersBox, (MyOcclusionQueryID)(frustumIndex + 1), m_castingRenderObjects, m_occlusionQueriesLists[frustumIndex], ref MyPerformanceCounter.PerCameraDraw.ShadowEntitiesOccluded[frustumIndex]);
                MyRender.PrepareEntitiesForDraw(ref castersFrustum, lightCamera.Position, 1, (MyOcclusionQueryID)(frustumIndex + 1), m_castingRenderObjects, m_castingCullObjects, null, ref MyPerformanceCounter.PerCameraDraw.ShadowEntitiesOccluded[frustumIndex]);

                MyRender.GetRenderProfiler().EndProfilingBlock();

                MyRender.GetRenderProfiler().StartProfilingBlock("m_castingRenderObjects");

                int c       = 0;
                int skipped = 0;

                while (c < m_castingRenderObjects.Count)
                {
                    MyRenderObject renderObject = (MyRenderObject)m_castingRenderObjects[c];
                    MyEntity       entity       = renderObject.Entity;

                    //TODO: Appears in Chinese Escape when reloaded several times
                    //System.Diagnostics.Debug.Assert(!entity.NearFlag);

                    if (RespectCastShadowsFlags)
                    {
                        System.Diagnostics.Debug.Assert(!(entity is MyDummyPoint) && !(entity is MinerWars.AppCode.Game.Entities.WayPoints.MyWayPoint));

                        if ((renderObject.ShadowCastUpdateInterval > 0) && ((MyRender.RenderCounter % renderObject.ShadowCastUpdateInterval) == 0))
                        {
                            renderObject.NeedsResolveCastShadow = true;
                            //We have to leave last value, because true when not casting shadow make radiation to ship
                            // renderObject.CastShadow = true;
                        }

                        if (renderObject.NeedsResolveCastShadow)
                        { //Resolve raycast to sun
                            if (renderObject.CastShadowJob == null)
                            {
                                renderObject.CastShadowJob  = new MyCastShadowJob(entity);
                                renderObject.CastShadowTask = ParallelTasks.Parallel.Start(renderObject.CastShadowJob);
                            }
                            else
                            if (renderObject.CastShadowTask.IsComplete)
                            {
                                renderObject.CastShadow             = renderObject.CastShadowJob.VisibleFromSun;
                                renderObject.CastShadowTask         = new ParallelTasks.Task();
                                renderObject.CastShadowJob          = null;
                                renderObject.NeedsResolveCastShadow = false;
                            }
                        }

                        if (!renderObject.NeedsResolveCastShadow && !renderObject.CastShadow)
                        {
                            m_castingRenderObjects.RemoveAtFast(c);
                            skipped++;
                            continue;
                        }
                    }
                    else
                    {
                        renderObject.NeedsResolveCastShadow = true;
                    }

                    /*
                     * //Skip object depending on their size and cascade
                     * if (entity.WorldVolume.Radius < (frustumIndex + 1) * 5)
                     * {
                     *  m_castingRenderObjects.RemoveAtFast(c);
                     *  continue;
                     * }
                     */

                    if (entity != null)
                    {
                        if (!m_castingRenderObjectsUnique.Contains(renderObject))
                        {
                            m_castingRenderObjectsUnique.Add(renderObject);

                            if (frustumIndex < MyRenderConstants.RenderQualityProfile.ShadowCascadeLODTreshold)
                            {
                                if (entity is MyVoxelMap)
                                {
                                    //(entity as MyVoxelMap).GetRenderElementsForShadowmap(m_renderElementsForShadows, ref castersBox, castersFrustum, MyLodTypeEnum.LOD0, true);
                                    (entity as MyVoxelMap).GetRenderElementsForShadowmap(m_renderElementsForShadows, renderObject.RenderCellCoord.Value, MyLodTypeEnum.LOD0, true);
                                }

                                else
                                if (entity.ModelLod0 != null)
                                {
                                    MyRender.CollectRenderElementsForShadowmap(m_renderElementsForShadows, m_transparentRenderElementsForShadows,
                                                                               entity, entity.ModelLod0);
                                }
                            }
                            else
                            {
                                if (entity is MyVoxelMap)
                                {
                                    (entity as MyVoxelMap).GetRenderElementsForShadowmap(m_renderElementsForShadows, renderObject.RenderCellCoord.Value, MyLodTypeEnum.LOD1, true);
                                }
                                else
                                if (entity.ModelLod1 != null)
                                {
                                    MyRender.CollectRenderElementsForShadowmap(m_renderElementsForShadows, m_transparentRenderElementsForShadows,
                                                                               entity, entity.ModelLod1);
                                }
                            }
                        }
                    }

                    c++;
                }

                MyRender.GetRenderProfiler().EndProfilingBlock();

                //Sorting VBs to minimize VB switches
                m_renderElementsForShadows.Sort(m_shadowElementsComparer);

                lightCamera.CastingRenderElements = m_renderElementsForShadows;

                MyPerformanceCounter.PerCameraDraw.RenderElementsInShadows += m_renderElementsForShadows.Count;

                frustumIndex++;
            }

            MinerWars.AppCode.Game.Render.MyRender.GetRenderProfiler().EndProfilingBlock();
        }