In-Game Special Effects and Lighting

Similar documents
Vertex and Pixel Shaders:

Interactive Cloth Simulation. Matthias Wloka NVIDIA Corporation

Project6 Lighting per-pixel shading and optimizations for Direct3D 8

Tutorial on GPU Programming #2. Joong-Youn Lee Supercomputing Center, KISTI

Canonical Shaders for Optimal Performance. Sébastien Dominé Manager of Developer Technology Tools

Deferred Rendering Due: Wednesday November 15 at 10pm

Optimal Shaders Using High-Level Languages

Surface Detail Maps with Soft Self- Shadowing. Chris Green, VALVE

AGDC Per-Pixel Shading. Sim Dietrich

Rippling Reflective and Refractive Water

3D buzzwords. Adding programmability to the pipeline 6/7/16. Bandwidth Gravity of modern computer systems

Computer Graphics (CS 543) Lecture 10: Soft Shadows (Maps and Volumes), Normal and Bump Mapping

Technical Report. Mesh Instancing

Technical Report. Anisotropic Lighting using HLSL

lecture 18 - ray tracing - environment mapping - refraction

Real-Time Universal Capture Facial Animation with GPU Skin Rendering

Real Time Skin Rendering

Programmable Graphics Hardware

Lighting and Shading

The Graphics Pipeline

Windowing System on a 3D Pipeline. February 2005

Real - Time Rendering. Pipeline optimization. Michal Červeňanský Juraj Starinský

Computer Graphics (CS 543) Lecture 10: Normal Maps, Parametrization, Tone Mapping

Render-To-Texture Caching. D. Sim Dietrich Jr.

Chapter 2 A top-down approach - How to make shaded images?

Drawing a Crowd. David Gosselin Pedro V. Sander Jason L. Mitchell. 3D Application Research Group ATI Research

Special Effects with DirectX 9

A Conceptual and Practical Look into Spherical Curvilinear Projection By Danny Oros

Chapter 3 ATI. Jason L. Mitchell

Shadow Techniques. Sim Dietrich NVIDIA Corporation

Introduction to Programmable GPUs CPSC 314. Real Time Graphics

Programming Graphics Hardware

Real Time Skin Rendering

CS 354R: Computer Game Technology

The Application Stage. The Game Loop, Resource Management and Renderer Design

CS Computer Graphics: Introduction to Ray Tracing

CS Computer Graphics: Introduction to Ray Tracing

Hardware-Assisted Relief Texture Mapping

Graphics Processing Unit Architecture (GPU Arch)

Lab 9 - Metal and Glass

LEVEL 1 ANIMATION ACADEMY2010

Applications of Explicit Early-Z Z Culling. Jason Mitchell ATI Research

RSX Best Practices. Mark Cerny, Cerny Games David Simpson, Naughty Dog Jon Olick, Naughty Dog

CS 130 Final. Fall 2015

Computergrafik. Matthias Zwicker. Herbst 2010

GUERRILLA DEVELOP CONFERENCE JULY 07 BRIGHTON

Dynamic Ambient Occlusion and Indirect Lighting. Michael Bunnell NVIDIA Corporation

How to Work on Next Gen Effects Now: Bridging DX10 and DX9. Guennadi Riguer ATI Technologies

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

Relief Mapping in a Pixel Shader using Binary Search Policarpo, Fabio

Introduction to Programmable GPUs CPSC 314. Introduction to GPU Programming CS314 Gordon Wetzstein, 09/03/09

MAXIS-mizing Darkspore*: A Case Study of Graphic Analysis and Optimizations in Maxis Deferred Renderer

Self-shadowing Bumpmap using 3D Texture Hardware

Introduction to 3D Graphics

Spring 2009 Prof. Hyesoon Kim

Mattan Erez. The University of Texas at Austin

Basics of GPU-Based Programming

Introduction to Visualization and Computer Graphics

Spring 2011 Prof. Hyesoon Kim

White Paper. Texture Arrays Terrain Rendering. February 2007 WP _v01

Recollection. Models Pixels. Model transformation Viewport transformation Clipping Rasterization Texturing + Lights & shadows

Point Lighting Using Shaders

Textures. Texture coordinates. Introduce one more component to geometry

Optimizing DirectX Graphics. Richard Huddy European Developer Relations Manager

CS451Real-time Rendering Pipeline

Graphics Performance Optimisation. John Spitzer Director of European Developer Technology

Enabling immersive gaming experiences Intro to Ray Tracing

Building scalable 3D applications. Ville Miettinen Hybrid Graphics

CS 450: COMPUTER GRAPHICS TEXTURE MAPPING SPRING 2015 DR. MICHAEL J. REALE

Real-Time Rendering of a Scene With Many Pedestrians

Evolution of GPUs Chris Seitz

Last Time. Why are Shadows Important? Today. Graphics Pipeline. Clipping. Rasterization. Why are Shadows Important?

Today. Rendering algorithms. Rendering algorithms. Images. Images. Rendering Algorithms. Course overview Organization Introduction to ray tracing

CMSC427 Final Practice v2 Fall 2017

Chapter 17: The Truth about Normals

Pipeline Operations. CS 4620 Lecture 10

Underwater Manager (Optional)

Graphics Hardware. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 2/26/07 1

DX10, Batching, and Performance Considerations. Bryan Dudash NVIDIA Developer Technology

Whiz-Bang Graphics and Media Performance for Java Platform, Micro Edition (JavaME)

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

Parallax Bumpmapping. Whitepaper

CS GPU and GPGPU Programming Lecture 3: GPU Architecture 2. Markus Hadwiger, KAUST

For Intuition about Scene Lighting. Today. Limitations of Planar Shadows. Cast Shadows on Planar Surfaces. Shadow/View Duality.

A Real-Time Procedural Shading System for Programmable Graphics Hardware

Optimizing and Profiling Unity Games for Mobile Platforms. Angelo Theodorou Senior Software Engineer, MPG Gamelab 2014, 25 th -27 th June

Easy Decal Version Easy Decal. Operation Manual. &u - Assets

Tutorial on GPU Programming. Joong-Youn Lee Supercomputing Center, KISTI

Texturing Theory. Overview. All it takes is for the rendered image to look right. -Jim Blinn 11/10/2018

Advanced Lighting Techniques Due: Monday November 2 at 10pm

Surface Rendering. Surface Rendering

CS GPU and GPGPU Programming Lecture 3: GPU Architecture 2. Markus Hadwiger, KAUST

Soft Particles. Tristan Lorach

Advanced Shading and Texturing

CS GAME PROGRAMMING Question bank

Graphics Hardware. Instructor Stephen J. Guy

Where Is That Instruction? How To Implement Missing Vertex Shader Instructions

CSE528 Computer Graphics: Theory, Algorithms, and Applications

What for? Shadows tell us about the relative locations. Vienna University of Technology 2

Assignment 6: Ray Tracing

Transcription:

In-Game Special Effects and Lighting

Introduction! Tomas Arce! Special Thanks! Matthias Wloka! Craig Galley! Stephen Broumley! Cryrus Lum! Sumie Arce! Inevitable! nvidia! Bungy

What Is Per-Pixel Pixel Lighting 1 of 2! Bad name! Texel-lighting lighting is more accurate! Texture resolution matters -- tiling helps! Complex operation done per-pixel pixel basis! Texture lookups, dp3, and pixel shaders! Use colors as data

What Is Per-Pixel Pixel Lighting 2 of 2! Encode pixel-normals in texture, fill RGB as: R=Normal.X, G=Normal.Y, B=Normal.Z! Light dir is also encoded, fill vertex color as: R=LightDir.X LightDir.X,, G = LightDir.Y,, B = LightDir.Z! Now we can do: ( Texture.Texel ) dot ( Vertex.Color )

