View Issue Details

IDProjectCategoryView StatusLast Update
0004962The Dark ModGraphicspublic06.05.2019 02:52
ReporterNightcrawler Assigned Toduzenko  
PrioritynormalSeveritynormalReproducibilityalways
Status resolvedResolutionfixed 
PlatformLinux x64OSUbuntu 
Product VersionTDM 2.07 
Target VersionTDM 2.07Fixed in VersionTDM 2.07 
Summary0004962: Lightning stops working in TDM v2.07
DescriptionLight sources do not produce any visible light in TDM v2.07beta.
Additional InformationI attached some screenshots of the same scenes in tdm v2.07 and tdm v2.06 to illustrate this issue.
TagsNo tags attached.

Relationships

related to 0004961 resolvedduzenko Tdm v2.07 crashes as soon as you enter the game if "Maps" was chosen as shadow implementation. 

Activities

Nightcrawler

Nightcrawler

17.01.2019 00:20

reporter  

light_bug_screenshots.zip (4,232,387 bytes)
Springheel

Springheel

17.01.2019 02:09

administrator   ~0011368

Any relation to this? http://forums.thedarkmod.com/topic/19807-lights-not-working-fixed/
nbohr1more

nbohr1more

17.01.2019 02:23

developer   ~0011370

Does this happen if you set r_useGLSL 0 ?

Please post a condump and your Darkmod.cfg
nbohr1more

nbohr1more

17.01.2019 02:26

developer   ~0011371

Also:

DRM 3.26.0, 4.18.0-13-generic

Does lighting work if you use AMD's non-free drivers?
Nightcrawler

Nightcrawler

17.01.2019 19:05

reporter  

Darkmod.cfg (12,894 bytes)
Nightcrawler

Nightcrawler

17.01.2019 19:08

reporter   ~0011400

Yes, this http://forums.thedarkmod.com/topic/19807-lights-not-working-fixed/ seems to be the same.

Setting r_useGLSL 0 fixed it for me.

I uploaded my darkmod.cfg if that's still useful
duzenko

duzenko

18.01.2019 12:40

developer   ~0011403

How about the shader compile log?
I believe you're on nVidia 7600? Or Intel?
Nightcrawler

Nightcrawler

18.01.2019 12:58

reporter   ~0011406

No, I'm on AMD Radeon R5.

Not sure where/how to get the shader compile log
nbohr1more

nbohr1more

18.01.2019 15:28

developer   ~0011411

The backtrace from 4961 has GL logging but we normally would want the results from:

1) Open Console
2) reloadGLSLprograms
3) Condump mygraphicissue.txt

thanks
Nightcrawler

Nightcrawler

20.01.2019 16:13

reporter  

graphicsIssue.dump (29,994 bytes)
Nightcrawler

Nightcrawler

20.01.2019 16:15

reporter   ~0011447

Ok, there you go
nbohr1more

nbohr1more

22.01.2019 15:37

developer   ~0011473

Last edited: 22.01.2019 15:39

View 2 revisions

Per stgatilov:

Too late in the development cycle to risk global changes to GL version support.
Updated shaders may be supplied at Moddb when a consensus has been reached about the best approach.

stgatilov

stgatilov

27.01.2019 13:36

developer   ~0011517

Last edited: 27.01.2019 13:37

View 2 revisions

I have the same problem in VMWare Linux VM.
It has:
  OpenGL vendor: VMware, Inc.
  OpenGL renderer: Gallium 0.4 on SVGA3D; build: RELEASE; LLVM;
  OpenGL version: 3.0 Mesa 12.0.6
  v - using GL version 2.0 (core)
I cannot see any sort of lights in any mode.

In fact, we now have stupid problem:
1) If we leave GL_EXT_gpu_shader4 extension in shader, then old GL2 cards and some new Linux drivers cannot get interaction lights working in any mode. Even with hard stencil shadows, which don't actually need this extension.
2) If we remove GL_EXT_gpu_shader4 extension in shader, then most of the cards can stop working with Stencil shadows because of syntax error (using type undefined in GLSL 1.20).

