Volumetric lightshafts via GPU

A place to show off your latest screenshots and for people to comment on them. Only start a new thread here if you have some nice images to show off!
User avatar
Lexx
Kobold
Posts: 34
Joined: Fri Mar 16, 2007 1:19 am
Location: Russia

Volumetric lightshafts via GPU

Post by Lexx » Sun Apr 06, 2008 3:00 pm

Hi guys
This is demo of gpu-based volumetric lightshafts, described by Kenny Mitchell (EA) in GPUGems3. Demo code and algo based on sources of Sebastien Hillaire (http://sebastien.hillaire.free.fr/demos ... godray.htm) and ported to Ogre by me.

pics:
Image
Image

source and demo(vs2010)
http://www.mediafire.com/?535a3bfv03286za
http://www.megaupload.com/?d=MG9J0HUN

As like Sebastien, i have found a bug with current code (just fly around model in scene and u'll see it). Kenny Mitchell write about this:

Code: Select all

when facing perpendicular to the source, the light's screen-space location can tend toward infinity and therefore lead to large separation between samples. This can be diminished by clamping the screen-space location to an appropriate guard-band region. Alternatively, the effect can be faded toward the perpendicular and is further decreased when using an occlusion method.
So, can anyone please tell me, how can i clamp screenspace light position? I'm lost with it...
Last edited by Lexx on Fri Aug 26, 2011 2:19 pm, edited 1 time in total.
0 x

User avatar
spookyboo
Silver Sponsor
Silver Sponsor
Posts: 1139
Joined: Tue Jul 06, 2004 5:57 am
x 15
Contact:

Post by spookyboo » Sun Apr 06, 2008 3:07 pm

Very impressive!
0 x

Cobra8472
Halfling
Posts: 83
Joined: Thu Jun 02, 2005 4:44 pm

Post by Cobra8472 » Sun Apr 06, 2008 3:37 pm

Very Very impressive! Looks great
0 x

User avatar
Brocan
Orc
Posts: 441
Joined: Tue Aug 01, 2006 1:43 am
Location: Spain!!

Post by Brocan » Sun Apr 06, 2008 5:16 pm

Amazing!
0 x


User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19261
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
Contact:

Post by sinbad » Sun Apr 06, 2008 5:44 pm

Very nice, thanks for sharing!

As for clamping screen space light, can't you just use min/max/saturate?
0 x

User avatar
Lexx
Kobold
Posts: 34
Joined: Fri Mar 16, 2007 1:19 am
Location: Russia

Post by Lexx » Sun Apr 06, 2008 7:10 pm

I was trying to clamp/saturate light position in screen space, but coordinates of light in screen space is totally wrong. They can be for example [-1, -1] / [1, 1] (in a corner on screen space plane), when nonclamped value is [475, 816, 700](some point on the screen, not in a corner).
For rprojection of light vector to screen space, i use:

Code: Select all

Ogre::Vector3 vCamPos = m_pMainCamera->getRealPosition();
Ogre::Vector3 vSunPos = m_pSunLight->getDerivedPosition();
Ogre::Vector3 camToLightVector = vSunPos - vCamPos;

Ogre::Vector3 lightInCamSpace;
Ogre::Vector3 hcsPosition = m_pMainCamera->getProjectionMatrix() * m_pMainCamera->getViewMatrix() * camToLightVector; 
lightInCamSpace.x = 0.5 - hcsPosition.x * 0.5f;
lightInCamSpace.x = 1.0 - lightInCamSpace.x;
lightInCamSpace.y = hcsPosition.y * 0.5f + 0.5;
lightInCamSpace.y = 1.0 - lightInCamSpace.y;
lightInCamSpace.z = camToLightVector.z;
fpParams->setNamedConstant("screenLightPos", lightInCamSpace);
This code worked, when angle between camera direction and light vector is smaller than 90 degree.
I have search this problem in gamedev.net, and found topic with a same (as i think) problem. Guys were discussing about some kind of "pre-perspective" and "post-perspective" projection state... My english is sux (as like a my math ^^), so i don't understand anything of those math terms...
So, any help is welcome! :)

PS: sorry for my evil english :)
0 x

David Lancaster
Gnoblar
Posts: 2
Joined: Thu May 04, 2006 9:19 am

Post by David Lancaster » Mon Apr 07, 2008 1:05 am

Congrats that is amazing!
0 x

User avatar
cybereality
Hobgoblin
Posts: 563
Joined: Wed Jul 12, 2006 5:40 pm

Post by cybereality » Mon Apr 07, 2008 2:22 am

Wow, most impressive. This is the kinda stuff that makes ogre the best!
0 x

User avatar
altren
Gnome
Posts: 316
Joined: Tue Oct 24, 2006 9:02 am
Location: Moscow, Russa
Contact:

Post by altren » Mon Apr 07, 2008 9:15 am

Looks really good. One strange thing is that if i don't see an part of object - I don't see its shadow, so when I see only small part of object - shadow is incorrect.
0 x
Image

Jaiza
Gnoblar
Posts: 12
Joined: Thu Aug 23, 2007 5:49 am
Location: Brisbane, Australia

Post by Jaiza » Mon Apr 07, 2008 12:59 pm

wow! looks really neat
0 x

warmi
Gnoll
Posts: 674
Joined: Sun May 27, 2007 3:56 am
Location: USA

Post by warmi » Mon Apr 07, 2008 5:05 pm

Looks good but gee.. the download service is the worst I have ever seen.

It could serve as a study how to make your user life misreable ( which is probably the point , given that they have a paid service )
0 x

User avatar
Lexx
Kobold
Posts: 34
Joined: Fri Mar 16, 2007 1:19 am
Location: Russia

Post by Lexx » Mon Apr 07, 2008 10:18 pm

altren:
>One strange thing is that if i don't see an part of object - I don't >see its shadow, so when I see only small part of object - shadow >is incorrect.

yep, there's a lot of bugs and errors in rendering algorithm, like:

- worked only for screen quad

Code: Select all

As occluding objects cross the image's boundary, the shafts will flicker, because they are beyond the range of visible samples. This artifact may be reduced by rendering an extended region around the screen to increase the range of addressable samples.
Kenny Mitchell(c)
- wrong depth intersection
Image
this can be fixed with some kind of per-pixel depth checking

- wrong code for projection of light vector to screen-space
Image
i don't know how to fix this...

- for rendering black non-textured objects of the scene i use evil external technique with vertex shader... :/

etc.. So, there's a lot of space for optimization ;)
0 x

broli
Halfling
Posts: 48
Joined: Fri Mar 31, 2006 5:08 pm

Post by broli » Mon Apr 07, 2008 11:27 pm

When does that last issue arise? Also what editor is that in the background :p.
0 x

User avatar
detox
Greenskin
Posts: 103
Joined: Thu Sep 07, 2006 1:13 am
Location: Ohio, USA
Contact:

Post by detox » Tue Apr 08, 2008 3:16 pm

Very nice work. Thank you for sharing the code!
0 x

User avatar
jingjie
Kobold
Posts: 35
Joined: Mon Jul 18, 2005 5:00 am

Post by jingjie » Wed Apr 30, 2008 5:37 am

Lexx wrote:I was trying to clamp/saturate light position in screen space, but coordinates of light in screen space is totally wrong. They can be for example [-1, -1] / [1, 1] (in a corner on screen space plane), when nonclamped value is [475, 816, 700](some point on the screen, not in a corner).
For rprojection of light vector to screen space, i use:

Code: Select all

Ogre::Vector3 vCamPos = m_pMainCamera->getRealPosition();
Ogre::Vector3 vSunPos = m_pSunLight->getDerivedPosition();
Ogre::Vector3 camToLightVector = vSunPos - vCamPos;

