Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (AndrewAMD, monk12, TipmyPip, Quad, aliswee), 1,029 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 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