SlideShare ist ein Scribd-Unternehmen logo
1 von 19
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!
GRAPHICS PIPELINE Geometric Shaders Rasteriser VertexShaders Pixel Shaders
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
Games that Use Cg HIT MAN :  Blood Money BATTLE FIELD 2 FAR CRY RACER And many more
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 structVertIn			    //Input vertex { float4 pos : POSITION;  float4 color : COLOR0; };            // output vertex structVertOut { float4 pos : POSITION; float4 color : COLOR0; };  // vertex shader main entry VertOutmain(VertIn IN, uniform float4x4 modelViewProj)  { VertOut OUT;  OUT.pos= mul(modelViewProj, IN.pos); //position OUT.color= IN.color; // copy input color to output OUT.color.z= 1.0f; // blue component of color = 1.0f return OUT;	 }
Loading Pixel Shaders in OpenGL 1.Loading extensions: glEnable(GL_FRAGMENT_PROGRAM_ARB); 2.Create Shader Number: glGenProgramsARB(1, &shader_num);  glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, shader_num);
Actually Loading the Shader glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(program_string), program_string); glDisable(GL_FRAGMENT_PROGRAM_ARB); http://joshbeam.com/articles/cg_pixel_shaders_in_opengl/

Weitere ähnliche Inhalte

Was ist angesagt?

[C++ korea] effective modern c++ study item 4 - 6 신촌
[C++ korea] effective modern c++ study   item 4 - 6 신촌[C++ korea] effective modern c++ study   item 4 - 6 신촌
[C++ korea] effective modern c++ study item 4 - 6 신촌Seok-joon Yun
 
C++ Introduction
C++ IntroductionC++ Introduction
C++ Introductionparmsidhu
 
[Question Paper] Object Oriented Programming With C++ (Revised Course) [Janua...
[Question Paper] Object Oriented Programming With C++ (Revised Course) [Janua...[Question Paper] Object Oriented Programming With C++ (Revised Course) [Janua...
[Question Paper] Object Oriented Programming With C++ (Revised Course) [Janua...Mumbai B.Sc.IT Study
 
Ai unit3 planing
Ai unit3 planingAi unit3 planing
Ai unit3 planingMerbinJose
 
Shader Programming With Unity
Shader Programming With UnityShader Programming With Unity
Shader Programming With UnityMindstorm Studios
 
Unit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionUnit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionAKR Education
 
Sen17513 summer2015-question-paper
Sen17513 summer2015-question-paperSen17513 summer2015-question-paper
Sen17513 summer2015-question-papervaishali rane
 
3D Geo-standaarden workshop
3D Geo-standaarden workshop3D Geo-standaarden workshop
3D Geo-standaarden workshopLéon Berlo
 
Introduction to c programming language
Introduction to c programming languageIntroduction to c programming language
Introduction to c programming languagesanjay joshi
 
Using FME for Interoperability between GIS and non-GIS Systems
Using FME for Interoperability between GIS and non-GIS SystemsUsing FME for Interoperability between GIS and non-GIS Systems
Using FME for Interoperability between GIS and non-GIS SystemsSafe Software
 
Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#Tomas Petricek
 
Comparing PGQL, G-Core and Cypher
Comparing PGQL, G-Core and CypherComparing PGQL, G-Core and Cypher
Comparing PGQL, G-Core and CypheropenCypher
 
Challenges for advanced domain-specific frameworks
Challenges for advanced domain-specific frameworksChallenges for advanced domain-specific frameworks
Challenges for advanced domain-specific frameworksIstvan Rath
 
Direct Acyclic Graph (DAG)
Direct Acyclic Graph (DAG)Direct Acyclic Graph (DAG)
Direct Acyclic Graph (DAG)RubyyatAbir
 

Was ist angesagt? (19)

[C++ korea] effective modern c++ study item 4 - 6 신촌
[C++ korea] effective modern c++ study   item 4 - 6 신촌[C++ korea] effective modern c++ study   item 4 - 6 신촌
[C++ korea] effective modern c++ study item 4 - 6 신촌
 
C++ Introduction
C++ IntroductionC++ Introduction
C++ Introduction
 
[Question Paper] Object Oriented Programming With C++ (Revised Course) [Janua...
[Question Paper] Object Oriented Programming With C++ (Revised Course) [Janua...[Question Paper] Object Oriented Programming With C++ (Revised Course) [Janua...
[Question Paper] Object Oriented Programming With C++ (Revised Course) [Janua...
 
Tricks
TricksTricks
Tricks
 
History of c++
History of c++ History of c++
History of c++
 
Ai unit3 planing
Ai unit3 planingAi unit3 planing
Ai unit3 planing
 
Lecture1
Lecture1Lecture1
Lecture1
 
Shader Programming With Unity
Shader Programming With UnityShader Programming With Unity
Shader Programming With Unity
 
Unit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionUnit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introduction
 
Sen17513 summer2015-question-paper
Sen17513 summer2015-question-paperSen17513 summer2015-question-paper
Sen17513 summer2015-question-paper
 
3D Geo-standaarden workshop
3D Geo-standaarden workshop3D Geo-standaarden workshop
3D Geo-standaarden workshop
 
Introduction to c programming language
Introduction to c programming languageIntroduction to c programming language
Introduction to c programming language
 
Using FME for Interoperability between GIS and non-GIS Systems
Using FME for Interoperability between GIS and non-GIS SystemsUsing FME for Interoperability between GIS and non-GIS Systems
Using FME for Interoperability between GIS and non-GIS Systems
 
Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#Creating Domain Specific Languages in F#
Creating Domain Specific Languages in F#
 
Comparing PGQL, G-Core and Cypher
Comparing PGQL, G-Core and CypherComparing PGQL, G-Core and Cypher
Comparing PGQL, G-Core and Cypher
 
Haxe vs Unicode (en)
Haxe vs Unicode (en)Haxe vs Unicode (en)
Haxe vs Unicode (en)
 
Challenges for advanced domain-specific frameworks
Challenges for advanced domain-specific frameworksChallenges for advanced domain-specific frameworks
Challenges for advanced domain-specific frameworks
 
Assignment 4
Assignment 4Assignment 4
Assignment 4
 
Direct Acyclic Graph (DAG)
Direct Acyclic Graph (DAG)Direct Acyclic Graph (DAG)
Direct Acyclic Graph (DAG)
 

Andere mochten auch

Spark Data Streaming Pipeline
Spark Data Streaming PipelineSpark Data Streaming Pipeline
Spark Data Streaming PipelineJonathan Bradshaw
 
Big Data Logging Pipeline with Apache Spark and Kafka
Big Data Logging Pipeline with Apache Spark and KafkaBig Data Logging Pipeline with Apache Spark and Kafka
Big Data Logging Pipeline with Apache Spark and KafkaDogukan Sonmez
 
Email Classifier using Spark 1.3 Mlib / ML Pipeline
Email Classifier using Spark 1.3 Mlib / ML PipelineEmail Classifier using Spark 1.3 Mlib / ML Pipeline
Email Classifier using Spark 1.3 Mlib / ML Pipelineleorick lin
 
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeksBeginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeksJinTaek Seo
 
Geometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping SetupGeometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping SetupMark Kilgard
 
Shaders - Claudia Doppioslash - Unity With the Best
Shaders - Claudia Doppioslash - Unity With the BestShaders - Claudia Doppioslash - Unity With the Best
Shaders - Claudia Doppioslash - Unity With the BestBeMyApp
 
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeksBeginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeksJinTaek Seo
 
Unity Surface Shader for Artist 02
Unity Surface Shader for Artist 02Unity Surface Shader for Artist 02
Unity Surface Shader for Artist 02SangYun Yi
 
Advanced Spark and TensorFlow Meetup 08-04-2016 One Click Spark ML Pipeline D...
Advanced Spark and TensorFlow Meetup 08-04-2016 One Click Spark ML Pipeline D...Advanced Spark and TensorFlow Meetup 08-04-2016 One Click Spark ML Pipeline D...
Advanced Spark and TensorFlow Meetup 08-04-2016 One Click Spark ML Pipeline D...Chris Fregly
 
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...Jose Quesada (hiring)
 
Building Scalable Big Data Pipelines
Building Scalable Big Data PipelinesBuilding Scalable Big Data Pipelines
Building Scalable Big Data PipelinesChristian Gügi
 
Building a unified data pipeline in Apache Spark
Building a unified data pipeline in Apache SparkBuilding a unified data pipeline in Apache Spark
Building a unified data pipeline in Apache SparkDataWorks Summit
 
R&D to Product Pipeline Using Apache Spark in AdTech: Spark Summit East talk ...
R&D to Product Pipeline Using Apache Spark in AdTech: Spark Summit East talk ...R&D to Product Pipeline Using Apache Spark in AdTech: Spark Summit East talk ...
R&D to Product Pipeline Using Apache Spark in AdTech: Spark Summit East talk ...Spark Summit
 
Working with Shader with Unity
Working with Shader with UnityWorking with Shader with Unity
Working with Shader with UnityMinh Nghiem
 
Unity道場11 Shader Forge 101 ~ShaderForgeをつかって学ぶシェーダー入門~ 基本操作とよく使われるノード編
Unity道場11 Shader Forge 101 ~ShaderForgeをつかって学ぶシェーダー入門~ 基本操作とよく使われるノード編Unity道場11 Shader Forge 101 ~ShaderForgeをつかって学ぶシェーダー入門~ 基本操作とよく使われるノード編
Unity道場11 Shader Forge 101 ~ShaderForgeをつかって学ぶシェーダー入門~ 基本操作とよく使われるノード編小林 信行
 

Andere mochten auch (17)

Spark Data Streaming Pipeline
Spark Data Streaming PipelineSpark Data Streaming Pipeline
Spark Data Streaming Pipeline
 
Big Data Logging Pipeline with Apache Spark and Kafka
Big Data Logging Pipeline with Apache Spark and KafkaBig Data Logging Pipeline with Apache Spark and Kafka
Big Data Logging Pipeline with Apache Spark and Kafka
 
Email Classifier using Spark 1.3 Mlib / ML Pipeline
Email Classifier using Spark 1.3 Mlib / ML PipelineEmail Classifier using Spark 1.3 Mlib / ML Pipeline
Email Classifier using Spark 1.3 Mlib / ML Pipeline
 
Intro to Shader
Intro to ShaderIntro to Shader
Intro to Shader
 
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeksBeginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
Beginning direct3d gameprogramming10_shaderdetail_20160506_jintaeks
 
Geometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping SetupGeometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping Setup
 
Shaders - Claudia Doppioslash - Unity With the Best
Shaders - Claudia Doppioslash - Unity With the BestShaders - Claudia Doppioslash - Unity With the Best
Shaders - Claudia Doppioslash - Unity With the Best
 
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeksBeginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
 
Unity Surface Shader for Artist 02
Unity Surface Shader for Artist 02Unity Surface Shader for Artist 02
Unity Surface Shader for Artist 02
 
Advanced Spark and TensorFlow Meetup 08-04-2016 One Click Spark ML Pipeline D...
Advanced Spark and TensorFlow Meetup 08-04-2016 One Click Spark ML Pipeline D...Advanced Spark and TensorFlow Meetup 08-04-2016 One Click Spark ML Pipeline D...
Advanced Spark and TensorFlow Meetup 08-04-2016 One Click Spark ML Pipeline D...
 
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
A full Machine learning pipeline in Scikit-learn vs in scala-Spark: pros and ...
 
Building Scalable Big Data Pipelines
Building Scalable Big Data PipelinesBuilding Scalable Big Data Pipelines
Building Scalable Big Data Pipelines
 
Building a unified data pipeline in Apache Spark
Building a unified data pipeline in Apache SparkBuilding a unified data pipeline in Apache Spark
Building a unified data pipeline in Apache Spark
 
R&D to Product Pipeline Using Apache Spark in AdTech: Spark Summit East talk ...
R&D to Product Pipeline Using Apache Spark in AdTech: Spark Summit East talk ...R&D to Product Pipeline Using Apache Spark in AdTech: Spark Summit East talk ...
R&D to Product Pipeline Using Apache Spark in AdTech: Spark Summit East talk ...
 
Working with Shader with Unity
Working with Shader with UnityWorking with Shader with Unity
Working with Shader with Unity
 
Aws overview
Aws overviewAws overview
Aws overview
 
Unity道場11 Shader Forge 101 ~ShaderForgeをつかって学ぶシェーダー入門~ 基本操作とよく使われるノード編
Unity道場11 Shader Forge 101 ~ShaderForgeをつかって学ぶシェーダー入門~ 基本操作とよく使われるノード編Unity道場11 Shader Forge 101 ~ShaderForgeをつかって学ぶシェーダー入門~ 基本操作とよく使われるノード編
Unity道場11 Shader Forge 101 ~ShaderForgeをつかって学ぶシェーダー入門~ 基本操作とよく使われるノード編
 

Ähnlich wie Pixel shaders

CS 354 Programmable Shading
CS 354 Programmable ShadingCS 354 Programmable Shading
CS 354 Programmable ShadingMark Kilgard
 
OpenGL 3.2 and More
OpenGL 3.2 and MoreOpenGL 3.2 and More
OpenGL 3.2 and MoreMark Kilgard
 
Opengl lec 3
Opengl lec 3Opengl lec 3
Opengl lec 3elnaqah
 
OpenGL Shading Language
OpenGL Shading LanguageOpenGL Shading Language
OpenGL Shading LanguageJungsoo Nam
 
NVIDIA's OpenGL Functionality
NVIDIA's OpenGL FunctionalityNVIDIA's OpenGL Functionality
NVIDIA's OpenGL FunctionalityMark Kilgard
 
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 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
 
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
 
Hardware Shaders
Hardware ShadersHardware Shaders
Hardware Shadersgueste52f1b
 
Chapter02 graphics-programming
Chapter02 graphics-programmingChapter02 graphics-programming
Chapter02 graphics-programmingMohammed Romi
 
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
 
CS 354 Pixel Updating
CS 354 Pixel UpdatingCS 354 Pixel Updating
CS 354 Pixel UpdatingMark Kilgard
 
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
 
2GKS, Open GL and IGES_Video Lect Given by Renjin.pptx
2GKS, Open GL and IGES_Video Lect Given by Renjin.pptx2GKS, Open GL and IGES_Video Lect Given by Renjin.pptx
2GKS, Open GL and IGES_Video Lect Given by Renjin.pptxRamanathanSabesan
 

Ähnlich wie Pixel shaders (20)

CS 354 Programmable Shading
CS 354 Programmable ShadingCS 354 Programmable Shading
CS 354 Programmable Shading
 
OpenGL 3.2 and More
OpenGL 3.2 and MoreOpenGL 3.2 and More
OpenGL 3.2 and More
 
Opengl lec 3
Opengl lec 3Opengl lec 3
Opengl lec 3
 
Graphics Libraries
Graphics LibrariesGraphics Libraries
Graphics Libraries
 
OpenGL Shading Language
OpenGL Shading LanguageOpenGL Shading Language
OpenGL Shading Language
 
NVIDIA's OpenGL Functionality
NVIDIA's OpenGL FunctionalityNVIDIA's OpenGL Functionality
NVIDIA's OpenGL Functionality
 
Introduction to 2D/3D Graphics
Introduction to 2D/3D GraphicsIntroduction to 2D/3D Graphics
Introduction to 2D/3D Graphics
 
Unity advanced computer graphics week 02
Unity advanced computer graphics week 02Unity advanced computer graphics week 02
Unity advanced computer graphics week 02
 
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
 
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
 
Hardware Shaders
Hardware ShadersHardware Shaders
Hardware Shaders
 
Chapter02 graphics-programming
Chapter02 graphics-programmingChapter02 graphics-programming
Chapter02 graphics-programming
 
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 4 for 2010
OpenGL 4 for 2010OpenGL 4 for 2010
OpenGL 4 for 2010
 
CS 354 Pixel Updating
CS 354 Pixel UpdatingCS 354 Pixel Updating
CS 354 Pixel Updating
 
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
 
2GKS, Open GL and IGES_Video Lect Given by Renjin.pptx
2GKS, Open GL and IGES_Video Lect Given by Renjin.pptx2GKS, Open GL and IGES_Video Lect Given by Renjin.pptx
2GKS, Open GL and IGES_Video Lect Given by Renjin.pptx
 
Opengl basics
Opengl basicsOpengl basics
Opengl basics
 
1.Philosophy of .NET
1.Philosophy of .NET1.Philosophy of .NET
1.Philosophy of .NET
 

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. GRAPHICS PIPELINE Geometric Shaders Rasteriser VertexShaders Pixel Shaders
  • 8. Effect of Shaders Replaced hard coded effects Gives a programmable alternative Fixed Function PipelineProgrammable Function Pipeline 3.Parallel Programming
  • 9. Programming Shaders HLSL (Direct 3d) GLSL (OpenGl) Cg(Nvidia + Microsoft)
  • 10. Cg What is Cg? Is it similar to C? Is it the right question? Can we use it as a general programming language?
  • 11. 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?
  • 12. 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
  • 13. Advantage of Cg Portable Easy Optimize the code
  • 14. Games that Use Cg HIT MAN : Blood Money BATTLE FIELD 2 FAR CRY RACER And many more
  • 15. 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
  • 16. 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
  • 17. Example Shader structVertIn //Input vertex { float4 pos : POSITION; float4 color : COLOR0; }; // output vertex structVertOut { float4 pos : POSITION; float4 color : COLOR0; }; // vertex shader main entry VertOutmain(VertIn IN, uniform float4x4 modelViewProj) { VertOut OUT; OUT.pos= mul(modelViewProj, IN.pos); //position OUT.color= IN.color; // copy input color to output OUT.color.z= 1.0f; // blue component of color = 1.0f return OUT; }
  • 18. Loading Pixel Shaders in OpenGL 1.Loading extensions: glEnable(GL_FRAGMENT_PROGRAM_ARB); 2.Create Shader Number: glGenProgramsARB(1, &shader_num); glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, shader_num);
  • 19. Actually Loading the Shader glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(program_string), program_string); glDisable(GL_FRAGMENT_PROGRAM_ARB); http://joshbeam.com/articles/cg_pixel_shaders_in_opengl/
  • 20. Examples https://support.steampowered.com/kb_article.php?ref=4360-TPJL-2065 Gives what games need what version of pixel shaders http://www.nvidia.com/object/feature_pixelshader.html http://www.toymaker.info/Games/html/pixel_shaders.html