View Issue Details

IDProjectCategoryView StatusLast Update
0004888The Dark ModCodingpublic07.12.2018 14:30
Reporterduzenko Assigned Tostgatilov  
PrioritynormalSeveritynormalReproducibilityhave not tried
Status assignedResolutionopen 
Summary0004888: Teriible precision in light frustums
DescriptionLight->lightDef->frustum and Light->frustumTris don't match
Steps To ReproduceUse the map from attached map (originally posted on http://forums.thedarkmod.com/topic/19659-feature-request-emissive-materialsvolumetric-lights/) and the shaders
TagsNo tags attached.

Activities

duzenko

duzenko

27.09.2018 15:39

developer  

volumetric.fs (2,307 bytes)   
#version 430

layout(binding=0) uniform sampler2D s_projection;
layout(binding=1) uniform sampler2D s_falloff;
layout(binding=2) uniform sampler2D s_depth;

layout (location = 0) uniform mat4 u_MVP;
//layout (location = 1) uniform vec3 u_lightOrigin;
layout (location = 2) uniform vec3 u_viewOrigin;
layout (location = 3) uniform mat4 u_lightProject;
layout (location = 4) uniform vec4 u_lightFrustum[6];

in vec4 csLight;
in vec4 csThis;
in vec4 lightProject;
in vec4 worldPosition;

void main() {
	vec2 wrCoord = csThis.xy/csThis.w * .5 + .5;
	float depth = texture2D(s_depth, wrCoord ).r;
/*	if(depth < gl_FragCoord.z)
		discard;*/
	
	vec3 dirToViewer = normalize(u_viewOrigin - worldPosition.xyz);
	// where does the fragment-viewer ray leave the light frustum?

	float minRayCoord = -1e11; 
	vec3 rayPlaneIntersection[6]; 
	for(int i=0; i<6; i++) {  // https://stackoverflow.com/questions/23975555/how-to-do-ray-plane-intersection
		if(i!=2)
			;//continue;
		float top = dot(u_lightFrustum[i], worldPosition);
		float bottom = dot(u_lightFrustum[i].xyz, dirToViewer);
		if(abs(bottom) < 1e-3) { // special case, ray parallel to plane
			continue; 
		}
		float rayCoord = top / bottom;
		if(rayCoord > -1e-1) { // tested plane is the rendered plane
			continue;          // at least one of these must be zero (the plane being rendered now)
		}
		if(rayCoord < minRayCoord)
			continue;
		minRayCoord = rayCoord;
	}
	vec3 exitPoint = worldPosition.xyz - minRayCoord * dirToViewer;
	
	vec4 samplePos = worldPosition;
	vec3 color = vec3(0);
	color = vec3(distance(exitPoint, worldPosition.xyz)*1e-2);
	if(minRayCoord > 0)
		minRayCoord *= sin(gl_FragCoord.x*1e-1);
	color = vec3(abs(minRayCoord))*vec3(1e-2, 1e-3, 1e-4)*1e0;
	for(int i=0; i<20; i++) {
		vec4 sampleClip = u_MVP * samplePos;
		if(sampleClip.z <= 0)
			break;
		float sampleDepth = sampleClip.z/sampleClip.w * .5 + .5;
		if(sampleDepth < depth) {
			vec4 lightProject = samplePos * u_lightProject;
			vec4 t0 = texture2DProj(s_projection, lightProject.xyz );
			//color += t0.rgb * 0.05;
			//color += .05;
		}
		samplePos.xyz += dirToViewer * 3e0;
		//color += vec3(1e-2);
	}

	gl_FragColor.rgb = color.rgb * 1e0;
	//gl_FragColor.rg = wrCoord;
	//gl_FragColor.b = .1;
}
volumetric.fs (2,307 bytes)   
duzenko

duzenko

27.09.2018 15:39

developer  

volumetric.vs (440 bytes)
duzenko

duzenko

27.09.2018 15:42

developer  

glowtest_v03.pk4 (4,197,038 bytes)
stgatilov

stgatilov

07.12.2018 08:38

administrator   ~0010844

Oops, I got assigned =)

Any detail?
What to look at? Or it would be obvious after loading map?
And also:
Why do you think it is precision problem?
Any place in the code where to start looking from?

I'm pretty sure you know more, so I'm trying to extract additional information from you =)
duzenko

duzenko

07.12.2018 14:24

developer  

Untitled.jpg (361,601 bytes)
duzenko

duzenko

07.12.2018 14:24

developer   ~0010845

There might be more than one issue here, but let's start with the most obvious one

You can see on any "projected" light, e.g. on the window light in the room on the screenshot (It's below the water reservoir in the tower, map St Albans Cathedral)

http://bugs.thedarkmod.com/file_download.php?file_id=660&type=bug

r_singleLight x where x is the window light index, then
r_showlights 3, then noclip inside the light frustum and close up enough to see frustum edge cracks

This does not show up on the existing maps but the new experimental volumetric light make it very visible.
duzenko

duzenko

07.12.2018 14:28

developer   ~0010846

Last edited: 07.12.2018 14:30

View 2 revisions

I was able to track it down briefly to R_PolytopeSurface where I logged tri->verts for the 'projected' light and, after text-sorting vertex coordinates, can see that the same frustum corner has slightly different coordinates on different frustum planes (this particular data is for a light in Vol.L. demo map, not StAlbans)

1014.867188 316.531250 -64.437500
1014.867432 316.544800 -64.448486
1014.869507 316.562500 -64.453125
1016.601563 525.773438 -210.953125
1016.606506 525.751282 -210.936584
1016.609070 525.780579 -210.949265
774.837097 316.049744 -64.101852
774.843750 316.062500 -64.125000
774.843750 316.092590 -64.124115
776.585938 526.242188 -211.296875
776.598999 526.250000 -211.281250
776.625427 526.242981 -211.280823
896.000000 568.000000 72.000000
896.001953 568.000000 72.031250
896.007813 567.968750 72.000000
896.007813 567.988281 71.968750

EDIT
The real calculation seems to occur in idWinding::ClipInPlace

Issue History

Date Modified Username Field Change
27.09.2018 15:39 duzenko New Issue
27.09.2018 15:39 duzenko File Added: volumetric.fs
27.09.2018 15:39 duzenko File Added: volumetric.vs
27.09.2018 15:42 duzenko File Added: glowtest_v03.pk4
06.12.2018 16:22 duzenko Assigned To => stgatilov
06.12.2018 16:22 duzenko Status new => assigned
07.12.2018 08:38 stgatilov Note Added: 0010844
07.12.2018 14:24 duzenko File Added: Untitled.jpg
07.12.2018 14:24 duzenko Note Added: 0010845
07.12.2018 14:28 duzenko Note Added: 0010846
07.12.2018 14:30 duzenko Note Edited: 0010846 View Revisions