示例#1
0
        public HeadsUpDisplay()
        {
            RenderState renderState = new RenderState();
            renderState.FacetCulling.Enabled = false;
            renderState.DepthTest.Enabled = false;
            renderState.Blending.Enabled = true;
            renderState.Blending.SourceRGBFactor = SourceBlendingFactor.SourceAlpha;
            renderState.Blending.SourceAlphaFactor = SourceBlendingFactor.SourceAlpha;
            renderState.Blending.DestinationRGBFactor = DestinationBlendingFactor.OneMinusSourceAlpha;
            renderState.Blending.DestinationAlphaFactor = DestinationBlendingFactor.OneMinusSourceAlpha;

            ShaderProgram sp = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.HeadsUpDisplay.Shaders.HeadsUpDisplayVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.HeadsUpDisplay.Shaders.HeadsUpDisplayGS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.HeadsUpDisplay.Shaders.HeadsUpDisplayFS.glsl"));
            _colorUniform = (Uniform<Vector3F>)sp.Uniforms["u_color"];
            _originScaleUniform = (Uniform<Vector2F>)sp.Uniforms["u_originScale"];

            _drawState = new DrawState(renderState, sp, null);

            Color = Color.White;
            HorizontalOrigin = HorizontalOrigin.Left;
            VerticalOrigin = VerticalOrigin.Bottom;
            _positionDirty = true;
        }
示例#2
0
 protected void SetDrawAutomaticUniforms(Context context, DrawState drawState, SceneState sceneState)
 {
     for (int i = 0; i < _drawAutomaticUniforms.Count; ++i)
     {
         _drawAutomaticUniforms[i].Set(context, drawState, sceneState);
     }
 }
示例#3
0
        /// <summary>
        /// Example code in the book.
        /// </summary>
        private static int CompareDrawStates(DrawState left, DrawState right)
        {
            // Sort by shader first
            int leftShader = left.ShaderProgram.GetHashCode();
            int rightShader = right.ShaderProgram.GetHashCode();

            if (leftShader < rightShader)
            {
                return -1;
            }
            else if (leftShader > rightShader)
            {
                return 1;
            }

            // Shaders are equal, compare depth test enabled
            int leftEnabled = Convert.ToInt32(left.RenderState.DepthTest.Enabled);
            int rightEnabled = Convert.ToInt32(right.RenderState.DepthTest.Enabled);
                
            if (leftEnabled < rightEnabled)
            {
                return -1;
            }
            else if (rightEnabled > leftEnabled)
            {
                return 1;
            }

            // Continue comparing other states in order of most to least expensive...
            return 0;
        }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     //
     // viewport.Bottom should really be used but Rectangle goes top to botom, not bottom to top.
     //
     Rectangle viewport = context.Viewport;
     _uniform.Value = new Vector2F(1.0f / (float)viewport.Width, 1.0f / (float)viewport.Height);
 }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = new Vector4F(
         sceneState.DiffuseIntensity,
         sceneState.SpecularIntensity,
         sceneState.AmbientIntensity,
         sceneState.Shininess);
 }
示例#6
0
        public Polyline()
        {
            _drawState = new DrawState();
            _drawState.RenderState.FacetCulling.Enabled = false;

            Show = true;
            Width = 1;
        }
        public OutlinedPolylineGeometryShader()
        {
            _drawState = new DrawState();
            _drawState.RenderState.FacetCulling.Enabled = false;

            Width = 1;
            OutlineWidth = 1;
        }
示例#8
0
        public ClipmapUpdater(Context context, ClipmapLevel[] clipmapLevels)
        {
            ShaderVertexAttributeCollection vertexAttributes = new ShaderVertexAttributeCollection();
            vertexAttributes.Add(new ShaderVertexAttribute("position", VertexLocations.Position, ShaderVertexAttributeType.FloatVector2, 1));

            Mesh unitQuad = RectangleTessellator.Compute(new RectangleD(new Vector2D(0.0, 0.0), new Vector2D(1.0, 1.0)), 1, 1);
            _unitQuad = context.CreateVertexArray(unitQuad, vertexAttributes, BufferHint.StaticDraw);
            _unitQuadPrimitiveType = unitQuad.PrimitiveType;
            _sceneState = new SceneState();
            _framebuffer = context.CreateFramebuffer();

            _updateShader = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.ClipmapTerrain.ClipmapUpdateVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.ClipmapTerrain.ClipmapUpdateFS.glsl"));
            _updateTexelOutput = _updateShader.FragmentOutputs["texelOutput"];
            _updateDrawState = new DrawState(new RenderState(), _updateShader, _unitQuad);
            _updateDrawState.RenderState.FacetCulling.FrontFaceWindingOrder = unitQuad.FrontFaceWindingOrder;
            _updateDrawState.RenderState.DepthTest.Enabled = false;
            _updateDestinationOffset = (Uniform<Vector2F>)_updateShader.Uniforms["u_destinationOffset"];
            _updateUpdateSize = (Uniform<Vector2F>)_updateShader.Uniforms["u_updateSize"];
            _updateSourceOrigin = (Uniform<Vector2F>)_updateShader.Uniforms["u_sourceOrigin"];

            _upsampleShader = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.ClipmapTerrain.ClipmapUpsampleVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.ClipmapTerrain.ClipmapUpsampleFS.glsl"));
            _upsampleTexelOutput = _upsampleShader.FragmentOutputs["texelOutput"];
            _upsampleDrawState = new DrawState(new RenderState(), _upsampleShader, _unitQuad);
            _upsampleDrawState.RenderState.FacetCulling.FrontFaceWindingOrder = unitQuad.FrontFaceWindingOrder;
            _upsampleDrawState.RenderState.DepthTest.Enabled = false;
            _upsampleSourceOrigin = (Uniform<Vector2F>)_upsampleShader.Uniforms["u_sourceOrigin"];
            _upsampleUpdateSize = (Uniform<Vector2F>)_upsampleShader.Uniforms["u_updateSize"];
            _upsampleDestinationOffset = (Uniform<Vector2F>)_upsampleShader.Uniforms["u_destinationOffset"];
            _upsampleOneOverTextureSize = (Uniform<Vector2F>)_upsampleShader.Uniforms["u_oneOverTextureSize"];

            _computeNormalsShader = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.ClipmapTerrain.ClipmapComputeNormalsVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.ClipmapTerrain.ClipmapComputeNormalsFS.glsl"));
            _normalOutput = _computeNormalsShader.FragmentOutputs["normalOutput"];
            _computeNormalsDrawState = new DrawState(new RenderState(), _computeNormalsShader, _unitQuad);
            _computeNormalsDrawState.RenderState.FacetCulling.FrontFaceWindingOrder = unitQuad.FrontFaceWindingOrder;
            _computeNormalsDrawState.RenderState.DepthTest.Enabled = false;
            _computeNormalsOrigin = (Uniform<Vector2F>)_computeNormalsShader.Uniforms["u_origin"];
            _computeNormalsUpdateSize = (Uniform<Vector2F>)_computeNormalsShader.Uniforms["u_updateSize"];
            _computeNormalsOneOverHeightMapSize = (Uniform<Vector2F>)_computeNormalsShader.Uniforms["u_oneOverHeightMapSize"];
            _heightExaggeration = (Uniform<float>)_computeNormalsShader.Uniforms["u_heightExaggeration"];
            _postDelta = (Uniform<float>)_computeNormalsShader.Uniforms["u_postDelta"];

            HeightExaggeration = 1.0f;

            ClipmapLevel levelZero = clipmapLevels[0];
            InitializeRequestThreads(context, _terrain, levelZero, levelZero.Terrain);
            InitializeRequestThreads(context, _imagery, levelZero, levelZero.Imagery);
        }
