Gamestudio Links
Zorro Links
Newest Posts
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
LPDIRECT3DCUBETEXTUR
E9

by Ayumi. 04/12/24 11:00
Sam Foster Sound | Experienced Game Composer for Hire
by titanicpiano14. 04/11/24 14:56
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (1 invisible), 482 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
11honza11, ccorrea, sakolin, rajesh7827, juergen_wue
19045 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
How to cover a cube with a (tiled) texture by code #474215
09/30/18 13:17
09/30/18 13:17
Joined: Feb 2014
Posts: 1
N
Nobby Offline OP
Guest
Nobby  Offline OP
Guest
N

Joined: Feb 2014
Posts: 1
I want to cover primitives like a cube as well as more complex meshes with one or more textures (skins) from external bitmap files (e.g. 128x128 pixel / 32 Bit color / tga format) by code NOT with an editor. Any ideas?

I tried different things like this but w/o success:

ent = ent_create(CUBE_MDL, vector(-100, 0, 0), NULL); //create primitive
ent_clone(ent); //clone primitive
set(ent, SHADOW | CAST); //enable shadow if lighted by spots
BMAP* skin = bmap_create("Brick_08.tga");
ent_setskin(ent, skin, 1);

Re: How to cover a cube with a (tiled) texture by code [Re: Nobby] #474218
09/30/18 19:04
09/30/18 19:04
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
You could use tri-planar texturing, something like the following (untested but should/ could work):

Code:
const float4x4 matWorldViewProj;
const float4x4 matWorld;
const float4 vecSunDir;
float4 vecSkill41;

texture entSkin1;

sampler ColorMapSampler = sampler_state 
{ 
   Texture = <entSkin1>; 
   AddressU  = Wrap; 
   AddressV  = Wrap; 
}; 
    
void DiffuseVS( 
   in float4 InPos: POSITION, 
   in float3 InNormal: NORMAL, 
   in float2 InTex: TEXCOORD0, 
   out float4 OutPos: POSITION, 
   out float3 OutTex: TEXCOORD0, 
   out float3 OutNormal: TEXCOORD1,
   out float3 OutNormal2: TEXCOORD2) 
{ 
   OutPos = mul(InPos, matWorldViewProj); 
   OutNormal = mul(InNormal, matWorld);
   OutNormal2 = InNormal;
   OutTex = InPos.xyz*vecSkill41.x+vecSkill41.yzw;
} 
    
float4 DiffusePS( 
   in float3 InTex: TEXCOORD0, 
   in float3 InNormal: TEXCOORD1,
   in float3 InNormal2: TEXCOORD2): COLOR 
{ 
	InNormal = normalize(InNormal);
   
   float Diffuse = saturate(dot(-vecSunDir, InNormal)*2)*0.5+0.5; 
   
   float4 Color = tex2D(ColorMapSampler, InTex.xy)*InNormal2.z*InNormal2.z; 
   Color += tex2D(ColorMapSampler, InTex.xz+0.333)*InNormal2.y*InNormal2.y; 
   Color += tex2D(ColorMapSampler, InTex.yz+0.667)*InNormal2.x*InNormal2.x; 
   
   float4 final = Color*Diffuse;
  
   return final; 
} 
 

technique DiffuseTechnique 
{ 
   pass P0 
   { 
      VertexShader = compile vs_2_0 DiffuseVS(); 
      PixelShader  = compile ps_2_0 DiffusePS(); 
   } 
}



entity.skill41 is the scaling of the texture, try for example
entity.skill41 = floatd(1.0,16.0); // for a cube with a width of 16 quants

You can add an offset such as
entity.skill42 = floatv(0.5);
entity.skill43 = floatv(0.5);
entity.skill44 = floatv(0.5);
which might result in better tiling/ fitting textures.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1