Texture position and scale

Hi,

I need to set specific position and scale to texture, which will be applied on TerrainQuad.

How to do it?

Thanks

You can set the texture scale in the TerrainLighting material by setting the DiffuseMap_X_scale parameter (X = 1…4). This scales both axes, U and V. You cannot currently set different U and V scales. If you wanted to have a different scale on the axes, you would have to modify the texture coordinate in the vertex shader, or adjust the texture coordinates on the terrain patches.



There is no option of offsetting the texture right now, although it wouldn’t be too difficult to add to the fragment shader.

Ok, although I am not familiar with shaders for now, I’ll have a look at it.

I need differently scaled sides because of possible rectangular TerrainQuad heightmap (I made little modification in TerrainQuad and TerrainPatch classes).

Idea of make use of offsetting is if you need to put map tiles one next to another (maybe one tile == one TerrainPatch mesh…I am not sure with this for now).



Thanks :slight_smile:

Actually with some minor changes you could make it scalable on either axis.

If you look at TerrainLighting.frag, line 122, the texCoord is multiplied by the scale.

[java]vec4 diffuseColor = texture2D(m_DiffuseMap, texCoord * m_DiffuseMap_0_scale);[/java]

The texCoord is a vec2 and by multiplying it by the scale, both the x and y values of the vec2 get multiplied. So you could change it to:

[java]

texCoord.x * m_DiffuseMap_0_U_scale

texCoord.y * m_DiffuseMap_0_V_scale

[/java]

(you will have to create your own m_DiffuseMap_0_U_scale, m_DiffuseMap_0_V_scale, variables and pass them in.)

Also in the same place, you could add your offset to the same texture coordinate.

1 Like

Hello,



you dealt with scaling. Any advice for positioning?

Positioning can happen the same way as scaling. It’s not hard to implement, just isn’t implemented yet. I guess it would be a nice feature.



You would just add the translation coordinate (x and y) to the texCoord to offset it.