SlideShare uma empresa Scribd logo
1 de 15
Pixel shaders: programming the GPU By: Venkata Nanda Kishore
What is a Shader? Set of Software Instructions Degree of Flexibility Traits of an entity
Entities,Traits And Degree ,[object Object],	Pixels 	Vertices 	Geometric shapes ,[object Object],	Pixels: z-buffer, alpha values etc. Vertices: Texture co-ordinates, Color
Types of Shaders Initially, Shaders are just pixel shaders Types of Shaders: ,[object Object]
Vertex Shaders
Geometric ShadersBut the name remained as it was!
Effect of Shaders Replaced hard coded effects Gives a programmable alternative Fixed Function PipelineProgrammable Function Pipeline 3.Parallel Programming
Programming Shaders HLSL (Direct 3d) GLSL (OpenGl) Cg(Nvidia + Microsoft)
Cg What is Cg? Is it similar to C? Is it the right question? Can we use it as a general programming language?
Background of Cg Use of Assembly level language What is assembly level? What is high level,low level and middle level? How easy is it?
Example of assembly level language fib: movedx, [esp+8] cmpedx, 0 ja @f  moveax, 0  ret @@:  cmpedx, 2 ja @f moveax, 1 ret  @@:  push ebx movebx, 1 movecx, 1  @@: lea eax, [ebx+ecx]  cmpedx, 3 jbe @f movebx, ecx movecx, eax decedx jmp@b @@:  pop ebx  ret
Advantage of Cg Portable Easy Optimize the code
Syntax and Semantics(1) Data Types: int, float, half, fixed, bool, sampler* Operators: Arithmetic and logical operators as in C Additional: arithmetic operations for vector and matrix operrations
Syntax and Semantics(2) Functions and Control Structures: Similar to C Standard Cg Library: Specialised GPU programming tasks Eg. Texture Mapping functions tex1D and tex2D Cg Runtime Library:Can be used with OpenGl or DirectX
Example Shader // input vertexstructVertIn { float4 pos : POSITION;  float4 color : COLOR0; }; // output vertexstructVertOut { float4 pos : POSITION; float4 color : COLOR0; };  // vertex shader main entry VertOutmain(VertIn IN, uniform float4x4 modelViewProj)  { VertOut OUT;  OUT.pos= mul(modelViewProj, IN.pos); // calculate output coords OUT.color = IN.color; // copy input color to output OUT.color.z= 1.0f; // blue component of color = 1.0f return OUT; }

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

GCC compiler
GCC compilerGCC compiler
GCC compiler
 
Comparing PGQL, G-Core and Cypher
Comparing PGQL, G-Core and CypherComparing PGQL, G-Core and Cypher
Comparing PGQL, G-Core and Cypher
 
History of c++
History of c++ History of c++
History of c++
 
Lo18
Lo18Lo18
Lo18
 
Lecture1
Lecture1Lecture1
Lecture1
 
doug
dougdoug
doug
 
Introduction to c programming language
Introduction to c programming languageIntroduction to c programming language
Introduction to c programming language
 
Direct Acyclic Graph (DAG)
Direct Acyclic Graph (DAG)Direct Acyclic Graph (DAG)
Direct Acyclic Graph (DAG)
 
Touchless writer
Touchless writerTouchless writer
Touchless writer
 
N20181217
N20181217N20181217
N20181217
 
Intro of C
Intro of CIntro of C
Intro of C
 
History of C/C++ Language
History of C/C++ LanguageHistory of C/C++ Language
History of C/C++ Language
 
Tricks
TricksTricks
Tricks
 
Web
WebWeb
Web
 
built in function
built in functionbuilt in function
built in function
 
License Plate Recognition System
License Plate Recognition System License Plate Recognition System
License Plate Recognition System
 
Soalan chapter 5
Soalan chapter 5Soalan chapter 5
Soalan chapter 5
 
Internet Technologies (December - 2018) [IDOL - Old Course]
Internet Technologies (December - 2018) [IDOL - Old Course]Internet Technologies (December - 2018) [IDOL - Old Course]
Internet Technologies (December - 2018) [IDOL - Old Course]
 
Haxe vs Unicode (en)
Haxe vs Unicode (en)Haxe vs Unicode (en)
Haxe vs Unicode (en)
 
