Texture mapping according with vertex position(terrain generation)

I think that it may simply be that you’re not applying the texture-transforms in your shader. You’re simply using untransformed texture-coordinates, and thus the scaling is never put into effect.

The texture-transforms are–if I’m not much mistaken–supplied automatically by Panda3D to your shaders, and goes into a uniform array called “p3d_TextureMatrix”–like so:
uniform mat4 p3d_TextureMatrix[];
(As shown here.)

The transforms thus provided are then multiplied by your texture-coordinates to get the final, transformed coordinates–like so:
vec4 finalTexCoord = p3d_TextureMatrix[0] * texcoord0;
(I’m showing that as a single line for the sake of clarity; naturally this can just be done within the call to “texture2D”.)

I wouldn’t like to swear to it, as I don’t think that I’ve worked with multiple texture-transform layers myself, but I imagine that the transforms are indexed just as the textures are–thus “p3d_TextureMatrix[0]” would correspond to “p3d_MultiTexCoord0”, “p3d_TextureMatrix[1]” would correspond to “p3d_MultiTexCoord1”, and so on.

1 Like

What @Thaumaturge says is exactly right, but to be honest, if you know you are just applying a scale, I’d just do a multiplication with the UV coordinates in the shader.

1 Like

Yes, that’s exactly what I have done:

vec4 texel0 = texture2D(p3d_Texture0, texcoord0.st * TexScaleFactor0).rgba;

where TexScaleFactor0 is passed with setShaderInput.

What do you think? :slight_smile:

2 Likes

BTW, here is the path to the repository. Maybe it will be useful to someone in the future :slight_smile:

1 Like