SlideShare une entreprise Scribd logo
1  sur  49
Télécharger pour lire hors ligne
Jean-Marc Le Roux
@promethe42
http://blogs.aerys.in/jeanmarc-leroux
Resources
 Sources
 https://github.com/aerys/minko
 Forum
 http://forum.minko.io
 Samples
 http://github.com/aerys/minko-examples
 Documentation
 http://doc.minko.io
@MINKO3D
Follow us on Twitter! 
http://soccerpun.ch
 Full 3D game built with Minko in just 48h!
 http://www.youtube.com/watch?v=Hv0cp4NwSoY
 Your smartphone is the gamepad: up to 8 players!
 All assets hanlded through the editor
 Imported from 3DS Max
 Editor available for free on http://minko.io
 Physics rigging in a few clicks
 Extensive use of particles
 Designed with the new particles editor
 Running with a new C++ particles engine
Last time…
… and now!
 What are shaders?
 Why is AGAL hard to work with and what
solutions does Minko provide?
 A few simple shader examples
 Hardware accelerated particles with shaders
 Particles engine and editor!
HDR Rendering
Dynamic lights
Static lights
Dynamic shadows
Static shadows
Diffuse texture
Noise
Diffuse texture
Hardware specific shader bytecode
Program3D
AGAL bytecode
Vertex Shader Fragment Shader
GLSL/HLSL
Program3D
PixelBender3D AGAL assembly
ActionScript3FlashHardware
Program3D – Vertex Shader
va1.x va1.y 0 0 …
x y z w …
v0 …
Varying
Registers
IndexBuffer3D
-5 -5 0 0 1 0 5 0 0 0.5 5 -5 0 1 1 …
x y z u v x y z u v x y z u v x
VertexBuffer3D
0 1 2
0 2 1 …
InputProgramOutput
0 (-5, -5, 0)
1 (0, 5, 0)
2 (5, -5, 0)
InputProgramOutput
Program3D – Fragment Shader
va1.x va1.y 0 0 …
x y z w …
v0 …
Varying
Registers
Texture3D
0 (0, 1) 2 (1, 1)
1 (0.5, 0)
Kids, this is the story of how I met your shader…
1992 2001 2004 2011
Mortal Kombat GTA III Doom 3 Crysis 2
1996
Evolution of shader languages
What about AGAL?
1992 2001 2004 2011
Mortal Kombat GTA III Doom 3 Crysis 2
1996
Language Features
In 1992, Flash was called FutureSplash Animator and written by a single man: Jonathan Gay
Simple scene use case
How many shaders?
Shadows
Lights
Animations
How many « possible shaders » ?
 Handle 0 to 8 joints
 With normals
 With tangents
 Handle 0 to 5 lights
 With bump-mapping or not
 Handle shadows
(9 x 3 x 6 x 2 x 2)²
= 419904 different shaders!
• To write
• To test
• To debug
• To maintain
• To distribute
• To adapt
• …
Shaders are
« static »
They
handle one
« scenario »
A lot of
shaders to
write…
 learning AGAL != learning GPU programming
 AGAL is awesome for 3D engines developers
 Low-level binary assembly code
 Cross-platform
 AGAL is a nightmare for 3D applications
