Discussion:
[osg-users] Value of a variable in shaders?
Rowley, Marlin R
2018-09-27 18:14:04 UTC
Permalink
All,

Is there a way to examine variable values in shader code? I can't figure out this problem that we are having unless I can see the values in the shaders.

Any help would be appreciated

----------------------------------------
Marlin Rowley
Software Engineer, Staff
[cid:***@01D39374.DEC5A2E0]
Missiles and Fire Control
972-603-1931 (office)
214-926-0622 (mobile)
***@lmco.com<mailto:***@lmco.com>
Robert Osfield
2018-09-28 06:40:28 UTC
Permalink
Hi Marlin,
Is there a way to examine variable values in shader code? I can’t figure
out this problem that we are having unless I can see the values in the
shaders.
To pass data into shaders you have use a combination of uniforms
(osg::Unfiorm), textures (osg::Textre*) and vertex attributes. With recent
3.4.x onwards you also have the option of passing in constants via
#prama(tic) shader composition system that passes #define values into the
compilation of shaders.

Shaders are a big topic so it's impossible for me to give you a full guide,
there are plenty of reosurces online about GLSL shaders, within the OSG
search for uses of osg::Program, osg::Shader, osg::Uniform.

Robert.
Werner Modenbach
2018-09-28 08:22:41 UTC
Permalink
Hi Marlin,

in case you want to know the value of a variable (not uniform) of a shader
there is no way (to my knowledge) inspecting it like in a debugger.
The usual workaround is visualizing things by coloring the output pixels.
If you want to "see" the "value" of a normal vector you can just take it
as a
color and set it in the fragment shader as the output color.
Be creative when "debugging" other values: Bools or thresholds go black
and white etc.
If you have to "debug" values in vertex or geometry shaders, just pass
colors to the fragment shader.

I hope this helps a little.

- Werner -
Post by Robert Osfield
Hi Marlin,
On Thu, 27 Sep 2018 at 19:30, Rowley, Marlin R
Is there a way to examine variable values in shader code? I can’t
figure out this problem that we are having unless I can see the
values in the shaders.
To pass data into shaders you have use a combination of uniforms
(osg::Unfiorm), textures (osg::Textre*) and vertex attributes.  With
recent 3.4.x onwards you also have the option of passing in constants
via #prama(tic) shader composition system that passes #define values
into the compilation of shaders.
Shaders are a big topic so it's impossible for me to give you a full
guide, there are plenty of reosurces online about GLSL shaders, within
the OSG search for uses of osg::Program, osg::Shader, osg::Uniform.
Robert.
 
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Robert Osfield
2018-09-28 08:41:18 UTC
Permalink
Hi Marlin,
To pass data into shaders you have use a combination of uniforms (osg::Unfiorm), textures (osg::Textre*) and vertex attributes. With recent 3.4.x onwards you also have the option of passing in constants via #prama(tic) shader composition system that passes #define values into the compilation of shaders.
Seems I mis-read your question :-)

Testing internal values in shader is an easy thing to do, what I end
up doing is build up shaders bit by bit making sure each bit works on
it's own before I assemble it into a more complex shader. When I want
to test values I usually just set the fragment colour value, though
often this will have a processed version of the value to make it
visible. You can use #ifdef's in shaders to toggle the debug code
paths and even toggle these paths on/off via the
osg::StateSet::setDefine("ENABLE_DEBUG");

Robert.
Rowley, Marlin R
2018-09-28 13:48:04 UTC
Permalink
Robert,

LOL @ mis-reading my question. 😊

How would you check the values of vertices? I just need to see the transformed values of a vertex.

Thanks,

-M

----------------------------------------
Marlin Rowley
Software Engineer, Staff

Missiles and Fire Control
972-603-1931 (office)
214-926-0622 (mobile)
***@lmco.com

-----Original Message-----
From: osg-users <osg-users-***@lists.openscenegraph.org> On Behalf Of Robert Osfield
Sent: Friday, September 28, 2018 3:41 AM
To: OpenSceneGraph Users <osg-***@lists.openscenegraph.org>
Subject: EXTERNAL: Re: [osg-users] Value of a variable in shaders?

Hi Marlin,
To pass data into shaders you have use a combination of uniforms (osg::Unfiorm), textures (osg::Textre*) and vertex attributes. With recent 3.4.x onwards you also have the option of passing in constants via #prama(tic) shader composition system that passes #define values into the compilation of shaders.
Seems I mis-read your question :-)

Testing internal values in shader is an easy thing to do, what I end up doing is build up shaders bit by bit making sure each bit works on it's own before I assemble it into a more complex shader. When I want to test values I usually just set the fragment colour value, though often this will have a processed version of the value to make it visible. You can use #ifdef's in shaders to toggle the debug code paths and even toggle these paths on/off via the osg::StateSet::setDefine("ENABLE_DEBUG");

