#155168 - Noda - Fri Apr 25, 2008 10:52 pm
Hi,
have a floor texture (a big quad) on which I want to apply decals on it (smaller quads). Which is the best way to do it?
Currently I simply offset the decals by 0.15 which works fine when the camera is near but when it gets farther, I've go flickering problems.
0.3 seems to be the limit from which the offset become visible, and since I have 2 layers of decals (the second one being the shadows of the walls casted on the floor) I can't enlarge the offsets. And even at 0.3 the z-fighting problem is present.
Is there a better way to do what I want?
Thanks for your help and suggestions.
#155170 - silent_code - Fri Apr 25, 2008 11:23 pm
that's pretty "normal" or common. you can try to use distance based offsets, so that further away decals get offset more. that's won't be noticable.
are you using w or z buffering? z buffering is getting more issues the farther away stuff is, as w buffering affects near stuff more that z buffering, but equally throughout the whole depth range. sort of... try to read up on it. :^)
hope that helps. :^D
#155176 - M3d10n - Sat Apr 26, 2008 12:46 am
There's a setting in the polyfmt which allows you to draw decals without z-fighting, but I believe you need to use the same exact vertex positions and matrix transformations.
So you'd need to draw your entire floor again (or only the triangles under the decal) for each decal, turn off texture wrapping and use a texture matrix to offset and scale the texture so the decal is where you want it to be. That's how things works on actual videocards as well, more or less.
#155177 - TwentySeven - Sat Apr 26, 2008 1:16 am
On real videocards everyone just uses polygonoffset. :P
To me it seems like you're going to have to simulate polygonoffset with worldspace transforms (distance based bias), as mentioned above.
#155183 - silent_code - Sat Apr 26, 2008 3:20 am
actually polyoffset isn't recommended. you would use the stencil buffer...
using decal blending is a good idea!
well, i'd sure try to decalblend with regular per decal geometry first. :^)
@ TS: ps: the nds doen't have imaginary graphics hw. ;^D
#155187 - tepples - Sat Apr 26, 2008 3:57 am
silent_code wrote: |
@ TS: ps: the nds doen't have imaginary graphics hw. ;^D |
It does render to an imaginary frame buffer when you're not in capture mode. Does that count?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#155191 - Noda - Sat Apr 26, 2008 5:24 am
Thanks for the ideas :)
I'll think I'll first try to simulate polygon offset by adjusting the offset based on the camera distance. Still I think there would be some problem, as with very low camera angle (very close and in the direction of the floor) the zfighting would still occurs.
The idea of using decal mode and the same vertices as the floor with texture matrix transform would fix that problem, but still the issue with the shadows would be here (as shadows are not texture but polygons drawn using the stencil).
Seems there's no perfect solution for my problem, but a mix of those 2 ideas (distance adjusted offset for shadow + decal mode for decals objects) should do the job I hope. Now I just need to rewrite some parts of my rendering engine...
Oh, and for the solution of using W-buffer instead of Z-buffer, I tried but it seems it did not changed anything, I found it strange as I would expect at least some changes...
#155193 - a128 - Sat Apr 26, 2008 8:25 am
Great discussion...if someone could share the results with source code this would be great.
#155197 - simonjhall - Sat Apr 26, 2008 11:10 am
There's the "Z equal" test in polyfmt (which M3d10n was hinting at) which would be very useful for a problem like this.
If you want to see an example of this, check out Quake's two-layer sky. The lower layer of clouds is effectively a decal and I do this by drawing the skybox twice (with the exact same geometry) but use the Z equal test, a different texture and an alpha channel to make it work.
_________________
Big thanks to everyone who donated for Quake2
#155203 - TwentySeven - Sat Apr 26, 2008 3:29 pm
Quote: |
I'll think I'll first try to simulate polygon offset by adjusting the offset based on the camera distance. Still I think there would be some problem, as with very low camera angle (very close and in the direction of the floor) the zfighting would still occurs. |
Yeah, that sounds like you're thinking of just moving the decal vertically off the floor..
eg: position += floornormal * distance bias
More robustly, you should be moving the decal back towards the camera just a touch.
eg: position -= cameraforwardvector * distance bias
This is closer to what goes on with (the sadly unavailable on the ds!)polygonoffset, except obviously your decal is going to be scaled a touch larger by this whereas polygonoffset only messes with the zbuffer values.
#155205 - silent_code - Sat Apr 26, 2008 4:01 pm
ok (or not), "equal" depth compare will most likely give you artifacts if not rendered with the same vertex setup (e.g. triangle). :^C