@@ -143,6 +143,35 @@ float RayIntersectDisplaceMap(vec2 dp, vec2 ds, sampler2D normalMap)
143
143
144
144
return bestDepth;
145
145
}
146
+
147
+ float LightRay(vec2 dp, vec2 ds, sampler2D normalMap)
148
+ {
149
+ const int linearSearchSteps = 16 ;
150
+
151
+ // current size of search window
152
+ float size = 1.0 / float (linearSearchSteps);
153
+
154
+ // current height from initial texel depth
155
+ float height = 0.0 ;
156
+
157
+ float startDepth = SampleDepth(normalMap, dp);
158
+
159
+ // find a collision or escape
160
+ for (int i = 0 ; i < linearSearchSteps - 1 ; ++ i)
161
+ {
162
+ height += size;
163
+
164
+ if (startDepth < height)
165
+ return 1.0 ;
166
+
167
+ float t = SampleDepth(normalMap, dp + ds * height);
168
+
169
+ if (startDepth > t + height)
170
+ return 0.0 ;
171
+ }
172
+
173
+ return 1.0 ;
174
+ }
146
175
#endif
147
176
148
177
vec3 CalcDiffuse(vec3 diffuseAlbedo, float NH, float EH, float roughness)
@@ -252,7 +281,7 @@ void main()
252
281
vec2 texCoords = var_TexCoords.xy;
253
282
254
283
#if defined(USE_PARALLAXMAP)
255
- vec3 offsetDir = viewDir * tangentToWorld;
284
+ vec3 offsetDir = E * tangentToWorld;
256
285
257
286
offsetDir.xy *= - u_NormalScale.a / offsetDir.z;
258
287
@@ -319,6 +348,13 @@ void main()
319
348
#endif
320
349
#endif
321
350
351
+ #if defined(USE_PARALLAXMAP) && defined(USE_PARALLAXMAP_SHADOWS)
352
+ offsetDir = L * tangentToWorld;
353
+ offsetDir.xy *= u_NormalScale.a / offsetDir.z;
354
+ lightColor *= LightRay(texCoords, offsetDir.xy, u_NormalMap);
355
+ #endif
356
+
357
+
322
358
#if ! defined(USE_LIGHT_VECTOR)
323
359
ambientColor = lightColor;
324
360
float surfNL = clamp (dot (var_Normal.xyz, L), 0.0 , 1.0 );
@@ -457,6 +493,12 @@ void main()
457
493
// enable when point lights are supported as primary lights
458
494
// lightColor *= CalcLightAttenuation(float(u_PrimaryLightDir.w > 0.0), u_PrimaryLightDir.w / sqrLightDist);
459
495
496
+ #if defined(USE_PARALLAXMAP) && defined(USE_PARALLAXMAP_SHADOWS)
497
+ offsetDir = L2 * tangentToWorld;
498
+ offsetDir.xy *= u_NormalScale.a / offsetDir.z;
499
+ lightColor *= LightRay(texCoords, offsetDir.xy, u_NormalMap);
500
+ #endif
501
+
460
502
gl_FragColor .rgb += lightColor * reflectance * NL2;
461
503
#endif
462
504
0 commit comments