Computer Graphics Coursework 1

Similar documents
CS 130 Final. Fall 2015

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

Deferred Rendering Due: Wednesday November 15 at 10pm

Computer Graphics with OpenGL ES (J. Han) Chapter 6 Fragment shader

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

CSE 167: Lecture #8: Lighting. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Objectives Shading in OpenGL. Front and Back Faces. OpenGL shading. Introduce the OpenGL shading methods. Discuss polygonal shading

CS559 Computer Graphics Fall 2015

Advanced Lighting Techniques Due: Monday November 2 at 10pm

[175 points] The purpose of this assignment is to give you practice with shaders in OpenGL.

INFOGR Computer Graphics

INFOGR Computer Graphics

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1

Shading and Texturing Due: Friday, Feb 17 at 6:00pm

Homework 3: Programmable Shaders

Shaders. Slide credit to Prof. Zwicker

OPENGL RENDERING PIPELINE

CSE 167: Lecture #8: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

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

1 of 5 9/10/ :11 PM

Computer Graphics (CS 543) Lecture 8a: Per-Vertex lighting, Shading and Per-Fragment lighting

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

Pipeline Operations. CS 4620 Lecture 14

-=Bui Tuong Phong's Lighting=- University of Utah, but with shaders. Anton Gerdelan Trinity College Dublin

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

CS452/552; EE465/505. Intro to Lighting

CS 432 Interactive Computer Graphics

CS 130 Exam I. Fall 2015

Raytracing CS148 AS3. Due :59pm PDT

Lighting and Shading II. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Illumination and Shading with GLSL/WebGL

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

CS 4620 Program 3: Pipeline

CS451Real-time Rendering Pipeline

CS5620 Intro to Computer Graphics

Lessons Learned from HW4. Shading. Objectives. Why we need shading. Shading. Scattering

Game Graphics & Real-time Rendering

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

CS 381 Computer Graphics, Fall 2008 Midterm Exam Solutions. The Midterm Exam was given in class on Thursday, October 23, 2008.

CS452/552; EE465/505. Lighting & Shading

Shading. Slides by Ulf Assarsson and Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology

CS4621/5621 Fall Computer Graphics Practicum Intro to OpenGL/GLSL

Lecture 5 Vertex and Fragment Shaders-1. CITS3003 Graphics & Animation

Lab 9 - Metal and Glass

Chapter 7 - Light, Materials, Appearance

Shader Programs. Lecture 30 Subsections 2.8.2, Robb T. Koether. Hampden-Sydney College. Wed, Nov 16, 2011

Shading. Slides by Ulf Assarsson and Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology

Shading. Shading = find color values at pixels of screen (when rendering a virtual 3D scene).

Spring 2012 Final. CS184 - Foundations of Computer Graphics. University of California at Berkeley

From Graphics to Visualization

CPSC 436D Video Game Programming

THE AUSTRALIAN NATIONAL UNIVERSITY Final Examinations (Semester 2) COMP4610/COMP6461 (Computer Graphics) Final Exam

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

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

Models and Architectures

COMP371 COMPUTER GRAPHICS

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

PROFESSIONAL. WebGL Programming DEVELOPING 3D GRAPHICS FOR THE WEB. Andreas Anyuru WILEY. John Wiley & Sons, Ltd.

The Rasterization Pipeline

TDA361/DIT220 Computer Graphics, January 15 th 2016

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

Illumination Models & Shading

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

Institutionen för systemteknik

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

Lecture 15: Shading-I. CITS3003 Graphics & Animation

TDA362/DIT223 Computer Graphics EXAM (Same exam for both CTH- and GU students)

OpenGl Pipeline. triangles, lines, points, images. Per-vertex ops. Primitive assembly. Texturing. Rasterization. Per-fragment ops.

CS 418: Interactive Computer Graphics. Basic Shading in WebGL. Eric Shaffer

Illumination and Shading

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

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

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

SUMMARY. CS380: Introduction to Computer Graphics Texture Mapping Chapter 15. Min H. Kim KAIST School of Computing 18/05/03.

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Specular Reflection. Lecture 19. Robb T. Koether. Hampden-Sydney College. Wed, Oct 4, 2017

INF3320 Computer Graphics and Discrete Geometry

A simple OpenGL animation Due: Wednesday, January 27 at 4pm

SHADER PROGRAMMING. Based on Jian Huang s lecture on Shader Programming

OpenGL shaders and programming models that provide object persistence

CS 130 Exam I. Fall 2015

Computergraphics Exercise 15/ Shading & Texturing

Computer Graphics MTAT Raimond Tunnel

CSE 167: Introduction to Computer Graphics. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2013

Blue colour text questions Black colour text sample answers Red colour text further explanation or references for the sample answers

TSBK03 Screen-Space Ambient Occlusion

Shaders (some slides taken from David M. course)

Introduction to Shaders.

The Graphics Pipeline and OpenGL I: Transformations!

CSE 167: Lecture #7: Color and Shading. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Supplement to Lecture 22

Projections and Hardware Rendering. Brian Curless CSE 557 Fall 2014

Illumination & Shading I

Programmable Graphics Hardware

Graphics for VEs. Ruth Aylett

Introduction to Visualization and Computer Graphics

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

Introduction to Computer Graphics. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Computer Graphics (CS 4731) Lecture 18: Lighting, Shading and Materials (Part 3)

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

Transcription:

Computer Graphics Coursework 1 Deadline Deadline: 4pm, 24/10/2016 4pm 23/10/2015 Outline The aim of the coursework is to modify the vertex and fragment shaders in the provided OpenGL framework to implement transformations using the provided model, view and projection matrices, and to implement Phong shading. The object is rendered into a texture, which can then be modified in a post processing fragment shader before being drawn onscreen. Specification The additions required are: Modify the vertex and fragment shader code (vertex.glsl, fragment.glsl) to: Transform the vertices using the model, view and projection matrices provided Transform the normals using the matrix provided Calculate vectors from the transformed vertex to the light source and eye (the light and eye coordinates in the global coordinate system are provided, these should not be transformed). Calculate Phong illumination, with an ambient, diffuse and specular component Implement Phong shading, using interpolated vertex normals per fragment/pixel You should not use Gouraud shading (calculating illumination once per vertex and interpolating). Implementing these methods will give you a good mark, however extra marks will be awarded for: 1

Using the texture provided in combination with the Phong shading in fragment.glsl Modifying the post processing shader in postfragment.glsl, to add effects. For ideas see lecture 4 (OpenGL). Framework The cw1.tgz file contains a framework with all of the necessary code to create a window, load an object file and render to it using OpenGL. You do not need to understand the OpenGL API calls to be able to complete the coursework. The only files you need to edit are vertex.glsl and fragment.glsl, and optionally postfragment.glsl. Compilation The program should compile on DICE machines running Scientific Linux 7. However older machines using OpenGL 2.1 will not run the coursework. To check the OpenGL version on a machine type glxinfo grep OpenGL in the terminal. The Drill Hall computer lab machines (1.B30) should all be capable of running the program, and you can test this using the demo framework before making modifications. A makefile is provided to build the program, and it can be compiled simply by typing make in the folder containing the makefile and source files. Note that the shader programs are not compiled until runtime, and so any errors in these will not be reported until the program is run. Running The framework can be run using: make run or:./demo1 models/bunny.obj You should see something that looks like this before having modified the shaders: 2

Modifications The vertex shader has some uniform variables as input that you should use to transform the vertices and normal vectors: uniform mat4 model 4 by 4 model transformation matrix uniform mat4 view 4 by 4 view transformation matrix uniform mat4 proj 4 by 4 projection transformation matrix uniform mat4 normtrans 4 by 4 normal vector transformation matrix uniform vec4 eyepos Homogeneous coordinate of eye/camera uniform vec4 lightpos Homogeneous coordinate of light source Each vertex has position and normal vector attributes: in vec3 position Vertex position in vec3 normal Vertex normal 3

