How to displace UVs in real time?

Expanding and utilizing the engine via C++.
  • 1
  • 2
12 posts Page 1 of 2
LoLJester
Posts: 64
Joined: Thu Aug 13, 2015 5:58 pm
 
by LoLJester » Wed Nov 11, 2015 8:44 pm
Hello,

I'm trying to create a Tank vehicle with animated UV tracks.
Material animation is not an option as I'm to understand that Materials are not instanced per mesh, but one material applies to all meshes that have this material mapped to them.

Is it "tverts" that I must modify for the UV to displace in real time?
LoLJester
Posts: 64
Joined: Thu Aug 13, 2015 5:58 pm
 
by LoLJester » Wed Nov 11, 2015 10:46 pm
Hi Azaezel, the video looks pretty good.
I can see what you did, but the code seems to only apply to quads that you create from point A to point B.
How do I apply this to sceneObjects that are already mapped?
What I'm trying to do is modify the positioning of a texture already mapped to the tank tracks.
I see that "tverts" is assigned the UVs of the mesh in assembleMesh() and assembleShape(), but once I modify it, where is it updated?
Am I even on the right path?
LoLJester
Posts: 64
Joined: Thu Aug 13, 2015 5:58 pm
 
by LoLJester » Thu Nov 12, 2015 5:38 pm
Anybody, please?
I'm sure there's been a situation similar to this that someone must have encountered. Nobody's ever worked with the UVs in T3D before? I'm tempted to animate the tracks themselves, but they are already animated for suspension.
Azaezel
Posts: 395
Joined: Tue Feb 03, 2015 9:50 pm
 
by Azaezel » Thu Nov 12, 2015 6:12 pm
Honestly, what I'd do is hack into something like
https://github.com/GarageGames/Torque3D ... l.cpp#L887
with
https://github.com/Azaezel/Torque3D/com ... 39fa405ba7

The per-instance material damage in the vid was an older version that used that mMaterialDamage being passed around to modify the pre-existing detail feature alpha blend, for instance. So in your case...

https://github.com/Azaezel/Torque3D/com ... 9b5f1R2604 would be something along the lines of rdata.setMaterialSpeed(getVelocity().len());

https://github.com/Azaezel/Torque3D/com ... f78792R161 for you setMaterialSpeed definitions

https://github.com/Azaezel/Torque3D/com ... d85565R215 + https://github.com/Azaezel/Torque3D/com ... c077883R37 + https://github.com/Azaezel/Torque3D/com ... 88d090R175 for your glue code

probably will need to alt https://github.com/GarageGames/Torque3D ... l.cpp#L783 to pass the sgData along so you can do the equivalent of https://github.com/Azaezel/Torque3D/com ... 534a5R1240 for your offset multiplier. (also probably want to add a flag to materials that conrols whether or not they're multiplied by velocity so you don't end up grinding the rest to a halt)

Edit: further reading: http://wiki.torque3d.org/coder:extendin ... ial-system probably does a much better job of handling the whys.
LoLJester
Posts: 64
Joined: Thu Aug 13, 2015 5:58 pm
 
by LoLJester » Fri Nov 13, 2015 5:17 pm
Thanks, Azaezel! It looks like something that might just work.
LoLJester
Posts: 64
Joined: Thu Aug 13, 2015 5:58 pm
 
by LoLJester » Mon Nov 30, 2015 1:04 am
Ok. I got it to somewhat work, but strangely only in Debug. For some odd reason, I can't get the shader to work in Release or Optimized Debug mode. Is there something I'm missing?
Azaezel
Posts: 395
Joined: Tue Feb 03, 2015 9:50 pm
 
by Azaezel » Mon Nov 30, 2015 1:19 am
Only working in debug sounds like somethings not getting initialized properly. Got a fork up to look it over?
LoLJester
Posts: 64
Joined: Thu Aug 13, 2015 5:58 pm
 
by LoLJester » Mon Nov 30, 2015 1:41 am
No. I'm on the road right now, always on the move. :) I will double check if everything gets initialized properly. I basically looked at how WindDeform and Visibility do it. Is there a way to Debug the Shaders through Torque?
LoLJester
Posts: 64
Joined: Thu Aug 13, 2015 5:58 pm
 
by LoLJester » Mon Nov 30, 2015 2:28 am
The Vert and Pix shaders:

void uvAnimFeatureHLSL::processVert( Vector<ShaderComponent*> &componentList, 
const MaterialFeatureData &fd )
{
MultiLine *meta = new MultiLine;

if(fd.features[MFT_UseInstancing])
{
// We pass the uvOffset to the pixel shader via
// another output register.
//
// TODO: We should see if we can share this register
// with some other common instanced data.
//
ShaderConnector *conn = dynamic_cast<ShaderConnector *>( componentList[C_CONNECTOR] );
Var *out_UV_Offset = conn->getElement( RT_TEXCOORD );
out_UV_Offset->setStructName( "OUT" );
out_UV_Offset->setName( "uvOffset" );
out_UV_Offset->setType( "float" );

ShaderConnector *vertStruct = dynamic_cast<ShaderConnector *>( componentList[C_VERT_STRUCT] );
Var *inst_UV_Offset = vertStruct->getElement( RT_TEXCOORD, 1 );
inst_UV_Offset->setStructName( "IN" );
inst_UV_Offset->setName( "inst_uvOffset" );
inst_UV_Offset->setType( "float" );
mInstancingFormat->addElement( "uvOffset", GFXDeclType_Float, inst_UV_Offset->constNum );

meta->addStatement( new GenOp( " @ = @; // Instancing!\r\n", out_UV_Offset, inst_UV_Offset ) );
}

getOutTexCoord("texCoord", "float2", true, false, meta, componentList);

output = meta;
}

//-------------------------------------------------------------------------------------------------------
void uvAnimFeatureHLSL::processPix( Vector<ShaderComponent*> &componentList,
const MaterialFeatureData &fd )
{
//Sorin D: Get the uvOffset constant.
Var *uvOffset = NULL;
if(fd.features[MFT_UseInstancing])
uvOffset = getInTexCoord( "uvOffset", "float", false, componentList );
else
{
uvOffset = (Var*)LangElement::find( "uvOffset" );

if(!uvOffset)
{
uvOffset = new Var();
uvOffset->setType( "float" );
uvOffset->setName( "uvOffset" );
uvOffset->uniform = true;
uvOffset->constSortPos = cspPotentialPrimitive;
}
}

MultiLine *meta = new MultiLine;

//Sorin D: Get the texture coordinate UV0.
Var *inUV = getInTexCoord( "texCoord", "float2", true, componentList );

//Sorin D: Calculate and set the UV's offset.
meta->addStatement(new GenOp( " @ = float2( @.x, @.y + @ );\r\n", inUV, inUV, inUV, uvOffset));

output = meta;
}
  • 1
  • 2
12 posts Page 1 of 2

Who is online

Users browsing this forum: No registered users and 2 guests