Sign in to follow this  

Detecting texture "density" in pixel shaders?

This topic is 2846 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. 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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites

This topic is 2846 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this