# Detecting texture "density" in pixel shaders?

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

## Recommended Posts

Hello. Right now, I'm implementing a parallax mapping shader, and I've ran into a quite subtle problem. Basically, the 'height' of a pixel is computed by sampling the heightmap, and scaling/biasing the value. The problem is, obviously the absolute value of the pixel height is dependent on the tiling amount of the texture. For instance, if I have a brick texture which I texture with tile=1,1 into a quad, we have a certain maximum height, a certain ratio between width/height dimensions and depth, right? Now, if I decide to texture it with tiling=10,10, thus making the bricks 'smaller', I think the height must be scaled appropriately, to keep the ratio constant. Is there any way to obtain that value in the pixel shader? First of all, am I even correct in my view that we need to scale the height that way? If so, what is the way to achieve it? I thought different things, like passing the tiling as uniforms, but this is not very practical, requires manual work and can't work a lot of the time. One solution that crossed my mind was to calculate the texcoord delta(u,v) for each edge, and pass that per each vertex. Basically, something like passing the tangent vector unnormalized. Would that work? I'm hearing suggestions. Thanks a lot!

##### Share on other sites
texture density would depend on the actual texture resolution, but it sounds like you're asking for the texturecoordinate-density relative to the pixels.

if my assumption is right, then you can get your reguested data with the ddx and ddy functions (as you're talking about uniforms, in case you're using glsl, I think it's called dFdx dFdy).

##### Share on other sites
Hm, I'm a afraid those functions have to do with screen-space. What I want is the increase of (u,v) coordinates in world space. For example, in a square with side=1 unit, if it's textured tiled=(1,1), we have (1,1) increase. If it's tiled 10 times, we have (10,10) increase. And so on.

##### Share on other sites
oh, sorry, for some reason I thought you're talking about 2d parallax mapping.

for POM we pass an per-object value that is artist defined. We tried some metrics based on object-scaling, uv2xyz ration etc. but in the end artist always asked for some tweaking parameters.

So yeah, we pass it as 'uniform' to the shader system.

##### Share on other sites
You could do something along the lines of

texcoordDensity = area of ddx(texcoords),ddy(texcoords)
worldSpaceDensity = area of ddx(worldpos),ddy(worldpos)

texCoordDensityPerWorldUnit = texcoordDensity / worldSpaceDensity

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
18

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632998
• Total Posts
3009802
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

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!