示例#9
0
        public ViewportQuad(Context context, string fs)
        {
            Verify.ThrowIfNull(context);

            RenderState renderState = new RenderState();
            renderState.FacetCulling.Enabled = false;
            renderState.DepthTest.Enabled = false;

            _drawState = new DrawState();
            _drawState.RenderState = renderState;
            _drawState.ShaderProgram = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.ViewportQuad.Shaders.ViewportQuadVS.glsl"),
                fs == null ? EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.ViewportQuad.Shaders.ViewportQuadFS.glsl") : fs);

            _geometry = new ViewportQuadGeometry();
        }
        public OutlinedPolylineTexture()
        {
            RenderState renderState = new RenderState();
            renderState.FacetCulling.Enabled = false;
            renderState.Blending.Enabled = true;
            renderState.Blending.SourceRGBFactor = SourceBlendingFactor.SourceAlpha;
            renderState.Blending.SourceAlphaFactor = SourceBlendingFactor.SourceAlpha;
            renderState.Blending.DestinationRGBFactor = DestinationBlendingFactor.OneMinusSourceAlpha;
            renderState.Blending.DestinationAlphaFactor = DestinationBlendingFactor.OneMinusSourceAlpha;

            _drawState = new DrawState();
            _drawState.RenderState = renderState;

            Width = 3;
            OutlineWidth = 2;
        }
示例#11
0
        public GPURelativeToEye(Context context, Vector3D[] positions, byte[] colors)
        {
            _sp = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Examples.GPURelativeToEye.Shaders.VS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Examples.Shaders.FS.glsl"));
            _cameraEyeHigh = (Uniform<Vector3F>)_sp.Uniforms["u_cameraEyeHigh"];
            _cameraEyeLow = (Uniform<Vector3F>)_sp.Uniforms["u_cameraEyeLow"];
            _modelViewPerspectiveMatrixRelativeToEye = (Uniform<Matrix4F>)(_sp.Uniforms["u_modelViewPerspectiveMatrixRelativeToEye"]);
            _pointSize = (Uniform<float>)_sp.Uniforms["u_pointSize"];

            ///////////////////////////////////////////////////////////////////

            Mesh mesh = new Mesh();
            VertexAttributeFloatVector3 positionsHighAttribute = new VertexAttributeFloatVector3("positionHigh", positions.Length);
            VertexAttributeFloatVector3 positionsLowAttribute = new VertexAttributeFloatVector3("positionLow", positions.Length);
            VertexAttributeRGB colorAttribute = new VertexAttributeRGB("color", positions.Length);
            mesh.Attributes.Add(positionsHighAttribute);
            mesh.Attributes.Add(positionsLowAttribute);
            mesh.Attributes.Add(colorAttribute);

            for (int i = 0; i < positions.Length; ++i)
            {
                Vector3F positionHigh;
                Vector3F positionLow;
                Vector3DToTwoVector3F(positions[i], out positionHigh, out positionLow);

                positionsHighAttribute.Values.Add(positionHigh);
                positionsLowAttribute.Values.Add(positionLow);
            }

            for (int i = 0; i < colors.Length; ++i)
            {
                colorAttribute.Values.Add(colors[i]);
            }

            _va = context.CreateVertexArray(mesh, _sp.VertexAttributes, BufferHint.StaticDraw);

            ///////////////////////////////////////////////////////////////////

            RenderState renderState = new RenderState();
            renderState.FacetCulling.Enabled = false;
            renderState.DepthTest.Enabled = false;
            renderState.ProgramPointSize = ProgramPointSize.Enabled;

            _drawState = new DrawState(renderState, _sp, _va);
        }
