Point Lighting Using Shaders Game Design Experience Professor Jim Whitehead March 13, 2009 Creative Commons Attribution 3.0 (Except copyrighted images.

Slides:



Advertisements
Similar presentations
16.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 16 – Some Special Rendering Effects.
Advertisements

Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
1 Graphics CSCI 343, Fall 2013 Lecture 18 Lighting and Shading.
SE 313 – Computer Graphics Lecture 13: Lighting and Materials Practice Lecturer: Gazihan Alankuş 1.
Lecture 23: Photometric Stereo CS4670/5760: Computer Vision Kavita Bala Scott Wehrwein.
Introduction to Shader Programming
Particle Systems Final Exam Study Guide Game Design Experience Professor Jim Whitehead March 16, 2009 Creative Commons Attribution 3.0 (Except copyrighted.
Simple 3D Camera Game Design Experience Professor Jim Whitehead March 6, 2009 Creative Commons Attribution 3.0 (Except copyrighted images) creativecommons.org/licenses/by/3.0.
Introduction to 3D in XNA Game Design Experience Professor Jim Whitehead February 27, 2009 Creative Commons Attribution 3.0 creativecommons.org/licenses/by/3.0.
Triangles, Translations Game Design Experience Professor Jim Whitehead March 2, 2009 Creative Commons Attribution 3.0 (Except copyrighted images) creativecommons.org/licenses/by/3.0.
Graphics Systems I-Chen Lin’s CG slides, Doug James’s CG slides Angel, Interactive Computer Graphics, Chap 1 Introduction to Graphics Pipeline.
MSU CSE 803 Fall 2008 Stockman1 CV: 3D sensing and calibration Coordinate system changes; perspective transformation; Stereo and structured light.
Computer Science – Game DesignUC Santa Cruz Adapted from Jim Whitehead’s slides Shaders Feb 18, 2011 Creative Commons Attribution 3.0 (Except copyrighted.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Beyond Meshes Spring 2012.
SET09115 Intro Graphics Programming
Lecture 5: 3D Rendering Pipeline (II) Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Institute of Technology.
COMP 261 Lecture 14 3D Graphics 2 of 2. Doing better than 3x3? Translation, scaling, rotation are different. Awkward to combine them. Use homogeneous.
University of Illinois at Chicago Electronic Visualization Laboratory (EVL) CS 426 Intro to 3D Computer Graphics © 2003, 2004, 2005 Jason Leigh Electronic.
Modelling and Simulation Types of Texture Mapping.
COMP 175: Computer Graphics March 24, 2015
GPU Programming Robert Hero Quick Overview (The Old Way) Graphics cards process Triangles Graphics cards process Triangles Quads.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
CSE 381 – Advanced Game Programming Basic 3D Graphics
Rujchai Ung-arunyawee Department of Computer Engineering Khon Kaen University.
Week 2 - Wednesday CS361.
09/09/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Event management Lag Group assignment has happened, like it or not.
TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain 
Computer Graphics Using Direct 3D Introduction. 2 What are we doing here? Simply, learning how to make the computer draw.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
Advanced Computer Graphics Advanced Shaders CO2409 Computer Graphics Week 16.
CSE 381 – Advanced Game Programming GLSL Lighting.
Game Programming 06 The Rendering Engine
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
Lighting Review & Example Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 17, 2003.
Realtime NPR Toon and Pencil Shading Joel Jorgensen May 4, 2010.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Games Development 2 Entity Update & Rendering CO3301 Week 2, Part 1.
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
Vertices, Edges and Faces By Jordan Diamond. Vertices In geometry, a vertices is a special kind of point which describes the corners or intersections.
RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program.
Lighting a 3D Scene Guilford County Sci Vis V part 1.
Local Illumination and Shading
Day 06 Vertex Shader for Ambient-Diffuse-Specular Lighting.
Computer Graphics Matrices
Current Student – University of Wisconsin – Stout Applied Mathematics and Computer Science: Software Development Associate Degree in Computer Programming.
Written by: Itzik Ben Shabat Technion - Israel Institute of Technology Faculty of Mechanical Engineering Laboratory for CAD & Lifecycle Engineering Lab.
Lighting and Reflection Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Computer Graphics Lecture 30 Mathematics of Lighting and Shading - IV Taqdees A. Siddiqi
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
Computer Graphics: Illumination
Chapter 5. Lighting Computer Graphics (spring, 2009) School of Computer Science University of Seoul.
Introduction to Computer Graphics
Tessellation Shaders.
Implementing Phong Lighting
Geometry Objectives 6 – 8 Part 1
2.2: Translations.
Shaders, part 2 alexandri zavodny.
© University of Wisconsin, CS559 Spring 2004
Tips for Shading Your Terrain
CS451Real-time Rendering Pipeline
Lighting.
Computer Animation Texture Mapping.
UMBC Graphics for Games
Chapter IX Lighting.
Computer Graphics 4Practical Lesson
Game Programming Algorithms and Techniques
Computer Graphics Material Colours and Lighting
03 | Creating, Texturing and Moving Objects
Computer Graphics Shading in OpenGL
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

Point Lighting Using Shaders Game Design Experience Professor Jim Whitehead March 13, 2009 Creative Commons Attribution 3.0 (Except copyrighted images and example Shader) creativecommons.org/licenses/by/3.0

Announcements Days until Final Project Due: 3 ► Due Monday, March 16 ► Can turn in game until 5pm Monday ► Few students have been attending help sessions ► We will not be able to help you as well at the last minute ► Help sessions Friday –5:00PM - 8:45PM, Oakes 101 Sunday –8pm – 1am(ish), BE 105 (Unix lab) Post question to forum Don’t let yourself stay stuck for too long. 1-2 hours max!

Pop Quiz Ungraded – test your knowledge of key concepts ► Similar to questions that will appear on final What does the world matrix represent? What does multiplying world * view * projection do? What are the two main types of shaders? What do they do? What is a normal vector? What is a normalized vector? To make a scene brighter, perform what operation on color values? What are texture coordinates?

Pop Quiz Answers What does the world matrix represent? ► The transformation of a model’s coordinates into world coordinates What does multiplying world * view * projection do? ► Transforms model coords into world coords, then applies camera What are the two main types of shaders? What do they primarily do? ► Vertex shader, pixel shader ► Vertex shader: mostly changes vertex locations ► Pixel shader: mostly changes pixel color values What is a normal vector? What is a normalized vector? ► Normal vector: A vector pointing in the direction perpendicular to a surface ► Normalized vector: one where all values lie between 0 and 1 To make a scene brighter, perform what operation on color values? ► Increase color values What are texture coordinates? ► Also known as u,v coordinates, they are fractions of the distance between upper left and lower right corners of a bitmap image

Lighting In games, often want to have parts of a scene that are more lit than other parts ► Helps create the mood of a scene Dark and mysterious, bright and cheerful ► Increase realism Streetlights are brighter under the light Lighting is a complex subject ► Many ways to create lights, shadows ► Physical materials interact with light in different ways ► Dull surface, shiny surface, skin: all different

Ambient Light Ambient light ► When a scene has a uniform level of lighting ► All surfaces of all objects have the same amount of light In code ► Brighter lighting RGB values that are closer to 1 As lights get brighter, everything seems more and more white ► Dimmer lighting RGB values that are closer to 0 As lights get dimmer, everything seems more dark Ambient light is not very realistic

Point Light Represents lights that are similar to a bare light bulb Light radiates uniformly in all directions Light modeled with a location (lightPos) and an intensity (xPower, values between 0 and 3 work well)

Point lighting on a model To determine point lighting on a model ► Determine lightDir vector Direction from point light to location on surface of model –lightDir = inPos – lightPos –Normalize to make next step easier ► Compute angle between lightDir and surface normal This gives the percentage of the light’s value to apply to surface Determine using dot product –a dot b = |a||b| cos (angle) –If a & b are normalized, a dot b is cos(angle) –Cos(0) = 1, Cos(pi/2) = 0 –If light overhead (angle = 0), get full intensity –If light parallel to surface, get no lighting lightPos lightDir Surface Normal inPos (current vertex in model) angle

Point lighting on a model (cont’d) Compute final color as follows ► Calculate a base color Grab a color value from a texture by applying texture coordinates Or, apply a uniform base color ► Compute the fraction of the light’s intensity that reaches model Model intensity = light intensity (xPower) * cos(angle) ► Add the ambient light and the light from the point light to the base color Final color = base color * (model intensity + ambient)

Some important details To compute lighting, Vertex shader needs normal vectors as input ► Normals come into the Shader via the NORMAL0 semantic ► These need to be supplied from C#/XNA, since they are part of the model ► This occurs by default if you draw meshes mesh.Draw sends normal information ► If drawing triangles, need to tell XNA to send normal information Do this by using the VertexPositionNormalTexture class to define vertices of triangles –Each point has (x,y,z) position, (x,y,z) normal, and (u,v) texture coordinate Then, must – GraphicsDevice.VertexDeclaration = new VertexDeclaration(GraphicsDevice, VertexPositionNormalTexture.VertexElements); –This determines the kind of input data that is passed to the vertex shader

Using your own shader with a mesh By default, each part of a mesh has a shader associated with it ► Each ModelMeshPart has an associated Effect ► An Effect is a shader To use your own shader, need to replace model effects with your own for (int i = 0; i < mesh.MeshParts.Count; i++) { // Set this MeshParts effect to // our pixel lighting effect mesh.MeshParts[i].Effect = effect; } Overrides effects present in model originally Model ModelMesh 1 N Bone 1 N ModelMeshPart Effect 1 N 1 N VertexBuffer 1 1 Verticies 1 N Effect 1 1 StartIndex NumVerticies PrimitiveCount

Example point shader in XNA Example of a point shader C#/XNA Demonstrated shader from ► s3/Per-pixel_lighting.php