simple improvements to li: shadows image based lighting lászló szécsi
Post on 22-Dec-2015
216 views
TRANSCRIPT
Simple Improvements to Simple Improvements to LI:LI:ShadowsShadowsImage Based LightingImage Based Lighting
László SzécsiLászló Szécsi
Image based lighting Image based lighting (IBL)(IBL)
CPU program
Vertex shader
Pixelshader
PositionNormal
Transforms
Transf. posReflection direction
Environment map id
RasterizationInterpolation
Env.Maptexels
Interpolated Reflection direction
Env.map lookup
IBLIBL: vertex/fragment : vertex/fragment shadersshadersvoid VertexShader(
in float4 position : POSITION, in float4 normal : NORMAL, uniform float4x4 MVP : state.matrix.mvp, uniform float4x4 MV : state.matrix.modelview[0], uniform float4x4 MVIT : state.matrix.modelview.invtrans[0], out float4 hPosition : POSITION, out float3 reflectdir : TEXCOORD1 ) {
hPosition = mul(MVP, position);
float3 view = normalize( - mul(MV, position).xyz ); float3 normcam = normalize( mul(MVIT, normal).xyz );
refrectdir = reflect(view, normcam); }
float4 FragmentShader( in float3 reflectdir : TEXCOORD1, uniform samplerCUBE envMap ) : COLOR
{ return texCUBE(envMap, reflectdir); }
Reflection of ideal Reflection of ideal mirrors: Fresnel mirrors: Fresnel functionfunction
F|| = F =cos ’ - (n+k j ) coscos’+ (n+k j ) cos
2cos - (n+k j ) cos’
cos+ (n+k j ) cos’
’
n =sin’sin
Snellius-Descarteslaw of refractionn = Relative speed of the wave
2
SimplificationSimplification
FF||+ F
2= if light is not polarized
F F0 + (1-F0) (1-cos’)5
F0 =
(n -1)2 + k2
(n+1)2 + k2Schlick93, Lazányi05
Fresnel Fragment Fresnel Fragment shadershader
float4 FragmentShader( in float3 reflectdir : TEXCOORD1, in float3 normal : TEXCOORD2, uniform float3 F0,
uniform samplerCUBE envMap ) : COLOR{ // Fresnel reflection reflectdir = normalize( reflectdir ); normal = normalize( normal ); float3 F = F0 + pow(1-dot(normal, reflectdir), 5) * (1-F0);
float3 I = texCUBE(envMap, reflectdir); return float4( F * I, 1 );}