Show Part of a Texture (Shader)

Hi guys :slight_smile: I’ve decided to continue learning Shaders. I’m making some progress, and am now meddling around with the Unshaded Shader. One thing I haven’t been able to do is change it to show only a part of a texture of the Color Map (say a quarter).

I assumed that texCoord1 and texCoord2 were the variables I had to toy with to achieve the desired effect, but I’m not having too much luck at the moment.

This is the part of the code I’m trying to change, although results are kind of sporadic:
texCoord1 = inTexCoord;

An experiment I tried:
texCoord1 = vec2(2, 16);

And:
texCoord1 = vec2(0.25f, 1);

What should I change to show only part of the texture on the material? Thanks in advance!

Maybe http://hub.jmonkeyengine.org/javadoc/com/jme3/scene/Mesh.html#scaleTextureCoordinates(com.jme3.math.Vector2f) does what you want?

Thanks wezrule, however I was planning on making a small sprite Shader, so I don’t think that’s what I’m looking for. In a nutshell, there would be 8 different images next to each other (or in a box) packed in one image, and depending on the Time passed, it would alternate and show different images. In that case, I don’t think that scaleTextureCoordinates would work. I also remember asking how sprites would work, and someone said that the right way to do it would be to use a Shader.

Thats just essentially a texture atlas then. It’s defiantly not required to have a shader for that. Just change the texture buffer coordinates:

http://hub.jmonkeyengine.org/forum/topic/modifying-a-mesh/#post-148777

Thanks a lot :slight_smile: Will check that out!