SlideShare a Scribd company logo
1 of 73
Download to read offline
The Day You 
Finally Use Algebra! 
Janie Clayton
About Me
But math is hard! 
(Let’s go shopping!)
Math is hard. 
But math is fun too.
Demo
Normalized 
Coordinate 
Systems
Cartesian 
Coordinates
320 
480
320 
480 
or 
568
1 
1
(0,0) (1,0) 
(0,1) (1,1)
(0,0) (1,0) 
(0,1) (1,1)
(0,0) (1,0) 
(0,1) (1,1)
self.size.width 
self. 
size. 
height
- Colors, like the 
screen dimensions, 
are based on 
percentages rather 
than absolute 
values. 
- If you come from 
a graphic design 
background, you 
need to convert 
your 255 scale to 
percentages.
Algorithm Rosetta 
Stone
Rosetta Stone 
- Had the same text in 
Greek, demotic, and 
hieroglyphics. Was 
used to translate 
hieroglyphics 
- Going to do similar 
thing, but with math 
algorithms, plain 
English, and code
√-1 2ˆ3 Σ π
Algoritm 
Σ5 
i = 1 
4i
Plain English 
I have a starting value of one. 
I have an end value of five. 
I want to multiply each value 
by four and add them together.
var x = 0 
for index in 1…5 { 
x += (4 * index) 
} 
Code
√-1 2ˆ3 Σ π 
…and it was delicious!
i 8 sum pi 
…and it was delicious!
Trigonometry
Triangles 
A shape with three sides where the 
angles add up to 180 degrees 
Everything in our world comes back 
to triangles 
The most stable shape 
Foundation of 3D graphics
Right Triangles
Pythagorean 
Theorem 
aˆ2 + bˆ2 = cˆ2
Circle Formulas 
Circumference: 2πr 
Area: πrˆ2
So What Can We Do 
Knowing This? 
Change the direction a character is 
moving in 
Check to see if the user is hitting a 
target area on the screen 
Draw shapes and filters in specific 
configurations
Linear Algebra
“The survivors of 
linear algebra classes 
are physicists, graphics 
programmers and other 
masochists.” 
– BetterExplained.com
What is Linear 
Algebra? 
Linear Algebra allows you to 
perform an action on many values 
at the same time. 
This action must be consistent 
across all values, such as multiplying 
every value by two.
What is Linear 
Algebra? 
Values are placed in an object 
called a matrix and the actions 
performed on the values are called 
transforms 
Linear algebra is optimized for 
parallel mathematical operations.
Vector Data Types 
vec2, vec3, vec4: 2D, 3D, and 4D 
floating point vector objects. 
vec2: (x, y) 
vec3: (x, y, z) 
vec4: (r, g, b, a)
Vectors 
9 
3 
3√10
Demo
Enter the Matrix
Matrix Data Types 
mat2, mat3, mat4: 2, 3, and 4 
element matrices. 
mat2: Holds a 2 X 2 number matrix 
mat3: Holds a 3 X 3 number matrix, 
used for 2D linear algebra 
mat4: Holds a 4 X 4 number matrix, 
used for 3D linear algebra
Column 
1.0 1.0 1.0 0 
1.0 1.0 1.0 0 
1.0 1.0 1.0 0 
1.0 1.0 1.0 0 
Row
mat4 genericMatrix = mat4( 
1.0, 1.0, 1.0, 1.0, 
1.0, 1.0, 1.0, 1.0, 
1.0, 1.0, 1.0, 1.0, 
0, 0, 0, 0 
Column 
); 
Row
vec4 firstColumn = vec4(1.0, 1.0, 1.0, 
1.0); 
vec4 secondColumn = vec4(1.0, 1.0, 1.0, 
1.0); 
vec4 thirdColumn = vec4(1.0, 1.0, 1.0, 
1.0); 
vec4 fouthColumn = vec4(0, 0, 0, 0); 
mat4 myMatrix = mat4( 
firstColumn, SecondColumn, 
thirdColumn, FourthColumn 
);
CGAffineTransform
Affine, Wha?? :( 
A transform is any function that 
alters the size, position, or rotation 
of an object on your screen. 
Four types: Identity, Translate, 
Rotation, and Scale. 
For a transform to be affine, the 
lines in your shape must be parallel.
CGAffine 
Transform Methods 
CGAffineTransformMakeRotation 
(GLFloat angle); 
CGAffineTransformMakeScale 
(CGFLoat sx, CGFloat sy); 
CGAffineTransformMakeTranslation 
(CGFloat tx, CGFloat ty);
struct CGAffineTransform { 
CGFloat a; 
GLFloat b; 
CGFloat c; 
CGFloat d; 
CGFloat tx; 
CGFloat ty 
}
[x y 1] 
[a b 0 
c d 0 
tx ty 0] 
X = 
[x’ y’ 1]
let pointX = a * x + 
c * y + tx 
let pointY = b * x 
+ d * y + ty
CGAffineTransformMakeRotation(45) 
CGAffineTransformMakeScale(2,2)
rotate 45 
degrees 
Double 
Size
Refraction 
Fragment 
Shader 
Example
void main() 
{ 
highp vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * 
aspectRatio + 0.5 - 0.5 * aspectRatio)); 
highp float distanceFromCenter = distance(center, textureCoordinateToUse); 
lowp float checkForPresenceWithinSphere = step(distanceFromCenter, radius); 
distanceFromCenter = distanceFromCenter / radius; 
highp float normalizedDepth = radius * sqrt(1.0 - distanceFromCenter * 
distanceFromCenter); 
highp vec3 sphereNormal = normalize(vec3(textureCoordinateToUse - center, 
normalizedDepth)); 
highp vec3 refractedVector = 2.0 * refract(vec3(0.0, 0.0, -1.0), sphereNormal, 
refractiveIndex); 
refractedVector.xy = -refractedVector.xy; 
highp vec3 finalSphereColor = texture2D(inputImageTexture, (refractedVector.xy + 1.0) * 
0.5).rgb; 
// Grazing angle lighting 
highp float lightingIntensity = 2.5 * (1.0 - pow(clamp(dot(ambientLightPosition, 
sphereNormal), 0.0, 1.0), 0.25)); 
finalSphereColor += lightingIntensity; 
// Specular lighting 
lightingIntensity = clamp(dot(normalize(lightPosition), sphereNormal), 0.0, 1.0); 
lightingIntensity = pow(lightingIntensity, 15.0); 
finalSphereColor += vec3(0.8, 0.8, 0.8) * lightingIntensity; 
gl_FragColor = vec4(finalSphereColor, 1.0) * checkForPresenceWithinSphere; 
}
highp vec2 textureCoordinateToUse = 
vec2(textureCoordinate.x, 
(textureCoordinate.y * aspectRatio + 
0.5 - 0.5 * aspectRatio));
highp float 
distanceFromCenter = 
distance(center, 
textureCoordinateToUse);
lowp float 
checkForPresenceWithinSphere 
= step(distanceFromCenter, 
radius);
distanceFromCenter = 
distanceFromCenter / 
radius;
highp float normalizedDepth = 
radius * sqrt(1.0 - 
distanceFromCenter * 
distanceFromCenter);
highp vec3 sphereNormal = 
normalize(vec3 
(textureCoordinateToUse - 
center, normalizedDepth));
highp vec3 refractedVector = 
refract(vec3(0.0, 0.0, -1.0), 
sphereNormal, 
refractiveIndex);
gl_FragColor = 
texture2D(inputImageTexture, 
(refractedVector.xy + 1.0) * 0.5) 
* checkForPresenceWithinSphere;
The End

More Related Content

What's hot

Solving systems by substitution
Solving systems by substitutionSolving systems by substitution
Solving systems by substitution
joannahstevens
 
The Application of Derivatives
The Application of DerivativesThe Application of Derivatives
The Application of Derivatives
divaprincess09
 
L5 infinite limits squeeze theorem
L5 infinite limits squeeze theoremL5 infinite limits squeeze theorem
L5 infinite limits squeeze theorem
James Tagara
 

What's hot (20)

Applied numerical methods lec9
Applied numerical methods lec9Applied numerical methods lec9
Applied numerical methods lec9
 
Lagrange’s interpolation formula
Lagrange’s interpolation formulaLagrange’s interpolation formula
Lagrange’s interpolation formula
 
Numerical method
Numerical methodNumerical method
Numerical method
 
Interpolation
InterpolationInterpolation
Interpolation
 
3.2.interpolation lagrange
3.2.interpolation lagrange3.2.interpolation lagrange
3.2.interpolation lagrange
 
numerical methods
numerical methodsnumerical methods
numerical methods
 
bresenham circles and polygons in computer graphics(Computer graphics tutorials)
bresenham circles and polygons in computer graphics(Computer graphics tutorials)bresenham circles and polygons in computer graphics(Computer graphics tutorials)
bresenham circles and polygons in computer graphics(Computer graphics tutorials)
 
