summaryrefslogtreecommitdiffstats
path: root/src/GLSLShaderTest/dimple.frag
blob: 282add72b4dc3e37a793ab8f74e54906915fe680 (plain)
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

//
// dimple.frag: Fragment shader for bump mapping dimples (bumps)
//
// author: John Kessenich
//
// Copyright (c) 2002: 3Dlabs, Inc.
//
//
varying vec3 LightDir;
varying vec3 EyeDir;
varying vec3 Normal;

//const vec3 Color = vec3(0.7, 0.6, 0.18);

//const float Density = 16.0;
//const float Size = 0.25;

uniform vec3 Color;
uniform float Density;
uniform float Size;
// uniform float SpecularFactor;

//float Density = 27.6;
//float Size = 0.13025;


//uniform float Scale;

const float SpecularFactor = 0.4;

void main (void)
{
    vec3 litColor;

    vec2 c = Density * (gl_TexCoord[0].xy);
    vec2 p = fract(c) - vec2(0.5);
    float d = (p.x * p.x) + (p.y * p.y);
    if (d >= Size)
        p = vec2(0.0);

    vec3 normDelta = vec3(-p.x, -p.y, 1.0);
      
    litColor = Color * max(0.0, dot(normDelta, LightDir));
      
    float t = 2.0 * dot(LightDir, normDelta);
    vec3 reflectDir = t * normDelta;
    reflectDir = LightDir - reflectDir;
    
//    vec3 reflectDir = LightDir - 2.0 * dot(LightDir, normDelta) * normDelta;
    
    float spec = max(dot(EyeDir, reflectDir), 0.0);
    spec = spec * spec;
    spec = spec * spec;
    spec *= SpecularFactor;

    litColor = min(litColor + spec, vec3(1.0));
    gl_FragColor = vec4(litColor, gl_Color.a);
//    gl_FragColor = vec4(litColor, 1.0);
//    gl_FragColor = vec4(Scale);
}