示例#12
0
        public TessellatedGlobe()
        {
            ShaderProgram sp = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Globes.Tessellated.Shaders.GlobeVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Globes.Tessellated.Shaders.GlobeFS.glsl"));
            _textured = (Uniform<bool>)sp.Uniforms["u_Textured"];
            _logarithmicDepth = (Uniform<bool>)sp.Uniforms["u_logarithmicDepth"];
            _logarithmicDepthConstant = (Uniform<float>)sp.Uniforms["u_logarithmicDepthConstant"];
            LogarithmicDepthConstant = 1;
            
            _drawState = new DrawState();
            _drawState.ShaderProgram = sp;

            Shape = Ellipsoid.ScaledWgs84;
            NumberOfSlicePartitions = 32;
            NumberOfStackPartitions = 16;
        }
        public DayNightViewportQuad(Context context)
        {
            Verify.ThrowIfNull(context);

            RenderState renderState = new RenderState();
            renderState.FacetCulling.Enabled = false;
            renderState.DepthTest.Enabled = false;

            ShaderProgram sp = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Globes.DayNight.Shaders.ViewportQuadVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Globes.DayNight.Shaders.ViewportQuadFS.glsl"));
            _dayNightOutput = (Uniform<int>)sp.Uniforms["u_DayNightOutput"];

            _drawState = new DrawState();
            _drawState.RenderState = renderState;
            _drawState.ShaderProgram = sp;

            _geometry = new ViewportQuadGeometry();
        }
示例#14
0
        public DayNightGlobe(Context context)
        {
            Verify.ThrowIfNull(context);

            ShaderProgram sp = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Globes.DayNight.Shaders.GlobeVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Globes.DayNight.Shaders.GlobeFS.glsl"));
            _cameraEyeSquaredSP = (Uniform<Vector3F>)sp.Uniforms["u_cameraEyeSquared"];
            _useAverageDepth = (Uniform<bool>)sp.Uniforms["u_useAverageDepth"];

            float blendDurationScale = 0.1f;
            ((Uniform<float>)sp.Uniforms["u_blendDuration"]).Value = blendDurationScale;
            ((Uniform<float>)sp.Uniforms["u_blendDurationScale"]).Value = 1 / (2 * blendDurationScale);

            _drawState = new DrawState();
            _drawState.ShaderProgram = sp;

            Shape = Ellipsoid.ScaledWgs84;
            ShowGlobe = true;
        }
        public RayCastedTerrainTile(TerrainTile tile)
        {
            ShaderProgram sp = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.RayCastedTerrainTile.TerrainVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Terrain.RayCastedTerrainTile.TerrainFS.glsl"));

            _tileResolution = tile.Resolution;
            _tileMinimumHeight = tile.MinimumHeight;
            _tileMaximumHeight = tile.MaximumHeight;
            _tileAABBLowerLeft = Vector3D.Zero;             // TEXEL_SPACE_TODO
            _tileAABBUpperRight = new Vector3D(tile.Resolution.X, tile.Resolution.Y,
                tile.MaximumHeight - tile.MinimumHeight);

            _heightExaggeration = (Uniform<float>)sp.Uniforms["u_heightExaggeration"];
            _minimumHeight = (Uniform<float>)sp.Uniforms["u_minimumHeight"];
            _maximumHeight = (Uniform<float>)sp.Uniforms["u_maximumHeight"];
            _aabbLowerLeft = (Uniform<Vector3F>)sp.Uniforms["u_aabbLowerLeft"];
            _aabbUpperRight = (Uniform<Vector3F>)sp.Uniforms["u_aabbUpperRight"];
            _shadingAlgorithm = (Uniform<int>)sp.Uniforms["u_shadingAlgorithm"];

            HeightExaggeration = 1;

            ///////////////////////////////////////////////////////////////////

            _drawState = new DrawState();
            _drawState.RenderState.FacetCulling.Face = CullFace.Front;
            _drawState.ShaderProgram = sp;

            //
            // Upload height map as a one channel floating point texture
            //
            WritePixelBuffer pixelBuffer = Device.CreateWritePixelBuffer(PixelBufferHint.Stream,
                sizeof(float) * tile.Heights.Length);
            pixelBuffer.CopyFromSystemMemory(tile.Heights);

            _texture = Device.CreateTexture2DRectangle(new Texture2DDescription(
                tile.Resolution.X, tile.Resolution.Y, TextureFormat.Red32f));
            _texture.CopyFromBuffer(pixelBuffer, ImageFormat.Red, ImageDatatype.Float);

            ShowTerrain = true;
        }
        public override void Set(Context context, DrawState drawState, SceneState sceneState)
        {
            Camera camera = sceneState.Camera;
            double theta = camera.FieldOfViewX * 0.5;
            double phi = camera.FieldOfViewY * 0.5;
            double nearDistance = camera.PerspectiveNearPlaneDistance;

            //
            // Coordinate system for the near plane:  origin is at center, x and y
            // span [-1, 1] just like noramlized device coordinates.
            //
            Vector3D origin = camera.Eye + (nearDistance * camera.Forward);    // Project eye onto near plane
            Vector3D xAxis = camera.Right * (nearDistance * Math.Tan(theta));  // Rescale right to near plane
            Vector3D yAxis = camera.Up * (nearDistance * Math.Tan(phi));       // Rescale up to near plane

            _uniform.Value = new Matrix4D(
                    xAxis.X, yAxis.X, 0.0, origin.X,
                    xAxis.Y, yAxis.Y, 0.0, origin.Y,
                    xAxis.Z, yAxis.Z, 0.0, origin.Z,
                    0.0,     0.0,     0.0, 1.0).ToMatrix4F();
        }