developers
With Minko you can program the GPU
using ActionScript 3.0 !
Minko embedded JIT
Compiler
Shader ByteCode
ActionScript Shader
Code
public class MyShader
{
public function getVertexPosition() : SFloat
{
return localToScreen(vertexXYZ);
}
public function getPixelColor() : SFloat
{
return sampleTexture(
meshBindings.getTextureParameter(‘texture’),
interpolate(vertexUV)
);
}
}
m44 vt0, va0, vc0
m44 vt0, vt0, vc5
mov oc, vt0
mov v0, va1
tex ft0, v0 <linear,2d>
mov oc, ft0
at runtime compilation
ActionScript
Shader
•Use all ActionScript 3.0 features
•getOutputPosition => Vertex Shader
•getOutputColor => Fragment Shader
•OOP style
•CPU/GPU balancing
ASG
•Abstract Shader Graph
•Optimizations
•Constants and temporary registers
allocation
•Operations re-ordering for faster
execution and optimal use of temporary
registers
AGAL
•Direct bytecode generation at runtime
•Custom compiler
•Optional debug data
•AGAL assembly output
•Shader graph output
•Memory allocation map
Execution
 Full AS3 workflow
 Conditionnals and loops
 Classes and methods
 Dynamic OOP coding style
 Exhaustive AGAL implementation
 Extra high-level operations set
 Re-usable « shader parts »
 Shaders compiled at-runtime
 Just like any other AS3 code
 Dynamic according to
 The scene properties
 The mesh properties/material
 Any constant, variable, etc…
 Redistributable as SWF/SWC files
public class RedShader extends Shader
{
override protected function getVertexPosition() : Sfloat
{
return worldToScreen(localToWorld(vertexXYZ));
}
override protected function getPixelColor() : SFloat
{
return float4(1, 0, 0, 1);
}
}
RedShader – Step 1: AS3
RedShader – Step 2 : ASG
RedShader – Step 3 : AGAL
- vertex shader
m44 vt0.xyzw, va0.xyzw, vc0.xyzw
m44 vt0.xyzw, vt0.xyzw, vc4.xyzw
mov op.xyzw, vt0.xyzw
- fragment shader
mov oc.xyzw, fc0.xyzw
AS Shaders Workflow
Yes
shaderSignature(scene, mesh)
Does the
signature
already
exists ?
No
Set streams, textures and
constants:
• Vertex streams
• Vertex constants
• Fragment constants
• Textures
vsGraph = shader.getVertexPosition();
fsGraph = shader.getPixelColor();
Optimize ASG
Memory allocation
• Vertex attributes
• Vertex constants
• Fragment constants
• Resolving varying
Draw triangles
Shader Compilation
save(signature, compiledBytecode)
ACTIONSCRIPT IS NOW
THE MOST POWERFUL
SHADER LANGUAGE
ACTIONSCRIPT IS NOW
THE MOST POWERFUL
SHADER LANGUAGE
(as a language, but not GPU feature wise because of Stage3D limitations )
More about JIT shaders compilation…
 JIT shaders for better performance article on
my blog
EXAMPLES
Solid Red
override protected function getPixelColor() : SFloat
{
return float4(1, 0, 0, 1);
}
Solid Parametrized Color
override protected function getPixelColor() : SFloat
{
return meshBindings.getParameter(‘diffuseColor’, 4);
}
mesh.material.diffuseColor = Vector4(1., 0., 0., 1.);
Texture Mapping
override protected function getPixelColor() : SFloat
{
var texture : Sfloat = meshBindings.getTextureParameter(
‘diffuseMap’
);
return sampleTexture(texture, interpolate(vertexUV));
}
mesh.material.diffuseMap = TextureLoader.load(
new URLRequest(‘texture.jpg’)
);
interpolate()
Vertex Shader
Value
Fragment Shader
Value
interpolate()
interpolate()
Fragment Shader
Varying Registers
Vertex Shader
vertex0
x y r g b
Vertex Shader Output
Varying Registers
Vertex Shader
vertex1
x y r g b
Vertex Shader Output
Varying Registers
Vertex Shader
vertex2
x y r g b
Vertex Shader Output
Pixel Shader Output
Linear
Interpolation
color
x y z w
Linear
Interpolation
vertex0
vertex1vertex2
Particles
1. Fill vertex buffer with batched « quads »
2. (optional) Edit quads position on the CPU
 State-related animations
3. Render all the quads in a single draw call
 Stateless position/size/rotation animation in the
vertex shader
 Stateless color animation in the fragment shader
