Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualBacterius

Posted 17 December 2012 - 02:17 AM

The "i" coordinate is in texture space, e.g. (0, 0) to (1, 1). You need to multiply your ix and iy by the texture's width and height respectively to reach the correct texel in your 2D array. Otherwise it is correct and the +0.5 is correct as well (for rounding). Be aware that you will need to simulate bilinear or trilinear sampling on the CPU if you use those kinds of samplers which is a pain (here it is a nearest-neighbor point sampler, so there's no need).

nx = m_NoiseData[(int)(iy * 256 + 0.5f)  % 256][(int)(ix * 256 + 0.5f) % 256] / 256.0f;

If you are using D3D10 or better, you could use a compute shader to get this kind of information from the GPU without a rewrite (and you can also use it to get height information for other entities like enemies). Not necessarily more efficient, but it spares you the need to port GPU stuff like perlin noise etc.. to the CPU (and it's not like one height query is the bottleneck.. right?)

#3Bacterius

Posted 16 December 2012 - 04:29 PM

The "i" coordinate is in texture space, e.g. (0, 0) to (1, 1). You need to multiply your ix and iy by the texture's width and height respectively to reach the correct texel in your 2D array. Otherwise it is correct and the +0.5 is correct as well (for rounding). Be aware that you will need to simulate bilinear or trilinear sampling on the CPU if you use those kinds of samplers which is a pain (here it is a nearest-neighbor point sampler, so there's no need).

nx = m_NoiseData[(int)(iy * 256 + 0.5f)  % 256][(int)(ix * 256 + 0.5f) % 256] / 256.0f;

If you are using D3D10 or better, you could use a compute shader to get this kind of information from the GPU without a rewrite (and you can also use it to get height information for other entities like enemies). Not necessarily more efficient, but it spares you the need to port GPU stuff like perlin noise etc.. to theCPU.

#2Bacterius

Posted 16 December 2012 - 04:25 PM

The "i" coordinate is in texture space, e.g. (0, 0) to (1, 1). You need to multiply your ix and iy by the texture's width and height respectively to reach the correct texel in your 2D array. Otherwise it is correct and the +0.5 is correct as well (for rounding). Be aware that you will need to simulate bilinear or trilinear sampling on the CPU if you use those kinds of samplers which is a pain (here it is a nearest-neighbor point sampler, so there's no need).

nx = m_NoiseData[(int)(iy * 256 + 0.5f)  % 256][(int)(ix * 256 + 0.5f) % 256] / 256.0f;

#1Bacterius

Posted 16 December 2012 - 04:25 PM

The "i" coordinate is in texture space, e.g. (0, 0) to (1, 1). You need to multiply your ix and iy by the texture's width and height respectively to reach the correct texel in your 2D array. Otherwise it is correct and the +0.5 is correct as well (for rounding). Be aware that you will need to simulate bilinear or trilinear sampling on the CPU if you use those kinds of samplers which is a pain (here it is a point sampler, so there's no need).

nx = m_NoiseData[(int)(iy * 256 + 0.5f)  % 256][(int)(ix * 256 + 0.5f) % 256] / 256.0f;

PARTNERS