What this story teaches us?
1) Always enable new features by conditional compilation, don't use only uniforms for that. Just like you do #ifdef in C++.
2) GL3 core profile is really important if we want to get TDM friendly to wide range of drivers.

duzenko

duzenko

27.01.2019 14:40

developer   ~0011518

Switch to shadow maps if GL_EXT_gpu_shader4 not supported and gl version >= 4?
stgatilov

stgatilov

28.01.2019 12:53

developer   ~0011520

Last edited: 28.01.2019 12:54

View 2 revisions

Geometry shaders extension is not supported (and core geometry shaders too since it is GL 3.0) =)

We have two workarounds for people with this problem.
Applying either of them is enough:
1) Set "r_useGLSL 0" and restart to revert to old shaders.
2) Download file "interaction_oldgl.fs" from here, and rename it into file "glprogs/interaction.fs" (this path is relative to TDM installation root dir).

I hope the whole mess with extensions will go away by TDM 2.08.

stgatilov

stgatilov

28.01.2019 12:54

developer  

interaction_oldgl.fs (10,748 bytes)   
#version 120
//#extension GL_EXT_gpu_shader4: enable
#define DISABLE_STENCIL_TEXTURE

//when = 1: the samples are filtered so that "halos" do not appear (new)
//     = 0: the samples are weighted based on heuristic (old)
#define ENABLE_ANTI_HALO_PATCH 1

varying vec3 var_Position;
varying vec3 var_WorldLightDir;
varying vec3 var_tc0;  
varying vec3 var_tc6;  
varying vec2 var_TexDiffuse;        
varying vec2 var_TexNormal;        
varying vec2 var_TexSpecular;       
varying vec4 var_TexLight; 
varying mat3 var_TangentBitangentNormalMatrix; 
varying vec4 var_Color;        
//varying vec4 var_ScreenPos;
     
uniform sampler2D u_normalTexture;
uniform sampler2D u_lightFalloffTexture;         
uniform sampler2D u_lightProjectionTexture;         
uniform samplerCube	u_lightProjectionCubemap;
uniform sampler2D u_diffuseTexture;         
uniform sampler2D u_specularTexture;        
uniform sampler2D u_depthTexture;        
#ifndef DISABLE_STENCIL_TEXTURE
uniform usampler2D u_stencilTexture;        
#endif
//uniform samplerCubeShadow u_shadowMap;
uniform samplerCube	u_shadowMap;
         
uniform vec4 	u_lightOrigin;
uniform vec3 	u_lightOrigin2;
uniform vec4 	u_viewOrigin;
uniform vec4 	u_diffuseColor;
uniform vec4 	u_specularColor;

uniform float	u_shadows;    
uniform float	u_advanced;    
uniform float	u_cubic;
uniform int		u_softShadowsQuality;
uniform float	u_softShadowsRadius;
uniform int		u_shadowMipMap;
uniform vec2	u_renderResolution;
uniform mat4	u_modelMatrix;
uniform float	u_RGTC;

// common local variables
vec3 lightDir	= u_lightOrigin.xyz - var_Position;
vec3 viewDir	= u_viewOrigin.xyz - var_Position;

// compute normalized light, view and half angle vectors 
vec3 L = normalize( lightDir ); 
vec3 V = normalize( viewDir ); 
vec3 H = normalize( L + V );

// compute normal from normal map, move from [0, 1] to [-1, 1] range, normalize 
vec4 bumpTexel = texture2D ( u_normalTexture, var_TexNormal.st ) * 2. - 1.;
vec3 RawN = u_RGTC == 1. 
	? vec3(bumpTexel.x, bumpTexel.y, sqrt(max(1.-bumpTexel.x*bumpTexel.x-bumpTexel.y*bumpTexel.y, 0)))
	: normalize( bumpTexel.wyz ); 
