Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Texture Stretching

Author
Message
Rims Flames
12
Years of Service
User Offline
Joined: 5th Apr 2014
Location:
Posted: 14th Sep 2014 12:02
Hi guys,

I want to scale a cube with a texture but the texture stretches when i scale it. How can make it automatically scale the texture when i am scaling the object? I tried like scale object texture obj, object size x(obj) / 5 but it didn't worked that well.

Thank You!

Rims Flames
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 14th Sep 2014 13:19
Quote: "How can make it automatically scale the texture when i am scaling the object?"


You need to explain what you mean. The texture should be scaled automatically when you scale an object. Perhaps you mean the opposite, i.e. perhaps you don't want the texture to be scaled at all when the object is scaled?

A simple picture created in MS Paint would clarify what you mean.



Powered by Free Banners
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 14th Sep 2014 13:19
Quote: "scale object texture obj, object size x(obj) / 5 but it didn't worked that well."


Yes, this is the way ! but we have better result in a plain object . If you do it in the main DO/LOOP you need something like this:




I'm not a grumpy grandpa
Rims Flames
12
Years of Service
User Offline
Joined: 5th Apr 2014
Location:
Posted: 14th Sep 2014 14:01
Chafari i used your code for scale object texture but it still looks like this

Rims Flames
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 14th Sep 2014 14:56
Quote: "Chafari i used your code for scale object texture but it still looks like this"


This piece of code scale the texture proportionally in the three axes

As GG commented
Quote: " perhaps you don't want the texture to be scaled at all when the object is scaled?
"


Could you show us an example you find on the net or could you make us a picture what you need exactly ?.

I'm not a grumpy grandpa
Rims Flames
12
Years of Service
User Offline
Joined: 5th Apr 2014
Location:
Posted: 14th Sep 2014 17:08
The photo attached on my last post before this contains a cube that is streched. That texture is square tiles that are SQUARE. Because of the X scaling, those textures went rectangular. The cube if its scaled, the texture must look the same as the photo attached in this post.

Thank You again!

Rims Flames
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 14th Sep 2014 19:13 Edited at: 14th Sep 2014 19:20
In the poste above , you showed us a scaled cube. But you said that you had use my code . Now I understand less than before . I'm using the same code with your image and it works correctly . Can you show us just the code that texture your object ?



EDIT You have to scale object proportionally...if not, you instead of show z face you have to see x face .

I'm not a grumpy grandpa
Rims Flames
12
Years of Service
User Offline
Joined: 5th Apr 2014
Location:
Posted: 14th Sep 2014 20:32
In the first photo i showed you a scaled cube with the texture that has been stretched and i don't want that texture to be stretched when the cube is scaled.
I have multiple texture stages:



Rims Flames
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 14th Sep 2014 20:46 Edited at: 14th Sep 2014 21:00
Then you need to Scale Object Texture on each texture stage.

@chafari: Cool snippet! Hope you don't mind, I took the hardcoding out of Scale Object Texture.



Rims Flames
12
Years of Service
User Offline
Joined: 5th Apr 2014
Location:
Posted: 14th Sep 2014 21:38
I did this but still stretched textures here is the new code, some faces are ok but others are stretched and when i am scaling the cube largely enogh, the texture that was ok starts to stretch again




Rims Flames
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 14th Sep 2014 21:45
Quote: "@chafari: Cool snippet! Hope you don't mind, I took the hardcoding out of Scale Object Texture."


@WickedX Don't worry.
The texture has height and width. If we scale object texture obj,1,1 that is the same as no scaling at all. We can scale of course under 0 and more than 1. when we refer to scale object texture, it scale in three axes at once . I have used your method but it looks to stretches the image . Can you show us what you mean with Scale Object Texture on each texture stage.


I'm not a grumpy grandpa
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 14th Sep 2014 21:58 Edited at: 14th Sep 2014 22:00
Try this. It may be the integer divisor is causing a floating point error or the scale is just too large.



Rims Flames
12
Years of Service
User Offline
Joined: 5th Apr 2014
Location:
Posted: 14th Sep 2014 21:59
What do you mean explain scale object texture on each texture stage?

I have these textures to load:

load image "Textures/Detail/Detail.dds",1
load image "Textures/Floor/Floor.dds",9
load image "Textures/Floor/floor_n.dds",10
load image "Textures/Floor/floor_s.dds",11

