Bump Mapping. Displacement Mapping. Deferred Shading
Bump Mapping. Displacement Mapping. Deferred Shading
Perete vertical
Harta normalelor
N normala
B binormala - B = N x T
Vertex shader
M
poz_lumina
poz_observator
P
N, T
texCoord
uniformi
Vertex shader
P= P
texCoord (N)
Raza de lumina (L) in spatiul TBN
Culoare = componenta difuza
5
{
gl_Position = P*V*M*position;
texcoord = in_texcoord;
position = pos.xyz;
texcoord(N)
Raza de lumina (L)
variabili
Harta normalelor
uniformi
Fragment shader
Componenta difuza
in vec3 L;
in vec3 texcoord;
out vec4 frag_color;
void main()
{
vec3 Nn = texture(normalMap, texcoord.st).rgb * 2.0 - 1.0;
vec3 Ln = normalize(L);
frag_color = dot(Nn, Ln);
}
8
Ecuatiile torului:
10
11
12
Displacement mapping
Bump mapping
Displacement
mapping
13
Displacement mapping
se modifica geometria
suprafata finala
suprafata initiala
14
Divizare Catmull-Clark
Divizare Catmull-Clark
Face points
1
F1 (V1 V2 V3 V4 )
4
V4
V1
F1
V2
V6
F2
V3
V5
16
Divizare Catmull-Clark
Edge points
V3 V4 F1 F2
e1
4
V4
V1
V2
F1
e2
e1
V3
e3
V6
F2
e4
V5
17
Divizare Catmull-Clark
V4
V1
V2
F1
e2
F3
e1
V3
e3
V6
F2
e4
V5
F4
Vertex points
1
V3 ' [8V3 (e1 e2 e3 e4 ) ( F1 F2 F3 F4 )]
16
18
Divizare Catmull-Clark
Face points
1 n
f vi
n 1
Edge points
v1 v2 f1 f 2
e
4
Vertex points
n2
1
vi 1
vi 2
n
n
1
j e j n2
19
Displacement mapping
20
Deplasarea varfurilor
esantionare uniforma
Deplasarea varfurilor
Deplasarea varfurilor
23
Raza cu originea in p0
si vectorul de directie d
p1 = p0 + dist( p0, S) d
25
Produce o margine
luminoasa in jurul
conturului unui obiect
Sursa se afla pozitionata
in spatele obiectului si
nu influenteaza
iluminarea fetelor
acestuia
26
27
void main(void)
{
vec4 PW = MV * position;
N = mat3(MV) * normal;
out vec3 N;
L = light_pos - PW.xyz;
V = -PW.xyz;
out vec3 L;
out vec3 V;
uniform vec3 light_pos;
gl_Position = P * PW;
}
29
{
float f = 1.0 - dot(N, V);
in vec3 N;
in vec3 L;
in vec3 V;
f = pow(f, rim_power);
return f * rim_color;
}
30
Componenta difuza
Functie continua
Functie treapta
difuza = N.L
33
Componenta speculara
Contur
34
Toon shading
Fragment shader
in vec3 L, N;
in vec4 position; //spatiul de vizualizare
out vec4 Frag_Color;
void main() {
vec3 n = normalize(N);
vec3 V = normalize(-position.xyz); //spatiul de vizualizare
vec3 l = normalize(L);
vec3 h = normalize(l + V);
35
Toon shading
float edgeMask = (dot(V, n) > 0.4) ? 1 : 0;
float specMask = (pow(dot(h, n), nspec) > 0.5)? 1:0;
float difuseMask = (dot(l, n) > 0.4) ? 1 : 0;
color.xyz = edgeMask *
(difuseMask * kd) *
(specMask * ks);
Frag_Color = color;
}
36
Deferred shading
Realizarea iluminarii:
pentru fiecare obiect
pentru fiecare sursa de lumina
randare obiect iluminat
Complexitate: O(nr_obiecte * nr_lumini)
37
Deferred shading
Pozitie
Normala
Culoare
Depth, etc
Normale
Depth
Culoare
38
Deferred shading
39
Deferring shading
1. Pas 1: vertex shader
in vec4 position;
in vec3 in_normal;
in vec2 in_texcoord;
void main(void)
{
mat4 MV = V *M;
gl_Position = P * V * M* position;
ws_coords = (M * position).xyz;
normal = mat3(M) * in_normal;
texcoord = in_texcoord;
40
Deferring shading
1. Pas 1: fragment shader
in vec3 ws_coords;
in vec3 normal;
in vec2 texcoord;
void main(void)
{
color = texture(texture, texcoord).rgb;
WS_coord = ws_coord;
N = normal;
}
41
Deffered shading
Pas 2: Vertex shader
void main()
{
gl_Position = .;
.
}
42
Deffered shading
Pas 2: Fragment shader
out vec4 color_out;
uniform usampler2D texture_P;
void main(void)
{
fragment_info fragment;
vec3 normal;
color_out = light_fragment(fragment);
}
vec3 ws_coord;
};
43
Deffered shading
vec4 light_fragment(fragment_info fragment){
vec4 result;
vec3 L = light.position - fragment.ws_coord;
L = normalize(L);
vec3 N = normalize(fragment.normal);
44