Page 1 of 1

Parallax Maps?

Posted: 27 Nov 2012, 22:32
by Funkencool
I have a some questions regarding this, but before I get to those I have only one. Has anyone actually used this on a map, i.e. does a map with a parallax map exist that I can look into?

Re: Parallax Maps?

Posted: 28 Nov 2012, 07:14
by Forboding Angel
Most of the evo maps have them (assuming by parallax you mean a normalmap).

Re: Parallax Maps?

Posted: 28 Nov 2012, 09:10
by Funkencool
I'm think more along the lines of..
parallaxHeightTex (RGBA)
should be the same size as specularTex

modifies the diffuse, normal, and specular
TEXTURE COORDINATES before sampling is done

height, scale, and bias parameters are packed
as follows to produce a texel offset-factor f

h = (parallaxHeightTex.r * 65280 + parallaxHeightTex.g * 256) / 65536
s = (parallaxHeightTex.b)
b = (parallaxHeightTex.a - 0.5)
f = h * s + b
from the pastebin in kloot's post


I've been testing it some more and I think I have everything in order. When it's working right it looks good, though it appears to be a little buggy (at least on my setup), and doesn't appear to use occlusion?

Only relevent bit I could find
Kloot wrote:I never got around to documenting the newer/more advanced features (the changelog references them, but they didn't gain any interest from mappers), so you'll have to make do with this draft (and this old screenshot).
I'll post screens, with my test map and findings, when I get back to my desktop.

Re: Parallax Maps?

Posted: 28 Nov 2012, 17:18
by Anarchid
Can i has screenshot? :0

Re: Parallax Maps?

Posted: 28 Nov 2012, 17:36
by Beherith
Noone has done parallax before, should be useful for sand dunes and stuff.

Re: Parallax Maps?

Posted: 28 Nov 2012, 19:52
by Funkencool
Anarchid wrote:Can i has screenshot? :0
Its pretty hard to capture the effect in an image, I do have one but its of what I presume is a bug
Image
It's a little hard to see but theres a grid like pattern throughout the whole map where the pixels are stretched. I have no idea why, and I can't seem to get rid of it.
Anyway that's just a plain flat grass map but parallax adds a sense of depth when changing the view (and the normals add the shading)
Beherith wrote:Noone has done parallax before, should be useful for sand dunes and stuff.
Unfortunately it doesn't effect splatting, in fact it sort of clashes with it. I suppose it would be useful in replacing splatted dunes, but that would require high res ssmf maps.

Re: Parallax Maps?

Posted: 28 Nov 2012, 19:57
by Beherith
Does the stretching happen at coordinates that are multiples of 1024?

Re: Parallax Maps?

Posted: 28 Nov 2012, 20:39
by Funkencool
Yes I believe they did, Is it something to do with my image format?

Re: Parallax Maps?

Posted: 29 Nov 2012, 06:40
by enetheru
added appropriate tag to the mapinfo.lua wiki page.

Re: Parallax Maps?

Posted: 29 Nov 2012, 08:53
by Beherith
You should file a bug report, and attach your map to it. I think something may be wrong in the engine, because map gets rendered in patched of 1024.

A hacky workaround is to make sure parallax is 0 on a grid of 1024.

Re: Parallax Maps?

Posted: 08 Dec 2012, 09:24
by Funkencool
Alright I've messed around with it some more and I've seemed to get it working. I'm on a 1024x1024 map with a 4096x4096 spec/parallax map and all is well. It seems though that its near impossible to get the settings right (they appear to be too sensitive).
height, scale, and bias parameters are packed
as follows to produce a texel offset-factor f

h = (parallaxHeightTex.r * 65280 + parallaxHeightTex.g * 256) / 65536
s = (parallaxHeightTex.b)
b = (parallaxHeightTex.a - 0.5)
f = h * s + b
For example, if I wanted the parallax to be completely neutral I would need f == 0 (I assume)

Which would have to be something like this
h = (0 * 65280 + 0 * 256) / 65536
s = (parallaxHeightTex.b)
b = (0.5 - 0.5)
f = 0 * s + 0
So I set my r,g channels to zero(black) and my alpha channel to .5 (or 128/256 in 8bit), and leave blue channel or 's' alone since it doesn't matter in this example. That should make f == 0

Yet ingame it still wants to "raise" everything, as if the b>0 (In other words, it seems to be biased 'up')
Then if I try "lowering" everything by i.e. setting the alpha channel to the next lowest number which is 127/256 in 8bit.
Everything now appears "below" the surface.

Basically I want this..
Image

but the closest I can get is this..
Image

Re: Parallax Maps?

Posted: 08 Dec 2012, 12:26
by Kloot
Thanks for testing my undocumented junk.
Funkencool wrote:It's a little hard to see but theres a grid like pattern throughout the whole map where the pixels are stretched. I have no idea why, and I can't seem to get rid of it.
On SMF maps the main texture gets split up into squares, and if the parallax offset pushes a texel's coordinates to a neighboring square during rendering then its value is undefined (read: clamped to the border) which produces stretching artefacts.

Funkencool wrote:For example, if I wanted the parallax to be completely neutral I would need f == 0 (I assume)

So I set my r,g channels to zero(black) and my alpha channel to .5 (or 128/256 in 8bit), and leave blue channel or 's' alone since it doesn't matter in this example. That should make f == 0

Yet ingame it still wants to "raise" everything, as if the b>0 (In other words, it seems to be biased 'up')
Then if I try "lowering" everything by i.e. setting the alpha channel to the next lowest number which is 127/256 in 8bit.
Everything now appears "below" the surface.
That happens because neither 127 nor 128 is a midpoint of the range [0, 255] but the bias constant is exactly 0.5, so there will always be a non-zero offset (negative and positive) with those parameters. Mathematically there is just one real way to neutralize it: set r = 127, g = 255, b = 255, a = 0 (or r = 128, g = 0).

Re: Parallax Maps?

Posted: 08 Dec 2012, 20:41
by Funkencool
kloot wrote:That happens because neither 127 nor 128 is a midpoint of the range [0, 255] but the bias constant is exactly 0.5, so there will always be a non-zero offset (negative and positive) with those parameters. Mathematically there is just one real way to neutralize it: set r = 127, g = 255, b = 255, a = 0 (or r = 128, g = 0).
Okay, now it all makes more sense :-)
I'll mess with it some more and see if I can come up with something that looks good.

Also just so it's out there, I would have to say it's biggest downfall is that it doesn't effect the splat texture, but it might still have its uses.