### How to displace UVs in real time?

Expanding and utilizing the engine via C++.
• 1
• 2

#### How to displace UVs in real time?

LoLJester
Posts: 66
Joined: Thu Aug 13, 2015 5:58 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?

#### Re: How to displace UVs in real time?

Azaezel
Posts: 409
Joined: Tue Feb 03, 2015 9:50 pm

#### Re: How to displace UVs in real time?

LoLJester
Posts: 66
Joined: Thu Aug 13, 2015 5:58 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?

#### Re: How to displace UVs in real time?

LoLJester
Posts: 66
Joined: Thu Aug 13, 2015 5:58 pm

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.

#### Re: How to displace UVs in real time?

Azaezel
Posts: 409
Joined: Tue Feb 03, 2015 9:50 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.

#### Re: How to displace UVs in real time?

LoLJester
Posts: 66
Joined: Thu Aug 13, 2015 5:58 pm

Thanks, Azaezel! It looks like something that might just work.

#### Re: How to displace UVs in real time?

LoLJester
Posts: 66
Joined: Thu Aug 13, 2015 5:58 pm

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?

#### Re: How to displace UVs in real time?

Azaezel
Posts: 409
Joined: Tue Feb 03, 2015 9:50 pm

Only working in debug sounds like somethings not getting initialized properly. Got a fork up to look it over?

#### Re: How to displace UVs in real time?

LoLJester
Posts: 66
Joined: Thu Aug 13, 2015 5:58 pm

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?

#### Re: How to displace UVs in real time?

LoLJester
Posts: 66
Joined: Thu Aug 13, 2015 5:58 pm

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.
//
// with some other common instanced data.
//
Var *out_UV_Offset = conn->getElement( RT_TEXCOORD );
out_UV_Offset->setStructName( "OUT" );
out_UV_Offset->setName( "uvOffset" );
out_UV_Offset->setType( "float" );

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" );

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

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

output = meta;
}

//-------------------------------------------------------------------------------------------------------
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

#### Who is online

Users browsing this forum: No registered users and 1 guest