How to sample my texture via shader composition

classic Classic list List threaded Threaded
3 messages Options
GameCodingNinja GameCodingNinja
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to sample my texture via shader composition

Below is just some test code to get an idea of what would happen.

        varying vec4 oe_layer_texc;
        void MyFragShader(inout vec4 color)
        {
                color = color * texture2D(myTexture, oe_layer_texc.st);
        }

I'm not sure what oe_layer_tilec, oe_layer_texc or oe_lodblend_texc is or how to best use them. The above code doesn't provide any useful results.

Could someone post an example of how to sample a texture to point me in the right direction?
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to sample my texture via shader composition

Where does your texture come from? Is it from a shared ImageLayer?

oe_layer_tilec is [0..1] in both x and y for each vertex in a terrain tile. So if your texture is from a shared ImageLayer, you can multiple oe_layer_tilec by your texture matrix to position it on a terrain tile.
Glenn Waldron / Pelican Mapping
GameCodingNinja GameCodingNinja
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to sample my texture via shader composition

I'm loading a test texture like so. This could be why it's not working.

  auto image = osgDB::readImageFile("white.png");
  mMyTexture = new osg::Texture2D();
  mMyTexture->setImage(image);

  mMyTextureSampler = new osg::Uniform("myTexture", int(MY_TEXTURE_UNIT));

  auto stateSet = mMapNode->getOrCreateStateSet();
  stateSet->addUniform(mMyTextureSampler);

  stateSet->setTextureAttributeAndModes(
    MY_TEXTURE_UNIT,
    mMyTexture,
    osg::StateAttribute::ON);

Even if I change the shader to "texture2D(myTexture, vec2(0.0, 0.0))" I can tell it's not pulling the right color. The texture is solid white but all I'm getting is black. Not really sure what I'm doi9ng wrong.
Loading...