Permalink
Browse files

Major update to add 3D terrain and shader rendering

  • Loading branch information...
1 parent 971464a commit 69115fc017216ce01a180da458d644d2737620db @RossAnderson committed May 2, 2012
View
@@ -1,2 +1 @@
-xcuserdata
.DS_Store
View
@@ -10,7 +10,8 @@
#import "RASceneGraphController.h"
-#define SAMPLE_DATASET 4
+#define IMAGERY_DATASET 2
+#define TERRAIN_DATASET 1
@implementation DRAppDelegate
@@ -29,19 +30,23 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}
// setup the tile set used
- RATileDatabase * database = self.viewController.database;
- switch( SAMPLE_DATASET ) {
+ RATileDatabase * database = [RATileDatabase new];
+ database.bounds = CGRectMake( -180,-90,360,180 );
+ database.googleTileConvention = YES;
+ database.minzoom = 2;
+
+ switch( IMAGERY_DATASET ) {
case 1:
- // Sample database from: http://a.tiles.mapbox.com/v3/mapbox.blue-marble-topo-jul-bw.jsonp
+ // MapBox Streets: http://a.tiles.mapbox.com/v3/mapbox.mapbox-streets.jsonp
database.baseUrlStrings = [NSArray arrayWithObjects:
- @"http://a.tiles.mapbox.com/v3/mapbox.blue-marble-topo-jul-bw/{z}/{x}/{y}.png",
- @"http://b.tiles.mapbox.com/v3/mapbox.blue-marble-topo-jul-bw/{z}/{x}/{y}.png",
- @"http://c.tiles.mapbox.com/v3/mapbox.blue-marble-topo-jul-bw/{z}/{x}/{y}.png",
- @"http://d.tiles.mapbox.com/v3/mapbox.blue-marble-topo-jul-bw/{z}/{x}/{y}.png",
- nil];
-
- database.maxzoom = 8;
+ @"http://a.tiles.mapbox.com/v3/mapbox.mapbox-streets/{z}/{x}/{y}.png",
+ @"http://b.tiles.mapbox.com/v3/mapbox.mapbox-streets/{z}/{x}/{y}.png",
+ @"http://c.tiles.mapbox.com/v3/mapbox.mapbox-streets/{z}/{x}/{y}.png",
+ @"http://d.tiles.mapbox.com/v3/mapbox.mapbox-streets/{z}/{x}/{y}.png",
+ nil];
+ database.maxzoom = 17;
break;
+
case 2:
// Sample database from: http://a.tiles.mapbox.com/v3/mapbox.blue-marble-topo-bathy-jul.jsonp
database.baseUrlStrings = [NSArray arrayWithObjects:
@@ -52,6 +57,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
nil];
database.maxzoom = 8;
break;
+
case 3:
// OpenStreetMap
database.baseUrlStrings = [NSArray arrayWithObjects:
@@ -61,24 +67,46 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
nil];
database.maxzoom = 18;
break;
+
case 4:
- // MapBox Streets: http://a.tiles.mapbox.com/v3/mapbox.mapbox-streets.jsonp
+ // Stamen Maps Watercolor - http://maps.stamen.com/watercolor
database.baseUrlStrings = [NSArray arrayWithObjects:
- @"http://a.tiles.mapbox.com/v3/mapbox.mapbox-streets/{z}/{x}/{y}.png",
- @"http://b.tiles.mapbox.com/v3/mapbox.mapbox-streets/{z}/{x}/{y}.png",
- @"http://c.tiles.mapbox.com/v3/mapbox.mapbox-streets/{z}/{x}/{y}.png",
- @"http://d.tiles.mapbox.com/v3/mapbox.mapbox-streets/{z}/{x}/{y}.png",
- nil];
+ @"http://a.tile.stamen.com/watercolor/{z}/{x}/{y}.png",
+ @"http://b.tile.stamen.com/watercolor/{z}/{x}/{y}.png",
+ @"http://c.tile.stamen.com/watercolor/{z}/{x}/{y}.png",
+ nil];
database.maxzoom = 17;
break;
- /*
- case 5:
+
+ default:
+ database = nil;
+ break;
+ }
+ self.viewController.pager.imageryDatabase = database;
+
+ // setup height tile dataset
+ database = [RATileDatabase new];
+ database.bounds = CGRectMake( -180,-90,360,180 );
+ database.googleTileConvention = YES;
+ database.minzoom = 2;
+
+ switch ( TERRAIN_DATASET ) {
+ case 1:
+ // World Topography: https://tiles.mapbox.com/v3/dancingrobots.world-topo
+ database.baseUrlStrings = [NSArray arrayWithObjects:
+ @"http://a.tiles.mapbox.com/v3/dancingrobots.world-topo/{z}/{x}/{y}.png",
+ @"http://b.tiles.mapbox.com/v3/dancingrobots.world-topo/{z}/{x}/{y}.png",
+ @"http://c.tiles.mapbox.com/v3/dancingrobots.world-topo/{z}/{x}/{y}.png",
+ @"http://d.tiles.mapbox.com/v3/dancingrobots.world-topo/{z}/{x}/{y}.png",
+ nil];
+ database.maxzoom = 8;
+ break;
+
default:
- // Stamen Maps Watercolor - http://maps.stamen.com/watercolor
- database.baseUrlString = @"http://a.tile.stamen.com/watercolor/{z}/{x}/{y}.png";
- database.maxzoom = 17;
- */
+ database = nil;
+ break;
}
+ self.viewController.pager.terrainDatabase = database;
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
@@ -9,11 +9,13 @@
/* Begin PBXBuildFile section */
9109E03C153D86100008286D /* star1.png in Resources */ = {isa = PBXBuildFile; fileRef = 9109E03B153D86100008286D /* star1.png */; };
9109E03E153D864F0008286D /* RASceneGraphController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9109E03D153D864F0008286D /* RASceneGraphController.m */; };
- 91BBDFB2153A49A900CEF4BA /* README.md in Resources */ = {isa = PBXBuildFile; fileRef = 91BBDFB1153A49A900CEF4BA /* README.md */; };
91C9975C1548E1BF00B69A8A /* Icon114.png in Resources */ = {isa = PBXBuildFile; fileRef = 91C9975B1548E1BF00B69A8A /* Icon114.png */; };
91C9975E1548E1F000B69A8A /* Icon57.png in Resources */ = {isa = PBXBuildFile; fileRef = 91C9975D1548E1F000B69A8A /* Icon57.png */; };
91C997601548E21400B69A8A /* Icon144.png in Resources */ = {isa = PBXBuildFile; fileRef = 91C9975F1548E21400B69A8A /* Icon144.png */; };
91C997621548E22E00B69A8A /* Icon72.png in Resources */ = {isa = PBXBuildFile; fileRef = 91C997611548E22E00B69A8A /* Icon72.png */; };
+ 91C9979D1549DBD400B69A8A /* Shader.fsh in Resources */ = {isa = PBXBuildFile; fileRef = 91C9979B1549DBD400B69A8A /* Shader.fsh */; };
+ 91C9979E1549DBD400B69A8A /* Shader.vsh in Resources */ = {isa = PBXBuildFile; fileRef = 91C9979C1549DBD400B69A8A /* Shader.vsh */; };
+ 91F22019154C7B4700A5F74E /* RAShaderProgram.m in Sources */ = {isa = PBXBuildFile; fileRef = 91F22018154C7B4700A5F74E /* RAShaderProgram.m */; };
91F77E271539335000F8AE05 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 91F77E261539335000F8AE05 /* UIKit.framework */; };
91F77E291539335000F8AE05 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 91F77E281539335000F8AE05 /* Foundation.framework */; };
91F77E2B1539335000F8AE05 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 91F77E2A1539335000F8AE05 /* CoreGraphics.framework */; };
@@ -42,7 +44,6 @@
91F77EA51539C32D00F8AE05 /* TPPropertyAnimation.m in Sources */ = {isa = PBXBuildFile; fileRef = 91F77E731539341B00F8AE05 /* TPPropertyAnimation.m */; };
91F77EA7153A089A00F8AE05 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 91F77EA6153A089A00F8AE05 /* QuartzCore.framework */; };
91F77EA8153A08C300F8AE05 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 91F77E8D1539349900F8AE05 /* main.m */; };
- 91F77EAC153A0F9B00F8AE05 /* LICENSE.txt in Resources */ = {isa = PBXBuildFile; fileRef = 91F77EAB153A0F9A00F8AE05 /* LICENSE.txt */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -53,6 +54,10 @@
91C9975D1548E1F000B69A8A /* Icon57.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon57.png; sourceTree = "<group>"; };
91C9975F1548E21400B69A8A /* Icon144.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon144.png; sourceTree = "<group>"; };
91C997611548E22E00B69A8A /* Icon72.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Icon72.png; sourceTree = "<group>"; };
+ 91C9979B1549DBD400B69A8A /* Shader.fsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = Shader.fsh; sourceTree = "<group>"; };
+ 91C9979C1549DBD400B69A8A /* Shader.vsh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = Shader.vsh; sourceTree = "<group>"; };
+ 91F22017154C7B4600A5F74E /* RAShaderProgram.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RAShaderProgram.h; sourceTree = "<group>"; };
+ 91F22018154C7B4700A5F74E /* RAShaderProgram.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RAShaderProgram.m; sourceTree = "<group>"; };
91F77E221539335000F8AE05 /* EarthViewExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = EarthViewExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
91F77E261539335000F8AE05 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
91F77E281539335000F8AE05 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@@ -121,6 +126,15 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
+ 91C9979A1549DBD300B69A8A /* Shaders */ = {
+ isa = PBXGroup;
+ children = (
+ 91C9979B1549DBD400B69A8A /* Shader.fsh */,
+ 91C9979C1549DBD400B69A8A /* Shader.vsh */,
+ );
+ path = Shaders;
+ sourceTree = SOURCE_ROOT;
+ };
91F77E171539335000F8AE05 = {
isa = PBXGroup;
children = (
@@ -162,6 +176,7 @@
91F77E461539335100F8AE05 /* SceneView_iPad.xib */,
91F77E531539341B00F8AE05 /* Source */,
91F77E841539342A00F8AE05 /* Images */,
+ 91C9979A1549DBD300B69A8A /* Shaders */,
91F77E311539335000F8AE05 /* Supporting Files */,
);
path = EarthViewExample;
@@ -211,6 +226,8 @@
91F77E6F1539341B00F8AE05 /* RATilePager.m */,
91F77E701539341B00F8AE05 /* RATransform.h */,
91F77E711539341B00F8AE05 /* RATransform.m */,
+ 91F22017154C7B4600A5F74E /* RAShaderProgram.h */,
+ 91F22018154C7B4700A5F74E /* RAShaderProgram.m */,
91F77E721539341B00F8AE05 /* TPPropertyAnimation.h */,
91F77E731539341B00F8AE05 /* TPPropertyAnimation.m */,
);
@@ -288,11 +305,11 @@
91F77E481539335100F8AE05 /* SceneView_iPad.xib in Resources */,
91F77E891539342A00F8AE05 /* clear256.png in Resources */,
91F77E8B1539342A00F8AE05 /* grid256.png in Resources */,
- 91F77EAC153A0F9B00F8AE05 /* LICENSE.txt in Resources */,
- 91BBDFB2153A49A900CEF4BA /* README.md in Resources */,
9109E03C153D86100008286D /* star1.png in Resources */,
91C9975C1548E1BF00B69A8A /* Icon114.png in Resources */,
91C9975E1548E1F000B69A8A /* Icon57.png in Resources */,
+ 91C9979D1549DBD400B69A8A /* Shader.fsh in Resources */,
+ 91C9979E1549DBD400B69A8A /* Shader.vsh in Resources */,
91C997601548E21400B69A8A /* Icon144.png in Resources */,
91C997621548E22E00B69A8A /* Icon72.png in Resources */,
);
@@ -323,6 +340,7 @@
91F77E971539C31E00F8AE05 /* RACamera.m in Sources */,
91F77E981539C31E00F8AE05 /* RAGeographicUtils.c in Sources */,
9109E03E153D864F0008286D /* RASceneGraphController.m in Sources */,
+ 91F22019154C7B4700A5F74E /* RAShaderProgram.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges</key>
+ <true/>
+ <key>SnapshotAutomaticallyBeforeSignificantChanges</key>
+ <false/>
+</dict>
+</plist>
@@ -2,4 +2,13 @@
<Bucket
type = "1"
version = "1.0">
+ <ExceptionBreakpoints>
+ <ExceptionBreakpoint
+ shouldBeEnabled = "Yes"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ scope = "0"
+ stopOnStyle = "0">
+ </ExceptionBreakpoint>
+ </ExceptionBreakpoints>
</Bucket>
View
@@ -38,7 +38,6 @@ The example application connects to various map tile services over the web such
Bugs and Limitations
--------------------
-- The light position lags by 1 frame for some reason.
- The derived bounding boxes don't appear to be calculated correctly.
- Should redraw in reaction to Manipulator movement, rather than a constant frame rate. There doesn't appear to be a good way to do this with GLKit.
- There are holes in the globe at the poles because there is no map tile content there.
View
@@ -0,0 +1,17 @@
+//
+// Shader.fsh
+// EarthViewExample
+//
+// Created by Ross Anderson on 4/26/12.
+// Copyright (c) 2012 Ross Anderson. All rights reserved.
+//
+
+uniform sampler2D texture0;
+
+varying mediump vec2 fragmentTextureCoordinates;
+varying lowp vec4 fragmentColor;
+
+void main()
+{
+ gl_FragColor = texture2D(texture0, fragmentTextureCoordinates) * fragmentColor;
+}
View
@@ -0,0 +1,35 @@
+//
+// Shader.vsh
+// EarthViewExample
+//
+// Created by Ross Anderson on 4/26/12.
+// Copyright (c) 2012 Ross Anderson. All rights reserved.
+//
+
+attribute vec4 position;
+attribute vec2 textureCoordinate;
+attribute vec3 normal;
+
+uniform mat4 modelViewProjectionMatrix;
+uniform mat3 normalMatrix;
+
+uniform vec3 lightDirection;
+uniform vec4 lightAmbientColor;
+uniform vec4 lightDiffuseColor;
+
+varying mediump vec2 fragmentTextureCoordinates;
+varying lowp vec4 fragmentColor;
+
+const float c_zero = 0.0;
+const float c_one = 1.0;
+
+void main()
+{
+ vec4 color = lightAmbientColor;
+ float ndotl = max( c_zero, dot( normal, lightDirection ) );
+ color += ndotl * ndotl * lightDiffuseColor;
+
+ gl_Position = modelViewProjectionMatrix * position;
+ fragmentTextureCoordinates = textureCoordinate;
+ fragmentColor = color;
+}
View
@@ -23,7 +23,6 @@
@property (strong, nonatomic) RATextureWrapper * texture0;
@property (strong, nonatomic) RATextureWrapper * texture1;
@property (assign, nonatomic) GLKVector4 color; // set 1st component to -1 to disable
-@property (retain, nonatomic) GLKEffectPropertyMaterial * material;
@property (assign, nonatomic) GLenum elementStyle; // default: GL_TRIANGLES
- (void)setObjectData:(const void *)data withSize:(NSUInteger)length withStride:(NSUInteger)stride;
View
@@ -43,7 +43,6 @@ @implementation RAGeometry {
@synthesize textureOffset = _textureOffset;
@synthesize texture0 = _texture0, texture1 = _texture1;
@synthesize color = _color;
-@synthesize material = _material;
@synthesize elementStyle = _elementStyle;
@@ -241,8 +240,22 @@ - (void)renderGL
[self setupGL];
@synchronized(self) {
+ glActiveTexture (GL_TEXTURE0);
+ if ( _texture0 ) {
+ glBindTexture(GL_TEXTURE_2D, _texture0.name);
+ } else {
+ glBindTexture(GL_TEXTURE_2D, 0);
+ }
+
+ glActiveTexture (GL_TEXTURE1);
+ if ( _texture1 ) {
+ glBindTexture(GL_TEXTURE_2D, _texture1.name);
+ } else {
+ glBindTexture(GL_TEXTURE_2D, 0);
+ }
+
glBindVertexArrayOES(_vertexArray);
-
+
if ( _indexStride > 0 && [_indexData length] > 0 ) {
GLenum type = -1;
switch( _indexStride ) {
Oops, something went wrong. Retry.

0 comments on commit 69115fc

Please sign in to comment.