-
Notifications
You must be signed in to change notification settings - Fork 0
/
14 - default.frag
83 lines (67 loc) · 2.37 KB
/
14 - default.frag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#version 330 core
out vec4 MauFrag;
in vec3 vtht, bThg, mauSac;
in vec2 txCrd;
uniform sampler2D pTan, pChieu;
uniform vec4 mauDen;
uniform vec3 vtDen, vtCam;
vec4 sangCoHuong()
{
vec3 huongDen = vtDen - vtht;
float kCach = length(huongDen);
float a = 2.0, b = 0.3;
float cuongDo = 1.0f / (a * kCach * kCach + b * kCach + 1.0f);
float mTrg = 0.2f;
vec3 bthg = normalize(bThg);
vec3 huongSang = normalize(huongDen);
float phanTan = max(dot(bthg, huongSang), 0.0f);
float phanChieu = 0.5f;
vec3 huongNhin = normalize(vtCam - vtht);
vec3 huongChieu = reflect(-huongSang, bthg);
float luongSang = pow(max(dot(huongNhin, huongChieu), 0.0f), 16);
float anhSang = luongSang * phanChieu;
return (texture(pTan, txCrd) * (phanTan * cuongDo + mTrg) + texture(pChieu, txCrd).r * anhSang * cuongDo) * mauDen;
}
vec4 sangTrucTiep()
{
float mTrg = 0.2f;
vec3 bthg = normalize(bThg);
vec3 huongSang = normalize(vec3(1.0f, 1.0f, 0.0f));
float phanTan = max(dot(bthg, huongSang), 0.0f);
float phanChieu = 0.5f;
vec3 huongNhin = normalize(vtCam - vtht);
vec3 huongChieu = reflect(-huongSang, bthg);
float luongSang = pow(max(dot(huongNhin, huongChieu), 0.0f), 16);
float anhSang = luongSang * phanChieu;
return (texture(pTan, txCrd) * (phanTan + mTrg) + texture(pChieu, txCrd).r * anhSang) * mauDen;
}
vec4 sang1diem()
{
float benNgoai = 0.7f, benTrg = 0.85f, mTrg = 0.2f;
vec3 bthg = normalize(bThg), huongDen = vtDen - vtht;
vec3 huongSang = normalize(huongDen);
float phanTan = max(dot(bthg, huongSang), 0.0f);
float phanChieu = 0.5f;
vec3 huongNhin = normalize(vtCam - vtht);
vec3 huongChieu = reflect(-huongSang, bthg);
float luongSang = pow(max(dot(huongNhin, huongChieu), 0.0f), 16);
float anhSang = luongSang * phanChieu;
float goc = dot(vec3(0.0f, -1.0f, 0.0f), -huongSang);
float cuongDo = clamp((goc - benNgoai) / (benTrg - benNgoai), 0.0f, 1.0f);
return (texture(pTan, txCrd) * (phanTan * cuongDo + mTrg) + texture(pChieu, txCrd).r * anhSang * cuongDo) * mauDen;
}
float gan = 0.1f, xa = 100.0f;
float tuyenTinhSau(float sau)
{
return (2.0 * gan / xa) / (gan + xa - (sau * 2.0 - 1.0) * (xa - gan));
}
float logicSau(float sau)
{
float z = tuyenTinhSau(sau), doc = 0.5f, bu = 5.0f;
return (1 / (1 + exp(-doc * (z - bu))));
}
void main()
{
float doSau = logicSau(gl_FragCoord.z);
MauFrag = sangTrucTiep() * (1.0f - doSau) + vec4(doSau * vec3(0.85f, 0.85f, 0.90f), 1.0f);
}