Skip to content

Commit d068e1d

Browse files
committed
Add r_parallaxMapShadows.
1 parent e5da13f commit d068e1d

File tree

5 files changed

+54
-1
lines changed

5 files changed

+54
-1
lines changed

code/renderergl2/glsl/lightall_fp.glsl

+43-1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,35 @@ float RayIntersectDisplaceMap(vec2 dp, vec2 ds, sampler2D normalMap)
143143

144144
return bestDepth;
145145
}
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+
}
146175
#endif
147176

148177
vec3 CalcDiffuse(vec3 diffuseAlbedo, float NH, float EH, float roughness)
@@ -252,7 +281,7 @@ void main()
252281
vec2 texCoords = var_TexCoords.xy;
253282

254283
#if defined(USE_PARALLAXMAP)
255-
vec3 offsetDir = viewDir * tangentToWorld;
284+
vec3 offsetDir = E * tangentToWorld;
256285

257286
offsetDir.xy *= -u_NormalScale.a / offsetDir.z;
258287

@@ -319,6 +348,13 @@ void main()
319348
#endif
320349
#endif
321350

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+
322358
#if !defined(USE_LIGHT_VECTOR)
323359
ambientColor = lightColor;
324360
float surfNL = clamp(dot(var_Normal.xyz, L), 0.0, 1.0);
@@ -457,6 +493,12 @@ void main()
457493
// enable when point lights are supported as primary lights
458494
//lightColor *= CalcLightAttenuation(float(u_PrimaryLightDir.w > 0.0), u_PrimaryLightDir.w / sqrLightDist);
459495

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+
460502
gl_FragColor.rgb += lightColor * reflectance * NL2;
461503
#endif
462504

code/renderergl2/tr_glsl.c

+3
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,9 @@ void GLSL_InitGPUShaders(void)
11221122
Q_strcat(extradefines, 1024, "#define USE_PARALLAXMAP\n");
11231123
if (r_parallaxMapping->integer > 1)
11241124
Q_strcat(extradefines, 1024, "#define USE_RELIEFMAP\n");
1125+
1126+
if (r_parallaxMapShadows->integer)
1127+
Q_strcat(extradefines, 1024, "#define USE_PARALLAXMAP_SHADOWS\n");
11251128
}
11261129
}
11271130

code/renderergl2/tr_init.c

+2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ cvar_t *r_normalMapping;
131131
cvar_t *r_specularMapping;
132132
cvar_t *r_deluxeMapping;
133133
cvar_t *r_parallaxMapping;
134+
cvar_t *r_parallaxMapShadows;
134135
cvar_t *r_cubeMapping;
135136
cvar_t *r_cubemapSize;
136137
cvar_t *r_deluxeSpecular;
@@ -1235,6 +1236,7 @@ void R_Register( void )
12351236
r_specularMapping = ri.Cvar_Get( "r_specularMapping", "1", CVAR_ARCHIVE | CVAR_LATCH );
12361237
r_deluxeMapping = ri.Cvar_Get( "r_deluxeMapping", "1", CVAR_ARCHIVE | CVAR_LATCH );
12371238
r_parallaxMapping = ri.Cvar_Get( "r_parallaxMapping", "0", CVAR_ARCHIVE | CVAR_LATCH );
1239+
r_parallaxMapShadows = ri.Cvar_Get( "r_parallaxMapShadows", "0", CVAR_ARCHIVE | CVAR_LATCH );
12381240
r_cubeMapping = ri.Cvar_Get( "r_cubeMapping", "0", CVAR_ARCHIVE | CVAR_LATCH );
12391241
r_cubemapSize = ri.Cvar_Get( "r_cubemapSize", "128", CVAR_ARCHIVE | CVAR_LATCH );
12401242
r_deluxeSpecular = ri.Cvar_Get("r_deluxeSpecular", "0.3", CVAR_ARCHIVE | CVAR_LATCH);

code/renderergl2/tr_local.h

+1
Original file line numberDiff line numberDiff line change
@@ -1771,6 +1771,7 @@ extern cvar_t *r_normalMapping;
17711771
extern cvar_t *r_specularMapping;
17721772
extern cvar_t *r_deluxeMapping;
17731773
extern cvar_t *r_parallaxMapping;
1774+
extern cvar_t *r_parallaxMapShadows;
17741775
extern cvar_t *r_cubeMapping;
17751776
extern cvar_t *r_cubemapSize;
17761777
extern cvar_t *r_deluxeSpecular;

opengl2-readme.md

+5
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,11 @@ Cvars for advanced material usage:
184184
1 - Use parallax occlusion mapping.
185185
2 - Use relief mapping. (slower)
186186

187+
* `r_parallaxMapShadows` - Enable self-shadowing on parallax map
188+
supported materials.
189+
0 - No. (default)
190+
1 - Yes.
191+
187192
* `r_baseSpecular` - Set the specular reflectance of materials
188193
which don't include a specular map or
189194
use the specularReflectance keyword.

0 commit comments

Comments
 (0)