pjcozzi's picture

Virtual Globe and Terrain Rendering Example Code

I am using C# and OpenTK for example code for a book I am writing on virtual globe and terrain rendering. I wanted to share some early screen shots. Everything is done using OpenGL 3.3 core profile (could be also be 3.2, we are not using any 3.3 features yet), which OpenTK has made so easy!

Day and night imagery blended based on light (sun) position. Vector data is only rendered over the day imagery using a deferred approach. The day imagery and vector data are from Natural Earth, the night imagery is from NASA Visible Earth.

Vector data from shapefiles. The thick (pixel size greater than one), outlined, anti-aliased polylines are rendered using a geometry shader. The star billboards are also rendering using a geometry shader, which expands points into quads. The star icon is from Yusuke Kamiyamane.

Slope-based terrain shading in a fragment shader. Steep areas are shaded using a stone texture and flat areas use a grass texture. Obviously, I am not an artist :).

Constant pixel width contour lines procedurally generated in a fragment shader based on terrain height.

For more information, check out the book's blog or download the code from SourceForge. Much more to come!


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

This is looking great!

migueltk's picture

Hello, pjcozzi

I would say it is impressive, but do not get it to work, I guess my graphics card and the version of opengl is insufficient.

OpenGL Version = 3.3.9901 Compatibility Profile Context

I hope some day see it working ...

pjcozzi's picture

Thanks for the interest guys.

Since we're using OpenGL 3.x core profile, you need a video card (and drivers) that support it. These cards came out in late 2006 and include the NVIDIA GeForce 8 seriers or later, and ATI Radeon 2000 series or later. If you do have such a card, please let me know more details about your issue. We've tested on various NVIDIA and ATI cards without problem. Although, we've only tried Windows - I'd be happy to accept patches for Linux, Mac, etc. I expect porting to be straightforward.

Also, there's a small chance that we might back port some of the code to GL 2.1 (or more likely: GL ES 2.0) but I don't expect that to happen this year, as we are so busy with the other code examples and writing the actual manuscript. That, and geometry shaders are just so useful, it would be a shame to go without them.

Regards,
Patrick

migueltk's picture

O.K

This is the error ...

Vertex shader failed to compile with the following errors:
ERROR: 0:2: error(#88) Syntax error ERROR___INTEGER_CONST_OVERFLOW

.Renderer.CouldNotCreateVideoCardResourceException: Could not compile shader object. Compile Log:

Vertex shader failed to compile with the following errors:
ERROR: 0:2: error(#88) Syntax error ERROR___INTEGER_CONST_OVERFLOW
ERROR: 0:2: error(#132) Syntax error: '71828182845905' parse error
ERROR: error(#273) 2 compilation errors. No code generated

en OpenGlobe.Renderer.GL3x.ShaderObjectGL3x..ctor(ShaderType shaderType, String source) en c:\Users\Miguel\Downloads\miniglobe\Source\Renderer\GL3x\Shaders\ShaderObjectGL3x.cs:línea 72
en OpenGlobe.Renderer.GL3x.ShaderProgramGL3x..ctor(String vertexShaderSource, String geometryShaderSource, String fragmentShaderSource) en c:\Users\Miguel\Downloads\miniglobe\Source\Renderer\GL3x\Shaders\ShaderProgramGL3x.cs:línea 33
en OpenGlobe.Renderer.GL3x.ShaderProgramGL3x..ctor(String vertexShaderSource, String fragmentShaderSource) en c:\Users\Miguel\Downloads\miniglobe\Source\Renderer\GL3x\Shaders\ShaderProgramGL3x.cs:línea 21
en OpenGlobe.Renderer.Device.CreateShaderProgram(String vertexShaderSource, String fragmentShaderSource) en c:\Users\Miguel\Downloads\miniglobe\Source\Renderer\Device.cs:línea 48
en OpenGlobe.Examples.Chapter3.SubdivisionSphere1..ctor() en c:\Users\Miguel\Downloads\miniglobe\Source\Examples\Chapter3\SubdivisionSphere1\SubdivisionSphere1.cs:línea 87
en OpenGlobe.Examples.Chapter3.SubdivisionSphere1.Main() en c:\Users\Miguel\Downloads\miniglobe\Source\Examples\Chapter3\SubdivisionSphere1\SubdivisionSphere1.cs:línea 152

My video car is:

ATI Radeon HD 3800 series and Operating System = Windows 7 (32 bit)

Regards, ...

pjcozzi's picture

Thanks for the call stack. Looks like it cannot compile the vertex shader. Your video card should support GL 3.3 though. Do you have the latest drivers? I believe you need Catalyst 10.6. Also, I will double check this example tomorrow on my Radeon HD 5570. I am pretty sure it was working though.

The other thing that comes to mind is if a cultural setting is affecting the string with the shader source.

Regards,
Patrick

migueltk's picture

True, it is a problem of cultural adjustment.

I added the line "Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");" and everything works.

    internal class ShaderObjectGL3x : Disposable
    {
        public ShaderObjectGL3x(ShaderType shaderType, string source)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
 
            string builtInConstants =  etc ...

But! which is the chapter that corresponds to the first image of this document. With chapter 7 my ocean is gray, as shown in the attached image.

Regards, ...

AttachmentSize
chapter7.jpg251.2 KB
pjcozzi's picture

Thanks. I'm glad you got the examples running. We'll fix the cultural issue.

As for the first image in this blog post, you found the example used to create it. I'm not quite sure why your globe texture appears gray and banded like that. I didn't have that problem with a HD 5570/Vista-64 but I'm not sure if I've tested that example since upgrading to Catalyst 10.6. I'll give it a try and get back to you.

Regards,
Patrick

pjcozzi's picture

I submitted a fix for the culture issue. Thanks again for reporting it!

I am not experiencing the gray globe on HD 5870/Catalyst 10.6/Vista-64 or any NVIDIA cards. Although, there is a similar known issue with the nights light example on ATI, which is hopefully related, but I haven't been able to debug it yet. It could be a problem with the texture format or alignment.

Regards,
Patrick

rtalan's picture

Patrick,

We communicated about OpenGlobe rendering in WPF several months ago. I have exhausted all attempts in modifying OpenGlobe and OpenTK to work within an HWNDHOST.

For clarification, I'm talking about hosting an OpenGlobe GameWindow (which internally uses the OpenTK.GameWindow) in WPF , not an OpenTK.GLControl.

The HWNDHOST needs the hwnd handle to the win32 window created by OpenTK.WinGLNative. But it is buried so deep and hidden away behind 'internal sealed' classes that it is impossible to get to.

Have you seen any progress on this front?
Any ideas where OpenTK.WinGLNative might be modified to make this all possible?

LOVE THE BOOK!

Thanks for your time,

Bob Smith
Columbia, MD.