1. Trang chủ
  2. » Công Nghệ Thông Tin

Giáo trình thực tại ảo BKHN Ánh sáng – Light Kỹ thuật tạo bóng Render

70 283 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 70
Dung lượng 1,15 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Definitions  Illumination: the transport of energy in particular, the luminous flux of visible light from light sources to surfaces & points – Note: includes direct and indirect illumi

Trang 1

Ánh sáng – Light

K ỹ thuật tạo bóng - Render

Trang 2

Lighting

 So…given a 3-D triangle and a 3-D viewpoint,

we can set the right pixels

 But what color should those pixels be?

 If we’re attempting to create a realistic image,

we need to simulate the lighting of the surfaces

in the scene

– Fundamentally simulation of physics and optics

– As you’ll see, we use a lot of approximations (a.k.a hacks) to do this simulation fast enough

Trang 3

Definitions

Illumination: the transport of energy (in

particular, the luminous flux of visible light) from light sources to surfaces & points

– Note: includes direct and indirect illumination

Lighting: the process of computing the luminous

intensity (i.e., outgoing light) at a particular 3-D point, usually on a surface

Shading: the process of assigning colors to

pixels

Trang 4

Definitions

 Illumination models fall into two categories:

Empirical: simple formulations that approximate

observed phenomenon

Physically-based: models based on the actual

physics of light interacting with matter

 We mostly use empirical models in interactive graphics for simplicity

 Increasingly, realistic graphics are using

physically-based models

Trang 5

Components of Illumination

 Two components of illumination: light sources and surface properties

 Light sources (or emitters)

– Spectrum of emittance (i.e, color of the light)

– Geometric attributes

 Position

 Direction

 Shape – Directional attenuation

Trang 6

Lights

 Infinitely distant point light

creates parallel rays

– Constant direction across field

of view

– No radiant energy drop-off

 Local light sources

Trang 7

 Common simplifications in interactive graphics

– Only direct illumination from emitters to surfaces

– Simplify geometry of emitters to trivial cases

Trang 8

Ambient Light Sources

 Objects not directly lit are typically still visible

– E.g., the ceiling in this room, undersides of desks

 This is the result of indirect illumination from

emitters, bouncing off intermediate surfaces

 Too expensive to calculate (in real time), so we use a hack called an ambient light source

– No spatial or directional characteristics; illuminates all surfaces equally

– Amount reflected depends on surface properties

Trang 9

Ambient Light Sources

 For each sampled wavelength, the ambient light reflected from a surface depends on

– The surface properties

– The intensity of the ambient light source (constant for all points on all surfaces )

I reflected = k ambient I ambient

Trang 10

Ambient Light Sources

 A scene lit only with an ambient light source:

Trang 11

Directional Light Sources

 For a directional light source we make the

simplifying assumption that all rays of light from the source are parallel

– As if the source is infinitely far away

from the surfaces in the scene

– A good approximation to sunlight

 The direction from a surface to the light source is important in lighting the surface

 With a directional light source, this direction is

constant for all surfaces in the scene

Trang 12

Directional Light Sources

 The same scene lit with a directional and an ambient light source (animated gif)

Trang 13

Point Light Sources

 A point light source emits light equally in all directions from a single point

 The direction to the light from a point on a surface thus differs for different points:

– So we need to calculate a

normalized vector to the light

source for every point we light:

l p

Trang 14

Point Light Sources

 Using an ambient and

a point light source:

How can we tell the

difference between a

point light source and

a directional light

source on a sphere?

Trang 15

Other Light Sources

Spotlights are point sources whose intensity falls off directionally

– Supported by OpenGL

Area light sources define a 2-D emissive surface (usually a disc or polygon)

– Good example: fluorescent light panels

– Capable of generating soft shadows (why?)

Trang 16

The Physics of Reflection

 Ideal diffuse reflection

– An ideal diffuse reflector, at the microscopic level,

is a very rough surface (real-world example: chalk)

– Because of these microscopic variations, an

incoming ray of light is equally likely to be reflected

in any direction over the hemisphere:

What does the reflected intensity depend on?

Trang 17

Lambert’s Cosine Law

 Ideal diffuse surfaces reflect according to

Lambert’s cosine law:

The energy reflected by a small portion of a surface from a light source in a given direction is proportional

to the cosine of the angle between that direction and the surface normal

 These are often called Lambertian surfaces

 Note that the reflected intensity is independent of the viewing direction, but does depend on the

surface orientation with regard to the light source

Trang 18

Lambert’s Law

Trang 19

Computing Diffuse Reflection

 The angle between the surface normal and the incoming light is the angle of incidence:

I diffuse = k d I light cos

 In practice we use vector arithmetic:

I diffuse = k d I light ( n • l)

n

l

Trang 20

Diffuse Lighting Examples

 We need only consider angles from 0° to 90° (Why?)

 A Lambertian sphere seen at several different lighting angles:

 An animated gif

Trang 21

Specular Reflection

 Shiny surfaces exhibit specular reflection

– Polished metal