Ogre::Vector3 lightInCamSpace;
Ogre::Vector3 hcsPosition = m_pMainCamera->getProjectionMatrix() * m_pMainCamera->getViewMatrix() * camToLightVector; 
lightInCamSpace.x = 0.5 - hcsPosition.x * 0.5f;
lightInCamSpace.x = 1.0 - lightInCamSpace.x;
lightInCamSpace.y = hcsPosition.y * 0.5f + 0.5;
lightInCamSpace.y = 1.0 - lightInCamSpace.y;
lightInCamSpace.z = camToLightVector.z;
fpParams->setNamedConstant("screenLightPos", lightInCamSpace);
You can make easy function "saturate" that transforms from coordinate space [-1, 1] to [0, 1]. :D

Code: Select all

 Ogre::Vector3 saturate ( const Ogre::Vector3& point , const Ogre::Camera& cam)
{
     // Transform the 3D point into screen space
     Ogre::Vector3 result = camera.getProjectionMatrix() * (camera.getViewMatrix() *   
   point);

     // Transform from coordinate space [-1, 1] to [0, 1] and update in-value
     result.x = (result.x / 2) + 0.5f;
     result.y = 1 - ((result.y / 2) + 0.5f);
     return result;
}
0 x

User avatar
GlobalExplorer
Halfling
Posts: 82
Joined: Sat Oct 14, 2006 12:39 pm
Location: Berlin

Post by GlobalExplorer » Thu May 01, 2008 12:27 pm

depositfiles sucks ass!!
0 x

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Post by jacmoe » Thu Dec 18, 2008 10:10 pm

Seems like we lost it. :(
I'd be a happy coder if someone would be so kind and upload it! :)
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

User avatar
Lexx
Kobold
Posts: 34
Joined: Fri Mar 16, 2007 1:19 am
Location: Russia

Post by Lexx » Fri Dec 19, 2008 12:18 am

Hi there, I'm here \o/
fcking depositfiles.com...

there's new links:
source: http://www.sendspace.com/file/5v7ubz
demo: http://www.sendspace.com/file/2nqfsm

duh... looks like sendspace is another <sensored> service...

source: http://www.savefile.com/files/1937851
demo: http://www.savefile.com/files/1937855
0 x

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Post by jacmoe » Fri Dec 19, 2008 12:51 am

Cool! Thanks a lot! :D
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

User avatar
xadhoom
Minaton
Posts: 973
Joined: Fri Dec 28, 2007 4:35 pm
Location: Germany

Post by xadhoom » Fri Dec 19, 2008 11:38 am

I recommend this server: http://www.mediafire.com/

Its as easy as it should and (currently) reliable...
0 x

mapleleaf
Gnoblar
Posts: 8
Joined: Fri Aug 21, 2009 3:27 am

I can't download

Post by mapleleaf » Fri Aug 21, 2009 3:40 am

I can't download because is not connected to the download link. :(

Please repair...........
0 x
Hello.

User avatar
boyamer
Orc
Posts: 459
Joined: Sat Jan 24, 2009 11:16 am
Location: Italy

Re: Volumetric lightshafts via GPU

Post by boyamer » Fri Aug 21, 2009 9:26 am

Me too,anyone can provide a working link please?
0 x

User avatar
Lexx
Kobold
Posts: 34
Joined: Fri Mar 16, 2007 1:19 am
Location: Russia

Re: Volumetric lightshafts via GPU

Post by Lexx » Sun Aug 30, 2009 9:44 am

0 x

chenxiaobang3
Gnoblar
Posts: 7
Joined: Wed Aug 26, 2009 11:37 am

Re: Volumetric lightshafts via GPU

Post by chenxiaobang3 » Sun Aug 30, 2009 12:42 pm

I can't download either. :( :( :( :(
0 x

Post Reply