Particles – Quads?
quadVertex = {
particleId,
x, y, z,
offsetX, offsetY, offsetZ ,
rotation
}
0 1
23
(x, y, z)
(offsetX, offsetY, offsetZ)
rotation
quad = { 0, 1, 2, 3}
particleId ϵ * 0 … numParticles ]
Particles – Quads?
quadVertex = {
particleId,
x, y, z,
offsetX, offsetY, offsetZ ,
rotation
}
0 1
23
(x, y, z)
(offsetX, offsetY, offsetZ)
rotation
Fixed for the 4 vertex of a particule quad
Particles – Quads?
0
1
2
3
0 = {
0,
1., 4., 0.,
-0.5, 0.5, 0.,
1.4
}
1 = {
0,
1., 4., 0.,
0.5, 0.5, 0.,
1.4
}
2 = {
0,
1., 4., 0.,
0.5, -0.5, 0.,
1.4
}
3 = {
0,
1., 4., 0.,
-0.5, -0.5, 0.,
1.4
}
y
x
(1., 4., 0.)
Vertex shader logic
1. Transform quad center to view space
2. Add offset (~= corner position) to the view space
quad center
3. Apply rotation
4. Project on the screen
Particule Properties
 Each particle can have many properties!
 Start/end color
 Start/end velocity
 Start/end force
 …
 Particles design can be done with code…
 … but it is much more efficient with an editor!
Particle Editor
 Full WYSIWYG particles editor!
 http://www.youtube.com/watch?v=tyW2RUm2naI
 Stay tuned for the release (June)
 Follow @Minko3D
 Read http://minko.io
GLOBAL ILLUMINATION!
Next time…
MERCI !

Contenu connexe

Tendances

Deferred rendering case study
Deferred rendering case studyDeferred rendering case study
Deferred rendering case study
ozlael ozlael
 
บทที่ 2
บทที่ 2บทที่ 2
บทที่ 2
jibbie23
 
บทที่ 2
บทที่ 2บทที่ 2
บทที่ 2
jibbie23
 
บทที่ 2
บทที่ 2บทที่ 2
บทที่ 2
jibbie23
 
บทที่ 2
บทที่ 2บทที่ 2
บทที่ 2
jibbie23
 
Introduce coco2dx with cookingstar
Introduce coco2dx with cookingstarIntroduce coco2dx with cookingstar
Introduce coco2dx with cookingstar
ozlael ozlael
 

Tendances (14)

Deferred rendering case study
Deferred rendering case studyDeferred rendering case study
Deferred rendering case study
 
Unite 2013 optimizing unity games for mobile platforms
Unite 2013 optimizing unity games for mobile platformsUnite 2013 optimizing unity games for mobile platforms
Unite 2013 optimizing unity games for mobile platforms
 
บทที่ 2
บทที่ 2บทที่ 2
บทที่ 2
 
บทที่ 2
บทที่ 2บทที่ 2
บทที่ 2
 
บทที่ 2
บทที่ 2บทที่ 2
บทที่ 2
 
บทที่ 2
บทที่ 2บทที่ 2
บทที่ 2
 
Optimizing Games for Mobiles
Optimizing Games for MobilesOptimizing Games for Mobiles
Optimizing Games for Mobiles
 
유니티 그래픽 최적화, 어디까지 해봤니 (Optimizing Unity Graphics) NDC15 Ver.
유니티 그래픽 최적화, 어디까지 해봤니 (Optimizing Unity Graphics) NDC15 Ver.유니티 그래픽 최적화, 어디까지 해봤니 (Optimizing Unity Graphics) NDC15 Ver.
유니티 그래픽 최적화, 어디까지 해봤니 (Optimizing Unity Graphics) NDC15 Ver.
 
그래픽 최적화로 가...가버렷! (부제: 배치! 배칭을 보자!) , Batch! Let's take a look at Batching! -...
그래픽 최적화로 가...가버렷! (부제: 배치! 배칭을 보자!) , Batch! Let's take a look at Batching! -...그래픽 최적화로 가...가버렷! (부제: 배치! 배칭을 보자!) , Batch! Let's take a look at Batching! -...
그래픽 최적화로 가...가버렷! (부제: 배치! 배칭을 보자!) , Batch! Let's take a look at Batching! -...
 
Optimizing unity games (Google IO 2014)
Optimizing unity games (Google IO 2014)Optimizing unity games (Google IO 2014)
Optimizing unity games (Google IO 2014)
 
Frostbite on Mobile
Frostbite on MobileFrostbite on Mobile
Frostbite on Mobile
 
Introduce coco2dx with cookingstar
Introduce coco2dx with cookingstarIntroduce coco2dx with cookingstar
Introduce coco2dx with cookingstar
 
Multilayer Neuronal network hardware implementation
Multilayer Neuronal network hardware implementation Multilayer Neuronal network hardware implementation
Multilayer Neuronal network hardware implementation
 
Introduction to Stockfish bitboard representation and magic bitboard
Introduction to Stockfish bitboard representation and magic bitboardIntroduction to Stockfish bitboard representation and magic bitboard
Introduction to Stockfish bitboard representation and magic bitboard
 

En vedette

Minko stage3d 20130222
Minko stage3d 20130222Minko stage3d 20130222
Minko stage3d 20130222
Minko3D
 
Minko - Scripting 3D apps with Lua and C++
Minko - Scripting 3D apps with Lua and C++Minko - Scripting 3D apps with Lua and C++
Minko - Scripting 3D apps with Lua and C++
Minko3D
 
Minko - Flash Conference #5
Minko - Flash Conference #5Minko - Flash Conference #5
Minko - Flash Conference #5
Minko3D
 
Minko - Why we created our own Flash platform and why you should care
Minko - Why we created our own Flash platform and why you should careMinko - Why we created our own Flash platform and why you should care
Minko - Why we created our own Flash platform and why you should care
Minko3D
 
Minko - Targeting Flash/Stage3D with C++ and GLSL
Minko - Targeting Flash/Stage3D with C++ and GLSLMinko - Targeting Flash/Stage3D with C++ and GLSL
Minko - Targeting Flash/Stage3D with C++ and GLSL
Minko3D
 
Minko - Creating cross-platform 3D apps with Minko
Minko - Creating cross-platform 3D apps with MinkoMinko - Creating cross-platform 3D apps with Minko
Minko - Creating cross-platform 3D apps with Minko
Minko3D
 
WebGL games with Minko - Next Game Frontier 2014
WebGL games with Minko - Next Game Frontier 2014WebGL games with Minko - Next Game Frontier 2014
WebGL games with Minko - Next Game Frontier 2014
Minko3D
 
Minko - Windows App Meetup Nov. 2013
Minko - Windows App Meetup Nov. 2013Minko - Windows App Meetup Nov. 2013
Minko - Windows App Meetup Nov. 2013
Minko3D
 
Minko - Build WebGL applications with C++ and asm.js
Minko - Build WebGL applications with C++ and asm.jsMinko - Build WebGL applications with C++ and asm.js
Minko - Build WebGL applications with C++ and asm.js
Minko3D
 
Hutan rahmawaty12
Hutan rahmawaty12Hutan rahmawaty12
Hutan rahmawaty12
Debby Ochta
 
Hutan rahmawaty12
Hutan rahmawaty12Hutan rahmawaty12
Hutan rahmawaty12
Debby Ochta
 

En vedette (19)

Stage3D and AGAL
Stage3D and AGALStage3D and AGAL
Stage3D and AGAL
 
Paris Android User Group - Build 3D web, mobile and desktop applications with...
Paris Android User Group - Build 3D web, mobile and desktop applications with...Paris Android User Group - Build 3D web, mobile and desktop applications with...
Paris Android User Group - Build 3D web, mobile and desktop applications with...
 
