Exemplo n.º 1
0
        public static void Initialize()
        {
            mieRT      = RenderingFunctions.CreateRenderTarget(Format.R16G16B16A16_Float, 128, 64);
            rayleighRT = RenderingFunctions.CreateRenderTarget(Format.R16G16B16A16_Float, 128, 64);
            // SpriteDrawer.AddInstance(rayleighRT.srv, 0.0f, 0.0f);


            moonTex          = TextureLoader.LoadTexture("sky/moon.png");
            glowTex          = TextureLoader.LoadTexture("sky/moonglow.png");
            starsTex         = TextureLoader.LoadTexture("sky/starfield.png");
            skyClouds1       = TextureLoader.LoadTexture("sky/clouds1.png");
            skyClouds2       = TextureLoader.LoadTexture("sky/clouds2.png");
            skyBoxCloudsMesh = WorldData.GetObject("skyDomeClouds") as Model;

            GenerateDome();
            GenerateMoon();



            lensFlare = new LensFlare();
            lensFlare.Initialize();

            SetSettings(WorldData.GetObject("defaultWeather") as WeatherSetting);
            Rain.Initialize();
            Snow.Initialize();
            Wind.Initalize();
            Lightning.Initalize();
        }
Exemplo n.º 2
0
        public static void Dispose()
        {
            mieRT.Dispose();
            rayleighRT.Dispose();
            if (skyBoxCloudsMesh != null)
            {
                skyBoxCloudsMesh.Dispose();
            }

            if (moonTex != null && !moonTex.Disposed)
            {
                moonTex.Dispose();
            }
            if (glowTex != null && !glowTex.Disposed)
            {
                glowTex.Dispose();
            }
            if (starsTex != null && !starsTex.Disposed)
            {
                starsTex.Dispose();
            }
            if (skyClouds1 != null && !skyClouds1.Disposed)
            {
                skyClouds1.Dispose();
            }
            if (skyClouds2 != null && !skyClouds2.Disposed)
            {
                skyClouds2.Dispose();
            }


            if (domeVerts != null && !domeVerts.Disposed)
            {
                domeVerts.Dispose();
            }
            if (domeIndices != null && !domeIndices.Disposed)
            {
                domeIndices.Dispose();
            }
            if (moonVerts != null && !moonVerts.Disposed)
            {
                moonVerts.Dispose();
            }
            if (moonIndices != null && !moonIndices.Disposed)
            {
                moonIndices.Dispose();
            }

            if (lensFlare != null)
            {
                lensFlare.Dispose();
            }
            Rain.Dispose();
            Snow.Dispose();
        }
Exemplo n.º 3
0
        public static void SetSettings(WeatherSetting s)
        {
            if (s == null)
            {
                s = new WeatherSetting();
            }
            settings = s;

            Rain.IsOn      = settings.IsRainOn;
            Snow.IsOn      = settings.IsSnowOn;
            Lightning.IsOn = settings.IsLightningOn;

            Rain.SetSettings(settings.RainSettings);
            Snow.SetSettings(settings.SnowSettings);
            setLengths();
        }
Exemplo n.º 4
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();
            }
        }