Пример #1
0
        /// <summary>
        /// Creates a new effect pass.
        /// Marked as internal to prevent users from creating it.
        /// </summary>
        internal SilverlightEffectPass(string name, GraphicsDevice device, Stream vertexShaderCode, Stream pixelShaderCode, Stream vertexShaderParameters, Stream pixelShaderParameters)
        {
            this.device = device;
            Name        = name;

            // Assembly codes
            Dictionary <string, SilverlightEffectInternalParameter> tempParameters = new Dictionary <string, SilverlightEffectInternalParameter>();

            // Shaders
            if (vertexShaderCode != null)
            {
                vertexShader = VertexShader.FromStream(device, vertexShaderCode);
                ExtractConstantsRegisters(vertexShaderParameters, false, tempParameters);
            }

            if (pixelShaderCode != null)
            {
                pixelShader = PixelShader.FromStream(device, pixelShaderCode);
                ExtractConstantsRegisters(pixelShaderParameters, true, tempParameters);
            }

            parameters = new List <SilverlightEffectInternalParameter>(tempParameters.Values);

            for (int index = 0; index < SamplerStatesCount; index++)
            {
                samplerStates[index] = new SilverlightEffectSamplerState(index);
            }
        }
Пример #2
0
        public override void LoadContent()
        {
            // Load mesh
            mesh = new SpherePrimitive(1.0f, 50);

            // Load effects
            earthVertexShader           = VertexShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/EarthVS.vs", UriKind.Relative)).Stream);
            earthPixelShader            = PixelShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/EarthPS.ps", UriKind.Relative)).Stream);
            atmosphereVertexShader      = VertexShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/AtmosphereVS.vs", UriKind.Relative)).Stream);
            cloudsPixelShader           = PixelShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/CloudsPS.ps", UriKind.Relative)).Stream);
            lowerAtmospherePixelShader  = PixelShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/AtmosphereLowerPS.ps", UriKind.Relative)).Stream);
            upperAtmospherePixelShader  = PixelShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/AtmosphereUpperPS.ps", UriKind.Relative)).Stream);
            upperAtmosphereVertexShader = VertexShader.FromStream(GraphicsDeviceManager.Current.GraphicsDevice, Application.GetResourceStream(new Uri(@"/SLARToolKit3DSample;component/Shaders/AtmosphereUpperVS.vs", UriKind.Relative)).Stream);

            // Load textures
            atmosphereTexture  = ContentManager.LoadBitmapAndMipFromResource("Textures/Earth/EarthAtmosphere.png");
            cloudTexture       = ContentManager.LoadBitmapAndMipFromResource("Textures/Earth/EarthClouds.png");
            dayTexture         = ContentManager.LoadBitmapAndMipFromResource("Textures/Earth/EarthDay.jpg");
            maskTexture        = ContentManager.LoadBitmapAndMipFromResource("Textures/Earth/EarthMask.png");
            nightTexture       = ContentManager.LoadBitmapAndMipFromResource("Textures/Earth/EarthNight.png");
            nightLightsTexture = ContentManager.LoadBitmapAndMipFromResource("Textures/Earth/EarthNightLights.png");
            normalTexture      = ContentManager.LoadBitmapAndMipFromResource("Textures/Earth/EarthNormal.jpg");

            // Set initial state
            depthState = new DepthStencilState
            {
                DepthBufferEnable      = true,
                DepthBufferWriteEnable = true,
                DepthBufferFunction    = CompareFunction.LessEqual
            };

            cloudBlendState = new BlendState()
            {
                ColorSourceBlend      = Blend.SourceAlpha,
                AlphaSourceBlend      = Blend.SourceAlpha,
                ColorDestinationBlend = Blend.One,
                AlphaDestinationBlend = Blend.One
            };

            atmosphereBlendState = new BlendState()
            {
                ColorSourceBlend      = Blend.SourceAlpha,
                AlphaSourceBlend      = Blend.SourceAlpha,
                ColorDestinationBlend = Blend.One,
                AlphaDestinationBlend = Blend.One
            };

            // Load Moon data
            Moon.LoadContent();
        }