Minko stage3d 20130222
Minko stage3d 20130222Minko stage3d 20130222
Minko stage3d 20130222
 
BIG DATA MANAGEMENT - forget the hype, let's talk about the facts!
BIG DATA MANAGEMENT - forget the hype, let's talk about the facts! BIG DATA MANAGEMENT - forget the hype, let's talk about the facts!
BIG DATA MANAGEMENT - forget the hype, let's talk about the facts!
 
Minko - Scripting 3D apps with Lua and C++
Minko - Scripting 3D apps with Lua and C++Minko - Scripting 3D apps with Lua and C++
Minko - Scripting 3D apps with Lua and C++
 
Minko - Flash Conference #5
Minko - Flash Conference #5Minko - Flash Conference #5
Minko - Flash Conference #5
 
Paris Android LiveCode - Creating cross-platform 3D apps with Minko
Paris Android LiveCode - Creating cross-platform 3D apps with MinkoParis Android LiveCode - Creating cross-platform 3D apps with Minko
Paris Android LiveCode - Creating cross-platform 3D apps with Minko
 
Minko - Why we created our own Flash platform and why you should care
Minko - Why we created our own Flash platform and why you should careMinko - Why we created our own Flash platform and why you should care
Minko - Why we created our own Flash platform and why you should care
 
Daotaonguonnhanluc
DaotaonguonnhanlucDaotaonguonnhanluc
Daotaonguonnhanluc
 
đề Ktra hóa
đề Ktra hóađề Ktra hóa
đề Ktra hóa
 
Minko - Targeting Flash/Stage3D with C++ and GLSL
Minko - Targeting Flash/Stage3D with C++ and GLSLMinko - Targeting Flash/Stage3D with C++ and GLSL
Minko - Targeting Flash/Stage3D with C++ and GLSL
 
Minko - Creating cross-platform 3D apps with Minko
Minko - Creating cross-platform 3D apps with MinkoMinko - Creating cross-platform 3D apps with Minko
Minko - Creating cross-platform 3D apps with Minko
 
WebGL games with Minko - Next Game Frontier 2014
WebGL games with Minko - Next Game Frontier 2014WebGL games with Minko - Next Game Frontier 2014
WebGL games with Minko - Next Game Frontier 2014
 
Minko - Windows App Meetup Nov. 2013
Minko - Windows App Meetup Nov. 2013Minko - Windows App Meetup Nov. 2013
Minko - Windows App Meetup Nov. 2013
 
Minko - Build WebGL applications with C++ and asm.js
Minko - Build WebGL applications with C++ and asm.jsMinko - Build WebGL applications with C++ and asm.js
Minko - Build WebGL applications with C++ and asm.js
 
React in Native Apps - Meetup React - 20150409
React in Native Apps - Meetup React - 20150409React in Native Apps - Meetup React - 20150409
React in Native Apps - Meetup React - 20150409
 
Hutan rahmawaty12
Hutan rahmawaty12Hutan rahmawaty12
Hutan rahmawaty12
 
Hutan rahmawaty12
Hutan rahmawaty12Hutan rahmawaty12
Hutan rahmawaty12
 
D010202
D010202D010202
D010202
 

Similaire à Minko stage3d workshop_20130525

Midterm revision 2022 without answer.pdf
Midterm revision 2022  without answer.pdfMidterm revision 2022  without answer.pdf
Midterm revision 2022 without answer.pdf
AhmedSalah48055
 

Similaire à Minko stage3d workshop_20130525 (20)

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
 
Implementing a modern, RenderMan compliant, REYES renderer
Implementing a modern, RenderMan compliant, REYES rendererImplementing a modern, RenderMan compliant, REYES renderer
Implementing a modern, RenderMan compliant, REYES renderer
 
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
 