Assignment 4
Assignment 4Assignment 4
Assignment 4
 

Destaque

02 direct3 d_pipeline
02 direct3 d_pipeline02 direct3 d_pipeline
02 direct3 d_pipelineGirish Ghate
 
Why Graphics Is Fast, and What It Can Teach Us About Parallel Programming
Why Graphics Is Fast, and What It Can Teach Us About Parallel ProgrammingWhy Graphics Is Fast, and What It Can Teach Us About Parallel Programming
Why Graphics Is Fast, and What It Can Teach Us About Parallel ProgrammingJonathan Ragan-Kelley
 
SIGGRAPH 2012: NVIDIA OpenGL for 2012
SIGGRAPH 2012: NVIDIA OpenGL for 2012SIGGRAPH 2012: NVIDIA OpenGL for 2012
SIGGRAPH 2012: NVIDIA OpenGL for 2012Mark Kilgard
 
Chapter02 graphics-programming
Chapter02 graphics-programmingChapter02 graphics-programming
Chapter02 graphics-programmingMohammed Romi
 
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeksBeginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeksJinTaek Seo
 
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with QtConvert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with QtICS
 
OpenGL NVIDIA Command-List: Approaching Zero Driver Overhead
OpenGL NVIDIA Command-List: Approaching Zero Driver OverheadOpenGL NVIDIA Command-List: Approaching Zero Driver Overhead
OpenGL NVIDIA Command-List: Approaching Zero Driver OverheadTristan Lorach
 
Modern OpenGL Usage: Using Vertex Buffer Objects Well
Modern OpenGL Usage: Using Vertex Buffer Objects Well Modern OpenGL Usage: Using Vertex Buffer Objects Well
Modern OpenGL Usage: Using Vertex Buffer Objects Well Mark Kilgard
 
Migrating from OpenGL to Vulkan
Migrating from OpenGL to VulkanMigrating from OpenGL to Vulkan
Migrating from OpenGL to VulkanMark Kilgard
 
OpenGL 4.5 Update for NVIDIA GPUs
OpenGL 4.5 Update for NVIDIA GPUsOpenGL 4.5 Update for NVIDIA GPUs
OpenGL 4.5 Update for NVIDIA GPUsMark Kilgard
 
NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016Mark Kilgard
 
GPGPU algorithms in games
GPGPU algorithms in gamesGPGPU algorithms in games
GPGPU algorithms in gameszlatan4177
 
Approaching zero driver overhead
Approaching zero driver overheadApproaching zero driver overhead
Approaching zero driver overheadCass Everitt
 

Destaque (15)

02 direct3 d_pipeline
02 direct3 d_pipeline02 direct3 d_pipeline
02 direct3 d_pipeline
 
Why Graphics Is Fast, and What It Can Teach Us About Parallel Programming
Why Graphics Is Fast, and What It Can Teach Us About Parallel ProgrammingWhy Graphics Is Fast, and What It Can Teach Us About Parallel Programming
Why Graphics Is Fast, and What It Can Teach Us About Parallel Programming
 
GPU Programming
GPU ProgrammingGPU Programming
GPU Programming
 
SIGGRAPH 2012: NVIDIA OpenGL for 2012
SIGGRAPH 2012: NVIDIA OpenGL for 2012SIGGRAPH 2012: NVIDIA OpenGL for 2012
SIGGRAPH 2012: NVIDIA OpenGL for 2012
 
Chapter02 graphics-programming
Chapter02 graphics-programmingChapter02 graphics-programming
Chapter02 graphics-programming
 
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeksBeginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
 
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with QtConvert Your Legacy OpenGL Code to Modern OpenGL with Qt
Convert Your Legacy OpenGL Code to Modern OpenGL with Qt
 
OpenGL NVIDIA Command-List: Approaching Zero Driver Overhead
OpenGL NVIDIA Command-List: Approaching Zero Driver OverheadOpenGL NVIDIA Command-List: Approaching Zero Driver Overhead
OpenGL NVIDIA Command-List: Approaching Zero Driver Overhead
 
Modern OpenGL Usage: Using Vertex Buffer Objects Well
Modern OpenGL Usage: Using Vertex Buffer Objects Well Modern OpenGL Usage: Using Vertex Buffer Objects Well
Modern OpenGL Usage: Using Vertex Buffer Objects Well
 