示例#17
0
        public Wireframe(Context context, Mesh mesh)
        {
            RenderState renderState = new RenderState();
            renderState.Blending.Enabled = true;
            renderState.Blending.SourceRGBFactor = SourceBlendingFactor.SourceAlpha;
            renderState.Blending.SourceAlphaFactor = SourceBlendingFactor.SourceAlpha;
            renderState.Blending.DestinationRGBFactor = DestinationBlendingFactor.OneMinusSourceAlpha;
            renderState.Blending.DestinationAlphaFactor = DestinationBlendingFactor.OneMinusSourceAlpha;
            renderState.FacetCulling.FrontFaceWindingOrder = mesh.FrontFaceWindingOrder;
            renderState.DepthTest.Function = DepthTestFunction.LessThanOrEqual;

            //
            // This implementation is based on the 2006 SIGGRAPH Sketch:
            //
            //    Single-pass Wireframe Rendering
            //    http://www2.imm.dtu.dk/pubdb/views/edoc_download.php/4884/pdf/imm4884.pdf
            //
            // NVIDIA published a white paper with some enhancements we can consider:
            //
            //    Solid Wireframe
            //    http://developer.download.nvidia.com/SDK/10.5/direct3d/Source/SolidWireframe/Doc/SolidWireframe.pdf
            //
            // More recent work, which I was not aware of at the time, is:
            //
            //    Two Methods for Antialiased Wireframe Drawing with Hidden Line Removal
            //    http://orbit.dtu.dk/getResource?recordId=219956&objectId=1&versionId=1
            //
            ShaderProgram sp = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.Wireframe.Shaders.WireframeVS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.Wireframe.Shaders.WireframeGS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Scene.Renderables.Wireframe.Shaders.WireframeFS.glsl"));
            _lineWidth = (Uniform<float>)sp.Uniforms["u_halfLineWidth"];
            Width = 1;

            _colorUniform = (Uniform<Vector3F>)sp.Uniforms["u_color"];
            Color = Color.Black;

            _drawState = new DrawState(renderState, sp, context.CreateVertexArray(mesh, sp.VertexAttributes, BufferHint.StaticDraw));
            _primitiveType = mesh.PrimitiveType;
        }