Robert.
_______________________________________________
osg-users mailing list
osg-***@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Robert Osfield
2018-09-28 13:54:14 UTC
Permalink
My best excuses is speed reading and trying to do too many things at once
:-)
Post by Rowley, Marlin R
How would you check the values of vertices? I just need to see the
transformed values of a vertex.
One way would be to use a draw callback attached to the program
osg::Geometry that reports the current ModelView and Projection matrices
and the list of vertices, at least then you could double check the input
values.

Checking the vertices on GPU isn't don't something that is easy at runtime
without changing the rendering quite extensively such as using
Transfom_Feedback:

https://www.khronos.org/opengl/wiki/Transform_Feedback

The other possibility would be to see what tools are available on your
OS/hardware/driver combination.

Rowley, Marlin R
2018-09-28 13:38:56 UTC
Permalink
Robert,

I’ve written the shaders already and am well-versed in writing them. I just need a debugging tool that will allow me to see their values at runtime.

----------------------------------------
Marlin Rowley
Software Engineer, Staff
[cid:***@01D39374.DEC5A2E0]
Missiles and Fire Control
972-603-1931 (office)
214-926-0622 (mobile)
***@lmco.com<mailto:***@lmco.com>

From: osg-users <osg-users-***@lists.openscenegraph.org> On Behalf Of Robert Osfield
Sent: Friday, September 28, 2018 1:40 AM
To: OpenSceneGraph Users <osg-***@lists.openscenegraph.org>
Subject: EXTERNAL: Re: [osg-users] Value of a variable in shaders?

Hi Marlin,
On Thu, 27 Sep 2018 at 19:30, Rowley, Marlin R <***@lmco.com<mailto:***@lmco.com>> wrote:
Is there a way to examine variable values in shader code? I can’t figure out this problem that we are having unless I can see the values in the shaders.

To pass data into shaders you have use a combination of uniforms (osg::Unfiorm), textures (osg::Textre*) and vertex attributes. With recent 3.4.x onwards you also have the option of passing in constants via #prama(tic) shader composition system that passes #define values into the compilation of shaders.

Shaders are a big topic so it's impossible for me to give you a full guide, there are plenty of reosurces online about GLSL shaders, within the OSG search for uses of osg::Program, osg::Shader, osg::Uniform.

Robert.
Sebastian Messerschmidt
2018-09-28 06:59:44 UTC
Permalink
Hi,

Usually you can use the output-colors in case of a fragment shader to
inspect the values per fragment. Rendering to a texture and inspecting
the values in the image is also an option.

Another approach to display incoming/per state values is this nifty shader:

http://mew.cx/drawtext/drawtext.html

Appart from this, in case you're using a modern Nvidia-GPU and
Visual-Studio:

https://developer.nvidia.com/nsight-visual-studio-edition

Cheers
Sebastian
All,
Is there a way to examine variable values in shader code? I can’t figure
out this problem that we are having unless I can see the values in the
shaders.
Any help would be appreciated
----------------------------------------
Marlin Rowley
Software Engineer, Staff
/Missiles and Fire Control/
972-603-1931 (office)
214-926-0622 (mobile)
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Rowley, Marlin R
2018-09-28 13:42:34 UTC
Permalink
Thanks, I'll look into that.

----------------------------------------
Marlin Rowley
Software Engineer, Staff

Missiles and Fire Control
972-603-1931 (office)
214-926-0622 (mobile)
***@lmco.com

-----Original Message-----
From: Sebastian Messerschmidt <***@gmx.de>
Sent: Friday, September 28, 2018 2:00 AM
To: OpenSceneGraph Users <osg-***@lists.openscenegraph.org>; Rowley, Marlin R (US) <***@lmco.com>
Subject: EXTERNAL: Re: [osg-users] Value of a variable in shaders?

Hi,

Usually you can use the output-colors in case of a fragment shader to inspect the values per fragment. Rendering to a texture and inspecting the values in the image is also an option.

Another approach to display incoming/per state values is this nifty shader:

http://mew.cx/drawtext/drawtext.html

Appart from this, in case you're using a modern Nvidia-GPU and
Visual-Studio:

https://developer.nvidia.com/nsight-visual-studio-edition

Cheers
Sebastian
All,
Is there a way to examine variable values in shader code? I cant
figure out this problem that we are having unless I can see the values
in the shaders.
Any help would be appreciated
----------------------------------------
Marlin Rowley
Software Engineer, Staff
/Missiles and Fire Control/
972-603-1931 (office)
214-926-0622 (mobile)
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.
org
Continue reading on narkive:
Loading...