Parallax Occlusion Mapping

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!
Caphalor
Greenskin
Posts: 116
Joined: Tue Feb 06, 2007 8:54 pm
Location: Berlin, Germany
x 25

Parallax Occlusion Mapping

Post by Caphalor »

I implemented Parallax Occlusion Mapping in Ogre.
Shader Features:
- Supports up to 3 Lights
- Parallax Occlusion Mapping (:D)

Image

A screenshot taken from my editor:
Image

.hlsl, .program and .material files (for Ogre 1.6):
See page 3
Last edited by Caphalor on Tue Jun 09, 2009 12:38 pm, edited 6 times in total.
User avatar
Samuelgames
Gnoblar
Posts: 15
Joined: Fri Mar 14, 2008 12:44 am

Post by Samuelgames »

Wow, awesome work you did there, this is the most 'volumetric' texture shader i've seen
User avatar
Nauk
Gnoll
Posts: 653
Joined: Thu May 11, 2006 9:12 pm
Location: Bavaria
x 36

Post by Nauk »

Wow this looks damn nice, totally have to agree with Samuelgames :)
Caphalor
Greenskin
Posts: 116
Joined: Tue Feb 06, 2007 8:54 pm
Location: Berlin, Germany
x 25

Post by Caphalor »

It's basically just an implementation of the POM shader you can find in the DirectX SDK with some minor changes, but I'm glad that you like it. :)
The really great thing here is Ogre with its flexible and powerful material system. 8)
todderod
Halfling
Posts: 43
Joined: Mon Jan 02, 2006 9:32 pm

Post by todderod »

Copy from DX SDK or not, it looks darn good!
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

Post by sinbad »

Nice! I'll use that in the samples if you don't mind? Provided I can get around to writing a GLSL version of course.
Caphalor
Greenskin
Posts: 116
Joined: Tue Feb 06, 2007 8:54 pm
Location: Berlin, Germany
x 25

Post by Caphalor »

I'll use that in the samples if you don't mind?
It would be a honour. :D
Maybe the shader needs some additional testing and tweaking, feel free to do what you want with it. And you should consider using another parallax map, rockwall_NH.tga is really a bit small (I used a 256x256 parallax map).
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 11

Post by nullsquared »

Very, very nice! This is excellent! I've been wanted to implement POM for a while now, but never found a decent source to observe (that also magically worked with Ogre) :D

Mind if I post a quick screenshot while playing around with it? :)
Image

Code: Select all

float nMinSamples = 100;
float nMaxSamples = 200;
Depth scale of 1 needs ... quite a lot of samples :lol:

Anyways, note the FPS. On my 8800GTS, it runs a lot faster like this:
- ditch all of the LOD calculations, do complete POM regardless of distance/etc.
- ditch the derivatives, ray trace using the first mip level of the height texture:

Code: Select all

fCurrHeight = tex2Dlod( normalHeightMap, float4(vTexCurrentOffset, 0, 0)).a;
Chances are that the POM was being computed for some fragments regardless of the LOD'ing; and the derivatives usually only make things slower.

In my honest opinion, not only does this run faster, but it also looks a lot better when at a distance. Of course, using the first mip map of the height map has its own problems, but it looks good enough and runs fast enough for most scenes, so it's up to you.

(I can post the source if you want, but all I did was the above tex2Dlod change and I commented out the derivatives calculation and all of the if's for the LOD)

EDIT:
Here's with min 10 and max 50 samples, with LOTS of processing (filling up a lot of the screen):
Image

EDIT2: Sorry, I just can't stop playing with it, this is BEAUTIFUL, man! :D :D
Image
Last edited by nullsquared on Tue Jul 01, 2008 7:55 pm, edited 1 time in total.
Caphalor
Greenskin
Posts: 116
Joined: Tue Feb 06, 2007 8:54 pm
Location: Berlin, Germany
x 25

Post by Caphalor »

I did not test the performance very much (my Editor has a fixed framerate at the moment), but thank you for the advice, I will try it soon. :)
Edit: You are right, the performance gain without LOD is really impressive! I updated the .rar file.
Edit2: Your screenshots are always welcome. ;)
Last edited by Caphalor on Tue Jul 01, 2008 8:38 pm, edited 3 times in total.
User avatar
tuan kuranes
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 2653
Joined: Wed Sep 24, 2003 8:07 am
Location: Haute Garonne, France
x 4