示例#18
0
        public CPURelativeToEye(Context context, Vector3D[] positions, byte[] colors)
        {
            _sp = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Examples.CPURelativeToEye.Shaders.VS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Examples.Shaders.FS.glsl"));
            _modelViewPerspectiveMatrixRelativeToEye = (Uniform<Matrix4F>)(_sp.Uniforms["u_modelViewPerspectiveMatrixRelativeToEye"]);
            _pointSize = (Uniform<float>)_sp.Uniforms["u_pointSize"];

            ///////////////////////////////////////////////////////////////////

            _positions = new Vector3D[positions.Length];
            positions.CopyTo(_positions, 0);
            _positionsRelativeToEye = new Vector3F[_positions.Length];
            _eye = Vector3D.Zero;

            //
            // _positionBuffer is dynamic, and is written to when the camera moves.
            //
            _positionBuffer = Device.CreateVertexBuffer(BufferHint.DynamicDraw, ArraySizeInBytes.Size(_positionsRelativeToEye));

            _colorBuffer = Device.CreateVertexBuffer(BufferHint.StaticDraw, colors.Length);
            _colorBuffer.CopyFromSystemMemory(colors);

            _va = context.CreateVertexArray();
            _va.Attributes[_sp.VertexAttributes["position"].Location] =
                new VertexBufferAttribute(_positionBuffer, ComponentDatatype.Float, 3);
            _va.Attributes[_sp.VertexAttributes["color"].Location] =
                new VertexBufferAttribute(_colorBuffer, ComponentDatatype.UnsignedByte, 3, true, 0, 0);

            ///////////////////////////////////////////////////////////////////

            RenderState renderState = new RenderState();
            renderState.FacetCulling.Enabled = false;
            renderState.DepthTest.Enabled = false;
            renderState.ProgramPointSize = ProgramPointSize.Enabled;

            _drawState = new DrawState(renderState, _sp, _va);
        }
示例#19
0
        public RelativeToCenter(Context context, Vector3D[] positions, byte[] colors)
        {
            _sp = Device.CreateShaderProgram(
                EmbeddedResources.GetText("OpenGlobe.Examples.RelativeToCenter.Shaders.VS.glsl"),
                EmbeddedResources.GetText("OpenGlobe.Examples.Shaders.FS.glsl"));
            _modelViewPerspectiveMatrixRelativeToCenter = (Uniform<Matrix4F>)(_sp.Uniforms["u_modelViewPerspectiveMatrixRelativeToCenter"]);
            _pointSize = (Uniform<float>)_sp.Uniforms["u_pointSize"];

            ///////////////////////////////////////////////////////////////////

            Mesh mesh = new Mesh();
            VertexAttributeFloatVector3 positionsAttribute = new VertexAttributeFloatVector3("position", positions.Length);
            VertexAttributeRGB colorAttribute = new VertexAttributeRGB("color", positions.Length);
            mesh.Attributes.Add(positionsAttribute);
            mesh.Attributes.Add(colorAttribute);

            _center = new AxisAlignedBoundingBox(positions).Center;
            for (int i = 0; i < positions.Length; ++i)
            {
                positionsAttribute.Values.Add((positions[i] - _center).ToVector3F());
            }

            for (int i = 0; i < colors.Length; ++i)
            {
                colorAttribute.Values.Add(colors[i]);
            }

            _va = context.CreateVertexArray(mesh, _sp.VertexAttributes, BufferHint.StaticDraw);

            ///////////////////////////////////////////////////////////////////

            RenderState renderState = new RenderState();
            renderState.FacetCulling.Enabled = false;
            renderState.DepthTest.Enabled = false;
            renderState.ProgramPointSize = ProgramPointSize.Enabled;

            _drawState = new DrawState(renderState, _sp, _va);
        }
示例#20
0
        public RayCastedGlobe(Context context)
        {
            Verify.ThrowIfNull(context);

            _renderState = new RenderState();
            _renderState.FacetCulling.Face = CullFace.Front;
            string vs = EmbeddedResources.GetText("OpenGlobe.Scene.Globes.RayCasted.Shaders.GlobeVS.glsl");

            ShaderProgram sp = Device.CreateShaderProgram(vs, EmbeddedResources.GetText("OpenGlobe.Scene.Globes.RayCasted.Shaders.GlobeFS.glsl"));
            _cameraEyeSquared = (Uniform<Vector3F>)sp.Uniforms["u_cameraEyeSquared"];
            _useAverageDepth = (Uniform<bool>)sp.Uniforms["u_useAverageDepth"];

            ShaderProgram solidSP = Device.CreateShaderProgram(vs, EmbeddedResources.GetText("OpenGlobe.Scene.Globes.RayCasted.Shaders.SolidShadedGlobeFS.glsl"));
            _cameraEyeSquaredSolid = (Uniform<Vector3F>)solidSP.Uniforms["u_cameraEyeSquared"];
            _useAverageDepthSolid = (Uniform<bool>)solidSP.Uniforms["u_useAverageDepth"];

            _drawState = new DrawState(_renderState, sp, null);
            _drawStateSolid = new DrawState(_renderState, solidSP, null);

            Shape = Ellipsoid.ScaledWgs84;
            Shade = true;
            ShowGlobe = true;
        }
