Image & fragment shader

classic Classic list List threaded Threaded
9 messages Options
JD JD
Reply | Threaded
Open this post in threaded view
|

Image & fragment shader

Hi,

I want to change the colors of an Image Layer through a shader.
The image is a GeoTiff with only one band.
To customize the coloring I add the <shader> tag and use the "fragment_coloring" position in my earth file and it works.
But this way I have to use as input a preprocessed color value which ranges from 0 to 1 (inout vec4 color).
I would like to kown if it is possible to access the interpolated value on that fragment of the original raster band ?

Thank you,
Jérôme.
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Image & fragment shader

Jérôme,

Set the property coverage="true" on the image layer. This will preserve the original values (as floats) instead of interpreting them as colors.
Glenn Waldron / Pelican Mapping
JD JD
Reply | Threaded
Open this post in threaded view
|

Re: Image & fragment shader

Ok i can now have the source value from color.x. But is it possible to have it interpolated xith neighboors ?
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Image & fragment shader

Treating it as a coverage will cause the texture to use nearest-neighbor sampling, so you won't get any interpolation. You can do the bilinear interpolation yourself; I found some sample code here.
Glenn Waldron / Pelican Mapping
JD JD
Reply | Threaded
Open this post in threaded view
|

Re: Image & fragment shader

Thank you for the link.

I have another question regarding the shader code for ImageLayers.
My earth file is:

<map name="test" type="geocentric" version="2">

	<options>
		<terrain color="#000050" />
	</options>
	
	<image name="elevationBack" driver="gdal" coverage="false" visible="true">
		<url>C:/PROJECTS/DYNAMO/Data/topo30_pack_180_nd0_tiled_ovr.tif</url>
        </image>
</map>

Without shader code, the terrain color appears where NODATA is defined, like if NODATA are treated as transparent and then the terrain color reveals.
When added a GLSL code at fragment_coloring position, all the globe will be painted. Thus, for the NODATA, I tried setting the color to fully transparent or to discard it but this way the concerned parts of the globe become transparent (I see the clear/background color, not the terrain color).
How can I get, with shader code, the terrain color to display where NODATA is defined in the layer as it is the case without shader code?

Thank you.
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Image & fragment shader

Jerome,
This certainly looks like a bug - but I don't have a quick fix in mind. Can you please open a Github issue? Thanks.
Glenn Waldron / Pelican Mapping
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Image & fragment shader

ON second thought, I will create the issue -- never mind :)
Glenn Waldron / Pelican Mapping
JD JD
Reply | Threaded
Open this post in threaded view
|

Re: Image & fragment shader

Hi,

Is there a documentation available about the uniform/attributes that are available at each OsgEarth shader stage ?
I mean for example what is the uniform name to get the texture in my case, how do I get the texture u v coordinates ?

Sorry if my questions are stupid! I am new in GLSL development.

Cheers,
Jérôme.
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Image & fragment shader

Jérôme,

No, there's no documentation, just the example earth files. Here are the ones you asked for:

uniform sampler2D oe_layer_tex; // texture
uniform mat4 oe_layer_texMatrix; // texture matrix
vec4 oe_layer_tilec; // texture coordinates

To sample it:

vec4 texel = texture(oe_layer_tex, (oe_layer_texMatrix*oe_layer_tilec).st);

Glenn Waldron / Pelican Mapping