Decals

Started by
23 comments, last by Locke 22 years, 3 months ago
quote:Here you go, perfect refllections, no stencil needed, works on every card that supports a zbuffer.

Well, you mean :
glClearDepth(0);
glClear(GL_DEPTH_BUFFER_BIT); // writes 0s in all depth buffer
glDepthRange(1,1);
glDepthFunc(GL_ALWAYS);
drawMyPolygon(); // create the mask with 1s in depth buffer
glDepthRange(0,1);
glDepthFunc(GL_LESS);
drawMyObjects(); // draw objects in the masked region

That's purely awesome !!!
Thanx for the tip

Also, it has one limitation : you can't render that at any moment. You have to find the time to do it at the beginning or the end of the rendering. right ?



quote:Disons, que tu as 2 faces en X, l'une d'entre elles bouge lentement en X ou Y. Regardes l'intersection de plus proche, tu verras qu'il y a une sorte de scintillement dans les pixel qui font l'intersection.

Oui oui, Je vois très bien l'effet que c'est. Mais je ne vois pas en quoi le découpage des polygones peut arranger cet effet. Effectivement, l'approximation des Z est meilleure, mais toujours pas parfaite (et ne le sera jamais car les flottants auront toujours une précision limitée).

Mais ceci dit, je ce que vois encore moins, c'est pourquoi on se prend la tête avec ce cas particulier. Il faut qu'il y ait beaucoup de conditions réunies pour que ce soit visibile, et tout juste visible quand on sait qu'il existe et qu'on s'y attarde.



quote:I would say, it practically does eleminate the problem. Keep in mind, that the range of a 64bit buffer is around 1,100,000,000,000 times higher than the range of a 24bit buffer...

LOL !!!
For the X junction, I agree it would be sufficient (unless your viewport is around 1e+15 pixels wide and high ).
But it would still not get rid of flickering for decal. Polygon Offset remains necessary.

Edited by - vincoof on January 18, 2002 5:49:30 PM
Advertisement
> Also, it has one limitation : you can''t render that at any moment. You have to find the time to do it at the beginning or the end of the rendering. right ?

Yes, right. I do that at the beginning, before rendering the actual scene. Before rendering your non-reflected scene, you have to remove the screen mask with a glClear(), but this one is rather fast, esp. since it''s only on the zbuffer.
Then, directly after removing the mask, I rerender my original mask polygons (those who make the reflective faces) into the freshly cleared zbuffer, but this time without mask (with their normal depth values) and with their original texture. You can simply blend them with a constant alpha (will make a constant reflectivity), or with an alpha mask to modulate reflectivity by a map, very nice effect. It''s important to render them *directly* after clearing the mask, so that their original zbuffer coordinates are restored, or they will be overwritten by some other geometry.

If you want multiple reflective surfaces per frame, just remask your poly after having drawn your reflected scene, and repeat the procedure. This opens the door for another *really* cool effect you can do while rendering your initial masks: normally you would render your masks black or without affecting the colour channel. But if you actually set the blend function to modulate and render a coloured polygon while remasking your faces, then you will get a mirror with a filter colour effect. It will reflect the scene tinted in a specific colour, if you set it to eg. red, all your reflected scene will be tinted blood-red in the mirror.

AND: (while I''m allready at giving out the cool functions of my engine ), you can go a step further: don''t use a constant colour for the filter, but a filter colour map. Now, it''s starts to get really awesome. Take photoshop and write a red text onto a white background, make it look like blood... Use it as a filter colour map. Now your reflected scene will look normal in the mirror, but will be reflected tinted in red on the part of the mirror covered with your letters. This effect is so cool, and I haven''t seen it done anywhere before.
quote:
Mais ceci dit, je ce que vois encore moins, c''est pourquoi on se prend la tête avec ce cas particulier. Il faut qu''il y ait beaucoup de conditions réunies pour que ce soit visibile, et tout juste visible quand on sait qu''il existe et qu''on s''y attarde.


Bof, ça depends, moi ça m''énerve ce genre de problèmes, mais c''est peut-être, parce-que je suis perfectionniste

quote:
But it would still not get rid of flickering for decal. Polygon Offset remains necessary.


Your decal would have to be really very *very* close to your surface. Lift it up about a µm, and it will be OK. It all depends on your scale, and your depth range settings. But if you manage to get z fighting with a 64bit zbuffer, then you just deserve it

quote:If you want multiple reflective surfaces per frame, just remask your poly after having drawn your reflected scene, and repeat the procedure.

Okay, that''s not so difficult. But don''t you think there could be a problem with depth buffer ?
With stencil buffer, you don''t modify the depth fragments, so there''s not a problem.
But with your technique you keep on clearing the z-buffer... that may yield some unexpected results when the polygons overlap between two reflections...


quote:It will reflect the scene tinted in a specific colour, if you set it to eg. red, all your reflected scene will be tinted blood-red in the mirror.

Eh eh, but you can also do that with the stencil buffer


quote:Take photoshop and write a red text onto a white background, make it look like blood... Use it as a filter colour map. Now your reflected scene will look normal in the mirror, but will be reflected tinted in red on the part of the mirror covered with your letters.

That seems to be very cool
Moreover, I don''t know if you can achieve such effects with the stencil buffer because I don''t know if removing the color masks also removes alpha testing.



Thanks again for all those tips. Make sure read ones of mine somewhere in this forum
quote:
Okay, that''s not so difficult. But don''t you think there could be a problem with depth buffer ?
With stencil buffer, you don''t modify the depth fragments, so there''s not a problem.
But with your technique you keep on clearing the z-buffer... that may yield some unexpected results when the polygons overlap between two reflections...


Well, you can''t have reflective faces that intersect. But who uses them anyway ? Intersecting mirros automatically mean infinite interreflections, not a good idea... Other than that, everything else is possible with this method.
quote:
Eh eh, but you can also do that with the stencil buffer


Yes, but it requires an additional pass.

That z-buffer technique sounds really good!!
And what do your experiments show? Is it faster or slower than using stencil buffer? Well, stencil buffer is implemented in hardware, but depth-buffer also!

Thanks in advance


-- tSG --
-- tSG --

This topic is closed to new replies.

Advertisement