Skip to content

Commit

Permalink
Add VR button and start with VR flow
Browse files Browse the repository at this point in the history
  • Loading branch information
reindernijhoff committed Nov 15, 2015
1 parent 78059d6 commit 2e8ac48
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 8 deletions.
49 changes: 47 additions & 2 deletions shadertoy/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions shadertoy/Images.xcassets/vr.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "vr.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file added shadertoy/Images.xcassets/vr.imageset/vr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions shadertoy/ShaderCanvasViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import <GLKit/GLKit.h>
#import "APIShaderObject.h"
#import "VRSettings.h"

typedef NS_ENUM(NSUInteger, ShaderInputFilterMode) {
NEAREST,
Expand All @@ -22,6 +23,7 @@ typedef NS_ENUM(NSUInteger, ShaderInputWrapMode) {

@interface ShaderCanvasViewController : GLKViewController

- (void) setVRSettings:(VRSettings *)vrSettings;
- (BOOL) compileShaderPass:(APIShaderPass *)shader theError:(NSString **)error;

- (void) start;
Expand Down
19 changes: 17 additions & 2 deletions shadertoy/ShaderCanvasViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

@interface ShaderCanvasViewController () {
APIShaderPass* _shaderPass;
VRSettings* _vrSettings;

GLuint _programId;
GLuint _vertexBuffer;
Expand Down Expand Up @@ -94,13 +95,19 @@ - (BOOL) createShaderProgram:(APIShaderPass *)shaderPass theError:(NSString **)e
GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);

NSString *VertexShaderCode = [[NSString alloc] readFromFile:@"/shaders/vertex_main" ofType:@"glsl"];
NSString *VertexShaderCode;

if( _vrSettings ) {
VertexShaderCode = [_vrSettings getVertexShaderCode];
} else {
VertexShaderCode = [[NSString alloc] readFromFile:@"/shaders/vertex_main" ofType:@"glsl"];
}

char const * VertexSourcePointer = [VertexShaderCode UTF8String];
glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
glCompileShader(VertexShaderID);

NSString *FragmentShaderCode = [[NSString alloc] readFromFile:@"/shaders/fragment_base_uniforms" ofType:@"glsl"];
NSString *FragmentShaderCode =[[NSString alloc] readFromFile:@"/shaders/fragment_base_uniforms" ofType:@"glsl"];

for( APIShaderPassInput* input in shaderPass.inputs ) {
if( [input.ctype isEqualToString:@"cubemap"] ) {
Expand All @@ -117,6 +124,8 @@ - (BOOL) createShaderProgram:(APIShaderPass *)shaderPass theError:(NSString **)e

if( [shaderPass.type isEqualToString:@"sound"] ) {
FragmentShaderCode = [FragmentShaderCode stringByAppendingString:[[NSString alloc] readFromFile:@"/shaders/fragment_main_sound" ofType:@"glsl"]];
} else if( _vrSettings ) {
FragmentShaderCode = [FragmentShaderCode stringByAppendingString:[_vrSettings getFragmentShaderCode]];
} else {
FragmentShaderCode = [FragmentShaderCode stringByAppendingString:[[NSString alloc] readFromFile:@"/shaders/fragment_main_image" ofType:@"glsl"]];
}
Expand Down Expand Up @@ -326,6 +335,12 @@ - (void)bindUniforms {
}
}

#pragma mark - VR

- (void) setVRSettings:(VRSettings *)vrSettings {
_vrSettings = vrSettings;
}

#pragma mark - ShaderCanvasViewController

- (BOOL)compileShaderPass:(APIShaderPass *)shader theError:(NSString **)error {
Expand Down
4 changes: 4 additions & 0 deletions shadertoy/ShaderViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>

#import "APIShaderObject.h"
#import "VRSettings.h"

typedef NS_ENUM(NSUInteger, ShaderViewMode) {
VIEW_FULLSCREEN_IF_LANDSCAPE,
Expand All @@ -25,6 +27,7 @@ typedef NS_ENUM(NSUInteger, ShaderViewMode) {

@property (strong, nonatomic) IBOutlet UILabel *shaderCompiling;
@property (strong, nonatomic) IBOutlet UIButton *shaderCompileInfoButton;
@property (strong, nonatomic) IBOutlet UIButton *shaderVRButton;

@property (strong, nonatomic) IBOutlet UIButton *shaderPlayerRewind;
@property (strong, nonatomic) IBOutlet UIButton *shaderPlayerPlay;
Expand All @@ -34,5 +37,6 @@ typedef NS_ENUM(NSUInteger, ShaderViewMode) {
@property (strong, nonatomic) IBOutlet UIBarButtonItem *shaderShareButton;

- (void) setShaderObject:(APIShaderObject *)shader;
- (void) setVRSettings:(VRSettings *)vrSettings;

@end
22 changes: 22 additions & 0 deletions shadertoy/ShaderViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
@interface ShaderViewController () {
APIShaderObject* _shader;
SoundPassPlayer* _soundPassPlayer;
VRSettings* _vrSettings;

UIView* _imageShaderView;
ShaderCanvasViewController* _imageShaderViewController;
Expand Down Expand Up @@ -238,6 +239,9 @@ - (void) compileImageShader {
if( ![headerComment isEqualToString:@""] ) {
[_shaderCompileInfoButton setHidden:NO];
}
if( [_shader vrImplemented] && !_vrSettings ) {
[_shaderVRButton setHidden:NO];
}
} completion:^(BOOL finished) {
[_shaderImageView setHidden:YES];
[weakSelf.view bringSubviewToFront:_imageShaderView];
Expand Down Expand Up @@ -304,6 +308,24 @@ - (void) playSoundSyncedWithShader {
}
}

#pragma mark - VR

- (void) setVRSettings:(VRSettings *)vrSettings {
_vrSettings = vrSettings;
[_imageShaderViewController setVRSettings:vrSettings];
}

- (IBAction)shaderVRClick:(id)sender {
VRSettings *vrSettings = [[VRSettings alloc] init];

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
UIViewController* viewController = (UIViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"ShaderViewController"];

[((ShaderViewController *)viewController) setShaderObject:_shader];
[((ShaderViewController *)viewController) setVRSettings:vrSettings];
[self.navigationController pushViewController:viewController animated:YES];
}

#pragma mark - UI

- (IBAction)shaderPlayerRewindClick:(id)sender {
Expand Down
3 changes: 3 additions & 0 deletions shadertoy/VRSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@ typedef NS_ENUM(NSUInteger, VRSettingsInput) {
@property (atomic) VRSettingsRenderMode renderMode;
@property (atomic) VRSettingsInput inputMode;

-(NSString *) getVertexShaderCode;
-(NSString *) getFragmentShaderCode;

@end
22 changes: 22 additions & 0 deletions shadertoy/VRSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,29 @@
//

#import "VRSettings.h"
#import "Utils.h"

@implementation VRSettings

@synthesize renderMode, rightEyeParams, leftEyeParams, inputMode, positionState;

- (id)init {
self = [super init];
if(self){
}
return self;
}

-(NSString *) getVertexShaderCode {
NSString *vertexShaderCode = [[NSString alloc] readFromFile:@"/shaders/vertex_main" ofType:@"glsl"];
return vertexShaderCode;
}

-(NSString *) getFragmentShaderCode {
NSString *fragmentShaderCode = [[NSString alloc] readFromFile:@"/shaders/fragment_main_vr" ofType:@"glsl"];
return fragmentShaderCode;
}



@end
2 changes: 1 addition & 1 deletion shadertoy/shaders/fragment_main_image.glsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
void main() {
mainImage(gl_FragColor, gl_FragCoord.xy + ifFragCoordOffsetUniform );
gl_FragColor.w = 1.;
}
}
2 changes: 1 addition & 1 deletion shadertoy/shaders/fragment_main_sound.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ void main() {
vec2 vl = mod(v,256.0)/255.0;
vec2 vh = floor(v/256.0)/255.0;
gl_FragColor = vec4(vl.x,vh.x,vl.y,vh.y);
}
}
2 changes: 1 addition & 1 deletion shadertoy/shaders/fragment_main_vr.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ void main() {
gl_FragColor.xyz *= vec3( eyeID, 1.0-eyeID, 1.0-eyeID );

gl_FragColor.w = 1.;
}
}
2 changes: 1 addition & 1 deletion shadertoy/shaders/vertex_main.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ attribute vec3 position;
void main() {
gl_Position.xyz = position;
gl_Position.w = 1.0;
}
}

0 comments on commit 2e8ac48

Please sign in to comment.