3 registered members (AndrewAMD, Ayumi, ozgur),
650
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
scaling textures with object's scale?
#399496
04/16/12 14:55
04/16/12 14:55
|
Joined: Oct 2008
Posts: 513
Carlos3DGS
OP
User
|
OP
User
Joined: Oct 2008
Posts: 513
|
Hard to describe this clearly in the title, so let me try get the idea across in more detailed explanation: I have lots of square cube blocks in my game, the player can place and scale the height of these blocks, kind of like a simplified minecraft. These blocks all have tileable textures so they look continueous side by side. To build a castle looking structure you would scale a block to a height of x12, the block beside to height x10, and continue altering heights of your blocks between x12 and x10 till you have built the complete structure out of blocks.
My problem is this: When scaling the height of a block, the texture on the sides (walls) are streched, so the tileable textures on the sides (wall) no longer match the wall textures of the blocks beside it.
My question is, to avoid this "stretching" problem on the textures... Is there any way to tile the texture on the objects depending on it's size instead of stretching it?
Last edited by Carlos3DGS; 04/16/12 15:10.
|
|
|
Re: scaling textures with object's scale?
[Re: HeelX]
#399514
04/16/12 17:04
04/16/12 17:04
|
Joined: Oct 2008
Posts: 513
Carlos3DGS
OP
User
|
OP
User
Joined: Oct 2008
Posts: 513
|
Thought I might need a shader for it... Ive started to work on some pseudo-code to get my ideas straight and the logic looks something like this so far:
float3 object_pos = my object's origin;
float3 pixel_pos = position relative to object origin;
float3 world_pos = object_pos + pixel_pos;
float3 normal = pixel surface's normal;
float2 texture_pos = world_pos;
texture_pos.x += world_pos.z * normal.x;
texture_pos.y += world_pos.z * normal.y;
float4 pixel = texture_sampler(texture_pos);//wrap
I am definately interested in your approach, sending you a pm right now
|
|
|
Re: scaling textures with object's scale?
[Re: sivan]
#399564
04/17/12 10:18
04/17/12 10:18
|
Joined: Oct 2008
Posts: 513
Carlos3DGS
OP
User
|
OP
User
Joined: Oct 2008
Posts: 513
|
even though I called them "blocks" some times they are not wed blocks. They are simple med models. I am trying the shader route here: http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=399546&#Post399546 but am open to any suggestions. What is that u1 u2 thing you mentioned for? Changing the UV texture mapping coordinates at runtime or something else?
|
|
|
Re: scaling textures with object's scale?
[Re: sivan]
#399574
04/17/12 12:04
04/17/12 12:04
|
Joined: Mar 2011
Posts: 3,150 Budapest
sivan
Expert
|
Expert
Joined: Mar 2011
Posts: 3,150
Budapest
|
by ent_getvertex it is possible to access the D3DVERTEX pointer of any model/terrain vertex called c.v if:
CONTACT* c = ent_getvertex(entity,NULL,vertex_number);
and as described in atypes.h:
typedef struct { float x,y,z; // position in DirectX coordinates float nx,ny,nz; // normal float u1,v1; // first coordinate set, for textures float u2,v2; // second coordinate set, for shadow maps float x3,y3,z3,w3; // third coordinate set, for tangent vector and handedness #ifdef A8 float tu4,tv4; // 4th coordinate set, for additional data #endif } D3DVERTEX;
very similar to mesh deformation, but now c.v.u1 and v1 are what you need (floats!). And then ent_setvertex(entity,c,vertex_number);
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|