SlideShare a Scribd company logo
Using Shader in cocos2d-x
Dong Xuan Thuy, Fuji Technology
2017/03/09
About myself
- Đồng Xuân Thủy (Nick), 1992
- Game/Full-stack Developer (FujiTech)
- TechLead (WeenGame Studio)
https://github.com/thuydx55
nick@weengame.com
thuy.dong@fujitechjsc.com
Cocos2d family
Wiki: https://en.wikipedia.org/wiki/Cocos2d
Cocos2d (Python)
Cocos2d-ObjC (ObjC)
Cocos2d-x (C++, Javascript, Lua)
Cocos2d-html5 (deprecated) (Javascript)
Cocos2d-XNA (C#)
Rendering Pipeline
Position: Identifies it in a 3D space (x, y, z).
Color: Holds an RGBA value (R, G and B for the red,
green, and blue channels, alpha for transparency
— all values range from 0.0 to 1.0).
Normal: A way to describe the direction the vertex is
facing.
Texture: A 2D image that the vertex can use to
decorate the surface it is part of instead of a simple
color.
Rendering Pipeline
Ref: https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_on_the_web/Basic_theory
Rendering Pipeline
Vertex processing
Rendering Pipeline
Rasterization
Rendering Pipeline
Fragment processing
What is shader?
Micro-program
Executed for each “vertex” or each “pixel”
Run on GPU
Languages
GLSL (OpenGL)
HLSL (DirectX)
2 kinds of shader: Vertex & Fragment
Example (What I’ve done)
TSOG (The School Of Games)
Lines98
TSOG (The School Of Games)
- http://www.theschoolofgames.org/
- Source Code: https://github.com/theschoolofgames/tsog-mainapp/
- Open Source Project
- Education
TSOG
Problem
200 objects difference images
Create animations
Create shade images
Create outline images
TSOG
TSOG
TSOG
Edge Detection
Lines98
- http://lines98.net/
- Board Game
Lines98
- OpenCV?
Lines98
Clipping Node - Aliasing
Lines98
R
G
B
A
Lines98
Lines98
Barrel Distort
Lines98
Lines98
QA
Example of shader in cocos2d-x
Old way to create effect like that
60 FPS
189 Frames / 30.6MB
Memory: 129.8 MB
30 FPS
95 Frames / 15.4MB
Memory: 65.2 MB
Old way to create effect like that
15 FPS
47 Frames / 7.6MB
Memory: 32.3 MB
10 FPS
31 Frames / 5MB
Memory: 21.3 MB
60 FPS
60 FPS 30 FPS
15 FPS 10 FPS
Using Shader: Better
Only one image
Implement shader and apply to that image
Comparison
Memory
FPS

More Related Content

What's hot

What's hot (20)

Killer Design Patterns for F2P Mobile/Tablet Games
Killer Design Patterns for F2P Mobile/Tablet GamesKiller Design Patterns for F2P Mobile/Tablet Games
Killer Design Patterns for F2P Mobile/Tablet Games
 
The birth of jrpg and its own revolution
The birth of jrpg and its own revolutionThe birth of jrpg and its own revolution
The birth of jrpg and its own revolution
 
2-Game Design (Game Design and Development)
2-Game Design (Game Design and Development)2-Game Design (Game Design and Development)
2-Game Design (Game Design and Development)
 
HCIから見た漫画
HCIから見た漫画HCIから見た漫画
HCIから見た漫画
 
Process of Game Design
Process of Game DesignProcess of Game Design
Process of Game Design
 
Game development pipeline
Game development pipelineGame development pipeline
Game development pipeline
 
LAFS Game Design 1 - Dramatic Elements
LAFS Game Design 1 - Dramatic ElementsLAFS Game Design 1 - Dramatic Elements
LAFS Game Design 1 - Dramatic Elements
 
Gaming & Storytelling in the 21st Century
Gaming & Storytelling in the 21st CenturyGaming & Storytelling in the 21st Century
Gaming & Storytelling in the 21st Century
 
The Latest Trends in Hyper-Casual Games - GameAnalytics
The Latest Trends in Hyper-Casual Games - GameAnalyticsThe Latest Trends in Hyper-Casual Games - GameAnalytics
The Latest Trends in Hyper-Casual Games - GameAnalytics
 
Idle Games: The Mechanics and Monetization of Self-Playing Games
Idle Games: The Mechanics and Monetization of Self-Playing GamesIdle Games: The Mechanics and Monetization of Self-Playing Games
Idle Games: The Mechanics and Monetization of Self-Playing Games
 
Game Design Process
Game Design ProcessGame Design Process
Game Design Process
 
Lecture 15 Game Analytics in the Age of Big Data
Lecture 15 Game Analytics in the Age of Big DataLecture 15 Game Analytics in the Age of Big Data
Lecture 15 Game Analytics in the Age of Big Data
 
Game Design fundamentals
Game Design fundamentalsGame Design fundamentals
Game Design fundamentals
 
Game Design as Career
Game Design as CareerGame Design as Career
Game Design as Career
 
Hyper-casual in a Hypercompetitive Market - Voodoo
Hyper-casual in a Hypercompetitive Market - VoodooHyper-casual in a Hypercompetitive Market - Voodoo
Hyper-casual in a Hypercompetitive Market - Voodoo
 
GDC 2019 : Deconstructor of Fun Breaking Down Top Mobile Titles
GDC 2019 : Deconstructor of Fun Breaking Down Top Mobile TitlesGDC 2019 : Deconstructor of Fun Breaking Down Top Mobile Titles
GDC 2019 : Deconstructor of Fun Breaking Down Top Mobile Titles
 
[IGC 2017] 라이엇게임즈 유석문 - 게임 개발의 Agile Best Practices
[IGC 2017] 라이엇게임즈 유석문 - 게임 개발의 Agile Best Practices[IGC 2017] 라이엇게임즈 유석문 - 게임 개발의 Agile Best Practices
[IGC 2017] 라이엇게임즈 유석문 - 게임 개발의 Agile Best Practices
 
Game Design Fundamentals: The Formal Elements
Game Design Fundamentals: The  Formal ElementsGame Design Fundamentals: The  Formal Elements
Game Design Fundamentals: The Formal Elements
 
Idle Clicker Games Presentation (Casual Connect USA 2017)
Idle Clicker Games Presentation (Casual Connect USA 2017)Idle Clicker Games Presentation (Casual Connect USA 2017)
Idle Clicker Games Presentation (Casual Connect USA 2017)
 
ההיסטוריה המשוגעת של משחקי המחשב
ההיסטוריה המשוגעת של משחקי המחשבההיסטוריה המשוגעת של משחקי המחשב
ההיסטוריה המשוגעת של משחקי המחשב
 

Similar to Using Shader in cocos2d-x

Shaders in Unity by Zoel
Shaders in Unity by ZoelShaders in Unity by Zoel
Shaders in Unity by Zoel
Agate Studio
 
OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...
OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...
OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...
ogdc
 
OGDC 2014: Program farmery by cocos2dx
OGDC 2014: Program farmery by cocos2dxOGDC 2014: Program farmery by cocos2dx
OGDC 2014: Program farmery by cocos2dx
GameLandVN
 

Similar to Using Shader in cocos2d-x (15)

Build a Game in 60 minutes
Build a Game in 60 minutesBuild a Game in 60 minutes
Build a Game in 60 minutes
 
Shaders and the black magic
Shaders and the black magicShaders and the black magic
Shaders and the black magic
 
Geohex v2 at GMS_nagoya
Geohex v2 at GMS_nagoyaGeohex v2 at GMS_nagoya
Geohex v2 at GMS_nagoya
 
Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5
 
Shaders in Unity by Zoel
Shaders in Unity by ZoelShaders in Unity by Zoel
Shaders in Unity by Zoel
 
OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...
OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...
OGDC 2014_Hands on experience with Cocos2dx in cross-platform with Farmery_Mr...
 
OGDC 2014: Program farmery by cocos2dx
OGDC 2014: Program farmery by cocos2dxOGDC 2014: Program farmery by cocos2dx
OGDC 2014: Program farmery by cocos2dx
 
Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8
 
Introduction to Digital Image Processing
Introduction to Digital Image ProcessingIntroduction to Digital Image Processing
Introduction to Digital Image Processing
 
Games 3 dl4-example
Games 3 dl4-exampleGames 3 dl4-example
Games 3 dl4-example
 
Geohex at Off4g2009
Geohex at Off4g2009Geohex at Off4g2009
Geohex at Off4g2009
 
Unity advanced computer graphics week 02
Unity advanced computer graphics week 02Unity advanced computer graphics week 02
Unity advanced computer graphics week 02
 
Build an original 3D model in either SketchUp or Blender.Project m.docx
Build an original 3D model in either SketchUp or Blender.Project m.docxBuild an original 3D model in either SketchUp or Blender.Project m.docx
Build an original 3D model in either SketchUp or Blender.Project m.docx
 
DirectX 11 Rendering in Battlefield 3
DirectX 11 Rendering in Battlefield 3DirectX 11 Rendering in Battlefield 3
DirectX 11 Rendering in Battlefield 3
 
CS 354 Texture Mapping
CS 354 Texture MappingCS 354 Texture Mapping
CS 354 Texture Mapping
 

More from Vu Hung Nguyen

Basic & Advanced Scrum Framework
Basic & Advanced Scrum FrameworkBasic & Advanced Scrum Framework
Basic & Advanced Scrum Framework
Vu Hung Nguyen
 
Anti patterns in it project management
Anti patterns in it project managementAnti patterns in it project management
Anti patterns in it project management
Vu Hung Nguyen
 

More from Vu Hung Nguyen (20)

Co ban horenso - Tai lieu training noi bo
Co ban horenso - Tai lieu training noi boCo ban horenso - Tai lieu training noi bo
Co ban horenso - Tai lieu training noi bo
 
Funix techtalk: Tự học hiệu quả thời 4.0
Funix techtalk: Tự học hiệu quả thời 4.0Funix techtalk: Tự học hiệu quả thời 4.0
Funix techtalk: Tự học hiệu quả thời 4.0
 
Học cờ cùng con - Nguyễn Vỹ Kỳ Anh [U8]
Học cờ cùng con - Nguyễn Vỹ Kỳ Anh [U8]Học cờ cùng con - Nguyễn Vỹ Kỳ Anh [U8]
Học cờ cùng con - Nguyễn Vỹ Kỳ Anh [U8]
 
Japanese for it bridge engineers
Japanese for it bridge engineersJapanese for it bridge engineers
Japanese for it bridge engineers
 
Basic IT Project Management Terminologies
Basic IT Project Management TerminologiesBasic IT Project Management Terminologies
Basic IT Project Management Terminologies
 
2018 Học cờ cùng con - Nguyễn Vũ Kỳ Anh [U7]
2018 Học cờ cùng con - Nguyễn Vũ Kỳ Anh [U7]2018 Học cờ cùng con - Nguyễn Vũ Kỳ Anh [U7]
2018 Học cờ cùng con - Nguyễn Vũ Kỳ Anh [U7]
 
Làm việc hiệu quả với sếp Nhật (2017)
Làm việc hiệu quả với sếp Nhật (2017)Làm việc hiệu quả với sếp Nhật (2017)
Làm việc hiệu quả với sếp Nhật (2017)
 
Problem Solving Skills (for IT Engineers)
Problem Solving Skills (for IT Engineers)Problem Solving Skills (for IT Engineers)
Problem Solving Skills (for IT Engineers)
 
Pham Anh Tu - TK Framework
Pham Anh Tu - TK FrameworkPham Anh Tu - TK Framework
Pham Anh Tu - TK Framework
 
My idol: Magnus Carlsen vs. Ky Anh 2G1 NGS Newton
My idol: Magnus Carlsen vs. Ky Anh 2G1 NGS NewtonMy idol: Magnus Carlsen vs. Ky Anh 2G1 NGS Newton
My idol: Magnus Carlsen vs. Ky Anh 2G1 NGS Newton
 
Basic advanced scrum framework
Basic advanced scrum frameworkBasic advanced scrum framework
Basic advanced scrum framework
 
FPT Univ. Talkshow IT khong chi la lap trinh
FPT Univ. Talkshow IT khong chi la lap trinhFPT Univ. Talkshow IT khong chi la lap trinh
FPT Univ. Talkshow IT khong chi la lap trinh
 
Basic & Advanced Scrum Framework
Basic & Advanced Scrum FrameworkBasic & Advanced Scrum Framework
Basic & Advanced Scrum Framework
 
Agile Vietnam Conference 2016: Recap
Agile Vietnam Conference 2016: RecapAgile Vietnam Conference 2016: Recap
Agile Vietnam Conference 2016: Recap
 
IT Public Speaking Guidelines
IT Public Speaking GuidelinesIT Public Speaking Guidelines
IT Public Speaking Guidelines
 
Kanban: Cơ bản và Nâng cao
Kanban: Cơ bản và Nâng caoKanban: Cơ bản và Nâng cao
Kanban: Cơ bản và Nâng cao
 
Học cờ vua cùng con Nguyễn Vũ Kỳ Anh (U6)
Học cờ vua cùng con Nguyễn Vũ Kỳ Anh (U6)Học cờ vua cùng con Nguyễn Vũ Kỳ Anh (U6)
Học cờ vua cùng con Nguyễn Vũ Kỳ Anh (U6)
 
Fuji Technology Workshop: Learning Skills
Fuji Technology Workshop: Learning SkillsFuji Technology Workshop: Learning Skills
Fuji Technology Workshop: Learning Skills
 
Anti patterns in it project management
Anti patterns in it project managementAnti patterns in it project management
Anti patterns in it project management
 
Mindmap and Plan Planning
Mindmap and Plan PlanningMindmap and Plan Planning
Mindmap and Plan Planning
 

Recently uploaded

Recently uploaded (20)

How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
The Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryThe Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. Henry
 
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.pptBasic_QTL_Marker-assisted_Selection_Sourabh.ppt
Basic_QTL_Marker-assisted_Selection_Sourabh.ppt
 
Keeping Your Information Safe with Centralized Security Services
Keeping Your Information Safe with Centralized Security ServicesKeeping Your Information Safe with Centralized Security Services
Keeping Your Information Safe with Centralized Security Services
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
 
Application of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matricesApplication of Matrices in real life. Presentation on application of matrices
Application of Matrices in real life. Presentation on application of matrices
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceutics
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
 

Using Shader in cocos2d-x

Editor's Notes

  1. Vertex processing is about combining the information about individual vertices into primitives and setting their coordinates in the 3D space for the viewer to see. It's like taking a photo of the given scenery you have prepared — you have to place the objects first, configure the camera, and then take the shot.
  2. Rasterization converts primitives (which are connected vertices) to a set of fragments. Those fragments — which are 3D projections of the 2D pixels — are aligned to the pixel grid, so eventually they can be printed out as pixels on a 2D screen display during the output merging stage.
  3. Fragment processing focuses on textures and lighting — it calculates final colors based on the given parameters.
  4. Of course! These days, even the cheapest GPU will bring you at least 300 or so cores (with monster cards having over 3000 of them), and performing the same thing across all the cores, is what GPUs are really good with. Those 30M shader runs per second, when distributed across 300 GPU cores running @ 1GHz each, will mean that we have 10000 GPU clocks to run our shader. And while GPU cores are weaker than CPU ones7 for generic calculations, they have hardware support for those things which matter for graphics and shaders. Just as one example, GPUs tend to have sin/cos operations8 at mere 8x of the cost of integer addition operation, while for CPU the ratio is more like 50-200x Fragment: returns the color of the pixel. Vertex: what vertices we’re speaking about?