– Glossy car finish

 A light shining on a specular surface causes a bright spot known as a specular highlight

 Where these highlights appear is a function of the viewer’s position, so specular reflectance is view-dependent

Trang 22

The Physics of Reflection

 At the microscopic level a specular reflecting

surface is very smooth

 Thus rays of light are likely to bounce off the

microgeometry in a mirror-like fashion

 The smoother the surface, the closer it becomes

to a perfect mirror

– Polishing metal example (draw it)

Trang 23

The Optics of Reflection

 Reflection follows Snell’s Laws:

– The incoming ray and reflected ray lie in a plane with the surface normal

– The angle that the reflected ray forms with the surface normal equals the angle formed by the incoming ray and the surface normal:

l = r

Trang 24

Non-Ideal Specular Reflectance

 Snell’s law applies to perfect mirror-like

surfaces, but aside from mirrors (and chrome) few surfaces exhibit perfect specularity

 How can we capture the “softer” reflections of surface that are glossy rather than mirror-like?

 One option: model the microgeometry of the surface and explicitly bounce rays off of it

 Or…

Trang 25

Non-Ideal Specular Reflectance: An

Empirical Approximation

 In general, we expect most reflected light to

travel in direction predicted by Snell’s Law

 But because of microscopic surface variations, some light may be reflected in a direction slightly off the ideal reflected ray

 As the angle from the ideal reflected ray

increases, we expect less light to be reflected

Trang 26

Non-Ideal Specular Reflectance: An Empirical Approximation

 An illustration of this angular falloff:

 How might we model this falloff?

Trang 27

specular k I

The n shiny term is a purely

empirical constant that

varies the rate of falloff

 Though this model has no

physical basis, it works

(sort of) in practice

Trang 28

Phong Lighting: The nshiny Term

 This diagram shows how the Phong reflectance term drops off with divergence of the viewing

angle from the ideal reflected ray:

What does this term control, visually?

Trang 29

Calculating Phong Lighting

The cos term of Phong lighting can be computed

using vector arithmetic:

V is the unit vector towards the viewer

Common simplification: V is constant ( implying what? )

R is the ideal reflectance direction

An aside: we can efficiently calculate R

 n shiny

light s

Trang 30

Calculating The R Vector

 This is illustrated below:

R ˆ  ˆ  2 ˆ  ˆ ˆ

Trang 31

Phong Examples

These spheres illustrate the Phong model as L and n shiny are varied:

Trang 32

The Phong Lighting Model

 Our final empirically-motivated model for the

illumination at a surface includes ambient, difuse, and specular components:

Commonly called Phong lighting

– Note: once per light

– Note: once per color component

Do k a , k d , and k s vary with color component?

d i

ambient a

total

shiny

R V

k L

N k

I I

k I

# 1

ˆ ˆ

ˆ ˆ

Trang 33

Phong Lighting: Intensity Plots

Trang 34

Phong Lighting:

OpenGL Implementation

 The final Phong model as we studied it:

 OpenGL variations:

– Every light has an ambient component

– Surfaces can have “emissive” component to simulate glow

 Added directly to the visible reflected intensity

 Not actually a light source (does not illuminate other surfaces)

d i

ambient a

total

shiny

R V

k L

N k

I I

k I

#

1

ˆ ˆ

ˆ ˆ

Trang 35

Applying Illumination

 We now have an illumination model for a point

on a surface

 Assuming that our surface is defined as a mesh

of polygonal facets, which points should we use?

 Keep in mind:

– It’s a fairly expensive calculation

– Several possible answers, each with different

implications for the visual quality of the result

Trang 36

Applying Illumination

 With polygonal/triangular models:

– Each facet has a constant surface normal

– If the light is directional, the diffuse reflectance is

constant across the facet

If the eyepoint is infinitely far away (constant V), the

specular reflectance of a directional light is constant across the facet

Trang 37

– For point sources, the direction to light varies

across the facet

– For specular reflectance, direction to eye varies

across the facet

Trang 38

Flat Shading

 We can refine it a bit by evaluating the Phong

lighting model at each pixel of each polygon, but the result is still clearly faceted:

 To get smoother-looking surfaces

we introduce vertex normals at each

vertex

– Usually different from facet normal

– Used only for shading (as opposed to what?)

– Think of as a better approximation of the real surface that the polygons approximate (draw it)

Trang 39

Vertex Normals

 Vertex normals may be

– Provided with the model

– Computed from first principles

– Approximated by averaging the normals of the facets that share the vertex

Trang 40

Gouraud Shading

 This is the most common approach

– Perform Phong lighting at the vertices

– Linearly interpolate the resulting colors over faces

– This is what OpenGL does

 Demo at:

– http://www.cs.virginia.edu/~gfx/Courses/2000/intro.sprin g00.html/vrml/tpot.wrl

– Requires a VRML browser or plug-in (common on most browsers today)

Does this eliminate the facets?

 No: we’re still subsampling the lighting parameters (normal, view vector, light vector)

Trang 41

Phong Shading

