Page 1 of 1

Advanced stencil buffer ops

Posted: Sun Oct 07, 2012 5:40 pm
by Kalda
Hello!
I am just probably blind, but can't find answer in docs.
I need to manipulate with stencil buffer and use it for masking.
So is there any way to achieve these without modifying the library?

1) Stencil ops like invert/increment/decrement
2) Select depth/stencil buffer mode like 8-bits for stencil and 24-bit depth (and what is default)
3) Color masking (like render into blue channel only or disabling color rendering at all)
4) Rendering directly to stencil buffer from pixel shader

Thanks in advance! I'd be looking for this forever...

Re: Advanced stencil buffer ops

Posted: Sun Oct 07, 2012 7:33 pm
by Mel
You have to modify the library. The stencil buffer is only used by the shadow volumes, and there is no any direct way to modify it.

Re: Advanced stencil buffer ops

Posted: Sun Oct 07, 2012 7:40 pm
by Kalda
Ok thanks!
So question to library maintainers.
Is there any good reason for this? I offer to write the patch for SMaterial.
IMHO it is an elementary function of any 3D engine and should be accesible directly through Irrlicht API (Ogre also has it accessible in material system).

Re: Advanced stencil buffer ops

Posted: Sun Oct 07, 2012 9:55 pm
by hybrid
Well, we discussed this a while ago, and did not yet decide whether we really need stencil modes in the material system, or just in scene manager settings. Because it's only required to have it in SMaterial if these values change from object to object during one render stage. Otherwise, it could be provided via a different, e.g., a shadow scene and the main scene. But for a first start you could provide a patch for the basic driver interfaces to access stencil settings. These functions could then be used for the higher levels once we know where to put it.

Re: Advanced stencil buffer ops

Posted: Mon Oct 08, 2012 5:00 pm
by hendu
I've been using stencil ops without modifying the library for a long time.

Works well since irr doesn't touch the stencil when one doesn't use its stencil shadows.


The color masking is already supported, and rendering to stencil is really slow, so you really don't want to do that on any card.

Re: Advanced stencil buffer ops

Posted: Mon Oct 08, 2012 5:15 pm
by Kalda
2 hendu:
Well I need it for "Stencil then cover" vector graphics rendering like NV_path_rendering.
What I am trying to acomplish is to make accelerated VG library for my bachelor thesis.
And this is the best (fastest & simplest) way to do that. In fact it definitely is not that
slow as you say. The performance is really good. I got just nasty hacked demo at this point,
so I cannot provide any further info. But if everything will be according to plan, I will
release the library demo with source here in next few weeks.

2 hybrid:
I am on it ;)

Re: Advanced stencil buffer ops

Posted: Mon Oct 08, 2012 5:38 pm
by hendu
Are you related to cairo by any chance? Recent talk on phoronix is that rendering trapezoids on the cpu is still faster unless you have a really good gpu (ivy bridge is not enough for example).

Re: Advanced stencil buffer ops

Posted: Mon Oct 08, 2012 6:05 pm
by Kalda
I am just cairo user ;)
Main point of the thesis is to let everything compute on GPU from path (line strip) and compare results.
But If you ever see the NV_path_rendering extension, they claim it is many times faster than cairo
(there are graphs in their paper). So I really look forward to see my results.

Re: Advanced stencil buffer ops

Posted: Mon Oct 08, 2012 6:42 pm
by hendu
Yes, on a high-end Nvidia GPU no doubt ;)


I googled nv_path_rendering benchmarks, and found this:
http://zrusin.blogspot.fi/2011/09/nv-pa ... ering.html

Qt software rendering was 4x the speed of the gpu-accelerated nv extension, on a Quadro 600.

Re: Advanced stencil buffer ops

Posted: Mon Oct 08, 2012 6:54 pm
by Kalda
Yes, as you say no doubt ;)
I cannot compare anything with that 'cause I am running on HD5870.
Second think is, I am currently targeting SM4 cards and working with
geometry shaders which eliminates many old cards. Thats why I am
interested in the results. At this point "only Carmack knows!" :D

Re: Advanced stencil buffer ops

Posted: Tue Oct 09, 2012 12:28 am
by Kalda
So here comes the first diff for stencil access!
(I am ready for criticism and to modify it.)

Diff file here

Re: Advanced stencil buffer ops

Posted: Tue Oct 09, 2012 11:26 pm
by TheMrCerebro
It would help to have total control of the Stencil Buffer. Would be easier to make, optimizations shadows and other actions.
We know that the future is in use Shadow Maps, but there are still nostalgic like me :D

PD: Thanks Kalda for the DIFF!!!