Migrating from OpenGL to Vulkan
Migrating from OpenGL to VulkanMigrating from OpenGL to Vulkan
Migrating from OpenGL to Vulkan
 
OpenGL 4.5 Update for NVIDIA GPUs
OpenGL 4.5 Update for NVIDIA GPUsOpenGL 4.5 Update for NVIDIA GPUs
OpenGL 4.5 Update for NVIDIA GPUs
 
NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016
 
GPGPU algorithms in games
GPGPU algorithms in gamesGPGPU algorithms in games
GPGPU algorithms in games
 
Approaching zero driver overhead
Approaching zero driver overheadApproaching zero driver overhead
Approaching zero driver overhead
 
Thesis Defense
Thesis DefenseThesis Defense
Thesis Defense
 

Semelhante a Pixel shaders

CS 354 Programmable Shading
CS 354 Programmable ShadingCS 354 Programmable Shading
CS 354 Programmable ShadingMark Kilgard
 
Gdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_glGdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_glchangehee lee
 
Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming I💻 Anton Gerdelan
 
Opengl lec 3
Opengl lec 3Opengl lec 3
Opengl lec 3elnaqah
 
OpenGL 3.2 and More
OpenGL 3.2 and MoreOpenGL 3.2 and More
OpenGL 3.2 and MoreMark Kilgard
 
OpenGL ES based UI Development on TI Platforms
OpenGL ES based UI Development on TI PlatformsOpenGL ES based UI Development on TI Platforms
OpenGL ES based UI Development on TI PlatformsPrabindh Sundareson
 
NVIDIA's OpenGL Functionality
NVIDIA's OpenGL FunctionalityNVIDIA's OpenGL Functionality
NVIDIA's OpenGL FunctionalityMark Kilgard
 
Hardware Shaders
Hardware ShadersHardware Shaders
Hardware Shadersgueste52f1b
 
OpenGL Shading Language
OpenGL Shading LanguageOpenGL Shading Language
OpenGL Shading LanguageJungsoo Nam
 
Unity advanced computer graphics week 02
Unity advanced computer graphics week 02Unity advanced computer graphics week 02
Unity advanced computer graphics week 02Tri Thanh
 
openGL basics for sample program (1).ppt
openGL basics for sample program (1).pptopenGL basics for sample program (1).ppt
openGL basics for sample program (1).pptHIMANKMISHRA2
 
openGL basics for sample program.ppt
openGL basics for sample program.pptopenGL basics for sample program.ppt
openGL basics for sample program.pptHIMANKMISHRA2
 
고급컴파일러구성론_개레_230303.pptx
고급컴파일러구성론_개레_230303.pptx고급컴파일러구성론_개레_230303.pptx
고급컴파일러구성론_개레_230303.pptxssuser1e7611
 
Graphics software
Graphics softwareGraphics software
Graphics softwareMohd Arif
 
A Follow-up Cg Runtime Tutorial for Readers of The Cg Tutorial
A Follow-up Cg Runtime Tutorial for Readers of The Cg TutorialA Follow-up Cg Runtime Tutorial for Readers of The Cg Tutorial
A Follow-up Cg Runtime Tutorial for Readers of The Cg TutorialMark Kilgard
 

Semelhante a Pixel shaders (20)

CS 354 Programmable Shading
CS 354 Programmable ShadingCS 354 Programmable Shading
CS 354 Programmable Shading
 
Graphics Libraries
Graphics LibrariesGraphics Libraries
Graphics Libraries
 
Cg in Two Pages
Cg in Two PagesCg in Two Pages
Cg in Two Pages
 
Gdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_glGdc 14 bringing unreal engine 4 to open_gl
Gdc 14 bringing unreal engine 4 to open_gl
 
Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming I
 
Opengl lec 3
Opengl lec 3Opengl lec 3
Opengl lec 3
 
Introduction to 2D/3D Graphics
Introduction to 2D/3D GraphicsIntroduction to 2D/3D Graphics
Introduction to 2D/3D Graphics
 
OpenGL 3.2 and More
OpenGL 3.2 and MoreOpenGL 3.2 and More
OpenGL 3.2 and More
 
OpenGL ES based UI Development on TI Platforms
OpenGL ES based UI Development on TI PlatformsOpenGL ES based UI Development on TI Platforms
OpenGL ES based UI Development on TI Platforms
 
NVIDIA's OpenGL Functionality
NVIDIA's OpenGL FunctionalityNVIDIA's OpenGL Functionality
NVIDIA's OpenGL Functionality
 
Hardware Shaders
Hardware ShadersHardware Shaders
Hardware Shaders
 
OpenGL Shading Language
OpenGL Shading LanguageOpenGL Shading Language
OpenGL Shading Language
 
Unity advanced computer graphics week 02
Unity advanced computer graphics week 02Unity advanced computer graphics week 02
Unity advanced computer graphics week 02
 
openGL basics for sample program (1).ppt
openGL basics for sample program (1).pptopenGL basics for sample program (1).ppt
openGL basics for sample program (1).ppt
 
openGL basics for sample program.ppt
openGL basics for sample program.pptopenGL basics for sample program.ppt
openGL basics for sample program.ppt
 
고급컴파일러구성론_개레_230303.pptx
고급컴파일러구성론_개레_230303.pptx고급컴파일러구성론_개레_230303.pptx
고급컴파일러구성론_개레_230303.pptx
 
1.Philosophy of .NET
1.Philosophy of .NET1.Philosophy of .NET
1.Philosophy of .NET
 
Opengl basics
Opengl basicsOpengl basics
Opengl basics
 
Graphics software
Graphics softwareGraphics software
Graphics software
 
A Follow-up Cg Runtime Tutorial for Readers of The Cg Tutorial
A Follow-up Cg Runtime Tutorial for Readers of The Cg TutorialA Follow-up Cg Runtime Tutorial for Readers of The Cg Tutorial
A Follow-up Cg Runtime Tutorial for Readers of The Cg Tutorial
 

Pixel shaders

  • 1. Pixel shaders: programming the GPU By: Venkata Nanda Kishore
  • 2. What is a Shader? Set of Software Instructions Degree of Flexibility Traits of an entity
  • 3.
  • 4.
  • 6. Geometric ShadersBut the name remained as it was!
  • 7. Effect of Shaders Replaced hard coded effects Gives a programmable alternative Fixed Function PipelineProgrammable Function Pipeline 3.Parallel Programming
  • 8. Programming Shaders HLSL (Direct 3d) GLSL (OpenGl) Cg(Nvidia + Microsoft)
  • 9. Cg What is Cg? Is it similar to C? Is it the right question? Can we use it as a general programming language?
  • 10. Background of Cg Use of Assembly level language What is assembly level? What is high level,low level and middle level? How easy is it?
  • 11. Example of assembly level language fib: movedx, [esp+8] cmpedx, 0 ja @f moveax, 0 ret @@: cmpedx, 2 ja @f moveax, 1 ret @@: push ebx movebx, 1 movecx, 1 @@: lea eax, [ebx+ecx] cmpedx, 3 jbe @f movebx, ecx movecx, eax decedx jmp@b @@: pop ebx ret
  • 12. Advantage of Cg Portable Easy Optimize the code
  • 13. Syntax and Semantics(1) Data Types: int, float, half, fixed, bool, sampler* Operators: Arithmetic and logical operators as in C Additional: arithmetic operations for vector and matrix operrations
  • 14. Syntax and Semantics(2) Functions and Control Structures: Similar to C Standard Cg Library: Specialised GPU programming tasks Eg. Texture Mapping functions tex1D and tex2D Cg Runtime Library:Can be used with OpenGl or DirectX
  • 15. Example Shader // input vertexstructVertIn { float4 pos : POSITION; float4 color : COLOR0; }; // output vertexstructVertOut { float4 pos : POSITION; float4 color : COLOR0; }; // vertex shader main entry VertOutmain(VertIn IN, uniform float4x4 modelViewProj) { VertOut OUT; OUT.pos= mul(modelViewProj, IN.pos); // calculate output coords OUT.color = IN.color; // copy input color to output OUT.color.z= 1.0f; // blue component of color = 1.0f return OUT; }
  • 16. Games that Use Cg HIT MAN : Blood Money BATTLE FIELD 2 FAR CRY RACER And many more
  • 17. How to use Pixel Shaders?