Rims Flames
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 14th Sep 2014 22:05 Edited at: 14th Sep 2014 22:19
When we use a plain object, it is easy, as we don't need to worry about the third axe.



@WickedX Could you apply your method to this code adding a box or cube instead of a plain ?

Edit
I'm trying to use Wickedx's method but not luck . Press a/s to see.



I'm not a grumpy grandpa
Rims Flames
12
Years of Service
User Offline
Joined: 5th Apr 2014
Location:
Posted: 14th Sep 2014 22:18
I did this code still the same result...

Rims Flames
Rims Flames
12
Years of Service
User Offline
Joined: 5th Apr 2014
Location:
Posted: 14th Sep 2014 22:21
A box yes will be a good example to the plain one

Rims Flames
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 14th Sep 2014 22:21 Edited at: 14th Sep 2014 22:22
When we were scaling equally on all axis both methods work. Scaling on individual axis, both methods fail.

Quote: "@WickedX Could you apply your method to this code adding a box or cube instead of a plain ?"


no, won't work. May be able to change uv data with vertex data functions.

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 14th Sep 2014 22:23 Edited at: 14th Sep 2014 22:26
@Rims Flames

I don't know why you need a box to achieve that. This is not completly imposible . There is a way to make this without driving crazy . You could make your own box made of six limbs (plains) then use the method scaling limb texture instead of object texture

Cheers.

Edit.
@WickedX . Finally you saw it !

I'm not a grumpy grandpa
WickedX
17
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 14th Sep 2014 22:31 Edited at: 14th Sep 2014 22:32
Quote: "@WickedX . Finally you saw it !"


Sometimes it takes me a while. We need functions to scale the objects texture on all 3 axis.

Rims Flames
12
Years of Service
User Offline
Joined: 5th Apr 2014
Location:
Posted: 14th Sep 2014 22:33
This code kind of resolves it but only on 4 faces the rest of two top and bottom still remains stretched.



Rims Flames
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 14th Sep 2014 22:39 Edited at: 14th Sep 2014 23:28
Quote: "Sometimes it takes me a while."


Me too

Quote: "This code kind of resolves it but only on 4 faces the rest of two top and bottom still remains stretched.
"



Yes it work always in two axes, so you can add two plain to the cube .

EDIT.

Half the trick done !!



I'm not a grumpy grandpa
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Sep 2014 14:49
@Chafari

Nice.


@Rims Flames

I see what your problem is now.

Chafari seems to be making good progress with it. As long as you are using simple cubes and boxes aligned with the XYZ axes you should be OK. I guess things get a bit messier if the object's pivot is rotated.



Powered by Free Banners
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 15th Sep 2014 15:17
Quote: "I guess things get a bit messier if the object's pivot is rotated. "


I have not tried yet but I think the rotation does not interfere at all in the textured.

I'm not a grumpy grandpa
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 15th Sep 2014 15:31
It must do since you are using object size X(), etc. Simple rotations are fine but not if your object is rotated to begin with. I need to be convinced by an example. Suppose, for example, your object is a simple plain with corners (X,Y) = (-1,0), (0,1), (1,0) and (0,-1) but with the usual UV coordinates?



Powered by Free Banners
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 15th Sep 2014 15:52
GG
Maybe you are right in this example it change drastically, but I think that what change is the mesh aswell . fifty fifty



I'm not a grumpy grandpa
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 16th Sep 2014 19:26
To supplement your progress on this matter; Evolved created a number of code snippets on his website www.evolved-software.com. One of these snippets, known as Automap, includes a function for automatically scaling a texture given a set of measurements per pixel.

The link to the page

chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 17th Sep 2014 00:13 Edited at: 17th Sep 2014 00:14
@Chris Tate
I have used this function before ...great tool !! but until now I didn't pay attention too much how it works. I'm trying to do the same with my example above, but it needs some scroll aswell, because this function automap the object increasing texture in both sides . I tried offseting then center but not good result .





I'm not a grumpy grandpa
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 17th Sep 2014 18:47
Good luck with it; it is a shame I am unable to help out at present; but I am sure you will all figure it all out

Login to post a reply

Server time is: 2026-07-17 23:34:11
Your offset time is: 2026-07-17 23:34:11