   stencil buffer.. i dont get it
  ill try to keep it short, but its not that short..i read all sorts of material throughout the net, i understand the general operation but i have some questions..the test equation as i gather is:left side : stencil reference && stencil maskright side: pixel value && stencil maskwe compare the two using predefined function (always, never less...), and act according to the actions we defined in stencil-pass, stencil-fail and stencil z-fail (keep, zero replace ...)my problem is that i cant connect the dots in that description. i comprehend the general operation, but cant make sense of it; i know the play, but i cant understand the players..1. what is the stencil mask exactly? why does it have such a long default value?2. what do i do with the mask write mask? what does it do with me?3. stencil ref and pixel value - i set the ref, but the pixel comes from somewhere - what sort of values does it bring with it? what sort of value should i give the ref?4. the compare function, which direction? : ref by mask less/greater than pixel by mask or the other way around?5. difference between fail and z-fail?i don't know if anyone here knows OGRE3D well enough to answer this, but i cant seem to get an answer on OGRE3D forums so ill ask anyway: in hlsl fx files i can set stencil buffer operations in techniques in individual passes. am i wrong or in ogre i can only hard code it in render group or use it in compositor script technique? if so, why?if you could help me out here, I'll be most grateful... if you could provide some simple examples that don't have something to do with shadows ill be even gladder.   
  1- stencil mask is used for setting which bits of the stencil buffer will be read in stencil test. it is basically an and operation before reading the stencil buffer value(stencil value)&(stencil mask)for example if you require only right most bit of stencil buffer and other bits are used for some other tasks you can use stencil mask 0x01 so other bits will not interfere with your stencil testing. if right most bit is 1, resut will be 1 else it will be 0, other bits will not be influential2- stencil write mask is same as stencil mask but this time it is used while writing on stencil buffer. you can specify which bits will be writable using write mask and all other bits will be preserved while writing. for example previous value in the buffer is 0xFF and you want to set right most bit to 0, you can set write mask to 0x01 and stencil value to 0x00. only right most bit will be altered and buffer values will be 0xFE3- you can alter the value in the buffer while rendering on object using stencil operations. for example StencilPass operation will be executed if stencil test passes. for example you want to render a mirror on the scene. first job is rendering the scene normally, after that render the mirror but set stencil func to always and stencil pass to replace and stencil ref to 0x01. in this case stencil test will always pass. while rendering the mirror, it will replace the stencil buffer value with 0x01 while outside of mirror will remain 0x00. After that render the mirror scene, but use stencil test = equal and stencil ref = 0x01. change stencil operation back to keep (or set stencil write mask to 0x00) to prevent altering stencil buffer. So this time scene will be rendered if stencil buffer is 0x01 which is position of mirror. 4- it compares reference value to buffer value. if it is greater, it will be something reference > buffer.5- There are 3 different events you can use stencil operation. stencil pass, stencil fail, stencil z fail. stencil pass operation will be trigerred if both z test and stencil test passes. stencil fail operation will be trigerred if only z test passes and stencil test fails. and stencil z fail will be trigerred if both z and stencil tests fails.stencil buffer is not a feature of ogre. it is a feature of graphics unit and graphics libraries simply change render states to use it. ;  thanks, I've been looking all across, thought ill never find helplets take two (presumably) simple examples 1. cutting one shape off the other2. creating an outlinehow would those two be done? (preferably using hlsl, but ill take all the help i can get)to cut one shape off the other, ill need to use the shape of the 'cutting shape' and use it as the mask correct?i made an outline with inflated version of an object in first pass with depth write off, and original version with depth write on in second pass. i presume that would be somewhere close to how it will be done with stencil, but i cant get my head around what exactly to do, and in what order.i just cant 'verbalize' it into code.. hope you have patience   ;  you are right about first example. render the cutting shape on the stencil buffer, set every value to something specific while rendering. after that render second shape using stencil test not equal so it will render not render on cutting shape. finding outlines would be much harder. I am not sure if it is related to stencil buffers. you can search for cel shaded animation in ogre. here is the wikipedia articlehttp://en.wikipedia.org/wiki/Cel-shaded_animationif ogre supports rendering objects as a wireframe using thick lines you can easily implement it using first method.   ;  alright... hope i don't sound too dumb by this point..i have a two pass technique, one renders the object, the other renders it slightly deviated from the center (x y and z -> - 1) so it will appear in front of the original one, slightly to the side.mainVS2 is the deviated version.. i know it sounds lazy, but what now?technique technique0 {pass p0 {stencilEnable = true;stencilMask = ?;stencilRef = ?;VertexShader = compile vs_3_0 mainVS2();PixelShader = compile ps_3_0 mainPS();}pass p1 {stencilEnable = true;stencilFunc = notequal;STENCILFAIL = ?;STENCILZFAIL = ?;STENCILPASS = ?;VertexShader = compile vs_3_0 mainVS();PixelShader = compile ps_3_0 mainPS();}}[Edited by - JaJDoo on June 3, 2010 1:45:58 AM]