Question about texturing objects.

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
Jay721
Halfling
Posts: 62
Joined: Mon Jan 29, 2018 8:19 am

Question about texturing objects.

Post 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.
Slicky
Bronze Sponsor
Bronze Sponsor
Posts: 614
Joined: Mon Apr 14, 2003 11:48 pm
Location: Was LA now France
x 25

Re: Question about texturing objects.

Post by Slicky »

I'm not sure but it would seem you would need to dynamically change the uv's.
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: Question about texturing objects.

Post by xrgo »

or map the texture using world space
Jay721
Halfling
Posts: 62
Joined: Mon Jan 29, 2018 8:19 am

Re: Question about texturing objects.

Post 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?
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: Question about texturing objects.

Post 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
Jay721
Halfling
Posts: 62
Joined: Mon Jan 29, 2018 8:19 am

Re: Question about texturing objects.

Post 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!
Jay721
Halfling
Posts: 62
Joined: Mon Jan 29, 2018 8:19 am

Re: Question about texturing objects.

Post 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?
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: Question about texturing objects.

Post 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 :) )
Jay721
Halfling
Posts: 62
Joined: Mon Jan 29, 2018 8:19 am

Re: Question about texturing objects.

Post by Jay721 »

Ok sounds good thanks.
xrgo
OGRE Expert User
OGRE Expert User
Posts: 1148
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 168

Re: Question about texturing objects.

Post 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
Post Reply