• Create Account

# Deferred Shading: point light and bounding volume

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.

31 replies to this topic

### #21froop  Members   -  Reputation: 642

Like
0Likes
Like

Posted 08 May 2011 - 08:15 AM

In that tutorial they reconstruct position from depth which is fine.

Are you sure that the sphere has the correct radius? I had this once when I used a sphere that was too small.

### #22enigmagame  Members   -  Reputation: 140

Like
0Likes
Like

Posted 08 May 2011 - 10:40 AM

In that tutorial they reconstruct position from depth which is fine.

It's right, in fact storing also x and y positions don't change the results.

Are you sure that the sphere has the correct radius? I had this once when I used a sphere that was too small.

I don't understand very well. What you intend?

### #23n3Xus  Members   -  Reputation: 922

Like
0Likes
Like

Posted 09 May 2011 - 04:16 AM

You must make you sphere smaller or bigger depending on the maximum light range. You should have a unit sphere (a sphere with radius 1) and then scale this sphere by the maximum light range using a scale matrix, so you end up with a matrix for a sphere which is like this:

sphereWorldMatrix=sphereScaleMatrix*sphereTranslationMatrix.

### #24froop  Members   -  Reputation: 642

Like
0Likes
Like

Posted 09 May 2011 - 01:35 PM

Yeah, or instead of using a matrix, in the vertex shader multiply the sphere vertices by your lightrange and add the translation offset.

### #25enigmagame  Members   -  Reputation: 140

Like
0Likes
Like

Posted 10 May 2011 - 01:58 AM

You must make you sphere smaller or bigger depending on the maximum light range. You should have a unit sphere (a sphere with radius 1) and then scale this sphere by the maximum light range using a scale matrix, so you end up with a matrix for a sphere which is like this:

sphereWorldMatrix=sphereScaleMatrix*sphereTranslationMatrix.

Yes, but I already do that, the vertex shader receive the world matrix (for the sphere) that you've wrote above. I think that the problem isn't here.
The problem is the clear cut, that you can see in all the screenshot that I've linked in the precedents post.
]

### #26Hodgman  Moderators   -  Reputation: 48364

Like
0Likes
Like

Posted 10 May 2011 - 02:53 AM

That's because there's no connection between the range of your light and the size of your sphere.....

### #27enigmagame  Members   -  Reputation: 140

Like
0Likes
Like

Posted 10 May 2011 - 02:58 AM

That's because there's no connection between the range of your light and the size of your sphere.....

Do you mean the attenuation? Because if I use the original attenuation formula described on the tutorial:

//surface-to-light vector
float3 lightVector = lightPosition - position;
//compute attenuation based on distance - linear attenuation
float attenuation = saturate(1.0f - length(lightVector)/lightRadius);


I obtain the same, wrong, result.

### #28Hodgman  Moderators   -  Reputation: 48364

Like
0Likes
Like

Posted 10 May 2011 - 03:10 AM

The range of your light is determined by your attenuation function, yes.

This is pretty straight-forward. Any pixel that has a greater-than-zero attenuation result MUST be covered by your sphere mesh. If you sphere mesh doesn't cover pixels with >0 attenuation, you're going to get a hard edge where pixels stop being lit.

Solve your attenuation function to find out what the maximum range of lit pixels is, and then make your sphere that big.

### #29enigmagame  Members   -  Reputation: 140

Like
0Likes
Like

Posted 10 May 2011 - 03:59 AM

Solve your attenuation function to find out what the maximum range of lit pixels is, and then make your sphere that big.

Sorry, but I don't understand very well. I'm a bit confused.
I've correctly understood the problem that you've explained, but not the solution.

### #30Hodgman  Moderators   -  Reputation: 48364

Like
1Likes
Like

Posted 10 May 2011 - 04:44 AM

In the attenuation function you posted, the attenuation becomes zero at a distance of 'lightRadius' units from the centre of the light. Any pixels further than this distance away will not be lit.

Also, any pixels outside of your sphere will not be lit.

Therefore the radius of your sphere should be at least 'lightRadius' units to avoid getting the hard-line where a pixel that should've been lit, isn't (due to it not being covered by the sphere).

### #31enigmagame  Members   -  Reputation: 140

Like
1Likes
Like

Posted 10 May 2011 - 12:13 PM

Ok guys, I've found the problem, and it was a very, very, very stupid problem: the size of the sphere mesh.
I was convinced, very convinced, that the size was 1, but I was wrong.
I've created a new mesh, and this is the results:

It seems correct. You confirm?
Thanks.

### #32MajorTom  Members   -  Reputation: 734

Like
0Likes
Like

Posted 10 May 2011 - 12:42 PM

I've created a new mesh, and this is the results:

Yeah, looks fine.
It's easy to over look things, it's always best to narrow down where the problem could be, in this case the size of the sphere.
Nice work.

Saving the world, one semi-colon at a time.

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