示例#21
0
 public abstract void Draw(PrimitiveType primitiveType, int offset, int count, DrawState drawState, SceneState sceneState);
示例#22
0
 public abstract void Draw(PrimitiveType primitiveType, DrawState drawState, SceneState sceneState);
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = (float)(Math.Tan(0.5 * sceneState.Camera.FieldOfViewY) * 2.0 / context.Viewport.Height);
 }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = SceneState.ComputeViewportOrthographicMatrix(context.Viewport).ToMatrix4F();
 }
示例#25
0
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = (float)(Math.Tan(0.5 * sceneState.Camera.FieldOfViewY) * 2.0 / context.Viewport.Height);
 }
示例#26
0
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = sceneState.Camera.Eye.ToVector3F();
 }
示例#27
0
        private void DrawBlock(VertexArray block, ClipmapLevel level, ClipmapLevel coarserLevel, int overallWest, int overallSouth, int blockWest, int blockSouth, Context context, SceneState sceneState)
        {
            int textureWest = blockWest - overallWest;
            int textureSouth = blockSouth - overallSouth;

            _patchOriginInClippedLevel.Value = new Vector2F(textureWest, textureSouth);
            DrawState drawState = new DrawState(_renderState, _shaderProgram, block);
            context.Draw(_primitiveType, drawState, sceneState);
        }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = sceneState.ComputeViewportTransformationMatrix(context.Viewport,
                                                                     drawState.RenderState.DepthRange.Near, drawState.RenderState.DepthRange.Far).ToMatrix4F();
 }
示例#29
0
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = Matrix42 <float> .DoubleToFloat(sceneState.ModelZToClipCoordinates);
 }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = (float)sceneState.Camera.Height(Ellipsoid.Wgs84);
 }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = sceneState.ModelViewPerspectiveMatrixRelativeToEye.ToMatrix4F();
 }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = sceneState.ComputeViewportTransformationMatrix(context.Viewport,
         drawState.RenderState.DepthRange.Near, drawState.RenderState.DepthRange.Far).ToMatrix4F();
 }
示例#33
0
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = sceneState.ModelViewPerspectiveMatrixRelativeToEye.ToMatrix4F();
 }
示例#34
0
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = sceneState.ViewMatrix.ToMatrix4F();
 }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = sceneState.OrthographicMatrix.ToMatrix4F();
 }