Why Is Per-Pixel Pixel Better? 1 of 3! Per-vertex light is faster and more flexible but lacks resolution! Light-maps have pit-falls! No real specular! Low resolution! Doesn t t work for dynamic objects! Projected textures don t t give much detail for the surface

Why Is Per-Pixel Pixel Better? 2 of 3! Detail. Detail. Detail.! pplighting needs few polygons per-mesh! Simplifies collision, stencil shadows, and memory! Bump mapping is a subset of the pplighting! Normal maps! Normal maps handle different types of lights and surfaces well

Why Is Per-Pixel Pixel Better? 3 of 3

How to Store Normals in Texels 1 of 3! What space?! Local-Space vs Texture Space! Local Space Normals (LS)! Use the origin of the object to extract normals! Texture Space Normals (TS)! Store normals in generic space, e.g., Tangent Space! Store a matrix per vertex that takes the light from local- space to texture space

How to Store Normals in Texels 2 of 3 Local Space Texture Space

How to Store Normals in Texels 3 of 3! LS is simple to work with and can be very fast! But cannot be compressed! Good for characters and objects such as cars! TS is more complex to work with but has 2 advantages! Tileable maps! Palletized textures! Good for big things like terrain with detail textures

Different Types of Lights 1 of 2! 3 typical light types! Directional! Point! Spot! Point and spot lighting usually have attenuation coefficients! Store spot lighting attenuation function in a texture! X is a function of the distance! Y is a function of the angle The dot-product direction of the light with the vertex

Different Types of Lights 2 of 2! Implementing attenuation function (1/(k1+d*k2 +d*d*k3) ) directly in the vertex shader! Takes few instructions, but has issues going towards zero! Light vector normalization is usually not needed but! Use cube-map lookup (32x32 or so)! Or use Newton-Raphson approximation in pixel-shader shader: mul r0, LightDir,, 0.5 dp3 r1, LightDir, LightDir mad r0, 1-r1, 1 r0, LightDir

LS vs TS Standard Comparison 1 of 3 ; LS Directional Light ; Transform position to clip space and output it dp4 opos.x,, V_POSITION, c[cv_worldviewproj_0] dp4 opos.y,, V_POSITION, c[cv_worldviewproj_1] dp4 opos.z,, V_POSITION, c[cv_worldviewproj_2] dp4 opos.w,, V_POSITION, c[cv_worldviewproj_3] ; Output tex coords mov ot0, V_TEXTURE mov ot1, V_TEXTURE

LS vs TS Standard Comparison 2 of 3 ; TS Directional Light ; Transform position to clip space and output it dp4 opos.x,, V_POSITION, c[cv_worldviewproj_0] dp4 opos.y,, V_POSITION, c[cv_worldviewproj_1] dp4 opos.z,, V_POSITION, c[cv_worldviewproj_2] dp4 opos.w,, V_POSITION, c[cv_worldviewproj_3] ; Transform local space light by basis vectors to put it ; into texture space dp3 LIGHT_T.x, V_S, c[l_dir_local] dp3 LIGHT_T.y, V_T, c[l_dir_local] dp3 LIGHT_T.z, V_Q, c[l_dir_local] ; Scale to 0-10 add LIGHT_T, LIGHT_T, c[cv_one] mul od0, LIGHT_T, c[cv_half] ; Output tex coords mov ot0, V_TEXTURE mov ot1, V_TEXTURE

LS vs TS Standard Comparison 3 of 3! This example is mostly for rigid geometry! Optimized TS: 11 instructions! Optimizes LS: 6 instructions! Note that the LS could do up to 5 lights! All light directions in local space are loaded into the pixel-shader constants! The TS uses light direction in local space! Faster than transforming the basis vectors

LS vs TS Soft-Skin Skin

