Physically Based Shading

61
A simplified artist interface Physically Based Shading Niklas Hansson Head Teacher Game programming The Game Assembly.

description

Physically Based Shading. A simplified artist interface. Niklas Hansson Head Teacher Game programming The Game Assembly. Physically Based Shading. What is it ? Why should I use it ? How do I integrate it into a project ?. Basic BRDF Theory. - PowerPoint PPT Presentation

Transcript of Physically Based Shading

  • A simplified artist interface

    Physically Based Shading

    Niklas HanssonHead Teacher Game programming The Game Assembly.

  • Physically Based Shading

    What is it ?Why should I use it ?How do I integrate it into a project ?

  • Basic BRDF TheoryBoundary : When light goes from one material to anotherLight splits up into two directions : reflection and refraction.The amount of light reflected depends on thematerials reflective index.

    Image from Real-Time Rendering 3rd Edition

  • Basic BRDF Theory Basic Material- Part is Reflected- Part enters the material

    MetalPart is ReflectedThe part entering the Material is absorbed

    Image from Real-Time Rendering 3rd Edition

  • Basic BRDF TheoryNon metals- Light that enters the material scatters internally- Is absorbed- and often exits the surface again.Image from Real-Time Rendering 3rd Edition

  • Basic BRDF TheorySub surface scatteringDistance between enter and exit positions are determined by the material.

    Image from Real-Time Rendering 3rd Edition

  • Basic BRDF TheoryPoint modelBy ignoring distance between exit and enter points we can model lighting with an BRDF.

    Image from Real-Time Rendering 3rd Edition

  • Basic Microfacet BRDF TheoryImage from Real-Time Rendering 3rd EditionMicrofacetsA surface consists of many small perfectly flat surfaces.How much they differ in normal determines how light interact

  • Basic Microfacet BRDF TheoryImages from Real-Time Rendering 3rd Edition

  • Shadowing & Masking Not all micro facets facing half vectors direction contribute to lightning

    ShadowingMasking

    Images from Real-Time Rendering 3rd Edition

  • So why is specular so important ?Images from Everything is Shiny by John Hable

  • So why is specular so important ?Images from Everything is Shiny by John Hable

  • The Microfacet BRDF

  • Fresnel ReflectanceReturns a Value from 0-1 in RGBFraction of light reflected from optically flat surface given Light directon l and Half vector h

  • Fresnel ReflectanceDepends on refraction index (in our terms the substance of the object) and the light angle.Image from Real-Time Rendering 3rd Edition

  • FresnelImages from Everything has Fresnel by John Hable

  • Schlicks ApproximationDecently Accurate, uses F(0) the refractive index as input.Which is our substance term.

  • Geometric termGives a scalar value between 0 and 1 Contains the fraction of non obscured microfacets Various functions exists most using roughness as input

  • Distribution function

    Calculates factor of microfacets reflecting light towards the eyeThe function determines size and shape of the specular highlight

  • Blinn Phong Distribution FunctionsBlinn Phong Distribution Function

    Modified Blinn Phong

  • Beckman Distribution functionConversion :

  • Blinn Phong Energy ConversationIf the specular highlight is larger the specular intensity must be lower.

    N = roughness

  • Blinn Phong Energy Conversation

  • Blinn Phong Energy Conversation

  • Blinn Phong Energy Conversation

  • Blinn Phong Energy Conversation

  • Blinn Phong Energy Conversation0.397436n+0.0856832

  • Blinn Phong Energy Conversation0.397436n+0.03183

  • Blinn Phong Energy Conversation

  • Energy ConversationOur Normalized equation for specular light

    Lambert

    Cdiff*PI

  • Ambient LightAmbient Light is just LightHas a specular component tooreflections roughness controls reflections blurriness substance controls reflection strength.

    Pre blurred cubemaps

  • Ambient Light

    ATI cubemap gen has nice functions for preblurring mipmaps.For correctnes the blurring needs to match your specular light

  • Blurred cubemap

    Use the angular extent and always sample from top mip.Use the glossiness for that mipmap level and evaluate max size of highlight for size of angular extent.Use the phong function to evaluate a contribution for all the pixels inside the extent.

  • Why physically based ?Its more realistic thanks to being physically based?

    Materials does not require as much retweaking under changing lighting conditions.

    You can create more easily varied materials with lesser number of values

    It saves artist time and simplifies workflow

  • Simplified Artist interfaceReduces number of maps from 4-5 to 2.

    Simplifies Junior artist trainingNo longer take albedo and desaturate for intensityAnd then lower color for glossWe have all seen it

  • Simplified Artist interfacePBL simplifies this by creating a material interface that makes sense. SubstanceIs the index of refraction for the materialNo need to hand paint.Mathematically matches old intensity

  • Color picker

  • Simplified Artist interfaceRoughnessThe old glossBut thanks to Normalization a lot more usefulWhere hand painting happensControls reflection blurrinees and spec Surface Roughness that normal maps cant show

    TouchObserve

  • Example Material rusty Paint

  • Flexibillity

  • Sample Oskar stlberg

  • Why physically based ?Lower numbers of values to tweak

    Smaller tighter gbufferLow bandwitdhSmall ALU increaseIdeal for deferred rendering

    While still allowing very varied materials

  • How to use itWhat did we do ?

    Microfacet BRDF with Normalized Blinn PhongFresnel reflectanceVoid Geometry FunctionG(h) = 4(n dot l)(n dot v)Prefiltered glossy reflections from cubemap probesAmbient from ambient probes

  • What we did Cref is the value from the reflection probe Camb is the value from the ambient probe Fschlick(v,h) is the fresnel term using the view direction instead of the light direction

  • Ambient vs reflection Energy Conversation

  • Lessons learned

    Substance and Roughness vs Intensity and GlossSpend time training and communicating to your artistsHelp them use the new interface

    Tools is essentialBeware of bugs

  • Maya plugin

  • What we didFlexibleKind of projectsSpace shooterRealtime Strategy First Person shooter

  • Space shooter

  • Fps projectGoalsResolve all issues found during the last projectGet an easy to light solution that took little rebuild time and would work with just a few spot lights.TechniquesAll enviroment and ambient probes generated by the ingame engine to achieve consistency.Box projected cubemaps was used for reflections and a variation was used for ambientSimple Multi bounce solution for lightning

  • OcclusionSpecular and reflection doing more workWill look weird in areas normally dont reach by much lightUse Ambient occlusionMultiply to specMultiply to reflectionIf needed add special Specular occlusion

  • ReferencesSbastien Lagarde Adopting a physically based shadingmodel ,Feeding a physically based shadingmodelRoy Driscol Energy Conversation In GamesFabien Giesen Blinn-Phong normalization factorNathaniel Hoffmann, Crafting Physically Motivated Shading Models for Game Development, SIGGRAPH 2010Dimitar Lazarov, Physically-based lighting in Call of Duty: Black Ops SIGGRAPH 2011Christian Schler, An Efficient and Physically Plausible Real-Time Shading Model. , The Blinn-Phong Normalization ZooAkienne-Mller, Haines and Hoffmann, Real-Time Rendering bookYoshiharu Gotanda, Practical Implementation of Physically-Based Shading Models at tri-Ace, SIGGRAPH 2010Yoshiharu Gotanda, Practical Physically Based Rendering in Real-time, SIGGRAPH 2012

  • Going forwardTesting on real projects

    Better Geometry term

    Using the proper mipmapping for cubemaps

    Some kind of Diffuse- specular energy conversation

  • Physically based for non realistic renderingCan we do it ?Yes just a material interfaceRules can be bent and broken.Specular not that important for cartoonish lookDiffuse light ,albedo,normal,AO more important

  • RTS game

  • More non photo

    Lightning base on the physical properties of light.

    Replacement of Ad Hoc solutions

    Instead of havingSpec Intensity,Spec Gloss,Reflectivity,Fresnel strength map and even a separate reflection gloss factor.

    With a physically based solution we will be able to collapse this down to two simple maps.

    Instead of Ad hoc solutions competing we have one stable system.

    *Been asked to keep this not to technical

    Basics are important.

    BoundraryL is split into ri and t

    SplitRefractive index

    BRDF

    Works no matter the materials

    We will only look at air to other material***If red pixel and green exit pos

    needs SSSBRDF cant cope.

    If other wayWorks *Holds holds true no matter the source of the light.

    Works for perfectly flat boundaries

    Most real world materials (except mirrors) doesnt share this property.

    *MicrofactesNormal differences encoded as a normal distribution

    The difference from the Phong model to the Blinn Phong model

    Blinn Phong instead used the microfacet

    If parallel light hits small solid angle with all light, the rougher the larger solid angle the light will hit.

    We use a normal distribution function to model this

    The data it uses is the roughness of the surface (or flattnes would be a better name)*As you can see the rougher the surface the blurrier reflection and larger specular highlights.

    Microfacets model sub normal map resolution shapes

    *Strength of being physically based

    Values have real value

    Can update formulas without changing the value

    Can be used to uppdate difuse to for exampel to Oren-Nayar

    Rough material not gonna be as reflective due to ridges blocking light

    Microfacet BRDF cant handle bounces on ridges*Microfacet BRDFLEGO parts

    Most different BRDF models only contains changes to the D and G term.

    Except denominator

    //Is a correction factor that accounts for quantities being transformed between the local space of the micro facets and the overall macro surface

    The 4 is related to transforming from the space of half-angle directions to other spaces,

    and the two clamped dot products are foreshortening factors that relate to the way that the visible area of microfacets change in relation to their orientation.*Frist part Fresnel reflectivity

    Gives the reflctivity of the surface vs the viweing and light angle.

    Returns spectral values

    Reflected color doesnt absorb light

    However they reflect different amounts of lights at different wavelengths

    We simplify this using RGB just as in the rest of CG*Fresnel curve

    Light bounce amount varies with angle.

    Try putting your head next to a door and se a clear reflection appear.

    Starts on index of refraction which we will call substance

    Objects with RGB spec has 3 index of refraction

    Barely changes in beginning.

    Turns quickly upwards at the end

    Some materials dip

    We wont model this*Some real world examples**Using the geometric term to cancel out the denominator is extremely cheap as you can just remove booth from the calculation but will result in a to dark specular.

    Look at lazarovs keynote for good solutions to this.*Distribution function calculates how many microfacets reflects light based on the roughnees

    Decides specular size and strength

    The blinn-phong distribution function is widely used in the games industry

    *Basic Blinn Phong

    Doesnt account for amount of light hitting the surface

    Using a max cap is not enough

    Calcualte amount of light hittign surface

    And multiply with that

    Cant reflect more light than hits it.

    *Cook torrence used beckaman

    More accurate

    More expensive.

    Can convert between*A surface cant emit more light than hits it

    Therefore of light is reflected over a larger solid angle.

    It needs to be weaker

    We use a normalization factor to adapt light strength to scale.

    This makes the equation energy conserving

    The normalization factors differs depending on the distribution

    N= roughness

    phong has a very different normalization factor than blinn Phong.

    This normalization was derived by Fabian Giesen

    *Formula from physically based shading 2010

    Seems vey off ?

    Pi is lacking

    Comes from hemisphere integration

    Applies constantly over all light so can be removed in our case.

    Just change light scale with pi*Adding in the pi seems to give a correct curve so lets zoom in to make certain*Zooming in it seems that this curve is off with quite a bit in the lower 100 range at least. *Another common approximation as an 8 instead of a 2 at the top. This one fits much more well.

    An important part is that it fits better at lower values which contains most of the real world materials. So we get some extra precision where it counts.

    The factor of 8 is also used in the real time rendering book.*This is another common approximation taken from tri Arcs papers but as you can see it plots vs the n+2/8 curve and not the real one*This is another common approximation taken from tri Arcs papers but as you can see it plots vs the n+2/8 curve and not the real one*Mathematically actually this formula is a better match but as you can see we have a higher margin of error on the lower values where most natural objects resides which is why the formula with an 8 is more often used.*Our equation

    Lambert equation for diffuse

    Using Cdiff for albedo

    To be energy conserving Cdiff*pi