A NonPhotorealistic Fragment Shader in Open GL 2
- Slides: 26
A Non-Photorealistic Fragment Shader in Open. GL 2. 0 Bert Freudenberg Institut für Simulation und Graphik University of Magdeburg, Germany
Outline • Open. GL 2. 0 proposal • Vertex and fragment shaders • Non-photorealistic shading • Anti-aliasing in a shader • Lighting • Adding noise • Conclusion Bert Freudenberg, University of Magdeburg
Open. GL 2. 0 Proposal Shading Language • High-level language for • vertex shaders • fragment shaders • even more • Experimentally implemented as GL 2 extension • available on 3 Dlabs Wildcat VP Bert Freudenberg, University of Magdeburg
Base for our shader Scott F. Johnston’s “Mock Media” • From “Advanced Render. Man: Beyond the Companion” (SIGGRAPH ’ 98 Course #11) • Render. Man 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 • Our shader: • one surface parameter • screen-space position Bert Freudenberg, University of Magdeburg
Vertex Shader varying float v; void main(void) { v = gl_Multi. Tex. Coord 0. s; gl_Position = gl_Model. View. Projection. Matrix * gl_Vertex; } Bert Freudenberg, University of Magdeburg
Fragment Shader • Gets interpolated varying parameters • Similar to Render. Man surface shader • Evaluates some function to output color at a certain point in parameter space • Our shader: • output black or white to create lines Bert Freudenberg, University of Magdeburg
Parameter varying float v; v = texcoord 0. s; • Assigned in vertex 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! Bert Freudenberg, University of Magdeburg
Anti-aliasing • FSAA will not help • just raises resolution • Need to remove higher frequencies • manually • 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: edge 0 = 0. 4; edge 1 = 0. 6; t = clamp((triangle - edge 0) / (edge 1 - edge 0), 0. , 1. ); square = t * (3. - 2. * t); • Aliasing + blurring Bert Freudenberg, University of Magdeburg
Derivatives • d. Pdx(v), d. Pdy(v) • Derivative of parameter v in screen x and y Bert Freudenberg, University of Magdeburg
Length of derivative dp = length(vec 2(d. Pdx, d. Pdy)); 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. ); Bert Freudenberg, University of Magdeburg
Raising frequency • No more individual lines • Too dense in certain regions • Adjust frequency based on screen space density Bert Freudenberg, University of Magdeburg
Partitioning by derivative ilogdp = floor(log 2(dp)); • No log 2() yet • Texture as lookup table vec 3 tex 0 = texture 3(0, dp * 8. ); float logdp = (tex 0. r - 0. 5) * 256. + tex 0. g; Bert Freudenberg, University of Magdeburg
Adjusting frequency exp 2(floor(log 2(dp))) * f; • frequency doubles in discrete steps • also works for distance! Bert Freudenberg, University of Magdeburg
Tapering ends • linearly interpolate to double frequency t = fract(log 2(dp)); triangle = abs((1. + t) * triangle - t); Bert Freudenberg, University of Magdeburg
Lighting Vertex Shader pos = vec 3(gl_Model. View. Matrix * gl_Vertex); tnorm = normalize(gl_Normal. Matrix * gl_Normal); vec 3 light. Vec = normalize(Light. Position - pos); light. Intensity = max(dot(light. Vec, tnorm), 0. 0); Bert Freudenberg, University of Magdeburg
Lighting • Line width dependent on lighting • Adjust threshold by light intensity square = step(light. Intensity, triangle); Bert Freudenberg, University of Magdeburg
Noise • No noise() yet 3 D 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 Bert Freudenberg, University of Magdeburg
Noisy wiggles Bert Freudenberg, University of Magdeburg
Conclusion • Learn about Render. Man shaders • Translate to Open. GL 2. 0 • almost straight-forward • Anti-aliasing is an issue • use derivatives • Non-photorealistic Rendering is cool! Bert Freudenberg, University of Magdeburg
- Podaj oznaczenie literowe nukleozydu
- Open 4es shaders
- Open innovation open science open to the world
- Gooch shading model
- 셰이더 로드 및 컴파일
- Vray toon shader maya
- Dynamic penetration shader
- Packets
- Hpse shader
- Hull shader
- Shader model 5
- Citra post processing shader
- George borshukov
- Kuwahara filter unity
- Simple vertex shader
- What is tesselation
- Glsl outline
- Sdl_gpu
- Skybox shader
- Power set
- Quadratic inequality shading
- Gl_triangles_adjacency
- Nvidia slang
- Gooch shader
- High performance shader
- Suggesstive
- Cg shading language