LS vs TS Soft-Skin Skin ( L.S. ) 1 of 7 // Transform pos with Weight 1 mov a0.x, V_INDICES.x dp4 r1.x, V_POSITION, c[a0.x + CV_BONESTART + 0] dp4 r1.y, V_POSITION, c[a0.x + CV_BONESTART + 1] dp4 r1.z, V_POSITION, c[a0.x + CV_BONESTART + 2] // Weight the light part 1 mul r7, c[a0.x + CV_LDIR_LOCALSPACE], V_WEIGHT0.x // Transform pos with Weight 2 mov a0.x, V_INDICES.y dp4 r2.x, V_POSITION, c[a0.x + CV_BONESTART + 0] dp4 r2.y, V_POSITION, c[a0.x + CV_BONESTART + 1] dp4 r2.z, V_POSITION, c[a0.x + CV_BONESTART + 2] // Weight the 2 part of the light mad r8, c[a0.x + CV_LDIR_LOCALSPACE], V_WEIGHT1.x, r7

LS vs TS Soft-Skin Skin ( L.S. ) 2 of 7 // Blend between r1 and r2 mul r1.xyz, r1.xyz, V_WEIGHT0.x mad r2, r2.xyz, V_WEIGHT1.x, r1.xyz mov r2.w, c[cv_constants].z //set w to one // r2 now contains final position ; Do the texture compression by multiplying ; 1 or 11 as needed mul r1.x, r1.x, V_MIRROR_FLAG // Normalize light vector dp3 r1.w, r1, r1 rsq r1.w, r1.w mul r1, r1, r1.w

LS vs TS Soft-Skin Skin ( L.S. ) 3 of 7 // Transform to clip space dp4 opos.x,, r2, c[cv_worldviewproj_0] dp4 opos.y,, r2, c[cv_worldviewproj_1] dp4 opos.z,, r2, c[cv_worldviewproj_2] dp4 opos.w,, r2, c[cv_worldviewproj_3] // Scale to 0-10 // [-1,[ 1] --> > [0, 1] add r1, r1, c[cv_constants].z mul od0, r1, c[cv_constants].y // Pass through texcoords mov ot0.xy, V_TEX mov ot1.xy, V_TEX

LS vs TS Soft-Skin Skin ( T.S. ) 4 of 7 // Transform pos with Weight 1 mov a0.x, V_INDICES.x dp4 r1.x, V_POSITION, c[a0.x + CV_BONESTART + 0] dp4 r1.y, V_POSITION, c[a0.x + CV_BONESTART + 1] dp4 r1.z, V_POSITION, c[a0.x + CV_BONESTART + 2] // Transform the light from the bone local space to the TS dp3 r7.x, V_S, c[a0.x + CV_LDIR_LOCALSPACE] dp3 r7.y, V_T, c[a0.x + CV_LDIR_LOCALSPACE] dp3 r7.z, V_SxT,, c[a0.x + CV_LDIR_LOCALSPACE] // Transform pos with Weight 2 mov a0.x, V_INDICES.y dp4 r2.x, V_POSITION, c[a0.x + CV_BONESTART + 0] dp4 r2.y, V_POSITION, c[a0.x + CV_BONESTART + 1] dp4 r2.z, V_POSITION, c[a0.x + CV_BONESTART + 2]

LS vs TS Soft-Skin Skin ( T.S. ) 5 of 7 // Transform the light from the bone local space to the // texture space dp3 r8.x, V_S, c[a0.x + CV_LDIR_LOCALSPACE] dp3 r8.y, V_T, c[a0.x + CV_LDIR_LOCALSPACE] dp3 r8.z, V_SXT, c[a0.x + CV_LDIR_LOCALSPACE] // Blend between r1 and r2, r2 now contains final position mul r1.xyz, r1.xyz, V_WEIGHT0.x mad r2, r2.xyz, V_WEIGHT1.x, r1.xyz mov r2.w, c[cv_constants].z // set w to one // Blend the light mul r7, r7.xyz, V_WEIGHT0.x mad r8, r8.xyz, V_WEIGHT1.x, r7 // Normalize light vector dp3 r1.w, r1, r1 rsq r1.w, r1.w mul r1, r1, r1.w

