Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "A Non-Photorealistic Fragment Shader in OpenGL 2.0 Bert Freudenberg Institut für Simulation und Graphik University of Magdeburg, Germany."— Presentation transcript:

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

2 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

3 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

4 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

5 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

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

7 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; }

8 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

9 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

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

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

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

13 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

14 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 * (3. - 2. * t); Aliasing + blurring Aliasing + blurring

15 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

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

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

18 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

19 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) * 256. + tex0.g;

20 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!

21 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);

22 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);

23 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);

24 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);

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

26 Bert Freudenberg, University of Magdeburg Noisy wiggles

27 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!


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

Similar presentations


Ads by Google