The Technology behind Shadow Warrior, ZTG 2014
The Technology behind Shadow Warrior, ZTG 2014The Technology behind Shadow Warrior, ZTG 2014
The Technology behind Shadow Warrior, ZTG 2014
 
Computer Graphics Part1
Computer Graphics Part1Computer Graphics Part1
Computer Graphics Part1
 
Rendering Techniques in Rise of the Tomb Raider
Rendering Techniques in Rise of the Tomb RaiderRendering Techniques in Rise of the Tomb Raider
Rendering Techniques in Rise of the Tomb Raider
 
iOS Visual F/X Using GLSL
iOS Visual F/X Using GLSLiOS Visual F/X Using GLSL
iOS Visual F/X Using GLSL
 
Advanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics APIAdvanced Game Development with the Mobile 3D Graphics API
Advanced Game Development with the Mobile 3D Graphics API
 
Introduce to 3d rendering engine
Introduce to 3d rendering engineIntroduce to 3d rendering engine
Introduce to 3d rendering engine
 
XRobots
XRobotsXRobots
XRobots
 
Cg shaders with Unity3D
Cg shaders with Unity3DCg shaders with Unity3D
Cg shaders with Unity3D
 
Android RenderScript on LLVM
Android RenderScript on LLVMAndroid RenderScript on LLVM
Android RenderScript on LLVM
 
DirectX 11 Rendering in Battlefield 3
DirectX 11 Rendering in Battlefield 3DirectX 11 Rendering in Battlefield 3
DirectX 11 Rendering in Battlefield 3
 
NvFX GTC 2013
NvFX GTC 2013NvFX GTC 2013
NvFX GTC 2013
 
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeksBeginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
 
Secrets of CryENGINE 3 Graphics Technology
Secrets of CryENGINE 3 Graphics TechnologySecrets of CryENGINE 3 Graphics Technology
Secrets of CryENGINE 3 Graphics Technology
 
Parallel Graphics in Frostbite - Current & Future (Siggraph 2009)
Parallel Graphics in Frostbite - Current & Future (Siggraph 2009)Parallel Graphics in Frostbite - Current & Future (Siggraph 2009)
Parallel Graphics in Frostbite - Current & Future (Siggraph 2009)
 
Creating Custom Charts With Ruby Vector Graphics
Creating Custom Charts With Ruby Vector GraphicsCreating Custom Charts With Ruby Vector Graphics
Creating Custom Charts With Ruby Vector Graphics
 
Midterm revision 2022 without answer.pdf
Midterm revision 2022  without answer.pdfMidterm revision 2022  without answer.pdf
Midterm revision 2022 without answer.pdf
 
Moving NEON to 64 bits
Moving NEON to 64 bitsMoving NEON to 64 bits
Moving NEON to 64 bits
 

