OpenGL ES 2.0 Lighting 2 Per-fragment Lighting. CS421 Advanced Computer Graphics Jay Urbain, Ph.D.

Similar documents
Introduction to Computer Graphics with WebGL

Image Processing and Computer Graphics. Rendering Pipeline. Matthias Teschner. Computer Science Department University of Freiburg

Shader Model 3.0. Ashu Rege. NVIDIA Developer Technology Group

GPU Shading and Rendering: Introduction & Graphics Hardware

Monash University Clayton s School of Information Technology CSE3313 Computer Graphics Sample Exam Questions 2007

Android and OpenGL. Android Smartphone Programming. Matthias Keil. University of Freiburg

Vertex and fragment programs

CS418 GLSL Shader Programming Tutorial (I) Shader Introduction. Presented by : Wei-Wen Feng 3/12/2008

INTRODUCTION TO RENDERING TECHNIQUES

CSE 564: Visualization. GPU Programming (First Steps) GPU Generations. Klaus Mueller. Computer Science Department Stony Brook University

How To Make A Texture Map Work Better On A Computer Graphics Card (Or Mac)

Computer Applications in Textile Engineering. Computer Applications in Textile Engineering

Optimizing Unity Games for Mobile Platforms. Angelo Theodorou Software Engineer Unite 2013, 28 th -30 th August

GPUs Under the Hood. Prof. Aaron Lanterman School of Electrical and Computer Engineering Georgia Institute of Technology

3D Graphics and Cameras

Introduction to GPGPU. Tiziano Diamanti

Parallel Web Programming

Modern Graphics Engine Design. Sim Dietrich NVIDIA Corporation

GUI GRAPHICS AND USER INTERFACES. Welcome to GUI! Mechanics. Mihail Gaianu 26/02/2014 1

A Pipeline From COLLADA to WebGL for Skeletal Animation

The Evolution of Computer Graphics. SVP, Content & Technology, NVIDIA

How To Understand The Power Of Unity 3D (Pro) And The Power Behind It (Pro/Pro)

Midgard GPU Architecture. October 2014

Introduction to Computer Graphics

A.R.I.S.E. Architectural Real-time Interactive Showing Environment. Supervisor: Scott Chase

Programmable Graphics Hardware

Hardware design for ray tracing

Game Development in Android Disgruntled Rats LLC. Sean Godinez Brian Morgan Michael Boldischar

Advances in Real-Time Skin Rendering

Recent Advances and Future Trends in Graphics Hardware. Michael Doggett Architect November 23, 2005

High Dynamic Range and other Fun Shader Tricks. Simon Green

2: Introducing image synthesis. Some orientation how did we get here? Graphics system architecture Overview of OpenGL / GLU / GLUT

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

Computer Graphics. Anders Hast

Radeon HD 2900 and Geometry Generation. Michael Doggett

The Future Of Animation Is Games

Computer Graphics Hardware An Overview

CUBE-MAP DATA STRUCTURE FOR INTERACTIVE GLOBAL ILLUMINATION COMPUTATION IN DYNAMIC DIFFUSE ENVIRONMENTS

3D Math Overview and 3D Graphics Foundations

Procedural Shaders: A Feature Animation Perspective

Color correction in 3D environments Nicholas Blackhawk

Graphics Cards and Graphics Processing Units. Ben Johnstone Russ Martin November 15, 2011

Volume Rendering on Mobile Devices. Mika Pesonen

IT 386: 3D Modeling and Animation. Review Sheet. Notes from Professor Nersesian s IT 386: 3D Modeling and Animation course

Introduction to Computer Graphics

Realtime 3D Computer Graphics Virtual Reality

GPU(Graphics Processing Unit) with a Focus on Nvidia GeForce 6 Series. By: Binesh Tuladhar Clay Smith

A Crash Course on Programmable Graphics Hardware

Writing Applications for the GPU Using the RapidMind Development Platform

Shadows. Shadows. Thanks to: Frédo Durand and Seth Teller MIT. Realism Depth cue

Introduction GPU Hardware GPU Computing Today GPU Computing Example Outlook Summary. GPU Computing. Numerical Simulation - from Models to Software

Data Visualization Using Hardware Accelerated Spline Interpolation

NVPRO-PIPELINE A RESEARCH RENDERING PIPELINE MARKUS TAVENRATH MATAVENRATH@NVIDIA.COM SENIOR DEVELOPER TECHNOLOGY ENGINEER, NVIDIA

Deferred Shading & Screen Space Effects

Introduction to Game Programming. Steven Osman

GPU Christmas Tree Rendering. Evan Hart

Developer Tools. Tim Purcell NVIDIA

Optimizing AAA Games for Mobile Platforms

GPGPU Computing. Yong Cao

CMSC 427 Computer Graphics Programming Assignment 1: Introduction to OpenGL and C++ Due Date: 11:59 PM, Sept. 15, 2015

PRODUCT LIFECYCLE MANAGEMENT COMPETENCY CENTRE RENDERING. PLMCC, JSS Academy of Technical Education, Noida Rendering 1 of 16

Interactive Computer Graphics

Transformations in the pipeline

GPU Architecture. Michael Doggett ATI

QCD as a Video Game?

Graphics Pipeline in a Nutshell

Tutorial 9: Skeletal Animation

A Short Introduction to Computer Graphics

OpenGL Performance Tuning

COMP-557: Fundamentals of Computer Graphics McGill University, Fall 2010

Silverlight for Windows Embedded Graphics and Rendering Pipeline 1

OpenGL Shading Language Course. Chapter 5 Appendix. By Jacobo Rodriguez Villar jacobo.rodriguez@typhoonlabs.com

L20: GPU Architecture and Models

Performance Optimization and Debug Tools for mobile games with PlayCanvas

Advanced Visual Effects with Direct3D

Computer Graphics on Mobile Devices VL SS ECTS

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

Low power GPUs a view from the industry. Edvard Sørgård

Computer Graphics. Introduction. Computer graphics. What is computer graphics? Yung-Yu Chuang

In the early 1990s, ubiquitous

Algebra Geometry Glossary. 90 angle

Geometric algebra rotors for skinned character animation blending

glga: an OpenGL Geometric Application framework for a modern, shader-based computer graphics curriculum

Unreal Engine 4: Mobile Graphics on ARM CPU and GPU Architecture

GPU Point List Generation through Histogram Pyramids

Nicolas P. Rougier PyConFr Conference 2014 Lyon, October 24 25

