[osg-users] 32bit DEPTH for RTT

Chris Hanson xenon at alphapixel.com
Wed Oct 26 08:36:43 PDT 2016


Can you post the solution, for others in the future to benefit from?

On Mon, Oct 24, 2016 at 8:04 AM, Trajce Nikolov NICK <
trajce.nikolov.nick at gmail.com> wrote:

> Got a help offline from a friend on this ... So glad there are so cool
> people on this list ...
>
> Thanks all!
>
> Nick
>
> On Fri, Oct 21, 2016 at 3:54 PM, Trajce Nikolov NICK <
> trajce.nikolov.nick at gmail.com> wrote:
>
>> Hi readers to this thread ;-),
>>
>> I am close to resolve this but the math involved is a bit tricky for me
>> to understand it right. And suddenly I can not send screenshots or videos
>> publicly - maybe on private email to those willing to help.
>>
>> The story now is this:
>>
>> The environment is ECEF terrain, and I have light source. I am rendering
>> to texture from this light source position/direction into a depth texture.
>> The light matrix is computed now in view space, and is used against the
>> view vertex in pixel shader, where the shadow projection is done. It gives
>> non-flickering results, which is very good however the texture coords are
>> wrong, and the missing part for me is the coorect texture coords
>> computation from lightmatrix and vertex in view space.
>>
>> Any help is very appreciated !!!
>>
>> And thanks
>>
>> Nick
>>
>> On Thu, Oct 20, 2016 at 7:13 PM, Trajce Nikolov NICK <
>> trajce.nikolov.nick at gmail.com> wrote:
>>
>>> almost there .. the flickering is gone, just the shadow texture lookup
>>> coordinates are messed up when used view space matrix and vertex.
>>>
>>> This is the code for constructing the final matrix:
>>>
>>>  osg::Matrixf lmvpm =
>>> lightMatrixInViewSpace * osg::Matrixf(camera->getProjectionMatrix()) *
>>>         osg::Matrixf::translate(1, 1, 1) * osg::Matrixf::scale(0.5, 0.5,
>>> 0.5);
>>>
>>> and the GLSL:
>>>
>>> vec4 projShadow = light.lmvpMatrix  * vVertexView;
>>>
>>>         vec4 uvzw;
>>>         uvzw.xyw = projShadow.xyz;
>>>         uvzw.z = light.occlusionLayer-1;
>>>         float factor = texture( lightOcclusionTextureArray, uvzw );
>>>
>>>         fDiffuseColor *= factor;
>>>
>>> if you spot anything ...
>>>
>>> Thanks so much Glenn!
>>>
>>>
>>> On Thu, Oct 20, 2016 at 6:52 PM, Glenn Waldron <gwaldron at gmail.com>
>>> wrote:
>>>
>>>> Up vector doesn't really matter, so just pick one like:
>>>>
>>>> side = cross(view_vec, (0,0,1));
>>>> up = cross(side, view_vec);
>>>>
>>>>
>>>>
>>>> Glenn Waldron
>>>>
>>>> On Thu, Oct 20, 2016 at 12:00 PM, Trajce Nikolov NICK <
>>>> trajce.nikolov.nick at gmail.com> wrote:
>>>>
>>>>> Just last question .. What the 'up' vector would be now for making the
>>>>> light matrix in view space?
>>>>>
>>>>> On Thu, Oct 20, 2016 at 5:39 PM, Trajce Nikolov NICK <
>>>>> trajce.nikolov.nick at gmail.com> wrote:
>>>>>
>>>>>> Glenn,
>>>>>>
>>>>>> this worked ... :-) ... Thanks for the hint ...
>>>>>>
>>>>>> On Thu, Oct 20, 2016 at 5:02 PM, Trajce Nikolov NICK <
>>>>>> trajce.nikolov.nick at gmail.com> wrote:
>>>>>>
>>>>>>> wops ..
>>>>>>>
>>>>>>> mx.makeLookAt(lightPosInViewSpace,lightPosInViewSpace+lightD
>>>>>>> irInViewSpace,up)
>>>>>>>
>>>>>>> On Thu, Oct 20, 2016 at 5:00 PM, Trajce Nikolov NICK <
>>>>>>> trajce.nikolov.nick at gmail.com> wrote:
>>>>>>>
>>>>>>>> Thanks Glenn,
>>>>>>>>
>>>>>>>> actually I was expecting this. I have the math to get the light
>>>>>>>> direction in view space, just the construction of the light matrix in view
>>>>>>>> space hurts my head a bit ( I missed that part of the class :-) )
>>>>>>>>
>>>>>>>> vec3 lightDirInViewSpace;
>>>>>>>> vec3 lightPosInViewSpace;
>>>>>>>> mx.makeLookAt(lightPosInViewSpace,lightPosInViewSpace+lightP
>>>>>>>> osInViewSpace,up)
>>>>>>>>
>>>>>>>> Something like this?
>>>>>>>>
>>>>>>>> On Thu, Oct 20, 2016 at 4:04 PM, Glenn Waldron <gwaldron at gmail.com>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>> There's your precision loss, you can't do that with ECEF
>>>>>>>>> coordinates or they will be truncated.
>>>>>>>>>
>>>>>>>>> Better idea: build your light matrix in view space on the CPU
>>>>>>>>> (instead of world space), and then use it on the view-space vertex in the
>>>>>>>>> shader. (You'll have to update it every time the camera moves, of course.)
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Glenn Waldron
>>>>>>>>>
>>>>>>>>> On Thu, Oct 20, 2016 at 10:00 AM, Trajce Nikolov NICK <
>>>>>>>>> trajce.nikolov.nick at gmail.com> wrote:
>>>>>>>>>
>>>>>>>>>> Hi Glenn,
>>>>>>>>>>
>>>>>>>>>> vec3 vVertex = vec3(gl_ModelViewMatrix * VertexMODEL);
>>>>>>>>>> worldSpaceVertex = osg_ViewMatrixInverse * vec4( vVertex, 1.0 );
>>>>>>>>>>
>>>>>>>>>> Part of VP
>>>>>>>>>>
>>>>>>>>>> On Thu, Oct 20, 2016 at 3:52 PM, Glenn Waldron <
>>>>>>>>>> gwaldron at gmail.com> wrote:
>>>>>>>>>>
>>>>>>>>>>> Nick, how did you calculate "worldSpaceVertex"?
>>>>>>>>>>>
>>>>>>>>>>> Glenn Waldron
>>>>>>>>>>>
>>>>>>>>>>> On Thu, Oct 20, 2016 at 9:13 AM, Trajce Nikolov NICK <
>>>>>>>>>>> trajce.nikolov.nick at gmail.com> wrote:
>>>>>>>>>>>
>>>>>>>>>>>> hehe .. ok :-) .. Maybe you give me a hint.
>>>>>>>>>>>>
>>>>>>>>>>>> I have F+ lighting (written by a friend of mine) and I have
>>>>>>>>>>>> extended it so local lights cast shadows (a bit of complex code -
>>>>>>>>>>>> relatively actually, but for me it is ;-) ). Works well for flat terrains
>>>>>>>>>>>> with reasonable sizes. I am trying to make it work with ECEF terrain (for
>>>>>>>>>>>> testing I use osgearth). The debug code works just fine, I am seeing the
>>>>>>>>>>>> renderings from the local lights are correct, so the light view matrix
>>>>>>>>>>>> passed to the shader is correct, but getting z-fights with
>>>>>>>>>>>> setInternalFormat(GL_DEPTH_COMPONENT); only. Here is my setup
>>>>>>>>>>>> for the RTT (it is texturearray):
>>>>>>>>>>>>
>>>>>>>>>>>> http://pastebin.com/Nnc2iA1F
>>>>>>>>>>>>
>>>>>>>>>>>> With DEPTH32bit (really naive approach, I "was" thinking fast
>>>>>>>>>>>> the increase of the DEPTH precision will solve this issue, just recently
>>>>>>>>>>>> started with reading papers and I must admit I am not a "shadowing expert").
>>>>>>>>>>>>
>>>>>>>>>>>> Further, I am calculating the Light View Matrix and passing it
>>>>>>>>>>>> to the shader - this one is correct as well, since I am seeing the light in
>>>>>>>>>>>> the scene with the z artifacts as I mentioned .... and this is my GLSL
>>>>>>>>>>>> snippet:
>>>>>>>>>>>>
>>>>>>>>>>>> http://pastebin.com/r2W0gh0L
>>>>>>>>>>>>
>>>>>>>>>>>> I am trying to get it done as simple as is ... meanwhile found
>>>>>>>>>>>> this:
>>>>>>>>>>>>
>>>>>>>>>>>> http://developer.download.nvidia.com/SDK/10/direct3d/Source/
>>>>>>>>>>>> VarianceShadowMapping/Doc/VarianceShadowMapping.pdf
>>>>>>>>>>>>
>>>>>>>>>>>> that looks promising and apparently should help with the Z
>>>>>>>>>>>> issues.
>>>>>>>>>>>>
>>>>>>>>>>>> This is my story for now, any hints are highly appreciated !!!!!
>>>>>>>>>>>>
>>>>>>>>>>>> And thanks a bunch for so far!
>>>>>>>>>>>>
>>>>>>>>>>>> Cheers,
>>>>>>>>>>>>
>>>>>>>>>>>> On Thu, Oct 20, 2016 at 2:56 PM, Voerman, L. <l.voerman at rug.nl>
>>>>>>>>>>>> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>>> yes?
>>>>>>>>>>>>> we use a variation on OpenSceneGraph\src\osgShadow\P
>>>>>>>>>>>>> arallelSplitShadowMap.cpp
>>>>>>>>>>>>> regards, Laurens.
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Thu, Oct 20, 2016 at 2:35 PM, Trajce Nikolov NICK <
>>>>>>>>>>>>> trajce.nikolov.nick at gmail.com> wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hi Laurens,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> do you have experience with DEPTH32bit and shadowcomparation
>>>>>>>>>>>>>> set to true - for shadow mapping?
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> On Thu, Oct 20, 2016 at 12:08 PM, Trajce Nikolov NICK <
>>>>>>>>>>>>>> trajce.nikolov.nick at gmail.com> wrote:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Hi Voerman,
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Yes, GL_DEPTH_COMPONENT32 was what I was missing ... Thanks
>>>>>>>>>>>>>>> a lot!
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Trajce
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> On Thu, Oct 20, 2016 at 9:25 AM, Voerman, L. <
>>>>>>>>>>>>>>> l.voerman at rug.nl> wrote:
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> Hi Trajce,
>>>>>>>>>>>>>>>> maybe this sniplet helps?
>>>>>>>>>>>>>>>> _textureDepthBuffer = new osg::Texture2D;
>>>>>>>>>>>>>>>> _textureDepthBuffer->setTextur
>>>>>>>>>>>>>>>> eSize(_width+2.0f*_width*_guardBandPercentage,
>>>>>>>>>>>>>>>> _height+2.0f*_height*_guardBandPercentage);
>>>>>>>>>>>>>>>> _textureDepthBuffer->setSourceFormat(GL_DEPTH_COMPONENT);
>>>>>>>>>>>>>>>> _textureDepthBuffer->setIntern
>>>>>>>>>>>>>>>> alFormat(GL_DEPTH_COMPONENT32);
>>>>>>>>>>>>>>>> _textureDepthBuffer->setFilter
>>>>>>>>>>>>>>>> (osg::Texture2D::MIN_FILTER,osg::Texture2D::NEAREST);
>>>>>>>>>>>>>>>> _textureDepthBuffer->setFilter
>>>>>>>>>>>>>>>> (osg::Texture2D::MAG_FILTER,osg::Texture2D::NEAREST);
>>>>>>>>>>>>>>>> _textureDepthBuffer->setShadowComparison(false);
>>>>>>>>>>>>>>>> _textureDepthBuffer->setWrap(o
>>>>>>>>>>>>>>>> sg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE);
>>>>>>>>>>>>>>>> _textureDepthBuffer->setWrap(o
>>>>>>>>>>>>>>>> sg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE);
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> // camera
>>>>>>>>>>>>>>>> _colorDepthCamera = new osg::Camera;
>>>>>>>>>>>>>>>> _colorDepthCamera->setStats(new osg::Stats("Camera"));
>>>>>>>>>>>>>>>> _colorDepthCamera->setName("colorDepth");
>>>>>>>>>>>>>>>> _colorDepthCamera->setClearMask(GL_COLOR_BUFFER_BIT |
>>>>>>>>>>>>>>>> GL_DEPTH_BUFFER_BIT);
>>>>>>>>>>>>>>>> _colorDepthCamera->setReferenc
>>>>>>>>>>>>>>>> eFrame(osg::Transform::RELATIVE_RF);
>>>>>>>>>>>>>>>> // set viewport
>>>>>>>>>>>>>>>> _colorDepthCamera->setViewport
>>>>>>>>>>>>>>>> (0,0,_width+2.0f*_width*_guard
>>>>>>>>>>>>>>>> BandPercentage,_height+2.0f*_height*_guardBandPercentage);
>>>>>>>>>>>>>>>> _colorDepthCamera->setRenderOr
>>>>>>>>>>>>>>>> der(osg::Camera::PRE_RENDER,0);
>>>>>>>>>>>>>>>> _colorDepthCamera->setRenderTa
>>>>>>>>>>>>>>>> rgetImplementation(osg::Camera::FRAME_BUFFER_OBJECT);
>>>>>>>>>>>>>>>> _colorDepthCamera->attach(osg::Camera::DEPTH_BUFFER,
>>>>>>>>>>>>>>>> _textureDepthBuffer.get(),0,0,false,0,0); // depth
>>>>>>>>>>>>>>>> _colorDepthCamera->attach(osg::Camera::COLOR_BUFFER,
>>>>>>>>>>>>>>>> _textureColorBuffer.get(),0,0,false,_msaa,_msaa); // color
>>>>>>>>>>>>>>>> regards, Laurens.
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> On Wed, Oct 19, 2016 at 11:15 PM, Trajce Nikolov NICK <
>>>>>>>>>>>>>>>> trajce.nikolov.nick at gmail.com> wrote:
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Hi Community,
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> anyone with clue how to set RTT osg::Texture with 32bit
>>>>>>>>>>>>>>>>> DEPTH?
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> Thanks a bunch as always!
>>>>>>>>>>>>>>>>> Cheers,
>>>>>>>>>>>>>>>>> Nick
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> --
>>>>>>>>>>>>>>>>> trajce nikolov nick
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>> _______________________________________________
>>>>>>>>>>>>>>>>> osg-users mailing list
>>>>>>>>>>>>>>>>> osg-users at lists.openscenegraph.org
>>>>>>>>>>>>>>>>> http://lists.openscenegraph.or
>>>>>>>>>>>>>>>>> g/listinfo.cgi/osg-users-openscenegraph.org
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>> _______________________________________________
>>>>>>>>>>>>>>>> osg-users mailing list
>>>>>>>>>>>>>>>> osg-users at lists.openscenegraph.org
>>>>>>>>>>>>>>>> http://lists.openscenegraph.or
>>>>>>>>>>>>>>>> g/listinfo.cgi/osg-users-openscenegraph.org
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> --
>>>>>>>>>>>>>>> trajce nikolov nick
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> --
>>>>>>>>>>>>>> trajce nikolov nick
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> _______________________________________________
>>>>>>>>>>>>>> osg-users mailing list
>>>>>>>>>>>>>> osg-users at lists.openscenegraph.org
>>>>>>>>>>>>>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-opens
>>>>>>>>>>>>>> cenegraph.org
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> _______________________________________________
>>>>>>>>>>>>> osg-users mailing list
>>>>>>>>>>>>> osg-users at lists.openscenegraph.org
>>>>>>>>>>>>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-opens
>>>>>>>>>>>>> cenegraph.org
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> --
>>>>>>>>>>>> trajce nikolov nick
>>>>>>>>>>>>
>>>>>>>>>>>> _______________________________________________
>>>>>>>>>>>> osg-users mailing list
>>>>>>>>>>>> osg-users at lists.openscenegraph.org
>>>>>>>>>>>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-opens
>>>>>>>>>>>> cenegraph.org
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> _______________________________________________
>>>>>>>>>>> osg-users mailing list
>>>>>>>>>>> osg-users at lists.openscenegraph.org
>>>>>>>>>>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-opens
>>>>>>>>>>> cenegraph.org
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> --
>>>>>>>>>> trajce nikolov nick
>>>>>>>>>>
>>>>>>>>>> _______________________________________________
>>>>>>>>>> osg-users mailing list
>>>>>>>>>> osg-users at lists.openscenegraph.org
>>>>>>>>>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-opens
>>>>>>>>>> cenegraph.org
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> _______________________________________________
>>>>>>>>> osg-users mailing list
>>>>>>>>> osg-users at lists.openscenegraph.org
>>>>>>>>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-opens
>>>>>>>>> cenegraph.org
>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --
>>>>>>>> trajce nikolov nick
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> trajce nikolov nick
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> trajce nikolov nick
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> trajce nikolov nick
>>>>>
>>>>> _______________________________________________
>>>>> osg-users mailing list
>>>>> osg-users at lists.openscenegraph.org
>>>>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-opens
>>>>> cenegraph.org
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> osg-users mailing list
>>>> osg-users at lists.openscenegraph.org
>>>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-opens
>>>> cenegraph.org
>>>>
>>>>
>>>
>>>
>>> --
>>> trajce nikolov nick
>>>
>>
>>
>>
>> --
>> trajce nikolov nick
>>
>
>
>
> --
> trajce nikolov nick
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>


-- 
Chris 'Xenon' Hanson, omo sanza lettere. Xenon at AlphaPixel.com
http://www.alphapixel.com/
Training • Consulting • Contracting
3D • Scene Graphs (Open Scene Graph/OSG) • OpenGL 2 • OpenGL 3 • OpenGL 4 •
GLSL • OpenGL ES 1 • OpenGL ES 2 • OpenCL
Legal/IP • Code Forensics • Digital Imaging • GIS • GPS •
osgEarth • Terrain • Telemetry • Cryptography • LIDAR • Embedded • Mobile •
iPhone/iPad/iOS • Android
@alphapixel <https://twitter.com/alphapixel> facebook.com/alphapixel (775)
623-PIXL [7495]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20161026/afa1feab/attachment-0003.htm>


More information about the osg-users mailing list