Minko stage3d workshop_20130525

  • 2. Resources  Sources  https://github.com/aerys/minko  Forum  http://forum.minko.io  Samples  http://github.com/aerys/minko-examples  Documentation  http://doc.minko.io
  • 3. @MINKO3D Follow us on Twitter! 
  • 4. http://soccerpun.ch  Full 3D game built with Minko in just 48h!  http://www.youtube.com/watch?v=Hv0cp4NwSoY  Your smartphone is the gamepad: up to 8 players!  All assets hanlded through the editor  Imported from 3DS Max  Editor available for free on http://minko.io  Physics rigging in a few clicks  Extensive use of particles  Designed with the new particles editor  Running with a new C++ particles engine
  • 5.
  • 7. … and now!  What are shaders?  Why is AGAL hard to work with and what solutions does Minko provide?  A few simple shader examples  Hardware accelerated particles with shaders  Particles engine and editor!
  • 8. HDR Rendering Dynamic lights Static lights Dynamic shadows Static shadows Diffuse texture Noise Diffuse texture
  • 9. Hardware specific shader bytecode Program3D AGAL bytecode Vertex Shader Fragment Shader GLSL/HLSL Program3D PixelBender3D AGAL assembly ActionScript3FlashHardware
  • 10.
  • 11.
  • 12. Program3D – Vertex Shader va1.x va1.y 0 0 … x y z w … v0 … Varying Registers IndexBuffer3D -5 -5 0 0 1 0 5 0 0 0.5 5 -5 0 1 1 … x y z u v x y z u v x y z u v x VertexBuffer3D 0 1 2 0 2 1 … InputProgramOutput 0 (-5, -5, 0) 1 (0, 5, 0) 2 (5, -5, 0)
  • 13. InputProgramOutput Program3D – Fragment Shader va1.x va1.y 0 0 … x y z w … v0 … Varying Registers Texture3D 0 (0, 1) 2 (1, 1) 1 (0.5, 0)
  • 14. Kids, this is the story of how I met your shader…
  • 15. 1992 2001 2004 2011 Mortal Kombat GTA III Doom 3 Crysis 2 1996 Evolution of shader languages
  • 16. What about AGAL? 1992 2001 2004 2011 Mortal Kombat GTA III Doom 3 Crysis 2 1996 Language Features
  • 17. In 1992, Flash was called FutureSplash Animator and written by a single man: Jonathan Gay
  • 18. Simple scene use case How many shaders? Shadows Lights Animations
  • 19. How many « possible shaders » ?  Handle 0 to 8 joints  With normals  With tangents  Handle 0 to 5 lights  With bump-mapping or not  Handle shadows (9 x 3 x 6 x 2 x 2)² = 419904 different shaders! • To write • To test • To debug • To maintain • To distribute • To adapt • …
  • 20. Shaders are « static » They handle one « scenario » A lot of shaders to write…
  • 21.  learning AGAL != learning GPU programming  AGAL is awesome for 3D engines developers  Low-level binary assembly code  Cross-platform  AGAL is a nightmare for 3D applications developers
  • 22. With Minko you can program the GPU using ActionScript 3.0 !
  • 23.
  • 24. Minko embedded JIT Compiler Shader ByteCode ActionScript Shader Code public class MyShader { public function getVertexPosition() : SFloat { return localToScreen(vertexXYZ); } public function getPixelColor() : SFloat { return sampleTexture( meshBindings.getTextureParameter(‘texture’), interpolate(vertexUV) ); } } m44 vt0, va0, vc0 m44 vt0, vt0, vc5 mov oc, vt0 mov v0, va1 tex ft0, v0 <linear,2d> mov oc, ft0 at runtime compilation
  • 25. ActionScript Shader •Use all ActionScript 3.0 features •getOutputPosition => Vertex Shader •getOutputColor => Fragment Shader •OOP style •CPU/GPU balancing ASG •Abstract Shader Graph •Optimizations •Constants and temporary registers allocation •Operations re-ordering for faster execution and optimal use of temporary registers AGAL •Direct bytecode generation at runtime •Custom compiler •Optional debug data •AGAL assembly output •Shader graph output •Memory allocation map Execution  Full AS3 workflow  Conditionnals and loops  Classes and methods  Dynamic OOP coding style  Exhaustive AGAL implementation  Extra high-level operations set  Re-usable « shader parts »  Shaders compiled at-runtime  Just like any other AS3 code  Dynamic according to  The scene properties  The mesh properties/material  Any constant, variable, etc…  Redistributable as SWF/SWC files
  • 26. public class RedShader extends Shader { override protected function getVertexPosition() : Sfloat { return worldToScreen(localToWorld(vertexXYZ)); } override protected function getPixelColor() : SFloat { return float4(1, 0, 0, 1); } } RedShader – Step 1: AS3
  • 28. RedShader – Step 3 : AGAL - vertex shader m44 vt0.xyzw, va0.xyzw, vc0.xyzw m44 vt0.xyzw, vt0.xyzw, vc4.xyzw mov op.xyzw, vt0.xyzw - fragment shader mov oc.xyzw, fc0.xyzw
  • 29. AS Shaders Workflow Yes shaderSignature(scene, mesh) Does the signature already exists ? No Set streams, textures and constants: • Vertex streams • Vertex constants • Fragment constants • Textures vsGraph = shader.getVertexPosition(); fsGraph = shader.getPixelColor(); Optimize ASG Memory allocation • Vertex attributes • Vertex constants • Fragment constants • Resolving varying Draw triangles Shader Compilation save(signature, compiledBytecode)
  • 30. ACTIONSCRIPT IS NOW THE MOST POWERFUL SHADER LANGUAGE
  • 31. ACTIONSCRIPT IS NOW THE MOST POWERFUL SHADER LANGUAGE (as a language, but not GPU feature wise because of Stage3D limitations )
  • 32. More about JIT shaders compilation…  JIT shaders for better performance article on my blog
  • 33.
  • 35. Solid Red override protected function getPixelColor() : SFloat { return float4(1, 0, 0, 1); }
  • 36. Solid Parametrized Color override protected function getPixelColor() : SFloat { return meshBindings.getParameter(‘diffuseColor’, 4); } mesh.material.diffuseColor = Vector4(1., 0., 0., 1.);
  • 37. Texture Mapping override protected function getPixelColor() : SFloat { var texture : Sfloat = meshBindings.getTextureParameter( ‘diffuseMap’ ); return sampleTexture(texture, interpolate(vertexUV)); } mesh.material.diffuseMap = TextureLoader.load( new URLRequest(‘texture.jpg’) );
  • 39. interpolate() Fragment Shader Varying Registers Vertex Shader vertex0 x y r g b Vertex Shader Output Varying Registers Vertex Shader vertex1 x y r g b Vertex Shader Output Varying Registers Vertex Shader vertex2 x y r g b Vertex Shader Output Pixel Shader Output Linear Interpolation color x y z w Linear Interpolation vertex0 vertex1vertex2
  • 40. Particles 1. Fill vertex buffer with batched « quads » 2. (optional) Edit quads position on the CPU  State-related animations 3. Render all the quads in a single draw call  Stateless position/size/rotation animation in the vertex shader  Stateless color animation in the fragment shader
  • 41. Particles – Quads? quadVertex = { particleId, x, y, z, offsetX, offsetY, offsetZ , rotation } 0 1 23 (x, y, z) (offsetX, offsetY, offsetZ) rotation quad = { 0, 1, 2, 3} particleId ϵ * 0 … numParticles ]
  • 42. Particles – Quads? quadVertex = { particleId, x, y, z, offsetX, offsetY, offsetZ , rotation } 0 1 23 (x, y, z) (offsetX, offsetY, offsetZ) rotation Fixed for the 4 vertex of a particule quad
  • 43. Particles – Quads? 0 1 2 3 0 = { 0, 1., 4., 0., -0.5, 0.5, 0., 1.4 } 1 = { 0, 1., 4., 0., 0.5, 0.5, 0., 1.4 } 2 = { 0, 1., 4., 0., 0.5, -0.5, 0., 1.4 } 3 = { 0, 1., 4., 0., -0.5, -0.5, 0., 1.4 } y x (1., 4., 0.)
  • 44. Vertex shader logic 1. Transform quad center to view space 2. Add offset (~= corner position) to the view space quad center 3. Apply rotation 4. Project on the screen
  • 45. Particule Properties  Each particle can have many properties!  Start/end color  Start/end velocity  Start/end force  …  Particles design can be done with code…  … but it is much more efficient with an editor!
  • 46. Particle Editor  Full WYSIWYG particles editor!  http://www.youtube.com/watch?v=tyW2RUm2naI  Stay tuned for the release (June)  Follow @Minko3D  Read http://minko.io
  • 47.