Lecture by: Martin Deschamps CSE 4431

Slides:



Advertisements
Similar presentations
Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 171 Today’s class OpenGL Shading Language.
Advertisements

MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes Week 4 : GLSL Shaders Topics: Shader programs, vertex & fragment shaders, passing data into.
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.
Mohan Sridharan Based on slides created by Edward Angel GLSL I 1 CS4395: Computer Graphics.
Non-Photorealistic Rendering - This is the attempt to make a realistic scene or object look as if it were hand drawn.
Image Processing.  a typical image is simply a 2D array of color or gray values  i.e., a texture  image processing takes as input an image and outputs.
Foundations of Computer Graphics (Fall 2012) CS 184, Lecture 7: OpenGL Shading
A Non-Photorealistic Fragment Shader in OpenGL 2.0 Bert Freudenberg Institut für Simulation und Graphik University of Magdeburg, Germany.
OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.
CS 4363/6353 TEXTURE MAPPING PART II. WHAT WE KNOW We can open image files for reading We can load them into texture buffers We can link that texture.
Cel Shading Jason McCollum. Overview Nonphotorealistic Rendering (NPR) Cel-shading Concepts Demonstration.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
© Copyright Khronos Group, Page 1 Shaders Go Mobile: An Introduction to OpenGL ES 2.0 Tom Olson, Texas Instruments Inc.
Shadow Mapping Chun-Fa Chang National Taiwan Normal University.
GPU Shading and Rendering: OpenGL Shading Language Marc Olano UMBC.
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
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.
Shaders in OpenGL Marshall Hahn. Introduction to Shaders in OpenGL In this talk, the basics of OpenGL Shading Language will be covered. This includes.
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
OpenGL Shading Language (GLSL)
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
OpenGL Shading Language (GLSL)
1 Graphics CSCI 343, Fall 2015 Lecture 5 Color in WebGL.
Cel shading By jared brock.
GLSL II.
GLSL II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New.
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
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.
Day 06 Vertex Shader for Ambient-Diffuse-Specular Lighting.
 Learn how you can use the shader through OpenGL ES  Add texture on object and make the object have a different look!!
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.
OpenGL Shading Language
OpenGL Shading Language (GLSL)
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.
Advanced Texture Mapping Bump Mapping & Environment Mapping (Reflection)
GLSL II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/XX13 – GLSL Lecture 13: OpenGL Shading Language (GLSL) COMP 175: Computer Graphics April 12, 2016.
Non-photorealistic rendering
Shaders, part 2 alexandri zavodny.
Introduction to Computer Graphics with WebGL
Shader.
Texture Mapping Part II
Introduction to Computer Graphics with WebGL
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
Cel Shading Jason McCollum.
Vectors, Normals, & Shading
Day 05 Shader Basics.
Chapter VI OpenGL ES and Shader
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Unity’s Standard Shader Physically Based Shading
ICG 2018 Fall Homework1 Guidance
Programming with OpenGL Part 3: Shaders
Hw03 : shader.
Mickaël Sereno Shaders Mickaël Sereno 25/04/2019 Mickaël Sereno -
Introduction to OpenGL
CS 480/680 Computer Graphics GLSL Overview.
Computer Graphics Shading in OpenGL
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science
Introduction to Computer Graphics with WebGL
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

Lecture by: Martin Deschamps CSE 4431 Cel Shading Lecture by: Martin Deschamps CSE 4431

Essentially, it is a type of non-photorealistic rendering designed to make computer graphics appear to be hand-drawn. Cel- shading is often used to mimic the simplistic style and feel of a hand drawn comic book or cartoon. The name originates from the clear sheets of acetate, called cels, which are painted on for use in traditional 2D animation. The style is more typically seen in cartoons, but a recent trend has cel-shading used more and more in recent video games and graphic applications. Can also be referred to as Toon-shading What is cel shading?

Use of non-photorealistic shading means system processing is kept to a minimum OpenGL 2.0 and GLSL 1.2 System Requirements

Normal vs Cel Shading Comparison Seen here is a representation of Tintin’s Space exploring suit pictured in both cell shading and your everyday normal 3d shader. Normal vs Cel Shading Comparison

Examples

The cosine of the face’s normal is used to determine the brightness level. Closest to direction of light gets brighter tones. cos(lightDir,normal) = dot(lightDir , normal) / ( |lightDir| * |normal| ) If both light dir and normal are normalized, above is simplified to : cos(lightDir,normal) = dot(lightDir, normal) If given a OpenGL variable for the lights position instead of the uniform lightDir, we normalize it before using it in the dot product that forms intensity values. So our vertex shader whould look like this: Vec3 lightDir = normalize(vec3(gl_LightSource[0].position)); intensity = dot(lightDir, gl_Normal); gl_Position = ftransform(); The Basics

Because the intensity is set up as a varying variable used by both vertex and fragment shaders, we must first write it in the vertex shader so that the fragment shader can use it. The fragment shader would then follow a similar form to this: vec4 color; if ( intensity > 0.95 ) color = vec4( 1.0, 0.5, 0.5, 1.0 ); else if ( intensity > 0.5 ) color = vec4( 0.6, 0.3, 0.3, 1.0 ); else if ( intensity > 0.25 ) color = vec4( 0.4, 0.2, 0.2, 1.0 ); else color = vec4( 0.2, 0.1, 0.1, 1.0 ); gl_FragColor = color; The Basics pt2

Per Vertex Normalization uniform vec3 lightDir; varying vec3 intensity; void main(){ float intensity; vec4 color; intensity = dot(lightDir, gl_Normal); if (intensity > 0.95) color = vec4(1.0,0.5,0.5,1.0); else if (intensity > 0.5) color = vec4(0.6,0.3,0.3,1.0); else if (intensity > 0.25) color = vec4(0.4,0.2,0.2,1.0); else color = vec4(0.2,0.1,0.1,1.0); gl_FragColor = color; } In this case we compute the face normals in the vertex shader before passing the values to the fragment shader. It works but results are not optimal. uniform vec3 lightDir; varying float intensity; void main(){ intensity = dot(lightDir, gl_Normal); gl_Position = ftransform(); } Per Vertex Normalization

Per Fragment Normalization uniform vec3 lightDir; varying vec3 normal; void main() { float intensity; vec4 color; intensity = dot(lightDir,normalize(normal)); if (intensity > 0.95) color = vec4(1.0,0.5,0.5,1.0); else if (intensity > 0.5) color = vec4(0.6,0.3,0.3,1.0); else if (intensity > 0.25) color = vec4(0.4,0.2,0.2,1.0); else color = vec4(0.2,0.1,0.1,1.0); gl_FragColor = color; } The difference between this new fragment shader and the one above is that we are now computing the normals in the fragment shader and not the vertex shader. We therefore get proper direction and unit length instead of just proper direction. Our vertex shader in this case essentially becomes two lines: varying vec3 normal; void main() { normal = gl_Normal; gl_Position = ftransform(); } Per Fragment Normalization

Using Light Source with Parameters varying vec3 normal; void main(){ float intensity; vec4 color; vec3 n = normalize(normal); intensity = dot(vec3(gl_LightSource[0].position, n); if (intensity > 0.95) color = vec4(1.0,0.5,0.5,1.0); else if (intensity > 0.5) color = vec4(0.6,0.3,0.3,1.0); else if (intensity > 0.25) color = vec4(0.4,0.2,0.2,1.0); else color = vec4(0.2,0.1,0.1,1.0); gl_FragColor = color; } A way to simplify things a bit and use built in OpenGL Light attributes to save having to specify Light details in lightDir, we would modify our fragment shader to utilize said predetermined parameters as indicated below. varying vec3 normal; void main() { normal = gl_NormalMatrix * gl_Normal; gl_Position = ftransform(); } Using Light Source with Parameters

Use of Texture Coordinates in Shader uniform vec3 LightDir; uniform sampler2D Texture0; varying vec3 normal; vec4 CelShading (vec4 color){ float intensity = dot (LightDir, normalize (normal)); float factor = 1.0; if (intensity <0.5) factor = 0.5; color *= vec4 (factor, factor, factor, 1.0); return color; } void main (void){ vec4 color = Texture2D (Texture0, vec2(gl_TexCoord [0])); //additional effects can be added here color = CelShading( color ); gl_FragColor = color; The benefit of this method allows for a segregation of the shading steps and opens opportunity for additional effects. The vertex shader also changes slightly to take the texture information into consideration. varying vec3 normal; void main(){ //Front color gl_FrontColor = gl_Color; //determine the normal of the vertex normal = gl_NormalMatrix * gl_Normal; //Texture coordinates gl_TexCoord[0] = gl_MultiTexCoord0; //The position of the vertex gl_Position = ftransform(); } Use of Texture Coordinates in Shader

Gradient Increments Simplified vec4 CelShading (vec4 color) { float intensity = dot(LightDir, normalize (normal));  float factor = 0.5;  if (Intensity> 0.95) factor = 1.0; else if (Intensity> 0.5) factor = 0.7; else if (Intensity> 0.25) factor = 0.4; else if (Intensity < 0.1 ) factor = 0.0; //rough outline approximation color *= vec4 (factor, factor, factor, 1.0);  return color; } Gradient Increments Simplified

Why use cel shading?