Hi Sebastian

> I need to bind the models textures in order to use them in the 
> fragment shader. So far I did not succeed.
> Can you elaborate if it is possible to mix images and classic sampler
> objects with textures? A small extension to the example regarding
> texturing would be really nice

Mixing image units and textures is allowed.
I skipped the texture subject on purpose ( this would make the example even
more complicated ). But I will explain, how it can be implemented.

The problem with instancing is that you have to have all your textures bound
at the moment of drawing. So there are four possible solutions  :
- use only one texture for all instanced objects ( problems, when
  new object must be added )
- build texture atlas from your textures ( I highly recommend NOT to use
  this solution, because if your textures use repeat wrap then it is
  really hard to implement drawing properly ).
- use bindless textures in shaders ( I don't have any experience 
  with that. Furthermore I don't know if bindless textures are Implemented 
  in AMD drivers )
- build an osg::Texture2DArray from your textures, which is the best way 
  in my opinion, but with one caveat : all your textures must be the same size
  and the same format ( 1024x1024 DXT1 for example ).

Let's suppose that your objects use only one texture ( for simplicity ).
The AggregateGeometryVisitor may be the one that builds osg::Texture2DArray.
During object visiting AggregateGeometryVisitor may track statesets to
find what textures are bound. When the geometry is found, the visitor 
should add the texture to texture array and send the index of the texture to 
ConvertTrianglesOperator::setGeometryData().

ConvertTrianglesOperator should create texture coordinates as Vec3Array,
not Vec2Array ( as it does at the moment ). The index of the texture should
be sent as Z in texture coordinates.

The last step is the modyfying of drawing fragment shader :
// I don't remember if the line below is still required in OpenGL 4.2 :
#extension GL_EXT_gpu_shader4 : enable
//  define sampler :
uniform sampler2DArray colorTexture;
// texture coordinates from vertex shader (it is a vec3):
in vec3 TexCoord0;
 // read the data in shader :
vec4 color  = texture2DArray ( colorTexture, TexCoord0 );

If more than one texture is used on the model, then the case is much more
complicated. But can be solved with another level of indirection :)

-- 
Pawel Ksiezopolski

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=58223#58223





_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to