POV-Ray : Newsgroups : povray.binaries.animations : parallax mapping (504k mpeg 1) : parallax mapping (504k mpeg 1) Server Time
18 Jul 2024 18:22:59 EDT (-0400)
  parallax mapping (504k mpeg 1)  
From: Tek
Date: 9 Apr 2004 04:03:48
Message: <407658e4@news.povray.org>
I was inspired by Samuel Benge's fake volumetrics post in p.b.i. It reminded me
of a technique I know of for real time graphics called "parallax mapping". So I
decided to implement it in pov! :)

What you are looking at is a flat plane (okay, right now what you're looking at
is an e-mail, but you get my drift). The illusion of bumps is acheived using 2
tricks: firstly pov's "normal" command which we know and love, and secondly a
displacement applied to the texture in the direction of the camera according to
a height field. Both the pigment and the normal map are displaced (otherwise
they wouldn't line up).

What this does is fake the effect of different perspective on deeper points on
the surface, even though all the points are actually at the same height. The
limitation of parallax mapping is that there's no occlusion (since each point on
the surface only reads the height once), which means you get errors when you
view the surface at a shallow angle. Also there's a small inherent inaccuracy,
which causes the surface to creep around slightly.

It's pretty neat, but I'm not convinced it's that much use in povray. Still,
might be good if you need a cheap surface displacement and normal maps aren't
enough.

Here's the code for the effect. I've only done the maths for a horizontal plane,
but it is possible to implement the technique for a surface at any angle:

plane {
 #declare planeY = -4;
 y, planeY

 #declare camHeightAbovePlane = camPos.y - planeY;
 #declare bumpDepth = .5;
 #declare q = 1/(1 + bumpDepth/max(camHeightAbovePlane,.001));

 #declare camPosX = camPos.x; #declare camPosY = camPos.y; #declare camPosZ =
camPos.z;

 pigment {
  function {
   Colour( camPosX + (x-camPosX)*(Height(x,0,z).x*(1-q) + q), 0, camPosZ +
(z-camPosZ)*(Height(x,0,z).x*(1-q) + q) ).x
  }
 }
 normal {
  //slightly bizarre, use the height map for the bumps, but displace it by
itself
  function {
   Height( camPosX + (x-camPosX)*(Height(x,0,z).x*(1-q) + q), 0, camPosZ +
(z-camPosZ)*(Height(x,0,z).x*(1-q) + q) ).x
  } -2
 }
 finish { ambient 0 diffuse 1 }
}


-- 
Tek
www.evilsuperbrain.com


Post a reply to this message


Attachments:
Download 'parallax mapping000.m1v.mpg' (505 KB)

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.