Ejemplo n.º 1
0
        public override void Draw(GraphicsDevice gd, TimeSpan time, Camera camera)
        {
            if (!IsVisible)
            {
                return;
            }

            ccwState = new RasterizerState
            {
                CullMode = CullMode.CullCounterClockwiseFace,
                FillMode = ShowWireframe ? FillMode.WireFrame : FillMode.Solid,
            };


            gd.Textures[0] = sunTexture;
            gd.Textures[1] = turbulence1Texture;
            gd.Textures[2] = turbulence2Texture;
            gd.Textures[3] = gradientTexture;

            gd.SamplerStates[1] = SamplerState.AnisotropicWrap;
            gd.SamplerStates[2] = SamplerState.AnisotropicWrap;
            gd.SamplerStates[3] = SamplerState.LinearClamp;


            //
            // Pass 1, Sun map
            //
            var transform = Transform;

            transform = Matrix.CreateScale((float)Scale) * transform;
            shaderConstants.WorldMatrix = transform;
            shaderConstants.WorldInverseTransposeMatrix = Matrix.Transpose(Matrix.Invert(transform));
            shaderConstants.WorldViewProjectionMatrix   = transform * camera.ViewTransform * camera.ProjectionTransform;
            shaderConstants.ViewInverseMatrix           = Matrix.Invert(camera.ViewTransform);
            shaderConstants.TotalSeconds.X = (float)time.TotalSeconds;
            shaderConstants.LightPos       = new Vector4(LightPosition, 1);
            gd.SetVertexShaderConstantFloat4(0, ref shaderConstants);

            var showWireframe = new Vector4(ShowWireframe ? 1 : 0);

            gd.SetPixelShaderConstantFloat4(0, ref showWireframe);

            gd.SetVertexShader(sunVertexShader);
            gd.SetPixelShader(sunPixelShader);

            gd.DepthStencilState = depthState;
            gd.BlendState        = BlendState.Opaque;
            gd.RasterizerState   = ccwState;

            // Perform refraction mapping
            if (ReflectionTexture != null)
            {
                gd.Textures[0] = ReflectionTexture;
                gd.SetPixelShader(refractionPixelShader);
            }
            mesh.Draw(gd);
        }