Jump to content
  • Advertisement
Sign in to follow this  
adrian_134

LUT texture for procedural terrain textring

This topic is 2504 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

Hi!

I create lut texture for precedural terrain texturing, that texture have the same size what my heightmap, because i want to store texture id in each pixel for one vertex, for example pixel[0, 1] store texture id for vertex[0, 1]. But i have problem when i try read texture id in pixel shader.

LUT texture is D3DFMT_A8R8G8B8.

That is code who save data to lut texture:

int getTextureID(D3DXVECTOR3 n)
{
D3DXVECTOR3 nn;
D3DXVec3Normalize(&nn, &n);
if(nn.y <= 0.9f)
{
return 10;
}
return 0;
}

///
void generateTerrainVertex()
{
D3DXVECTOR3 p(0.0f, 0.0f, 0.0f);
int c = 0;
for(int i = 0; i < cWidth; i++)
{
p.z = -(float)i * 2.0f);
for(int j = 0; j < cHeight; j++)
{
p.x = (float)j * 2.0f;

p.y = cHeightMap[getVertex(i, j)];
v[c].pos = p;
v[c].normal = calcNormal(i, j);
v[c].texcoord.x = (float)i / (float)cLUT->getWidth();
v[c].texcoord.y = (float)j / (float)cLUT->getHeight();


// LUT Texture

int id = getTextureID(v[c].normal);
data[i + j * cLUT->getWidth()] = (id<<16) | (0<<8) | 0;

c++;
}
}
}

The code is very simple because i want to lern this technique...

In my pixel shader i read texure id:

float3 Color = c0;

float3 B = tex2D(lutSampler, input.nonTiledTexCoord).rgb;
int texID = int(B.r);
if(texID == 10)
{
Color = c1;
}

"texID == 10" is false, i don't know why, why texID isn't 10 ? When i generated vertex i saved to lut texture 10 or 0, in pixel shader i have unknown value... Why ?
When i change the code:

float3 Color = c0;
float3 B = tex2D(lutSampler, input.nonTiledTexCoord).rgb;
if(B.r >= 0.01f)
{ Color = c1;}

And i get this:
http://www.coubetech.republika.pl/p.jpg
The result is correctly but why b.r have unknown value ?

c0 - grass
c1 - stone

Share this post


Link to post
Share on other sites
Advertisement
That texture format will return a normalized [0, 1] floating point value in the shader, which means you will never a get a value of 10. You will have to multiply by 255 to convert it back to what you had in its 8-bit integer representation.

Also you should know that D3D9 shaders don' t support integer operations, the code you wrote will be expressed entirely with floating point numbers and operations.

Share this post


Link to post
Share on other sites
I was definite if D3D9 don't support integer operations the compilator show any error, i tried multibly by 255 ant convert to int but i got bad result, now i know why.

I have last question, i rode this article http://www.gamedev.net/blog/73/entry-1692117-terrain-texturing-explained/ and i saw what data are save to lut texture, on U axis slope, on V axis altitude. This is good solution because i don't must refresh my lut texture when i change terrain geometry. But i don't know how i should save altitude data, range on V axis is 0-1, my heightmap vertex can have any height. How save and read this ? I should do somthing like this:
Pixel Shader:

float height;
float3 B = tex2D(lutsampler, float2(height / LUTTextureHeight, normal.y);

Or:

float height;
float3 B = tex2D(lutsampler, float2(height / MaxTerrainHeight, normal.y);

I don't know how i should do this....

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!