Results 1 to 4 of 4

Thread: How to index a texture

  1. #1
    Join Date
    Jun 2009
    Posts
    404

    How to index a texture

    I want to encode a data structure in a 3D texture and access in a fragment shader in GLSL. In GLSL, there is no pointer and there is no clean way to access by index. It seems that the only way to access a texture is to send coordinates scalar.

    Imagine the simple case of a 1D texture of size N. I want to access the value in box number k of my texture. The case k may for example contain the number of a child or a neighbor in my data structure. It is very important that I get exactly the value stored at this location in the texture and not an interpolated value.

    Does texture1D(id, k / (float) N) work? Is that from the data access there is no interpolation or other filtering that could screw up my value?

  2. #2
    Join Date
    Nov 2008
    Posts
    1,022

    Re: How to index a texture

    According to me, it depends on how the sampler is configured. It should be put in nearest. After the formatting of the coordinate, we must watch the conventions used in OpenGL. That means sampling in texture, it can be done by nearest sampling, bilinear filtering, with mipmapping, trilinear aniso bili / tril. Logically for unfiltered access, it must be nearest (no mipmap).

  3. #3
    Join Date
    Jun 2009
    Posts
    404

    Re: How to index a texture

    But, now I have another problem. To my index I use floating, and I have problems with details of what is stored in textures. Let's say I want to store an integer n in a square texture. I store a float: n / coef where I am assured that float coef always be greater than all the n possible to always have a float value between 0 and 1.

    Then in my fragment shader that I value and I remultiply by coef. I should return by n. But that does not work well at all. When n and coef are about 1000 of my value is of type n + - 20% of true value! To make the indexing is not really top ...

    You have an idea of where it can go and how to fix that? Unfortunately I also need to store floating in my texture so I can not use a full texture.

    I tested by the scope of division and multiplication in the shader and I have no problem with accuracy. This indicates that my lose data precision somewhere in the transfer.

    I'm a glTexImage3D (GL_TEXTURE_3D, 0, GL_RGBA16,
    arraySize [0], arraySize [1], arraySize [2]
    0, GL_RGBA, GL_FLOAT, array);

  4. #4
    Join Date
    Nov 2008
    Posts
    1,022

    Re: How to index a texture

    With GL_RGBA16, you have the 16 bits integers with internal format. Basically the problem is that floats are on 32bit CPU on your machine and it is trashing you to convert 16bits on the GPU. The conversion must still be well because to lose 20% on something on the order of 10 ^ -3 is terrible. Try RGBA32F, without your conversion, and see if it works.

Similar Threads

  1. Saints Row 3 texture are not appropriate
    By Edie Adams in forum Video Games
    Replies: 7
    Last Post: 20-11-2011, 11:54 AM
  2. CG Texture Conservation Help
    By Bhartiya-Technician in forum Windows Software
    Replies: 6
    Last Post: 13-05-2010, 04:11 PM
  3. Does Google decides which content to index & what not to index?
    By Uddhav in forum Technology & Internet
    Replies: 5
    Last Post: 04-03-2010, 07:37 PM
  4. Inserting an index entry into index 0 of file 25
    By Dharmesh Arora in forum Operating Systems
    Replies: 3
    Last Post: 16-07-2009, 10:10 AM
  5. UV Texture in blender 2.48
    By Lord in forum Windows Software
    Replies: 6
    Last Post: 24-03-2009, 10:01 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,153,695.86719 seconds with 16 queries