Course Overview. CSCI 480 Computer Graphics Lecture 1. Administrative Issues Modeling Animation Rendering OpenGL Programming [Angel Ch.

Instructor. Goals. Image Synthesis Examples. Applications. Computer Graphics. Why Study 3D Computer Graphics?

How To Teach Computer Graphics

My Materials. In this tutorial, we ll examine the material settings for some simple common materials used in modeling.

Quick Tutorial. Overview. The NVIDIA Software Improvement Program. Creating an Effect

Self-Positioning Handheld 3D Scanner

CAUSTICS are complex patterns of shimmering

Math for Game Programmers: Dual Numbers. Gino van den Bergen

Transcription:

OpenGL ES 2.0 Lighting 2 Per-fragment Lighting CS421 Advanced Computer Graphics Jay Urbain, Ph.D. 1

Objectives Per-fragment lighting Foundation for Phong Model, textures, etc. Shader implementation in OpenGL ES 2.0 References: Fallout Software: OpenGL Lighting or How Light Sources Work (Long, In-depth Tutorial) Clockworkcoders Tutorials: Per Fragment Lighting Lighthouse3D.com: The Normal Matrix arcsynthesis.org: OpenGL Tutorials: Normal Transformation OpenGL Programming Guide: Chapter 5 Lighting OpenGL ES 2.0 Programming Guide http://www.learnopengles.com 2

Per-vertex lighting Front face of cube appears flatshaded. No evidence of a light nearby. Why? The four points of the front face are (approximately) equidistant from the light. Low light intensity at each of the four points is interpolated (smoothed) across the two triangles that make up the front face. 3

Per-pixel vs. Per-fragment Lighting Per vertex lighting Per fragment lighting The per-fragment version shows a nice highlight 4 in comparison.

Lighting Techniques Per-vertex: smooth shading (Gouraud shading). Lightmaps: Can give very nice results. Expensive light calculations are typically pre-computed. Downside: they take up a lot of memory, and doing dynamic lighting is limited to simple calculations. Shaders: Calculations can be offloaded to the GPU. Allows for many more effects to be done in real-time. Per-fragment lighting: relatively new phenomenon with the advent of shaders. 5

Per-pixel vs. Per-fragment Lighting Vertex (Gouraud) shaded cube Vertex shading: As light source moves near the corner of the front face of the cube, a triangle-like effect can be seen. Front face is composed of two triangles. As the values are interpolated in different directions across each triangle we can see the underlying geometry. Fragment shading: Shows no signs of interpolation errors, nice circular highlight near the edge. Fragment shaded cube 6

Vertex Shader Lighting uniform mat4 u_mvpmatrix; // model/view/projection matrix. uniform mat4 u_mvmatrix; // model/view matrix. attribute vec4 a_position; // Per-vertex position information we will pass in. attribute vec4 a_color; // Per-vertex color information we will pass in. attribute vec3 a_normal; // Per-vertex normal information we will pass in. 7

Vertex Shader Lighting (cont.) void main() { } // Transform the vertex & normal into eye space. vec3 modelviewvertex = vec3(u_mvmatrix * a_position); vec3 modelviewnormal = vec3(u_mvmatrix * vec4(a_normal, 0.0)); // Used for attenuation. float distance = length(u_lightpos - modelviewvertex); // Lighting direction vector from the light to the vertex. vec3 lightvector = normalize(u_lightpos - modelviewvertex); // Dot product of the light vector and vertex normal. float diffuse = max(dot(modelviewnormal, lightvector), 0.1); // Attenuate the light based on distance. diffuse = diffuse *(1.0/(1.0 + (0.1* distance * distance))); // Multiply color by the illumination level. Interpolated across the triangle. v_color = a_color * diffuse; // gl_position is a special variable used to store the final position. gl_position = u_mvpmatrix * a_position; 8

Vertex Shader after Moving Lighting Code to Fragment Shader uniform mat4 u_mvpmatrix; // Combined model/view/projection matrix. uniform mat4 u_mvmatrix; // Combined model/view matrix. attribute vec4 a_position; // Per-vertex position information we will pass in. attribute vec4 a_color; // Per-vertex color information we will pass in. attribute vec3 a_normal; // Per-vertex normal information we will pass in. varying vec3 v_position; varying vec4 v_color; varying vec3 v_normal; // Passed into the fragment shader. // Passed into the fragment shader. // Passed into the fragment shader. 9

Lighting -Vertex Shader (cont.) void main() { // Transform the vertex into eye space. v_position = vec3(u_mvmatrix* a_position); // Pass through the color. v_color = a_color; // Transform the normal's orientation into eye space. v_normal = vec3(u_mvmatrix* vec4(a_normal, 0.0)); // gl_position is used to store the final position. // Multiply vertex by the matrix to get final point in normalized screen coordinates. gl_position = u_mvpmatrix* a_position; } 10

Fragment Shader precision mediump float; // Set default precision uniform vec3 u_lightpos; // Position of the light in eye space. varying vec3 v_position; varying vec4 v_color; varying vec3 v_normal; // Interpolated position for this fragment. // Color from the vertex shader interpolated across the // triangle per fragment. // Interpolated normal for this fragment. 11

Fragment Shader (cont.) void main() { // Used for attenuation. float distance = length(u_lightpos- v_position); // Get a lighting direction vector from the light to the vertex. vec3 lightvector = normalize(u_lightpos- v_position); // Dot product of the light vector and vertex normal. float diffuse = max(dot(v_normal, lightvector), 0.1); // Add attenuation. diffuse = diffuse * (1.0 / (1.0 + (0.1 * distance * distance))); } // Multiply the color by the diffuse illumination level to get final output color. gl_fragcolor = v_color* diffuse; 12