Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Approximate Hybrid Raytracing - Work in Progress


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
19 replies to this topic

#1 pachesantiago   Members   -  Reputation: 180

Like
2Likes
Like

Posted 03 April 2014 - 04:04 PM

Hy everyone,

I had been working for the last few months in a method to render reflections / GI  ( and other things too) at real time in mid range hardware, and a few days back I finished a presentation video and applied to the Real Time Live! conference at SIGGRAPH.

Because of that I can't talk details now, but I wanted to show what I had accomplished.

The video is below:

https://www.youtube.com/watch?v=dL_SxY2Njq4

 

As I said at the description, the demo actually runs more fluent, but Camtasia took some of it away.

Anyway, what I can say is that is a combination of standard rasterization and raytracing, supports fully dynamic scenes, doesn't requires extra passes on the geometry( well, the triangles are duplicated, but inside a geometry shader), and is really simple to implement, which leaves a lot of room for improvement and new techniques based on it.


Edited by pachesantiago, 04 April 2014 - 08:24 AM.


Sponsor:

#2 hudovisk   Members   -  Reputation: 140

Like
2Likes
Like

Posted 03 April 2014 - 09:48 PM

Awesome,

 

Can you say which data structure you used to accelerate the intersection test? I'm struggling  to implement my k-d tree efficient enough to use it dynamically.



#3 pachesantiago   Members   -  Reputation: 180

Like
0Likes
Like

Posted 04 April 2014 - 08:27 AM

Awesome,

 

Can you say which data structure you used to accelerate the intersection test? I'm struggling  to implement my k-d tree efficient enough to use it dynamically.

I'm sorry, but I don't want to get into implementation details (ph34r.png ) until I know if I'm accepted / rejected to present at SIGGRAPH.

I can say that I don't use acceleration structures per se , it's more like a brute force raytracer. Next month I should know the verdict, and I'll get into details then.
Hope you understand.



#4 ApochPiQ   Moderators   -  Reputation: 16001

Like
4Likes
Like

Posted 04 April 2014 - 10:48 AM

Unfortunately, from my perspective, the only really interesting part of a demo like this is how it's done. Specifically: what makes your approach superior to the innumerable other demos that purport to accomplish the exact same thing :-)

It's also really hard to discuss a graphics demo without knowing the techniques behind it; I can't tell if your grossly over-saturated diffuse interreflection is an artifact of rendering method or just the result of using too much specular gloss on the floors, for instance.

Having worked in realtime GI back in the days before it was actually hardware-practical, I appreciate the work that goes into a project like this, and I'm certainly not trying to denigrate your efforts. In fact it's probably my background in RTGI that makes me overly critical. What I'd personally rather see (besides the stock castle/banner scene) is stuff like material demos where you illustrate how your technique handles various surface types, especially in combination.

One of my favorite test scenes is Cornell Box variants for exactly that reason. It's a standard scene (even though the castle scene is pretty close to de-facto GI demo standard these days) and for someone with a trained eye it makes it immediately effortless to recognize the strengths and tradeoffs of a given rendering method.

#5 pachesantiago   Members   -  Reputation: 180

Like
0Likes
Like

Posted 04 April 2014 - 12:02 PM

Unfortunately, from my perspective, the only really interesting part of a demo like this is how it's done. Specifically: what makes your approach superior to the innumerable other demos that purport to accomplish the exact same thing :-)

It's also really hard to discuss a graphics demo without knowing the techniques behind it; I can't tell if your grossly over-saturated diffuse interreflection is an artifact of rendering method or just the result of using too much specular gloss on the floors, for instance.

Having worked in realtime GI back in the days before it was actually hardware-practical, I appreciate the work that goes into a project like this, and I'm certainly not trying to denigrate your efforts. In fact it's probably my background in RTGI that makes me overly critical. What I'd personally rather see (besides the stock castle/banner scene) is stuff like material demos where you illustrate how your technique handles various surface types, especially in combination.

One of my favorite test scenes is Cornell Box variants for exactly that reason. It's a standard scene (even though the castle scene is pretty close to de-facto GI demo standard these days) and for someone with a trained eye it makes it immediately effortless to recognize the strengths and tradeoffs of a given rendering method.

I totally understand your point, I know it's hard to talk about something not knowing how it works.
Also, I'm all in for constructive criticism.

Now to the scene related things:
You said you'll like to see different materials, I think I can put together a scene with a bunch of spheres with different reflection amount, gi amount, etc in the next couple hours. Is that what you had in mind?
Regarding the reflections, is mostly the fact I had quite a problem combining the GI , Reflections and Direct Illumination buffers, and making it look good, but is more of an "artistical" problem of sorts wink.png



#6 ApochPiQ   Moderators   -  Reputation: 16001

Like
0Likes
Like