LS vs TS Soft-Skin Skin ( T.S. ) 6 of 7 // Transform to clip space dp4 opos.x,, r2, c[cv_worldviewproj_0] dp4 opos.y,, r2, c[cv_worldviewproj_1] dp4 opos.z,, r2, c[cv_worldviewproj_2] dp4 opos.w,, r2, c[cv_worldviewproj_3] // [-1,[ 1] --> > [0, 1] add r1, r1, c[cv_constants].z mul od0, r1, c[cv_constants].y // Pass through texcoords mov ot0.xy, V_TEX mov ot1.xy, V_TEX

LS vs TS Soft-Skin Skin 7 of 7! Optimized LS: 25 instructions! Optimized TS: 30 instructions! Skinning the light direction is as good as skinning a normal! The LS technique works well for characters! Unique pixel per polygon and symmetrical! Passing the light in the local space for each bone for the TS is a good idea! Standard TS technique is about 50 instructions

LS vs TS Soft-Skin Skin 8 of 8! Evolution demo shader is 42 instructions! Vertex-shader was the first bottle neck that we hit! Geforce3 Ti500 runs a 240Mhz! 1 clock per instruction = 240M instruction/sec! @ 60fps is 4M so 4M/25 = 160K Peak! The Geforce4 can do 600M instruction/sec! Step in the right direction

Working with Shaders 1 of 4! 1 to n lights and different types of lights! Compile and cache vertex/pixel shaders on the fly! Layout code so they can be combined! DoomIII does 1 light per pass! Geforce3 has max. 8 instructions in the pixel-shader! But can use an off-screen texture as a temporary register! Then project texture in consequent passes! Allows for unlimited length of pixel shaders (with extra cost of course)

Working with Shaders 2 of 4! Anisotropic textures are a good way to do complex lighting equations based on the specular and diffuse angles

Working with Shaders 3 of 4! Use UVs to set the lightdir and half-vector! Then use texm3x2pad and texm3x2tex to compute the look up UVs! Pre-scale the lightdir and the half-vector by 0.5 to get the full range 11 to 1 of the light equation! Useful for back-lighting! Be creative with your lighting equation! Diffuse + Specular pretty much sucks! Try: Diffuse + X * Specular * Diffuse

Working with Shaders 4 of 4! Use multiple layers to achieve complex lighting! Evolution demo had 3: Diffuse, Anisotropic, and ppspecular! Make sure to use all channels in your textures! Don t t forget about the alpha channel! Compress textures (DXT1, DXT3)! Post-Effects are becoming part of the shading technology; don t t miss that (check out Wreckless)

Wreckless Nice job guys!

Shadows 1 of 3! Two main techniques projected textures (nvidia/ati/plain) and stencil volumes! Projected textures are easier to implement! Self-shadow! Can do 4 lights/shadows at a time! But can only do spot and directional lights! Hint: try to use orthogonal projections! Do per-object projected textures

Shadows 2 of 3! Stencils are a more generic solution! But fill rate is an issue! Worth looking at! SVBSP and order tree structures! As well as Cut and Continue type of techniques! Make sure to cache shadow volumes! For perfect lighting, use stencil to not write lit pixels! vs darkening them

Shadows 3 of 3 Massive over-draw!

The Future 1 of 2! In the near future new versions of vertex/pixel shaders will make another big leap! Expect to see lighting independent of geometry complexity, and a final generalized lighting solution! Shadows will still be a thing to try to achieve efficiently! Although it may be helped via fill-rate increases etc.! Post-effects will be very important as they start to became part of the final shader render

The Future 2 of 2 We still live in very exciting times, but it would be more exciting if they do a real time ray-tracer!