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, }; // s0: DayTexture = Moon // s1: NormalTexture = MoonNormal gd.Textures[0] = moonTexture; gd.Textures[1] = moonNormalTexture; 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(moonVertexShader); gd.SetPixelShader(moonPixelShader); gd.DepthStencilState = depthState; gd.BlendState = BlendState.Opaque; gd.RasterizerState = ccwState; mesh.Draw(gd); }
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); }
public abstract void Draw(GraphicsDevice gd, TimeSpan time, Camera camera);
public override void Draw(GraphicsDevice gd, TimeSpan time, Camera camera) { if(!IsVisible) { return; } cwState = new RasterizerState { CullMode = CullMode.CullClockwiseFace, FillMode = ShowWireframe ? FillMode.WireFrame : FillMode.Solid, }; ccwState = new RasterizerState { CullMode = CullMode.CullCounterClockwiseFace, FillMode = ShowWireframe ? FillMode.WireFrame : FillMode.Solid, }; // Pass 1 - Draw Earth // s0: DayTexture = EarthDay // s1: NightTexture = EarthNight // s2: NightLightsTexture = EarthNightLights // s3: NormalTexture = EarthNormal // s4: MaskTexture = EarthMask gd.Textures[0] = dayTexture; gd.Textures[1] = nightTexture; gd.Textures[2] = nightLightsTexture; gd.Textures[3] = normalTexture; gd.Textures[4] = maskTexture; var worldMatrix = Transform; worldMatrix = Matrix.CreateScale((float) Scale) * worldMatrix; earthConstants.WorldMatrix = worldMatrix; earthConstants.WorldInverseTransposeMatrix = Matrix.Transpose(Matrix.Invert(worldMatrix)); earthConstants.WorldViewProjectionMatrix = worldMatrix * camera.ViewTransform * camera.ProjectionTransform; earthConstants.ViewInverseMatrix = Matrix.Invert(camera.ViewTransform); earthConstants.TotalSeconds.X = (float)time.TotalSeconds; earthConstants.LightPos = new Vector4(LightPosition, 1); gd.SetVertexShaderConstantFloat4(0, ref earthConstants); var showWireframe = new Vector4(ShowWireframe ? 1.0f : 0.0f, 0f, 0f, 0f); gd.SetPixelShaderConstantFloat4(0, ref showWireframe); gd.SetVertexShader(earthVertexShader); gd.SetPixelShader(earthPixelShader); gd.DepthStencilState = depthState; gd.BlendState = BlendState.Opaque; gd.RasterizerState = ccwState; mesh.Draw(gd); if (AtmosphereVisible) { // // Pass 2 - Draw clouds // // s0: CloudTexture = EarthClouds gd.Textures[0] = cloudTexture; gd.SetVertexShader(atmosphereVertexShader); gd.SetPixelShader(cloudsPixelShader); gd.BlendState = cloudBlendState; mesh.Draw(gd); // // Pass 3 - Lower atmosphere // // s0: AtmosphereTexture = EarthAtmosphere gd.Textures[0] = atmosphereTexture; gd.SetPixelShader(lowerAtmospherePixelShader); gd.BlendState = atmosphereBlendState; mesh.Draw(gd); // // Pass 4 - Upper atmosphere // gd.SetVertexShader(upperAtmosphereVertexShader); gd.SetPixelShader(upperAtmospherePixelShader); gd.RasterizerState = cwState; mesh.Draw(gd); } // Rotate and draw Moon var transform = Matrix.CreateTranslation(0, 0, 1f); transform *= Matrix.CreateRotationY((float)time.TotalSeconds * 0.05f); transform *= worldMatrix; Moon.Transform = transform; Moon.Draw(gd, time, camera); }