1 Graphics CSCI 343, Fall 2015 Lecture 5 Color in WebGL.

Slides:



Advertisements
Similar presentations
8.1si31_2001 SI31 Advanced Computer Graphics AGR Lecture 8 Polygon Rendering.
Advertisements

Color & Light, Digitalization, Storage. Vision Rods work at low light levels and do not see color –That is, their response depends only on how many photons,
CHAPTER 10 Alpha Blending and Fog © 2008 Cengage Learning EMEA.
As well as colors, normals, and other vertex data PUSHIN’ GEO TO THE GPU JEFF CHASTINE 1.
Bit Depth and Spatial Resolution SIMG-201 Survey of Imaging Science © 2002 CIS/RIT.
Informationsteknologi Monday, October 29, 2007Computer Graphics - Class 21 Today’s class Graphics programming Color.
1 Lecture 6 Attributes of graphical primitives Colors Colors in OpenGL Algorithms for scan-conversion.
IAT 3551 Computer Graphics Overview Color Displays Drawing Pipeline.
Open Graphics Library (OpenGL)
Data starts with width and height of image Then an array of pixel values (colors) The number of elements in this array is width times height Colors can.
Michael Robertson Yuta Takayama. WebGL is OpenGL on a web browser. OpenGL is a low-level 3D graphics API Basically, WebGL is a 3D graphics API that generates.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Basic Graphics Concepts Day One CSCI 440. Terminology object - the thing being modeled image - view of object(s) on the screen frame buffer - memory that.
Basics of a Computer Graphics System Introduction to Computer Graphics CSE 470/598 Arizona State University Dianne Hansford.
I-1 Steps of Image Generation –Create a model of the objects –Create a model for the illumination of the objects –Create an image (render) the result I.
Chapter 2 Getting Started: Drawing Figures. The Framebuffer Lecture 2 Fri, Aug 29, 2003.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 14 Introduction to Computer Graphics.
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
CS 418: Interactive Computer Graphics Introduction to WebGL: HelloTriangle.html Eric Shaffer.
Images The Science of Images What is an Image on the computer? The Psychology of Images What do we use images for? What effect color has on our mood and.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
BPC: Art and Computation – Summer 2007 Digital Media - Images Glenn Bresnahan
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera Real Light Synthetic Light Source.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
User Input and Animation. For Further Reading Angel 7 th Ed: –Chapter 3: Input and Animation. –Chapter 4: Rotation and other transformation. Beginning.
1 Graphics CSCI 343, Fall 2015 Lecture 6 Viewing, Animation, User Interface.
OpenGL-ES 3.0 And Beyond Boston Photo credit :Johnson Cameraface OpenGL Basics.
Color Web Design Professor Frank. Color Displays Based on cathode ray tubes (CRTs) or back- lighted flat-screen Monitors transmit light - displays use.
COMPUTER GRAPHICS. Can refer to the number of pixels in a bitmapped image Can refer to the number of pixels in a bitmapped image The amount of space it.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Graphics CSCI 343, Fall 2015 Lecture 21 Lighting and Shading III.
Vertex Buffer Objects and Shader Attributes. For Further Reading Angel 7 th Ed: –Most parts of Chapter 2. Beginning WebGL: –Chapter 1: vertex Buffer Objects,
Programming with OpenGL Part 0: 3D API. For Further Reading Angel 7 th Ed: –2.2: JavaScript –2.3: OpenGL & WebGL –2.8: fragment & vertex shaders Beginning.
CS 480/680 Computer Graphics Programming with Open GL Part 5: Putting it all together Dr. Frederick C Harris, Jr. Fall 2011.
Programming with OpenGL Part 5: More GLSL Isaac Gang University of Mary Hardin-Baylor E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley.
Visual Appearance Chapter 4 Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology.
1 Graphics CSCI 343, Fall 2015 Lecture 25 Texture Mapping.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
Mouse Input. For Further Reading Learning WebGL, Lesson 11: 2.
Chapter 4 -- Color1 Color Open GL Chapter 4. Chapter 4 -- Color2 n The goal of almost all OpenGL applications is to draw color pictures in a window on.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 4: Color and Attributes Isaac Gang University.
A study of efficiency INDEX BUFFERS JEFF CHASTINE 1.
Advanced Texture Mapping Bump Mapping & Environment Mapping (Reflection)
1 Introduction to Computer Graphics with WebGL ADOPTED from Ed Angel Chapter 2 Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
Pushin’ Geo to the GPU As well as colors, normals, and other vertex data Made by Jeff Chastine, Modified by Chao Mei Jeff Chastine.
Image Processing Objectives To understand pixel based image processing
Introduction to Computer Graphics with WebGL
Interactive Computer Graphics CS 418 – Fall 2017 Indexed Meshes Transformations Background Imagery:
Graphics CSCI 343, Fall 2017 Lecture 13 More on WebGL
Real-Time Rendering Buffers in OpenGL 3.3
Objectives Simple Shaders Programming shaders with GLSL
Programming with OpenGL Part 2: Complete Programs
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 4: Color and Attributes
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 4: Color and Attributes
Mickaël Sereno Shaders Mickaël Sereno 25/04/2019 Mickaël Sereno -
Introduction to Computer Graphics with WebGL
Computer Graphics Shading in OpenGL
Textures in WebGL.
Introduction to Computer Graphics with WebGL
Presentation transcript:

1 Graphics CSCI 343, Fall 2015 Lecture 5 Color in WebGL

2 Physical Color  Visible light has wavelengths from nm in the electromagnetic spectrum.  Short wavelengths are perceived as blue.  Long wavelengths are perceived as red.  Light is reflected of surfaces, and some of that enters the eye and is detected by cells (photoreceptors).  Reflected light has some function of intensities. c( )

3 Red, Green and Blue photoreceptors Photoreceptors come in three types: Red, Green and Blue. Each is sensitive to light in a given range of wavelengths. R( ) G( ) B( ) Our color perception is based on the relative response magnitudes of these three types of photoreceptors.

4 Color Matching To reproduce the appearance of any color, we need to stimulate the photoreceptors by the same amount as a given color stimulates them. c( ) Physical Color Resp. BGR Photoreceptor response c( ) Matching color We can match the appearance of any color with the proper amount or red, green and blue light combined.

5 The Frame Buffer The frame buffer stores the value of each pixel in the viewing window. Each pixel has a given number of bits to encode the color. The number of bits is the bit depth. Bit depth = 8 implies 256 possible colors. Bit depth = 32 implies millions of possible colors (2 32 )

6 Indexed color Problem: If the bit depth is small (<=8), you have a limited number of colors to work with. Solution: Create a color table with 256 cells. Choose the colors that best represent the image to store in the cells. Each number from represents a color in the color table. When displaying the image, the computer looks up the color associated with the number stored for a given pixel.

7 Color tables

8 RGB Color If you have lots of memory, can use a bit depth of 24. This allows 8 bits to code for each of Red, Green and Blue values. Color is often specified by Hexadecimal values (base 16): #FF FF FF(What color is this?) RGB OpenGL: Don't want to depend on particular hardware or number of bits per pixel. Use generic color scale from between 0 and 1.0 for each R, G, B value.

9 WebGL Color specification var pointColor = vec3(r, g, b); //r, g and b range between 0 and 1.0 pointColor = vec3(1.0, 0.0, 0.0);//What color is this? pointColor = vec3(1.0, 0.0, 1.0); pointColor = vec3(0.0, 1.0, 0.0); The alpha channel is a fourth color parameter that specifies opacity vs. transparency (0 = transparent, 1 = opaque). gl.clearColor(1.0, , 1.0); RGB white  opaque

10 Specifying vertex color Colors are set for each vertex and fragment by the fragment shader. We can pass specific colors for each vertex to the shaders using a color data array. We can either pass one array containing both vertex location and vertex color, Or we can create two separate arrays, one for color and one for position.

11 Example: the color_square( ) function var points = [ ]; var colors = [ ];... function color_square( ) { var vertices = [ vec3(-1.0, -1.0, 0.0 ), vec3(-1.0, 1.0, 0.0 ), vec3( 1.0, 1.0, 0.0 ), vec3( 1.0, -1.0, 0.0) ]; // add colors and vertices for one triangle var baseColors = [ vec3(1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), ];

12 More of the color_square( ) function triangle(vertices[0], vertices[1], vertices[2], baseColors[0]); triangle(vertices[0], vertices[2], vertices[3], baseColors[1]); } //end color square function triangle(a, b, c, color) { colors.push( color );//first vertex points.push( a ); colors.push( color );//second vertex points.push( b ); colors.push( color );//third vertex points.push( c ); } //end triangle

13 In the init( ) function: var cBuffer = gl.createBuffer(); gl.bindBuffer( gl.ARRAY_BUFFER, cBuffer ); gl.bufferData( gl.ARRAY_BUFFER, flatten(colors), gl.STATIC_DRAW ); var vColor = gl.getAttribLocation( program, "vColor" ); gl.vertexAttribPointer( vColor, 3, gl.FLOAT, false, 0, 0 ); gl.enableVertexAttribArray( vColor ); Note: You still need to have the code for vPosition. The code for the two buffers is very similar.

14 Assigning Color in the Shaders We use the keyword, attribute, to indicate variables whose values are input to the vertex shader from the graphics program. We use the keyword, varying, to indicate variables that are output from the vertex shader and passed to the fragment shader.

15 The new vertex shader attribute vec3 vPosition;//passed to vertex shader attribute vec3 vColor;//passed to vertex shader varying vec4 color;//output to the fragment shader void main() { gl_Position = vec4(vPosition, 1.0); color = vec4(vColor, 1.0); //output to fragment shader }

16 The new fragment shader precision mediump float; varying vec4 color;//input from vertex shader void main() { gl_FragColor = color; }