Are Decals on DTS possible in TGEA?
by Ronald J Nelson · in Torque Game Engine Advanced · 01/08/2008 (5:50 pm) · 19 replies
It wasn't possible without a ton of additional code in TGE. I did eventually get it to work in a manner of speaking. I have asked several questions about texture layers in an attempt to make a method that works in TGEA. I just want to ask if it is possible in TGEA and if it has been done already. Now keep in mind I don't mean static DTS objects, I am referring to player and vehicle classes.
If it has been done in TGEA already, please let me know.
If it has been done in TGEA already, please let me know.
#2
01/08/2008 (6:51 pm)
If you are familiar with programming with C, and C+ then learning HLSL wont be a problem for you, and if not then starting there in my opinion can be a good opener for learning to program games...it was for me. This is on my list of things to add to TGEA...will let you know when progress in other ares let me get to this;)
#3
Thats why I have been really looking into what i would take to make a texture layer system for TGEA.
Frankly I was hoping since the TGEA/TSE had been around for a few years now, someone had already managed to do it.
01/08/2008 (6:51 pm)
Well Marc to be honest with the system that I did before in TGE was nothing more than detecting the location on the player, converting the coordinates into an equivalent to the texture's XY coordinates and placing a texture layer on the object based upon those coordinates.Thats why I have been really looking into what i would take to make a texture layer system for TGEA.
Frankly I was hoping since the TGEA/TSE had been around for a few years now, someone had already managed to do it.
#4
01/08/2008 (7:07 pm)
Cool Bobby. I have been trying as well. Just not having the best of luck so far.
#5
01/08/2008 (7:13 pm)
I'm not sure what it is that your trying to do with decals on DTS, but the simplistic way to do it would just be to add a second pass and have the second pass on top of your model which is your decal pass. Create a decal texture which had a blood splatter (or multiple ones) image that has some transparent space around it. Have it always draw that image as the second pass, but have the UVs set to the transparent areas normally, and then adjust the uvs on the image so that the splatters appear in a certain location. If the decals are in a static location (like a patch or something) then it is very easy to do, if your having blood splatters that can be in different locations of the body its a little bit trickier as your going to have to develop some code to figure out where to offset the uvs for where you was hit. You'd also run into the problem of multiple splatters on a single character at once. But that would be the direction I'd look into.
#6
01/08/2008 (8:45 pm)
Well... had a thought, and feel free to drive it all the way into the dirt if it's as dumb as half of me thinks it is, but... what about adapting that render-a-gui-to-texture rescource? know you've got that incorporated already since parts of that were the foundation stone of some of the stuff we've already put our heads togeather over... at that point it'd be a matter of genning a gui element and attatching it in the right spot...
#7
So if you used this on a vehicle, you would be replacing the entire base material with a GUI element. So if I were to use this, it would really be ablout the same thing as setting a material.
What I need is the ability to allow the texture to keep its size and not have to be the same size as the base texture. I have been digging alot in the materials code and have only seen a setting for scale in the wave code for materialInstances.
Additionally, I would need to allow it to apply the layer texture based upon XY coordinates of the object's material base texture. Now I have not seen anything like this in the code for TGEA and it looks as if it would have to somehow access the base material's texture and perform the adjustment that way rather than try and change the material itself.
Now this resource for TGE:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=12197
Has the basic elements of what I think need to be done. But rather than using some set base texture value, it needs to get the base texture from the object's base material in use.
This would mean, performing a function to get the current base material, then that material's base texture. Then you would perform the layering operations that were in this resource.
Finally you would have to perform a setTexture for that material instance that is a combination of the layers.
Now if it were possible to base it upon the XYZ coordinates of the object itself, well that would be even better, but it would be extremely difficult to pull off. I never did get it to work that way in TGE. The only guy I think did was John Kabus.
As you can see I have a pretty strong idea on what needs to be done, I am just working out alot of the particulars.
01/08/2008 (9:28 pm)
Well it is far from a dumb idea. I had considered this but it is not going to work. The reson is basically that resource is making a GUI element into a material that can be mapped onto a surface. It actually is the material for that surface area and not a layer. So if you used this on a vehicle, you would be replacing the entire base material with a GUI element. So if I were to use this, it would really be ablout the same thing as setting a material.
What I need is the ability to allow the texture to keep its size and not have to be the same size as the base texture. I have been digging alot in the materials code and have only seen a setting for scale in the wave code for materialInstances.
Additionally, I would need to allow it to apply the layer texture based upon XY coordinates of the object's material base texture. Now I have not seen anything like this in the code for TGEA and it looks as if it would have to somehow access the base material's texture and perform the adjustment that way rather than try and change the material itself.
Now this resource for TGE:
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=12197
Has the basic elements of what I think need to be done. But rather than using some set base texture value, it needs to get the base texture from the object's base material in use.
This would mean, performing a function to get the current base material, then that material's base texture. Then you would perform the layering operations that were in this resource.
Finally you would have to perform a setTexture for that material instance that is a combination of the layers.
Now if it were possible to base it upon the XYZ coordinates of the object itself, well that would be even better, but it would be extremely difficult to pull off. I never did get it to work that way in TGE. The only guy I think did was John Kabus.
As you can see I have a pretty strong idea on what needs to be done, I am just working out alot of the particulars.
#8
As the way stuff is rendered was totally changed (Batcher implementation), most resources from before that point do not work anymore.
And in the last 10 months most people spend a lot of time fixing annoying bugs or just going back to TGE / using a stable working engine I sometimes think ...
01/09/2008 (4:42 am)
The main problem is, TGEA has not been around for years. It has been around until Release and then after.As the way stuff is rendered was totally changed (Batcher implementation), most resources from before that point do not work anymore.
And in the last 10 months most people spend a lot of time fixing annoying bugs or just going back to TGE / using a stable working engine I sometimes think ...
#9
Here is the code I am in the process of converting from that resource. Could someone tell me what I am doing wrong in getting baseTex[0] from the material?
The value "selectedMaterial" is set in a console method and it is the name of the material you want to add the layer to.
Right now it just crashes. But that is in the works too.
01/09/2008 (10:43 pm)
Well I have been hard at work at converting that resource into something that will work. However, I am running into what seems to be a small issue but it is kicking my butt all the same. How to get the baseTex[0] of a material.Here is the code I am in the process of converting from that resource. Could someone tell me what I am doing wrong in getting baseTex[0] from the material?
The value "selectedMaterial" is set in a console method and it is the name of the material you want to add the layer to.
bool ShapeBase::generateTexture()
{
if(!isGhost()) return false;
GBitmap* baseBitmap;
char fullpath[256]={'/0'};
Material* currentMaterial;
TSMaterialList* pMatList = mShapeInstance->getMaterialList();
S32 pMatPos = -1;
for (S32 j = 0; j < pMatList->mMaterialNames.size(); j++)
{
const char* pName = pMatList->mMaterialNames[j];
if (pName == NULL) continue;
if (dStrstr(pName, selectedMaterial))
{
pMatPos = j;
//Material::loadMaterial(selectedMaterial);
MatInstance * matInst = pMatList->getMaterialInst(j);
currentMaterial = matInst->getMaterial();
//fullpath = currentMaterial->baseTexFilename[0];
Con::errorf(ConsoleLogEntry::General, "This should be the baseTex[0]: %s", currentMaterial->baseTexFilename[0]);
break;
}
}
//Need to change this to get the material's base texture
//Use selectedMaterial to get this
baseBitmap = (GBitmap*)ResourceManager->loadInstance( fullpath ); Right now it just crashes. But that is in the works too.
#10
new_mat.baseTexFilename[your_stage .. 0 is first];
or GFX->GetRenderTargetData(RT, surface);
01/10/2008 (3:56 am)
Material new_mat;new_mat.baseTexFilename[your_stage .. 0 is first];
or GFX->GetRenderTargetData(RT, surface);
#11
01/10/2008 (2:44 pm)
Thanks Picasso. So basically what I have in the Console Log Entry is correct.
#12
Other than that this conversion is progressing nicely. Any ideas on why I am getting this problem?
01/10/2008 (11:22 pm)
Well this is what I have so far and the last Console log entry that should be giving me the string that is the baseTex[0] for the material is giving me NULL.void ShapeBase::generateTexture()
{
GBitmap* baseBitmap;
const char* fullpath = "";
Material* currentMaterial;
// If materiallist is not cloned, clone it ( need to do this so we dont
// change the material for all instances of this shape
if(!mShapeInstance->ownMaterialList())
{
mShapeInstance->cloneMaterialList();
}
TSMaterialList* pMatList = mShapeInstance->getMaterialList();
S32 pMatPos = -1;
for (S32 j = 0; j < pMatList->getMaterialCount(); j++)
{
const char* pName = pMatList->getMaterialName(j);
if (pName == NULL)
continue;
if (dStrstr(pName, selectedMaterial))
{
Con::errorf(ConsoleLogEntry::General, "Found the material!");
pMatPos = j;
MatInstance * matInst = pMatList->getMaterialInst(j);
currentMaterial = matInst->getMaterial();
fullpath = currentMaterial->baseTexFilename[0];
break;
}
}
Con::errorf(ConsoleLogEntry::General, "This should be the baseTex[0]: %s", fullpath);Other than that this conversion is progressing nicely. Any ideas on why I am getting this problem?
#14
Hopefully someone can throw me me a bone on where to start on the final portion of creating a working texture layer system for TGEA.
Here is the main function:
The portion that is I am just needing a good starting point from someone a bit more versed in TGEA is this one at the end:
First the texture.set portion is no longer valid in TGEA. Additionally I need to actually access the material instance texture in a set texture style of function. In the second part there, I was just hoping if someone could let me know if there is already an available method for that?
Thanks for any assistance you can provide. I am not asking you to do my work for me. Just point me in a good direction please.
01/11/2008 (7:43 pm)
Well I have managed to get all of the resource converted to TGEA other than one segement. It correctly works with the materials and makes the layers based upon the materials base texture.Hopefully someone can throw me me a bone on where to start on the final portion of creating a working texture layer system for TGEA.
Here is the main function:
void ShapeBase::generateTexture()
{
GBitmap* baseBitmap;
const char* fullpath = "";
Material* currentMaterial;
GFXTexHandle potentialMaterial;
// If materiallist is not cloned, clone it ( need to do this so we dont
// change the material for all instances of this shape
if(!mShapeInstance->ownMaterialList())
{
mShapeInstance->cloneMaterialList();
}
TSMaterialList* pMatList = mShapeInstance->getMaterialList();
S32 pMatPos = -1;
for (S32 j = 0; j < pMatList->getMaterialCount(); j++)
{
MatInstance * matInst = pMatList->getMaterialInst(j);
currentMaterial = matInst->getMaterial();
const char* pName = currentMaterial->getName();
if (pName == NULL)
continue;
if (dStrstr(pName, selectedMaterial))
{
pMatPos = j;
fullpath = currentMaterial->baseTexFilename[0];
break;
}
}
baseBitmap = (GBitmap*)ResourceManager->loadInstance( fullpath );
if( baseBitmap->getFormat() != GFXFormatR8G8B8 ) {
Con::errorf(ConsoleLogEntry::General, "material texture not RGB format");
return;
}
for( U32 i = 0; i < TEXTURELAYERS; i++ )
{
if( layerTextureName[i] != NULL && dStrlen(layerTextureName[i])>0 )
{
GBitmap* layerBitmap = (GBitmap*)ResourceManager->loadInstance( layerTextureName[i] );
if( layerBitmap == NULL ) {
Con::errorf(ConsoleLogEntry::General, "layerTextureName (%s) invalid file", layerTextureName[i]);
continue;
}
if( layerBitmap->getFormat() != GFXFormatR8G8B8A8 ) {
Con::errorf(ConsoleLogEntry::General, "layerTextureName (%s) not RGBA", layerTextureName[i]);
continue;
}
if( !blit( baseBitmap, layerBitmap, pointsList[i], rotationList[i] ) ) {
Con::errorf(ConsoleLogEntry::General, "Unable to blit layerTextureName (%s)", layerTextureName[i]);
continue;
}
delete layerBitmap;
}
}
char texName[50] = "[[628116bd82378]]";
dSprintf(texName, sizeof(texName), "unique_texture_name_%s", this->getIdString());
GFXTexHandle texture;
//Need to modify this so it will set the texture for the material
texture.set(texName, baseBitmap, MeshTexture);
if (pMatPos > -1)
{
pMatList->mMaterials[pMatPos] = GFXTexHandle( texture );
}
}The portion that is I am just needing a good starting point from someone a bit more versed in TGEA is this one at the end:
char texName[50] = "[[628116bd82650]]";
dSprintf(texName, sizeof(texName), "unique_texture_name_%s", this->getIdString());
GFXTexHandle texture;
//Need to modify this so it will set the texture for the material
texture.set(texName, baseBitmap, MeshTexture);
if (pMatPos > -1)
{
pMatList->mMaterials[pMatPos] = GFXTexHandle( texture );
}First the texture.set portion is no longer valid in TGEA. Additionally I need to actually access the material instance texture in a set texture style of function. In the second part there, I was just hoping if someone could let me know if there is already an available method for that?
Thanks for any assistance you can provide. I am not asking you to do my work for me. Just point me in a good direction please.
#15
And it should compile.
01/11/2008 (8:01 pm)
Try texture.set( baseBitmap, &GFXDefaultStaticDiffuseProfile, true); And it should compile.
#16
01/11/2008 (8:08 pm)
Thanks Steven. I had suspected something like that from what I was reading, but it is good to hear a confirmation before I blow things up.
#17
BAsically what I need to figure out is how to update the material instance to use either "texture" or "baseBitmap". I image I will have to create a new method of sorts in the material code.
01/11/2008 (9:40 pm)
Well it certainly compiles. but I am fairly certain thereis no way this linepMatList->mMaterials[pMatPos] = GFXTexHandle( texture );is going to work in TGEA.
BAsically what I need to figure out is how to update the material instance to use either "texture" or "baseBitmap". I image I will have to create a new method of sorts in the material code.
#18
And it should compile.
01/12/2008 (12:53 am)
Try texture.set( baseBitmap, &GFXDefaultStaticDiffuseProfile, true); And it should compile.
#19
01/12/2008 (3:40 pm)
Well I have figured out how to do this with one needed piece of information. Is there some way to change components of a material Instance in code? I specifically want to change the bitmap for it.
Torque 3D Owner Marc Dreamora Schaerer
Gayasoft