Sign in to follow this  
gboxentertainment

OpenGL Voxel Cone Tracing Experiment - Part 2 Progress

Recommended Posts

jcabeleira    723

Interesting results, I think it's time for you to get a more complex scene to evaluate your implementation. It would be nice to see that running on a room scene or some exterior scene with walls and buidlings around you.

 


The area is currently only limited to this scene (i'm using a single 64x64x64 3D texture), but I intend to have a go at this "camera-centred cascades" idea to see if I can get consistent interactive framerates for a much larger scene. The main concern I have with using cascades is that it involves dynamically shifting the volume texture, thus leading to large scale flickering. This flickering is evident when I move around emissive objects in my current implementation.

 

Yup, I can confirm that camera centered cascades will result in large flickering. I've tested that my self on my own implementation of Voxel Cone Tracing and I can say that it simply doesn't look good.

Share this post


Link to post
Share on other sites

Yup, I can confirm that camera centered cascades will result in large flickering. I've tested that my self on my own implementation of Voxel Cone Tracing and I can say that it simply doesn't look good.

 

hmm...

I'm thinking now that cascades do not have to be camera-centred. I might have an alternative idea.

Edited by gboxentertainment

Share this post


Link to post
Share on other sites
jcabeleira    723

hmm...
I'm thinking now that cascades do not have to be camera-centred. I might have an alternative idea.

 

What do you have in mind?

 

If you are thinking about keeping the volume centered on the camera but snapping it to the voxel grid then I can tell you before hand that it doesn't solve the problem either. My approach did that and there was still lots of flickering when the volume changed position. smile.png

Edited by jcabeleira

Share this post


Link to post
Share on other sites
FreneticPonE    3294

What is quality difference of screenspace reflections vs just using cone tracing reflections? Also have you tested voxel space ambient oclusion?

 

I imagine both are dependent on voxel resolution. Which reminds to point out Directed Acylic Graphs for Voxels: http://www.cse.chalmers.se/~uffe/HighResolutionSparseVoxelDAGs.pdf Which seems like a fantastic win for reflections and thin object problems both.

 

I also don't remember any flickering in Epic's Elemental demo, despite some quite vast areas using cascaded octree levels. I can't remember if they mentioned flickering being a problem though.

Edited by Frenetic Pony

Share this post


Link to post
Share on other sites

YMMV? Snapping to voxel grid positions after N number of steps/distance works fine for almost all of the flickering I've had. How are you voxelizing the scene?

 

This actually describes a much better way of understanding a possible implementation of my idea.

As well as doing this, I am thinking of using something similar to partially resident textures (because most of us, especially with nvidia hardware still are not able to use them yet).

We piece together multiple smaller high-res textures, together with larger lower-res textures to simulate cascaded partially resident textures.

The biggest problem is that there may be texture seams between texture edges which cannot be hardware filtered (this must be done manually).

Has anyone tried this yet?

Share this post


Link to post
Share on other sites

 

I also don't remember any flickering in Epic's Elemental demo, despite some quite vast areas using cascaded octree levels. I can't remember if they mentioned flickering being a problem though.

 

 

I'm pretty sure the flickering problem shouldn't occur with octrees - the main reason being that instead of sampling directly from a 3D texture, they aren't limited in their filtering method to offset the sampling by each voxel. With octrees, they can offset by half a voxel, if I understand Crassin's paper correctly.

Edited by gboxentertainment

Share this post


Link to post
Share on other sites

I think Frenetic mentioned to me once about something that I guess would be called "Voxel Temporal Anti-aliasing".

I tried to implement it but couldn't get it working - but now that I think about it - I only tried it for the lowest level voxels (highest res).

Majority of the flickering actually occurs at mid-level.

 

I think the way to implement it is to fade in/fade out the color of adjacent voxels based on the position of the object within each voxel so that it smoothly interpolates instead of jumping from 0 to 1.

 

Has anyone tried something like this yet?

Share this post


Link to post
Share on other sites
jcabeleira    723

I'm pretty sure the flickering problem shouldn't occur with octrees - the main reason being that instead of sampling directly from a 3D texture, they aren't limited in their filtering method to offset the sampling by each voxel. With octrees, they can offset by half a voxel, if I understand Crassin's paper correctly.

 

They don't have any flickering because the octree allows them to store the entire voxelized scene. Their lighting is stable because they don't need to have a moving voxel volume that only covers the scene partially. However, the octree is probably impractical for many games because larger scenes may not fit inside the 512x512x512 texture they use to store the voxel bricks.

Edited by jcabeleira

Share this post


Link to post
Share on other sites

I've just re-viewed the original UE4 walkthrough demo (back from when they were showing off their fancy new lighting tech - which they later removed and covered up) and noticed that there is flickering in the reflection of the gold statue on the floor when he moves it. The emissive object that he moves around (the fire hammer) also flickers but its hard to differentiate that from the flickering effect that they purposely used. There's also some noticeable flickering of the indirect lighting when he moves the "spotlight planet" around. I never actually noticed any of this before.

 

I then went to have another look at Crassin's video and paid close attention to the hand's reflection on the floor when he demonstrates the specularity control - I had to pinpoint the exact moment, but it flickers! This occurs most abruptly when the specular cone ratio was turned to medium, but when it was either high(diffuse) or very low(reflective), then its smooth.

 

So it seems that the solution to this problem is neither to do with octrees or voxel resolution or filtering, which is good for me because it doesn't really give too much incentives to using octrees.

Share this post


Link to post
Share on other sites

What is quality difference of screenspace reflections vs just using cone tracing reflections?

 

For a true comparison, I turned up the voxel resolution to 256 (left) and turned off any fade effects from the ssr (right).

 

[attachment=18166:giboxvct.png][attachment=18167:giboxssr.png]

 

To tell you the truth - I am simply just using SSRs to fake reflections that I cannot yet achieve with VCT (but one day in the future I may be able to).

 

The biggest issue that I can't seem to figure out with my VCT reflections though, is the transparency. I'm not sure if this is anything to do with the way I filter my voxels.

Each ray should terminate when it accumulates full opacity. So when a ray hits the surface of the orange box it should terminate when it detects that its opacity is 1, but it doesn't, instead, it continues on, accumulating everything that is behind it.

 

Here's the specular cone tracing code if anyone wants to analyze it:

vec4 specConeTrace(vec3 o, vec3 d, float coneRatio, float maxDist)
{
	vec3 samplePos = o;
	vec4 accum = vec4(0.0);
	float minDiam = 1.0/voxDim;
	float startDist = 2*minDiam;

	float dist = startDist;
	while(dist <= maxDist && accum.w < 1.0)
	{		
		float sampleDiam = max(minDiam, coneRatio*dist);
		float sampleLOD = log2(sampleDiam*voxDim);
		vec3 samplePos = o + d*dist;
		vec4 sampleVal = sampleSpecVox(samplePos, -d, sampleLOD);

		float sampleWt = (1.0 - accum.w);
		accum += sampleVal * sampleWt;

		dist += sampleDiam;
	}

	accum.xyz *= 2.0;

	return accum;
}

Share this post


Link to post
Share on other sites
kalle_h    2464
        float sampleWt = (1.0 - accum.w);
        accum += sampleVal * sampleWt;

There is bug. With full opaque voxel you get zero value for sampleWT. Or am I missing something?

Share this post


Link to post
Share on other sites
Chris_F    3030

 

What is quality difference of screenspace reflections vs just using cone tracing reflections?

 

For a true comparison, I turned up the voxel resolution to 256 (left) and turned off any fade effects from the ssr (right).

 

attachicon.gifgiboxvct.pngattachicon.gifgiboxssr.png

 

To tell you the truth - I am simply just using SSRs to fake reflections that I cannot yet achieve with VCT (but one day in the future I may be able to).

 

The biggest issue that I can't seem to figure out with my VCT reflections though, is the transparency. I'm not sure if this is anything to do with the way I filter my voxels.

Each ray should terminate when it accumulates full opacity. So when a ray hits the surface of the orange box it should terminate when it detects that its opacity is 1, but it doesn't, instead, it continues on, accumulating everything that is behind it.

 

Here's the specular cone tracing code if anyone wants to analyze it:

vec4 specConeTrace(vec3 o, vec3 d, float coneRatio, float maxDist)
{
	vec3 samplePos = o;
	vec4 accum = vec4(0.0);
	float minDiam = 1.0/voxDim;
	float startDist = 2*minDiam;

	float dist = startDist;
	while(dist <= maxDist && accum.w < 1.0)
	{		
		float sampleDiam = max(minDiam, coneRatio*dist);
		float sampleLOD = log2(sampleDiam*voxDim);
		vec3 samplePos = o + d*dist;
		vec4 sampleVal = sampleSpecVox(samplePos, -d, sampleLOD);

		float sampleWt = (1.0 - accum.w);
		accum += sampleVal * sampleWt;

		dist += sampleDiam;
	}

	accum.xyz *= 2.0;

	return accum;
}

 

Why are your voxel reflections transparent?

 

EDIT: Nevermind. I need to read first.

Edited by Chris_F

Share this post


Link to post
Share on other sites

Okay, so I'm going to answer my own question about the transparent voxel reflections.

For diffuse reflections (or glossy but not clearly reflective) I had to divide my alpha samples by a factor (say 10 in this case) during filtering, otherwise ugly voxel artifacts occur on the surface - as seen below on the sphere and the red wall (which are glossy but not entirely reflective - specular cone ratios of 0.4).

 

[attachment=18175:giboxvct2.png]

 

The floor, which has a specular cone ratio of 0.01, is now showing clear reflections without transparency.

Of course this scene only runs at about 7fps because I turned up the voxel resolution to 256 to demonstrate the effect.

Share this post


Link to post
Share on other sites
Styves    1792

Heh, I'll ask again since it seems my question was skipped: how are you downsampling your voxel data? This might play a role in the issue you're having.

Edited by Styves

Share this post


Link to post
Share on other sites
jcabeleira    723

Another reason for the transparency is that you are sampling the voxels along the view ray but none of the samples hits the exact center of an opaque voxel so they never achieve full opacity. This is because the voxel volume texture is configured to use bilinear filtering so whenever you sample an opaque voxel without hitting its center you get a partially transparent result that is the interpolation between the opaque voxel and the neighboring transparent ones.

Share this post


Link to post
Share on other sites

Heh, I'll ask again since it seems my question was skipped: how are you downsampling your voxel data? This might play a role in the issue you're having.

 

I'm pretty certain I've solved my issue. But for your interest:

The same method that this guy uses:

http://www.geeks3d.com/20121214/voxel-cone-tracing-global-illumination-in-opengl-4-3/

 

I use hardware mip-mapping and then filtering with the compute shader by transferring values for each 3x3x3 voxels to neighbouring voxels in each direction.

 

Btw, I've also posted a video at the bottom of the start of my thread.

Edited by gboxentertainment

Share this post


Link to post
Share on other sites

I think Frenetic mentioned to me once about something that I guess would be called "Voxel Temporal Anti-aliasing".
I tried to implement it but couldn't get it working - but now that I think about it - I only tried it for the lowest level voxels (highest res).
Majority of the flickering actually occurs at mid-level.
 
I think the way to implement it is to fade in/fade out the color of adjacent voxels based on the position of the object within each voxel so that it smoothly interpolates instead of jumping from 0 to 1.

 

I'm trying to re-attempt this but I just realised I don't actually know how to track how much each part of an object is within a voxel. Originally I had thought of accessing the geometry shader stage of my voxelization and storing the difference between the position of each voxel and triangle.

Then I set my input for alpha into the voxel texture as 1-density. But this doesn't help the flickering - it actually makes it worse because when my alpha value is set to one, it reduces the color bleeding of the entire scene. Thus it flickers between color bleeding and little color bleeding - leading to flashing.

Edited by gboxentertainment

Share this post


Link to post
Share on other sites

In my attempts of trying to reduce flickering I have come across an unusual discovery:

 

There is much less mid-level flickering in the z direction than there is in the x direction. i.e. Flickering caused by voxels at lod = 1 and lod = 2 is much less in the z direction (as opposed to lod = 0 (densest level), where there is the same amount of flickering no matter what direction).

 

Looking at the debug view I noticed that when I switch to lod = 1 debug, there seems to be much more information captured in the voxels in the x direction, than in the z direction:

 

[attachment=18352:gibox-debug0.jpg]

 

As you can notice in the above image, the voxels are a lot thicker on the facing surfaces of the left and right walls than on the wall at the very back.

 

Originally, a while ago when I had first discovered this, I had thought that this must be caused by some incorrect filtering during the mip-map stage. But I have checked my code many many times and voxels are filtered in exactly the same manner in each direction.

 

There must be something that I'm doing wrong during the mip-mapping stage which requires further investigation.

Share this post


Link to post
Share on other sites

So it turns out I had misinterpreted the original code that my method is based on. I am in fact manually mip-mapping to downsample my voxels.

#version 430

layout(local_size_x = 16, local_size_y = 8, local_size_z = 1) in;

layout(binding = 0, rgba8) uniform image3D srcMip;
layout(binding = 1, rgba8) uniform image3D dstMip;

uniform uint direction;

void main()
{
	ivec3 dstSize = imageSize(dstMip);

	if(gl_GlobalInvocationID.x >= dstSize.x || gl_GlobalInvocationID.y >= dstSize.y || gl_GlobalInvocationID.z >= dstSize.z){
		// out of range, ignore
	} else {
		ivec3 dstPos = ivec3(gl_GlobalInvocationID);
		ivec3 srcPos = dstPos*2;
		vec4 outColor;

		vec4 srcCol0 = imageLoad(srcMip, srcPos + ivec3(0,0,0));
		vec4 srcCol1 = imageLoad(srcMip, srcPos + ivec3(1,0,0));
		vec4 srcCol2 = imageLoad(srcMip, srcPos + ivec3(2,0,0));
		vec4 srcCol3 = imageLoad(srcMip, srcPos + ivec3(0,1,0));
		vec4 srcCol4 = imageLoad(srcMip, srcPos + ivec3(1,1,0));
		vec4 srcCol5 = imageLoad(srcMip, srcPos + ivec3(2,1,0));
		vec4 srcCol6 = imageLoad(srcMip, srcPos + ivec3(0,2,0));
		vec4 srcCol7 = imageLoad(srcMip, srcPos + ivec3(1,2,0));
		vec4 srcCol8 = imageLoad(srcMip, srcPos + ivec3(2,2,0));

		vec4 srcCol9 = imageLoad(srcMip, srcPos + ivec3(0,0,1));
		vec4 srcCol10 = imageLoad(srcMip, srcPos + ivec3(1,0,1));
		vec4 srcCol11 = imageLoad(srcMip, srcPos + ivec3(2,0,1));
		vec4 srcCol12 = imageLoad(srcMip, srcPos + ivec3(0,1,1));
		vec4 srcCol13 = imageLoad(srcMip, srcPos + ivec3(1,1,1));
		vec4 srcCol14 = imageLoad(srcMip, srcPos + ivec3(2,1,1));
		vec4 srcCol15 = imageLoad(srcMip, srcPos + ivec3(0,2,1));
		vec4 srcCol16 = imageLoad(srcMip, srcPos + ivec3(1,2,1));
		vec4 srcCol17 = imageLoad(srcMip, srcPos + ivec3(2,2,1));

		vec4 srcCol18 = imageLoad(srcMip, srcPos + ivec3(0,0,2));
		vec4 srcCol19 = imageLoad(srcMip, srcPos + ivec3(1,0,2));
		vec4 srcCol20 = imageLoad(srcMip, srcPos + ivec3(2,0,2));
		vec4 srcCol21 = imageLoad(srcMip, srcPos + ivec3(0,1,2));
		vec4 srcCol22 = imageLoad(srcMip, srcPos + ivec3(1,1,2));
		vec4 srcCol23 = imageLoad(srcMip, srcPos + ivec3(2,1,2));
		vec4 srcCol24 = imageLoad(srcMip, srcPos + ivec3(0,2,2));
		vec4 srcCol25 = imageLoad(srcMip, srcPos + ivec3(1,2,2));
		vec4 srcCol26 = imageLoad(srcMip, srcPos + ivec3(2,2,2));

	if(direction == 0) {
		//+X direction
		outColor.xyz = mix(srcCol0.xyz, srcCol1.xyz, 1.0 - srcCol0.w)
					+ mix(srcCol1.xyz, srcCol2.xyz, 1.0 - srcCol1.w)
					+ mix(srcCol3.xyz, srcCol4.xyz, 1.0 - srcCol3.w)
					+ mix(srcCol4.xyz, srcCol5.xyz, 1.0 - srcCol4.w)
					+ mix(srcCol6.xyz, srcCol7.xyz, 1.0 - srcCol6.w)
					+ mix(srcCol7.xyz, srcCol8.xyz, 1.0 - srcCol7.w)

					+ mix(srcCol9.xyz, srcCol10.xyz, 1.0 - srcCol9.w)
					+ mix(srcCol10.xyz, srcCol11.xyz, 1.0 - srcCol10.w)
					+ mix(srcCol12.xyz, srcCol13.xyz, 1.0 - srcCol12.w)
					+ mix(srcCol13.xyz, srcCol14.xyz, 1.0 - srcCol13.w)
					+ mix(srcCol15.xyz, srcCol16.xyz, 1.0 - srcCol15.w)
					+ mix(srcCol16.xyz, srcCol17.xyz, 1.0 - srcCol16.w)
					
					+ mix(srcCol18.xyz, srcCol19.xyz, 1.0 - srcCol18.w)
					+ mix(srcCol19.xyz, srcCol20.xyz, 1.0 - srcCol19.w)
					+ mix(srcCol21.xyz, srcCol22.xyz, 1.0 - srcCol21.w)
					+ mix(srcCol22.xyz, srcCol23.xyz, 1.0 - srcCol22.w)
					+ mix(srcCol24.xyz, srcCol25.xyz, 1.0 - srcCol24.w)
					+ mix(srcCol25.xyz, srcCol26.xyz, 1.0 - srcCol25.w);
		outColor.w = 4.0 - (1.0 - srcCol0.w) * (1.0 - srcCol1.w)
						- (1.0 - srcCol1.w) * (1.0 - srcCol2.w)
						- (1.0 - srcCol3.w) * (1.0 - srcCol4.w)
						- (1.0 - srcCol4.w) * (1.0 - srcCol5.w)
						- (1.0 - srcCol6.w) * (1.0 - srcCol7.w)
						- (1.0 - srcCol7.w) * (1.0 - srcCol8.w)
						
						- (1.0 - srcCol9.w) * (1.0 - srcCol10.w)
						- (1.0 - srcCol10.w) * (1.0 - srcCol11.w)
						- (1.0 - srcCol12.w) * (1.0 - srcCol13.w)
						- (1.0 - srcCol13.w) * (1.0 - srcCol14.w)
						- (1.0 - srcCol15.w) * (1.0 - srcCol16.w)
						- (1.0 - srcCol16.w) * (1.0 - srcCol17.w)
						
						- (1.0 - srcCol18.w) * (1.0 - srcCol19.w)
						- (1.0 - srcCol19.w) * (1.0 - srcCol20.w)
						- (1.0 - srcCol21.w) * (1.0 - srcCol22.w)
						- (1.0 - srcCol22.w) * (1.0 - srcCol23.w)
						- (1.0 - srcCol24.w) * (1.0 - srcCol25.w)
						- (1.0 - srcCol25.w) * (1.0 - srcCol26.w);

	} else if(direction == 1) {
		//-X direction
		outColor.xyz = mix(srcCol1.xyz, srcCol0.xyz, 1.0 - srcCol1.w)
					+ mix(srcCol2.xyz, srcCol1.xyz, 1.0 - srcCol2.w)
					+ mix(srcCol4.xyz, srcCol3.xyz, 1.0 - srcCol4.w)
					+ mix(srcCol5.xyz, srcCol4.xyz, 1.0 - srcCol5.w)
					+ mix(srcCol7.xyz, srcCol6.xyz, 1.0 - srcCol7.w)
					+ mix(srcCol8.xyz, srcCol7.xyz, 1.0 - srcCol8.w)

					+ mix(srcCol10.xyz, srcCol9.xyz, 1.0 - srcCol10.w)
					+ mix(srcCol11.xyz, srcCol10.xyz, 1.0 - srcCol11.w)
					+ mix(srcCol13.xyz, srcCol12.xyz, 1.0 - srcCol13.w)
					+ mix(srcCol14.xyz, srcCol13.xyz, 1.0 - srcCol14.w)
					+ mix(srcCol16.xyz, srcCol15.xyz, 1.0 - srcCol16.w)
					+ mix(srcCol17.xyz, srcCol16.xyz, 1.0 - srcCol17.w)
					
					+ mix(srcCol19.xyz, srcCol18.xyz, 1.0 - srcCol19.w)
					+ mix(srcCol20.xyz, srcCol19.xyz, 1.0 - srcCol20.w)
					+ mix(srcCol22.xyz, srcCol21.xyz, 1.0 - srcCol22.w)
					+ mix(srcCol23.xyz, srcCol22.xyz, 1.0 - srcCol23.w)
					+ mix(srcCol25.xyz, srcCol24.xyz, 1.0 - srcCol25.w)
					+ mix(srcCol26.xyz, srcCol25.xyz, 1.0 - srcCol26.w);
		outColor.w = 4.0 - (1.0 - srcCol1.w) * (1.0 - srcCol0.w)
						- (1.0 - srcCol2.w) * (1.0 - srcCol1.w)
						- (1.0 - srcCol4.w) * (1.0 - srcCol3.w)
						- (1.0 - srcCol5.w) * (1.0 - srcCol4.w)
						- (1.0 - srcCol7.w) * (1.0 - srcCol6.w)
						- (1.0 - srcCol8.w) * (1.0 - srcCol7.w)

						- (1.0 - srcCol10.w) * (1.0 - srcCol9.w)
						- (1.0 - srcCol11.w) * (1.0 - srcCol10.w)
						- (1.0 - srcCol13.w) * (1.0 - srcCol12.w)
						- (1.0 - srcCol14.w) * (1.0 - srcCol13.w)
						- (1.0 - srcCol16.w) * (1.0 - srcCol15.w)
						- (1.0 - srcCol17.w) * (1.0 - srcCol16.w)
						
						- (1.0 - srcCol19.w) * (1.0 - srcCol18.w)
						- (1.0 - srcCol20.w) * (1.0 - srcCol19.w)
						- (1.0 - srcCol22.w) * (1.0 - srcCol21.w)
						- (1.0 - srcCol23.w) * (1.0 - srcCol22.w)
						- (1.0 - srcCol25.w) * (1.0 - srcCol24.w)
						- (1.0 - srcCol26.w) * (1.0 - srcCol25.w);

	} else if(direction == 2) {
		//+Y direction
		outColor.xyz = mix(srcCol0.xyz, srcCol3.xyz, 1.0 - srcCol0.w)
					+ mix(srcCol3.xyz, srcCol6.xyz, 1.0 - srcCol3.w)
					+ mix(srcCol1.xyz, srcCol4.xyz, 1.0 - srcCol1.w)
					+ mix(srcCol4.xyz, srcCol7.xyz, 1.0 - srcCol4.w)
					+ mix(srcCol2.xyz, srcCol5.xyz, 1.0 - srcCol2.w)
					+ mix(srcCol5.xyz, srcCol8.xyz, 1.0 - srcCol5.w)

					+ mix(srcCol9.xyz, srcCol12.xyz, 1.0 - srcCol9.w)
					+ mix(srcCol12.xyz, srcCol15.xyz, 1.0 - srcCol12.w)
					+ mix(srcCol10.xyz, srcCol13.xyz, 1.0 - srcCol10.w)
					+ mix(srcCol13.xyz, srcCol16.xyz, 1.0 - srcCol13.w)
					+ mix(srcCol11.xyz, srcCol14.xyz, 1.0 - srcCol11.w)
					+ mix(srcCol14.xyz, srcCol17.xyz, 1.0 - srcCol14.w)
					
					+ mix(srcCol18.xyz, srcCol21.xyz, 1.0 - srcCol18.w)
					+ mix(srcCol21.xyz, srcCol24.xyz, 1.0 - srcCol21.w)
					+ mix(srcCol19.xyz, srcCol22.xyz, 1.0 - srcCol19.w)
					+ mix(srcCol22.xyz, srcCol25.xyz, 1.0 - srcCol22.w)
					+ mix(srcCol20.xyz, srcCol23.xyz, 1.0 - srcCol20.w)
					+ mix(srcCol23.xyz, srcCol26.xyz, 1.0 - srcCol23.w);
		outColor.w = 4.0 - (1.0 - srcCol0.w) * (1.0 - srcCol3.w)
						- (1.0 - srcCol3.w) * (1.0 - srcCol6.w)
						- (1.0 - srcCol1.w) * (1.0 - srcCol4.w)
						- (1.0 - srcCol4.w) * (1.0 - srcCol7.w)
						- (1.0 - srcCol2.w) * (1.0 - srcCol5.w)
						- (1.0 - srcCol5.w) * (1.0 - srcCol8.w)
						
						- (1.0 - srcCol9.w) * (1.0 - srcCol12.w)
						- (1.0 - srcCol12.w) * (1.0 - srcCol15.w)
						- (1.0 - srcCol10.w) * (1.0 - srcCol13.w)
						- (1.0 - srcCol13.w) * (1.0 - srcCol16.w)
						- (1.0 - srcCol11.w) * (1.0 - srcCol14.w)
						- (1.0 - srcCol14.w) * (1.0 - srcCol17.w)
						
						- (1.0 - srcCol18.w) * (1.0 - srcCol21.w)
						- (1.0 - srcCol21.w) * (1.0 - srcCol24.w)
						- (1.0 - srcCol19.w) * (1.0 - srcCol22.w)
						- (1.0 - srcCol22.w) * (1.0 - srcCol25.w)
						- (1.0 - srcCol20.w) * (1.0 - srcCol23.w)
						- (1.0 - srcCol23.w) * (1.0 - srcCol26.w);
	} 
	else if(direction == 3) {
		//-Y direction
		outColor.xyz = mix(srcCol3.xyz, srcCol0.xyz, 1.0 - srcCol3.w)
					+ mix(srcCol6.xyz, srcCol3.xyz, 1.0 - srcCol6.w)
					+ mix(srcCol4.xyz, srcCol1.xyz, 1.0 - srcCol4.w)
					+ mix(srcCol7.xyz, srcCol4.xyz, 1.0 - srcCol7.w)
					+ mix(srcCol5.xyz, srcCol2.xyz, 1.0 - srcCol5.w)
					+ mix(srcCol8.xyz, srcCol5.xyz, 1.0 - srcCol8.w)
					
					+ mix(srcCol15.xyz, srcCol12.xyz, 1.0 - srcCol15.w)
					+ mix(srcCol12.xyz, srcCol9.xyz, 1.0 - srcCol12.w)
					+ mix(srcCol16.xyz, srcCol13.xyz, 1.0 - srcCol16.w)
					+ mix(srcCol13.xyz, srcCol10.xyz, 1.0 - srcCol13.w)
					+ mix(srcCol17.xyz, srcCol14.xyz, 1.0 - srcCol17.w)
					+ mix(srcCol14.xyz, srcCol11.xyz, 1.0 - srcCol14.w)
					
					+ mix(srcCol24.xyz, srcCol21.xyz, 1.0 - srcCol24.w)
					+ mix(srcCol21.xyz, srcCol18.xyz, 1.0 - srcCol21.w)
					+ mix(srcCol25.xyz, srcCol22.xyz, 1.0 - srcCol25.w)
					+ mix(srcCol22.xyz, srcCol19.xyz, 1.0 - srcCol22.w)
					+ mix(srcCol26.xyz, srcCol23.xyz, 1.0 - srcCol26.w)
					+ mix(srcCol23.xyz, srcCol20.xyz, 1.0 - srcCol23.w);
		outColor.w = 4.0 - (1.0 - srcCol3.w) * (1.0 - srcCol0.w)
						- (1.0 - srcCol6.w) * (1.0 - srcCol3.w)
						- (1.0 - srcCol4.w) * (1.0 - srcCol1.w)
						- (1.0 - srcCol7.w) * (1.0 - srcCol4.w)
						- (1.0 - srcCol5.w) * (1.0 - srcCol2.w)
						- (1.0 - srcCol8.w) * (1.0 - srcCol5.w)
						
						- (1.0 - srcCol15.w) * (1.0 - srcCol12.w)
						- (1.0 - srcCol12.w) * (1.0 - srcCol9.w)
						- (1.0 - srcCol16.w) * (1.0 - srcCol13.w)
						- (1.0 - srcCol13.w) * (1.0 - srcCol10.w)
						- (1.0 - srcCol17.w) * (1.0 - srcCol14.w)
						- (1.0 - srcCol14.w) * (1.0 - srcCol11.w)
						
						- (1.0 - srcCol24.w) * (1.0 - srcCol21.w)
						- (1.0 - srcCol21.w) * (1.0 - srcCol18.w)
						- (1.0 - srcCol25.w) * (1.0 - srcCol22.w)
						- (1.0 - srcCol22.w) * (1.0 - srcCol19.w)
						- (1.0 - srcCol23.w) * (1.0 - srcCol23.w)
						- (1.0 - srcCol14.w) * (1.0 - srcCol20.w);
	} else if(direction == 4) {
		//+Z direction
		outColor.xyz = mix(srcCol0.xyz, srcCol9.xyz, 1.0 - srcCol0.w)
					+ mix(srcCol9.xyz, srcCol18.xyz, 1.0 - srcCol9.w)
					+ mix(srcCol1.xyz, srcCol10.xyz, 1.0 - srcCol1.w)
					+ mix(srcCol10.xyz, srcCol19.xyz, 1.0 - srcCol10.w)
					+ mix(srcCol2.xyz, srcCol11.xyz, 1.0 - srcCol2.w)
					+ mix(srcCol11.xyz, srcCol20.xyz, 1.0 - srcCol11.w)

					+ mix(srcCol3.xyz, srcCol12.xyz, 1.0 - srcCol3.w)
					+ mix(srcCol12.xyz, srcCol21.xyz, 1.0 - srcCol12.w)
					+ mix(srcCol4.xyz, srcCol13.xyz, 1.0 - srcCol14.w)
					+ mix(srcCol13.xyz, srcCol22.xyz, 1.0 - srcCol13.w)
					+ mix(srcCol5.xyz, srcCol14.xyz, 1.0 - srcCol5.w)
					+ mix(srcCol14.xyz, srcCol23.xyz, 1.0 - srcCol14.w)
					
					+ mix(srcCol6.xyz, srcCol15.xyz, 1.0 - srcCol6.w)
					+ mix(srcCol15.xyz, srcCol24.xyz, 1.0 - srcCol15.w)
					+ mix(srcCol7.xyz, srcCol16.xyz, 1.0 - srcCol7.w)
					+ mix(srcCol16.xyz, srcCol25.xyz, 1.0 - srcCol16.w)
					+ mix(srcCol8.xyz, srcCol17.xyz, 1.0 - srcCol8.w)
					+ mix(srcCol17.xyz, srcCol26.xyz, 1.0 - srcCol17.w);
		outColor.w = 4.0 - (1.0 - srcCol0.w) * (1.0 - srcCol9.w)
						- (1.0 - srcCol9.w) * (1.0 - srcCol18.w)
						- (1.0 - srcCol1.w) * (1.0 - srcCol10.w)
						- (1.0 - srcCol10.w) * (1.0 - srcCol19.w)
						- (1.0 - srcCol2.w) * (1.0 - srcCol11.w)
						- (1.0 - srcCol11.w) * (1.0 - srcCol20.w)
						
						- (1.0 - srcCol3.w) * (1.0 - srcCol12.w)
						- (1.0 - srcCol12.w) * (1.0 - srcCol21.w)
						- (1.0 - srcCol4.w) * (1.0 - srcCol13.w)
						- (1.0 - srcCol13.w) * (1.0 - srcCol22.w)
						- (1.0 - srcCol5.w) * (1.0 - srcCol14.w)
						- (1.0 - srcCol14.w) * (1.0 - srcCol23.w)
						
						- (1.0 - srcCol6.w) * (1.0 - srcCol15.w)
						- (1.0 - srcCol15.w) * (1.0 - srcCol24.w)
						- (1.0 - srcCol7.w) * (1.0 - srcCol6.w)
						- (1.0 - srcCol16.w) * (1.0 - srcCol25.w)
						- (1.0 - srcCol8.w) * (1.0 - srcCol17.w)
						- (1.0 - srcCol17.w) * (1.0 - srcCol26.w);
	} else if(direction == 5) {
		//-Z direction
		outColor.xyz = mix(srcCol9.xyz, srcCol0.xyz, 1.0 - srcCol9.w)
					+ mix(srcCol18.xyz, srcCol9.xyz, 1.0 - srcCol18.w)
					+ mix(srcCol10.xyz, srcCol1.xyz, 1.0 - srcCol10.w)
					+ mix(srcCol19.xyz, srcCol10.xyz, 1.0 - srcCol19.w)
					+ mix(srcCol11.xyz, srcCol2.xyz, 1.0 - srcCol11.w)
					+ mix(srcCol20.xyz, srcCol11.xyz, 1.0 - srcCol20.w)

					+ mix(srcCol12.xyz, srcCol3.xyz, 1.0 - srcCol12.w)
					+ mix(srcCol21.xyz, srcCol12.xyz, 1.0 - srcCol21.w)
					+ mix(srcCol13.xyz, srcCol4.xyz, 1.0 - srcCol13.w)
					+ mix(srcCol22.xyz, srcCol13.xyz, 1.0 - srcCol22.w)
					+ mix(srcCol14.xyz, srcCol5.xyz, 1.0 - srcCol14.w)
					+ mix(srcCol23.xyz, srcCol14.xyz, 1.0 - srcCol23.w)
					
					+ mix(srcCol15.xyz, srcCol6.xyz, 1.0 - srcCol15.w)
					+ mix(srcCol24.xyz, srcCol15.xyz, 1.0 - srcCol24.w)
					+ mix(srcCol16.xyz, srcCol7.xyz, 1.0 - srcCol16.w)
					+ mix(srcCol25.xyz, srcCol16.xyz, 1.0 - srcCol25.w)
					+ mix(srcCol17.xyz, srcCol8.xyz, 1.0 - srcCol17.w)
					+ mix(srcCol26.xyz, srcCol17.xyz, 1.0 - srcCol26.w);
		outColor.w = 4.0 - (1.0 - srcCol0.w) * (1.0 - srcCol9.w)
						- (1.0 - srcCol9.w) * (1.0 - srcCol18.w)
						- (1.0 - srcCol1.w) * (1.0 - srcCol10.w)
						- (1.0 - srcCol10.w) * (1.0 - srcCol19.w)
						- (1.0 - srcCol2.w) * (1.0 - srcCol11.w)
						- (1.0 - srcCol11.w) * (1.0 - srcCol20.w)
						
						- (1.0 - srcCol3.w) * (1.0 - srcCol12.w)
						- (1.0 - srcCol12.w) * (1.0 - srcCol21.w)
						- (1.0 - srcCol4.w) * (1.0 - srcCol13.w)
						- (1.0 - srcCol13.w) * (1.0 - srcCol22.w)
						- (1.0 - srcCol5.w) * (1.0 - srcCol14.w)
						- (1.0 - srcCol14.w) * (1.0 - srcCol23.w)
						
						- (1.0 - srcCol6.w) * (1.0 - srcCol15.w)
						- (1.0 - srcCol15.w) * (1.0 - srcCol24.w)
						- (1.0 - srcCol7.w) * (1.0 - srcCol6.w)
						- (1.0 - srcCol16.w) * (1.0 - srcCol25.w)
						- (1.0 - srcCol8.w) * (1.0 - srcCol17.w)
						- (1.0 - srcCol17.w) * (1.0 - srcCol26.w);
	}
	
		outColor.xyz *= 0.2;

		imageStore(dstMip, dstPos, outColor);
	}
}

However, I figured out that I have only been transferring my values in the -X direction! because in my shader code:

void TextureManager::mipMapPass(GLuint shader, GLuint tex, int dir, int voxDim)
{
	glUseProgram(shader);

	int workGroupSize[3] = {};
	glGetProgramiv(shader, GL_COMPUTE_WORK_GROUP_SIZE, workGroupSize);
	if (workGroupSize[0] * workGroupSize[1] * workGroupSize[2] == 0){
		cout << "failed to load compute shader" << endl;
		return;
	}

	int mipLevels = GetBitIndex(voxDim) + 1;
	for (int mip = 1; mip < mipLevels; mip++)
	{
		glUniform1ui(glGetUniformLocation(shader, "direction"), dir);

		glBindImageTexture(0, tex, mip - 1, GL_TRUE, 0, GL_READ_ONLY, GL_RGBA8);
		glBindImageTexture(1, tex, mip, GL_TRUE, 0, GL_WRITE_ONLY, GL_RGBA8);

		glDispatchCompute(
			((voxDim >> 1) + workGroupSize[0] - 1) / workGroupSize[0],
			((voxDim >> 1) + workGroupSize[1] - 1) / workGroupSize[1],
			((voxDim >> 1) + workGroupSize[2] - 1) / workGroupSize[2]);
	}
}

I only run this function once with dir = 0.

 

The issue that I'm facing now is when I run this function 6 times for each direction, it doesn't accumulate the values in each direction, instead overwriting the 3d texture with the last direction.

If I use hardware generation of mipmaps and then do the transfer of values to neighbouring voxels in each direction for each mip level, the results come out wrong.

Edited by gboxentertainment

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Similar Content

    • By Zaphyk
      I am developing my engine using the OpenGL 3.3 compatibility profile. It runs as expected on my NVIDIA card and on my Intel Card however when I tried it on an AMD setup it ran 3 times worse than on the other setups. Could this be a AMD driver thing or is this probably a problem with my OGL code? Could a different code standard create such bad performance?
    • By Kjell Andersson
      I'm trying to get some legacy OpenGL code to run with a shader pipeline,
      The legacy code uses glVertexPointer(), glColorPointer(), glNormalPointer() and glTexCoordPointer() to supply the vertex information.
      I know that it should be using setVertexAttribPointer() etc to clearly define the layout but that is not an option right now since the legacy code can't be modified to that extent.
      I've got a version 330 vertex shader to somewhat work:
      #version 330 uniform mat4 osg_ModelViewProjectionMatrix; uniform mat4 osg_ModelViewMatrix; layout(location = 0) in vec4 Vertex; layout(location = 2) in vec4 Normal; // Velocity layout(location = 3) in vec3 TexCoord; // TODO: is this the right layout location? out VertexData { vec4 color; vec3 velocity; float size; } VertexOut; void main(void) { vec4 p0 = Vertex; vec4 p1 = Vertex + vec4(Normal.x, Normal.y, Normal.z, 0.0f); vec3 velocity = (osg_ModelViewProjectionMatrix * p1 - osg_ModelViewProjectionMatrix * p0).xyz; VertexOut.velocity = velocity; VertexOut.size = TexCoord.y; gl_Position = osg_ModelViewMatrix * Vertex; } What works is the Vertex and Normal information that the legacy C++ OpenGL code seem to provide in layout location 0 and 2. This is fine.
      What I'm not getting to work is the TexCoord information that is supplied by a glTexCoordPointer() call in C++.
      Question:
      What layout location is the old standard pipeline using for glTexCoordPointer()? Or is this undefined?
       
      Side note: I'm trying to get an OpenSceneGraph 3.4.0 particle system to use custom vertex, geometry and fragment shaders for rendering the particles.
    • By markshaw001
      Hi i am new to this forum  i wanted to ask for help from all of you i want to generate real time terrain using a 32 bit heightmap i am good at c++ and have started learning Opengl as i am very interested in making landscapes in opengl i have looked around the internet for help about this topic but i am not getting the hang of the concepts and what they are doing can some here suggests me some good resources for making terrain engine please for example like tutorials,books etc so that i can understand the whole concept of terrain generation.
       
    • By KarimIO
      Hey guys. I'm trying to get my application to work on my Nvidia GTX 970 desktop. It currently works on my Intel HD 3000 laptop, but on the desktop, every bind textures specifically from framebuffers, I get half a second of lag. This is done 4 times as I have three RGBA textures and one depth 32F buffer. I tried to use debugging software for the first time - RenderDoc only shows SwapBuffers() and no OGL calls, while Nvidia Nsight crashes upon execution, so neither are helpful. Without binding it runs regularly. This does not happen with non-framebuffer binds.
      GLFramebuffer::GLFramebuffer(FramebufferCreateInfo createInfo) { glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); textures = new GLuint[createInfo.numColorTargets]; glGenTextures(createInfo.numColorTargets, textures); GLenum *DrawBuffers = new GLenum[createInfo.numColorTargets]; for (uint32_t i = 0; i < createInfo.numColorTargets; i++) { glBindTexture(GL_TEXTURE_2D, textures[i]); GLint internalFormat; GLenum format; TranslateFormats(createInfo.colorFormats[i], format, internalFormat); // returns GL_RGBA and GL_RGBA glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, createInfo.width, createInfo.height, 0, format, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); DrawBuffers[i] = GL_COLOR_ATTACHMENT0 + i; glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, textures[i], 0); } if (createInfo.depthFormat != FORMAT_DEPTH_NONE) { GLenum depthFormat; switch (createInfo.depthFormat) { case FORMAT_DEPTH_16: depthFormat = GL_DEPTH_COMPONENT16; break; case FORMAT_DEPTH_24: depthFormat = GL_DEPTH_COMPONENT24; break; case FORMAT_DEPTH_32: depthFormat = GL_DEPTH_COMPONENT32; break; case FORMAT_DEPTH_24_STENCIL_8: depthFormat = GL_DEPTH24_STENCIL8; break; case FORMAT_DEPTH_32_STENCIL_8: depthFormat = GL_DEPTH32F_STENCIL8; break; } glGenTextures(1, &depthrenderbuffer); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); glTexImage2D(GL_TEXTURE_2D, 0, depthFormat, createInfo.width, createInfo.height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(GL_TEXTURE_2D, 0); glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthrenderbuffer, 0); } if (createInfo.numColorTargets > 0) glDrawBuffers(createInfo.numColorTargets, DrawBuffers); else glDrawBuffer(GL_NONE); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) std::cout << "Framebuffer Incomplete\n"; glBindFramebuffer(GL_FRAMEBUFFER, 0); width = createInfo.width; height = createInfo.height; } // ... // FBO Creation FramebufferCreateInfo gbufferCI; gbufferCI.colorFormats = gbufferCFs.data(); gbufferCI.depthFormat = FORMAT_DEPTH_32; gbufferCI.numColorTargets = gbufferCFs.size(); gbufferCI.width = engine.settings.resolutionX; gbufferCI.height = engine.settings.resolutionY; gbufferCI.renderPass = nullptr; gbuffer = graphicsWrapper->CreateFramebuffer(gbufferCI); // Bind glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo); // Draw here... // Bind to textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, textures[0]); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, textures[1]); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, textures[2]); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, depthrenderbuffer); Here is an extract of my code. I can't think of anything else to include. I've really been butting my head into a wall trying to think of a reason but I can think of none and all my research yields nothing. Thanks in advance!
    • By Adrianensis
      Hi everyone, I've shared my 2D Game Engine source code. It's the result of 4 years working on it (and I still continue improving features ) and I want to share with the community. You can see some videos on youtube and some demo gifs on my twitter account.
      This Engine has been developed as End-of-Degree Project and it is coded in Javascript, WebGL and GLSL. The engine is written from scratch.
      This is not a professional engine but it's for learning purposes, so anyone can review the code an learn basis about graphics, physics or game engine architecture. Source code on this GitHub repository.
      I'm available for a good conversation about Game Engine / Graphics Programming
  • Popular Now