Jump to content
  • Advertisement
Sign in to follow this  
#Include Graphics

Texture sampling (tex2D) concrete uv coordinates problem

This topic is 1068 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone,

 

Firstly my apologies for this thread when are some other more interesting themes right now on the forum.

 

I am creating a 2D texture 9x27 storing some 9x9 positions data and using 3 levels of data for the heights there. The thing is that I seem to be unable to access to all that positions and I really dont know why. All works well when I simply use one level, I am using a screen quad and my HLSL code is:

 

On the texture creation

#define NUM_PROBES_X 9
#define NUM_PROBES_Y 9
#define NUM_FACES 6
#define NUM_PROBES_LEVELS 3

#define PROBE_POSITION_SCALE 10000.0f
#define PROBE_POSITION_OFFSET 5000.0f

#define PROBES_POS_WIDTH  200
#define PROBES_POS_HEIGHT  200
#define PROBES_POS_DEPTH  200

PS_OUTPUT ps_main( float2 UV : TEXCOORD0 )
{   
   PS_OUTPUT res = ( PS_OUTPUT )0;

   float3 data;

   int idX = (int)(UV.x*(NUM_PROBES_X));
   int idY = (int)(UV.y*(NUM_PROBES_Y)*NUM_PROBES_LEVELS)%NUM_PROBES_Y;
   
   int level = (int)(UV.y*NUM_PROBES_LEVELS);
      
   float2 position2D = float2( idX * PROBES_POS_WIDTH, idY * PROBES_POS_DEPTH );
   data = ( float3( position2D.x, PROBES_POS_HEIGHT+level*PROBES_POS_HEIGHT, position2D.y )+PROBE_POSITION_OFFSET )*PROBE_POSITION_SCALE;
   
   res.c0 = float4( data, 1 );
   
   return res;   
}

on the render code

const float probesAmount = 0.01234568f;//81 probes

const float probesLevelsAmount = 0.3334f;//3 levels

const float maxProbesX = (1.0/(float)NUM_PROBES_X)+0.0001;
const float maxProbesY = (1.0/(float)NUM_PROBES_Y)+0.0001;

float3 getProbePosition( float probeIdX, float probeIdY, float level )
{
   //float relativeY = probeIdY*maxProbesY;
   float2 coords = float2( (probeIdX*maxProbesX), ((probeIdY*maxProbesY)+level)*probesLevelsAmount );
   //coords = float2(0.01f, dataType*0.333f );
   return ((tex2Dlod( probesDataSampler, float4( coords, 0, 0 ) ).rgb*PROBE_POSITION_SCALE)-PROBE_POSITION_OFFSET);
}

I have been recently driving me crazy and modified a  bit my original code but I hope the essence of the problem is shown. I dont know what I am doing wrong with the UV texcoords I am sending to tex2D but maybe i am not well understanding something, if someone can please iluminate my path sad.png

 

Thank you in advance.

 

Share this post


Link to post
Share on other sites
Advertisement

Check this:

1. Nearest filtering instead of linear filtering active ?

2. Do you access the center of the texel ? Best to use a half-texel offset, in your case (0.5/9.0,0.5/27.0).

3. Is the level value 0,1,2 ? If this is the case, try this ((probeIdY*3+level)*probesLevelsAmount*maxProbesY as y-coord,when using interleaved levels..

Edited by Ashaman73

Share this post


Link to post
Share on other sites

Hello Ahaman73!!

 

Thank you so much for your reply smile.png

 

 

1. Nearest filtering instead of linear filtering active ?

 

Yes I am using D3DTEXF_POINT for min, mag and D3DTEXF_NONE for mipmaps anyway I am not using mipmaps for that texture.

 

 

2. Do you access the center of the texel ? Best to use a half-texel offset, in your case (0.5/9.0,0.5/27.0).

 

Does it really works like that? In that case isnt the real access formula this one?:


const float probeHalfTexelX = (0.5f/(float)NUM_PROBES_X);
const float probeFullTexelX = (1.0f/(float)NUM_PROBES_X);
const float probeHalfTexelY = (0.5f/(float)NUM_PROBES_Y*NUM_PROBES_LEVELS);
const float probeFullTexelY = (1.0f/(float)NUM_PROBES_Y*NUM_PROBES_LEVELS);

float3 getProbePosition( float probeIdX, float probeIdY, float level )
{
   //float relativeY = probeIdY*maxProbesY;
   float2 coords = float2( ( probeIdX*probeFullTexelX+probeHalfTexelX ), ( ( (probeIdY*probeFullTexelY)+probeHalfTexelY )+( level*probesLevelsAmount ) ) );
   //coords = float2(0.01f, dataType*0.333f );
   return ((tex2Dlod( probesDataSampler, float4( coords, 0, 0 ) ).rgb*PROBE_POSITION_SCALE)-PROBE_POSITION_OFFSET);
}

 

 

 

3. Is the level value 0,1,2 ? If this is the case, try this ((probeIdY*3+level)*probesLevelsAmount*maxProbesY as y-coord,when using interleaved levels..

 

Yes, all my indexes goes from 0-(MAX-1)

 

 

 

Apart of all of this I will try uploading the 9x27 image of my probes positions. IMHO it is malformed on the blue component which is continuously repeated. So maybe there is another big problem.

Edited by #Include Graphics

Share this post


Link to post
Share on other sites

Omg so sorry people, It seems I have one of this days...

 

I have fixed this texture create malformation by using

 

int idY = (int)((UV.y*NUM_PROBES_Y*NUM_PROBES_LEVELS)%NUM_PROBES_Y);

 

instead of

 

int idY = (int)(UV.y*NUM_PROBES_Y*NUM_PROBES_LEVELS)%NUM_PROBES_Y;

 

Apologizies for that, but I am still managing to access that data properly.

Edited by #Include Graphics

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!