[osg-users] Check if sampler2D is valid in fragment shader

Sebastian Messerschmidt sebastian.messerschmidt at gmx.de
Tue Dec 27 07:11:23 PST 2016



Hi Rômulo,
> Hi,
>
> is there a way to check if a texture (as uniform sampler2D) is valid in fragment shader?
There is no direct way. If you need shaders with and without texturing 
you should bind different programs to the affected geometries.
Also OSG has the pragmatic-shadercomposition which allows you to use 
#defines to be set in the OSG-code. See the osgshadercomposition for 
reference.

>
> This is my current code:
>
>
> Code:
>
> if (textureSize(myTexture, 0).x > 1) {
> // do something with the texture
> }
> else {
> // process without texture information
> }
You shouldn't use this. AFAIK there is no rule how the driver evaluates 
non-bound samplers, so this might lead to undesired behavior. Even if it 
is working it will cost some amount of performance.

Cheers
Sebastian
>
>
>
> ...
>
> Thank you in advance!
>
> Cheers,
> Rômulo
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=69772#69772
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




More information about the osg-users mailing list