Geometry Shaders. And how to use them

Similar documents
Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program

OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders

COMP371 COMPUTER GRAPHICS

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40)

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 4: Three Dimensions

Building Models. Prof. George Wolberg Dept. of Computer Science City College of New York

WebGL A quick introduction. J. Madeira V. 0.2 September 2017

CSE 167. Discussion 03 ft. Glynn 10/16/2017

CPSC 436D Video Game Programming

Particle Systems with Compute & Geometry Shader. Institute of Computer Graphics and Algorithms Vienna University of Technology

Discussion 3. PPM loading Texture rendering in OpenGL

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University

CS 432 Interactive Computer Graphics

CSE 167: Introduction to Computer Graphics Lecture #7: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016

Announcement. Homework 1 has been posted in dropbox and course website. Due: 1:15 pm, Monday, September 12

OpenGL Performances and Flexibility. Visual Computing Laboratory ISTI CNR, Italy

OUTLINE. Implementing Texturing What Can Go Wrong and How to Fix It Mipmapping Filtering Perspective Correction

OPENGL AND GLSL. Computer Graphics

Graphics with OpenGL Documentation

OUTLINE. Hierarchical Models Z-Fighting Primitives Besides Triangles Back Face Culling

GPU Programming EE Final Examination

2D Drawing Primitives

CS195V Week 3. GLSL Programming

Computação Gráfica. Computer Graphics Engenharia Informática (11569) 3º ano, 2º semestre. Chap. 4 Windows and Viewports

OpenGL Performances and Flexibility

CS 432 Interactive Computer Graphics

OPENGL RENDERING PIPELINE

Starting out with OpenGL ES 3.0. Jon Kirkham, Senior Software Engineer, ARM

Shaders. Slide credit to Prof. Zwicker

8 Three-Dimensional Object Representations. Chapter 8. Three-Dimensional Object Representations. Department of Computer Science and Engineering 8-1

CS 450: COMPUTER GRAPHICS REVIEW: STATE, ATTRIBUTES, AND OBJECTS SPRING 2015 DR. MICHAEL J. REALE

Mobile Application Programing: Android. OpenGL Operation

Advanced Graphics. OpenGL and Shaders I. Alex Benton, University of Cambridge Supported in part by Google UK, Ltd

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

CS130 : Computer Graphics. Tamar Shinar Computer Science & Engineering UC Riverside

CS452/552; EE465/505. Image Processing Frame Buffer Objects

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 3: Shaders

CSE 167: Introduction to Computer Graphics Lecture #5: Visibility, OpenGL

Advanced Graphics. OpenGL and Shaders I. Alex Benton, University of Cambridge Supported in part by Google UK, Ltd

The Graphics Pipeline

Rendering. Part 1 An introduction to OpenGL

Rendering Objects. Need to transform all geometry then

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

CS475/CS675 - Computer Graphics. OpenGL Drawing

The Graphics Pipeline

Programming with OpenGL Complete Programs Objectives Build a complete first program

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL

How OpenGL Works. Retained Mode. Immediate Mode. Introduction To OpenGL

The OpenGL Shading Language

HW-Tessellation Basics

Fog example. Fog is atmospheric effect. Better realism, helps determine distances

Computergraphics Exercise 15/ Shading & Texturing

How to use tessellation to add geometric detail to your scenes. How to use geometry shaders to process whole primitives and create geometry on the fly

Texture Mapping. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

CGT520 Lighting. Lighting. T-vertices. Normal vector. Color of an object can be specified 1) Explicitly as a color buffer

Building Models. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

The Graphics Pipeline

CSE 4431/ M Advanced Topics in 3D Computer Graphics. TA: Margarita Vinnikov

Best practices for effective OpenGL programming. Dan Omachi OpenGL Development Engineer

Mobile Application Programing: Android. OpenGL Operation

EDAF80 Introduction to Computer Graphics. Seminar 3. Shaders. Michael Doggett. Slides by Carl Johan Gribel,

Converts geometric primitives into images Is split into several independent stages Those are usually executed concurrently

Applying Textures. Lecture 27. Robb T. Koether. Hampden-Sydney College. Fri, Nov 3, 2017

Computer Graphics CS 543 Lecture 4 (Part 2) Building 3D Models (Part 2)

CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

Computer graphics Labs: OpenGL (2/2) Vertex Shaders and Fragment Shader

Today. Rendering - III. Outline. Texturing: The 10,000m View. Texture Coordinates. Specifying Texture Coordinates in GL

WebGL and GLSL Basics. CS559 Fall 2015 Lecture 10 October 6, 2015

Graphics Pipeline & APIs

Computer Graphics (CS 4731) OpenGL/GLUT(Part 1)

Dave Shreiner, ARM March 2009

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

Mali & OpenGL ES 3.0. Dave Shreiner Jon Kirkham ARM. Game Developers Conference 27 March 2013

Programming with OpenGL Part 3: Shaders. Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Pipeline Operations. CS 4620 Lecture 14

Lighting and Texturing

CS452/552; EE465/505. Image Formation

ERKELEY DAVIS IRVINE LOS ANGELES RIVERSIDE SAN DIEGO SAN FRANCISCO EECS 104. Fundamentals of Computer Graphics. OpenGL

Introduction to Computer Graphics with WebGL

Shader Programming. Daniel Wesslén, Stefan Seipel, Examples