Phong shading is not the same as Phong

lighting, though they are sometimes mixed up

– Phong lighting: the empirical model we’ve been

discussing to calculate illumination at a point on a surface

– Phong shading: linearly interpolating the surface

normal across the facet, applying the Phong lighting model at every pixel

 Same input as Gouraud shading

 Usually very smooth-looking results:

But, considerably more expensive

Trang 42

An Aside: Transforming Normals

 Irritatingly, the matrix for transforming a normal vector is not the same as the matrix for the

corresponding transformation on points

– In other words, don’t just treat normals as points:

Trang 43

Transforming Normals

 Some not-too-complicated affine analysis shows :

If A is a matrix for transforming points,

then (AT ) -1 is the matrix for transforming normals

When is this the same matrix?

What is the homogeneous representation of a vector (as opposed to a point?)

 Can use this to simplify the problem: only upper 3x3 matrix matters, so use only it

Trang 45

– http://www.wiley.com/legacy/compbooks/vrml2sbk/toc/ch20.htm

Trang 47

Intensity calculation

 = wavelength

I(  ) = wavelength  intensity of light reaching eye

I(  ) = Idiff(  ) + Ispec(  ) + Irefl(  ) + Itrans(  ) + Iamb(  )

Idiff(  ) = diffuse component of I(  ) thành phần khuếch tán

Ispec(  ) = specular component of I(  ) thành phần phản chiếu

Irefl(  ) = reflected light component of I(  ) thành phần phản xạ

Itrans(  ) = transmitted light component of I(  ) thành phần truyền dẫn

Iamb(  ) = ambient component of I(  ) xung quanh(môi trường)

Trang 48

Phản xạ Khuếch tán

Diffuse reflection

 Idiff(  ) = diffuse component of I(  )

 Idiff(  ) = kdiff j Sj ILj(  ) Fdiff(  ) (N • Lj)

 kdiff = diffuse reflectance coefficient;

 Sj = light j hệ số bóng (0 = shadow; 1= no shadow);

 ILj(  ) = cườn độ của ánh sáng j;

 Fdiff(  ) = đường cong phản xạ khuếch tán;

 N = surface normal;

 Lj = hướng của chùm sáng j

Trang 49

Phản chiếu - Specular reflection

 Ispec(  ) = specular component of I(  )

 Ispec(  ) = kspec j Sj ILj(  ) Fspec(  ) (N • Hj) f

 kspec = specular reflectance coefficient;

 Sj = light j shadow coefficient (0 = shadow; 1= no shadow);

 ILj(  ) = intensity of light j;

 Fspec(  ) = specular reflection curve (white);

 f = specular exponent;

 N = surface normal;

 Hj = vector halfway between viewing direction and light

 Hj =where V and Lj are the viewing and light directions | |

j

j

L V

L V

Trang 50

Ánh sáng môi trường - Ambient light

 Iamb(  ) = ambient component of I(  )

 Iamb(  ) = kamb Ea(  ) Famb(  )

 kamb = ambient coefficient;

 Ea(  ) = ambient light intensity of environment;

 Famb(  ) = ambient reflection curve (usually Famb(  ) =

Fdiff(  ))

Trang 52

Nguy ên lý T ạo bóng - Shader

 Calculates the appearance of visible

surfaces in the scene

 Describes the interactions of lights

and surfaces, volumes

 Is composed of shading language (*.sl)

Trang 53

Shading Language

 C-based programming language

 Basic data types : float, string, point, colors

 Mathematical, geometric, and string functions

 Global variables : access to the geometric state

at the point being shaded(position, normal,

surface parameters, amount of incoming light)

 Instance variables : parameters supplied to the shader, as specified in the declaration of the

shader or alternatively attached to the geometry

Trang 56

Surface Shader (1)

• Texture Mapping

Trang 57

Surface Shader (2)

• Displacement & Bump Mapping

Trang 58

– atmosphere affecting light passing through space

between a surface and the eye

Trang 59

Volume shader Example : Smoke

Trang 60

Practical

RenderMan

Trang 61

– ASCII/Binary metafile binding

– Shading Language for describing

surfaces, lights, volumes

Trang 62

What you might get

 CSG(Constructive Solid Modeling)

Trang 63

PRMan’s features & nonfeatures

– Multiple levels of detail

Trang 64

BMRT

– Ray tracing

– Radiosity

– Correct area lights

– Correct volume & imager shaders

– NO true displacements (bump maps instead)

– NO shadow maps (ray tracing instead)

Trang 65

PRMan vs BMRT

PRMan – Ray Casting

BMRT – Ray Tracing

BMRT – Radiosity

Trang 66

PRMan vs BMRT

Usage heuristics :

 Speed, true displacements → PRMan

 Ray tracing, radiosity, area lights,

volumetric effects → BMRT

Trang 67

RenderMan

Trang 69

Mango shader 적용

Trang 70

New Shader

 redapple shader 에 mango shader의 bump 성분을 가미

Ngày đăng: 24/10/2014, 01:40

TỪ KHÓA LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm