Language Definitions Chap. 3 of Orange Book.

Slides:



Advertisements
Similar presentations
Question Bank. Explain the syntax of if else statement? Define Union Define global and local variables with example Concept of recursion with example.
Advertisements

Programming Languages and Paradigms
Programming Languages and Paradigms The C Programming Language.
EECS 700: Computer Modeling, Simulation, and Visualization Dr. Shontz Chapter 2: Shader Fundamentals (continued)
Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 171 Today’s class OpenGL Shading Language.
MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes Week 5 : GLSL Shaders Topics: Shader syntax, passing textures into shaders, per-pixel lighting,
GLSL I May 28, 2007 (Adapted from Ed Angel’s lecture slides)
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Chapter 6. 2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single Value Pass by Reference Variable Scope.
Mohan Sridharan Based on slides created by Edward Angel GLSL I 1 CS4395: Computer Graphics.
Functions in C. Function Terminology Identifier scope Function declaration, definition, and use Parameters and arguments Parameter order, number, and.
Imperative Programming
Real-time Graphical Shader Programming with Cg (HLSL)
An Introduction to the OpenGL Shading Language Benj Lipchak Rob Simpson Bill Licea-Kane.
OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.
A First Book of C++: From Here To There, Third Edition2 Objectives You should be able to describe: Function and Parameter Declarations Returning a Single.
Programming Language C++ Xulong Peng CSC415 Programming Languages.
Copyright © 2012 Pearson Education, Inc. Chapter 6: Functions.
Learners Support Publications Classes and Objects.
Programming Languages and Paradigms Imperative Programming.
Classes In C++ 1. What is a class Can make a new type in C++ by declaring a class. A class is an expanded concept of a data structure: instead of holding.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
OpenGL Shader Language Vertex and Fragment Shading Programs.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
A FIRST BOOK OF C++ CHAPTER 6 MODULARITY USING FUNCTIONS.
Chapter Functions 6. Modular Programming 6.1 Modular Programming Modular programming: breaking a program up into smaller, manageable functions or modules.
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 6: Functions.
OpenGL Shading Language
Programming with OpenGL Part 3: Shaders Ed Angel Professor of Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive.
OpenGl Shaders Lighthouse3d.com.
GLSL I.  Fixed vs. Programmable  HW fixed function pipeline ▪ Faster ▪ Limited  New programmable hardware ▪ Many effects become possible. ▪ Global.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/XX13 – GLSL Lecture 13: OpenGL Shading Language (GLSL) COMP 175: Computer Graphics April 12, 2016.
Test 2 Review Outline.
Shader.
Learning to Program D is for Digital.
Friend Class Friend Class A friend class can access private and protected members of other class in which it is declared as friend. It is sometimes useful.
Introduction to C++ Systems Programming.
Programming with ANSI C ++
C++, OBJECT ORIENTED PROGRAMMING
Structures Revisited what is an aggregate construct? What aggregate constructs have we studied? what is a structure? what is the keyword to define a structure?
C Short Overview Lembit Jürimägi.
Prepared By: G.UshaRani B.Pranalini A.S.Lalitha
Operator Overloading BCA Sem III K.I.R.A.S.
Programmazione I a.a. 2017/2018.
This pointer, Dynamic memory allocation, Constructors and Destructor
11/10/2018.
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Introduction to Computer Graphics with WebGL
Chapter 3 Introduction to Classes, Objects Methods and Strings
7 Arrays.
Day 05 Shader Basics.
Chapter VI OpenGL ES and Shader
6 Chapter Functions.
Introduction to Computer Graphics with WebGL
Introduction to Classes and Objects
Classes and Objects.
Shader Basics Chap. 2 of Orange Book.
7 Arrays.
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Object Oriented Programming in java
Programming with OpenGL Part 3: Shaders
Based on slides created by Bjarne Stroustrup & Tony Gaddis
Programming Languages and Paradigms
CS 480/680 Computer Graphics GLSL Overview.
C Language B. DHIVYA 17PCA140 II MCA.
CS 480/680 Part 1: Model Loading.
Introduction to Computer Graphics with WebGL
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

Language Definitions Chap. 3 of Orange Book

Contents Data types Initializers and constructors Type conversions Qualifiers; interface to a shader Flow control Operators

Introduction A program typically contains two shaders: one vertex shader and one fragment shader. More than one shader of each type can be present, but there must be exactly one function main among all the fragment shaders; and exactly one function main among all the vertex shaders.

Example (Vertex Shader)

Example (Fragment Shader)

Data Types Scalar types Vectors Matrices (floating point only) float, bool, int [bitwise ops are not supported] Vectors vec[2|3|4], bvec[2|3|4], ivec[2|3|4] selecting components: x,y,z,w; s,t,p,q; r,g,b,a GLSL does not distinguish between a color vector and a position vector or other uses of a floating-point vector. Matrices (floating point only) mat[2|3|4] (column-major order) Samplers 1|2|3D textures, cube map, shadow (depth texture) They can only receive them from the application, through a uniform qualified sampler, or pass them on to user or built-in functions. Shaders may not manipulate sampler values. Grass + 1 is not allowed.

Bitwise Operators new!

Data Types (cont) typedef Structure (no typedef) arrays No {typecast, pointers, implicit type change} use constructors to perform conversions

Note: this is different from C ! Type Conversion Note: this is different from C !

Swizzling

Component-wise Operation

Initializers and Constructors Constant qualified variables must be initialized. Attribute, uniform, and varying variables cannot be initialized when declared. Attribute,uniform: API sets it Varying: vertex shader sets it Extra components within a single constructor argument are silently ignored. Normally, this is useful for shrinking a value, like eliminating alpha from a color (or w from a position).

Initialize Struct To initialize aggregate types, constructors are used. No initializer uses the brace syntax "{. . .}" from C.

Example: initializers (column-major)

Qualifiers Attribute Uniform Varying Const Absent Floating point scalar, vectors, and matrices For vertex shaders only Uniform Read-only in shaders Varying Dynamic interface between vertex shaders and fragment shader Const Compile time constant Absent (See next page)

Absent Qualifier If no qualifier is specified when a variable (not a function parameter) is declared, the variable can be both read and written by the shader. Nonqualified variables declared at global scope can be shared between shaders of the same type that are linked in the same program. Vertex shaders and fragment shaders each have their own separate global name space for nonqualified globals. (compare uniform) However, nonqualified user-defined variables are not visible outside a program. Unqualified variables have a lifetime limited to a single run of a shader. There is also no concept corresponding to a static variable in a C function that would allow a variable to be set to a value and have its shader retain that value from one execution to the next.

goto, switch

Flow Control Looping can be done with for, while, and do-while The keywords break and continue also exist and behave as in C. Selection can be done with if and if-else, just as in C++, with the exception that a variable cannot be declared in the if statement. Selection by means of the selection operator (?:) is also available, with the extra constraint that the second and third operands must have exactly the same type. The type of the expression provided to an if statement or a while statement, or to terminate a for statement, must be a scalar Boolean A special branch, discard, can prevent a fragment from updating the frame buffer

Function Calls call by value-return Parameter qualifiers: in, out, inout; const in qualifier is implied when no qualifiers are specified

Most GPU driver vendors don't usually bother to implement noiseX in GLSL, rand() in glsl (url) float rand(vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); }