forked from lettier/3d-game-shaders-for-beginners
-
Notifications
You must be signed in to change notification settings - Fork 0
/
normal.frag
64 lines (52 loc) · 1.21 KB
/
normal.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
/*
(C) 2019 David Lettier
lettier.com
*/
#version 150
uniform float osg_FrameTime;
uniform sampler2D p3d_Texture1;
uniform sampler2D flowTexture;
uniform vec2 normalMapsEnabled;
uniform vec2 flowMapsEnabled;
in vec3 vertexNormal;
in vec3 binormal;
in vec3 tangent;
in vec2 normalCoord;
out vec4 fragColor;
void main() {
vec2 flow = texture(flowTexture, normalCoord).xy;
flow = (flow - 0.5) * 2;
flow.x = abs(flow.x) <= 0.02 ? 0 : flow.x;
flow.y = abs(flow.y) <= 0.02 ? 0 : flow.y;
vec4 normalTex =
texture
( p3d_Texture1
, vec2
( normalCoord.x + flowMapsEnabled.x * flow.x * osg_FrameTime
, normalCoord.y + flowMapsEnabled.y * flow.y * osg_FrameTime
)
);
vec3 normal;
if (normalMapsEnabled.x == 1) {
normal =
normalize
( normalTex.rgb
* 2.0
- 1.0
);
normal =
normalize
( mat3
( tangent
, binormal
, vertexNormal
)
* normal
);
} else {
normal = normalize(vertexNormal);
}
// To convert Panda3D z-up to OpenGL y-up.
// fragColor = vec4(normal.x, normal.z, -normal.y, 1);
fragColor = vec4(normal, 1);
}