vec3 N = var_TangentBitangentNormalMatrix * RawN; 

float NdotH = clamp( dot( N, H ), 0.0, 1.0 );
float NdotL = clamp( dot( N, L ), 0.0, 1.0 );
float NdotV = clamp( dot( N, V ), 0.0, 1.0 );

vec3 lightColor() {
	// compute light projection and falloff 
	vec3 lightColor;
	if (u_cubic == 1.0) {
		vec3 cubeTC = var_TexLight.xyz * 2.0 - 1.0;
		lightColor = textureCube(u_lightProjectionCubemap, cubeTC).rgb;
		float att = clamp(1.0-length(cubeTC), 0.0, 1.0);
		lightColor *= att*att;
	} else {
		vec3 lightProjection = texture2DProj( u_lightProjectionTexture, var_TexLight.xyw ).rgb; 
		vec3 lightFalloff = texture2D( u_lightFalloffTexture, vec2( var_TexLight.z, 0.5 ) ).rgb;
		lightColor = lightProjection * lightFalloff;
	}
	return lightColor;
} 

vec3 simpleInteraction() {
	// compute the diffuse term    
	vec3 diffuse = texture2D( u_diffuseTexture, var_TexDiffuse ).rgb * u_diffuseColor.rgb;

	// compute the specular term
    float specularPower = 10.0;
    float specularContribution = pow( NdotH, specularPower );
	vec3 specular = texture2D( u_specularTexture, var_TexSpecular ).rgb * specularContribution * u_specularColor.rgb;

	// compute lighting model
    vec3 finalColor = ( diffuse + specular ) * NdotL * lightColor() * var_Color.rgb;
 
	return finalColor;
} 

vec3 advancedInteraction() {
	vec4 fresnelParms		= vec4( 1.0, .23, .5, 1.0  );			
	vec4 fresnelParms2		= vec4( .2, .023, 120.0, 4.0 );
	vec4 lightParms			= vec4( .7, 1.8, 10.0, 30.0 );

	vec3 diffuse = texture2D( u_diffuseTexture, var_TexDiffuse ).rgb;

	vec3 specular = vec3(0.026);	//default value if texture not set?...
	if (dot(u_specularColor, u_specularColor) > 0.0)
		specular = texture2D( u_specularTexture, var_TexSpecular ).rgb;

	vec3 localL = normalize(var_tc0);
	vec3 localV = normalize(var_tc6);
	//must be done in tangent space, otherwise smoothing will suffer (see #4958)
	float NdotL = clamp(dot(RawN, localL), 0.0, 1.0);
	float NdotV = clamp(dot(RawN, localV), 0.0, 1.0);
	float NdotH = clamp(dot(RawN, normalize(localV + localL)), 0.0, 1.0);

	// fresnel part, ported from test_direct.vfp
	float fresnelTerm = pow(1.0 - NdotV, fresnelParms2.w);
	float rimLight = fresnelTerm * clamp(NdotL - 0.3, 0.0, fresnelParms.z) * lightParms.y;
	float specularPower = mix(lightParms.z, lightParms.w, specular.z);
	float specularCoeff = pow(NdotH, specularPower) * fresnelParms2.z;
	float fresnelCoeff = fresnelTerm * fresnelParms.y + fresnelParms2.y;

	vec3 specularColor = specularCoeff * fresnelCoeff * specular * (diffuse * 0.25 + vec3(0.75));
	float R2f = clamp(localL.z * 4.0, 0.0, 1.0);
	float light = rimLight * R2f + NdotL;
	vec3 totalColor = (specularColor * R2f + diffuse) * light * u_diffuseColor.rgb * lightColor() * var_Color.rgb;

	return totalColor;
}

uniform vec2 u_softShadowsSamples[150];  //TODO: what cap is appropriate here?

//returns eye Z coordinate with reversed sign (monotonically increasing with depth)
float depthToZ(float depth) {
	float clipZ = 2.0 * depth - 1.0;
	float A = gl_ProjectionMatrix[2].z;
	float B = gl_ProjectionMatrix[3].z;
	return B / (A + clipZ);
}

#ifndef DISABLE_STENCIL_TEXTURE
void StencilSoftShadow() {
	vec2 texSize = u_renderResolution;
	vec2 pixSize = vec2(1.0, 1.0) / texSize;
	vec2 baseTC = gl_FragCoord.xy * pixSize;

	float StTex = float(texture2D( u_stencilTexture, baseTC ).r);
	float stencil = clamp( 129. - StTex, 0., 1.);
	float sumWeight = 1.;

	float LightDist = min(length(lightDir), 1e3); // crutch !
	//radius of light source
	float lightRadius = u_softShadowsRadius;
	//radius of one-point penumbra at the consided point (in world coordinates)
	//note that proper formula is:  lightRadius * (LightDist - OcclDist) / OcclDist;
	float blurRadiusWorld = lightRadius * LightDist / 66.6666;  //TODO: revert?!

	//project direction to light onto surface
	vec3 normal = var_TangentBitangentNormalMatrix[2];
	vec3 alongDirW = normalize(lightDir - dot(lightDir, normal) * normal);
	//get orthogonal direction on surface
	vec3 orthoDirW = cross(normal, alongDirW);
	//multiply the two axes by penumbra radius
	alongDirW *= blurRadiusWorld / max(NdotL, 0.2);  //penumbra is longer by (1/cos(a)) in light direction
	orthoDirW *= blurRadiusWorld;

	//convert both vectors into clip space (get only X and Y components)
	vec2 alongDir = (mat3(gl_ModelViewProjectionMatrix) * alongDirW).xy;
	vec2 orthoDir = (mat3(gl_ModelViewProjectionMatrix) * orthoDirW).xy;
	//now also get W component from multiplication by gl_ModelViewProjectionMatrix
	vec3 mvpRow3 = vec3(gl_ModelViewProjectionMatrix[0][3], gl_ModelViewProjectionMatrix[1][3], gl_ModelViewProjectionMatrix[2][3]);
	float along_w = dot(mvpRow3, alongDirW);
	float ortho_w = dot(mvpRow3, orthoDirW);
	//this is perspective correction: it is necessary because W component in clip space also varies
	//if you remove it and look horizontally parallel to a wall, then vertical shadow boundaries on this wall won't be blurred
	vec2 thisNdc = (2 * baseTC - vec2(1));
	alongDir -= thisNdc * along_w;
	orthoDir -= thisNdc * ortho_w;
	//divide by clip W to get NDC coords (screen coords are half of them)
	alongDir *= gl_FragCoord.w / 2;
	orthoDir *= gl_FragCoord.w / 2;
	//Note: if you want to check the math just above, consider how screen position changes when a point moves in specified direction:
	//  F(t) = divideByW(gl_ModelViewProjectionMatrix * (var_Position + dir_world * t)).xy
	//the converted vector must be equal to the derivative by parameter:
	//  dir_screen = dF/dt (0)
	//(here [dir_world, dir_screen] are either [alongDirW, alongDir] or [orthoDirW, orthoDir])

	//estimate the length of spot ellipse vectors (in pixels)
	float lenX = length(alongDir * texSize);
	float lenY = length(orthoDir * texSize);
	//make sure vectors are sufficiently sampled
	float avgSampleDistInPixels = 2 * max(1e-3 * texSize.y, 1.0);
	float oversize = max(lenX, lenY) / (avgSampleDistInPixels * sqrt(0.0 + u_softShadowsQuality));
	if (oversize > 1) {
		alongDir /= oversize;
		orthoDir /= oversize;
	}

#if ENABLE_ANTI_HALO_PATCH
	//compute partial derivatives of eye -Z by screen X and Y (normalized)
	float Z00 = depthToZ(gl_FragCoord.z);
	vec2 dzdxy = vec2(dFdx(Z00), dFdy(Z00));
	//this is a stupid version, which gets derivatives from depth texture:
/*	float Z00 = depthToZ(texture(u_depthTexture, baseTC).r);
	float Zp0 = depthToZ(texture(u_depthTexture, baseTC + vec2(pixSize.x, 0)).r);
	float Zm0 = depthToZ(texture(u_depthTexture, baseTC - vec2(pixSize.x, 0)).r);
	float Z0p = depthToZ(texture(u_depthTexture, baseTC + vec2(0, pixSize.y)).r);
	float Z0m = depthToZ(texture(u_depthTexture, baseTC - vec2(0, pixSize.y)).r);
	float dzdx = (abs(Zp0 - Z00) < abs(Z00 - Zm0) ? Zp0 - Z00 : Z00 - Zm0);
	float dzdy = (abs(Z0p - Z00) < abs(Z00 - Z0m) ? Z0p - Z00 : Z00 - Z0m);
	vec2 dzdxy = vec2(dzdx, dzdy);*/
	//rescale to derivatives by texture coordinates (not pixels)
	dzdxy *= texSize;
	//compute Z derivatives on a theoretical wall visible under 45-degree angle
	vec2 tanFovHalf = vec2(1.0 / gl_ProjectionMatrix[0][0], 1.0 / gl_ProjectionMatrix[1][1]);
	vec2 canonDerivs = 2.0 * Z00 * tanFovHalf;
#endif

	for( int i = 0; i < u_softShadowsQuality; i++ ) {
		vec2 delta = u_softShadowsSamples[i].x * alongDir + u_softShadowsSamples[i].y * orthoDir;
		vec2 StTc = baseTC + delta;
#if ENABLE_ANTI_HALO_PATCH
		float Zdiff = depthToZ(texture2D(u_depthTexture, StTc).r) - Z00;
		float tangentZdiff = dot(dzdxy, delta);
		float deg45diff = dot(canonDerivs, abs(delta));
		float weight = float(abs(Zdiff - tangentZdiff) <= abs(tangentZdiff) * 0.5 + deg45diff * 0.2);
#else
		float ZDiff = (gl_FragCoord.z-texture( u_depthTexture, StTc ).r) / gl_FragCoord.w;
		float weight = 1. / (1. + ZDiff*ZDiff);
#endif
		float StTex = float(texture2D( u_stencilTexture, StTc ).r);
		stencil += clamp( 129. - StTex, 0., 1. ) * weight;
		sumWeight += weight;
	}
	gl_FragColor.rgb *= stencil / sumWeight;
	/*vec2 StTc = baseTC + vec2(1, 0) * 1e-2;
	StTex = texture( u_stencilTexture, StTc ).r;
	stencil = .25*(128. - StTex);
	gl_FragColor.rgb = vec3(stencil, -stencil, stencil==0?.3:0);
	*/
}
#endif

void main() {
	if (u_advanced == 1.0)
		gl_FragColor.rgb = advancedInteraction();
	else
		gl_FragColor.rgb = simpleInteraction();
	                           
#ifndef DISABLE_STENCIL_TEXTURE
	if (u_shadows == 1. && u_softShadowsQuality > 0) 
		StencilSoftShadow();
#endif

    gl_FragColor.a = 1.0;              
}
interaction_oldgl.fs (10,748 bytes)   
duzenko

duzenko

28.01.2019 13:28

developer   ~0011521

I mean the particular problem reported by actual users, not your experience with VMWare
duzenko

duzenko

03.02.2019 15:06

developer   ~0011537

@Nightcrawler

Can you try the current MESA driver version?
duzenko

duzenko

09.02.2019 09:35

developer   ~0011553

At revision: 7948
Revision: 15621
duzenko

duzenko

19.02.2019 18:27

developer   ~0011625

Please could anyone test and report this
Nightcrawler

Nightcrawler

29.03.2019 23:55

reporter   ~0011699

Just tested the latest 2.07-hotfix and that bug is gone :)

No need to install the newest MESA driver (atm I use OpenGL version: 4.4 Mesa 18.2.8).

Sorry for the waiting...
duzenko

duzenko

05.05.2019 17:41

developer   ~0011784

Ready to close?
stgatilov

stgatilov

06.05.2019 02:52

developer   ~0011786

Fixed in 2.07-hotfix (just released).

Issue History

Date Modified Username Field Change
17.01.2019 00:20 Nightcrawler New Issue
17.01.2019 00:20 Nightcrawler File Added: light_bug_screenshots.zip
17.01.2019 02:09 Springheel Note Added: 0011368
17.01.2019 02:23 nbohr1more Note Added: 0011370
17.01.2019 02:26 nbohr1more Note Added: 0011371
17.01.2019 11:11 STiFU Status new => acknowledged
17.01.2019 11:11 STiFU Product Version => TDM 2.07
17.01.2019 11:11 STiFU Target Version => TDM 2.07
17.01.2019 19:05 Nightcrawler File Added: Darkmod.cfg
17.01.2019 19:08 Nightcrawler Note Added: 0011400
18.01.2019 12:40 duzenko Note Added: 0011403
18.01.2019 12:58 Nightcrawler Note Added: 0011406
18.01.2019 15:27 nbohr1more Relationship added related to 0004961
18.01.2019 15:28 nbohr1more Note Added: 0011411
20.01.2019 16:13 Nightcrawler File Added: graphicsIssue.dump
20.01.2019 16:15 Nightcrawler Note Added: 0011447
22.01.2019 15:37 nbohr1more Note Added: 0011473
22.01.2019 15:37 nbohr1more Target Version TDM 2.07 => TDM 2.08
22.01.2019 15:39 nbohr1more Note Edited: 0011473 View Revisions
27.01.2019 13:36 stgatilov Note Added: 0011517
27.01.2019 13:37 stgatilov Note Edited: 0011517 View Revisions
27.01.2019 14:40 duzenko Note Added: 0011518
28.01.2019 12:53 stgatilov Note Added: 0011520
28.01.2019 12:54 stgatilov Note Edited: 0011520 View Revisions
28.01.2019 12:54 stgatilov File Added: interaction_oldgl.fs
28.01.2019 13:28 duzenko Note Added: 0011521
03.02.2019 15:06 duzenko Note Added: 0011537
09.02.2019 09:33 duzenko Assigned To => duzenko
09.02.2019 09:33 duzenko Status acknowledged => assigned
09.02.2019 09:35 duzenko Note Added: 0011553
09.02.2019 09:35 duzenko Status assigned => resolved
09.02.2019 09:35 duzenko Fixed in Version => SVN
09.02.2019 09:35 duzenko Resolution open => fixed
19.02.2019 18:27 duzenko Note Added: 0011625
19.02.2019 18:28 duzenko Status resolved => feedback
19.02.2019 18:28 duzenko Resolution fixed => reopened
29.03.2019 23:55 Nightcrawler Note Added: 0011699
29.03.2019 23:55 Nightcrawler Status feedback => assigned
05.05.2019 17:41 duzenko Note Added: 0011784
06.05.2019 02:52 stgatilov Target Version TDM 2.08 => TDM 2.07
06.05.2019 02:52 stgatilov Note Added: 0011786
06.05.2019 02:52 stgatilov Status assigned => resolved
06.05.2019 02:52 stgatilov Fixed in Version SVN => TDM 2.07
06.05.2019 02:52 stgatilov Resolution reopened => fixed