Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Texture.offset/repeat vs. Material.offset/repeat #3549

Closed
WestLangley opened this issue Jun 7, 2013 · 10 comments
Closed

Texture.offset/repeat vs. Material.offset/repeat #3549

WestLangley opened this issue Jun 7, 2013 · 10 comments

Comments

@WestLangley
Copy link
Collaborator

As pointed out in this stackoverflow question, .offset and .repeat are properties of a texture, not a material.

Suppose, for example, a user wants to share a spritesheet across multiple materials. Currently that is not possible, since offset is a property of the texture, and can only be set once.

Also, making offset a property of a material would avoid the "uv repeat and offset setting priorities" in WebGLRenderer.

    // uv repeat and offset setting priorities
    //  1. color map
    //  2. specular map
    //  3. normal map
    //  4. bump map

This code logic forces all the texture offsets/repeats to be the same, anyway.

Should .offset and .repeat be properties of a material instead?

@huttarl
Copy link
Contributor

huttarl commented Jun 7, 2013

I was the one who asked the stackoverflow question. Thanks for posting the issue in this tracker.
Having offset (and repeat) be properties of a material instead of a texture makes sense to me (though I'm not an expert).

Illustration of separate cubelets with the same image, but that need separate offsets:

flipcube

Another possibility I wondered about was to have multiple texture objects that share the same image. That would allow us to have two different meshes using the same image in their material's texture, but at different offsets,
because the textures were separate.

@mrdoob
Copy link
Owner

mrdoob commented Jun 10, 2013

Yep. I agree that offset and repeat should be per texture.

@WestLangley
Copy link
Collaborator Author

@mrdoob

Yep. I agree that offset and repeat should be per texture.

Did you mean to say "material" -- or did you mean to say "disagree"?

@huttarl

Another possibility I wondered about was to have multiple texture objects that share the same image.

As I pointed out in my (edited) answer to your stackoverflow post, this is doable already via texture cloning.

@mrdoob
Copy link
Owner

mrdoob commented Jun 11, 2013

Yep. I agree that offset and repeat should be per texture.

Did you mean to say "material" -- or did you mean to say "disagree"?

Per "texture"+"material", sorry :)

@WestLangley
Copy link
Collaborator Author

OK, closing.

@mrdoob
Copy link
Owner

mrdoob commented Jun 11, 2013

The thing is... for the currently API design, the only solution would be doing this:

material.map
material.mapOffset
material.mapRepeat
material.env
material.envOffset
material.envRepeat
...

And that's quite messy.

With WebGLRenderer3 I want to explore an API along the lines of this:

var texture = new THREE.Texture( 'image.png' );
var material = new THREE.MeshMaterial(
    [
        new THREE.TextureMap( texture, offset, repeat, blending ),
        new THREE.EnvironmentMap( texture, offset, repeat, blending ),
        new THREE.BumpMap( texture, offset, repeat, blending ),
        ...
    ]
);

@Monokai
Copy link

Monokai commented Apr 30, 2014

I'm also looking for a solution. If I understand correctly, I now have to duplicate a texture for each individual material for which I want to have different offset / repeat values. This results in unnecessary memory usage.

My use case is that I have a bitmap font sprite sheet with digits 0 - 9 laid out vertically, and 10 objects for a score counter so that I can smoothly tween individual numbers to display a new score by changing their individual offsets (the effect is something like a flip counter).

Is there a way to share only one texture and use different offset / repeat values for each of the 10 objects' materials?

@WestLangley
Copy link
Collaborator Author

@Monokai

As stated in the guidelines, help requests should be directed to stackoverflow. This board is for bugs and feature requests.

I now have to duplicate a texture for each individual material

clone the texture, thereby sharing the image. See http://threejs.org/examples/misc_ubiquity_test2.html

@Monokai
Copy link

Monokai commented Apr 30, 2014

Thanks for your tip and sorry to disrupt this board.

@bhouston
Copy link
Contributor

bhouston commented Mar 3, 2016

I've just submitted a PR that should address this issue, PR #8278

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants