Page 1 of 1

Question about texturing objects.

Posted: Sat Jan 12, 2019 5:44 pm
by Jay721
Hi everyone. I have a basic cuboid that should stretch on different axes, and I need there to be a tiled texture on each face.

How would I get the texture to tile properly rather than stretch based on each face’s size?

Thanks.

Re: Question about texturing objects.

Posted: Sun Jan 13, 2019 9:46 pm
by Slicky
I'm not sure but it would seem you would need to dynamically change the uv's.

Re: Question about texturing objects.

Posted: Sun Jan 13, 2019 11:36 pm
by xrgo
or map the texture using world space

Re: Question about texturing objects.

Posted: Wed Feb 20, 2019 3:49 pm
by Jay721
xrgo wrote:
Sun Jan 13, 2019 11:36 pm
or map the texture using world space
Hi, what would I have to do to try this approach?

Re: Question about texturing objects.

Posted: Wed Feb 20, 2019 3:59 pm
by xrgo
you'll need to modify the shaders, but the problem is that Hlms is not so easy to customize per datablock, it is possible, I do it, I can share, but since its not that easy I prefer to confirm that this is what you need:

When projecting from world space the texture will stay put in the world, so if you move the object the texture will start to offset as you move it:


if all the objects in your scene needs the same treatment then customizing the shaders for every object is very straightforward

Re: Question about texturing objects.

Posted: Thu Feb 21, 2019 11:57 am
by Jay721
That’s exactly what I need, and I think it should be fine for every object.
I’ll try and have a go later on but I’d appreciate it if you could point me in the right direction.

Thanks!

Re: Question about texturing objects.

Posted: Thu Feb 21, 2019 4:06 pm
by Jay721
Actually, A lot of objects will be moving, so if the texture stays put in the world then it won’t look too impressive. Is there any solution that would have the texture scale according to the world but moves with the object?

Re: Question about texturing objects.

Posted: Fri Feb 22, 2019 1:17 am
by xrgo
That would be some kind of object space texturing, let me see If I am able to do that, give me a day (I am busy with some stuffs :) )

Re: Question about texturing objects.

Posted: Fri Feb 22, 2019 5:51 pm
by Jay721
Ok sounds good thanks.

Re: Question about texturing objects.

Posted: Sat Feb 23, 2019 9:34 pm
by xrgo
(Ogre 2.2, don't know which version you are using) Just for a quick test replacing this piece of code:

Code: Select all

outVs.uv@n = inVs_uv@n;
with this one (only if the object already has an uv):

Code: Select all

outVs.uv@n = inVs_vertex.xz * vec2( worldMat[0].x, worldMat[2].z );
you will get what you need but only projected from top!
what you really need is to implement triplanar mapping:
viewtopic.php?f=25&t=93596
but instead of using the world pos as texture coordinates use the local vertex pos ( inVs_vertex ) and multiply it with the corresponding scale component of the worldMat:

Code: Select all

inVs_vertex.xz * vec2( worldMat[0].x, worldMat[2].z ) from top/bottom
inVs_vertex.xy * vec2( worldMat[0].x, worldMat[2].y ) from front/back
inVs_vertex.yz * vec2( worldMat[0].y, worldMat[2].z ) left/right