-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathNewFShader.fragmentshader
89 lines (54 loc) · 2.05 KB
/
NewFShader.fragmentshader
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
84
85
86
87
88
89
#version 330 core
in vec2 UV;
in vec3 Eye_Direction;
in vec3 LightDirection_eyespace;
in vec3 Eye_Direction_tangentspace;
in vec3 LightDirection_tangentspace;
in vec3 interpolatedColor;
in vec4 world_position;
in vec3 Normal_eyespace;
in vec3 Tangent_eyespace;
in vec3 Tangent_modelspace;
uniform vec4 LightLocation_world_space;
uniform sampler2D textureMap_diffuse;
uniform sampler2D textureMap_specular;
uniform sampler2D textureMap_normal;
uniform mat4 VP;
uniform mat4 M;
uniform mat4 V;
// Ouput data
out vec3 color;
void main()
{
vec3 E = normalize(Eye_Direction_tangentspace);
vec2 texOffset = UV;
vec4 bumpPoint = texture2D(textureMap_specular,texOffset);
float height = 1.0;
float step = height/60;
vec2 delta = vec2(E.x, E.y)*0.045/ (-E.z * 60);
while(bumpPoint.r < height)
{
height-=step;
texOffset += delta;
bumpPoint = texture2D(textureMap_specular,texOffset);
}
vec4 texColorD=texture2D(textureMap_diffuse,texOffset);
vec4 texColorS=texture2D(textureMap_specular,texOffset);
vec4 texColorN=texture2D(textureMap_normal,texOffset);
vec3 LightColor = vec3(0.6,0.6,0.6);
float LightPower = 30.0f;
vec3 MaterialDiffuseColor = texColorD.rgb;
vec3 MaterialAmbientColor = vec3(0,0,0.1) * MaterialDiffuseColor;
vec3 MaterialSpecularColor = texColorS.rgb;
float distance = length( LightLocation_world_space - world_position );
vec3 n = normalize( texColorN.rgb*2.0-1.0) ;
//vec3 n = normalize( Normal_eyespace) ;
vec3 l = normalize( LightDirection_tangentspace );
float cosTheta = clamp( dot( n,l ), 0,1 );
vec3 R = normalize(reflect(-l,n));
float cosAlpha = clamp( dot( E,R ), 0,1 );
color = MaterialAmbientColor +
MaterialDiffuseColor * LightColor * LightPower * cosTheta / (distance*distance) +
MaterialSpecularColor * LightColor * LightPower * texColorS.rgb * pow(cosAlpha,5) / (distance*distance);
//color= vec3(texOffset.x,texOffset.y,1.0);
}