@@ -39,37 +39,21 @@ vec4 get_normal_map(vec2 uv)
39
39
40
40
float find_intersection(vec2 dp, vec2 ds)
41
41
{
42
- const int linear_steps = 10 ;
43
- const int binary_steps = 5 ;
44
- const float depth_step = 1.0 / linear_steps;
45
- float size = depth_step;
42
+ const float depth_step = 1.0 / 24.0 ;
46
43
float depth = 1.0 ;
47
- float best_depth = 1.0 ;
48
- for (int i = 0 ; i < linear_steps - 1 ; ++ i) {
49
- vec4 t = texture2D (normalTexture, dp + ds * depth);
50
- if (best_depth > 0.05 )
51
- if (depth >= t.a)
52
- best_depth = depth;
53
- depth -= size;
54
- }
55
- depth = best_depth - size;
56
- for (int i = 0 ; i < binary_steps ; ++ i) {
57
- size *= 0.5 ;
58
- vec4 t = texture2D (normalTexture, dp + ds * depth);
59
- if (depth >= t.a) {
60
- best_depth = depth;
61
- depth -= 2 * size;
62
- }
63
- depth += size;
44
+ for (int i = 0 ; i < 24 ; i++ ) {
45
+ float h = texture2D (normalTexture, dp + ds * depth).a;
46
+ if (h >= depth)
47
+ break ;
48
+ depth -= depth_step;
64
49
}
65
- return best_depth ;
50
+ return depth ;
66
51
}
67
52
68
53
float find_intersectionRGB(vec2 dp, vec2 ds) {
69
- const float iterations = 24.0 ;
70
- const float depth_step = 1.0 / iterations;
54
+ const float depth_step = 1.0 / 24.0 ;
71
55
float depth = 1.0 ;
72
- for (int i = 0 ; i < iterations ; i++ ) {
56
+ for (int i = 0 ; i < 24 ; i++ ) {
73
57
float h = get_rgb_height(dp + ds * depth);
74
58
if (h >= depth)
75
59
break ;
@@ -85,40 +69,41 @@ void main (void)
85
69
vec2 uv = gl_TexCoord [0 ].st;
86
70
bool use_normalmap = false;
87
71
88
- #ifdef USE_NORMALMAPS
72
+ #if USE_NORMALMAPS == 1
89
73
if (texture2D (useNormalmap,vec2 (1.0 , 1.0 )).r > 0.0 ) {
90
74
normalTexturePresent = true;
91
75
}
92
76
#endif
93
77
94
78
#ifdef ENABLE_PARALLAX_OCCLUSION
95
- vec3 eyeRay = normalize (tsEyeVec);
79
+ vec2 eyeRay = vec2 (tsEyeVec.x, - tsEyeVec.y);
80
+ const float scale = PARALLAX_OCCLUSION_SCALE / PARALLAX_OCCLUSION_ITERATIONS;
81
+ const float bias = PARALLAX_OCCLUSION_BIAS / PARALLAX_OCCLUSION_ITERATIONS;
82
+
96
83
#if PARALLAX_OCCLUSION_MODE == 0
97
84
// Parallax occlusion with slope information
98
85
if (normalTexturePresent && area_enable_parallax > 0.0 ) {
99
- const float scale = PARALLAX_OCCLUSION_SCALE / PARALLAX_OCCLUSION_ITERATIONS;
100
- const float bias = PARALLAX_OCCLUSION_BIAS / PARALLAX_OCCLUSION_ITERATIONS;
101
- for (int i = 0 ; i < PARALLAX_OCCLUSION_ITERATIONS; i++ ) {
86
+ for (int i = 0 ; i < PARALLAX_OCCLUSION_ITERATIONS; i++ ) {
102
87
vec4 normal = texture2D (normalTexture, uv.xy);
103
88
float h = normal.a * scale - bias;
104
- uv += h * normal.z * eyeRay.xy ;
89
+ uv += h * normal.z * eyeRay;
105
90
}
106
91
#endif
107
92
#if PARALLAX_OCCLUSION_MODE == 1
108
93
// Relief mapping
109
94
if (normalTexturePresent && area_enable_parallax > 0.0 ) {
110
- vec2 ds = eyeRay.xy * PARALLAX_OCCLUSION_SCALE;
95
+ vec2 ds = eyeRay * PARALLAX_OCCLUSION_SCALE;
111
96
float dist = find_intersection(uv, ds);
112
97
uv += dist * ds;
113
98
#endif
114
- } else if (area_enable_parallax > 0.0 ) {
115
- vec2 ds = eyeRay.xy * PARALLAX_OCCLUSION_SCALE;
99
+ } else if (GENERATE_NORMALMAPS == 1 && area_enable_parallax > 0.0 ) {
100
+ vec2 ds = eyeRay * PARALLAX_OCCLUSION_SCALE;
116
101
float dist = find_intersectionRGB(uv, ds);
117
102
uv += dist * ds;
118
103
}
119
104
#endif
120
105
121
- #ifdef USE_NORMALMAPS
106
+ #if USE_NORMALMAPS == 1
122
107
if (normalTexturePresent) {
123
108
bump = get_normal_map(uv);
124
109
use_normalmap = true;
@@ -136,7 +121,7 @@ void main (void)
136
121
float l = get_rgb_height(vec2 (uv.x - SAMPLE_STEP, uv.y));
137
122
float dX = (tr + 2.0 * r + br) - (tl + 2.0 * l + bl);
138
123
float dY = (bl + 2.0 * b + br) - (tl + 2.0 * t + tr);
139
- bump = vec4 (normalize (vec3 (- dX, - dY, NORMALMAPS_STRENGTH)), 1.0 );
124
+ bump = vec4 (normalize (vec3 (dX, dY, NORMALMAPS_STRENGTH)), 1.0 );
140
125
use_normalmap = true;
141
126
}
142
127
@@ -145,9 +130,9 @@ void main (void)
145
130
#ifdef ENABLE_BUMPMAPPING
146
131
if (use_normalmap) {
147
132
vec3 L = normalize (lightVec);
148
- vec3 E = normalize (- eyeVec);
149
- float specular = pow (clamp (dot (reflect (L, bump.xyz), - E), 0.0 , 1.0 ), 1.0 );
150
- float diffuse = dot (E,bump.xyz);
133
+ vec3 E = normalize (eyeVec);
134
+ float specular = pow (clamp (dot (reflect (L, bump.xyz), E), 0.0 , 1.0 ), 1.0 );
135
+ float diffuse = dot (- E,bump.xyz);
151
136
color = (diffuse + 0.1 * specular) * base.rgb;
152
137
} else {
153
138
color = base.rgb;
0 commit comments