Question about texturing objects.

Discussion area about developing with Ogre2 branches (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 » Sat Jan 12, 2019 5:44 pm

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.
0 x

Slicky
Bronze Sponsor
Bronze Sponsor
Posts: 537
Joined: Mon Apr 14, 2003 11:48 pm
Location: Was LA now France
x 12

Re: Question about texturing objects.

Post by Slicky » Sun Jan 13, 2019 9:46 pm

I'm not sure but it would seem you would need to dynamically change the uv's.
0 x

xrgo
OGRE Expert User
OGRE Expert User
Posts: 1044
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 73

Re: Question about texturing objects.

Post by xrgo » Sun Jan 13, 2019 11:36 pm

or map the texture using world space
0 x

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

Re: Question about texturing objects.

Post by Jay721 » Wed Feb 20, 2019 3:49 pm

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?
0 x

xrgo
OGRE Expert User
OGRE Expert User
Posts: 1044
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 73

Re: Question about texturing objects.

Post by xrgo » Wed Feb 20, 2019 3:59 pm

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
0 x

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

Re: Question about texturing objects.

Post by Jay721 » Thu Feb 21, 2019 11:57 am

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!
0 x

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

Re: Question about texturing objects.

Post by Jay721 » Thu Feb 21, 2019 4:06 pm

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?
0 x

xrgo
OGRE Expert User
OGRE Expert User
Posts: 1044
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 73

Re: Question about texturing objects.

Post by xrgo » Fri Feb 22, 2019 1:17 am

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 :) )
0 x

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

Re: Question about texturing objects.

Post by Jay721 » Fri Feb 22, 2019 5:51 pm

Ok sounds good thanks.
0 x

xrgo
OGRE Expert User
OGRE Expert User
Posts: 1044
Joined: Sat Jul 06, 2013 10:59 pm
Location: Chile
x 73

Re: Question about texturing objects.

Post by xrgo » Sat Feb 23, 2019 9:34 pm

(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
1 x

Post Reply