public TerrainRayCasting() { _window = Device.CreateWindow(800, 600, "Chapter 11: Terrain Ray Casting"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _window.Keyboard.KeyDown += OnKeyDown; _sceneState = new SceneState(); _sceneState.Camera.PerspectiveFarPlaneDistance = 4096; _clearState = new ClearState(); /////////////////////////////////////////////////////////////////// TerrainTile terrainTile = TerrainTile.FromBitmap(new Bitmap(@"ps-e.lg.png")); _tile = new RayCastedTerrainTile(terrainTile); _tile.HeightExaggeration = 30; /////////////////////////////////////////////////////////////////// double tileRadius = Math.Max(terrainTile.Resolution.X, terrainTile.Resolution.Y) * 0.5; _camera = new CameraLookAtPoint(_sceneState.Camera, _window, Ellipsoid.UnitSphere); _camera.CenterPoint = new Vector3D(terrainTile.Resolution.X * 0.5, terrainTile.Resolution.Y * 0.5, 0.0); _camera.MinimumRotateRate = 1.0; _camera.MaximumRotateRate = 1.0; _camera.RotateRateRangeAdjustment = 0.0; _camera.RotateFactor = 0.0; _sceneState.Camera.ZoomToTarget(tileRadius); /////////////////////////////////////////////////////////////////// _hudFont = new Font("Arial", 16); _hud = new HeadsUpDisplay(); _hud.Color = Color.Black; UpdateHUD(); }
public GlobeRayCasting() { Ellipsoid globeShape = Ellipsoid.ScaledWgs84; _window = Device.CreateWindow(800, 600, "Chapter 4: Globe Ray Casting"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _sceneState = new SceneState(); _camera = new CameraLookAtPoint(_sceneState.Camera, _window, globeShape); _clearState = new ClearState(); _window.Keyboard.KeyDown += delegate(object sender, KeyboardKeyEventArgs e) { if (e.Key == KeyboardKey.P) { CenterCameraOnPoint(); } else if (e.Key == KeyboardKey.C) { CenterCameraOnGlobeCenter(); } }; Bitmap bitmap = new Bitmap("NE2_50M_SR_W_4096.jpg"); _texture = Device.CreateTexture2D(bitmap, TextureFormat.RedGreenBlue8, false); _globe = new RayCastedGlobe(_window.Context); _globe.Shape = globeShape; _globe.Texture = _texture; _globe.ShowWireframeBoundingBox = true; _sceneState.Camera.ZoomToTarget(globeShape.MaximumRadius); }
public EllipsoidSurfaceNormals() { _globeShape = new Ellipsoid(1, 1, _semiMinorAxis); _window = Device.CreateWindow(800, 600, "Chapter 2: Ellipsoid Surface Normals"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _window.Keyboard.KeyDown += OnKeyDown; _sceneState = new SceneState(); _camera = new CameraLookAtPoint(_sceneState.Camera, _window, _globeShape); _instructions = new HeadsUpDisplay(); _instructions.Texture = Device.CreateTexture2D( Device.CreateBitmapFromText("Up - Increase semi-minor axis\nDown - Decrease semi-minor axis", new Font("Arial", 24)), TextureFormat.RedGreenBlueAlpha8, false); _instructions.Color = Color.Black; _clearState = new ClearState(); CreateScene(); /////////////////////////////////////////////////////////////////// _sceneState.Camera.Eye = Vector3D.UnitY; _sceneState.Camera.ZoomToTarget(2 * _globeShape.MaximumRadius); }
public DepthBufferPrecision() { _globeShape = Ellipsoid.Wgs84; _nearDistance = 1; _cubeRootFarDistance = 300; _window = Device.CreateWindow(800, 600, "Chapter 6: Depth Buffer Precision"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _window.Keyboard.KeyUp += OnKeyUp; _window.Keyboard.KeyDown += OnKeyDown; _sceneState = new SceneState(); _sceneState.DiffuseIntensity = 0.45f; _sceneState.SpecularIntensity = 0.05f; _sceneState.AmbientIntensity = 0.5f; _camera = new CameraLookAtPoint(_sceneState.Camera, _window, _globeShape); _sceneState.Camera.ZoomToTarget(_globeShape.MaximumRadius); /////////////////////////////////////////////////////////////////// _globe = new TessellatedGlobe(); _globe.Shape = _globeShape; _globe.NumberOfSlicePartitions = 64; _globe.NumberOfStackPartitions = 32; _globe.Texture = Device.CreateTexture2D(new Bitmap("world_topo_bathy_200411_3x5400x2700.jpg"), TextureFormat.RedGreenBlue8, false); _globe.Textured = true; _plane = new Plane(_window.Context); _plane.XAxis = 0.6 * _globeShape.MaximumRadius * Vector3D.UnitX; _plane.YAxis = 0.6 * _globeShape.MinimumRadius * Vector3D.UnitZ; _plane.OutlineWidth = 3; _cubeRootPlaneHeight = 100.0; UpdatePlaneOrigin(); _viewportQuad = new ViewportQuad(_window.Context, null); _framebuffer = _window.Context.CreateFramebuffer(); _depthFormatIndex = 1; _depthTestLess = true; _logarithmicDepthConstant = 1; UpdatePlanesAndDepthTests(); _clearState = new ClearState(); /////////////////////////////////////////////////////////////////// _hudFont = new Font("Arial", 16); _hud = new HeadsUpDisplay(); _hud.Color = Color.Blue; UpdateHUD(); }
public Multithreading() { Ellipsoid globeShape = Ellipsoid.ScaledWgs84; _workerWindow = Device.CreateWindow(1, 1); _window = Device.CreateWindow(800, 600, "Chapter 10: Multithreading"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _sceneState = new SceneState(); _camera = new CameraLookAtPoint(_sceneState.Camera, _window, globeShape); _clearState = new ClearState(); Bitmap bitmap = new Bitmap("NE2_50M_SR_W_4096.jpg"); _texture = Device.CreateTexture2D(bitmap, TextureFormat.RedGreenBlue8, false); _globe = new RayCastedGlobe(_window.Context); _globe.Shape = globeShape; _globe.Texture = _texture; _globe.UseAverageDepth = true; /////////////////////////////////////////////////////////////////// _doneQueue.MessageReceived += ProcessNewShapefile; _requestQueue.MessageReceived += new ShapefileWorker(_workerWindow.Context, globeShape, _doneQueue).Process; // 2ND_EDITION: Draw order _requestQueue.Post(new ShapefileRequest("110m_admin_0_countries.shp", new ShapefileAppearance())); _requestQueue.Post(new ShapefileRequest("110m_admin_1_states_provinces_lines_shp.shp", new ShapefileAppearance())); _requestQueue.Post(new ShapefileRequest("airprtx020.shp", new ShapefileAppearance() { Bitmap = new Bitmap("paper-plane--arrow.png") })); _requestQueue.Post(new ShapefileRequest("amtrakx020.shp", new ShapefileAppearance() { Bitmap = new Bitmap("car-red.png") })); _requestQueue.Post(new ShapefileRequest("110m_populated_places_simple.shp", new ShapefileAppearance() { Bitmap = new Bitmap("032.png") })); #if SINGLE_THREADED _requestQueue.ProcessQueue(); #else _requestQueue.StartInAnotherThread(); #endif /////////////////////////////////////////////////////////////////// _sceneState.Camera.ZoomToTarget(globeShape.MaximumRadius); }
public Jitter() { _window = Device.CreateWindow(800, 600, "Chapter 5: Jitter"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _window.Keyboard.KeyUp += OnKeyUp; _sceneState = new SceneState(); _clearState = new ClearState(); _hudFont = new Font("Arial", 16); _hud = new HeadsUpDisplay(); _hud.Color = Color.Black; CreateCamera(); CreateAlgorithm(); }
public ClipmapTerrainOnGlobe() { _window = Device.CreateWindow(800, 600, "Chapter 13: Clipmap Terrain on a Globe"); _ellipsoid = Ellipsoid.Wgs84; WorldWindTerrainSource terrainSource = new WorldWindTerrainSource(); EsriRestImagery imagery = new EsriRestImagery(); _clipmap = new GlobeClipmapTerrain(_window.Context, terrainSource, imagery, _ellipsoid, 511); _clipmap.HeightExaggeration = 1.0f; _sceneState = new SceneState(); _sceneState.DiffuseIntensity = 0.90f; _sceneState.SpecularIntensity = 0.05f; _sceneState.AmbientIntensity = 0.05f; _sceneState.Camera.FieldOfViewY = Math.PI / 3.0; _clearState = new ClearState(); _clearState.Color = Color.White; _sceneState.Camera.PerspectiveNearPlaneDistance = 0.000001 * _ellipsoid.MaximumRadius; _sceneState.Camera.PerspectiveFarPlaneDistance = 10.0 * _ellipsoid.MaximumRadius; _sceneState.SunPosition = new Vector3D(200000, 300000, 200000) * _ellipsoid.MaximumRadius; _lookCamera = new CameraLookAtPoint(_sceneState.Camera, _window, _ellipsoid); _lookCamera.Range = 1.5 * _ellipsoid.MaximumRadius; _globe = new RayCastedGlobe(_window.Context); _globe.Shape = _ellipsoid; Bitmap bitmap = new Bitmap("NE2_50M_SR_W_4096.jpg"); _globe.Texture = Device.CreateTexture2D(bitmap, TextureFormat.RedGreenBlue8, false); _clearDepth = new ClearState(); _clearDepth.Buffers = ClearBuffers.DepthBuffer | ClearBuffers.StencilBuffer; _window.Keyboard.KeyDown += OnKeyDown; _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _window.PreRenderFrame += OnPreRenderFrame; _hudFont = new Font("Arial", 16); _hud = new HeadsUpDisplay(); _hud.Color = Color.Blue; UpdateHUD(); }
public Curves() { _semiMinorAxis = Ellipsoid.ScaledWgs84.Radii.Z; SetShape(); _window = Device.CreateWindow(800, 600, "Chapter 2: Curves"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _window.Keyboard.KeyDown += OnKeyDown; _sceneState = new SceneState(); _camera = new CameraLookAtPoint(_sceneState.Camera, _window, _globeShape); _clearState = new ClearState(); _texture = Device.CreateTexture2D(new Texture2DDescription(1, 1, TextureFormat.RedGreenBlue8)); WritePixelBuffer pixelBuffer = Device.CreateWritePixelBuffer(PixelBufferHint.Stream, 3); pixelBuffer.CopyFromSystemMemory(new byte[] { 0, 255, 127 }); _texture.CopyFromBuffer(pixelBuffer, ImageFormat.RedGreenBlue, ImageDatatype.UnsignedByte, 1); _instructions = new HeadsUpDisplay(); _instructions.Color = Color.Black; _sampledPoints = new BillboardCollection(_window.Context); _sampledPoints.Texture = Device.CreateTexture2D(Device.CreateBitmapFromPoint(8), TextureFormat.RedGreenBlueAlpha8, false); _sampledPoints.DepthTestEnabled = false; _ellipsoid = new RayCastedGlobe(_window.Context); _ellipsoid.Texture = _texture; _polyline = new Polyline(); _polyline.Width = 3; _polyline.DepthTestEnabled = false; _plane = new Plane(_window.Context); _plane.Origin = Vector3D.Zero; _plane.OutlineWidth = 3; CreateScene(); /////////////////////////////////////////////////////////////////// _sceneState.Camera.Eye = Vector3D.UnitY; _sceneState.Camera.ZoomToTarget(2 * _globeShape.MaximumRadius); }
public LatitudeLongitudeGrid() { Ellipsoid globeShape = Ellipsoid.Wgs84; _window = Device.CreateWindow(800, 600, "Chapter 4: Latitude Longitude Grid"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _sceneState = new SceneState(); _camera = new CameraLookAtPoint(_sceneState.Camera, _window, globeShape); _clearState = new ClearState(); _sceneState.Camera.PerspectiveNearPlaneDistance = 0.01 * globeShape.MaximumRadius; _sceneState.Camera.PerspectiveFarPlaneDistance = 10.0 * globeShape.MaximumRadius; _sceneState.Camera.ZoomToTarget(globeShape.MaximumRadius); /////////////////////////////////////////////////////////////////// IList<GridResolution> gridResolutions = new List<GridResolution>(); gridResolutions.Add(new GridResolution( new Interval(0, 1000000, IntervalEndpoint.Closed, IntervalEndpoint.Open), new Vector2D(0.005, 0.005))); gridResolutions.Add(new GridResolution( new Interval(1000000, 2000000, IntervalEndpoint.Closed, IntervalEndpoint.Open), new Vector2D(0.01, 0.01))); gridResolutions.Add(new GridResolution( new Interval(2000000, 20000000, IntervalEndpoint.Closed, IntervalEndpoint.Open), new Vector2D(0.05, 0.05))); gridResolutions.Add(new GridResolution( new Interval(20000000, double.MaxValue, IntervalEndpoint.Closed, IntervalEndpoint.Open), new Vector2D(0.1, 0.1))); _globe = new LatitudeLongitudeGridGlobe(_window.Context); _globe.Texture = Device.CreateTexture2D(new Bitmap("NE2_50M_SR_W_4096.jpg"), TextureFormat.RedGreenBlue8, false); _globe.Shape = globeShape; _globe.GridResolutions = new GridResolutionCollection(gridResolutions); /////////////////////////////////////////////////////////////////// Vector3D vancouver = globeShape.ToVector3D(new Geodetic3D(Trig.ToRadians(-123.06), Trig.ToRadians(49.13), 0)); TextureAtlas atlas = new TextureAtlas(new Bitmap[] { new Bitmap("building.png"), Device.CreateBitmapFromText("Vancouver", new Font("Arial", 24)) }); _vancouverLabel = new BillboardCollection(_window.Context); _vancouverLabel.Texture = Device.CreateTexture2D(atlas.Bitmap, TextureFormat.RedGreenBlueAlpha8, false); _vancouverLabel.DepthTestEnabled = false; _vancouverLabel.Add(new Billboard() { Position = vancouver, TextureCoordinates = atlas.TextureCoordinates[0] }); _vancouverLabel.Add(new Billboard() { Position = vancouver, TextureCoordinates = atlas.TextureCoordinates[1], HorizontalOrigin = HorizontalOrigin.Left }); atlas.Dispose(); }
public NightLights() { _window = Device.CreateWindow(800, 600, "Chapter 4: Night Lights"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _sceneState = new SceneState(); _camera = new CameraLookAtPoint(_sceneState.Camera, _window, Ellipsoid.ScaledWgs84); _clearState = new ClearState(); string vs = @"#version 330 layout(location = og_positionVertexLocation) in vec4 position; out vec3 worldPosition; out vec3 positionToLight; out vec3 positionToEye; uniform mat4 og_modelViewPerspectiveMatrix; uniform vec3 og_cameraEye; uniform vec3 og_sunPosition; void main() { gl_Position = og_modelViewPerspectiveMatrix * position; worldPosition = position.xyz; positionToLight = og_sunPosition - worldPosition; positionToEye = og_cameraEye - worldPosition; }"; string fs = @"#version 330 in vec3 worldPosition; in vec3 positionToLight; in vec3 positionToEye; out vec3 fragmentColor; uniform vec4 og_diffuseSpecularAmbientShininess; uniform sampler2D og_texture0; // Day uniform sampler2D og_texture1; // Night uniform float u_blendDuration; uniform float u_blendDurationScale; float LightIntensity(vec3 normal, vec3 toLight, vec3 toEye, float diffuseDot, vec4 diffuseSpecularAmbientShininess) { vec3 toReflectedLight = reflect(-toLight, normal); float diffuse = max(diffuseDot, 0.0); float specular = max(dot(toReflectedLight, toEye), 0.0); specular = pow(specular, diffuseSpecularAmbientShininess.w); return (diffuseSpecularAmbientShininess.x * diffuse) + (diffuseSpecularAmbientShininess.y * specular) + diffuseSpecularAmbientShininess.z; } vec2 ComputeTextureCoordinates(vec3 normal) { return vec2(atan(normal.y, normal.x) * og_oneOverTwoPi + 0.5, asin(normal.z) * og_oneOverPi + 0.5); } vec3 NightColor(vec3 normal) { return texture(og_texture1, ComputeTextureCoordinates(normal)).rgb; } vec3 DayColor(vec3 normal, vec3 toLight, vec3 toEye, float diffuseDot, vec4 diffuseSpecularAmbientShininess) { float intensity = LightIntensity(normal, toLight, toEye, diffuseDot, diffuseSpecularAmbientShininess); return intensity * texture(og_texture0, ComputeTextureCoordinates(normal)).rgb; } void main() { vec3 normal = normalize(worldPosition); vec3 toLight = normalize(positionToLight); float diffuse = dot(toLight, normal); if (diffuse > u_blendDuration) { fragmentColor = DayColor(normal, toLight, normalize(positionToEye), diffuse, og_diffuseSpecularAmbientShininess); } else if (diffuse < -u_blendDuration) { fragmentColor = NightColor(normal); } else { vec3 night = NightColor(normal); vec3 day = DayColor(normal, toLight, normalize(positionToEye), diffuse, og_diffuseSpecularAmbientShininess); fragmentColor = mix(night, day, (diffuse + u_blendDuration) * u_blendDurationScale); } }"; ShaderProgram sp = Device.CreateShaderProgram(vs, fs); float blendDurationScale = 0.1f; ((Uniform<float>)sp.Uniforms["u_blendDuration"]).Value = blendDurationScale; ((Uniform<float>)sp.Uniforms["u_blendDurationScale"]).Value = 1 / (2 * blendDurationScale); Mesh mesh = SubdivisionEllipsoidTessellator.Compute(Ellipsoid.ScaledWgs84, 5, SubdivisionEllipsoidVertexAttributes.Position); VertexArray va = _window.Context.CreateVertexArray(mesh, sp.VertexAttributes, BufferHint.StaticDraw); _primitiveType = mesh.PrimitiveType; RenderState renderState = new RenderState(); renderState.FacetCulling.FrontFaceWindingOrder = mesh.FrontFaceWindingOrder; _drawState = new DrawState(renderState, sp, va); Bitmap dayBitmap = new Bitmap("world.topo.200412.3x5400x2700.jpg"); _dayTexture = Device.CreateTexture2D(dayBitmap, TextureFormat.RedGreenBlue8, false); Bitmap nightBitmap = new Bitmap("land_ocean_ice_lights_2048.jpg"); _nightTexture = Device.CreateTexture2D(nightBitmap, TextureFormat.RedGreenBlue8, false); _sceneState.DiffuseIntensity = 0.5f; _sceneState.SpecularIntensity = 0.15f; _sceneState.AmbientIntensity = 0.35f; _sceneState.Camera.ZoomToTarget(1); }
public TriangleMeshTerrainTile(Context context, TerrainTile tile) { ShaderProgram silhouetteSP = Device.CreateShaderProgram( EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.TriangleMeshTerrainTile.SilhouetteVS.glsl"), EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.TriangleMeshTerrainTile.SilhouetteGS.glsl"), EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.TriangleMeshTerrainTile.SilhouetteFS.glsl")); Uniform<float> fillDistance = (Uniform<float>)silhouetteSP.Uniforms["u_fillDistance"]; fillDistance.Value = 1.5f; _silhouetteHeightExaggeration = (Uniform<float>)silhouetteSP.Uniforms["u_heightExaggeration"]; ShaderProgram sp = Device.CreateShaderProgram( EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.TriangleMeshTerrainTile.TerrainVS.glsl"), EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.TriangleMeshTerrainTile.TerrainFS.glsl")); _tileMinimumHeight = tile.MinimumHeight; _tileMaximumHeight = tile.MaximumHeight; _heightExaggeration = (Uniform<float>)sp.Uniforms["u_heightExaggeration"]; _minimumHeight = (Uniform<float>)sp.Uniforms["u_minimumHeight"]; _maximumHeight = (Uniform<float>)sp.Uniforms["u_maximumHeight"]; HeightExaggeration = 1; /////////////////////////////////////////////////////////////////// Mesh mesh = new Mesh(); mesh.PrimitiveType = PrimitiveType.Triangles; mesh.FrontFaceWindingOrder = WindingOrder.Counterclockwise; int numberOfPositions = tile.Resolution.X * tile.Resolution.Y; VertexAttributeDoubleVector3 positionsAttribute = new VertexAttributeDoubleVector3("position", numberOfPositions); IList<Vector3D> positions = positionsAttribute.Values; mesh.Attributes.Add(positionsAttribute); int numberOfPartitionsX = tile.Resolution.X - 1; int numberOfPartitionsY = tile.Resolution.Y - 1; int numberOfIndices = (numberOfPartitionsX * numberOfPartitionsY) * 6; IndicesUnsignedInt indices = new IndicesUnsignedInt(numberOfIndices); mesh.Indices = indices; // // Positions // Vector2D lowerLeft = tile.Extent.LowerLeft; Vector2D toUpperRight = tile.Extent.UpperRight - lowerLeft; int heightIndex = 0; for (int y = 0; y <= numberOfPartitionsY; ++y) { double deltaY = y / (double)numberOfPartitionsY; double currentY = lowerLeft.Y + (deltaY * toUpperRight.Y); for (int x = 0; x <= numberOfPartitionsX; ++x) { double deltaX = x / (double)numberOfPartitionsX; double currentX = lowerLeft.X + (deltaX * toUpperRight.X); positions.Add(new Vector3D(currentX, currentY, tile.Heights[heightIndex++])); } } // // Indices // int rowDelta = numberOfPartitionsX + 1; int i = 0; for (int y = 0; y < numberOfPartitionsY; ++y) { for (int x = 0; x < numberOfPartitionsX; ++x) { indices.AddTriangle(new TriangleIndicesUnsignedInt(i, i + 1, rowDelta + (i + 1))); indices.AddTriangle(new TriangleIndicesUnsignedInt(i, rowDelta + (i + 1), rowDelta + i)); i += 1; } i += 1; } _drawState = new DrawState(); _drawState.RenderState.FacetCulling.FrontFaceWindingOrder = mesh.FrontFaceWindingOrder; _drawState.ShaderProgram = sp; _drawState.VertexArray = context.CreateVertexArray(mesh, sp.VertexAttributes, BufferHint.StaticDraw); _silhouetteDrawState = new DrawState(); _silhouetteDrawState.RenderState.FacetCulling.Enabled = false; _silhouetteDrawState.RenderState.DepthMask = false; _silhouetteDrawState.VertexArray = _drawState.VertexArray; _silhouetteDrawState.ShaderProgram = silhouetteSP; _primitiveType = mesh.PrimitiveType; _clearColor = new ClearState(); _clearColor.Buffers = ClearBuffers.ColorBuffer; // // Only depth needs to be cleared but include stencil for speed. // _clearDepthStencil = new ClearState(); _clearDepthStencil.Buffers = ClearBuffers.DepthBuffer | ClearBuffers.StencilBuffer; }
public abstract void Clear(ClearState clearState);
public SubdivisionSphere1() { _window = Device.CreateWindow(800, 600, "Chapter 4: Subdivision Sphere 1"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _sceneState = new SceneState(); _camera = new CameraLookAtPoint(_sceneState.Camera, _window, Ellipsoid.UnitSphere); _clearState = new ClearState(); string vs = @"#version 330 layout(location = og_positionVertexLocation) in vec4 position; out vec3 worldPosition; out vec3 positionToLight; out vec3 positionToEye; uniform mat4 og_modelViewPerspectiveMatrix; uniform vec3 og_cameraEye; uniform vec3 og_cameraLightPosition; void main() { gl_Position = og_modelViewPerspectiveMatrix * position; worldPosition = position.xyz; positionToLight = og_cameraLightPosition - worldPosition; positionToEye = og_cameraEye - worldPosition; }"; string fs = @"#version 330 in vec3 worldPosition; in vec3 positionToLight; in vec3 positionToEye; out vec3 fragmentColor; uniform vec4 og_diffuseSpecularAmbientShininess; uniform sampler2D og_texture0; float LightIntensity(vec3 normal, vec3 toLight, vec3 toEye, vec4 diffuseSpecularAmbientShininess) { vec3 toReflectedLight = reflect(-toLight, normal); float diffuse = max(dot(toLight, normal), 0.0); float specular = max(dot(toReflectedLight, toEye), 0.0); specular = pow(specular, diffuseSpecularAmbientShininess.w); return (diffuseSpecularAmbientShininess.x * diffuse) + (diffuseSpecularAmbientShininess.y * specular) + diffuseSpecularAmbientShininess.z; } vec2 ComputeTextureCoordinates(vec3 normal) { return vec2(atan(normal.y, normal.x) * og_oneOverTwoPi + 0.5, asin(normal.z) * og_oneOverPi + 0.5); } void main() { vec3 normal = normalize(worldPosition); float intensity = LightIntensity(normal, normalize(positionToLight), normalize(positionToEye), og_diffuseSpecularAmbientShininess); fragmentColor = intensity * texture(og_texture0, ComputeTextureCoordinates(normal)).rgb; }"; ShaderProgram sp = Device.CreateShaderProgram(vs, fs); /////////////////////////////////////////////////////////////////// Mesh mesh = SubdivisionSphereTessellatorSimple.Compute(5); VertexArray va = _window.Context.CreateVertexArray(mesh, sp.VertexAttributes, BufferHint.StaticDraw); _primitiveType = mesh.PrimitiveType; /////////////////////////////////////////////////////////////////// RenderState renderState = new RenderState(); //_renderState.RasterizationMode = RasterizationMode.Line; renderState.FacetCulling.FrontFaceWindingOrder = mesh.FrontFaceWindingOrder; _drawState = new DrawState(renderState, sp, va); /////////////////////////////////////////////////////////////////// Bitmap bitmap = new Bitmap("NE2_50M_SR_W_4096.jpg"); //Bitmap bitmap = new Bitmap("world_topo_bathy_200411_3x5400x2700.jpg"); //Bitmap bitmap = new Bitmap("world.topo.200412.3x5400x2700.jpg"); _texture = Device.CreateTexture2D(bitmap, TextureFormat.RedGreenBlue8, false); _sceneState.Camera.ZoomToTarget(1); }
public Triangle() { _window = Device.CreateWindow(800, 600, "Chapter 3: Triangle"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _sceneState = new SceneState(); _clearState = new ClearState(); string vs = @"#version 330 layout(location = og_positionVertexLocation) in vec4 position; uniform mat4 og_modelViewPerspectiveMatrix; void main() { gl_Position = og_modelViewPerspectiveMatrix * position; }"; string fs = @"#version 330 out vec3 fragmentColor; uniform vec3 u_color; void main() { fragmentColor = u_color; }"; ShaderProgram sp = Device.CreateShaderProgram(vs, fs); ((Uniform<Vector3F>)sp.Uniforms["u_color"]).Value = new Vector3F(1, 0, 0); /////////////////////////////////////////////////////////////////// Mesh mesh = new Mesh(); VertexAttributeFloatVector3 positionsAttribute = new VertexAttributeFloatVector3("position", 3); mesh.Attributes.Add(positionsAttribute); IndicesUnsignedShort indices = new IndicesUnsignedShort(3); mesh.Indices = indices; IList<Vector3F> positions = positionsAttribute.Values; positions.Add(new Vector3F(0, 0, 0)); positions.Add(new Vector3F(1, 0, 0)); positions.Add(new Vector3F(0, 0, 1)); indices.AddTriangle(new TriangleIndicesUnsignedShort(0, 1, 2)); VertexArray va = _window.Context.CreateVertexArray(mesh, sp.VertexAttributes, BufferHint.StaticDraw); /////////////////////////////////////////////////////////////////// RenderState renderState = new RenderState(); renderState.FacetCulling.Enabled = false; renderState.DepthTest.Enabled = false; _drawState = new DrawState(renderState, sp, va); /////////////////////////////////////////////////////////////////// _sceneState.Camera.ZoomToTarget(1); }
public VectorData() { Ellipsoid globeShape = Ellipsoid.ScaledWgs84; _window = Device.CreateWindow(800, 600, "Chapter 7: Vector Data"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _window.Keyboard.KeyDown += OnKeyDown; _window.Keyboard.KeyUp += OnKeyUp; _sceneState = new SceneState(); _camera = new CameraLookAtPoint(_sceneState.Camera, _window, globeShape); Context context = _window.Context; _framebuffer = context.CreateFramebuffer(); _clearBlack = new ClearState(); _clearBlack.Color = Color.Black; _clearWhite = new ClearState(); _clearWhite.Color = Color.White; _quad = new DayNightViewportQuad(context); _globe = new DayNightGlobe(context); _globe.Shape = globeShape; _globe.UseAverageDepth = true; _globe.DayTexture = Device.CreateTexture2D(new Bitmap("NE2_50M_SR_W_4096.jpg"), TextureFormat.RedGreenBlue8, false); _globe.NightTexture = Device.CreateTexture2D(new Bitmap("land_ocean_ice_lights_2048.jpg"), TextureFormat.RedGreenBlue8, false); _countries = new ShapefileRenderer("110m_admin_0_countries.shp", context, globeShape, new ShapefileAppearance() { PolylineWidth = 1.0, PolylineOutlineWidth = 1.0 }); _states = new ShapefileRenderer("110m_admin_1_states_provinces_lines_shp.shp", context, globeShape, new ShapefileAppearance() { PolylineWidth = 1.0, PolylineOutlineWidth = 1.0 }); _rivers = new ShapefileRenderer("50m-rivers-lake-centerlines.shp", context, globeShape, new ShapefileAppearance() { PolylineColor = Color.LightBlue, PolylineOutlineColor = Color.LightBlue, PolylineWidth = 1.0, PolylineOutlineWidth = 0.0 }); _populatedPlaces = new ShapefileRenderer("110m_populated_places_simple.shp", context, globeShape, new ShapefileAppearance() { Bitmap = new Bitmap("032.png") }); _airports = new ShapefileRenderer("airprtx020.shp", context, globeShape, new ShapefileAppearance() { Bitmap = new Bitmap("car-red.png") }); _amtrakStations = new ShapefileRenderer("amtrakx020.shp", context, globeShape, new ShapefileAppearance() { Bitmap = new Bitmap("paper-plane--arrow.png") }); _hudFont = new Font("Arial", 16); _hud = new HeadsUpDisplay(); _hud.Color = Color.Blue; _showVectorData = true; _sceneState.DiffuseIntensity = 0.5f; _sceneState.SpecularIntensity = 0.1f; _sceneState.AmbientIntensity = 0.4f; _sceneState.Camera.ZoomToTarget(globeShape.MaximumRadius); UpdateHUD(); }
public LinesOnTerrain() { _window = Device.CreateWindow(800, 600, "Research: Lines on Terrain"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _window.Keyboard.KeyDown += OnKeyDown; _sceneState = new SceneState(); _sceneState.Camera.PerspectiveFarPlaneDistance = 4096; _sceneState.Camera.PerspectiveNearPlaneDistance = 10; _instructions = new HeadsUpDisplay(); _instructions.Texture = Device.CreateTexture2D( Device.CreateBitmapFromText( "u - Use silhouette\ns - Show silhouette\n", new Font("Arial", 24)), TextureFormat.RedGreenBlueAlpha8, false); _instructions.Color = Color.LightBlue; /////////////////////////////////////////////////////////////////// TerrainTile terrainTile = TerrainTile.FromBitmap(new Bitmap(@"ps-e.lg.png")); _tile = new TriangleMeshTerrainTile(_window.Context, terrainTile); _tile.HeightExaggeration = 30.0f; /////////////////////////////////////////////////////////////////// double tileRadius = Math.Max(terrainTile.Resolution.X, terrainTile.Resolution.Y) * 0.5; _camera = new CameraLookAtPoint(_sceneState.Camera, _window, Ellipsoid.UnitSphere); _camera.CenterPoint = new Vector3D(terrainTile.Resolution.X * 0.5, terrainTile.Resolution.Y * 0.5, 0.0); _sceneState.Camera.ZoomToTarget(tileRadius); _sceneState.Camera.Eye = new Vector3D(_xPos, 256, 0); // // Positions // IList<Vector3D> positions = new List<Vector3D>(); double temp = 1.2 * _tile.HeightExaggeration; positions.Add(new Vector3D(0.0, 0.0, -temp)); positions.Add(new Vector3D(0.0, 0.0, temp)); positions.Add(new Vector3D(100.0, 100.0, -temp)); positions.Add(new Vector3D(100.0, 100.0, temp)); positions.Add(new Vector3D(200.0, 100.0, -temp)); positions.Add(new Vector3D(200.0, 100.0, temp)); positions.Add(new Vector3D(256.0, 256.0, -temp)); positions.Add(new Vector3D(256.0, 256.0, temp)); positions.Add(new Vector3D(512.0, 512.0, -temp)); positions.Add(new Vector3D(512.0, 512.0, temp)); // // junk _polylineOnTerrain = new PolylineOnTerrain(); _polylineOnTerrain.Set(_window.Context, positions); _clearState = new ClearState(); // junk string fs = @"#version 330 uniform sampler2D og_texture0; in vec2 fsTextureCoordinates; out vec4 fragmentColor; void main() { if (texture(og_texture0, fsTextureCoordinates).r == 0.0) { fragmentColor = vec4(0.0, 0.0, 0.0, 1.0); } else { discard; } }"; _viewportQuad = new ViewportQuad(_window.Context, fs); }
public SubdivisionSphere2() { _window = Device.CreateWindow(800, 600, "Chapter 4: Subdivision Sphere 2"); _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _sceneState = new SceneState(); _camera = new CameraLookAtPoint(_sceneState.Camera, _window, Ellipsoid.UnitSphere); _clearState = new ClearState(); string vs = @"#version 330 layout(location = og_positionVertexLocation) in vec4 position; layout(location = og_normalVertexLocation) in vec3 normal; layout(location = og_textureCoordinateVertexLocation) in vec2 textureCoordinate; out vec3 positionToLight; out vec3 positionToEye; out vec3 surfaceNormal; out vec2 surfaceTextureCoordinate; uniform mat4 og_modelViewPerspectiveMatrix; uniform vec3 og_cameraEye; uniform vec3 og_cameraLightPosition; void main() { gl_Position = og_modelViewPerspectiveMatrix * position; positionToLight = og_cameraLightPosition - position.xyz; positionToEye = og_cameraEye - position.xyz; surfaceNormal = normal; surfaceTextureCoordinate = textureCoordinate; }"; string fs = @"#version 330 in vec3 positionToLight; in vec3 positionToEye; in vec3 surfaceNormal; in vec2 surfaceTextureCoordinate; out vec3 fragmentColor; uniform vec4 og_diffuseSpecularAmbientShininess; uniform sampler2D og_texture0; float LightIntensity(vec3 normal, vec3 toLight, vec3 toEye, vec4 diffuseSpecularAmbientShininess) { vec3 toReflectedLight = reflect(-toLight, normal); float diffuse = max(dot(toLight, normal), 0.0); float specular = max(dot(toReflectedLight, toEye), 0.0); specular = pow(specular, diffuseSpecularAmbientShininess.w); return (diffuseSpecularAmbientShininess.x * diffuse) + (diffuseSpecularAmbientShininess.y * specular) + diffuseSpecularAmbientShininess.z; } void main() { vec3 normal = normalize(surfaceNormal); float intensity = LightIntensity(normal, normalize(positionToLight), normalize(positionToEye), og_diffuseSpecularAmbientShininess); fragmentColor = intensity * texture(og_texture0, surfaceTextureCoordinate).rgb; }"; ShaderProgram sp = Device.CreateShaderProgram(vs, fs); Mesh mesh = SubdivisionSphereTessellator.Compute(5, SubdivisionSphereVertexAttributes.All); VertexArray va = _window.Context.CreateVertexArray(mesh, sp.VertexAttributes, BufferHint.StaticDraw); _primitiveType = mesh.PrimitiveType; RenderState renderState = new RenderState(); renderState.FacetCulling.FrontFaceWindingOrder = mesh.FrontFaceWindingOrder; _drawState = new DrawState(renderState, sp, va); Bitmap bitmap = new Bitmap("NE2_50M_SR_W_4096.jpg"); _texture = Device.CreateTexture2D(bitmap, TextureFormat.RedGreenBlue8, false); }
private void myButton1_Click(object sender, EventArgs e) { _window = Device.CreateWindow(800, 600, "Chapter 13: Clipmap Terrain on a Globe"); _ellipsoid = Ellipsoid.Wgs84; WorldWindTerrainSource terrainSource = new WorldWindTerrainSource(); GMapRestImagery imagery = new GMapRestImagery(); _clipmap = new GlobeClipmapTerrain(_window.Context, terrainSource, imagery, _ellipsoid, 511); _clipmap.HeightExaggeration = 1.0f; IList<GridResolution> gridResolutions = new List<GridResolution>(); gridResolutions.Add(new GridResolution( new Interval(0, 1000000, IntervalEndpoint.Closed, IntervalEndpoint.Open), new Vector2D(0.005, 0.005))); gridResolutions.Add(new GridResolution( new Interval(1000000, 2000000, IntervalEndpoint.Closed, IntervalEndpoint.Open), new Vector2D(0.01, 0.01))); gridResolutions.Add(new GridResolution( new Interval(2000000, 20000000, IntervalEndpoint.Closed, IntervalEndpoint.Open), new Vector2D(0.05, 0.05))); gridResolutions.Add(new GridResolution( new Interval(20000000, double.MaxValue, IntervalEndpoint.Closed, IntervalEndpoint.Open), new Vector2D(0.1, 0.1))); _sceneState = new SceneState(); _sceneState.DiffuseIntensity = 0.90f; _sceneState.SpecularIntensity = 0.05f; _sceneState.AmbientIntensity = 0.05f; _sceneState.Camera.FieldOfViewY = Math.PI / 3.0; _clearState = new ClearState(); _clearState.Color = Color.White; _sceneState.Camera.PerspectiveNearPlaneDistance = 0.000001 * _ellipsoid.MaximumRadius; _sceneState.Camera.PerspectiveFarPlaneDistance = 10.0 * _ellipsoid.MaximumRadius; _sceneState.SunPosition = new Vector3D(200000, 300000, 200000) * _ellipsoid.MaximumRadius; _lookCamera = new CameraLookAtPoint(_sceneState.Camera, _window, _ellipsoid); _lookCamera.Range = 1.5 * _ellipsoid.MaximumRadius; _globe = new RayCastedGlobe(_window.Context); _globe.Shape = _ellipsoid; Bitmap bitmap = new Bitmap("NE2_50M_SR_W_4096.jpg"); _globe.Texture = Device.CreateTexture2D(bitmap, TextureFormat.RedGreenBlue8, false); //_globe.GridResolutions = new GridResolutionCollection(gridResolutions); _clearDepth = new ClearState(); _clearDepth.Buffers = ClearBuffers.DepthBuffer | ClearBuffers.StencilBuffer; //_window.Keyboard.KeyDown += OnKeyDown; _window.Resize += OnResize; _window.RenderFrame += OnRenderFrame; _window.PreRenderFrame += OnPreRenderFrame; _hudFont = new Font("Arial", 16); _hud = new HeadsUpDisplay(); _hud.Color = Color.Blue; //_flyCamera = new CameraFly(_sceneState.Camera, _window); //_flyCamera.MovementRate = 1200.0; //_flyCamera.InputEnabled = true; _sceneState.Camera.Target = new Vector3D(115, -35, 100.0); _window.Run(30); }