Shader Programming 1. Examples. Vertex displacement mapping. Daniel Wesslén 1. Post-processing, animated procedural textures

Three Main Themes of Computer Graphics

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Rasterization Overview

CSE 167: Introduction to Computer Graphics Lecture #5: Illumination Model

CS452/552; EE465/505. Review & Examples

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

WebGL and GLSL Basics. CS559 Fall 2016 Lecture 14 October

CSC 8470 Computer Graphics. What is Computer Graphics?

Lecture 2. Shaders, GLSL and GPGPU

COSC342: Computer Graphics

Tutorial 04. Harshavardhan Kode. September 14, 2015

Graphics Pipeline & APIs

INTRODUCTION TO OPENGL PIPELINE

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

Lecture 11 Shaders and WebGL. October 8, 2015

Programming with OpenGL Part 5: More GLSL. Ed Angel Professor Emeritus of Computer Science University of New Mexico

Transcription:

Geometry Shaders And how to use them

OpenGL Pipeline (part of it) Vertex data Vertex shader Vertices Primitives Geometry shader Primitives Fragments Fragment shader Color Depth Stencil

Vertex Data Attributes Can be anything you want Typically includes Position Normals Colors Texture coordinates // Create vertices in memory struct vtx { vec3 pos; // Position vec2 uv; // Texture coordinate }; vector<vtx> verts = {... }; nverts = verts.size(); // Create a buffer and fill it with vertex data glgenbuffers(1, &vbuf); glbindbuffer(gl_array_buffer, vbuf); glbufferdata(gl_array_buffer, nverts * sizeof(vtx), verts.data(), GL_STATIC_DRAW); // Specify vertex format glenablevertexattribarray(0); glvertexattribpointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(vtx), (GLvoid*)0); glenablevertexattribarray(1); glvertexattribpointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(vtx), (GLvoid*)sizeof(vec3));

Vertex Shader Process each vertex Input is vertex attributes Output is whatever you want Built-in outputs vec4 gl_position #version 330 core // Input: vertex attributes layout(location = 0) in vec3 pos; layout(location = 1) in vec2 uv; // Per-vertex output smooth out vec2 fraguv; // Uniform values uniform mat4 xform; void main() { gl_position = xform * vec4(pos, 1.0); fraguv = uv; }

Geometry Shader

Fragment Shader Process each fragment Fragment pixel Input is the interpolated output from previous stage #version 330 core // Input: interpolated vertex output smooth in vec2 fraguv; // Color output out vec4 outcol; // Uniform values uniform sampler2d tex; void main() { outcol = texture(tex, fraguv); }

Interpolation Qualifiers smooth flat Fragment input is smoothly interpolated between vertices Fragment input is equal to output from provoking vertex noperspective Also smoothly interpolated, but in window-space

Fragment Shader Process each fragment Fragment pixel Input is the interpolated output from previous stage Output is color, depth, and stencil values Depth is implicitly written #version 330 core // Input: interpolated vertex output smooth in vec2 fraguv; // Color output out vec4 outcol; // Uniform values uniform sampler2d tex; void main() { outcol = texture(tex, fraguv); }

Geometry Shader Sits between vertex and fragment shaders Operates on primitives

The Primitives GL_POINTS GL_LINES GL_LINE_STRIP GL_LINE_LOOP v 1 v 2 v 3 v 1 v 2 v 3 v 4 v 1 v 2 v 3 v 4 v 1 v 2 v 3 v4 GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN v 6 v 6 v 3 v 4 v 1 v 2 v 3 v 4 v 5 v 1 v 2 v 3 v 4 v 5 v 5 v 2 v 1 v 6

#version 330 core Geometry Shader Sits between vertex and fragment shaders Operates on primitives Specify input and output primitive types Input is array of vertex outputs Output is per-vertex Interpolated as in vertex shader Emit vertices to define output primitives // Input and output primitive types layout(triangles) in; layout(triangle_strip, max_vertices = 5) out; // Per-vertex input in vec3 vcol[]; // Interpolated output smooth out vec3 fcol; void main() { gl_position = gl_in[0].gl_position; fcol = vcol[0]; EmitVertex(); gl_position = gl_in[1].gl_position; fcol = vcol[1]; EmitVertex(); gl_position = (gl_in[0].gl_position + gl_in[1].gl_position + gl_in[2].gl_position) / vec4(3); fcol = vec3(1.0, 1.0, 1.0); EmitVertex(); gl_position = gl_in[2].gl_position; fcol = vcol[2]; EmitVertex(); gl_position = gl_in[0].gl_position; fcol = vcol[0]; EmitVertex(); } EndPrimitive();

How to use geometry shaders for the project?

How to use geometry shaders for the project? For each triangle, output three quads Quads should face the camera (billboards) Assign texture coordinates to quad vertices Perform texture lookup in fragment shader

What about backfaces? Use depth testing Perform two passes // Enables depth testing glenable(gl_depth_test); First, draw the cube (without geometry shader), but output depth only Then, draw the cube again, with the geometry shader Quads that are in the back of the cube will be culled by the depth test Push all quads slightly towards the camera to avoid z-fighting

Depth-only rendering Modify the write mask Fragment shader is optional Depth is still written without a fragment shader // Disables writing any color channels glcolormask(gl_false, GL_FALSE, GL_FALSE, GL_FALSE); // Disables writing any depth values gldepthmask(gl_false);

Questions?