I was thinking about hardware acceleration, using Stencil buffer instead of second set of "discard" operations (It is always faster when in one of the passes there is no need to load texture to compare value, but also there is huge advantage because of hardware support).
I have question about stencil script.
My question is about compositor script level configuration.
I'd like to check If I finally have changed the value in stencil buffer during render_quad operation

I stillthink that there might be something missing in configuration.
Rendering of 2 targets with "discard" command is just easy - I've done that with no problem. The whole point is to gain hadrware acceleration by using stencil buffer.
I'd like to provide that acceleration to make things work faster.
I am executing a rendering pass that takes 2 inputs (offscreen texture and sobel filter):
Code: Select all
target_output
{
depth_check off
depth_write off
cull_hardware off
cull_software off
input none
//shadows off
pass clear{
buffers stencil
stencil_value 0
}
stencil
{
check on
ref_value 1
pass_op replace
}
input none
//pass clear{}
pass render_quad
{
material OSP_BlendedOffScreenToOutput
input 0 particlesDownsampledTexture
input 1 sobelMaskTexture
}
}
I hope that hanks to this configuration:
Code: Select all
pass clear{
buffers stencil
stencil_value 0
}
stencil
{
check on
ref_value 1
pass_op replace
}
-Stencil buffer is cleared to 0
-Stencil buffer checking is activated.
-In every painted pixel (not discarded) stencil value changes from 0 (initial value after clear) to 1.
Next pass renders everything in stencil version (but it is supposed to do only in pixels with stencil value that still == 0).
Code: Select all
target_output
{
depth_check off
depth_write off
cull_hardware off
cull_software off
input none
//shadows off
material_scheme STANDARD //PARTICLE_ALPHABLEND_SCHEME
stencil
{
check on
comp_func not_equal
ref_value 1
pass_op replace
}
pass render_scene
{
first_render_queue 10
last_render_queue 20
}
}
there are only options to set how buffer is changed after rendering if the compare function of original value with reference value passes. I am not 100% sure about rules in that script to say "do not render here".
Could you please explain me how to cope with that based your experience?
Is it enough to fail comparation function so that pixel would avoid being rendered? Or is this function only used to decide whether to execute commands from fail_op attribute, etcetera?(Reference Value & Mask) CompareFunction (Stencil Buffer Value & Mask)
If from some although setting " stencil {check on}" it is not tourned on, (it is hard to debug), then what is needed to do so.
Are there any restrictions, additional expectations to activate it?
I've been trying to find that information weeks ago repeatedly, but I am not sure whether I get the documentation right (it uses both mask and stencil buffer). Lost many time without finding it out for sure.
I've of course red the forum thread under link that you gave me (about coping with stenciling on application level), I've red documentation of class used for controling stencil buffer form application, forum threads where people wanted to use stencil to something completely different (most of them ended with resigning from that idea

I think I might know how it works but it is possible that I am missing some part needed here.
Edit:
Is it possible only from level of code to manage that sctipt? Or does attribute "check on" activate stencil writing just like i tkink?
Edit2:
Code uploaded to repository.
Tests of efficiency show that decision made by "discard" operation in case of full resolution texture, only slows down rendering

It has to be buffer.
This is version that uses Sobel texture for stencilin with proper Y axis also in OpenGL and preserves the same calculations of colour: