A Non-Photorealistic Fragment Shader in OpenGL 2.0 Bert Freudenberg Institut für Simulation und Graphik University of Magdeburg, Germany.

Slides:



Advertisements
Similar presentations
POST-PROCESSING SET09115 Intro Graphics Programming.
Advertisements

Normal Map Compression with ATI 3Dc™ Jonathan Zarge ATI Research Inc.
Advanced Graphics Lecture Eight Alex Benton, University of Cambridge – Supported in part by Google UK, Ltd “The Shader knows…”
Non-photorealistic Rendering.  a longtime goal of graphics research has been to render a scene that is indistinguishable from a photograph of the scene.
Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 171 Today’s class OpenGL Shading Language.
The Programmable Graphics Hardware Pipeline Doug James Asst. Professor CS & Robotics.
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.
GLSlang compiler. GLSlang Front-End GL Shading Language compiler front end developed by 3DLabs. Redistribution and use in source and binary forms, with.
Status – Week 277 Victor Moya.
Mohan Sridharan Based on slides created by Edward Angel GLSL I 1 CS4395: Computer Graphics.
OpenGL and WebGL Drawing Functions CSCI 440 Day Five.
Shading Languages By Markus Kummerer. Markus Kummerer 2 / 19 State of the Art Shading.
GPU Tutorial 이윤진 Computer Game 2007 가을 2007 년 11 월 다섯째 주, 12 월 첫째 주.
Under the Hood: 3D Pipeline. Motherboard & Chipset PCI Express x16.
Computer Graphics Inf4/MSc Computer Graphics Lecture 9 Antialiasing, Texture Mapping.
1 Texture. 2 Overview Introduction Painted textures Bump mapping Environment mapping Three-dimensional textures Functional textures Antialiasing textures.
Procedural Textures.
REAL-TIME VOLUME GRAPHICS Christof Rezk Salama Computer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006 Real-Time Volume.
Real-Time Stroke Textures Bert Freudenberg Institut für Simulation und Graphik Universität Magdeburg.
Under the Hood: 3D Pipeline. Motherboard & Chipset PCI Express x16.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
An Introduction to the OpenGL Shading Language Benj Lipchak Rob Simpson Bill Licea-Kane.
OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.
Programmable Pipelines. 2 Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
CSE 690: GPGPU Lecture 6: Cg Tutorial Klaus Mueller Computer Science, Stony Brook University.
© Copyright Khronos Group, Page 1 Shaders Go Mobile: An Introduction to OpenGL ES 2.0 Tom Olson, Texas Instruments Inc.
Lecture by: Martin Deschamps CSE 4431
Week 6 - Wednesday.  What did we talk about last time?  Light  Material  Sensors.
GPU Shading and Rendering: OpenGL Shading Language Marc Olano UMBC.
CSE 381 – Advanced Game Programming GLSL Lighting.
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
Programmable Pipelines Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University.
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-ES 3.0 And Beyond Boston Photo credit :Johnson Cameraface OpenGL Basics.
OpenGL Shading Language (GLSL)
Higher Order Surfaces in OpenGL with NV_evaluators Cass Everitt
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.
Computing & Information Sciences Kansas State University Lecture 12 of 42CIS 636/736: (Introduction to) Computer Graphics CIS 636/736 Computer Graphics.
Day 06 Vertex Shader for Ambient-Diffuse-Specular Lighting.
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.
Background image by chromosphere.deviantart.com Fella in following slides by devart.deviantart.com DM2336 Programming hardware shaders Dioselin Gonzalez.
OpenGL Shading Language
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 4: Color and Attributes Isaac Gang University.
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.
Lighting and Reflection Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
2 3D Viewing Process  3D viewing process MC Model Space Model Transformation Model Transformation WC World Space Viewing Transformation Viewing Transformation.
GLSL I.  Fixed vs. Programmable  HW fixed function pipeline ▪ Faster ▪ Limited  New programmable hardware ▪ Many effects become possible. ▪ Global.
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
Non-photorealistic rendering
Shaders, part 2 alexandri zavodny.
Shader.
Programmable Pipelines
Shading CMSC 435/634.
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
Day 05 Shader Basics.
UMBC Graphics for Games
Programming with OpenGL Part 3: Shaders
Hw03 : shader.
CS 480/680 Computer Graphics GLSL Overview.
Computer Graphics Shading in OpenGL
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

A Non-Photorealistic Fragment Shader in OpenGL 2.0 Bert Freudenberg Institut für Simulation und Graphik University of Magdeburg, Germany

Bert Freudenberg, University of Magdeburg Outline OpenGL 2.0 proposal OpenGL 2.0 proposal Vertex and fragment shaders Vertex and fragment shaders Non-photorealistic shading Non-photorealistic shading Anti-aliasing in a shader Anti-aliasing in a shader Lighting Lighting Adding noise Adding noise Conclusion Conclusion

Bert Freudenberg, University of Magdeburg OpenGL 2.0 Proposal Shading Language High-level language for vertex shaders fragment shaders even more Experimentally implemented as GL2 extension available on 3Dlabs Wildcat VP

Bert Freudenberg, University of Magdeburg Base for our shader Scott F. Johnston’s “Mock Media” From “Advanced RenderMan: Beyond the Companion” (SIGGRAPH ’98 Course #11) RenderMan surface shader for woodprint-like appearance Shading by lines of varying width

Bert Freudenberg, University of Magdeburg Vertex Shader Uses constant and per-vertex data to set up attributes varying across the primitive Uses constant and per-vertex data to set up attributes varying across the primitive Our shader: Our shader: one surface parameter screen-space position

Bert Freudenberg, University of Magdeburg Vertex Shader varying float v; void main(void) { v = gl_MultiTexCoord0.s; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }

Bert Freudenberg, University of Magdeburg Vertex Shader uniform vec3 LightPosition; varying float lightIntensity; varying float v; void main(void) { vec3 pos = vec3(gl_ModelViewMatrix * gl_Vertex); vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal); vec3 lightVec = normalize(LightPosition - pos); lightIntensity = max(dot(lightVec, tnorm), 0.); v = gl_MultiTexCoord0.s; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }

Bert Freudenberg, University of Magdeburg Fragment Shader Gets interpolated varying parameters Gets interpolated varying parameters Similar to RenderMan surface shader Similar to RenderMan surface shader Evaluates some function to output color at a certain point in parameter space Evaluates some function to output color at a certain point in parameter space Our shader: Our shader: output black or white to create lines

Bert Freudenberg, University of Magdeburg Parameter varying float v; v = texcoord0.s; Assigned in vertex shader Assigned in vertex shader Interpolated value in fragment shader Interpolated value in fragment shader

Bert Freudenberg, University of Magdeburg Sawtooth wave sawtooth = fract( v * 16. );

Bert Freudenberg, University of Magdeburg Triangle wave triangle = abs(2. * sawtooth - 1.);

Bert Freudenberg, University of Magdeburg Square wave square = step(0.5, triangle); Aliasing! Aliasing!

Bert Freudenberg, University of Magdeburg Anti-aliasing FSAA will not help FSAA will not help just raises resolution Need to remove higher frequencies Need to remove higher frequencies manually Step function has unlimited frequency Step function has unlimited frequency use smooth step instead

Bert Freudenberg, University of Magdeburg Constant width smoothstep() square = smoothstep(0.4, 0.6, triangle); Buggy, hence: Buggy, hence: edge0 = 0.4; edge1 = 0.6; t = clamp((triangle - edge0) / (edge1 - edge0), 0., 1.); square = t * t * ( * t); Aliasing + blurring Aliasing + blurring

Bert Freudenberg, University of Magdeburg Derivatives dPdx(v), dPdy(v) dPdx(v), dPdy(v) Derivative of parameter v in screen x and y Derivative of parameter v in screen x and y

Bert Freudenberg, University of Magdeburg Length of derivative dp = length(vec2(dPdx, dPdy));

Bert Freudenberg, University of Magdeburg Adaptive filter width filterstep() float edge = 0.5; float w = 64. * dp; float square = clamp((triangle * w - edge) / w, 0., 1.);

Bert Freudenberg, University of Magdeburg Raising frequency No more individual lines No more individual lines Too dense in certain regions Too dense in certain regions Adjust frequency based on screen space density Adjust frequency based on screen space density

Bert Freudenberg, University of Magdeburg Partitioning by derivative ilogdp = floor(log2(dp)); No log2() yet No log2() yet Texture as lookup table Texture as lookup table vec3 tex0 = texture3(0, dp * 8.); float logdp = (tex0.r - 0.5) * tex0.g;

Bert Freudenberg, University of Magdeburg Adjusting frequency exp2(floor(log2(dp))) * f; frequency doubles in discrete steps frequency doubles in discrete steps also works for distance! also works for distance!

Bert Freudenberg, University of Magdeburg Tapering ends linearly interpolate to double frequency linearly interpolate to double frequency t = fract(log2(dp)); triangle = abs((1. + t) * triangle - t);

Bert Freudenberg, University of Magdeburg Lighting Vertex Shader pos = vec3(gl_ModelViewMatrix * gl_Vertex); tnorm = normalize(gl_NormalMatrix * gl_Normal); vec3 lightVec = normalize(LightPosition - pos); lightIntensity = max(dot(lightVec, tnorm), 0.0);

Bert Freudenberg, University of Magdeburg Lighting Line width dependent on lighting Line width dependent on lighting Adjust threshold by light intensity Adjust threshold by light intensity square = step(lightIntensity, triangle);

Bert Freudenberg, University of Magdeburg Noise No noise() yet No noise() yet 3D tilable noise tex = 3D tilable noise tex = ( F(x,y,z)*(t-x)*(t-y)*(t-z)+ F(x-t,y,z)*(x)*(t-y)*(t-z)+ F(x-t,y-t,z)*(x)*(y)*(t-z)+ F(x,y-t,z)*(t-x)*(y)*(t-z)+ F(x,y,z-t)*(t-x)*(t-y)*(z)+ F(x-t,y,z-t)*(x)*(t-y)*(z)+ F(x-t,y-t,z-t)*(x)*(y)*(z)+ F(x,y-t,z-t)*(t-x)*(y)*(z)) /(t*t*t);

Bert Freudenberg, University of Magdeburg Noisy width Bias threshold Bias threshold

Bert Freudenberg, University of Magdeburg Noisy wiggles

Bert Freudenberg, University of Magdeburg Conclusion Learn about RenderMan shaders Learn about RenderMan shaders Translate to OpenGL 2.0 Translate to OpenGL 2.0 almost straight-forward Anti-aliasing is an issue Anti-aliasing is an issue use derivatives Non-photorealistic Rendering is cool! Non-photorealistic Rendering is cool!