示例#36
0
        public void Set(Context context, IList<Vector3D> positions)
        {
            //
            // This method expects that the positions are ordered in a repeated pattern of 
            // below terrain, above terrain pairs.
            //
            // Wall mesh
            //
            Mesh wallMesh = new Mesh();
            wallMesh.PrimitiveType = PrimitiveType.TriangleStrip;

            //
            // Positions
            //
            int numberOfLineSegments = (positions.Count / 2) - 1;
            int numberOfVertices = 2 + numberOfLineSegments + numberOfLineSegments;
            VertexAttributeDoubleVector3 positionsAttribute = new VertexAttributeDoubleVector3("position", numberOfVertices);
            IList<Vector3D> tempPositions = positionsAttribute.Values;
            wallMesh.Attributes.Add(positionsAttribute);
            foreach (Vector3D v in positions)
            {
                tempPositions.Add(v);
            }

            //
            // Vertex array
            //
            _wallVA = context.CreateVertexArray(wallMesh, _wallSP.VertexAttributes, BufferHint.StaticDraw);

            //
            // Line mesh
            //
            Mesh lineMesh = new Mesh();
            lineMesh.PrimitiveType = PrimitiveType.LineStrip;

            //
            // Positions
            //
            positionsAttribute = new VertexAttributeDoubleVector3("position", numberOfVertices);
            tempPositions = positionsAttribute.Values;
            lineMesh.Attributes.Add(positionsAttribute);
            foreach (Vector3D v in positions)
            {
                tempPositions.Add(v);
            }

            //
            // Indices
            //
            int numIndices = 4 * numberOfLineSegments;
            ushort[] indices = new ushort[numIndices];
            int baseIndex = 1;
            for (int i = 0; i < numIndices; i += 4, baseIndex += 2)
            {
                indices[i] = (ushort)baseIndex;
                indices[i + 1] = (ushort)(baseIndex - 1);
                indices[i + 2] = (ushort)(baseIndex + 1);
                indices[i + 3] = (ushort)(baseIndex + 2);
            }
            IndexBuffer indexBuffer = Device.CreateIndexBuffer(BufferHint.StaticDraw, numIndices * sizeof(ushort));
            indexBuffer.CopyFromSystemMemory(indices);

            //
            // Vertex array
            //
            _lineVA = context.CreateVertexArray(lineMesh, _wallSP.VertexAttributes, BufferHint.StaticDraw);
            _lineVA.IndexBuffer = indexBuffer;

            //
            // State
            //
            _wallDrawState = new DrawState();
            _wallDrawState.RenderState.FacetCulling.Enabled = false;
            _wallDrawState.RenderState.DepthTest.Enabled = false;
            _wallDrawState.RenderState.DepthMask = false;
            _wallDrawState.VertexArray = _lineVA;
            _wallDrawState.ShaderProgram = _wallSP;

            _shadowVolumePassOne = new DrawState();
            _shadowVolumePassOne.VertexArray = _lineVA;
            _shadowVolumePassOne.ShaderProgram = _shadowVolumeSP;
            _shadowVolumePassOne.RenderState.FacetCulling.Enabled = false;
            _shadowVolumePassOne.RenderState.DepthMask = false;
            _shadowVolumePassOne.RenderState.ColorMask = new ColorMask(false, false, false, false);
            StencilTest stOne = _shadowVolumePassOne.RenderState.StencilTest;
            stOne.Enabled = true;
            stOne.FrontFace.DepthFailStencilPassOperation = StencilOperation.Decrement;
            stOne.BackFace.DepthFailStencilPassOperation = StencilOperation.Increment;

            _shadowVolumePassTwo = new DrawState();
            _shadowVolumePassTwo.VertexArray = _lineVA;
            _shadowVolumePassTwo.ShaderProgram = _shadowVolumeSP;
            _shadowVolumePassTwo.RenderState.DepthMask = false;
            StencilTest stTwo = _shadowVolumePassTwo.RenderState.StencilTest;
            stTwo.Enabled = true;
            stTwo.FrontFace.DepthFailStencilPassOperation = StencilOperation.Zero;
            stTwo.FrontFace.DepthPassStencilPassOperation = StencilOperation.Zero;
            stTwo.FrontFace.Function = StencilTestFunction.NotEqual;
            stTwo.BackFace.DepthFailStencilPassOperation = StencilOperation.Zero;
            stTwo.BackFace.DepthPassStencilPassOperation = StencilOperation.Zero;
            stTwo.BackFace.Function = StencilTestFunction.NotEqual;
        }
示例#37
0
        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 override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = sceneState.ModelViewOrthographicMatrix.ToMatrix4F();
 }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = sceneState.CameraLightPosition.ToVector3F();
 }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = sceneState.PerspectiveMatrix.ToMatrix4F();
 }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = sceneState.Camera.EyeHigh;
 }
 public override void Set(Context context, DrawState drawState, SceneState sceneState)
 {
     _uniform.Value = SceneState.ComputeViewportOrthographicMatrix(context.Viewport).ToMatrix4F();
 }