Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 26-11-2009
Member
 
Join Date: Jun 2009
Posts: 403
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?
Reply With Quote
  #2  
Old 26-11-2009
Member
 
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).
Reply With Quote
  #3  
Old 26-11-2009
Member
 
Join Date: Jun 2009
Posts: 403
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);
Reply With Quote
  #4  
Old 26-11-2009
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 06:06 PM.