About Store Forum Documentation Contact



Post Reply 
Blending Textures
Author Message
XeonXT Offline
Member

Post: #1
Blending Textures
Hi!

I figured out my last question (how to texture different parts of the same mesh with different textures), and now I have another.

When you use WE to edit terrains and apply textures, how does the editor achieve texture blending? Are the textures blended dynamically in game (and if so, how can I achieve this same functionality using code?) Or are they stitched/blended together beforehand and saved as a custom diffuse map that is loaded at runtime (if this is the case, can you tell me, in general, what size should I split my diffuse maps into for good performance? 1024? 2048? 4096?)

Thanks very much!
02-15-2010 07:05 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #2
RE: Blending Textures
they are dynamically blended real time
part.setMaterail(,,,)
base.vtx.material[0].set(...
part.setRender
02-15-2010 03:25 PM
Find all posts by this user Quote this message in a reply
XeonXT Offline
Member

Post: #3
RE: Blending Textures
Esenthel,

Thanks very much, but I am still a bit unsure about how to implement this.

Code:
for ( int j = 0; j < thisMesh.parts(); ++j ){
    thisMesh.part(j).setMaterial(myMaterials);
    thisMesh.part(j).base.vtx.material[0].set(100);
    thisMesh.part(j).base.vtx.material[1].set(155);
}

Can you tell me what is wrong with that?

myMaterials is an array of 2 different materials, and I would like to blend between them. The lines with .set() cause the program to immediately crash.

Thanks
02-15-2010 05:59 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #4
RE: Blending Textures
part.setMaterail(mat1,mat2,...)
base.include(VTX_MATERIAL);
for each vtx base.vtx.material[i].set(mat1_blend,mat2_blend,0,0);
part.setRender
02-15-2010 06:10 PM
Find all posts by this user Quote this message in a reply
XeonXT Offline
Member

Post: #5
RE: Blending Textures
Code:
for ( int j = 0; j < thisMesh.parts(); ++j ){
    thisMesh.part(j).setMaterial(myMaterials);
    thisMesh.part(j).base.include(VTX_MATERIAL);
    for ( int k = 0; k < thisMesh.part(j).base.vtxs(); ++k ){
        thisMesh.part(j).base.vtx.material[k].set(255,255,0,0);
    }
    thisMesh.part(j).setRender();
}

Still no blending, even when I play with the values in set? On the bright side, .include(VTX_MATERIAL) fixed the crash...but still no blending :/
02-15-2010 06:23 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #6
RE: Blending Textures
part.setMaterail(mat1,mat2,...) <- two materials
thisMesh.part(j).base.vtx.material[k].set(x,y,z,w); // set xyzw that x+y+z+w=255
(for example 128,127,0,0)
02-15-2010 06:40 PM
Find all posts by this user Quote this message in a reply
XeonXT Offline
Member

Post: #7
RE: Blending Textures
Perfect! Now I understand, and that works beautifully. Thanks so much!

...and, of course, I have one final problem (sorry!!) smile
If I set the material like this on my entire terrain, the program crashes. If I set the material like this on all but one of the meshes that make up the terrain meshgroup, everything works fine (except that, of course, the material is incorrect on the one mesh that I excluded).

So it seems that the meshgroup won't let me manually set the material for every single mesh, but is fine if do it for all but one. This is very strange, any ideas on what's happening?
02-15-2010 07:12 PM
Find all posts by this user Quote this message in a reply
Brainache Offline
Member

Post: #8
RE: Blending Textures
complete guess: Possably an index issue?
02-15-2010 09:30 PM
Find all posts by this user Quote this message in a reply
XeonXT Offline
Member

Post: #9
RE: Blending Textures
Thanks, that wasn't the issue, but somehow it resolved itself O.o

Scary.
02-16-2010 12:20 AM
Find all posts by this user Quote this message in a reply
Abril Offline
Member

Post: #10
RE: Blending Textures
Hi, Im trying to do the same thing but only the first material (ground) is shown, no matter what values I put into vtx.material. Any idea of what might be missing here to get blending to work? Thanks.

MeshPart &pMeshPart=m_mesh->parts.New();
MeshBase &pPlane=pMeshPart.base.createPlane(8,8,VTX_TEX0);
pPlane.include(VTX_MATERIAL);

[...looping all vertices...]
pPlane.vtx.material(k)=VecB4(128,127,0,0);
[...]

m_mesh->setAutoTanBin()->setRender();
(This post was last modified: 07-15-2011 01:34 PM by Abril.)
07-14-2011 01:29 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #11
RE: Blending Textures
did you set 2 materials for the mesh? Mesh::setMaterial
07-16-2011 01:08 PM
Find all posts by this user Quote this message in a reply
Abril Offline
Member

Post: #12
RE: Blending Textures
got it working - now another question is it possible to set by code a different UV set for the second material? I tried using tex1 with different texture coords but doesnt have any effect (both materials still using coords from tex0).
Basically what I'd like to get is a different texture scaling for the 2nd blending material. Thanks
07-19-2011 11:39 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #13
RE: Blending Textures
you'd need to write a custom shader that uses 2nd uv set for 2nd material
all default shaders use only 1st uv set
07-21-2011 12:27 PM
Find all posts by this user Quote this message in a reply
Abril Offline
Member

Post: #14
RE: Blending Textures
I've noticed the material "Age of the canyon.mtrl" included in the stock SDK distribution, it is somehow getting its texture scaled up when rendered, compared to all other materials.
This is the effect i am looking for, however I can't seem to find any material setting that could influence that... would like to know why this material has increased UV scale when rendered compared to other materials... do you have any idea? It's weird but it really looks like it is getting scaled...
12-21-2011 04:45 PM
Find all posts by this user Quote this message in a reply
Abril Offline
Member

Post: #15
RE: Blending Textures
To reproduce...
- Load any model in the model editor
- Apply any material and notice the tiling of the texture material
- Now apply the age of the canyon material to the same model and notice the texture tiling is much smaller, despite the same model having of course the same UVs and only the material has changed.
12-21-2011 07:10 PM
Find all posts by this user Quote this message in a reply
Post Reply