Posted 04 April 2014 - 12:24 PM

Something like that sounds cool, yeah - ideally something that showcases the strengths of your approach as much as you can manage, even if you don't get into any detail on how you pulled it off just yet.

I figured the reflection problem was likely an aesthetic tradeoff. It can be very hard to get multiple layers of GI to play nicely together depending on how you do your rendering, and definitely making them all look good when combined is a real trick.

#7 pachesantiago   Members   -  Reputation: 180

Like
0Likes
Like

Posted 04 April 2014 - 12:49 PM

Something like that sounds cool, yeah - ideally something that showcases the strengths of your approach as much as you can manage, even if you don't get into any detail on how you pulled it off just yet.

I figured the reflection problem was likely an aesthetic tradeoff. It can be very hard to get multiple layers of GI to play nicely together depending on how you do your rendering, and definitely making them all look good when combined is a real trick.

Great then! I should have that scene ready in a couple hours



#8 pachesantiago   Members   -  Reputation: 180

Like
0Likes
Like

Posted 04 April 2014 - 05:57 PM

Well, I ran into some unexpected problems, so it took more than I though.
Here are some screens of a dirty simple Cornell Box:

 

I disabled reflections, as I had some problems getting them to look good on that scene. Just GI for now.
The blur needs a lot of work too, but I believe the idea is there.
As you can see by the FPS, my poor GTX 750 Ti is trying it's best, but is not enough.
the 75 W TDP and mainly the 128 bits bus really hurts performance, as this is a bandwidth-bound algorithm. I ran it a couple times on a 7870, and it runs at twice or more framerate ( 256 bit bus ). 

It depends a lot on the scene and the settings, but I cant get 30 FPS with the 750 Ti at the Sponza scene( wich is actually faster, as a lot of rays collide really close to the start position)

EDIT: Does anyone knows how can I put an images album? Or at least the images one by one, nothing seems to work. For now, here goes the link
https://imgur.com/a/T0SJP


Edited by pachesantiago, 04 April 2014 - 06:01 PM.


#9 pachesantiago   Members   -  Reputation: 180

Like
0Likes
Like

Posted 12 April 2014 - 03:47 PM

Well, I had been working on improving the scene representation, and I managed to increase performance by about 20% - 25% with just a 3 % increase in memory usage and a small increase in the GBuffer stage, but I believe I could tune it up to 30% - 35%. Also now reflections take into account the sky, and I added specular lighting to the GI calculation. 

 

I'm having a problem though, and I wanted to ask you guys. I can't get the blur to work correctly. I'm implementing a Gaussian blur, separated on two passes, with the weights calculated on the fly, as I like to be able to tune the number of samples of the filter. Also, the Gaussian weight is multiplied by 1 / (epsilon + abs(z - depth[sample])) to take into account depth discontinuities. It works, but instead of producing a nice smooth blur, it creates a black cross in the middle. Below is a screen. Rays where reduced to 1 per pixel and strength upped to better display the problem. The blur is using 8 samples and a sigma of 4.3.

 

ywTzM6l.png

 

And here is the code for the horizontal pass. The vertical one is exactly the same, changing float2(1, 0) for float2(0, 1). I read two images, do the horizontal blur to two temp images, do the vertical blur sampling the temp images, and output to the original images.
Texture2D<float> tCoarseDepth : register(t0);
Texture2D<float4> tCoarseNormal : register(t1);
Texture2D<float4> tGI : register(t2);
Texture2D<float4> tRFL : register(t3);

RWTexture2D<float4> output : register(u0);
RWTexture2D<float4> outputRFL : register(u1);

static const float samples = 8;
static const float g_epsilon = 0.0001f;
static const float sigma = 4.3f * 4.3f;

[numthreads(256, 1, 1)]
void BlurH( uint3 DTid : SV_DispatchThreadID )
{
	float z = tCoarseDepth[DTid.xy];

	float4 gi = tGI[DTid.xy];
	float4 rfl = tRFL[DTid.xy];
	float acc = 1;

	float2 spos = float2(1, 0);
	for (float i = 1; i <= samples; i++)
	{
		// Sample right
		//		Calculate weights
		float zWeightR = 1.0f / (g_epsilon + abs(z - tCoarseDepth[DTid.xy + spos*i]));
		float WeightR = zWeightR * GaussianWeight(i, sigma);
		
		//		Sample 
		gi += tGI[DTid.xy + spos*i]* WeightR;
		rfl += tRFL[DTid.xy + spos*i] * WeightR;
		acc += WeightR;
		
		// Sample left
		//		Calculate weights
		float zWeightL = 1.0f / (g_epsilon + abs(z - tCoarseDepth[DTid.xy - spos*i]));
		float WeightL = zWeightL * GaussianWeight(i, sigma);

		//		Sample 
		gi += tGI[DTid.xy - spos*i] * WeightL;
		rfl += tRFL[DTid.xy - spos*i] * WeightL;
		acc += WeightL;
	}
	
	output[DTid.xy] = gi / acc;
	outputRFL[DTid.xy] = rfl / acc;
}