Output primitives in Computer Graphics
Output primitives in Computer GraphicsOutput primitives in Computer Graphics
Output primitives in Computer Graphics
 
What is meaning of epsilon and delta in limits of a function by Arun Umrao
What is meaning of epsilon and delta in limits of a function by Arun UmraoWhat is meaning of epsilon and delta in limits of a function by Arun Umrao
What is meaning of epsilon and delta in limits of a function by Arun Umrao
 
Statistics Assignment Help
Statistics Assignment HelpStatistics Assignment Help
Statistics Assignment Help
 
Numerical method (curve fitting)
Numerical method (curve fitting)Numerical method (curve fitting)
Numerical method (curve fitting)
 
Numerical Integration: Trapezoidal Rule
Numerical Integration: Trapezoidal RuleNumerical Integration: Trapezoidal Rule
Numerical Integration: Trapezoidal Rule
 
Solving systems by substitution
Solving systems by substitutionSolving systems by substitution
Solving systems by substitution
 
Langrange Interpolation Polynomials
Langrange Interpolation PolynomialsLangrange Interpolation Polynomials
Langrange Interpolation Polynomials
 
L4 one sided limits limits at infinity
L4 one sided limits limits at infinityL4 one sided limits limits at infinity
L4 one sided limits limits at infinity
 
Bresenham's line drawing algorithm
Bresenham's line drawing algorithmBresenham's line drawing algorithm
Bresenham's line drawing algorithm
 
Numerical Analysis (Solution of Non-Linear Equations)
Numerical Analysis (Solution of Non-Linear Equations)Numerical Analysis (Solution of Non-Linear Equations)
Numerical Analysis (Solution of Non-Linear Equations)
 
The Application of Derivatives
The Application of DerivativesThe Application of Derivatives
The Application of Derivatives
 
Dda algo notes
Dda algo notesDda algo notes
Dda algo notes
 
L5 infinite limits squeeze theorem
L5 infinite limits squeeze theoremL5 infinite limits squeeze theorem
L5 infinite limits squeeze theorem
 

Similar to 3D Math Primer: CocoaConf Atlanta

Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programming
Damian T. Gordon
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
krishna_093
 

Similar to 3D Math Primer: CocoaConf Atlanta (20)

3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago
 
Lec3
Lec3Lec3
Lec3
 
Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1
 
Primitives
PrimitivesPrimitives
Primitives
 
Lr4 math cad
Lr4 math cadLr4 math cad
Lr4 math cad
 
raster algorithm.pdf
raster algorithm.pdfraster algorithm.pdf
raster algorithm.pdf
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programming
 
Linear Algebra Presentation including basic of linear Algebra
Linear Algebra Presentation including basic of linear AlgebraLinear Algebra Presentation including basic of linear Algebra
Linear Algebra Presentation including basic of linear Algebra
 
Mit6 094 iap10_lec03
Mit6 094 iap10_lec03Mit6 094 iap10_lec03
Mit6 094 iap10_lec03
 
Idea for ineractive programming language
Idea for ineractive programming languageIdea for ineractive programming language
Idea for ineractive programming language
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx4 CG_U1_M3_PPT_4 DDA.pptx
4 CG_U1_M3_PPT_4 DDA.pptx
 
bobok
bobokbobok
bobok
 
2. Fixed Point Iteration.pptx
2. Fixed Point Iteration.pptx2. Fixed Point Iteration.pptx
2. Fixed Point Iteration.pptx
 
Research Inventy : International Journal of Engineering and Science
Research Inventy : International Journal of Engineering and ScienceResearch Inventy : International Journal of Engineering and Science
Research Inventy : International Journal of Engineering and Science
 
MATLABgraphPlotting.pptx
MATLABgraphPlotting.pptxMATLABgraphPlotting.pptx
MATLABgraphPlotting.pptx
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Finite Element Method.ppt
Finite Element Method.pptFinite Element Method.ppt
Finite Element Method.ppt
 
Rational Functions
Rational FunctionsRational Functions
Rational Functions
 
Final exam mariluz 1
Final exam mariluz 1Final exam mariluz 1
Final exam mariluz 1
 

More from Janie Clayton (8)

Robots in Swift
Robots in SwiftRobots in Swift
Robots in Swift
 
Beyond White: Embracing the iOS Design Aesthetic
Beyond White: Embracing the iOS Design AestheticBeyond White: Embracing the iOS Design Aesthetic
Beyond White: Embracing the iOS Design Aesthetic
 
Thinking In Swift
Thinking In SwiftThinking In Swift
Thinking In Swift
 
GPU Programming: Chicago CocoaConf 2015
GPU Programming: Chicago CocoaConf 2015GPU Programming: Chicago CocoaConf 2015
GPU Programming: Chicago CocoaConf 2015
 
GPU Programming: CocoaConf Atlanta
GPU Programming: CocoaConf AtlantaGPU Programming: CocoaConf Atlanta
GPU Programming: CocoaConf Atlanta
 
GPU Programming 360iDev
GPU Programming 360iDevGPU Programming 360iDev
GPU Programming 360iDev
 
Bug Hunting Safari
Bug Hunting SafariBug Hunting Safari
Bug Hunting Safari
 
Gpu Programming With GPUImage and Metal
Gpu Programming With GPUImage and MetalGpu Programming With GPUImage and Metal
Gpu Programming With GPUImage and Metal
 

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 

3D Math Primer: CocoaConf Atlanta

  • 1. The Day You Finally Use Algebra! Janie Clayton
  • 3. But math is hard! (Let’s go shopping!)
  • 4. Math is hard. But math is fun too.
  • 10.
  • 11. 1 1
  • 16. - Colors, like the screen dimensions, are based on percentages rather than absolute values. - If you come from a graphic design background, you need to convert your 255 scale to percentages.
  • 18. Rosetta Stone - Had the same text in Greek, demotic, and hieroglyphics. Was used to translate hieroglyphics - Going to do similar thing, but with math algorithms, plain English, and code
  • 20. Algoritm Σ5 i = 1 4i
  • 21. Plain English I have a starting value of one. I have an end value of five. I want to multiply each value by four and add them together.
  • 22. var x = 0 for index in 1…5 { x += (4 * index) } Code
  • 23. √-1 2ˆ3 Σ π …and it was delicious!
  • 24. i 8 sum pi …and it was delicious!
  • 26. Triangles A shape with three sides where the angles add up to 180 degrees Everything in our world comes back to triangles The most stable shape Foundation of 3D graphics
  • 28. Pythagorean Theorem aˆ2 + bˆ2 = cˆ2
  • 29. Circle Formulas Circumference: 2πr Area: πrˆ2
  • 30. So What Can We Do Knowing This? Change the direction a character is moving in Check to see if the user is hitting a target area on the screen Draw shapes and filters in specific configurations
  • 32. “The survivors of linear algebra classes are physicists, graphics programmers and other masochists.” – BetterExplained.com
  • 33. What is Linear Algebra? Linear Algebra allows you to perform an action on many values at the same time. This action must be consistent across all values, such as multiplying every value by two.
  • 34. What is Linear Algebra? Values are placed in an object called a matrix and the actions performed on the values are called transforms Linear algebra is optimized for parallel mathematical operations.
  • 35. Vector Data Types vec2, vec3, vec4: 2D, 3D, and 4D floating point vector objects. vec2: (x, y) vec3: (x, y, z) vec4: (r, g, b, a)
  • 36. Vectors 9 3 3√10
  • 37. Demo
  • 39. Matrix Data Types mat2, mat3, mat4: 2, 3, and 4 element matrices. mat2: Holds a 2 X 2 number matrix mat3: Holds a 3 X 3 number matrix, used for 2D linear algebra mat4: Holds a 4 X 4 number matrix, used for 3D linear algebra
  • 40. Column 1.0 1.0 1.0 0 1.0 1.0 1.0 0 1.0 1.0 1.0 0 1.0 1.0 1.0 0 Row
  • 41. mat4 genericMatrix = mat4( 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0, 0, 0, 0 Column ); Row
  • 42. vec4 firstColumn = vec4(1.0, 1.0, 1.0, 1.0); vec4 secondColumn = vec4(1.0, 1.0, 1.0, 1.0); vec4 thirdColumn = vec4(1.0, 1.0, 1.0, 1.0); vec4 fouthColumn = vec4(0, 0, 0, 0); mat4 myMatrix = mat4( firstColumn, SecondColumn, thirdColumn, FourthColumn );
  • 44. Affine, Wha?? :( A transform is any function that alters the size, position, or rotation of an object on your screen. Four types: Identity, Translate, Rotation, and Scale. For a transform to be affine, the lines in your shape must be parallel.
  • 45.
  • 46. CGAffine Transform Methods CGAffineTransformMakeRotation (GLFloat angle); CGAffineTransformMakeScale (CGFLoat sx, CGFloat sy); CGAffineTransformMakeTranslation (CGFloat tx, CGFloat ty);
  • 47. struct CGAffineTransform { CGFloat a; GLFloat b; CGFloat c; CGFloat d; CGFloat tx; CGFloat ty }
  • 48. [x y 1] [a b 0 c d 0 tx ty 0] X = [x’ y’ 1]
  • 49. let pointX = a * x + c * y + tx let pointY = b * x + d * y + ty
  • 51. rotate 45 degrees Double Size
  • 53. void main() { highp vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); highp float distanceFromCenter = distance(center, textureCoordinateToUse); lowp float checkForPresenceWithinSphere = step(distanceFromCenter, radius); distanceFromCenter = distanceFromCenter / radius; highp float normalizedDepth = radius * sqrt(1.0 - distanceFromCenter * distanceFromCenter); highp vec3 sphereNormal = normalize(vec3(textureCoordinateToUse - center, normalizedDepth)); highp vec3 refractedVector = 2.0 * refract(vec3(0.0, 0.0, -1.0), sphereNormal, refractiveIndex); refractedVector.xy = -refractedVector.xy; highp vec3 finalSphereColor = texture2D(inputImageTexture, (refractedVector.xy + 1.0) * 0.5).rgb; // Grazing angle lighting highp float lightingIntensity = 2.5 * (1.0 - pow(clamp(dot(ambientLightPosition, sphereNormal), 0.0, 1.0), 0.25)); finalSphereColor += lightingIntensity; // Specular lighting lightingIntensity = clamp(dot(normalize(lightPosition), sphereNormal), 0.0, 1.0); lightingIntensity = pow(lightingIntensity, 15.0); finalSphereColor += vec3(0.8, 0.8, 0.8) * lightingIntensity; gl_FragColor = vec4(finalSphereColor, 1.0) * checkForPresenceWithinSphere; }
  • 54. highp vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio));
  • 55.
  • 56. highp float distanceFromCenter = distance(center, textureCoordinateToUse);
  • 57.
  • 58. lowp float checkForPresenceWithinSphere = step(distanceFromCenter, radius);
  • 59.
  • 61.
  • 62. highp float normalizedDepth = radius * sqrt(1.0 - distanceFromCenter * distanceFromCenter);
  • 63.
  • 64. highp vec3 sphereNormal = normalize(vec3 (textureCoordinateToUse - center, normalizedDepth));
  • 65.
  • 66. highp vec3 refractedVector = refract(vec3(0.0, 0.0, -1.0), sphereNormal, refractiveIndex);
  • 67.
  • 68. gl_FragColor = texture2D(inputImageTexture, (refractedVector.xy + 1.0) * 0.5) * checkForPresenceWithinSphere;
  • 69.
  • 70.
  • 71.
  • 72.