The vertex shader should output into the following variables: vec4 gl_position Built in variable, the final position of the vertex in screen coordinates out vec4 lightvec Vector to light source out vec4 eyevec Vector to eye/camera out vec4 normout Vector of transformed surface normal Once the transformations in the vertex shader have been correctly implemented the object should begin to rotate on the screen. For the fragment shader, the GPU will automatically interpolate the outputs of the vertex shader between the three vertices of every triangle, calling the fragment shader with the interpolated values to draw each pixel within the triangle. The fragment shader takes the three out variables above as input. There is also a uniform sampler2d provided that gives access to a texture, that you can use to add extra special effects (optional). Output should be stored in: out vec4 outcolour Vector of red, green, blue and alpha for each pixel, as floating point values between 0 and 1 Postprocessing The object is rendered using vertex.glsl and fragment.glsl into a texture. Then two triangles that cover the screen are rendered using postvertex.glsl, with postfragment.glsl as fragment shader, having access to the texture into which the object was rendered. To modify the postfragment.glsl shader and add special effects, you have: in vec2 pos Position of pixel to be drawn in screen space uniform sampler2d depth Texture containing Z values for each pixel in the rendering of the object uniform sampler2d colour Texture containing colour values for each pixel in the rendering of the object The postfragment.glsl shader supplied with the framework simply looks out the corresponding pixel in the texture and outputs this to the screen. 4

Lighting calculations Illumination and shading is covered in lecture 2. The relevant equations for the coursework are given below. Normal vector transformation: Special care must be taken when transforming normal vectors to a surface to make sure they remain orthogonal to the surface after transformation. For a 4 by 4 3D transformation matrix M applied to an object, the correct transformation to apply to the vertex normals is: M = (M 1 ) T where M is the upper left 3 by 3 sub-matrix of M. See Shirley, 6.2.2 for more detail. This matrix is provided to you as normtrans. Model, view and projection transformations: The model transformation matrix takes vertex coordinates from their local coordinate system to the global coordinate system. Calculations of vectors from vertices to light sources and the eye should be performed in the global coordinate system, since the light and eye coordinates are given in global coordinates. The final coordinate of a vertex on the screen is then calculated by first transforming the vertex coordinate from global coordinates to coordinates relative to the camera using the view transformation matrix, and finally by transforming coordinates relative to the camera using the projection matrix. Diffuse reflection: I diff = I p k d cos θ where θ is the angle between the normal vector of the vertex and the direction to the light source. I p is the intensity of the light source, and k d the diffuse reflectivity. Specular reflection: I spec = I p k s (cos α) n where α is the angle between the reflected incoming light and the direction to the camera. I p is the intensity of the light source, and k s the specular reflectivity. n is the specular intensity. If L is the normalised vector pointing towards the light source and N the (normalised) normal vector at the vertex, cos θ can be calculated as: cos θ = L N To calculate cos α using the unit vector V pointing from the vertex towards the camera we use: cos α = (2N(L N) L) V 5

Colour calculations: Ambient lighting I amb is simply a constant value. The values of cos θ and cos α should be set to 0 if they are negative. Then as an example to calculate the red, green and blue components of the vertex colour for a blue surface with a white specular reflection: r = I spec g = I spec b = I spec + I diff + I amb Hints Some things you may find useful to know: OpenGL colour values for the red, green and blue channels are floating point values in the range 0.0 to 1.0. To combine ambient, diffuse and specular lighting you can simply add the red, green and blue intensities for each together. You can find documentation on the OpenGL API calls used in the framework at: http://docs.gl Submission Coursework is submitted electronically using the Informatics generic electronic submission procedure: submit cg 1 file1, file2, etc. or submit cg 1 directory The program must be compiled and run on DICE, and you must submit your work through the above route. Work will not be accepted otherwise. If your submission does not run on DICE you risk being scored 0. 6

University policies Late policy: http://www.inf.ed.ac.uk/student-services/teaching-organisation/for-taught-students/ coursework-and-projects/late-coursework-submission Conduct policy: http://www.inf.ed.ac.uk/admin/ito/divisionalguidelinesplagiarism.html 7