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
x 1

Volumetric lightshafts via GPU

Post by Lexx »

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.
User avatar
spookyboo
Silver Sponsor
Silver Sponsor
Posts: 1141
Joined: Tue Jul 06, 2004 5:57 am
x 151
Contact:

Post by spookyboo »

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

Post by Cobra8472 »

Very Very impressive! Looks great
User avatar
Brocan
Orc
Posts: 441
Joined: Tue Aug 01, 2006 1:43 am
Location: Spain!!
x 8

Post by Brocan »

Amazing!
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 66
Contact:

Post by sinbad »

Very nice, thanks for sharing!

As for clamping screen space light, can't you just use min/max/saturate?
User avatar
Lexx
Kobold
Posts: 34
Joined: Fri Mar 16, 2007 1:19 am
Location: Russia
x 1

Post by Lexx »

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 :)
David Lancaster
Gnoblar
Posts: 2
Joined: Thu May 04, 2006 9:19 am

Post by David Lancaster »

Congrats that is amazing!
User avatar
cybereality
Hobgoblin
Posts: 563
Joined: Wed Jul 12, 2006 5:40 pm
x 12

Post by cybereality »

Wow, most impressive. This is the kinda stuff that makes ogre the best!
User avatar
altren
Gnome
Posts: 329
Joined: Tue Oct 24, 2006 9:02 am
Location: Moscow, Russa
x 24
Contact:

Post by altren »

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.
Image
Jaiza
Gnoblar
Posts: 12
Joined: Thu Aug 23, 2007 5:49 am
Location: Brisbane, Australia

Post by Jaiza »

wow! looks really neat
warmi
Gnoll
Posts: 674
Joined: Sun May 27, 2007 3:56 am
Location: USA

Post by warmi »

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 )
User avatar
Lexx
Kobold
Posts: 34
Joined: Fri Mar 16, 2007 1:19 am
Location: Russia
x 1

Post by Lexx »

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 ;)
broli
Halfling
Posts: 48
Joined: Fri Mar 31, 2006 5:08 pm

Post by broli »

When does that last issue arise? Also what editor is that in the background :p.
User avatar
detox
Greenskin
Posts: 103
Joined: Thu Sep 07, 2006 1:13 am
Location: Ohio, USA
Contact:

Post by detox »

Very nice work. Thank you for sharing the code!
User avatar
jingjie
Kobold
Posts: 35
Joined: Mon Jul 18, 2005 5:00 am

Post by jingjie »

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;
}
User avatar
GlobalExplorer
Halfling
Posts: 82
Joined: Sat Oct 14, 2006 12:39 pm
Location: Berlin
x 1

Post by GlobalExplorer »

depositfiles sucks ass!!
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post by jacmoe »

Seems like we lost it. :(
I'd be a happy coder if someone would be so kind and upload it! :)
/* 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
x 1

Post by Lexx »

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
User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
x 179
Contact:

Post by jacmoe »

Cool! Thanks a lot! :D
/* 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
x 1

Post by xadhoom »

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

Its as easy as it should and (currently) reliable...
mapleleaf
Gnoblar
Posts: 8
Joined: Fri Aug 21, 2009 3:27 am

I can't download

Post by mapleleaf »

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

Please repair...........
Hello.
User avatar
boyamer
Orc
Posts: 459
Joined: Sat Jan 24, 2009 11:16 am
Location: Italy
x 6

Re: Volumetric lightshafts via GPU

Post by boyamer »

Me too,anyone can provide a working link please?
User avatar
Lexx
Kobold
Posts: 34
Joined: Fri Mar 16, 2007 1:19 am
Location: Russia
x 1

Re: Volumetric lightshafts via GPU

Post by Lexx »

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

Re: Volumetric lightshafts via GPU

Post by chenxiaobang3 »

I can't download either. :( :( :( :(
Post Reply