Get the scale of the texture mapping?

Started by
6 comments, last by amelia1111 7 months, 3 weeks ago

This is a new idea to me and I'm not sure how to describe it correctly.

I've realized that tessellation / displacement needs to be scaled proportionately to the texture mapping size. If the texture is mapped over a larger area, the displacement map needs to stick out more from the surface.

Is there any easy way to get a “mapping scale” value in a GLSL fragment shader? The closest thing I can think of is textureQueryLod, but I don't think that is really applicable here.

10x Faster Performance for VR: www.ultraengine.com

Advertisement

I'm not sure if this is really needed, at least in my implementation of POM. Maybe you need to scale the height by 1/UV scale in displacement mapping? Here are some examples where I only vary the UV scale from 0.1, to 2.0, no changes to height. You can see that the height changes inversely with the UV so that the proportions stay correct.

0.1 UV Scale
0.5 UV Scale
2.0 UV Scale

How do you know the UV scale if all you have is a single texture coordinate?

10x Faster Performance for VR: www.ultraengine.com

Josh Klint said:
How do you know the UV scale if all you have is a single texture coordinate?

I pass it in to shader as a uniform. All it does is multiply with the vertex UV. I also pass in a height scale uniform which is set manually for each material to get the right amount of displacement. The height map is always normalized to [0,1] range (for better precision) and the height scale is a unitless factor defined in terms of UV (i.e. units of height per UV). So as the UV gets scaled the height automatically gets scaled because its defined in UV units. If the original height range of the real surface was [0,zMax] and the texture covers an area of size X by X, then height scale would be zMax/X. Usually it's around 0.02 to 0.05, representing a maximum displacement of 4 to 10 cm for a 2 meter texture.

It looks like you are scaling the texture coordinates and displacement by a uniform value. What happens if you change the mesh texture coordinates themselves? How would the displacement value adjust for that? The only thing I can think of is that a per-triangle UV scale value must be applied, so the shader knows the area over which the texture is applied.

10x Faster Performance for VR: www.ultraengine.com

Josh Klint said:
It looks like you are scaling the texture coordinates and displacement by a uniform value. What happens if you change the mesh texture coordinates themselves? How would the displacement value adjust for that? The only thing I can think of is that a per-triangle UV scale value must be applied, so the shader knows the area over which the texture is applied.

I don't quite understand the issue. Generally mesh UVs are created with a constant scale for the parameterization (or as close as can be achieved). For instance, artists might have a target of 512px per meter, assuming 1024px textures, so that the UV space covers 2 meters. So, there shouldn't be any need for a per-triangle scale, just a global one if the UVs are not authored to spec. For assets with unknown scale, I suppose you could inspect the mesh triangles and UVs during build time to determine the average UV scale (uv per meter).

That's a good point. Thanks!

10x Faster Performance for VR: www.ultraengine.com

This topic is closed to new replies.

Advertisement