SlideShare a Scribd company logo
1 of 73
Download to read offline
iOS Visual F/X


Douglass Turner
Elastic Image Software
email: douglass.turner@gmail.com
tweets: @dugla
cell: 781 775 3708
• Cocoa Touch Limitations
• Visual f/x Idioms
• Show and Tell
Cocoa Touch and its realization in
Objective-C is about:

Abstraction. Pattern. Messaging.
Generality. Simplicity.
Containers:
NSArray. NSDictionary. NSSet.

Data:
NSData. NSString. CoreData.

Patterns:
MVC. Target/Action. Delegation.
The Objective-C Runtime is Powerful:

NSClassFromString | NSStringFromClass.
When it comes to visual expressive
power the limitations of Cocoa
Touch become apparent.
UIView lives in flatland ...

// UIView
struct CGRect { CGPoint origin; CGSize size; };
struct CGPoint { CGFloat x; CGFloat y; };

struct CGAffineTransform {
   CGFloat a, b, c, d;
   CGFloat tx, ty;
};

@property(nonatomic)   CGRect              frame;
@property(nonatomic)   CGRect              bounds;
@property(nonatomic)   CGPoint             center;
@property(nonatomic)   CGAffineTransform   transform;

- (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view;
- (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view;

- (CGRect)convertRect:(CGRect)rect toView:(UIView *)view;
- (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;
... but relies on CALayer which lives in 3D.


        struct CATransform3D
        {
           CGFloat m11, m12, m13,   m14;
           CGFloat m21, m22, m23,   m24;
           CGFloat m31, m32, m33,   m34;
           CGFloat m41, m42, m43,   m44;
        };

        // CALayer
        @property CGFloat zPosition;
        @property CGFloat anchorPointZ;
        @property CATransform3D transform;
iOS would prefer you ignore pixels and think
about resolution independent points instead
The level of visual abstraction is the asset:

Image. Video. Audio.
As long as you are willing to remain at this
high level of abstraction you can get a lot
done using UIViewAnimation, CIImage, etc.
But perhaps you are interested in going a bit deeper ...
Hello OpenGL




You take the red pill – you stay in Wonderland and I show you how deep
the rabbit-hole goes." -Morpheus
OpenGL   Cocoa
OpenGL is old school
You are flipping levers on a large state machine.
OpenGL is a dragster. Not a Prius. Just buckle up ...
... and enjoy the ride, baby!
OpenGL websites are a bit different than the
Cocoa websites/blogs you are familiar with ...
Isn’t that sweet ...
Um... WTF?
Can you feel the love?
Dude. I think my eyes are bleeding.
Our focus is GLSL the OpenGL Shading Language
The Shader Backstory

• Pixar creates Reyes (Render Everything You Ever Saw)
• Pixar creates RenderMan: C-like language for describing a
3D look at the sample (pixel) level.
• Boom! Everything changes.
• GLSL created in the spirit of RenderMan.
Shaders allow us to ignore the rest of a
software system, freeing us to focus on
achieving a specific look.
EISParticleSystem
http://github.com/turner/EISParticleSystem
Texture Atlas Hacks




http://github.com/turner/EISParticleSystem
t




                    s


    Texture Space
t




                    s



    Texture Space
Accelerometer Hacks




http://github.com/turner/EISParticleSystem
Initialize model state
touchesBegan:withEvent:




Evolve model state
touchesMoved:withEvent:




Clean up model state
touchesEnded:withEvent:

touchesCancelled:withEvent:
Demo
GLSL. Think C-lite.
TextureMapShader


varying!
       vec2 v_st;

uniform sampler2D hero;

void main() {
!
!   gl_FragColor =
    (heroChannels == 1) ? vec4(texture2D(hero, v_st).a) : texture2D(hero, v_st);
!
}




varying!
       vec2 v_st;

uniform sampler2D hero;

void main() {
!
!   gl_FragColor =
    (heroChannels == 1) ? vec4(texture2D(hero, v_st).a) : texture2D(hero, v_st);
!
}
InvertColorShader




vec2 v_st;

uniform int heroChannels;
uniform sampler2D hero;

void main() {
!   !
    vec3 rgb;
    rgb = (heroChannels == 1) ? 1.0 - vec3(raw.a) : 1.0 - raw.rgb;
    !
   gl_FragColor = vec4(rgb, raw.a);!
}
LuminanceShader



varying vec2 v_st;

uniform int heroChannels;
uniform sampler2D hero;

void main() {
!
    vec4 raw = (heroChannels == 1) ? vec4(texture2D(hero, v_st).a) : texture2D(hero, v_st);

!   vec3 rgb;
!   if (heroChannels == 1) {
!
!   ! rgb = vec3(texture2D(hero, v_st).a);! !
!   } else {
!
!   !   vec3 luminance_weights = vec3(0.30, 0.59, 0.11);!!
!   !   rgb = vec3( dot( luminance_weights, texture2D(hero, v_st).rgb ) );
!   }
!
!   gl_FragColor = vec4(rgb, raw.a);

}
MixShader

varying!
       vec2 v_st;

uniform vec3 overRGB;!
uniform vec3 underRGB;

uniform int heroChannels;
uniform sampler2D hero;

void main() {

!   float mixer;!
!   mixer = (heroChannels == 1) ? texture2D(hero, v_st).a : texture2D(hero, v_st).g;
!
!   gl_FragColor = vec4(mix(underRGB, overRGB, mixer), texture2D(hero, v_st).a);
!
}


varying!
       vec2 v_st;

uniform vec3 overRGB;!
uniform vec3 underRGB;

uniform int heroChannels;
uniform sampler2D hero;

void main() {

!   float mixer;!
!   mixer = (heroChannels == 1) ? texture2D(hero, v_st).a : texture2D(hero, v_st).g;
!
!   gl_FragColor = vec4(mix(underRGB, overRGB, mixer), texture2D(hero, v_st).a);
!
}
The GPU is a parallel processing beast. It uses a SIMD
architecture (Single Instruction Multiple Data) to achieve
massive processing power.


A GLSL shader is a SIMD program. The GPU takes a shader
and evaluates it simultaneously - but with different data - at
every sample (pixel) in parallel:


On iPad that is:
2048 x 1536 * 30 fps = 94,371,840 shader evaluations per sec.
What is exciting about this level of performance on an iOS
device is the ability to take tasks previously thought of as
desktop tasks done with Photoshop, Final Cut, etc. and do
them live in a handheld device equipped with camera, mic,
and other sensors.
Demo. GLSL Powered Apps



• Beautiful Panoramas. App Store: http://bit.ly/9KJBLA
• BMW Interior. Panoramic hotspots prototype.
• RadPad. iPad radiology prototype.
Shader Idioms

To fully “get” the power of shaders and their style of use it helps
know the idioms guiding their use:


• Multiple Passes
• Iteration aka Ping/Pong
• Buffers/Channels
• Indirection/Remapping
Shader Idioms

These idioms derive directly from Hollywood film production
workflows and practices that enable:
• complex problem decomposition. Tractability.
• rapid turnaround.
• maximum flexibility and tweek-ability.
• responsiveness to director’s whims
Demo. ElasticImage.
ElasticImage highlights.


• Rapid shader creation & deployment
• Shaders and gesture declared in plist
• Cocoa Touch for gestures & the usual.
• C++ for 3D glue code.
Shader Example: ColourLovers
I selected interesting palettes and created a texture.




Horizontal axis is the color palette.
Vertical axis selects between color palettes.


At runtime this palette texture is loaded and attached to
the ColourLoverShader.
EISColourLoversShader.fsh



varying!
       mediump vec2 v_st;

// Palette selector
uniform float paletteDial;

// Contribution of remapped color
uniform float strengthDial;

// Palettes are ganged together into a single texture.
// A specific palette is selected with the paletteDial
uniform sampler2D colourLoversPalettes;

// hero
uniform   int heroChannels;
uniform sampler2D hero;

void main() {
!
!   vec4 raw = (heroChannels == 1) ? vec4(texture2D(hero, v_st).a) : texture2D(hero, v_st);
!
!   vec3 cooked;
!   cooked.r = texture2D(colourLoversPalettes, vec2(raw.r, paletteDial)).r;
!   cooked.g = texture2D(colourLoversPalettes, vec2(raw.g, paletteDial)).g;
!   cooked.b = texture2D(colourLoversPalettes, vec2(raw.b, paletteDial)).b;
!
!   gl_FragColor = vec4(mix(raw.rgb, cooked, strengthDial), raw.a);
}
EISColourLoversShader.fsh



varying!
       mediump vec2 v_st;

// Palette selector
uniform float paletteDial;

// Contribution of remapped color
uniform float strengthDial;

// Palettes are ganged together into a single texture.
// A specific palette is selected with the paletteDial
uniform sampler2D colourLoversPalettes;

// hero
uniform   int heroChannels;
uniform sampler2D hero;

void main() {
!
!   vec4 raw = (heroChannels == 1) ? vec4(texture2D(hero, v_st).a) : texture2D(hero, v_st);
!
!   vec3 cooked;
!   cooked.r = texture2D(colourLoversPalettes, vec2(raw.r, paletteDial)).r;
!   cooked.g = texture2D(colourLoversPalettes, vec2(raw.g, paletteDial)).g;
!   cooked.b = texture2D(colourLoversPalettes, vec2(raw.b, paletteDial)).b;
!
!   gl_FragColor = vec4(mix(raw.rgb, cooked, strengthDial), raw.a);
}
Demo ColourLovers Shader
Hue Shift Shader




RGB                      HSB
Conceptually simple idea. Use one channel of a
photo to select the hue of a resultant image.
Demo Hue Shift Shader
Quantize ST Shader
Sampling a texture at a low rate results in quantization.




    Beyond Photography - The Digital Darkroom by Gerard J. Holzmann
Sampling in polar coordinates rather then cartesian is a bit more interesting.




               Beyond Photography - The Digital Darkroom by Gerard J. Holzmann
Demo Quantize ST Shader
BurnShader
red channel = drop shadow                      green channel = cut out




                            final rgb texture
Demo BurnShader
Links


A previous meetup talk I gave on iOS OpenGL
• iOS OpenGL - http://slidesha.re/Y1MW8


Github - code
• HelloGLSL - http://bit.ly/JCcMju
• EISRenderHelpful. Helpful 3D rendering glue code - http://bit.ly/JZ4HW3


Github - people to follow
• Philip Rideout - https://github.com/prideout
• Raphael Sebbe - https://github.com/rsebbe
• Brad Larson - https://github.com/BradLarson
• Jeff LaMarche - https://github.com/jlamarche

Elsewhere:
• Martins Upitis - http://devlog-martinsh.blogspot.com/
• Ole Begemann - http://bit.ly/srlCBV
• Daniel Rakos - http://bit.ly/a3QATn
Thank You!
Douglass Turner
Elastic Image Software
email: douglass.turner@gmail.com
tweets: @dugla
cell: 781 775 3708
                                   Copyright © Douglass Turner

More Related Content

Similar to iOS Visual F/X Using GLSL

GL Shading Language Document by OpenGL.pdf
GL Shading Language Document by OpenGL.pdfGL Shading Language Document by OpenGL.pdf
GL Shading Language Document by OpenGL.pdfshaikhshehzad024
 
OpenGL Introduction
OpenGL IntroductionOpenGL Introduction
OpenGL IntroductionYi-Lung Tsai
 
Neurotech Solutions Ltd: Рекомендации по Stage3D: выбор наиболее подходящего ...
Neurotech Solutions Ltd: Рекомендации по Stage3D: выбор наиболее подходящего ...Neurotech Solutions Ltd: Рекомендации по Stage3D: выбор наиболее подходящего ...
Neurotech Solutions Ltd: Рекомендации по Stage3D: выбор наиболее подходящего ...DevGAMM Conference
 
Minko stage3d workshop_20130525
Minko stage3d workshop_20130525Minko stage3d workshop_20130525
Minko stage3d workshop_20130525Minko3D
 
Cg shaders with Unity3D
Cg shaders with Unity3DCg shaders with Unity3D
Cg shaders with Unity3DMichael Ivanov
 
【Unite 2017 Tokyo】シェーダープログラミング入門!カスタムシェーダー、作るで!
【Unite 2017 Tokyo】シェーダープログラミング入門!カスタムシェーダー、作るで!【Unite 2017 Tokyo】シェーダープログラミング入門!カスタムシェーダー、作るで!
【Unite 2017 Tokyo】シェーダープログラミング入門!カスタムシェーダー、作るで!Unity Technologies Japan K.K.
 
Unconventional webapps with gwt:elemental & html5
Unconventional webapps with gwt:elemental & html5Unconventional webapps with gwt:elemental & html5
Unconventional webapps with gwt:elemental & html5firenze-gtug
 
CS 354 Programmable Shading
CS 354 Programmable ShadingCS 354 Programmable Shading
CS 354 Programmable ShadingMark Kilgard
 
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeksBeginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeksJinTaek Seo
 
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...ICS
 
Penn graphics
Penn graphicsPenn graphics
Penn graphicsfloored
 
Dynamic Wounds on Animated Characters in UE4
Dynamic Wounds on Animated Characters in UE4Dynamic Wounds on Animated Characters in UE4
Dynamic Wounds on Animated Characters in UE4Michał Kłoś
 
Opengl presentation
Opengl presentationOpengl presentation
Opengl presentationelnaqah
 
Game Programming 12 - Shaders
Game Programming 12 - ShadersGame Programming 12 - Shaders
Game Programming 12 - ShadersNick Pruehs
 
Building Native Apps- A Digital Canvas for Coders and Designers with Walter Luh
Building Native Apps- A Digital Canvas for Coders and Designers with Walter LuhBuilding Native Apps- A Digital Canvas for Coders and Designers with Walter Luh
Building Native Apps- A Digital Canvas for Coders and Designers with Walter LuhFITC
 
Going to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGoing to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGuillaume Laforge
 

Similar to iOS Visual F/X Using GLSL (20)

GL Shading Language Document by OpenGL.pdf
GL Shading Language Document by OpenGL.pdfGL Shading Language Document by OpenGL.pdf
GL Shading Language Document by OpenGL.pdf
 
OpenGL Introduction
OpenGL IntroductionOpenGL Introduction
OpenGL Introduction
 
Neurotech Solutions Ltd: Рекомендации по Stage3D: выбор наиболее подходящего ...
Neurotech Solutions Ltd: Рекомендации по Stage3D: выбор наиболее подходящего ...Neurotech Solutions Ltd: Рекомендации по Stage3D: выбор наиболее подходящего ...
Neurotech Solutions Ltd: Рекомендации по Stage3D: выбор наиболее подходящего ...
 
Minko stage3d workshop_20130525
Minko stage3d workshop_20130525Minko stage3d workshop_20130525
Minko stage3d workshop_20130525
 
Cg shaders with Unity3D
Cg shaders with Unity3DCg shaders with Unity3D
Cg shaders with Unity3D
 
Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
 
【Unite 2017 Tokyo】シェーダープログラミング入門!カスタムシェーダー、作るで!
【Unite 2017 Tokyo】シェーダープログラミング入門!カスタムシェーダー、作るで!【Unite 2017 Tokyo】シェーダープログラミング入門!カスタムシェーダー、作るで!
【Unite 2017 Tokyo】シェーダープログラミング入門!カスタムシェーダー、作るで!
 
COLLADA & WebGL
COLLADA & WebGLCOLLADA & WebGL
COLLADA & WebGL
 
Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
 
Unconventional webapps with gwt:elemental & html5
Unconventional webapps with gwt:elemental & html5Unconventional webapps with gwt:elemental & html5
Unconventional webapps with gwt:elemental & html5
 
CS 354 Programmable Shading
CS 354 Programmable ShadingCS 354 Programmable Shading
CS 354 Programmable Shading
 
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeksBeginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
 
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
OpenGL Fixed Function to Shaders - Porting a fixed function application to “m...
 
Penn graphics
Penn graphicsPenn graphics
Penn graphics
 
Dynamic Wounds on Animated Characters in UE4
Dynamic Wounds on Animated Characters in UE4Dynamic Wounds on Animated Characters in UE4
Dynamic Wounds on Animated Characters in UE4
 
Opengl presentation
Opengl presentationOpengl presentation
Opengl presentation
 
Game Programming 12 - Shaders
Game Programming 12 - ShadersGame Programming 12 - Shaders
Game Programming 12 - Shaders
 
OpenGL for 2015
OpenGL for 2015OpenGL for 2015
OpenGL for 2015
 
Building Native Apps- A Digital Canvas for Coders and Designers with Walter Luh
Building Native Apps- A Digital Canvas for Coders and Designers with Walter LuhBuilding Native Apps- A Digital Canvas for Coders and Designers with Walter Luh
Building Native Apps- A Digital Canvas for Coders and Designers with Walter Luh
 
Going to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific LanguagesGoing to Mars with Groovy Domain-Specific Languages
Going to Mars with Groovy Domain-Specific Languages
 

Recently uploaded

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 

Recently uploaded (20)

Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 

iOS Visual F/X Using GLSL

  • 1. iOS Visual F/X Douglass Turner Elastic Image Software email: douglass.turner@gmail.com tweets: @dugla cell: 781 775 3708
  • 2. • Cocoa Touch Limitations • Visual f/x Idioms • Show and Tell
  • 3. Cocoa Touch and its realization in Objective-C is about: Abstraction. Pattern. Messaging. Generality. Simplicity.
  • 4. Containers: NSArray. NSDictionary. NSSet. Data: NSData. NSString. CoreData. Patterns: MVC. Target/Action. Delegation.
  • 5. The Objective-C Runtime is Powerful: NSClassFromString | NSStringFromClass.
  • 6. When it comes to visual expressive power the limitations of Cocoa Touch become apparent.
  • 7. UIView lives in flatland ... // UIView struct CGRect { CGPoint origin; CGSize size; }; struct CGPoint { CGFloat x; CGFloat y; }; struct CGAffineTransform { CGFloat a, b, c, d; CGFloat tx, ty; }; @property(nonatomic) CGRect frame; @property(nonatomic) CGRect bounds; @property(nonatomic) CGPoint center; @property(nonatomic) CGAffineTransform transform; - (CGPoint)convertPoint:(CGPoint)point toView:(UIView *)view; - (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view; - (CGRect)convertRect:(CGRect)rect toView:(UIView *)view; - (CGRect)convertRect:(CGRect)rect fromView:(UIView *)view;
  • 8. ... but relies on CALayer which lives in 3D. struct CATransform3D { CGFloat m11, m12, m13, m14; CGFloat m21, m22, m23, m24; CGFloat m31, m32, m33, m34; CGFloat m41, m42, m43, m44; }; // CALayer @property CGFloat zPosition; @property CGFloat anchorPointZ; @property CATransform3D transform;
  • 9. iOS would prefer you ignore pixels and think about resolution independent points instead
  • 10. The level of visual abstraction is the asset: Image. Video. Audio.
  • 11. As long as you are willing to remain at this high level of abstraction you can get a lot done using UIViewAnimation, CIImage, etc.
  • 12. But perhaps you are interested in going a bit deeper ...
  • 13. Hello OpenGL You take the red pill – you stay in Wonderland and I show you how deep the rabbit-hole goes." -Morpheus
  • 14. OpenGL Cocoa
  • 15. OpenGL is old school
  • 16. You are flipping levers on a large state machine.
  • 17. OpenGL is a dragster. Not a Prius. Just buckle up ...
  • 18. ... and enjoy the ride, baby!
  • 19. OpenGL websites are a bit different than the Cocoa websites/blogs you are familiar with ...
  • 22. Can you feel the love?
  • 23. Dude. I think my eyes are bleeding.
  • 24. Our focus is GLSL the OpenGL Shading Language
  • 25. The Shader Backstory • Pixar creates Reyes (Render Everything You Ever Saw) • Pixar creates RenderMan: C-like language for describing a 3D look at the sample (pixel) level. • Boom! Everything changes. • GLSL created in the spirit of RenderMan.
  • 26. Shaders allow us to ignore the rest of a software system, freeing us to focus on achieving a specific look.
  • 29. t s Texture Space
  • 30. t s Texture Space
  • 32. Initialize model state touchesBegan:withEvent: Evolve model state touchesMoved:withEvent: Clean up model state touchesEnded:withEvent: touchesCancelled:withEvent:
  • 33. Demo
  • 35. TextureMapShader varying! vec2 v_st; uniform sampler2D hero; void main() { ! ! gl_FragColor = (heroChannels == 1) ? vec4(texture2D(hero, v_st).a) : texture2D(hero, v_st); ! } varying! vec2 v_st; uniform sampler2D hero; void main() { ! ! gl_FragColor = (heroChannels == 1) ? vec4(texture2D(hero, v_st).a) : texture2D(hero, v_st); ! }
  • 36. InvertColorShader vec2 v_st; uniform int heroChannels; uniform sampler2D hero; void main() { ! ! vec3 rgb; rgb = (heroChannels == 1) ? 1.0 - vec3(raw.a) : 1.0 - raw.rgb; ! gl_FragColor = vec4(rgb, raw.a);! }
  • 37.
  • 38.
  • 39. LuminanceShader varying vec2 v_st; uniform int heroChannels; uniform sampler2D hero; void main() { ! vec4 raw = (heroChannels == 1) ? vec4(texture2D(hero, v_st).a) : texture2D(hero, v_st); ! vec3 rgb; ! if (heroChannels == 1) { ! ! ! rgb = vec3(texture2D(hero, v_st).a);! ! ! } else { ! ! ! vec3 luminance_weights = vec3(0.30, 0.59, 0.11);!! ! ! rgb = vec3( dot( luminance_weights, texture2D(hero, v_st).rgb ) ); ! } ! ! gl_FragColor = vec4(rgb, raw.a); }
  • 40.
  • 41.
  • 42. MixShader varying! vec2 v_st; uniform vec3 overRGB;! uniform vec3 underRGB; uniform int heroChannels; uniform sampler2D hero; void main() { ! float mixer;! ! mixer = (heroChannels == 1) ? texture2D(hero, v_st).a : texture2D(hero, v_st).g; ! ! gl_FragColor = vec4(mix(underRGB, overRGB, mixer), texture2D(hero, v_st).a); ! } varying! vec2 v_st; uniform vec3 overRGB;! uniform vec3 underRGB; uniform int heroChannels; uniform sampler2D hero; void main() { ! float mixer;! ! mixer = (heroChannels == 1) ? texture2D(hero, v_st).a : texture2D(hero, v_st).g; ! ! gl_FragColor = vec4(mix(underRGB, overRGB, mixer), texture2D(hero, v_st).a); ! }
  • 43.
  • 44. The GPU is a parallel processing beast. It uses a SIMD architecture (Single Instruction Multiple Data) to achieve massive processing power. A GLSL shader is a SIMD program. The GPU takes a shader and evaluates it simultaneously - but with different data - at every sample (pixel) in parallel: On iPad that is: 2048 x 1536 * 30 fps = 94,371,840 shader evaluations per sec.
  • 45. What is exciting about this level of performance on an iOS device is the ability to take tasks previously thought of as desktop tasks done with Photoshop, Final Cut, etc. and do them live in a handheld device equipped with camera, mic, and other sensors.
  • 46. Demo. GLSL Powered Apps • Beautiful Panoramas. App Store: http://bit.ly/9KJBLA • BMW Interior. Panoramic hotspots prototype. • RadPad. iPad radiology prototype.
  • 47. Shader Idioms To fully “get” the power of shaders and their style of use it helps know the idioms guiding their use: • Multiple Passes • Iteration aka Ping/Pong • Buffers/Channels • Indirection/Remapping
  • 48. Shader Idioms These idioms derive directly from Hollywood film production workflows and practices that enable: • complex problem decomposition. Tractability. • rapid turnaround. • maximum flexibility and tweek-ability. • responsiveness to director’s whims
  • 50. ElasticImage highlights. • Rapid shader creation & deployment • Shaders and gesture declared in plist • Cocoa Touch for gestures & the usual. • C++ for 3D glue code.
  • 51.
  • 53.
  • 54.
  • 55. I selected interesting palettes and created a texture. Horizontal axis is the color palette. Vertical axis selects between color palettes. At runtime this palette texture is loaded and attached to the ColourLoverShader.
  • 56. EISColourLoversShader.fsh varying! mediump vec2 v_st; // Palette selector uniform float paletteDial; // Contribution of remapped color uniform float strengthDial; // Palettes are ganged together into a single texture. // A specific palette is selected with the paletteDial uniform sampler2D colourLoversPalettes; // hero uniform int heroChannels; uniform sampler2D hero; void main() { ! ! vec4 raw = (heroChannels == 1) ? vec4(texture2D(hero, v_st).a) : texture2D(hero, v_st); ! ! vec3 cooked; ! cooked.r = texture2D(colourLoversPalettes, vec2(raw.r, paletteDial)).r; ! cooked.g = texture2D(colourLoversPalettes, vec2(raw.g, paletteDial)).g; ! cooked.b = texture2D(colourLoversPalettes, vec2(raw.b, paletteDial)).b; ! ! gl_FragColor = vec4(mix(raw.rgb, cooked, strengthDial), raw.a); }
  • 57. EISColourLoversShader.fsh varying! mediump vec2 v_st; // Palette selector uniform float paletteDial; // Contribution of remapped color uniform float strengthDial; // Palettes are ganged together into a single texture. // A specific palette is selected with the paletteDial uniform sampler2D colourLoversPalettes; // hero uniform int heroChannels; uniform sampler2D hero; void main() { ! ! vec4 raw = (heroChannels == 1) ? vec4(texture2D(hero, v_st).a) : texture2D(hero, v_st); ! ! vec3 cooked; ! cooked.r = texture2D(colourLoversPalettes, vec2(raw.r, paletteDial)).r; ! cooked.g = texture2D(colourLoversPalettes, vec2(raw.g, paletteDial)).g; ! cooked.b = texture2D(colourLoversPalettes, vec2(raw.b, paletteDial)).b; ! ! gl_FragColor = vec4(mix(raw.rgb, cooked, strengthDial), raw.a); }
  • 60. Conceptually simple idea. Use one channel of a photo to select the hue of a resultant image.
  • 61. Demo Hue Shift Shader
  • 63. Sampling a texture at a low rate results in quantization. Beyond Photography - The Digital Darkroom by Gerard J. Holzmann
  • 64. Sampling in polar coordinates rather then cartesian is a bit more interesting. Beyond Photography - The Digital Darkroom by Gerard J. Holzmann
  • 67.
  • 68.
  • 69. red channel = drop shadow green channel = cut out final rgb texture
  • 71. Links A previous meetup talk I gave on iOS OpenGL • iOS OpenGL - http://slidesha.re/Y1MW8 Github - code • HelloGLSL - http://bit.ly/JCcMju • EISRenderHelpful. Helpful 3D rendering glue code - http://bit.ly/JZ4HW3 Github - people to follow • Philip Rideout - https://github.com/prideout • Raphael Sebbe - https://github.com/rsebbe • Brad Larson - https://github.com/BradLarson • Jeff LaMarche - https://github.com/jlamarche Elsewhere: • Martins Upitis - http://devlog-martinsh.blogspot.com/ • Ole Begemann - http://bit.ly/srlCBV • Daniel Rakos - http://bit.ly/a3QATn
  • 73. Douglass Turner Elastic Image Software email: douglass.turner@gmail.com tweets: @dugla cell: 781 775 3708 Copyright © Douglass Turner