Esempio n. 1
0
        public static void Draw(RenderTargetView rtv, DepthStencilView dsv, bool renderReflection)
        {
            //if (previousTheta != Theta || previousPhi != fPhi)
            if (!renderReflection)
            {
                UpdateMieRayleighTextures(rtv, dsv);
            }

            SunColor = GetSunColor(-Theta, 2);

            Shader scatterEffect = WorldData.GetObject("scatter.fx") as Shader;

            if (scatterEffect == null)
            {
                return;
            }
            EffectTechnique tech = scatterEffect.EffectObj.GetTechniqueByName("Render");

            if (renderReflection)
            {
                tech = scatterEffect.EffectObj.GetTechniqueByName("RenderReflection");
            }

            Game.Device.InputAssembler.SetPrimitiveTopology(PrimitiveTopology.TriangleList);
            Game.Device.InputAssembler.SetIndexBuffer(domeIndices, Format.R16_UInt, 0);
            Game.Device.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(domeVerts, 20, 0));
            EffectPass  p1     = tech.GetPassByIndex(0);
            InputLayout layout = ShaderHelper.ConstructInputLayout(MeshInputElements10.PosTex, p1.Description.Signature);

            Game.Device.InputAssembler.SetInputLayout(layout);

            scatterEffect.GetVar("cameraPosition").AsVector().Set(new Vector4(Camera.Position, 1));
            scatterEffect.GetVar("txMie").AsResource().SetResource(mieRT.srv);
            scatterEffect.GetVar("txRayleigh").AsResource().SetResource(rayleighRT.srv);
            if (renderReflection)
            {
                scatterEffect.GetVar("WorldViewProjection").AsMatrix().SetMatrix(Matrix.Scaling(1, -1, 1) * Matrix.Translation(Camera.Position) * Camera.ViewMatrix * Camera.ProjectionMatrix);
            }
            else
            {
                scatterEffect.GetVar("WorldViewProjection").AsMatrix().SetMatrix(Matrix.Translation(Camera.Position) * Camera.ViewMatrix * Camera.ProjectionMatrix);
            }
            scatterEffect.GetVar("v3SunDir").AsVector().Set(-LightDirection);

            if (settings != null && settings.SkySettings != null)
            {
                scatterEffect.GetVar("NumSamples").AsScalar().Set(settings.SkySettings.NumSamples);
                scatterEffect.GetVar("fExposure").AsScalar().Set(settings.SkySettings.Exposure);
            }
            scatterEffect.GetVar("StarsTex").AsResource().SetResource(starsTex);
            if (Theta < Math.PI / 2.0f || Theta > 3.0f * Math.PI / 2.0f)
            {
                scatterEffect.GetVar("starIntensity").AsScalar().Set((float)Math.Abs(Math.Sin(Theta + (float)Math.PI / 2.0f)));
            }
            else
            {
                scatterEffect.GetVar("starIntensity").AsScalar().Set(0.0f);
            }

            p1.Apply();
            Game.Device.DrawIndexed(DISize * 3, 0, 0);

            UnbindMRT(tech, scatterEffect.GetVar("txMie").AsResource(), scatterEffect.GetVar("txRayleigh").AsResource());


            if (!renderReflection)
            {
                DrawMoon();
            }
            if (!renderReflection)
            {
                DrawClouds(renderReflection);
            }
            if (!renderReflection)
            {
                lensFlare.Draw();
            }


            previousTheta = Theta;
            previousPhi   = fPhi;

            if (!renderReflection)
            {
                Rain.RenderParticles();
                Snow.RenderParticles();
            }
        }