About Store Forum Documentation Contact
Donations:
140$/mo



Post Reply 
Access to material / texture index (for multitexturing)
Author Message
Zorath Offline
Member

Post: #1
Access to material / texture index (for multitexturing)
Hello,

I create a plane mesh directly with code and apply a material to it. But I would like to add another material (or texture) on a second layer, in order to do multitexturing, which would be blended or added to the first layer's material.
I saw some functions to alter textures' UV mapping with tex_index parameter, but is there a way to apply a texture on other layers with code ?

Thanks.
03-30-2009 12:50 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
Re: Access to material / texture index (for multitexturing)
Hi,

You are able to achieve only the effect like you can achieve in the World Editor - smoothly blend between one material to another.

only one texture coordinate set is supported (Vec2 Mshb::vtx.tx0)

to do this you would need to:

set material[0] and material[1] of a MeshPart to different materials.
add information about per-vertex material blends
mesh_part.base.include(VTX_MTRL);
set per vertex material blend values
Mshb.vtx.mtrl[0]=ARGB(0,0,0,255); // set #0 vertex material full blend for first material
Mshb.vtx.mtrl[1]=ARGB(0,0,255,0); // set #1 vertex material full blend for second material
Mshb.vtx.mtrl[2]=ARGB(0,0,128,128); // set #2 vertex material partial blend between first and second material
update mesh render version - mesh.setRender();

please note that I've written this from my head, and not tested it.
03-30-2009 03:25 PM
Find all posts by this user Quote this message in a reply
Zorath Offline
Member

Post: #3
Re: Access to material / texture index (for multitexturing)
Thank you, that helped me a lot and is exactly what I was looking for smile
03-30-2009 05:04 PM
Find all posts by this user Quote this message in a reply
Biga Offline
Member

Post: #4
RE: Access to material / texture index (for multitexturing)
It is possible that these methods changed in later version?
I have to set material with setMaterial(ID,int)? as comment shows it is for LOD...
for vtx, I found only material() for getting blend, but where can I set it?
05-15-2014 10:27 AM
Find all posts by this user Quote this message in a reply
Biga Offline
Member

Post: #5
RE: Access to material / texture index (for multitexturing)
found sth about setting blending, it is correct?

PHP Code:
Earth.mesh->parts(0).base.vtx.material(0).set(12812800);
      
Earth.mesh->parts(0).base.vtx.material(1).set(12812800); 

but not sure how to add 2nd material to part...
05-15-2014 11:54 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
RE: Access to material / texture index (for multitexturing)
In MeshPart class:
Code:
MeshPart& setMaterial  (C MaterialPtr &m0, C MaterialPtr &m1, C MaterialPtr &m2, C MaterialPtr &m3, Int lod_index=0); // set materials, 'lod_index'=index of the lod in the mesh (required in order to set appropriate quality of the shader),  materials must point to object in constant memory address (mesh will store only the pointer to the material and later use it if needed), during rendering it is better to use MaterialLock to draw the mesh with different material (instead of calling this method)
05-15-2014 09:49 PM
Find all posts by this user Quote this message in a reply
Biga Offline
Member

Post: #7
RE: Access to material / texture index (for multitexturing)
seems I missed the 2nd version of method with more meshptrs..
thx!
05-15-2014 11:58 PM
Find all posts by this user Quote this message in a reply
Biga Offline
Member

Post: #8
RE: Access to material / texture index (for multitexturing)
using SetMaterial, but still getting black texture on mesh if I apply blending, trying to realize what you mentioned before:

Mshb.vtx.mtrl[2]=ARGB(0,0,128,128);

=>

Earth.mesh->parts(0).base.vtx.material(2).set(0,0,128,128);

can you pls tell me the right method instead of ...vtx.mtrl[x]

no such access I see , and no ARGB method. (=just VecB4?)

Edited: or maybe I just miss sth with Setrender...?
(This post was last modified: 05-16-2014 11:09 AM by Biga.)
05-16-2014 10:33 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #9
RE: Access to material / texture index (for multitexturing)
Please try
base.vtx.material(i).set(128,128,0,0);
part.setMaterial(mtrl1, mtrl2, null, null);
and at the end:
part.setRender();
05-17-2014 06:31 AM
Find all posts by this user Quote this message in a reply
Biga Offline
Member

Post: #10
RE: Access to material / texture index (for multitexturing)
thanks a lot! it worked:

PHP Code:
for(int v=0;  v<Earth.mesh->parts(0).base.vtx.elms();  v++)
      {
         
Earth.mesh->parts(0).base.vtx.material(v).set(128,12800);   
      } 
      
Earth.mesh->parts(0).setRender(); 

the problem was the order of parameters and probably that I missed the two null parameters after my ones in setmaterial.

so I would summary the workaround maybe someone will meet with the same problem:

1. settings (init):

Code:
Earth.mesh->setBase();
Earth.mesh->parts(0).base.include(VTX_MATERIAL);

2. materials (init):

Code:
MaterialPtr mptr1 =       UID(your uid1);
MaterialPtr mptr2= UID(your uid2);
yourmesh->parts(0).setMaterial(mptr1, mptr2, null, null);

3. blend:

Code:
for(int v=0;  v<Earth.mesh->parts(0).base.vtx.elms();  v++)
      {
         yourmesh->parts(0).base.vtx.material(v).set(128,128, 0, 0);  
      }
      yourmesh->parts(0).setRender();

thanks the help again smile
05-17-2014 11:18 AM
Find all posts by this user Quote this message in a reply
Post Reply