Post by tuan kuranes »

Nice results !

'Parallax Occlusion Mapping' is nice and can be used/extended to brillant ideas too.

Check the implementation used in the paper labeled 'Instant Animated Grass'

http://www.cg.tuwien.ac.at/research/pub ... _2007_IAG/

They did use Ogre and hlsl, and did released the shader and texture, only missing the .material file.
User avatar
captnoord
Halfling
Posts: 42
Joined: Wed Apr 30, 2008 11:01 am

Post by captnoord »

yup... I was waiting to get some time off so I could check that out... for our game....... atm we use PG for grass but it has some terrible disadvantages related to the grass......
To be or not to be that is the question that dazzles us for centuries, now modern science have found the answer: 0x2B | ~0x2B == 0xFF
Image
User avatar
xadhoom
Minaton
Posts: 973
Joined: Fri Dec 28, 2007 4:35 pm
Location: Germany
x 1

Post by xadhoom »

Hi!

Very nice shader! IMHO these lines are a copy paste error in ParallaxOcclusionMapping.hlsl:

Code: Select all

   float Dist1 = length(lightPosition1 - position);
   float Dist2 = length(lightPosition1 - position);
   float Dist3 = length(lightPosition1 - position);
[Edit]
You can avoid one normalize() in the VS if you calculate the tangent space matrix like this:

Code: Select all

   float3 nNormal = normalize(normal); 
   float3 nTangent = normalize(tangent);
   float3 binormal = cross(nTangent, nNormal);
The length of a cross is 1 if both vectors have the length 1.
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 11

Post by nullsquared »

Very nice, once again! And a very good example for Ogre, nice and clean without going on tangents (no pun intended).
Caphalor
Greenskin
Posts: 116
Joined: Tue Feb 06, 2007 8:54 pm
Location: Berlin, Germany
x 25

Post by Caphalor »

@xadhoom: Thank you for the fix! (it was really a copy and paste error)
I will update the shader once again.
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

Post by sinbad »

Cool, I hadn't seen that grass paper, great to see that it was done using OGRE.
User avatar
xadhoom
Minaton
Posts: 973
Joined: Fri Dec 28, 2007 4:35 pm
Location: Germany
x 1

Post by xadhoom »

I´m not sure if this is a shader bug, but if I put the shader on a capsule (or another cylindrical mesh) and
place one light at one side of it I see an inverse normalMap lighting on the left side of the capsule where the material becomes darker.

Can anybody confirm this?

[Edit]
Using Ogre 1.4.9
Caphalor
Greenskin
Posts: 116
Joined: Tue Feb 06, 2007 8:54 pm
Location: Berlin, Germany
x 25

Post by Caphalor »

I had problems with some meshes, too, but I blamed it on wrong or not existing tangent vectors, maybe you should check this. The fact that it worked with the knot mesh made me optimistic. ;)
Of course it is also possible that there's really a bug, I'm all in all a shader beginner.
User avatar
Kojack
OGRE Moderator
OGRE Moderator
Posts: 7157
Joined: Sun Jan 25, 2004 7:35 am
Location: Brisbane, Australia
x 535

Post by Kojack »

The length of a cross is 1 if both vectors have the length 1.
No it isn't.
The length of a cross product is affected by the angle between the 2 vectors. The result is only length 1 if the 2 vectors are unit length and at 90 degrees to each other.

If the normal and tangent are always going to be at right angles, then it's fine. But that's a specific case.
User avatar
iloseall
Gremlin
Posts: 156
Joined: Sun Sep 14, 2003 3:54 am
Location: Beijing China

Post by iloseall »

Cool~~~~~~
and Instant Animated Grass Cool too!
'Parallax Occlusion Mapping' is nice and can be used/extended to brillant ideas too.
Has another extented about POM?
User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2

Post by Kencho »

Kojack wrote:
The length of a cross is 1 if both vectors have the length 1.
No it isn't.
The length of a cross product is affected by the angle between the 2 vectors. The result is only length 1 if the 2 vectors are unit length and at 90 degrees to each other.

If the normal and tangent are always going to be at right angles, then it's fine. But that's a specific case.
I think he wanted to say it's in the range [-1, 1]. When both vectors are normalised, their dot product returns the cosine of the angle they form as is, because it's multiplied by the length of both vectors (which in this particular case is exactly 1 for both)
Image
Oogst
OGRE Expert User
OGRE Expert User
Posts: 1067
Joined: Mon Mar 29, 2004 8:49 pm
Location: the Netherlands
x 43

Post by Oogst »

Looking good!

If you are having fun with this, then you could try to improve the performance with relaxed cone step mapping. Also, you could try to improve the visual quality by adding shadow to it as well. :)
My dev blog
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/X1/PS3/PS4)
Blightbound: coop online dungeon crawler (PC)
Swords & Soldiers: side-scrolling RTS (Switch/PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance
The Ageless Gate: cello album
Caphalor
Greenskin
Posts: 116
Joined: Tue Feb 06, 2007 8:54 pm
Location: Berlin, Germany
x 25

Post by Caphalor »

Thank you for the advice!
As far as I understand, the cone mapping algorithm would replace my while loop, and all in all it would be cone mapping with a dynamic step count, right? I think I will try to implement it, but don't expect a working shader soon, I also have to continue the programming of my editor. ;)
And finally concerning the shadows, do you mean self-shadowing or shadows in general?
Oogst
OGRE Expert User
OGRE Expert User
Posts: 1067
Joined: Mon Mar 29, 2004 8:49 pm
Location: the Netherlands
x 43

Post by Oogst »

I meant self shadowing, because you can do that really easy once you have the ray marching working.

As for the relaxed cone step mapping: it is a pretty difficult one to implement, because it also requires a tool to generate the cone step map in the first place. Requires a lot of time to make, I would expect. That's why I first asked whether you are having fun with this. :D Relaxed cone step mapping is an awesome algorithm, though!
My dev blog
Awesomenauts: platforming MOBA (PC/Mac/Linux/XBox360/X1/PS3/PS4)
Blightbound: coop online dungeon crawler (PC)
Swords & Soldiers: side-scrolling RTS (Switch/PS3/Wii/PC/Mac/Linux/iPhone/iPad/Android)
Proun: abstract racing game (PC)
Cello Fortress: mixing game and live cello performance
The Ageless Gate: cello album
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 11

Post by nullsquared »

Oogst wrote:I meant self shadowing, because you can do that really easy once you have the ray marching working.

As for the relaxed cone step mapping: it is a pretty difficult one to implement, because it also requires a tool to generate the cone step map in the first place. Requires a lot of time to make, I would expect. That's why I first asked whether you are having fun with this. :D Relaxed cone step mapping is an awesome algorithm, though!
Wait, is there a difference between what you're describing and what one of those gamedev.net geniuses posted? Because the demo he provides runs with perfect quality (no aliasing or errors on the edges whatsoever) at least 10 times faster than POM or relief mapping with 200 steps (even at which you can still notice errors).
User avatar
PolyVox
OGRE Contributor
OGRE Contributor
Posts: 1316
Joined: Tue Nov 21, 2006 11:28 am
Location: Groningen, The Netherlands
x 18

Post by PolyVox »

nullsquared wrote:Wait, is there a difference between what you're describing and what one of those gamedev.net geniuses posted? Because the demo he provides runs with perfect quality (no aliasing or errors on the edges whatsoever) at least 10 times faster than POM or relief mapping with 200 steps (even at which you can still notice errors).
I don't know, can you provide a link to the GameDev.net post? Cone Step Mapping and Relaxed Cone Mapping are described in GPU Gems 2 & 3 respectively, and the image in there are very good quality.