If someone can shed some light, I would be grateful.

There's other thing I want / need to add to my blur shader, and that is to take into account the distance of the pixel, so everything gets the same amount of blur. Right now, things that are too far get too much blur, and things that are to close don't get enough.
I need suggestion on how to do that, I suppose someone here has done it before.

Well, that's it for now, I'll try to keep this thread with some more regular updates, maybe a screen every two or three days.

EDIT: Here's the code for the GaussianWeight function
 

float GaussianWeight(float x,float sigmaSquared)
{
        float alpha = 1.0f / sqrt(2.0f * 3.1416f * sigmaSquared);
	float beta = (x*x) / (2*sigmaSquared);

	return alpha*exp(-beta);
}

Edited by pachesantiago, 12 April 2014 - 03:51 PM.


#10 pachesantiago   Members   -  Reputation: 180

Like
0Likes
Like

Posted 21 April 2014 - 03:53 PM

Anyone have anything to say about the blur problem? I'm still fighting with that.

I'm also having another problem, and I posted on Stack Overflow about it : http://stackoverflow.com/questions/23189808/interlocked-average-cas-not-working-on-hlsl

I'm trying to remove the flickering of the light by storing it using atomic ops, but I can't get it to work correctly. Here's the code I'm using:

[allow_uav_condition] while (true)
{
    // Get old value
    uint old = irradianceVolume[vpos];

    // Average
    float3 avg = saturate((UnpackR5G5B5A1(old) + irradiance) * 0.5f);
    uint final = PackR5G5B5A1(float4(avg, 1));

    // Try to store
    uint ret = -1;
    InterlockedCompareExchange(irradianceVolume[vpos], old, final, ret);

    if (ret == old)
        break;
}

If anyone can say anything, I would really appreciate it.



#11 tonemgub   Members   -  Reputation: 1143

Like
0Likes
Like

Posted 25 April 2014 - 06:42 AM

[numthreads(256, 1, 1)]
void BlurH( uint3 DTid : SV_DispatchThreadID )
{
	float z = tCoarseDepth[DTid.xy];

	float4 gi = tGI[DTid.xy];
	float4 rfl = tRFL[DTid.xy];
	float acc = 1;

	float2 spos = float2(1, 0);
	for (float i = 1; i <= samples; i++)
	{
		// Sample right
		//		Calculate weights
		float zWeightR = 1.0f / (g_epsilon + abs(z - tCoarseDepth[DTid.xy + spos*i]));
		float WeightR = zWeightR * GaussianWeight(i, sigma);
		
		//		Sample 
		gi += tGI[DTid.xy + spos*i]* WeightR;
		rfl += tRFL[DTid.xy + spos*i] * WeightR;
		acc += WeightR;
		
		// Sample left
		//		Calculate weights
		float zWeightL = 1.0f / (g_epsilon + abs(z - tCoarseDepth[DTid.xy - spos*i]));
		float WeightL = zWeightL * GaussianWeight(i, sigma);

		//		Sample 
		gi += tGI[DTid.xy - spos*i] * WeightL;
		rfl += tRFL[DTid.xy - spos*i] * WeightL;
		acc += WeightL;
	}
	
	output[DTid.xy] = gi / acc;
	outputRFL[DTid.xy] = rfl / acc;
}
float GaussianWeight(float x,float sigmaSquared)
{
        float alpha = 1.0f / sqrt(2.0f * 3.1416f * sigmaSquared);
	float beta = (x*x) / (2*sigmaSquared);

	return alpha*exp(-beta);
}

This is a pretty classic brain fart. You're passing integer sample points [1..samples] to the gaussian function, but the domain of the gaussian is [-inf, +inf]. You should be passing GaussianWeight(i - centre, sigma_sq), where centre is the middle sample. Here centre = (samples+1) / 2 = 4.5. People conventionally use an odd number of samples to get an integer centre. You've also labelled your sigma squared constant as sigma, that was a little confusing.

There's other thing I want / need to add to my blur shader, and that is to take into account the distance of the pixel, so everything gets the same amount of blur. Right now, things that are too far get too much blur, and things that are to close don't get enough.
I need suggestion on how to do that, I suppose someone here has done it before.

This may not work well with a separable blur like this one, it would create anisotropic blur as different size kernels mix together on the second pass.

#12 pachesantiago   Members   -  Reputation: 180

Like
0Likes
Like

Posted 26 April 2014 - 09:49 AM


This is a pretty classic brain fart. You're passing integer sample points [1..samples] to the gaussian function, but the domain of the gaussian is [-inf, +inf]. You should be passing GaussianWeight(i - centre, sigma_sq), where centre is the middle sample. Here centre = (samples+1) / 2 = 4.5. People conventionally use an odd number of samples to get an integer centre. You've also labelled your sigma squared constant as sigma, that was a little confusing.

Thanks! Tried that, and it works better now. Still, I have some things to fix.
Anyone knows something about the atomic average problem I mentioned earlier? Still struggling with that.



#13 pachesantiago   Members   -  Reputation: 180

Like
3Likes
Like

Posted 03 May 2014 - 08:48 PM

I managed to implement a better material model, one similar to the one found on Blender's Cycles render engine(pathtracing), but simplified.
Only two types of materials exist. One is a Diffuse material, that has it's rays distributed around the normal hemisphere, and the other is a Glossy material, that has it's rays distributed around the reflection hemisphere. 
A value in the [0,1] range defines how much angle does the rays have with the hemisphere base(the normal for Diffuse materials, the reflection vector for Glossy materials)

Both materials can have their own tracing parameters, such as rays, samples per rays, samples displacement, etc, and can be combined as you like.

 

I'll try to upload a video tomorrow, but here are some screens. The screens show only a Glossy material, because is the most interesting one. More materials and combinations later. Also, to combine direct and indirect I'm just doing lerp(shadowMask,direct,indirect) that's why there's so much difference. I have to find a better way to mix the materials( that's up for the artists rolleyes.gif ?)

No blur
wRuVeui.png

 

7Yw1ZP4.png

 

G3A2coe.png

 

8 Samples Depth-Aware Gaussian blur

GpZHJJy.png

 

gScLWls.png

 

qYHrWkJ.png

 

Well, that's it for today. If I don't get to post the video tomorrow, don't expect anything from me on the next two weeks. Exams period on college wink.png .



#14 pachesantiago   Members   -  Reputation: 180

Like
0Likes
Like

Posted 14 May 2014 - 06:02 PM

Just a quick post. I played a bit with raytraced shadows, using AHR. Here are some (preliminary) results:
6SxS9PJ.png



#15 pachesantiago   Members   -  Reputation: 180

Like
0Likes
Like

Posted 15 May 2014 - 08:03 AM

Today I found out I was rejected to present my technique at SIGGRAPH, so I'm now open to talk about the technique, but I don't know how to continue from here. Should I do a tutorial, some kind of article, a downloadable demo? Maybe try to integrate it with some enigne, like Unity or UDK? Should I make a new post here on GameDev? What are other places where I can make this idea public?
If anyone can provide some suggestions, I would be really glad, as I said, I don't know where to move with this from now on. I'll continue improving it though.

#16 ApochPiQ   Moderators   -  Reputation: 16001

Like
0Likes
Like

Posted 15 May 2014 - 06:56 PM

How big of a presentation are you wanting to make? A journal series is best if you want to talk about processes you went though during development; an article is best if you just want to talk about the technique itself; and if you want to discuss it, this thread should be perfect :-)



#17 pachesantiago   Members   -  Reputation: 180

Like
0Likes
Like

Posted 17 May 2014 - 08:35 AM

How big of a presentation are you wanting to make? A journal series is best if you want to talk about processes you went though during development; an article is best if you just want to talk about the technique itself; and if you want to discuss it, this thread should be perfect :-)

Ok so I think that for now, I'll keep with this thread, and discuss about it. Ask away!
When I have it more polished, maybe I'll make an article.
Also I plan to try to enter next year GDC. Can't hurt trying, plus according to the SIGGRAPH reviewers, I was really close to make it.
AHR needs, as they pointed out, more polish and also compare it to other techniques.



#18 pachesantiago   Members   -  Reputation: 180

Like
0Likes
Like

Posted 25 June 2014 - 10:43 PM

I uploaded a new video, is at youtube now : https://www.youtube.com/watch?v=AXnAkTmGPyE



#19 Samith   Members   -  Reputation: 2260

Like
0Likes
Like

Posted 25 June 2014 - 10:57 PM

Looks pretty good. I'd love to know more about your technique. What's hybrid about it? And what's approximate about it? Have you given an explanation (even in broad terms) anywhere about your process?



#20 Rbn_3D   Members   -  Reputation: 102

Like
0Likes
Like

Posted 10 August 2014 - 03:49 AM

Could you share more details?

A playable demo maybe?

 

Looks really promising.

 

Are you taking in account the G-buffer to compute GI? or just world space data?

What about spreading the work across frames? Or even guess wich areas needs to be updated (based on lighting changes, moving objects, etc) at runtime.

 

Could be really useful for architectural visualization.

 

Keep up the good work!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS